mirror of
https://gitee.com/Lyon1998/pikapython.git
synced 2025-01-15 17:02:53 +08:00
STR is ok
This commit is contained in:
parent
73dbf66cbe
commit
edf3552aeb
@ -50,3 +50,33 @@ TEST(VM, a_1d1) {
|
|||||||
args_deinit(buffs);
|
args_deinit(buffs);
|
||||||
EXPECT_EQ(pikaMemNow(), 0);
|
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);
|
||||||
|
}
|
22
src/PikaVM.c
22
src/PikaVM.c
@ -45,18 +45,22 @@ static enum Instruct getInstruct(char* line) {
|
|||||||
return NON;
|
return NON;
|
||||||
}
|
}
|
||||||
|
|
||||||
Arg* pikaVM_runInstruct(PikaObj* self,
|
Arg* pikaVM_runAsmInstruct(PikaObj* self,
|
||||||
enum Instruct instruct,
|
enum Instruct instruct,
|
||||||
char* data,
|
char* data,
|
||||||
Queue* q0,
|
Queue* q0,
|
||||||
Queue* q1) {
|
Queue* q1) {
|
||||||
Arg* res = New_arg(NULL);
|
|
||||||
if (instruct == NUM) {
|
if (instruct == NUM) {
|
||||||
|
Arg* res = New_arg(NULL);
|
||||||
if (strIsContain(data, '.')) {
|
if (strIsContain(data, '.')) {
|
||||||
return arg_setFloat(res, "", atof(data));
|
return arg_setFloat(res, "", atof(data));
|
||||||
}
|
}
|
||||||
return arg_setInt(res, "", atoi(data));
|
return arg_setInt(res, "", atoi(data));
|
||||||
}
|
}
|
||||||
|
if (instruct == STR) {
|
||||||
|
Arg* res = New_arg(NULL);
|
||||||
|
return arg_setStr(res, "", data);
|
||||||
|
}
|
||||||
if (instruct == OUT) {
|
if (instruct == OUT) {
|
||||||
Arg* outArg = arg_copy(queue_popArg(q0));
|
Arg* outArg = arg_copy(queue_popArg(q0));
|
||||||
int outInt = arg_getInt(outArg);
|
int outInt = arg_getInt(outArg);
|
||||||
@ -68,7 +72,7 @@ Arg* pikaVM_runInstruct(PikaObj* self,
|
|||||||
return NULL;
|
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();
|
Args* buffs = New_strBuff();
|
||||||
char* code = pikaAsm + lineAddr;
|
char* code = pikaAsm + lineAddr;
|
||||||
char* line = strs_getLine(buffs, code);
|
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);
|
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) {
|
if (NULL != resArg) {
|
||||||
queue_pushArg(q0, resArg);
|
queue_pushArg(q0, resArg);
|
||||||
}
|
}
|
||||||
@ -106,7 +110,7 @@ int32_t pikaVM_runAsm(PikaObj* self, char* pikaAsm) {
|
|||||||
int lineAddr = 0;
|
int lineAddr = 0;
|
||||||
int size = strGetSize(pikaAsm);
|
int size = strGetSize(pikaAsm);
|
||||||
while (lineAddr < size) {
|
while (lineAddr < size) {
|
||||||
lineAddr = pikaVM_run(self, pikaAsm, lineAddr);
|
lineAddr = pikaVM_runAsmLine(self, pikaAsm, lineAddr);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (char deepthChar = '0'; deepthChar < '9'; deepthChar++) {
|
for (char deepthChar = '0'; deepthChar < '9'; deepthChar++) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user