diff --git a/port/linux/.vscode/launch.json b/port/linux/.vscode/launch.json index 998f2b330..b9967dd3f 100644 --- a/port/linux/.vscode/launch.json +++ b/port/linux/.vscode/launch.json @@ -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" diff --git a/port/linux/package/pikascript/rust-msc-latest-linux b/port/linux/package/pikascript/rust-msc-latest-linux index 4ebe06095..377757c4b 100755 Binary files a/port/linux/package/pikascript/rust-msc-latest-linux and b/port/linux/package/pikascript/rust-msc-latest-linux differ diff --git a/port/linux/test/VM-test.cpp b/port/linux/test/VM-test.cpp index b03abea07..b6292d679 100644 --- a/port/linux/test/VM-test.cpp +++ b/port/linux/test/VM-test.cpp @@ -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); } \ No newline at end of file diff --git a/src/PikaVM.c b/src/PikaVM.c index f79d1f11a..48996fde0 100644 --- a/src/PikaVM.c +++ b/src/PikaVM.c @@ -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); }