From ca00fd1e9602d0b4e0471f23df2c87e6f91ec047 Mon Sep 17 00:00:00 2001 From: lyon Date: Fri, 14 Jan 2022 22:42:42 +0800 Subject: [PATCH] init obj and run __init__ in OUT instruct --- src/PikaObj.c | 8 -------- src/PikaVM.c | 11 ++++++++++- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/PikaObj.c b/src/PikaObj.c index 9de72c197..e00b0e4c1 100644 --- a/src/PikaObj.c +++ b/src/PikaObj.c @@ -29,7 +29,6 @@ #include "PikaObj.h" #include "BaseObj.h" #include "PikaPlatform.h" -#include "PikaVM.h" #include "dataArgs.h" #include "dataMemory.h" #include "dataString.h" @@ -357,7 +356,6 @@ static PikaObj* __initObj(PikaObj* obj, char* name) { Args* buffs = New_args(NULL); PikaObj* thisClass; PikaObj* newObj; - Arg* methodArg; if (NULL == newObjFun) { /* no such object */ res = NULL; @@ -368,12 +366,6 @@ static PikaObj* __initObj(PikaObj* obj, char* name) { args_setPtrWithType(obj->list, name, TYPE_OBJECT, newObj); res = obj_getPtr(obj, name); - /* run __init__() when init obj */ - methodArg = obj_getMethod(res, "__init__"); - if (NULL != methodArg) { - arg_deinit(methodArg); - obj_run(res, "__init__()"); - } goto exit; exit: args_deinit(buffs); diff --git a/src/PikaVM.c b/src/PikaVM.c index dd00e872f..bf2470457 100644 --- a/src/PikaVM.c +++ b/src/PikaVM.c @@ -219,7 +219,16 @@ static Arg* VM_instruction_handler_OUT(PikaObj* self, obj_setArg(vmState->locals, data, outArg); if (TYPE_MATE_OBJECT == arg_getType(outArg)) { /* init all object */ - obj_getObj(self, data, 0); + PikaObj* new_obj = obj_getObj(self, data, 0); + /* run __init__() when init obj */ + Arg* methodArg = NULL; + methodArg = obj_getMethod(new_obj, "__init__"); + if (NULL != methodArg) { + arg_deinit(methodArg); + pikaVM_runAsm(new_obj, + "B0\n" + "0 RUN __init__\n"); + } } arg_deinit(outArg); return NULL;