mirror of
https://gitee.com/Lyon1998/pikapython.git
synced 2025-01-15 17:02:53 +08:00
debug obj run
This commit is contained in:
parent
3ffa044c06
commit
88471a15e7
@ -60,10 +60,10 @@ int32_t main()
|
||||
fgets(inputBuff, sizeof(inputBuff), stdin);
|
||||
|
||||
/* run PikaScript and get res */
|
||||
Args *resArgs = obj_runDirect(root, inputBuff);
|
||||
PikaObj *globals = obj_runDirect(root, inputBuff);
|
||||
|
||||
/* get system output of PikaScript*/
|
||||
char *sysOut = args_getSysOut(resArgs);;
|
||||
char *sysOut = args_getSysOut(globals->attributeList);
|
||||
|
||||
if (NULL != sysOut)
|
||||
{
|
||||
@ -72,6 +72,6 @@ int32_t main()
|
||||
}
|
||||
|
||||
/* deinit the res */
|
||||
args_deinit(resArgs);
|
||||
obj_deinit(globals);
|
||||
}
|
||||
}
|
||||
|
@ -57,10 +57,10 @@ int32_t main()
|
||||
fgets(inputBuff, sizeof(inputBuff), stdin);
|
||||
|
||||
/* run PikaScript and get res */
|
||||
Args *resArgs = obj_runDirect(root, inputBuff);
|
||||
PikaObj *globals = obj_runDirect(root, inputBuff);
|
||||
|
||||
/* get system output of PikaScript*/
|
||||
char *sysOut = args_getSysOut(resArgs);;
|
||||
char *sysOut = args_getSysOut(globals->attributeList);;
|
||||
|
||||
if (NULL != sysOut)
|
||||
{
|
||||
@ -69,6 +69,6 @@ int32_t main()
|
||||
}
|
||||
|
||||
/* deinit the res */
|
||||
args_deinit(resArgs);
|
||||
obj_deinit(globals);
|
||||
}
|
||||
}
|
||||
|
@ -55,10 +55,10 @@ int32_t main()
|
||||
fgets(inputBuff, sizeof(inputBuff), stdin);
|
||||
|
||||
/* run PikaScript and get res */
|
||||
Args *resArgs = obj_runDirect(root, inputBuff);
|
||||
PikaObj *globals = obj_runDirect(root, inputBuff);
|
||||
|
||||
/* get system output of PikaScript*/
|
||||
char *sysOut = args_getSysOut(resArgs);;
|
||||
char *sysOut = args_getSysOut(globals->attributeList);;
|
||||
|
||||
if (NULL != sysOut)
|
||||
{
|
||||
@ -67,6 +67,6 @@ int32_t main()
|
||||
}
|
||||
|
||||
/* deinit the res */
|
||||
args_deinit(resArgs);
|
||||
obj_deinit(globals);
|
||||
}
|
||||
}
|
||||
|
@ -110,10 +110,10 @@ int32_t main()
|
||||
fgets(inputBuff, sizeof(inputBuff), stdin);
|
||||
|
||||
/* run PikaScript and get res */
|
||||
Args *resArgs = obj_runDirect(root, inputBuff);
|
||||
PikaObj *globals = obj_runDirect(root, inputBuff);
|
||||
|
||||
/* get system output of PikaScript*/
|
||||
char *sysOut = args_getSysOut(resArgs);;
|
||||
char *sysOut = args_getSysOut(globals->attributeList);;
|
||||
|
||||
if (NULL != sysOut)
|
||||
{
|
||||
@ -122,6 +122,6 @@ int32_t main()
|
||||
}
|
||||
|
||||
/* deinit the res */
|
||||
args_deinit(resArgs);
|
||||
obj_deinit(globals);
|
||||
}
|
||||
}
|
||||
|
@ -42,10 +42,10 @@ int main()
|
||||
fgets(inputBuff, sizeof(inputBuff), stdin);
|
||||
|
||||
/* run PikaScript and get res */
|
||||
Args *resArgs = obj_runDirect(root, inputBuff);
|
||||
PikaObj *globals = obj_runDirect(root, inputBuff);
|
||||
|
||||
/* get system output of PikaScript*/
|
||||
char *sysOut = args_getSysOut(resArgs);
|
||||
char *sysOut = args_getSysOut(globals->attributeList);
|
||||
;
|
||||
|
||||
if (!strEqu("", sysOut))
|
||||
@ -56,6 +56,6 @@ int main()
|
||||
printf(">>> ");
|
||||
|
||||
/* deinit the res */
|
||||
args_deinit(resArgs);
|
||||
obj_deinit(globals);
|
||||
}
|
||||
}
|
||||
|
@ -21,10 +21,10 @@ int main()
|
||||
fgets(inputBuff, sizeof(inputBuff), stdin);
|
||||
|
||||
/* run PikaScript and get res */
|
||||
Args *resArgs = obj_runDirect(pikaMain, inputBuff);
|
||||
PikaObj *globals = obj_runDirect(pikaMain, inputBuff);
|
||||
|
||||
/* get system output of PikaScript*/
|
||||
char *sysOut = args_getSysOut(resArgs);
|
||||
char *sysOut = args_getSysOut(globals->attributeList);
|
||||
|
||||
if (!strEqu("", sysOut))
|
||||
{
|
||||
@ -34,6 +34,6 @@ int main()
|
||||
printf(">>> ");
|
||||
|
||||
/* deinit the res */
|
||||
args_deinit(resArgs);
|
||||
obj_deinit(globals);
|
||||
}
|
||||
}
|
||||
|
@ -1,111 +1,111 @@
|
||||
// #include "gtest/gtest.h"
|
||||
// extern "C" {
|
||||
// #include "BaseObj.h"
|
||||
// #include "PikaStdLib_SysObj.h"
|
||||
// #include "TinyObj.h"
|
||||
// }
|
||||
#include "gtest/gtest.h"
|
||||
extern "C" {
|
||||
#include "BaseObj.h"
|
||||
#include "PikaStdLib_SysObj.h"
|
||||
#include "TinyObj.h"
|
||||
}
|
||||
|
||||
// void testFloat(PikaObj* obj, Args* args) {
|
||||
// float val1 = args_getFloat(args, (char*)"val1");
|
||||
// float val2 = args_getFloat(args, (char*)"val2");
|
||||
// int32_t isShow = args_getInt(args, (char*)"isShow");
|
||||
// if (isShow) {
|
||||
// printf("the float val1 is: %f\r\n", val1);
|
||||
// printf("the float val2 is: %f\r\n", val2);
|
||||
// }
|
||||
// method_returnFloat(args, val1 + val2);
|
||||
// }
|
||||
void testFloat(PikaObj* obj, Args* args) {
|
||||
float val1 = args_getFloat(args, (char*)"val1");
|
||||
float val2 = args_getFloat(args, (char*)"val2");
|
||||
int32_t isShow = args_getInt(args, (char*)"isShow");
|
||||
if (isShow) {
|
||||
printf("the float val1 is: %f\r\n", val1);
|
||||
printf("the float val2 is: %f\r\n", val2);
|
||||
}
|
||||
method_returnFloat(args, val1 + val2);
|
||||
}
|
||||
|
||||
// void hello2(PikaObj* obj, Args* args) {
|
||||
// char* name1 = args_getStr(args, (char*)"name1");
|
||||
// char* name2 = args_getStr(args, (char*)"name2");
|
||||
// char* name3 = args_getStr(args, (char*)"name3");
|
||||
// char* myName = obj_getStr(obj, (char*)"_n");
|
||||
// int32_t isShow = args_getInt(args, (char*)"isShow");
|
||||
// if (isShow) {
|
||||
// printf("hello, %s, %s and %s!\r\n", name1, name2, name3);
|
||||
// printf("my name is %s.\r\n", myName);
|
||||
// }
|
||||
// }
|
||||
void hello2(PikaObj* obj, Args* args) {
|
||||
char* name1 = args_getStr(args, (char*)"name1");
|
||||
char* name2 = args_getStr(args, (char*)"name2");
|
||||
char* name3 = args_getStr(args, (char*)"name3");
|
||||
char* myName = obj_getStr(obj, (char*)"_n");
|
||||
int32_t isShow = args_getInt(args, (char*)"isShow");
|
||||
if (isShow) {
|
||||
printf("hello, %s, %s and %s!\r\n", name1, name2, name3);
|
||||
printf("my name is %s.\r\n", myName);
|
||||
}
|
||||
}
|
||||
|
||||
// void hello(PikaObj* obj, Args* args) {
|
||||
// char* name = args_getStr(args, (char*)"name");
|
||||
// int32_t isShow = args_getInt(args, (char*)"isShow");
|
||||
// if (isShow) {
|
||||
// printf("hello, %s!\r\n", name);
|
||||
// }
|
||||
// }
|
||||
void hello(PikaObj* obj, Args* args) {
|
||||
char* name = args_getStr(args, (char*)"name");
|
||||
int32_t isShow = args_getInt(args, (char*)"isShow");
|
||||
if (isShow) {
|
||||
printf("hello, %s!\r\n", name);
|
||||
}
|
||||
}
|
||||
|
||||
// void add(PikaObj* obj, Args* args) {
|
||||
// int32_t val1 = args_getInt(args, (char*)"val1");
|
||||
// int32_t val2 = args_getInt(args, (char*)"val2");
|
||||
// method_returnInt(args, val1 + val2);
|
||||
// }
|
||||
void add(PikaObj* obj, Args* args) {
|
||||
int32_t val1 = args_getInt(args, (char*)"val1");
|
||||
int32_t val2 = args_getInt(args, (char*)"val2");
|
||||
method_returnInt(args, val1 + val2);
|
||||
}
|
||||
|
||||
// PikaObj* New_PikaObj_test(Args* args) {
|
||||
// PikaObj* self = New_PikaStdLib_SysObj(args);
|
||||
// class_defineMethod(self, (char*)"hello(name:str, isShow:int)", hello);
|
||||
// class_defineMethod(
|
||||
// self, (char*)"hello2(name1:str, name2:str, name3:str, isShow:int)",
|
||||
// hello2);
|
||||
// class_defineMethod(
|
||||
// self, (char*)"testFloat(val1:float, val2:float, isShow:int)->float",
|
||||
// testFloat);
|
||||
// class_defineMethod(self, (char*)"add(val1:int, val2:int)->int", add);
|
||||
// return self;
|
||||
// }
|
||||
PikaObj* New_PikaObj_test(Args* args) {
|
||||
PikaObj* self = New_PikaStdLib_SysObj(args);
|
||||
class_defineMethod(self, (char*)"hello(name:str, isShow:int)", hello);
|
||||
class_defineMethod(
|
||||
self, (char*)"hello2(name1:str, name2:str, name3:str, isShow:int)",
|
||||
hello2);
|
||||
class_defineMethod(
|
||||
self, (char*)"testFloat(val1:float, val2:float, isShow:int)->float",
|
||||
testFloat);
|
||||
class_defineMethod(self, (char*)"add(val1:int, val2:int)->int", add);
|
||||
return self;
|
||||
}
|
||||
|
||||
// void sendMethod(PikaObj* self, Args* args) {
|
||||
// char* data = args_getStr(args, (char*)"data");
|
||||
// /* send to com1 */
|
||||
// printf("[com1]: %s\r\n", data);
|
||||
// }
|
||||
void sendMethod(PikaObj* self, Args* args) {
|
||||
char* data = args_getStr(args, (char*)"data");
|
||||
/* send to com1 */
|
||||
printf("[com1]: %s\r\n", data);
|
||||
}
|
||||
|
||||
// PikaObj* New_USART(Args* args) {
|
||||
// /* Derive from the tiny object class.
|
||||
// Tiny object can not import sub object.
|
||||
// Tiny object is the smallest object. */
|
||||
// PikaObj* self = New_TinyObj(args);
|
||||
PikaObj* New_USART(Args* args) {
|
||||
/* Derive from the tiny object class.
|
||||
Tiny object can not import sub object.
|
||||
Tiny object is the smallest object. */
|
||||
PikaObj* self = New_TinyObj(args);
|
||||
|
||||
// /* bind the method */
|
||||
// class_defineMethod(self, (char*)"send(data:str)", sendMethod);
|
||||
/* bind the method */
|
||||
class_defineMethod(self, (char*)"send(data:str)", sendMethod);
|
||||
|
||||
// /* return the object */
|
||||
// return self;
|
||||
// }
|
||||
/* return the object */
|
||||
return self;
|
||||
}
|
||||
|
||||
// PikaObj* New_MYROOT1(Args* args) {
|
||||
// /* Derive from the base object class .
|
||||
// BaseObj is the smallest object that can
|
||||
// import sub object. */
|
||||
// PikaObj* self = New_BaseObj(args);
|
||||
PikaObj* New_MYROOT1(Args* args) {
|
||||
/* Derive from the base object class .
|
||||
BaseObj is the smallest object that can
|
||||
import sub object. */
|
||||
PikaObj* self = New_BaseObj(args);
|
||||
|
||||
// /* new led object bellow root object */
|
||||
// obj_newObj(self, (char*)"usart", (char*)"USART", (NewFun)New_USART);
|
||||
/* new led object bellow root object */
|
||||
obj_newObj(self, (char*)"usart", (char*)"USART", (NewFun)New_USART);
|
||||
|
||||
// /* return the object */
|
||||
// return self;
|
||||
// }
|
||||
/* return the object */
|
||||
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, 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) {
|
||||
// PikaObj* process = newRootObj((char*)"sys", New_PikaStdLib_SysObj);
|
||||
// float floatTest = 12.231;
|
||||
// obj_bindFloat(process, (char*)"testFloatBind", &floatTest);
|
||||
// EXPECT_TRUE(
|
||||
// strEqu((char*)"12.231000", obj_print(process, (char*)"testFloatBind")));
|
||||
// obj_deinit(process);
|
||||
// EXPECT_EQ(pikaMemNow(), 0);
|
||||
// }
|
||||
TEST(object_test, test1) {
|
||||
PikaObj* process = newRootObj((char*)"sys", New_PikaStdLib_SysObj);
|
||||
float floatTest = 12.231;
|
||||
obj_bindFloat(process, (char*)"testFloatBind", &floatTest);
|
||||
EXPECT_TRUE(
|
||||
strEqu((char*)"12.231000", obj_print(process, (char*)"testFloatBind")));
|
||||
obj_deinit(process);
|
||||
EXPECT_EQ(pikaMemNow(), 0);
|
||||
}
|
||||
|
||||
// TEST(object_test, test2) {
|
||||
// int isShow = 1;
|
||||
|
@ -403,21 +403,14 @@ PIKA_WEAK int __runExtern_contral(PikaObj* self, char* cmd) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
Args* obj_runDirect(PikaObj* self, char* cmd) {
|
||||
Args* sysRes = NULL;
|
||||
PikaObj* obj_runDirect(PikaObj* self, char* cmd) {
|
||||
PikaObj* globals = NULL;
|
||||
|
||||
sysRes = pikaVM_run(self, cmd)->attributeList;
|
||||
globals = pikaVM_run(self, cmd);
|
||||
goto exit;
|
||||
|
||||
exit:
|
||||
/* check res */
|
||||
if (NULL == sysRes) {
|
||||
sysRes = New_args(NULL);
|
||||
args_setErrorCode(sysRes, 0);
|
||||
args_setSysOut(sysRes, "");
|
||||
goto exit;
|
||||
}
|
||||
return sysRes;
|
||||
return globals;
|
||||
}
|
||||
|
||||
int32_t obj_removeArg(PikaObj* self, char* argPath) {
|
||||
@ -473,13 +466,13 @@ exit:
|
||||
|
||||
void obj_runNoRes(PikaObj* slef, char* cmd) {
|
||||
/* unsafe, nothing would happend when error occord */
|
||||
args_deinit(obj_runDirect(slef, cmd));
|
||||
obj_deinit(obj_runDirect(slef, cmd));
|
||||
}
|
||||
|
||||
void obj_run(PikaObj* self, char* cmd) {
|
||||
/* safe, stop when error occord and error info would be print32_t */
|
||||
Args* sysRes = obj_runDirect(self, cmd);
|
||||
args_deinit(sysRes);
|
||||
PikaObj* globals = obj_runDirect(self, cmd);
|
||||
obj_deinit(globals);
|
||||
}
|
||||
|
||||
void obj_setErrorCode(PikaObj* self, int32_t errCode) {
|
||||
|
@ -70,7 +70,7 @@ int32_t class_defineMethod(PikaObj* self,
|
||||
|
||||
void obj_runNoRes(PikaObj* slef, char* cmd);
|
||||
void obj_run(PikaObj* self, char* cmd);
|
||||
Args* obj_runDirect(PikaObj* self, char* cmd);
|
||||
PikaObj* obj_runDirect(PikaObj* self, char* cmd);
|
||||
int32_t obj_removeArg(PikaObj* self, char* argPath);
|
||||
int32_t obj_isArgExist(PikaObj* self, char* argPath);
|
||||
PikaObj* obj_getClassObjByNewFun(PikaObj* self, char* name, NewFun newClassFun);
|
||||
|
Loading…
x
Reference in New Issue
Block a user