diff --git a/port/linux/test/VM-test.cpp b/port/linux/test/VM-test.cpp index 4c6775c8e..cf5926038 100644 --- a/port/linux/test/VM-test.cpp +++ b/port/linux/test/VM-test.cpp @@ -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); diff --git a/port/linux/test/compile-test.cpp b/port/linux/test/compile-test.cpp index d40694d63..bbc21f16b 100644 --- a/port/linux/test/compile-test.cpp +++ b/port/linux/test/compile-test.cpp @@ -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); +} diff --git a/src/PikaVM.c b/src/PikaVM.c index c24361e05..391177342 100644 --- a/src/PikaVM.c +++ b/src/PikaVM.c @@ -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 = diff --git a/src/PikaVM.h b/src/PikaVM.h index 96fa808c8..261271060 100644 --- a/src/PikaVM.h +++ b/src/PikaVM.h @@ -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); diff --git a/src/pikaCompiler.c b/src/pikaCompiler.c index 6b01e016c..56e6c5adc 100644 --- a/src/pikaCompiler.c +++ b/src/pikaCompiler.c @@ -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) { +} diff --git a/src/pikaCompiler.h b/src/pikaCompiler.h index c83ce346f..1930e7483 100644 --- a/src/pikaCompiler.h +++ b/src/pikaCompiler.h @@ -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 \ No newline at end of file