STR is ok

This commit is contained in:
lyon1998 2021-10-14 21:02:19 +08:00
parent 73dbf66cbe
commit edf3552aeb
2 changed files with 43 additions and 9 deletions

View File

@ -50,3 +50,33 @@ TEST(VM, a_1d1) {
args_deinit(buffs);
EXPECT_EQ(pikaMemNow(), 0);
}
TEST(VM, str_xy) {
char* line = (char*)"a = 'xy'";
Args* buffs = New_strBuff();
char* pikaAsm = pikaParseToAsm(buffs, line);
printf("%s", pikaAsm);
PikaObj* self = newRootObj((char*)"root", New_PikaStdLib_SysObj);
pikaVM_runAsm(self, pikaAsm);
ASSERT_STREQ(obj_getStr(self, (char*)"a"), (char*)"xy");
obj_deinit(self);
args_deinit(buffs);
EXPECT_EQ(pikaMemNow(), 0);
}
TEST(VM, str_xy_space) {
char* line = (char*)"a = 'xy '";
Args* buffs = New_strBuff();
char* pikaAsm = pikaParseToAsm(buffs, line);
printf("%s", pikaAsm);
PikaObj* self = newRootObj((char*)"root", New_PikaStdLib_SysObj);
pikaVM_runAsm(self, pikaAsm);
ASSERT_STREQ(obj_getStr(self, (char*)"a"), (char*)"xy ");
obj_deinit(self);
args_deinit(buffs);
EXPECT_EQ(pikaMemNow(), 0);
}

View File

@ -45,18 +45,22 @@ static enum Instruct getInstruct(char* line) {
return NON;
}
Arg* pikaVM_runInstruct(PikaObj* self,
enum Instruct instruct,
char* data,
Queue* q0,
Queue* q1) {
Arg* res = New_arg(NULL);
Arg* pikaVM_runAsmInstruct(PikaObj* self,
enum Instruct instruct,
char* data,
Queue* q0,
Queue* q1) {
if (instruct == NUM) {
Arg* res = New_arg(NULL);
if (strIsContain(data, '.')) {
return arg_setFloat(res, "", atof(data));
}
return arg_setInt(res, "", atoi(data));
}
if (instruct == STR) {
Arg* res = New_arg(NULL);
return arg_setStr(res, "", data);
}
if (instruct == OUT) {
Arg* outArg = arg_copy(queue_popArg(q0));
int outInt = arg_getInt(outArg);
@ -68,7 +72,7 @@ Arg* pikaVM_runInstruct(PikaObj* self,
return NULL;
}
int32_t pikaVM_run(PikaObj* self, char* pikaAsm, int32_t lineAddr) {
int32_t pikaVM_runAsmLine(PikaObj* self, char* pikaAsm, int32_t lineAddr) {
Args* buffs = New_strBuff();
char* code = pikaAsm + lineAddr;
char* line = strs_getLine(buffs, code);
@ -91,7 +95,7 @@ int32_t pikaVM_run(PikaObj* self, char* pikaAsm, int32_t lineAddr) {
obj_setPtr(self, d1, q1);
}
Arg* resArg = pikaVM_runInstruct(self, instruct, data, q0, q1);
Arg* resArg = pikaVM_runAsmInstruct(self, instruct, data, q0, q1);
if (NULL != resArg) {
queue_pushArg(q0, resArg);
}
@ -106,7 +110,7 @@ int32_t pikaVM_runAsm(PikaObj* self, char* pikaAsm) {
int lineAddr = 0;
int size = strGetSize(pikaAsm);
while (lineAddr < size) {
lineAddr = pikaVM_run(self, pikaAsm, lineAddr);
lineAddr = pikaVM_runAsmLine(self, pikaAsm, lineAddr);
}
for (char deepthChar = '0'; deepthChar < '9'; deepthChar++) {