mirror of
https://gitee.com/Lyon1998/pikapython.git
synced 2025-01-15 17:02:53 +08:00
fix bug: can not run the function defind from module
This commit is contained in:
parent
5120da9ce0
commit
2d98f1c63e
@ -1,4 +1,9 @@
|
||||
#include "cJSON_Utils.h"
|
||||
|
||||
PikaObj* cJSON_Utils_parse(PikaObj* self) {}
|
||||
PikaObj* cJSON_Utils_createObject(PikaObj *self){}
|
||||
PikaObj* cJSON_Utils_parse(PikaObj* self) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
PikaObj* cJSON_Utils_createObject(PikaObj *self){
|
||||
return NULL;
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
#include "cJSON_cJSON.h"
|
||||
|
||||
char* cJSON_cJSON_print(PikaObj *self){
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void cJSON_cJSON___init__(PikaObj *self){
|
||||
|
2
port/linux/.vscode/launch.json
vendored
2
port/linux/.vscode/launch.json
vendored
@ -11,7 +11,7 @@
|
||||
"program": "${workspaceFolder}/build/test/pikascript_test",
|
||||
// "program": "${workspaceFolder}/build/boot/demo06-pikamain/pikascript_demo06-pikamain",
|
||||
"args": [
|
||||
// "--gtest_filter=parser.slice_12lkj"
|
||||
"--gtest_filter=pikaMain.module_import_from_module"
|
||||
],
|
||||
"stopAtEntry": false,
|
||||
"cwd": "${workspaceFolder}",
|
||||
|
@ -1,4 +1,9 @@
|
||||
#include "cJSON_Utils.h"
|
||||
|
||||
PikaObj* cJSON_Utils_parse(PikaObj* self) {}
|
||||
PikaObj* cJSON_Utils_createObject(PikaObj *self){}
|
||||
PikaObj* cJSON_Utils_parse(PikaObj* self) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
PikaObj* cJSON_Utils_createObject(PikaObj *self){
|
||||
return NULL;
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
#include "cJSON_cJSON.h"
|
||||
|
||||
char* cJSON_cJSON_print(PikaObj *self){
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void cJSON_cJSON___init__(PikaObj *self){
|
||||
|
@ -1,4 +1,11 @@
|
||||
import test_module2
|
||||
import test_module3
|
||||
|
||||
|
||||
def mytest():
|
||||
print('test_module_1_hello')
|
||||
|
||||
|
||||
def test_module_import():
|
||||
print('in test module 2')
|
||||
test_module2.mytest()
|
||||
|
@ -2164,3 +2164,36 @@ TEST(pikaMain, string_str) {
|
||||
obj_deinit(self);
|
||||
EXPECT_EQ(pikaMemNow(), 0);
|
||||
}
|
||||
|
||||
TEST(pikaMain, module_import_from_module) {
|
||||
pikaMemInfo.heapUsedMax = 0;
|
||||
PikaObj* self = newRootObj("pikaMain", New_PikaMain);
|
||||
extern unsigned char pikaModules_py_a[];
|
||||
obj_linkLibrary(self, pikaModules_py_a);
|
||||
__platform_printf("BEGIN\r\n");
|
||||
obj_run(self,
|
||||
"import test_module1\n"
|
||||
"test_module1.test_module_import()\n"
|
||||
);
|
||||
EXPECT_STREQ(log_buff[0], "test_module_2_hello\r\n");
|
||||
EXPECT_STREQ(log_buff[1], "in test module 2\r\n");
|
||||
EXPECT_STREQ(log_buff[2], "BEGIN\r\n");
|
||||
obj_deinit(self);
|
||||
EXPECT_EQ(pikaMemNow(), 0);
|
||||
}
|
||||
|
||||
TEST(pikaMain, module_1_module2_test) {
|
||||
pikaMemInfo.heapUsedMax = 0;
|
||||
PikaObj* self = newRootObj("pikaMain", New_PikaMain);
|
||||
extern unsigned char pikaModules_py_a[];
|
||||
obj_linkLibrary(self, pikaModules_py_a);
|
||||
__platform_printf("BEGIN\r\n");
|
||||
obj_run(self,
|
||||
"import test_module1\n"
|
||||
"test_module1.test_module2.mytest()\n"
|
||||
);
|
||||
EXPECT_STREQ(log_buff[0], "test_module_2_hello\r\n");
|
||||
EXPECT_STREQ(log_buff[1], "BEGIN\r\n");
|
||||
obj_deinit(self);
|
||||
EXPECT_EQ(pikaMemNow(), 0);
|
||||
}
|
@ -1025,7 +1025,7 @@ int obj_runModule(PikaObj* self, char* module_name) {
|
||||
|
||||
int obj_importModule(PikaObj* self, char* module_name) {
|
||||
/* import bytecode of the module */
|
||||
uint8_t* bytecode = obj_getByteCodeFromModule(self, module_name);
|
||||
uint8_t* bytecode = obj_getByteCodeFromModule(__pikaMain, module_name);
|
||||
if (NULL == bytecode) {
|
||||
return 1;
|
||||
}
|
||||
|
10
src/PikaVM.c
10
src/PikaVM.c
@ -948,12 +948,11 @@ static Arg* VM_instruction_handler_IMP(PikaObj* self, VMState* vs, char* data) {
|
||||
return NULL;
|
||||
}
|
||||
/* import module from '__lib' */
|
||||
if (0 != obj_importModule(__pikaMain, data)) {
|
||||
VMState_setErrorCode(vs, 3);
|
||||
__platform_printf("ModuleNotFoundError: No module named '%s'\r\n",
|
||||
data);
|
||||
if (0 == obj_importModule(self, data)) {
|
||||
return NULL;
|
||||
}
|
||||
VMState_setErrorCode(vs, 3);
|
||||
__platform_printf("ModuleNotFoundError: No module named '%s'\r\n", data);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@ -1393,7 +1392,8 @@ void VMState_solveUnusedStack(VMState* vs) {
|
||||
continue;
|
||||
}
|
||||
if (argType_isObject(type)) {
|
||||
__platform_printf("<object at 0x%02x>\r\n", (uintptr_t)arg_getPtr(arg));
|
||||
__platform_printf("<object at 0x%02x>\r\n",
|
||||
(uintptr_t)arg_getPtr(arg));
|
||||
}
|
||||
if (type == ARG_TYPE_INT) {
|
||||
__platform_printf("%d\r\n", (int)arg_getInt(arg));
|
||||
|
Loading…
x
Reference in New Issue
Block a user