save ram for multiLine parse

This commit is contained in:
lyon1998 2021-10-17 19:35:50 +08:00
parent 46515f6811
commit bf59fe1667
2 changed files with 16 additions and 7 deletions

View File

@ -368,7 +368,9 @@ TEST(parser, while_true_if_false_both_exit) {
EXPECT_EQ(pikaMemNow(), 0);
}
extern PikaMemInfo pikaMemInfo;
TEST(parser, multiLine) {
pikaMemInfo.heapUsedMax = 0;
Args* buffs = New_strBuff();
char* lines =(char *)
"while true:\n"

View File

@ -192,22 +192,29 @@ char* pikaParseLineToAsm(Args* buffs, char* line, Stack* blockStack) {
}
char* pikaParseMultiLineToAsm(Args* outBuffs, char* multiLine) {
Args* multiRunBuffs = New_strBuff();
Stack* blockStack = New_Stack();
char* pikaAsm = strsCopy(multiRunBuffs, "");
multiLine = strsCopy(multiRunBuffs, multiLine);
Arg* pikaAsmBuff = arg_setStr(NULL, "", "");
char* pikaAsm;
Arg* multiLineBuff = arg_setStr(NULL, "", multiLine);
while (1) {
char* line = strsPopToken(multiRunBuffs, multiLine, '\n');
Args* singleRunBuffs = New_strBuff();
char* multiLine = strsCopy(singleRunBuffs, arg_getStr(multiLineBuff));
arg_deinit(multiLineBuff);
char* line = strsPopToken(singleRunBuffs, multiLine, '\n');
multiLineBuff = arg_setStr(NULL, "", multiLine);
char* singleAsm = pikaParseLineToAsm(singleRunBuffs, line, blockStack);
pikaAsm = strsAppend(multiRunBuffs, pikaAsm, singleAsm);
pikaAsm = arg_getStr(pikaAsmBuff);
pikaAsm = strsAppend(singleRunBuffs, pikaAsm, singleAsm);
arg_deinit(pikaAsmBuff);
pikaAsmBuff = arg_setStr(NULL, "", pikaAsm);
args_deinit(singleRunBuffs);
if (strGetSize(multiLine) == 0) {
break;
}
}
char* multiAsm = strsCopy(outBuffs, pikaAsm);
args_deinit(multiRunBuffs);
char* multiAsm = strsCopy(outBuffs, arg_getStr(pikaAsmBuff));
arg_deinit(multiLineBuff);
arg_deinit(pikaAsmBuff);
stack_deinit(blockStack);
return multiAsm;
}