mirror of
https://gitee.com/Lyon1998/pikapython.git
synced 2025-01-15 17:02:53 +08:00
keep both meta obj and direct obj, meta obj cannot init with arg
This commit is contained in:
parent
ceb8de7c81
commit
5cbe98d212
@ -41,8 +41,8 @@ void PikaStdLib_SysObj_type(PikaObj* self, Arg* arg) {
|
||||
obj_setSysOut(self, "<class 'object'>");
|
||||
return;
|
||||
}
|
||||
if (ARG_TYPE_OBJECT_MATE == type) {
|
||||
obj_setSysOut(self, "<class 'mate object'>");
|
||||
if (ARG_TYPE_OBJECT_META == type) {
|
||||
obj_setSysOut(self, "<class 'meta object'>");
|
||||
return;
|
||||
}
|
||||
if (ARG_TYPE_METHOD_NATIVE == type) {
|
||||
@ -116,7 +116,7 @@ Arg* PikaStdLib_SysObj_iter(PikaObj* self, Arg* arg) {
|
||||
return arg_newMetaObj(New_PikaStdLib_StringObj);
|
||||
}
|
||||
/* 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);
|
||||
}
|
||||
/* object */
|
||||
|
@ -41,8 +41,8 @@ void PikaStdLib_SysObj_type(PikaObj* self, Arg* arg) {
|
||||
obj_setSysOut(self, "<class 'object'>");
|
||||
return;
|
||||
}
|
||||
if (ARG_TYPE_OBJECT_MATE == type) {
|
||||
obj_setSysOut(self, "<class 'mate object'>");
|
||||
if (ARG_TYPE_OBJECT_META == type) {
|
||||
obj_setSysOut(self, "<class 'meta object'>");
|
||||
return;
|
||||
}
|
||||
if (ARG_TYPE_METHOD_NATIVE == type) {
|
||||
@ -116,7 +116,7 @@ Arg* PikaStdLib_SysObj_iter(PikaObj* self, Arg* arg) {
|
||||
return arg_newMetaObj(New_PikaStdLib_StringObj);
|
||||
}
|
||||
/* 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);
|
||||
}
|
||||
/* object */
|
||||
|
@ -379,28 +379,24 @@ Arg* obj_getRefArg(PikaObj* self) {
|
||||
return arg_setPtr(NULL, "", ARG_TYPE_OBJECT_FREE, self);
|
||||
}
|
||||
|
||||
Arg* arg_newMetaObj(NewFun objPtr) {
|
||||
Arg* argNew = New_arg(NULL);
|
||||
/* m means mate-object */
|
||||
argNew = arg_setPtr(argNew, "", ARG_TYPE_OBJECT_MATE, (void*)objPtr);
|
||||
return argNew;
|
||||
Arg* arg_newMetaObj(NewFun new_obj_fun) {
|
||||
Arg* arg_new = New_arg(NULL);
|
||||
/* m means meta-object */
|
||||
arg_new = arg_setPtr(arg_new, "", ARG_TYPE_OBJECT_META, (void*)new_obj_fun);
|
||||
return arg_new;
|
||||
}
|
||||
|
||||
Arg* arg_newDirectObj(NewFun newObjFun) {
|
||||
PikaObj* newObj = NewObjDirect(newObjFun);
|
||||
Arg* objArg = arg_setPtr(NULL, "", ARG_TYPE_OBJECT_FREE, newObj);
|
||||
return objArg;
|
||||
Arg* arg_newDirectObj(NewFun new_obj_fun) {
|
||||
PikaObj* newObj = NewObjDirect(new_obj_fun);
|
||||
Arg* arg_new = arg_setPtr(NULL, "", ARG_TYPE_OBJECT_FREE, newObj);
|
||||
return arg_new;
|
||||
}
|
||||
|
||||
Arg* arg_newObj(NewFun newObjFun) {
|
||||
return arg_newDirectObj(newObjFun);
|
||||
Arg* obj_newObjInPackage(NewFun new_obj_fun) {
|
||||
return arg_newDirectObj(new_obj_fun);
|
||||
}
|
||||
|
||||
Arg* obj_newObjInPackage(NewFun newObjFun) {
|
||||
return arg_newObj(newObjFun);
|
||||
}
|
||||
|
||||
static PikaObj* __initObj(PikaObj* obj, char* name) {
|
||||
static PikaObj* __obj_initSubObj(PikaObj* obj, char* name) {
|
||||
PikaObj* res = NULL;
|
||||
NewFun constructor = (NewFun)getNewClassObjFunByName(obj, name);
|
||||
Args buffs = {0};
|
||||
@ -428,9 +424,9 @@ static PikaObj* __obj_getObjDirect(PikaObj* self, char* name) {
|
||||
}
|
||||
/* finded object, check type*/
|
||||
ArgType type = args_getType(self->list, name);
|
||||
/* found mate Object */
|
||||
if (type == ARG_TYPE_OBJECT_MATE) {
|
||||
return __initObj(self, name);
|
||||
/* found meta Object */
|
||||
if (type == ARG_TYPE_OBJECT_META) {
|
||||
return __obj_initSubObj(self, name);
|
||||
}
|
||||
/* found Objcet */
|
||||
if (type == ARG_TYPE_OBJECT || type == ARG_TYPE_OBJECT_FREE) {
|
||||
@ -904,18 +900,18 @@ int32_t obj_newSubObj(PikaObj* self,
|
||||
char* objName,
|
||||
char* className,
|
||||
NewFun newFunPtr) {
|
||||
Arg* new_obj = arg_newObj(newFunPtr);
|
||||
Arg* new_obj = arg_newDirectObj(newFunPtr);
|
||||
new_obj = arg_setName(new_obj, objName);
|
||||
new_obj = arg_setType(new_obj, ARG_TYPE_OBJECT);
|
||||
args_setArg(self->list, new_obj);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t obj_newSubObjByMate(PikaObj* self,
|
||||
int32_t obj_newSubObjByMeta(PikaObj* self,
|
||||
char* objName,
|
||||
char* className,
|
||||
NewFun newFunPtr) {
|
||||
/* add mate Obj, no inited */
|
||||
/* add meta Obj, no inited */
|
||||
Arg* new_obj = arg_newMetaObj(newFunPtr);
|
||||
new_obj = arg_setName(new_obj, objName);
|
||||
args_setArg(self->list, new_obj);
|
||||
@ -926,5 +922,5 @@ int32_t obj_newObj(PikaObj* self,
|
||||
char* objName,
|
||||
char* className,
|
||||
NewFun newFunPtr) {
|
||||
return obj_newSubObjByMate(self, objName, className, newFunPtr);
|
||||
return obj_newSubObjByMeta(self, objName, className, newFunPtr);
|
||||
}
|
||||
|
@ -223,7 +223,6 @@ void obj_shellLineProcess(PikaObj* self,
|
||||
int pikaCompile(char* output_file_name, char* py_lines);
|
||||
Method obj_getNativeMethod(PikaObj* self, char* method_name);
|
||||
void obj_runNativeMethod(PikaObj* self, char* method_name, Args* args);
|
||||
Arg* arg_newObj(NewFun newObjFun);
|
||||
Arg* obj_newObjInPackage(NewFun newObjFun);
|
||||
|
||||
void obj_refcntInc(PikaObj* self);
|
||||
|
@ -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);
|
||||
|
||||
/* __init__() */
|
||||
if (arg_getType(return_arg) == ARG_TYPE_OBJECT_FREE) {
|
||||
if (ARG_TYPE_OBJECT_FREE == arg_getType(return_arg)) {
|
||||
/* init object */
|
||||
PikaObj* new_obj = arg_getPtr(return_arg);
|
||||
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 */
|
||||
obj_setArg_noCopy(hostObj, data, outArg);
|
||||
if (ARG_TYPE_OBJECT_MATE == outArg_type) {
|
||||
if (ARG_TYPE_OBJECT_META == outArg_type) {
|
||||
/* found a mate_object */
|
||||
/* init object */
|
||||
PikaObj* new_obj = obj_getObj(hostObj, data);
|
||||
@ -1333,7 +1333,7 @@ void VMState_solveUnusedStack(VMState* vs) {
|
||||
arg_deinit(arg);
|
||||
continue;
|
||||
}
|
||||
if (type == ARG_TYPE_OBJECT_FREE) {
|
||||
if (ARG_TYPE_OBJECT_FREE == type) {
|
||||
obj_deinit(arg_getPtr(arg));
|
||||
arg_deinit(arg);
|
||||
continue;
|
||||
|
@ -42,7 +42,7 @@ typedef enum {
|
||||
ARG_TYPE_BYTES,
|
||||
ARG_TYPE_POINTER,
|
||||
ARG_TYPE_OBJECT,
|
||||
ARG_TYPE_OBJECT_MATE,
|
||||
ARG_TYPE_OBJECT_META,
|
||||
ARG_TYPE_OBJECT_FREE,
|
||||
ARG_TYPE_METHOD_NATIVE,
|
||||
ARG_TYPE_METHOD_NATIVE_CONSTRUCTOR,
|
||||
|
Loading…
x
Reference in New Issue
Block a user