mirror of
https://gitee.com/Lyon1998/pikapython.git
synced 2025-01-15 17:02:53 +08:00
args_set can update type
This commit is contained in:
parent
95cfbf6caa
commit
4c6ec93f41
2
port/linux/.vscode/launch.json
vendored
2
port/linux/.vscode/launch.json
vendored
@ -11,7 +11,7 @@
|
|||||||
"program": "${workspaceFolder}/build/test/pikascript_test",
|
"program": "${workspaceFolder}/build/test/pikascript_test",
|
||||||
// "program": "${workspaceFolder}/../build/src/boot/demo06-pikamain/pikascript_demo06-pikamain",
|
// "program": "${workspaceFolder}/../build/src/boot/demo06-pikamain/pikascript_demo06-pikamain",
|
||||||
"args": [
|
"args": [
|
||||||
// "--gtest_filter=stack*"
|
"--gtest_filter=queueObj.currentObj"
|
||||||
// "--gtest_filter=parser*"
|
// "--gtest_filter=parser*"
|
||||||
// "--gtest_filter=VM.Run_add_1_2_3"
|
// "--gtest_filter=VM.Run_add_1_2_3"
|
||||||
// "--gtest_filter=block.ifrun2"
|
// "--gtest_filter=block.ifrun2"
|
||||||
|
@ -87,6 +87,16 @@ PikaObj* New_MYROOT1(Args* args) {
|
|||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST(object_test, test10) {
|
||||||
|
PikaObj* root = newRootObj((char*)"root", New_MYROOT1);
|
||||||
|
PikaObj* usart = obj_getObj(root, (char*)"usart", 0);
|
||||||
|
PikaObj* context = obj_getContext(usart);
|
||||||
|
EXPECT_EQ(context, root);
|
||||||
|
obj_run(root, (char*)"usart.send('hello world')");
|
||||||
|
obj_deinit(root);
|
||||||
|
EXPECT_EQ(pikaMemNow(), 0);
|
||||||
|
}
|
||||||
|
|
||||||
TEST(object_test, test1) {
|
TEST(object_test, test1) {
|
||||||
PikaObj* process = newRootObj((char*)"sys", PikaStdLib_SysObj);
|
PikaObj* process = newRootObj((char*)"sys", PikaStdLib_SysObj);
|
||||||
float floatTest = 12.231;
|
float floatTest = 12.231;
|
||||||
@ -166,13 +176,6 @@ TEST(object_test, test9) {
|
|||||||
EXPECT_EQ(pikaMemNow(), 0);
|
EXPECT_EQ(pikaMemNow(), 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(object_test, test10) {
|
|
||||||
PikaObj* root = newRootObj((char*)"root", New_MYROOT1);
|
|
||||||
obj_run(root, (char*)"usart.send('hello world')");
|
|
||||||
obj_deinit(root);
|
|
||||||
EXPECT_EQ(pikaMemNow(), 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST(object_test, noMethod) {
|
TEST(object_test, noMethod) {
|
||||||
PikaObj* root = newRootObj((char*)"root", New_MYROOT1);
|
PikaObj* root = newRootObj((char*)"root", New_MYROOT1);
|
||||||
obj_runNoRes(root, (char*)"noDefindMethod()");
|
obj_runNoRes(root, (char*)"noDefindMethod()");
|
||||||
|
@ -133,6 +133,8 @@ TEST(queueObj, currentObj) {
|
|||||||
queueObj_init(q);
|
queueObj_init(q);
|
||||||
|
|
||||||
queueObj_pushObj(q, (char*)"type1");
|
queueObj_pushObj(q, (char*)"type1");
|
||||||
|
PikaObj* currentObj = queueObj_getCurrentObj(q);
|
||||||
|
char* type = args_getType(q->attributeList, (char*)"0");
|
||||||
obj_setInt(queueObj_getCurrentObj(q), (char*)"test", 1);
|
obj_setInt(queueObj_getCurrentObj(q), (char*)"test", 1);
|
||||||
|
|
||||||
queueObj_pushObj(q, (char*)"type2");
|
queueObj_pushObj(q, (char*)"type2");
|
||||||
|
@ -15,24 +15,7 @@ static void* getClassPtr(PikaObj* classObj, char* classPath) {
|
|||||||
return obj_getPtr(classObj, ptrPath);
|
return obj_getPtr(classObj, ptrPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t obj_newObj(PikaObj* self,
|
Arg* arg_setMetaObj(char* objName, char* className, NewFun objPtr) {
|
||||||
char* objName,
|
|
||||||
char* className,
|
|
||||||
NewFun newFunPtr) {
|
|
||||||
/* class means subprocess init */
|
|
||||||
Args* buffs = New_strBuff();
|
|
||||||
|
|
||||||
/* class means subprocess init */
|
|
||||||
char* mataObjName = strsAppend(buffs, "[mate]", objName);
|
|
||||||
obj_setPtr(self, mataObjName, newFunPtr);
|
|
||||||
/* add void process Ptr, no inited */
|
|
||||||
args_setObjectWithClass(self->attributeList, objName, className, NULL);
|
|
||||||
|
|
||||||
args_deinit(buffs);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
Arg* arg_setMetaObj(char* objName, char* className, void* objPtr) {
|
|
||||||
Args* buffs = New_strBuff();
|
Args* buffs = New_strBuff();
|
||||||
char* typeWithClass = strsAppend(buffs, "_class-[mate]", className);
|
char* typeWithClass = strsAppend(buffs, "_class-[mate]", className);
|
||||||
Arg* argNew = New_arg(NULL);
|
Arg* argNew = New_arg(NULL);
|
||||||
@ -41,6 +24,20 @@ Arg* arg_setMetaObj(char* objName, char* className, void* objPtr) {
|
|||||||
return argNew;
|
return argNew;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int32_t obj_newObj(PikaObj* self,
|
||||||
|
char* objName,
|
||||||
|
char* className,
|
||||||
|
NewFun newFunPtr) {
|
||||||
|
/* class means subprocess init */
|
||||||
|
|
||||||
|
/* add mate Obj, no inited */
|
||||||
|
Arg* mateObj = arg_setMetaObj(objName, className, newFunPtr);
|
||||||
|
NewFun newFunInMate = arg_getPtr(mateObj);
|
||||||
|
args_setArg(self->attributeList, mateObj);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static void print(PikaObj* self, Args* args) {
|
static void print(PikaObj* self, Args* args) {
|
||||||
obj_setErrorCode(self, 0);
|
obj_setErrorCode(self, 0);
|
||||||
char* res = args_print(args, "val");
|
char* res = args_print(args, "val");
|
||||||
@ -53,7 +50,6 @@ static void print(PikaObj* self, Args* args) {
|
|||||||
obj_setSysOut(self, res);
|
obj_setSysOut(self, res);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
PikaObj* BaseObj(Args* args) {
|
PikaObj* BaseObj(Args* args) {
|
||||||
PikaObj* self = TinyObj(args);
|
PikaObj* self = TinyObj(args);
|
||||||
class_defineMethod(self, "print(val:any)", print);
|
class_defineMethod(self, "print(val:any)", print);
|
||||||
|
@ -18,4 +18,5 @@ int32_t obj_newObj(PikaObj* self,
|
|||||||
char* objName,
|
char* objName,
|
||||||
char* className,
|
char* className,
|
||||||
NewFun newFunPtr);
|
NewFun newFunPtr);
|
||||||
|
Arg* arg_setMetaObj(char* objName, char* className, NewFun objPtr);
|
||||||
#endif
|
#endif
|
||||||
|
@ -190,17 +190,6 @@ int32_t obj_load(PikaObj* self, Args* args, char* name) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t obj_setObjWithoutClass(PikaObj* self, char* objName, void* newFun) {
|
|
||||||
/* class means subprocess init */
|
|
||||||
Args* buffs = New_strBuff();
|
|
||||||
char* mataObjName = strsAppend(buffs, "[mate]", objName);
|
|
||||||
obj_setPtr(self, mataObjName, newFun);
|
|
||||||
/* add void object Ptr, no inited */
|
|
||||||
args_setObjectWithClass(self->attributeList, objName, "none", NULL);
|
|
||||||
args_deinit(buffs);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int32_t obj_addOther(PikaObj* self, char* subObjectName, void* new_ObjectFun) {
|
int32_t obj_addOther(PikaObj* self, char* subObjectName, void* new_ObjectFun) {
|
||||||
Args* initArgs = New_args(NULL);
|
Args* initArgs = New_args(NULL);
|
||||||
args_setPtr(initArgs, "_ctx", self);
|
args_setPtr(initArgs, "_ctx", self);
|
||||||
@ -264,12 +253,10 @@ char* obj_getClassPath(PikaObj* objHost, Args* buffs, char* objName) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void* getNewClassObjFunByName(PikaObj* obj, char* name) {
|
void* getNewClassObjFunByName(PikaObj* obj, char* name) {
|
||||||
Args* buffs = New_strBuff();
|
char* classPath = name;
|
||||||
char* classPath = strsAppend(buffs, "[mate]", name);
|
|
||||||
/* init the subprocess */
|
/* init the subprocess */
|
||||||
void* (*newClassObjFun)(Args * initArgs) =
|
void* (*newClassObjFun)(Args * initArgs) =
|
||||||
args_getPtr(obj->attributeList, classPath);
|
args_getPtr(obj->attributeList, classPath);
|
||||||
args_deinit(buffs);
|
|
||||||
return newClassObjFun;
|
return newClassObjFun;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -291,14 +278,6 @@ PikaObj* removeMethodInfo(PikaObj* thisClass) {
|
|||||||
return thisClass;
|
return thisClass;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void removeClassLoader(PikaObj* obj) {
|
|
||||||
PikaObj* classLoader = args_getPtr(obj->attributeList, "_clsld");
|
|
||||||
if (NULL != classLoader) {
|
|
||||||
obj_deinit(classLoader);
|
|
||||||
args_removeArg(obj->attributeList, "_clsld");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
PikaObj* newRootObj(char* name, NewFun newObjFun) {
|
PikaObj* newRootObj(char* name, NewFun newObjFun) {
|
||||||
PikaObj* thisClass = obj_getClassObjByNewFun(NULL, name, newObjFun);
|
PikaObj* thisClass = obj_getClassObjByNewFun(NULL, name, newObjFun);
|
||||||
PikaObj* newObj = removeMethodInfo(thisClass);
|
PikaObj* newObj = removeMethodInfo(thisClass);
|
||||||
@ -316,13 +295,11 @@ PikaObj* initObj(PikaObj* obj, char* name) {
|
|||||||
}
|
}
|
||||||
PikaObj* thisClass = obj_getClassObjByNewFun(obj, name, newObjFun);
|
PikaObj* thisClass = obj_getClassObjByNewFun(obj, name, newObjFun);
|
||||||
PikaObj* newObj = removeMethodInfo(thisClass);
|
PikaObj* newObj = removeMethodInfo(thisClass);
|
||||||
/* delete [mate]<objName> */
|
|
||||||
obj_removeArg(obj, strsAppend(buffs, "[mate]", name));
|
|
||||||
/* delete "_clsld" object */
|
|
||||||
removeClassLoader(newObj);
|
|
||||||
|
|
||||||
char* type = args_getType(obj->attributeList, name);
|
char* mateObjType = args_getType(obj->attributeList, name);
|
||||||
args_setPtrWithType(obj->attributeList, name, type, newObj);
|
char* pureType = strsGetLastToken(buffs, mateObjType, ']');
|
||||||
|
char* objType = strsAppend(buffs, "_class-", pureType);
|
||||||
|
args_setPtrWithType(obj->attributeList, name, objType, newObj);
|
||||||
res = obj_getPtr(obj, name);
|
res = obj_getPtr(obj, name);
|
||||||
goto exit;
|
goto exit;
|
||||||
exit:
|
exit:
|
||||||
@ -334,19 +311,16 @@ PikaObj* obj_getObjDirect(PikaObj* self, char* name) {
|
|||||||
if (NULL == self) {
|
if (NULL == self) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
/* finded object, check type*/
|
||||||
/* check subprocess */
|
|
||||||
if (NULL == args_getPtr(self->attributeList, name)) {
|
|
||||||
/* no inited subprocess, check subprocess init fun*/
|
|
||||||
return initObj(self, name);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* finded subscribe, check type*/
|
|
||||||
char* type = args_getType(self->attributeList, name);
|
char* type = args_getType(self->attributeList, name);
|
||||||
if (!strIsStartWith(type, "_class")) {
|
if (!strIsStartWith(type, "_class")) {
|
||||||
/* type error, could not found subprocess */
|
/* type error, could not found subprocess */
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
/* found mate Object */
|
||||||
|
if (strIsStartWith(type, "_class-[mate]")) {
|
||||||
|
return initObj(self, name);
|
||||||
|
}
|
||||||
return obj_getPtr(self, name);
|
return obj_getPtr(self, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -159,6 +159,7 @@ int32_t updateArg(Args* self, Arg* argNew) {
|
|||||||
nodeToUpdate = arg_setContent(nodeToUpdate, arg_getContent(argNew),
|
nodeToUpdate = arg_setContent(nodeToUpdate, arg_getContent(argNew),
|
||||||
arg_getContentSize(argNew));
|
arg_getContentSize(argNew));
|
||||||
|
|
||||||
|
nodeToUpdate = arg_setType(nodeToUpdate, arg_getType(argNew));
|
||||||
// update privior link, because arg_getContent would free origin pointer
|
// update privior link, because arg_getContent would free origin pointer
|
||||||
if (NULL == priorNode) {
|
if (NULL == priorNode) {
|
||||||
self->firstNode = nodeToUpdate;
|
self->firstNode = nodeToUpdate;
|
||||||
@ -339,17 +340,6 @@ int32_t args_setPtrWithType(Args* self, char* name, char* type, void* objPtr) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t args_setObjectWithClass(Args* self,
|
|
||||||
char* objName,
|
|
||||||
char* className,
|
|
||||||
void* objPtr) {
|
|
||||||
Args* buffs = New_strBuff();
|
|
||||||
char* typeWithClass = strsAppend(buffs, "_class-", className);
|
|
||||||
args_setPtrWithType(self, objName, typeWithClass, objPtr);
|
|
||||||
args_deinit(buffs);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int32_t args_foreach(Args* self,
|
int32_t args_foreach(Args* self,
|
||||||
int32_t (*eachHandle)(Arg* argEach, Args* handleArgs),
|
int32_t (*eachHandle)(Arg* argEach, Args* handleArgs),
|
||||||
Args* handleArgs) {
|
Args* handleArgs) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user