diff --git a/port/linux/.vscode/launch.json b/port/linux/.vscode/launch.json index 97c216a5b..66d1371b6 100644 --- a/port/linux/.vscode/launch.json +++ b/port/linux/.vscode/launch.json @@ -19,7 +19,8 @@ // "--gtest_filter=thread.test1" // "--gtest_filter=eventloop.test1" // "--gtest_filter=parser.tuple_single" - "--gtest_filter=parser.split_slice" + // "--gtest_filter=parser.split_slice" + "--gtest_filter=vm.var_global_run" ], "stopAtEntry": false, "cwd": "${workspaceFolder}", diff --git a/src/PikaVM.c b/src/PikaVM.c index 337d0c609..0d7f1ee29 100644 --- a/src/PikaVM.c +++ b/src/PikaVM.c @@ -999,14 +999,16 @@ static Arg* VM_instruction_handler_REF(PikaObj* self, aRes = _obj_getProp(oHost, arg_name); } - /* find res in globlas */ - if (NULL == aRes) { - aRes = args_getArg(vm->globals->list, arg_name); - } + /* find res in globals */ + if (arg_path == arg_name) { + if (NULL == aRes) { + aRes = args_getArg(vm->globals->list, arg_name); + } - /* find res in globals prop */ - if (NULL == aRes) { - aRes = _obj_getProp(vm->globals, arg_name); + /* find res in globals prop */ + if (NULL == aRes) { + aRes = _obj_getProp(vm->globals, arg_name); + } } /* proxy */ @@ -1786,6 +1788,7 @@ static Arg* VM_instruction_handler_RUN(PikaObj* self, VMParameters* oSublocals = NULL; VMParameters* oSublocalsInit = NULL; char* sRunPath = data; + char* sArgName = NULL; PikaObj* oMethodHost = NULL; PikaObj* oThis = NULL; Arg* aMethod = NULL; @@ -1799,6 +1802,10 @@ static Arg* VM_instruction_handler_RUN(PikaObj* self, .try_result = TRY_RESULT_NONE}; pika_assert(NULL != vm->run_state); + if (NULL != sRunPath) { + sArgName = strPointToLastToken(sRunPath, '.'); + } + /* inhert */ if (vm->pc - 2 * (int)instructUnit_getSize() >= 0) { if (CLS == VMstate_getInstructWithOffset( @@ -1823,6 +1830,7 @@ static Arg* VM_instruction_handler_RUN(PikaObj* self, /* support for super() */ if (strEqu(sRunPath, "super")) { sRunPath = _find_super_class_name(vm); + sArgName = sRunPath; vm->in_super = PIKA_TRUE; vm->super_invoke_deepth = VMState_getInvokeDeepthNow(vm); bSkipInit = PIKA_TRUE; @@ -1911,16 +1919,18 @@ static Arg* VM_instruction_handler_RUN(PikaObj* self, aMethod = obj_getMethodArg_noalloc(oMethodHost, sRunPath, &arg_reg1); } - /* get method in locals */ - if (NULL == aMethod) { - aMethod = obj_getMethodArg_noalloc(vm->locals, sRunPath, &arg_reg1); - } - - /* get method in global */ - if (NULL == aMethod) { - aMethod = obj_getMethodArg_noalloc(vm->globals, sRunPath, &arg_reg1); - if (aMethod != NULL) { - oThis = vm->globals; + if (sArgName == sRunPath) { + /* get method in locals */ + if (NULL == aMethod) { + aMethod = obj_getMethodArg_noalloc(vm->locals, sRunPath, &arg_reg1); + } + /* get method in global */ + if (NULL == aMethod) { + aMethod = + obj_getMethodArg_noalloc(vm->globals, sRunPath, &arg_reg1); + if (aMethod != NULL) { + oThis = vm->globals; + } } } diff --git a/test/VM-test.cpp b/test/VM-test.cpp index a3ddeffff..f70bfb712 100644 --- a/test/VM-test.cpp +++ b/test/VM-test.cpp @@ -2850,6 +2850,18 @@ TEST_RUN_LINES_EXCEPT_OUTPUT(vm, single_tuple_str, "('test',)", "('test',)\r\n") TEST_RUN_SINGLE_FILE_PASS(vm, is_not, "test/python/builtin/is_not.py") +TEST_RUN_LINES(vm, + var_global, + "import PikaStdLib\n" + "mem = PikaStdLib.MemChecker()\n" + "mem.clear\n") + +TEST_RUN_LINES(vm, + var_global_run, + "import PikaStdLib\n" + "mem = PikaStdLib.MemChecker()\n" + "mem.clear()\n") + #endif TEST_END \ No newline at end of file diff --git a/test/test_common.h b/test/test_common.h index 03b1a9277..d4628539a 100644 --- a/test/test_common.h +++ b/test/test_common.h @@ -59,7 +59,7 @@ extern char log_buff[LOG_BUFF_MAX][LOG_SIZE]; #define TEST_RUN_LINES(_test_suite_, _test_name_, _lines_) \ TEST(_test_suite_, _test_name_) { \ - PikaObj *self = newRootObj("root", New_PikaStdLib_SysObj); \ + PikaObj *self = newRootObj("root", New_PikaMain); \ obj_run(self, (_lines_)); /* collect */ /* assert */ \ obj_deinit(self); \ EXPECT_EQ(pikaMemNow(), 0); \