debug p0.x = 1 error

This commit is contained in:
lyon1998 2021-10-26 20:50:13 +08:00
parent 5497dde01c
commit 695554046b
4 changed files with 31 additions and 5 deletions

View File

@ -13,7 +13,7 @@
"args": [
// "--gtest_filter=queueObj.currentObj"
// "--gtest_filter=parser*"
// "--gtest_filter=VM.Run_add_1_2_3"
"--gtest_filter=VM.while_a_d_x"
// "--gtest_filter=block.ifrun2"
// "--gtest_filter=sysObj.print"
// "--gtest_filter=object_test.a_b"

View File

@ -1,6 +1,7 @@
#include "gtest/gtest.h"
extern "C" {
#include "BaseObj.h"
#include "PikaMain.h"
#include "PikaMath_Operator.h"
#include "PikaParser.h"
#include "PikaStdLib_SysObj.h"
@ -297,4 +298,25 @@ TEST(VM, while_a_1to10) {
args_deinit(buffs);
ASSERT_FLOAT_EQ(res, 10);
EXPECT_EQ(pikaMemNow(), 0);
}
TEST(VM, while_a_d_x) {
char* line = (char*)
"mem = PikaStdLib.MemChecker()\n"
"mem.x = 1\n"
"print(mem.x)\n"
"mem.x = 2\n"
"print(mem.x)\n"
"\n";
Args* buffs = New_strBuff();
char* pikaAsm = pikaParseMultiLineToAsm(buffs, line);
printf("%s", pikaAsm);
PikaObj* self = newRootObj((char*)"", New_PikaMain);
args_deinit(pikaVM_runAsm(self, pikaAsm));
int res = obj_getInt(self, (char*)"mem.x");
obj_deinit(self);
args_deinit(buffs);
ASSERT_FLOAT_EQ(res, 2);
EXPECT_EQ(pikaMemNow(), 0);
}

View File

@ -115,7 +115,10 @@ Arg* pikaVM_runAsmInstruct(PikaObj* self,
}
if (instruct == OUT) {
Arg* outArg = arg_copy(queue_popArg(invokeQuene0));
outArg = arg_setName(outArg, data);
Args* buffs = New_strBuff();
char* argName = strsGetLastToken(buffs, data, '.');
outArg = arg_setName(outArg, argName);
args_deinit(buffs);
obj_setArg(self, data, outArg);
arg_deinit(outArg);
return NULL;
@ -127,7 +130,8 @@ Arg* pikaVM_runAsmInstruct(PikaObj* self,
if (strEqu(data, (char*)"False")) {
return arg_setInt(NULL, "", 0);
}
return arg_copy(obj_getArg(self, data));
Arg* arg = arg_copy(obj_getArg(self, data));
return arg;
}
if (instruct == JMP) {
*jmp = fast_atoi(data);
@ -561,8 +565,8 @@ Args* pikaVM_runAsm(PikaObj* self, char* pikaAsm) {
__platformPrintf("%s\r\n", sysOut);
}
if (0 != errcode) {
Args *buffs = New_strBuff();
char *onlyThisLine = strsGetFirstToken(buffs, thisLine, '\n');
Args* buffs = New_strBuff();
char* onlyThisLine = strsGetFirstToken(buffs, thisLine, '\n');
__platformPrintf("[info] input commond: %s\r\n", onlyThisLine);
args_deinit(buffs);
}