diff --git a/port/linux/.vscode/launch.json b/port/linux/.vscode/launch.json index 37e32d0db..173754d96 100644 --- a/port/linux/.vscode/launch.json +++ b/port/linux/.vscode/launch.json @@ -11,7 +11,7 @@ "program": "${workspaceFolder}/build/test/pikascript_test", // "program": "${workspaceFolder}/build/boot/demo06-pikamain/pikascript_demo06-pikamain", "args": [ - // "--gtest_filter=stddata.list_str" + "--gtest_filter=vm.super_val_" ], "stopAtEntry": false, "cwd": "${workspaceFolder}", diff --git a/port/linux/package/pikascript/modbus.py b/port/linux/package/pikascript/modbus.py index bb963a6af..078036c73 100644 --- a/port/linux/package/pikascript/modbus.py +++ b/port/linux/package/pikascript/modbus.py @@ -52,8 +52,7 @@ class ModBus(_modbus._ModBus): def deserializeReadRegisters(self, msg: bytes) -> list: self.readBuff = msg - length = len(msg) - dest = super().deserializeReadRegisters(length) + dest = super().deserializeReadRegisters(len(msg)) ret = [] for i in range(0, len(dest), 2): ret.append(int(dest[i]) + int(dest[i + 1]) * 256) diff --git a/port/linux/test/VM-test.cpp b/port/linux/test/VM-test.cpp index f61e1d97a..6d5bbe4e1 100644 --- a/port/linux/test/VM-test.cpp +++ b/port/linux/test/VM-test.cpp @@ -1527,6 +1527,7 @@ TEST(vm, super_val_) { char* t2_a = obj_getStr(pikaMain, "t2.a"); /* assert */ EXPECT_EQ(t1_a, 1); + EXPECT_STREQ(t2_a, "1"); /* deinit */ obj_deinit(pikaMain); EXPECT_EQ(pikaMemNow(), 0); diff --git a/src/PikaVM.c b/src/PikaVM.c index 3e3e0c18f..0fa579fe5 100644 --- a/src/PikaVM.c +++ b/src/PikaVM.c @@ -1051,6 +1051,7 @@ static Arg* VM_instruction_handler_RUN(PikaObj* self, if (strEqu(run_path, "super")) { run_path = _find_super_class_name(vm); vm->in_super = PIKA_TRUE; + vm->super_invoke_deepth = VMState_getInvokeDeepthNow(vm); skip_init = PIKA_TRUE; } #endif @@ -1061,13 +1062,6 @@ static Arg* VM_instruction_handler_RUN(PikaObj* self, goto exit; } -#if !PIKA_NANO_ENABLE - if (!skip_init && vm->in_super) { - vm->in_super = PIKA_FALSE; - obj_this = obj_getPtr(vm->locals, _find_self_name(vm)); - } -#endif - /* get method host obj from reg */ if (NULL == method_host && _checkLReg(run_path)) { uint8_t reg_index = _getLRegIndex(run_path); @@ -1120,6 +1114,14 @@ static Arg* VM_instruction_handler_RUN(PikaObj* self, goto exit; } +#if !PIKA_NANO_ENABLE + if (!skip_init && vm->in_super && + VMState_getInvokeDeepthNow(vm) == vm->super_invoke_deepth - 1) { + vm->in_super = PIKA_FALSE; + obj_this = obj_getPtr(vm->locals, _find_self_name(vm)); + } +#endif + /* get object this */ if (NULL == obj_this) { obj_this = method_host; @@ -2664,11 +2666,11 @@ void VMState_solveUnusedStack(VMState* vm) { char* res = obj_toStr(arg_getPtr(arg)); __platform_printf("%s\r\n", res); } else if (type == ARG_TYPE_INT) { - #if PIKA_PRINT_LLD_ENABLE +#if PIKA_PRINT_LLD_ENABLE __platform_printf("%lld\r\n", arg_getInt(arg)); - #else +#else __platform_printf("%d\r\n", (int)arg_getInt(arg)); - #endif +#endif } else if (type == ARG_TYPE_FLOAT) { __platform_printf("%f\r\n", arg_getFloat(arg)); } else if (type == ARG_TYPE_STRING) { @@ -2706,6 +2708,7 @@ static VMParameters* __pikaVM_runByteCodeFrameWithState( .run_state = run_state, .ins_cnt = 0, .in_super = PIKA_FALSE, + .super_invoke_deepth = 0, }; stack_init(&(vm.stack)); VMState_initReg(&vm); diff --git a/src/PikaVM.h b/src/PikaVM.h index 429ab18fb..21648e8dc 100644 --- a/src/PikaVM.h +++ b/src/PikaVM.h @@ -77,6 +77,7 @@ struct VMState { uint8_t try_error_code; uint32_t ins_cnt; PIKA_BOOL in_super; + uint8_t super_invoke_deepth; PikaObj* lreg[PIKA_REGIST_SIZE]; PIKA_BOOL ireg[PIKA_REGIST_SIZE]; RunState* run_state;