fix can not invoke inner super.method()

This commit is contained in:
pikastech 2022-09-19 14:31:41 +08:00
parent a41f138895
commit abb557093a
5 changed files with 17 additions and 13 deletions

View File

@ -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}",

View File

@ -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)

View File

@ -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);

View File

@ -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);

View File

@ -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;