mirror of
https://gitee.com/Lyon1998/pikapython.git
synced 2025-01-15 17:02:53 +08:00
RAS tested ok
This commit is contained in:
parent
ea3c4b533f
commit
d10c5dbc97
1
port/linux/.vscode/launch.json
vendored
1
port/linux/.vscode/launch.json
vendored
@ -18,6 +18,7 @@
|
||||
"program": "${workspaceFolder}/build/test/pikascript_test",
|
||||
// "program": "${workspaceFolder}/../build/src/boot/demo06-pikamain/pikascript_demo06-pikamain",
|
||||
"args": [
|
||||
"--gtest_filter=VM.RUN_AS",
|
||||
// "--gtest_filter=parser.add_a_b*",
|
||||
// "--gtest_filter=parser.method_void",
|
||||
// "--gtest_filter=parser.add_a_b",
|
||||
|
@ -10,7 +10,6 @@ extern "C" {
|
||||
#include "dataQueue.h"
|
||||
#include "dataStrs.h"
|
||||
|
||||
|
||||
/* test head */
|
||||
VMParameters* pikaVM_runAsmWithPars(PikaObj* self,
|
||||
VMParameters* locals,
|
||||
@ -629,3 +628,34 @@ TEST(VM, EST) {
|
||||
EXPECT_EQ(pikaMemNow(), 0);
|
||||
}
|
||||
|
||||
TEST(VM, RUN_AS) {
|
||||
char* pikaAsm = (char*)
|
||||
"B0\n"
|
||||
"0 RUN PikaStdLib.PikaObj\n"
|
||||
"0 OUT as\n"
|
||||
"B0\n"
|
||||
"0 RAS as\n"
|
||||
"B0\n"
|
||||
"0 NUM 1\n"
|
||||
"0 OUT x\n"
|
||||
"B0\n"
|
||||
"0 RAS $origin\n"
|
||||
"B0\n"
|
||||
"0 NUM 2\n"
|
||||
"0 OUT x\n"
|
||||
;
|
||||
PikaObj* self = newRootObj((char*)"", New_PikaMain);
|
||||
pikaVM_runAsm(self, pikaAsm);
|
||||
PikaObj* as = obj_getObj(self, (char*)"as", 0);
|
||||
int x_as_ = obj_getInt(as, (char*)"x");
|
||||
int x_as = obj_getInt(self, (char*)"as.x");
|
||||
int x_origin = obj_getInt(self, (char*)"x");
|
||||
/* a is local, should not be exist in globals */
|
||||
EXPECT_EQ(x_as_, 1);
|
||||
EXPECT_EQ(x_as, 1);
|
||||
/* b is local, should not be exist in globals */
|
||||
EXPECT_EQ(x_origin, 2);
|
||||
obj_deinit(self);
|
||||
// obj_deinit(globals);
|
||||
EXPECT_EQ(pikaMemNow(), 0);
|
||||
}
|
||||
|
14
src/PikaVM.c
14
src/PikaVM.c
@ -44,7 +44,6 @@ VMParameters* pikaVM_runAsmWithPars(PikaObj* self,
|
||||
struct VMState_t {
|
||||
VMParameters* locals;
|
||||
VMParameters* globals;
|
||||
VMParameters* runAs;
|
||||
Queue* q0;
|
||||
Queue* q1;
|
||||
int32_t jmp;
|
||||
@ -340,8 +339,8 @@ static Arg* __VM_OUT(PikaObj* self,
|
||||
arg_deinit(global_list_arg);
|
||||
}
|
||||
/* use RunAs object */
|
||||
if (vs->runAs != NULL) {
|
||||
hostObj = vs->runAs;
|
||||
if (args_isArgExist(vs->locals->list, "__runAs")) {
|
||||
hostObj = args_getPtr(vs->locals->list, "__runAs");
|
||||
}
|
||||
/* ouput arg to locals */
|
||||
obj_setArg(hostObj, data, outArg);
|
||||
@ -373,12 +372,12 @@ static Arg* VM_instruction_handler_OUT(PikaObj* self, VMState* vs, char* data) {
|
||||
static Arg* VM_instruction_handler_RAS(PikaObj* self, VMState* vs, char* data) {
|
||||
if (strEqu(data, "$origin")) {
|
||||
/* use origin object to run */
|
||||
vs->runAs = NULL;
|
||||
obj_removeArg(vs->locals, "__runAs");
|
||||
return NULL;
|
||||
}
|
||||
/* use "data" object to run */
|
||||
PikaObj* runAs = obj_getObj(self, data, 0);
|
||||
vs->runAs = runAs;
|
||||
args_setPtr(vs->locals->list, "__runAs", runAs);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@ -580,9 +579,9 @@ static Arg* VM_instruction_handler_DEF(PikaObj* self, VMState* vs, char* data) {
|
||||
int offset = 0;
|
||||
int thisBlockDeepth = __getThisBlockDeepth(vs->ASM_start, vs->pc, &offset);
|
||||
PikaObj* hostObj = vs->locals;
|
||||
if (NULL != vs->runAs) {
|
||||
/* use RunAs object */
|
||||
hostObj = vs->runAs;
|
||||
if (args_isArgExist(vs->locals->list, "__runAs")) {
|
||||
hostObj = args_getPtr(vs->locals->list, "__runAs");
|
||||
}
|
||||
while (1) {
|
||||
if ((methodPtr[0] == 'B') &&
|
||||
@ -685,7 +684,6 @@ int32_t pikaVM_runAsmLine(PikaObj* self,
|
||||
VMState vs = {
|
||||
.locals = locals,
|
||||
.globals = globals,
|
||||
.runAs = NULL,
|
||||
.q0 = NULL,
|
||||
.q1 = NULL,
|
||||
.jmp = 0,
|
||||
|
Loading…
x
Reference in New Issue
Block a user