static Link ok

This commit is contained in:
lyon 2022-04-30 23:13:05 +08:00
parent e6b9116f1b
commit f002d9f73d
3 changed files with 12 additions and 12 deletions

View File

@ -334,7 +334,7 @@ TEST(lib, init) {
TEST(lib, lib_link_bytecode) {
LibObj* lib = New_LibObj();
LibObj_linkByteCode(lib, "module1", (uint8_t*)0x3344);
LibObj_dynamicLink(lib, "module1", (uint8_t*)0x3344);
EXPECT_STREQ(obj_getStr(lib, "index.module1.name"), "module1");
EXPECT_EQ((uintptr_t)obj_getPtr(lib, "index.module1.bytecode"), 0x3344);
/* deinit */
@ -344,7 +344,7 @@ TEST(lib, lib_link_bytecode) {
TEST(lib, lib_push_file) {
LibObj* lib = New_LibObj();
LibObj_pushByteCodeFile(lib, "test/python/main.py.o");
LibObj_staticLinkFile(lib, "test/python/main.py.o");
/* deinit */
LibObj_deinit(lib);
EXPECT_EQ(pikaMemNow(), 0);
@ -352,8 +352,8 @@ TEST(lib, lib_push_file) {
TEST(lib, lib_push_files) {
LibObj* lib = New_LibObj();
LibObj_pushByteCodeFile(lib, "test/python/main.py.o");
LibObj_pushByteCodeFile(lib, "test/python/main_snake_LCD.py.o");
LibObj_staticLinkFile(lib, "test/python/main.py.o");
LibObj_staticLinkFile(lib, "test/python/main_snake_LCD.py.o");
LibObj_listModules(lib);
/* asset */
EXPECT_STREQ(log_buff[0], "main\r\n");

View File

@ -124,7 +124,7 @@ void LibObj_deinit(LibObj* self) {
}
/* add bytecode to lib, not copy the bytecode */
void LibObj_linkByteCode(LibObj* self, char* module_name, uint8_t* bytecode) {
void LibObj_dynamicLink(LibObj* self, char* module_name, uint8_t* bytecode) {
PikaObj* index_obj = obj_getObj(self, "index");
if (!obj_isArgExist(index_obj, module_name)) {
obj_newObj(index_obj, module_name, "", New_TinyObj);
@ -135,7 +135,7 @@ void LibObj_linkByteCode(LibObj* self, char* module_name, uint8_t* bytecode) {
}
/* add bytecode to lib, and copy the bytecode to the buff in the lib */
int LibObj_pushByteCode(LibObj* self,
int LibObj_staticLink(LibObj* self,
char* module_name,
uint8_t* bytecode,
size_t size) {
@ -147,11 +147,11 @@ int LibObj_pushByteCode(LibObj* self,
/* copy bytecode to buff */
obj_setBytes(module_obj, "buff", bytecode, size);
/* link to buff */
LibObj_linkByteCode(self, module_name, obj_getBytes(module_obj, "buff"));
LibObj_dynamicLink(self, module_name, obj_getBytes(module_obj, "buff"));
return 0;
}
int LibObj_pushByteCodeFile(LibObj* self, char* input_file_name) {
int LibObj_staticLinkFile(LibObj* self, char* input_file_name) {
char* file_buff = __platform_malloc(PIKA_READ_FILE_BUFF_SIZE);
Args buffs = {0};
FILE* input_f = __platform_fopen(input_file_name, "r");
@ -164,7 +164,7 @@ int LibObj_pushByteCodeFile(LibObj* self, char* input_file_name) {
module_name[strlen(module_name) - (sizeof(".py.o") - 1)] = 0;
/* push bytecode */
LibObj_pushByteCode(self, module_name, (uint8_t*)file_buff, size);
LibObj_staticLink(self, module_name, (uint8_t*)file_buff, size);
/* deinit */
__platform_free(file_buff);

View File

@ -11,11 +11,11 @@ int pikaCompile(char* output_file_name, char* py_lines);
typedef PikaObj LibObj;
LibObj* New_LibObj(void);
void LibObj_deinit(LibObj* self);
void LibObj_linkByteCode(LibObj* self, char* module_name, uint8_t* bytecode);
int LibObj_pushByteCode(LibObj* self,
void LibObj_dynamicLink(LibObj* self, char* module_name, uint8_t* bytecode);
int LibObj_staticLink(LibObj* self,
char* module_name,
uint8_t* bytecode,
size_t size);
int LibObj_pushByteCodeFile(LibObj* self, char* input_file_name);
int LibObj_staticLinkFile(LibObj* self, char* input_file_name);
void LibObj_listModules(LibObj* self);
#endif