init obj and run __init__ in OUT instruct

This commit is contained in:
lyon 2022-01-14 22:42:42 +08:00
parent a1d1d12d32
commit ca00fd1e96
2 changed files with 10 additions and 9 deletions

View File

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

View File

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