conter size at out

This commit is contained in:
lyon1998 2021-10-14 16:12:08 +08:00
parent f984c29bc3
commit 43c764c6e0
2 changed files with 10 additions and 7 deletions

View File

@ -16,11 +16,9 @@ TEST(VM, a_1) {
PikaObj* root = newRootObj((char*)"root", New_PikaStdLib_SysObj);
int lineAddr = 0;
while (1) {
int size = strGetSize(pikaAsm);
while (lineAddr < size) {
lineAddr = pikaVM_run(root, pikaAsm, lineAddr);
if (lineAddr < 0) {
break;
}
}
obj_deinit(root);

View File

@ -17,11 +17,16 @@ static int32_t getLineSize(char* str) {
int32_t pikaVM_run(PikaObj* self, char* pikaAsm, int32_t lineAddr) {
Args* buffs = New_strBuff();
int32_t size = getLineSize(pikaAsm + lineAddr);
char* line = pikaAsm + lineAddr;
int32_t nextAddr = lineAddr;
char* code = pikaAsm + lineAddr;
int32_t lineSize = getLineSize(code);
nextAddr = lineAddr + lineSize + 1;
char* line = args_getBuff(buffs, lineSize + 1);
memcpy(line, code, lineSize);
line[lineSize + 1] = 0;
goto exit;
exit:
args_deinit(buffs);
return -1;
return nextAddr;
}