add PikaLib class to gen '*.a'

This commit is contained in:
lyon 2022-04-29 23:56:25 +08:00
parent c9f56112c7
commit 882421ae5b
6 changed files with 38 additions and 6 deletions

View File

@ -901,7 +901,7 @@ TEST(VM, load_static_bytes) {
.output_f = NULL,
}};
byteCodeFrame_loadBytes(&bytecode_frame, (uint8_t*)bytes);
byteCodeFrame_loadByteCode(&bytecode_frame, (uint8_t*)bytes);
byteCodeFrame_print(&bytecode_frame);
EXPECT_EQ(instructArray_getSize(&(bytecode_frame.instruct_array)), 520);

View File

@ -1,4 +1,3 @@
#include "gtest/gtest.h"
extern "C" {
#include "PikaMain.h"
@ -331,3 +330,9 @@ TEST(compiler, file2) {
pikaCompileFile((char*)"test/python/main_snake_LCD.py");
EXPECT_EQ(pikaMemNow(), 0);
}
TEST(lib, init) {
PikaLib* lib = New_PikaLib();
PikaLib_deinit(lib);
EXPECT_EQ(pikaMemNow(), 0);
}

View File

@ -1025,7 +1025,7 @@ static VMParameters* __pikaVM_runPyLines_or_byteCode(PikaObj* self,
}
} else {
/* load bytecode */
byteCodeFrame_loadBytes(bytecode_frame_p, bytecode);
byteCodeFrame_loadByteCode(bytecode_frame_p, bytecode);
}
/* run byteCode */
@ -1157,7 +1157,7 @@ void byteCodeFrame_init(ByteCodeFrame* self) {
instructArray_init(&(self->instruct_array));
}
void byteCodeFrame_loadBytes(ByteCodeFrame* self, uint8_t* bytes) {
void byteCodeFrame_loadByteCode(ByteCodeFrame* self, uint8_t* bytes) {
uint16_t* ins_size_p = (uint16_t*)bytes;
void* ins_start_p = (uint16_t*)(bytes + 2);
uint16_t* const_size_p =

View File

@ -124,7 +124,7 @@ void constPool_update(ConstPool* self);
void instructArray_update(InstructArray* self);
void constPool_printAsArray(ConstPool* self);
void instructArray_printAsArray(InstructArray* self);
void byteCodeFrame_loadBytes(ByteCodeFrame* self, uint8_t* bytes);
void byteCodeFrame_loadByteCode(ByteCodeFrame* self, uint8_t* bytes);
void byteCodeFrame_printAsArray(ByteCodeFrame* self);
VMParameters* pikaVM_runByteCode(PikaObj* self, uint8_t* bytecode);

View File

@ -86,6 +86,13 @@ int pikaCompile(char* output_file_name, char* py_lines) {
return 0;
};
/*
need implament :
__platform_fopen()
__platform_fread()
__platform_fwrite()
__platform_fclose()
*/
int pikaCompileFileWithOutputName(char* output_file_name,
char* input_file_name) {
char* file_buff = __platform_malloc(PIKA_READ_FILE_BUFF_SIZE);
@ -105,3 +112,14 @@ int pikaCompileFile(char* input_file_name) {
strsDeinit(&buffs);
return 0;
}
PikaLib* New_PikaLib(void) {
return New_TinyObj(NULL);
}
void PikaLib_deinit(PikaLib* self) {
obj_deinit(self);
}
void PikaLib_LinkByteCode(PikaLib* self, char* module_name, uint8_t* bytecode) {
}

View File

@ -1,8 +1,17 @@
#ifndef __PIKA_COMPILER__H
#define __PIKA_COMPILER__H
#include "PikaObj.h"
int pikaCompileFile(char* input_file_name);
int pikaCompileFileWithOutputName(char* output_file_name, char* input_file_name);
int pikaCompileFileWithOutputName(char* output_file_name,
char* input_file_name);
int pikaCompile(char* output_file_name, char* py_lines);
typedef PikaObj PikaLib;
PikaLib* New_PikaLib(void);
void PikaLib_deinit(PikaLib* self);
void PikaLib_importByteCodeFrame(PikaLib* self,
char* module_name,
ByteCodeFrame* bf);
#endif