add PGC instrument after "for loop"

This commit is contained in:
lyon 2021-12-23 10:26:51 +08:00
parent e749228ecb
commit e5ff0de3be
3 changed files with 25 additions and 5 deletions

View File

@ -1401,6 +1401,8 @@ TEST(parser, for_list) {
"B0\n"
"0 JMP -1\n"
"B0\n"
"0 PGC __list0\n"
"B0\n"
);
stack_deinit(bs);
args_deinit(bf);

View File

@ -993,10 +993,23 @@ char* AST_toPikaAsm(AST* ast, Args* buffs) {
break;
}
/* goto the while start when exit while block */
if (strEqu(blockType, "while") || (strEqu(blockType, "for"))) {
if (strEqu(blockType, "while")) {
pikaAsm = ASM_addBlockDeepth(ast, buffs, pikaAsm, blockTypeNum);
pikaAsm = strsAppend(buffs, pikaAsm, (char*)"0 JMP -1\n");
}
/* goto the while start when exit while block */
if (strEqu(blockType, "for")) {
pikaAsm = ASM_addBlockDeepth(ast, buffs, pikaAsm, blockTypeNum);
pikaAsm = strsAppend(buffs, pikaAsm, (char*)"0 JMP -1\n");
pikaAsm = ASM_addBlockDeepth(ast, buffs, pikaAsm, blockTypeNum);
char* __list_x = strsCopy(buffs, "__list");
char block_deepth_str[] = "0";
block_deepth_str[0] += obj_getInt(ast, "blockDeepth");
__list_x = strsAppend(runBuffs, __list_x, block_deepth_str);
pikaAsm = strsAppend(buffs, pikaAsm, (char*)"0 PGC ");
pikaAsm = strsAppend(buffs, pikaAsm, (char*)__list_x);
pikaAsm = strsAppend(buffs, pikaAsm, (char*)"\n");
}
/* return when exit method */
if (strEqu(blockType, "def")) {
pikaAsm = strsAppend(buffs, pikaAsm, (char*)"0 RET\n");
@ -1017,7 +1030,7 @@ char* AST_toPikaAsm(AST* ast, Args* buffs) {
char* list_in = obj_getStr(ast, "list_in");
char* arg_in = obj_getStr(ast, "arg_in");
char* __list_x = strsCopy(runBuffs, "__list");
char block_deepth_str[] ="0";
char block_deepth_str[] = "0";
block_deepth_str[0] += obj_getInt(ast, "blockDeepth");
__list_x = strsAppend(runBuffs, __list_x, block_deepth_str);
/* init iter */

View File

@ -57,7 +57,8 @@ enum Instruct {
RET,
NEL,
DEL,
EST
EST,
PGC
};
static char* strs_getLine(Args* buffs, char* code) {
@ -114,13 +115,17 @@ static enum Instruct getInstruct(char* line) {
return NEL;
}
if (0 == strncmp(line + 2, "DEL", 3)) {
/* not else */
/* delete */
return EST;
}
if (0 == strncmp(line + 2, "EST", 3)) {
/* not else */
/* is exist */
return EST;
}
if (0 == strncmp(line + 2, "PGC", 3)) {
/* pika garbage colloection */
return PGC;
}
return NON;
}