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