keep both meta obj and direct obj, meta obj cannot init with arg

This commit is contained in:
lyon 2022-04-28 00:42:06 +08:00
parent ceb8de7c81
commit 5cbe98d212
6 changed files with 29 additions and 34 deletions

View File

@ -41,8 +41,8 @@ void PikaStdLib_SysObj_type(PikaObj* self, Arg* arg) {
obj_setSysOut(self, "<class 'object'>"); obj_setSysOut(self, "<class 'object'>");
return; return;
} }
if (ARG_TYPE_OBJECT_MATE == type) { if (ARG_TYPE_OBJECT_META == type) {
obj_setSysOut(self, "<class 'mate object'>"); obj_setSysOut(self, "<class 'meta object'>");
return; return;
} }
if (ARG_TYPE_METHOD_NATIVE == type) { if (ARG_TYPE_METHOD_NATIVE == type) {
@ -116,7 +116,7 @@ Arg* PikaStdLib_SysObj_iter(PikaObj* self, Arg* arg) {
return arg_newMetaObj(New_PikaStdLib_StringObj); return arg_newMetaObj(New_PikaStdLib_StringObj);
} }
/* a MATE object, return itself */ /* a MATE object, return itself */
if (ARG_TYPE_OBJECT_MATE == arg_getType(arg)) { if (ARG_TYPE_OBJECT_META == arg_getType(arg)) {
return arg_copy(arg); return arg_copy(arg);
} }
/* object */ /* object */

View File

@ -41,8 +41,8 @@ void PikaStdLib_SysObj_type(PikaObj* self, Arg* arg) {
obj_setSysOut(self, "<class 'object'>"); obj_setSysOut(self, "<class 'object'>");
return; return;
} }
if (ARG_TYPE_OBJECT_MATE == type) { if (ARG_TYPE_OBJECT_META == type) {
obj_setSysOut(self, "<class 'mate object'>"); obj_setSysOut(self, "<class 'meta object'>");
return; return;
} }
if (ARG_TYPE_METHOD_NATIVE == type) { if (ARG_TYPE_METHOD_NATIVE == type) {
@ -116,7 +116,7 @@ Arg* PikaStdLib_SysObj_iter(PikaObj* self, Arg* arg) {
return arg_newMetaObj(New_PikaStdLib_StringObj); return arg_newMetaObj(New_PikaStdLib_StringObj);
} }
/* a MATE object, return itself */ /* a MATE object, return itself */
if (ARG_TYPE_OBJECT_MATE == arg_getType(arg)) { if (ARG_TYPE_OBJECT_META == arg_getType(arg)) {
return arg_copy(arg); return arg_copy(arg);
} }
/* object */ /* object */

View File

@ -379,28 +379,24 @@ Arg* obj_getRefArg(PikaObj* self) {
return arg_setPtr(NULL, "", ARG_TYPE_OBJECT_FREE, self); return arg_setPtr(NULL, "", ARG_TYPE_OBJECT_FREE, self);
} }
Arg* arg_newMetaObj(NewFun objPtr) { Arg* arg_newMetaObj(NewFun new_obj_fun) {
Arg* argNew = New_arg(NULL); Arg* arg_new = New_arg(NULL);
/* m means mate-object */ /* m means meta-object */
argNew = arg_setPtr(argNew, "", ARG_TYPE_OBJECT_MATE, (void*)objPtr); arg_new = arg_setPtr(arg_new, "", ARG_TYPE_OBJECT_META, (void*)new_obj_fun);
return argNew; return arg_new;
} }
Arg* arg_newDirectObj(NewFun newObjFun) { Arg* arg_newDirectObj(NewFun new_obj_fun) {
PikaObj* newObj = NewObjDirect(newObjFun); PikaObj* newObj = NewObjDirect(new_obj_fun);
Arg* objArg = arg_setPtr(NULL, "", ARG_TYPE_OBJECT_FREE, newObj); Arg* arg_new = arg_setPtr(NULL, "", ARG_TYPE_OBJECT_FREE, newObj);
return objArg; return arg_new;
} }
Arg* arg_newObj(NewFun newObjFun) { Arg* obj_newObjInPackage(NewFun new_obj_fun) {
return arg_newDirectObj(newObjFun); return arg_newDirectObj(new_obj_fun);
} }
Arg* obj_newObjInPackage(NewFun newObjFun) { static PikaObj* __obj_initSubObj(PikaObj* obj, char* name) {
return arg_newObj(newObjFun);
}
static PikaObj* __initObj(PikaObj* obj, char* name) {
PikaObj* res = NULL; PikaObj* res = NULL;
NewFun constructor = (NewFun)getNewClassObjFunByName(obj, name); NewFun constructor = (NewFun)getNewClassObjFunByName(obj, name);
Args buffs = {0}; Args buffs = {0};
@ -428,9 +424,9 @@ static PikaObj* __obj_getObjDirect(PikaObj* self, char* name) {
} }
/* finded object, check type*/ /* finded object, check type*/
ArgType type = args_getType(self->list, name); ArgType type = args_getType(self->list, name);
/* found mate Object */ /* found meta Object */
if (type == ARG_TYPE_OBJECT_MATE) { if (type == ARG_TYPE_OBJECT_META) {
return __initObj(self, name); return __obj_initSubObj(self, name);
} }
/* found Objcet */ /* found Objcet */
if (type == ARG_TYPE_OBJECT || type == ARG_TYPE_OBJECT_FREE) { if (type == ARG_TYPE_OBJECT || type == ARG_TYPE_OBJECT_FREE) {
@ -904,18 +900,18 @@ int32_t obj_newSubObj(PikaObj* self,
char* objName, char* objName,
char* className, char* className,
NewFun newFunPtr) { NewFun newFunPtr) {
Arg* new_obj = arg_newObj(newFunPtr); Arg* new_obj = arg_newDirectObj(newFunPtr);
new_obj = arg_setName(new_obj, objName); new_obj = arg_setName(new_obj, objName);
new_obj = arg_setType(new_obj, ARG_TYPE_OBJECT); new_obj = arg_setType(new_obj, ARG_TYPE_OBJECT);
args_setArg(self->list, new_obj); args_setArg(self->list, new_obj);
return 0; return 0;
} }
int32_t obj_newSubObjByMate(PikaObj* self, int32_t obj_newSubObjByMeta(PikaObj* self,
char* objName, char* objName,
char* className, char* className,
NewFun newFunPtr) { NewFun newFunPtr) {
/* add mate Obj, no inited */ /* add meta Obj, no inited */
Arg* new_obj = arg_newMetaObj(newFunPtr); Arg* new_obj = arg_newMetaObj(newFunPtr);
new_obj = arg_setName(new_obj, objName); new_obj = arg_setName(new_obj, objName);
args_setArg(self->list, new_obj); args_setArg(self->list, new_obj);
@ -926,5 +922,5 @@ int32_t obj_newObj(PikaObj* self,
char* objName, char* objName,
char* className, char* className,
NewFun newFunPtr) { NewFun newFunPtr) {
return obj_newSubObjByMate(self, objName, className, newFunPtr); return obj_newSubObjByMeta(self, objName, className, newFunPtr);
} }

View File

@ -223,7 +223,6 @@ void obj_shellLineProcess(PikaObj* self,
int pikaCompile(char* output_file_name, char* py_lines); int pikaCompile(char* output_file_name, char* py_lines);
Method obj_getNativeMethod(PikaObj* self, char* method_name); Method obj_getNativeMethod(PikaObj* self, char* method_name);
void obj_runNativeMethod(PikaObj* self, char* method_name, Args* args); void obj_runNativeMethod(PikaObj* self, char* method_name, Args* args);
Arg* arg_newObj(NewFun newObjFun);
Arg* obj_newObjInPackage(NewFun newObjFun); Arg* obj_newObjInPackage(NewFun newObjFun);
void obj_refcntInc(PikaObj* self); void obj_refcntInc(PikaObj* self);

View File

@ -367,7 +367,7 @@ static Arg* VM_instruction_handler_RUN(PikaObj* self, VMState* vs, char* data) {
VMState_runMethodArg(vs, method_host_obj, sub_locals, method_arg); VMState_runMethodArg(vs, method_host_obj, sub_locals, method_arg);
/* __init__() */ /* __init__() */
if (arg_getType(return_arg) == ARG_TYPE_OBJECT_FREE) { if (ARG_TYPE_OBJECT_FREE == arg_getType(return_arg)) {
/* init object */ /* init object */
PikaObj* new_obj = arg_getPtr(return_arg); PikaObj* new_obj = arg_getPtr(return_arg);
Arg* method_arg = obj_getMethodArg(new_obj, "__init__"); Arg* method_arg = obj_getMethodArg(new_obj, "__init__");
@ -504,7 +504,7 @@ static Arg* VM_instruction_handler_OUT(PikaObj* self, VMState* vs, char* data) {
/* ouput arg to locals */ /* ouput arg to locals */
obj_setArg_noCopy(hostObj, data, outArg); obj_setArg_noCopy(hostObj, data, outArg);
if (ARG_TYPE_OBJECT_MATE == outArg_type) { if (ARG_TYPE_OBJECT_META == outArg_type) {
/* found a mate_object */ /* found a mate_object */
/* init object */ /* init object */
PikaObj* new_obj = obj_getObj(hostObj, data); PikaObj* new_obj = obj_getObj(hostObj, data);
@ -1333,7 +1333,7 @@ void VMState_solveUnusedStack(VMState* vs) {
arg_deinit(arg); arg_deinit(arg);
continue; continue;
} }
if (type == ARG_TYPE_OBJECT_FREE) { if (ARG_TYPE_OBJECT_FREE == type) {
obj_deinit(arg_getPtr(arg)); obj_deinit(arg_getPtr(arg));
arg_deinit(arg); arg_deinit(arg);
continue; continue;

View File

@ -42,7 +42,7 @@ typedef enum {
ARG_TYPE_BYTES, ARG_TYPE_BYTES,
ARG_TYPE_POINTER, ARG_TYPE_POINTER,
ARG_TYPE_OBJECT, ARG_TYPE_OBJECT,
ARG_TYPE_OBJECT_MATE, ARG_TYPE_OBJECT_META,
ARG_TYPE_OBJECT_FREE, ARG_TYPE_OBJECT_FREE,
ARG_TYPE_METHOD_NATIVE, ARG_TYPE_METHOD_NATIVE,
ARG_TYPE_METHOD_NATIVE_CONSTRUCTOR, ARG_TYPE_METHOD_NATIVE_CONSTRUCTOR,