mirror of
https://gitee.com/Lyon1998/pikapython.git
synced 2025-01-15 17:02:53 +08:00
rename globalArgs to globals
This commit is contained in:
parent
3878bb23fd
commit
3ffa044c06
@ -17,10 +17,10 @@ TEST(VM, num1) {
|
||||
char* pikaAsm = pikaParseLineToAsm(buffs, line, NULL);
|
||||
printf("%s", pikaAsm);
|
||||
PikaObj* self = newRootObj((char*)"root", New_PikaStdLib_SysObj);
|
||||
PikaObj* globalArgs = pikaVM_runAsm(self, pikaAsm);
|
||||
PikaObj* globals = pikaVM_runAsm(self, pikaAsm);
|
||||
obj_deinit(self);
|
||||
args_deinit(buffs);
|
||||
obj_deinit(globalArgs);
|
||||
obj_deinit(globals);
|
||||
EXPECT_EQ(pikaMemNow(), 0);
|
||||
}
|
||||
|
||||
@ -30,11 +30,11 @@ TEST(VM, a_1) {
|
||||
char* pikaAsm = pikaParseLineToAsm(buffs, line, NULL);
|
||||
printf("%s", pikaAsm);
|
||||
PikaObj* self = newRootObj((char*)"root", New_PikaStdLib_SysObj);
|
||||
PikaObj* globalArgs = pikaVM_runAsm(self, pikaAsm);
|
||||
ASSERT_EQ(args_getInt(globalArgs->attributeList, (char*)"a"), 1);
|
||||
PikaObj* globals = pikaVM_runAsm(self, pikaAsm);
|
||||
ASSERT_EQ(args_getInt(globals->attributeList, (char*)"a"), 1);
|
||||
|
||||
obj_deinit(self);
|
||||
obj_deinit(globalArgs);
|
||||
obj_deinit(globals);
|
||||
args_deinit(buffs);
|
||||
EXPECT_EQ(pikaMemNow(), 0);
|
||||
}
|
||||
@ -45,11 +45,11 @@ TEST(VM, a_1d1) {
|
||||
char* pikaAsm = pikaParseLineToAsm(buffs, line, NULL);
|
||||
printf("%s", pikaAsm);
|
||||
PikaObj* self = newRootObj((char*)"root", New_PikaStdLib_SysObj);
|
||||
PikaObj* globalArgs = pikaVM_runAsm(self, pikaAsm);
|
||||
ASSERT_FLOAT_EQ(args_getFloat(globalArgs->attributeList, (char*)"a"), 1.1);
|
||||
PikaObj* globals = pikaVM_runAsm(self, pikaAsm);
|
||||
ASSERT_FLOAT_EQ(args_getFloat(globals->attributeList, (char*)"a"), 1.1);
|
||||
|
||||
obj_deinit(self);
|
||||
obj_deinit(globalArgs);
|
||||
obj_deinit(globals);
|
||||
args_deinit(buffs);
|
||||
EXPECT_EQ(pikaMemNow(), 0);
|
||||
}
|
||||
@ -60,13 +60,13 @@ TEST(VM, str_xy) {
|
||||
char* pikaAsm = pikaParseLineToAsm(buffs, line, NULL);
|
||||
printf("%s", pikaAsm);
|
||||
PikaObj* self = newRootObj((char*)"root", New_PikaStdLib_SysObj);
|
||||
PikaObj* globalArgs = pikaVM_runAsm(self, pikaAsm);
|
||||
PikaObj* globals = pikaVM_runAsm(self, pikaAsm);
|
||||
|
||||
ASSERT_STREQ(args_getStr(globalArgs->attributeList, (char*)"a"),
|
||||
ASSERT_STREQ(args_getStr(globals->attributeList, (char*)"a"),
|
||||
(char*)"xy");
|
||||
|
||||
obj_deinit(self);
|
||||
obj_deinit(globalArgs);
|
||||
obj_deinit(globals);
|
||||
args_deinit(buffs);
|
||||
EXPECT_EQ(pikaMemNow(), 0);
|
||||
}
|
||||
@ -77,14 +77,14 @@ TEST(VM, str_xy_space) {
|
||||
char* pikaAsm = pikaParseLineToAsm(buffs, line, NULL);
|
||||
printf("%s", pikaAsm);
|
||||
PikaObj* self = newRootObj((char*)"root", New_PikaStdLib_SysObj);
|
||||
PikaObj* globalArgs = pikaVM_runAsm(self, pikaAsm);
|
||||
PikaObj* globals = pikaVM_runAsm(self, pikaAsm);
|
||||
|
||||
ASSERT_STREQ(args_getStr(globalArgs->attributeList, (char*)"a"),
|
||||
ASSERT_STREQ(args_getStr(globals->attributeList, (char*)"a"),
|
||||
(char*)"xy ");
|
||||
|
||||
obj_deinit(self);
|
||||
args_deinit(buffs);
|
||||
obj_deinit(globalArgs);
|
||||
obj_deinit(globals);
|
||||
EXPECT_EQ(pikaMemNow(), 0);
|
||||
}
|
||||
|
||||
@ -92,16 +92,16 @@ TEST(VM, ref_a_b) {
|
||||
PikaObj* self = newRootObj((char*)"root", New_PikaStdLib_SysObj);
|
||||
Args* buffs = New_strBuff();
|
||||
|
||||
PikaObj* globalArgs = pikaVM_runAsm(
|
||||
PikaObj* globals = pikaVM_runAsm(
|
||||
self, pikaParseLineToAsm(buffs, (char*)"a = 'xy '", NULL));
|
||||
globalArgs = pikaVM_runAsmWithArgs(
|
||||
self, globalArgs, pikaParseLineToAsm(buffs, (char*)"b = a", NULL));
|
||||
globals = pikaVM_runAsmWithArgs(
|
||||
self, globals, pikaParseLineToAsm(buffs, (char*)"b = a", NULL));
|
||||
|
||||
args_deinit(buffs);
|
||||
ASSERT_STREQ(args_getStr(globalArgs->attributeList, (char*)"b"),
|
||||
ASSERT_STREQ(args_getStr(globals->attributeList, (char*)"b"),
|
||||
(char*)"xy ");
|
||||
obj_deinit(self);
|
||||
obj_deinit(globalArgs);
|
||||
obj_deinit(globals);
|
||||
EXPECT_EQ(pikaMemNow(), 0);
|
||||
}
|
||||
|
||||
@ -109,14 +109,14 @@ TEST(VM, Run_add) {
|
||||
PikaObj* self = newRootObj((char*)"root", New_PikaMath_Operator);
|
||||
Args* buffs = New_strBuff();
|
||||
|
||||
PikaObj* globalArgs = pikaVM_runAsm(
|
||||
PikaObj* globals = pikaVM_runAsm(
|
||||
self, pikaParseLineToAsm(buffs, (char*)"a = plusInt(1,2)", NULL));
|
||||
|
||||
args_deinit(buffs);
|
||||
int a = args_getInt(globalArgs->attributeList, (char*)"a");
|
||||
int a = args_getInt(globals->attributeList, (char*)"a");
|
||||
ASSERT_EQ(a, 3);
|
||||
obj_deinit(self);
|
||||
obj_deinit(globalArgs);
|
||||
obj_deinit(globals);
|
||||
EXPECT_EQ(pikaMemNow(), 0);
|
||||
}
|
||||
|
||||
@ -124,17 +124,17 @@ TEST(VM, Run_add_multy) {
|
||||
PikaObj* self = newRootObj((char*)"root", New_PikaMath_Operator);
|
||||
Args* buffs = New_strBuff();
|
||||
|
||||
PikaObj* globalArgs =
|
||||
PikaObj* globals =
|
||||
pikaVM_runAsm(self, pikaParseLineToAsm(buffs, (char*)"b = 2", NULL));
|
||||
globalArgs = pikaVM_runAsmWithArgs(
|
||||
self, globalArgs,
|
||||
globals = pikaVM_runAsmWithArgs(
|
||||
self, globals,
|
||||
pikaParseLineToAsm(buffs, (char*)"a = plusInt(1,b)", NULL));
|
||||
|
||||
args_deinit(buffs);
|
||||
int a = args_getInt(globalArgs->attributeList, (char*)"a");
|
||||
int a = args_getInt(globals->attributeList, (char*)"a");
|
||||
ASSERT_EQ(a, 3);
|
||||
obj_deinit(self);
|
||||
obj_deinit(globalArgs);
|
||||
obj_deinit(globals);
|
||||
EXPECT_EQ(pikaMemNow(), 0);
|
||||
}
|
||||
|
||||
@ -142,15 +142,15 @@ TEST(VM, Run_add_1_2_3) {
|
||||
PikaObj* self = newRootObj((char*)"root", New_PikaMath_Operator);
|
||||
Args* buffs = New_strBuff();
|
||||
|
||||
PikaObj* globalArgs = pikaVM_runAsm(
|
||||
PikaObj* globals = pikaVM_runAsm(
|
||||
self, pikaParseLineToAsm(buffs, (char*)"a = plusInt(1, plusInt(2,3) )",
|
||||
NULL));
|
||||
|
||||
args_deinit(buffs);
|
||||
int a = args_getInt(globalArgs->attributeList, (char*)"a");
|
||||
int a = args_getInt(globals->attributeList, (char*)"a");
|
||||
ASSERT_EQ(a, 6);
|
||||
obj_deinit(self);
|
||||
obj_deinit(globalArgs);
|
||||
obj_deinit(globals);
|
||||
EXPECT_EQ(pikaMemNow(), 0);
|
||||
}
|
||||
|
||||
@ -167,14 +167,14 @@ TEST(VM, JEZ) {
|
||||
Args* sysRes = New_args(NULL);
|
||||
args_setErrorCode(sysRes, 0);
|
||||
args_setSysOut(sysRes, (char*)"");
|
||||
PikaObj* globalArgs = New_TinyObj(NULL);
|
||||
lineAddr = pikaVM_runAsmLine(self, globalArgs, pikaAsm, lineAddr);
|
||||
lineAddr = pikaVM_runAsmLine(self, globalArgs, pikaAsm, lineAddr);
|
||||
lineAddr = pikaVM_runAsmLine(self, globalArgs, pikaAsm, lineAddr);
|
||||
__clearInvokeQueues(globalArgs);
|
||||
PikaObj* globals = New_TinyObj(NULL);
|
||||
lineAddr = pikaVM_runAsmLine(self, globals, pikaAsm, lineAddr);
|
||||
lineAddr = pikaVM_runAsmLine(self, globals, pikaAsm, lineAddr);
|
||||
lineAddr = pikaVM_runAsmLine(self, globals, pikaAsm, lineAddr);
|
||||
__clearInvokeQueues(globals);
|
||||
obj_deinit(self);
|
||||
args_deinit(sysRes);
|
||||
obj_deinit(globalArgs);
|
||||
obj_deinit(globals);
|
||||
EXPECT_EQ(lineAddr, 26);
|
||||
EXPECT_EQ(pikaMemNow(), 0);
|
||||
}
|
||||
@ -191,13 +191,13 @@ TEST(VM, JMP) {
|
||||
Args* sysRes = New_args(NULL);
|
||||
args_setErrorCode(sysRes, 0);
|
||||
args_setSysOut(sysRes, (char*)"");
|
||||
PikaObj* globalArgs = New_TinyObj(NULL);
|
||||
lineAddr = pikaVM_runAsmLine(self, globalArgs, pikaAsm, lineAddr);
|
||||
lineAddr = pikaVM_runAsmLine(self, globalArgs, pikaAsm, lineAddr);
|
||||
__clearInvokeQueues(globalArgs);
|
||||
PikaObj* globals = New_TinyObj(NULL);
|
||||
lineAddr = pikaVM_runAsmLine(self, globals, pikaAsm, lineAddr);
|
||||
lineAddr = pikaVM_runAsmLine(self, globals, pikaAsm, lineAddr);
|
||||
__clearInvokeQueues(globals);
|
||||
obj_deinit(self);
|
||||
args_deinit(sysRes);
|
||||
obj_deinit(globalArgs);
|
||||
obj_deinit(globals);
|
||||
EXPECT_EQ(lineAddr, 14);
|
||||
EXPECT_EQ(pikaMemNow(), 0);
|
||||
}
|
||||
@ -215,14 +215,14 @@ TEST(VM, JMP_back1) {
|
||||
Args* sysRes = New_args(NULL);
|
||||
args_setErrorCode(sysRes, 0);
|
||||
args_setSysOut(sysRes, (char*)"");
|
||||
PikaObj* globalArgs = New_TinyObj(NULL);
|
||||
lineAddr = pikaVM_runAsmLine(self, globalArgs, pikaAsm, lineAddr);
|
||||
lineAddr = pikaVM_runAsmLine(self, globalArgs, pikaAsm, lineAddr);
|
||||
lineAddr = pikaVM_runAsmLine(self, globalArgs, pikaAsm, lineAddr);
|
||||
__clearInvokeQueues(globalArgs);
|
||||
PikaObj* globals = New_TinyObj(NULL);
|
||||
lineAddr = pikaVM_runAsmLine(self, globals, pikaAsm, lineAddr);
|
||||
lineAddr = pikaVM_runAsmLine(self, globals, pikaAsm, lineAddr);
|
||||
lineAddr = pikaVM_runAsmLine(self, globals, pikaAsm, lineAddr);
|
||||
__clearInvokeQueues(globals);
|
||||
obj_deinit(self);
|
||||
args_deinit(sysRes);
|
||||
obj_deinit(globalArgs);
|
||||
obj_deinit(globals);
|
||||
EXPECT_EQ(lineAddr, 0);
|
||||
EXPECT_EQ(pikaMemNow(), 0);
|
||||
}
|
||||
@ -243,10 +243,10 @@ TEST(VM, WHILE) {
|
||||
printf("%s", pikaAsm);
|
||||
pikaMemInfo.heapUsedMax = 0;
|
||||
PikaObj* self = New_TinyObj(NULL);
|
||||
PikaObj* globalArgs = pikaVM_runAsm(self, pikaAsm);
|
||||
EXPECT_EQ(args_getInt(globalArgs->attributeList, (char*)"a"), 0);
|
||||
EXPECT_EQ(args_getInt(globalArgs->attributeList, (char*)"b"), 1);
|
||||
obj_deinit(globalArgs);
|
||||
PikaObj* globals = pikaVM_runAsm(self, pikaAsm);
|
||||
EXPECT_EQ(args_getInt(globals->attributeList, (char*)"a"), 0);
|
||||
EXPECT_EQ(args_getInt(globals->attributeList, (char*)"b"), 1);
|
||||
obj_deinit(globals);
|
||||
args_deinit(buffs);
|
||||
obj_deinit(self);
|
||||
EXPECT_EQ(pikaMemNow(), 0);
|
||||
@ -258,11 +258,11 @@ TEST(VM, a_1_1) {
|
||||
char* pikaAsm = pikaParseLineToAsm(buffs, line, NULL);
|
||||
printf("%s", pikaAsm);
|
||||
PikaObj* self = newRootObj((char*)"root", New_PikaStdLib_SysObj);
|
||||
PikaObj* globalArgs = pikaVM_runAsm(self, pikaAsm);
|
||||
PikaObj* globals = pikaVM_runAsm(self, pikaAsm);
|
||||
|
||||
int res = args_getInt(globalArgs->attributeList, (char*)"a");
|
||||
int res = args_getInt(globals->attributeList, (char*)"a");
|
||||
obj_deinit(self);
|
||||
obj_deinit(globalArgs);
|
||||
obj_deinit(globals);
|
||||
args_deinit(buffs);
|
||||
ASSERT_EQ(res, 2);
|
||||
EXPECT_EQ(pikaMemNow(), 0);
|
||||
@ -274,11 +274,11 @@ TEST(VM, a_1_1d1) {
|
||||
char* pikaAsm = pikaParseLineToAsm(buffs, line, NULL);
|
||||
printf("%s", pikaAsm);
|
||||
PikaObj* self = newRootObj((char*)"root", New_PikaStdLib_SysObj);
|
||||
PikaObj* globalArgs = pikaVM_runAsm(self, pikaAsm);
|
||||
PikaObj* globals = pikaVM_runAsm(self, pikaAsm);
|
||||
|
||||
float res = args_getFloat(globalArgs->attributeList, (char*)"a");
|
||||
float res = args_getFloat(globals->attributeList, (char*)"a");
|
||||
obj_deinit(self);
|
||||
obj_deinit(globalArgs);
|
||||
obj_deinit(globals);
|
||||
args_deinit(buffs);
|
||||
ASSERT_FLOAT_EQ(res, 2.1);
|
||||
EXPECT_EQ(pikaMemNow(), 0);
|
||||
@ -290,12 +290,12 @@ TEST(VM, a_jjcc) {
|
||||
char* pikaAsm = pikaParseLineToAsm(buffs, line, NULL);
|
||||
printf("%s", pikaAsm);
|
||||
PikaObj* self = newRootObj((char*)"root", New_PikaStdLib_SysObj);
|
||||
PikaObj* globalArgs = pikaVM_runAsm(self, pikaAsm);
|
||||
PikaObj* globals = pikaVM_runAsm(self, pikaAsm);
|
||||
|
||||
float res = args_getFloat(globalArgs->attributeList, (char*)"a");
|
||||
float res = args_getFloat(globals->attributeList, (char*)"a");
|
||||
obj_deinit(self);
|
||||
args_deinit(buffs);
|
||||
obj_deinit(globalArgs);
|
||||
obj_deinit(globals);
|
||||
ASSERT_FLOAT_EQ(res, 5.8);
|
||||
EXPECT_EQ(pikaMemNow(), 0);
|
||||
}
|
||||
@ -311,12 +311,12 @@ TEST(VM, while_a_1to10) {
|
||||
char* pikaAsm = pikaParseMultiLineToAsm(buffs, line);
|
||||
printf("%s", pikaAsm);
|
||||
PikaObj* self = newRootObj((char*)"root", New_PikaStdLib_SysObj);
|
||||
PikaObj* globalArgs = pikaVM_runAsm(self, pikaAsm);
|
||||
PikaObj* globals = pikaVM_runAsm(self, pikaAsm);
|
||||
|
||||
int res = args_getInt(globalArgs->attributeList, (char*)"a");
|
||||
int res = args_getInt(globals->attributeList, (char*)"a");
|
||||
obj_deinit(self);
|
||||
args_deinit(buffs);
|
||||
obj_deinit(globalArgs);
|
||||
obj_deinit(globals);
|
||||
ASSERT_FLOAT_EQ(res, 10);
|
||||
EXPECT_EQ(pikaMemNow(), 0);
|
||||
}
|
||||
@ -333,11 +333,11 @@ TEST(VM, mem_x) {
|
||||
char* pikaAsm = pikaParseMultiLineToAsm(buffs, line);
|
||||
printf("%s", pikaAsm);
|
||||
PikaObj* self = newRootObj((char*)"", New_PikaMain);
|
||||
PikaObj* globalArgs = pikaVM_runAsm(self, pikaAsm);
|
||||
PikaObj* globals = pikaVM_runAsm(self, pikaAsm);
|
||||
|
||||
int res = obj_getInt(globalArgs, (char*)"mem.x");
|
||||
int res = obj_getInt(globals, (char*)"mem.x");
|
||||
obj_deinit(self);
|
||||
obj_deinit(globalArgs);
|
||||
obj_deinit(globals);
|
||||
args_deinit(buffs);
|
||||
ASSERT_FLOAT_EQ(res, 2);
|
||||
EXPECT_EQ(pikaMemNow(), 0);
|
||||
@ -361,11 +361,11 @@ TEST(VM, DEF_instruct) {
|
||||
PikaObj* self = New_TinyObj(NULL);
|
||||
int lineAddr = 0;
|
||||
int size = strGetSize(pikaAsm);
|
||||
PikaObj* globalArgs = pikaVM_runAsm(self, pikaAsm);
|
||||
PikaObj* globals = pikaVM_runAsm(self, pikaAsm);
|
||||
char* methodPtr = (char*)obj_getPtr(self, (char*)"test");
|
||||
EXPECT_STREQ(methodCode, methodPtr);
|
||||
obj_deinit(self);
|
||||
obj_deinit(globalArgs);
|
||||
obj_deinit(globals);
|
||||
EXPECT_EQ(pikaMemNow(), 0);
|
||||
}
|
||||
|
||||
@ -380,12 +380,12 @@ TEST(VM, RET_instruct) {
|
||||
PikaObj* self = New_TinyObj(NULL);
|
||||
int lineAddr = 0;
|
||||
int size = strGetSize(pikaAsm);
|
||||
PikaObj* globalArgs = pikaVM_runAsm(self, pikaAsm);
|
||||
Arg* returnArg = args_getArg(globalArgs->attributeList, (char*)"return");
|
||||
PikaObj* globals = pikaVM_runAsm(self, pikaAsm);
|
||||
Arg* returnArg = args_getArg(globals->attributeList, (char*)"return");
|
||||
int num = arg_getInt(returnArg);
|
||||
EXPECT_EQ(num, 13);
|
||||
obj_deinit(self);
|
||||
obj_deinit(globalArgs);
|
||||
obj_deinit(globals);
|
||||
EXPECT_EQ(pikaMemNow(), 0);
|
||||
}
|
||||
|
||||
@ -402,9 +402,9 @@ TEST(VM, RUN_DEF) {
|
||||
"0 RUN test\n"
|
||||
"0 OUT a\n";
|
||||
PikaObj* self = New_TinyObj(NULL);
|
||||
PikaObj* globalArgs = pikaVM_runAsm(self, pikaAsm);
|
||||
PikaObj* globals = pikaVM_runAsm(self, pikaAsm);
|
||||
int num = obj_getInt(self, (char*)"a");
|
||||
obj_deinit(self);
|
||||
obj_deinit(globalArgs);
|
||||
obj_deinit(globals);
|
||||
EXPECT_EQ(pikaMemNow(), 0);
|
||||
}
|
94
src/PikaVM.c
94
src/PikaVM.c
@ -101,7 +101,7 @@ int fast_atoi(char* src) {
|
||||
}
|
||||
|
||||
Arg* pikaVM_runAsmInstruct(PikaObj* self,
|
||||
PikaObj* globalArgs,
|
||||
PikaObj* globals,
|
||||
enum Instruct instruct,
|
||||
char* data,
|
||||
Queue* invokeQuene0,
|
||||
@ -125,7 +125,7 @@ Arg* pikaVM_runAsmInstruct(PikaObj* self,
|
||||
char* argName = strsGetLastToken(buffs, data, '.');
|
||||
outArg = arg_setName(outArg, argName);
|
||||
args_deinit(buffs);
|
||||
obj_setArg(globalArgs, data, outArg);
|
||||
obj_setArg(globals, data, outArg);
|
||||
arg_deinit(outArg);
|
||||
return NULL;
|
||||
}
|
||||
@ -136,7 +136,7 @@ Arg* pikaVM_runAsmInstruct(PikaObj* self,
|
||||
if (strEqu(data, (char*)"False")) {
|
||||
return arg_setInt(NULL, "", 0);
|
||||
}
|
||||
Arg* arg = arg_copy(obj_getArg(globalArgs, data));
|
||||
Arg* arg = arg_copy(obj_getArg(globals, data));
|
||||
return arg;
|
||||
}
|
||||
if (instruct == JMP) {
|
||||
@ -146,7 +146,7 @@ Arg* pikaVM_runAsmInstruct(PikaObj* self,
|
||||
if (instruct == RET) {
|
||||
*jmp = -999;
|
||||
Arg* returnArg = arg_copy(queue_popArg(invokeQuene0));
|
||||
method_returnArg(globalArgs->attributeList, returnArg);
|
||||
method_returnArg(globals->attributeList, returnArg);
|
||||
return NULL;
|
||||
}
|
||||
if (instruct == DEF) {
|
||||
@ -320,7 +320,7 @@ Arg* pikaVM_runAsmInstruct(PikaObj* self,
|
||||
if (instruct == RUN) {
|
||||
Args* buffs = New_strBuff();
|
||||
Arg* returnArg = NULL;
|
||||
PikaObj* localArgs = NULL;
|
||||
PikaObj* locals = NULL;
|
||||
char* methodPath = data;
|
||||
/* return arg directly */
|
||||
if (strEqu(data, "")) {
|
||||
@ -331,8 +331,8 @@ Arg* pikaVM_runAsmInstruct(PikaObj* self,
|
||||
PikaObj* methodHostObj = obj_getObj(self, methodPath, 1);
|
||||
if (NULL == methodHostObj) {
|
||||
/* error, not found object */
|
||||
args_setErrorCode(globalArgs->attributeList, 1);
|
||||
args_setSysOut(globalArgs->attributeList,
|
||||
args_setErrorCode(globals->attributeList, 1);
|
||||
args_setSysOut(globals->attributeList,
|
||||
"[error] runner: object no found.");
|
||||
goto RUN_exit;
|
||||
}
|
||||
@ -341,8 +341,8 @@ Arg* pikaVM_runAsmInstruct(PikaObj* self,
|
||||
/* assert method*/
|
||||
if (NULL == method) {
|
||||
/* error, method no found */
|
||||
args_setErrorCode(globalArgs->attributeList, 2);
|
||||
args_setSysOut(globalArgs->attributeList,
|
||||
args_setErrorCode(globals->attributeList, 2);
|
||||
args_setSysOut(globals->attributeList,
|
||||
"[error] runner: method no found.");
|
||||
goto RUN_exit;
|
||||
}
|
||||
@ -357,13 +357,13 @@ Arg* pikaVM_runAsmInstruct(PikaObj* self,
|
||||
|
||||
if (typeList == NULL) {
|
||||
/* typeList no found */
|
||||
args_setErrorCode(globalArgs->attributeList, 3);
|
||||
args_setSysOut(globalArgs->attributeList,
|
||||
args_setErrorCode(globals->attributeList, 3);
|
||||
args_setSysOut(globals->attributeList,
|
||||
"[error] runner: type list no found.");
|
||||
goto RUN_exit;
|
||||
}
|
||||
|
||||
localArgs = New_TinyObj(NULL);
|
||||
locals = New_TinyObj(NULL);
|
||||
while (1) {
|
||||
Arg* methodArg = arg_copy(queue_popArg(invokeQuene1));
|
||||
if (NULL == methodArg) {
|
||||
@ -372,7 +372,7 @@ Arg* pikaVM_runAsmInstruct(PikaObj* self,
|
||||
char* argDef = strsPopToken(buffs, typeList, ',');
|
||||
char* argName = strsGetFirstToken(buffs, argDef, ':');
|
||||
methodArg = arg_setName(methodArg, argName);
|
||||
args_setArg(localArgs->attributeList, methodArg);
|
||||
args_setArg(locals->attributeList, methodArg);
|
||||
}
|
||||
|
||||
obj_setErrorCode(methodHostObj, 0);
|
||||
@ -382,34 +382,34 @@ Arg* pikaVM_runAsmInstruct(PikaObj* self,
|
||||
char* methodCode = (char*)methodPtr;
|
||||
if (methodCode[0] == 'B' && methodCode[2] == '\n') {
|
||||
/* VM method */
|
||||
localArgs = pikaVM_runAsmWithArgs(methodHostObj,
|
||||
localArgs, methodCode);
|
||||
locals = pikaVM_runAsmWithArgs(methodHostObj,
|
||||
locals, methodCode);
|
||||
/* get method return */
|
||||
returnArg = arg_copy(
|
||||
args_getArg(localArgs->attributeList, (char*)"return"));
|
||||
args_getArg(locals->attributeList, (char*)"return"));
|
||||
} else {
|
||||
/* native method */
|
||||
methodPtr(methodHostObj, localArgs->attributeList);
|
||||
methodPtr(methodHostObj, locals->attributeList);
|
||||
/* get method return */
|
||||
returnArg = arg_copy(
|
||||
args_getArg(localArgs->attributeList, (char*)"return"));
|
||||
args_getArg(locals->attributeList, (char*)"return"));
|
||||
}
|
||||
|
||||
/* transfer sysOut */
|
||||
char* sysOut = obj_getSysOut(methodHostObj);
|
||||
if (NULL != sysOut) {
|
||||
args_setSysOut(globalArgs->attributeList, sysOut);
|
||||
args_setSysOut(globals->attributeList, sysOut);
|
||||
}
|
||||
/* transfer errCode */
|
||||
if (0 != obj_getErrorCode(methodHostObj)) {
|
||||
/* method error */
|
||||
args_setErrorCode(globalArgs->attributeList, 6);
|
||||
args_setErrorCode(globals->attributeList, 6);
|
||||
}
|
||||
|
||||
goto RUN_exit;
|
||||
RUN_exit:
|
||||
if (NULL != localArgs) {
|
||||
obj_deinit(localArgs);
|
||||
if (NULL != locals) {
|
||||
obj_deinit(locals);
|
||||
}
|
||||
args_deinit(buffs);
|
||||
return returnArg;
|
||||
@ -417,14 +417,14 @@ Arg* pikaVM_runAsmInstruct(PikaObj* self,
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int32_t __clearInvokeQueues(PikaObj* globalArgs) {
|
||||
int32_t __clearInvokeQueues(PikaObj* globals) {
|
||||
for (char deepthChar = '0'; deepthChar < '9'; deepthChar++) {
|
||||
char deepth[2] = {0};
|
||||
deepth[0] = deepthChar;
|
||||
Queue* queue = (Queue*)args_getPtr(globalArgs->attributeList, deepth);
|
||||
Queue* queue = (Queue*)args_getPtr(globals->attributeList, deepth);
|
||||
if (NULL != queue) {
|
||||
args_deinit(queue);
|
||||
args_removeArg(globalArgs->attributeList, deepth);
|
||||
args_removeArg(globals->attributeList, deepth);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
@ -512,7 +512,7 @@ int32_t getAddrOffsetFromJmp(char* start, char* code, int32_t jmp) {
|
||||
}
|
||||
|
||||
int32_t pikaVM_runAsmLine(PikaObj* self,
|
||||
PikaObj* globalArgs,
|
||||
PikaObj* globals,
|
||||
char* pikaAsm,
|
||||
int32_t lineAddr) {
|
||||
Args* buffs = New_strBuff();
|
||||
@ -522,9 +522,9 @@ int32_t pikaVM_runAsmLine(PikaObj* self,
|
||||
int32_t jmp = 0;
|
||||
/* Found new script Line, clear the queues*/
|
||||
if ('B' == line[0]) {
|
||||
args_setErrorCode(globalArgs->attributeList, 0);
|
||||
args_setSysOut(globalArgs->attributeList, (char*)"");
|
||||
__clearInvokeQueues(globalArgs);
|
||||
args_setErrorCode(globals->attributeList, 0);
|
||||
args_setSysOut(globals->attributeList, (char*)"");
|
||||
__clearInvokeQueues(globals);
|
||||
uint8_t blockDeepth = line[1] - '0';
|
||||
goto nextLine;
|
||||
}
|
||||
@ -535,19 +535,19 @@ int32_t pikaVM_runAsmLine(PikaObj* self,
|
||||
enum Instruct instruct = getInstruct(line);
|
||||
char* data = line + 6;
|
||||
|
||||
Queue* invokeQuene0 = args_getPtr(globalArgs->attributeList, invokeDeepth0);
|
||||
Queue* invokeQuene1 = args_getPtr(globalArgs->attributeList, invokeDeepth1);
|
||||
Queue* invokeQuene0 = args_getPtr(globals->attributeList, invokeDeepth0);
|
||||
Queue* invokeQuene1 = args_getPtr(globals->attributeList, invokeDeepth1);
|
||||
if (NULL == invokeQuene0) {
|
||||
invokeQuene0 = New_queue();
|
||||
args_setPtr(globalArgs->attributeList, invokeDeepth0, invokeQuene0);
|
||||
args_setPtr(globals->attributeList, invokeDeepth0, invokeQuene0);
|
||||
}
|
||||
if (NULL == invokeQuene1) {
|
||||
invokeQuene1 = New_queue();
|
||||
args_setPtr(globalArgs->attributeList, invokeDeepth1, invokeQuene1);
|
||||
args_setPtr(globals->attributeList, invokeDeepth1, invokeQuene1);
|
||||
}
|
||||
|
||||
Arg* resArg =
|
||||
pikaVM_runAsmInstruct(self, globalArgs, instruct, data, invokeQuene0,
|
||||
pikaVM_runAsmInstruct(self, globals, instruct, data, invokeQuene0,
|
||||
invokeQuene1, &jmp, programCounter);
|
||||
if (NULL != resArg) {
|
||||
queue_pushArg(invokeQuene0, resArg);
|
||||
@ -582,20 +582,20 @@ char* useFlashAsBuff(char* pikaAsm, Args* buffs) {
|
||||
}
|
||||
|
||||
PikaObj* pikaVM_runAsmWithArgs(PikaObj* self,
|
||||
PikaObj* globalArgs,
|
||||
PikaObj* globals,
|
||||
char* pikaAsm) {
|
||||
int lineAddr = 0;
|
||||
int size = strGetSize(pikaAsm);
|
||||
args_setErrorCode(globalArgs->attributeList, 0);
|
||||
args_setSysOut(globalArgs->attributeList, (char*)"");
|
||||
args_setErrorCode(globals->attributeList, 0);
|
||||
args_setSysOut(globals->attributeList, (char*)"");
|
||||
while (lineAddr < size) {
|
||||
if (lineAddr == -99999) {
|
||||
break;
|
||||
}
|
||||
char* thisLine = pikaAsm + lineAddr;
|
||||
lineAddr = pikaVM_runAsmLine(self, globalArgs, pikaAsm, lineAddr);
|
||||
char* sysOut = args_getSysOut(globalArgs->attributeList);
|
||||
uint8_t errcode = args_getErrorCode(globalArgs->attributeList);
|
||||
lineAddr = pikaVM_runAsmLine(self, globals, pikaAsm, lineAddr);
|
||||
char* sysOut = args_getSysOut(globals->attributeList);
|
||||
uint8_t errcode = args_getErrorCode(globals->attributeList);
|
||||
if (!strEqu("", sysOut)) {
|
||||
__platformPrintf("%s\r\n", sysOut);
|
||||
}
|
||||
@ -606,24 +606,24 @@ PikaObj* pikaVM_runAsmWithArgs(PikaObj* self,
|
||||
args_deinit(buffs);
|
||||
}
|
||||
}
|
||||
__clearInvokeQueues(globalArgs);
|
||||
__clearInvokeQueues(globals);
|
||||
|
||||
return globalArgs;
|
||||
return globals;
|
||||
}
|
||||
|
||||
PikaObj* pikaVM_runAsm(PikaObj* self, char* pikaAsm) {
|
||||
PikaObj* globalArgs = New_TinyObj(NULL);
|
||||
globalArgs = pikaVM_runAsmWithArgs(self, globalArgs, pikaAsm);
|
||||
return globalArgs;
|
||||
PikaObj* globals = New_TinyObj(NULL);
|
||||
globals = pikaVM_runAsmWithArgs(self, globals, pikaAsm);
|
||||
return globals;
|
||||
}
|
||||
|
||||
PikaObj* pikaVM_run(PikaObj* self, char* multiLine) {
|
||||
Args* buffs = New_strBuff();
|
||||
char* pikaAsm = pikaParseMultiLineToAsm(buffs, multiLine);
|
||||
uint32_t asm_size = strGetSize(pikaAsm);
|
||||
PikaObj* globalArgs = pikaVM_runAsm(self, pikaAsm);
|
||||
PikaObj* globals = pikaVM_runAsm(self, pikaAsm);
|
||||
if (NULL != buffs) {
|
||||
args_deinit(buffs);
|
||||
}
|
||||
return globalArgs;
|
||||
return globals;
|
||||
}
|
||||
|
@ -4,14 +4,14 @@
|
||||
|
||||
PikaObj* pikaVM_run(PikaObj* self, char* pyLine);
|
||||
PikaObj* pikaVM_runAsm(PikaObj* self, char* pikaAsm);
|
||||
int32_t __clearInvokeQueues(PikaObj* globalArgs);
|
||||
int32_t __clearInvokeQueues(PikaObj* globals);
|
||||
char* useFlashAsBuff(char* pikaAsm, Args* buffs);
|
||||
int32_t gotoNextLine(char* code);
|
||||
int32_t gotoLastLine(char* start, char* code);
|
||||
int getThisBlockDeepth(char* start, char* code, int* offset);
|
||||
PikaObj* pikaVM_runAsmWithArgs(PikaObj* self, PikaObj* globalArgs, char* pikaAsm);
|
||||
PikaObj* pikaVM_runAsmWithArgs(PikaObj* self, PikaObj* globals, char* pikaAsm);
|
||||
int32_t pikaVM_runAsmLine(PikaObj* self,
|
||||
PikaObj* globalArgs,
|
||||
PikaObj* globals,
|
||||
char* pikaAsm,
|
||||
int32_t lineAddr);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user