diff --git a/port/linux/test/parse-test.cpp b/port/linux/test/parse-test.cpp index d515f1b8a..a65b5a162 100644 --- a/port/linux/test/parse-test.cpp +++ b/port/linux/test/parse-test.cpp @@ -2293,40 +2293,37 @@ TEST(parser, multiLine_import) { char* pikaAsm = Parser_multiLineToAsm(buffs, lines); printf("%s", pikaAsm); EXPECT_STREQ(pikaAsm, - "B0\n" - "1 REF TEE\n" - "0 OPT import \n" - "B0\n" - "1 REF EE\n" - "0 OPT import \n" - "B0\n" - "0 REF EE.C\n" - "0 OUT C\n" - "B0\n" - "1 REF PikaStdLib\n" - "0 OPT import \n" - "B0\n" - "0 REF PikaStdLib.MemChecker\n" - "0 OUT MC\n" - "B0\n" - "0 REF true\n" - "0 JEZ 2\n" - "B1\n" - "0 RUN rgb.flow\n" - "B1\n" - "0 REF false\n" - "0 JEZ 1\n" - "B2\n" - "0 NUM 3\n" - "0 OUT a\n" - "B2\n" - "2 NUM 2\n" - "2 NUM 3\n" - "1 RUN add\n" - "0 RUN test.on\n" - "B0\n" - "0 JMP -1\n" - "B0\n"); + "B0\n" + "0 IMP TEE\n" + "B0\n" + "0 IMP EE\n" + "B0\n" + "0 REF EE.C\n" + "0 OUT C\n" + "B0\n" + "0 IMP PikaStdLib\n" + "B0\n" + "0 REF PikaStdLib.MemChecker\n" + "0 OUT MC\n" + "B0\n" + "0 REF true\n" + "0 JEZ 2\n" + "B1\n" + "0 RUN rgb.flow\n" + "B1\n" + "0 REF false\n" + "0 JEZ 1\n" + "B2\n" + "0 NUM 3\n" + "0 OUT a\n" + "B2\n" + "2 NUM 2\n" + "2 NUM 3\n" + "1 RUN add\n" + "0 RUN test.on\n" + "B0\n" + "0 JMP -1\n" + "B0\n"); args_deinit(buffs); EXPECT_EQ(pikaMemNow(), 0); } @@ -2583,8 +2580,7 @@ TEST(parser, import_as) { printf("%s", pikaAsm); EXPECT_STREQ(pikaAsm, "B0\n" - "1 REF PikaStdLib\n" - "0 OPT import \n" + "0 IMP PikaStdLib\n" "B0\n" "0 REF PikaStdLib\n" "0 OUT std\n"); diff --git a/src/PikaParser.c b/src/PikaParser.c index a46afcb58..9b36098bd 100644 --- a/src/PikaParser.c +++ b/src/PikaParser.c @@ -161,9 +161,14 @@ static enum StmtType Lexer_matchStmtType(char* right) { uint8_t is_get_number = 0; uint8_t is_get_symbol = 0; uint8_t is_get_index = 0; + uint8_t is_get_import = 0; ParserState_forEachToken(ps, rightWithoutSubStmt) { ParserState_iterStart(&ps); /* collect type */ + if (strEqu(ps.token1.pyload, " import ")) { + is_get_import = 1; + goto iter_continue; + } if (strEqu(ps.token1.pyload, "[")) { is_get_index = 1; goto iter_continue; @@ -197,6 +202,10 @@ static enum StmtType Lexer_matchStmtType(char* right) { iter_continue: ParserState_iterEnd(&ps); } + if (is_get_import) { + stmtType = STMT_import; + goto exit; + } if (is_get_operator) { stmtType = STMT_operator; goto exit; @@ -933,6 +942,7 @@ AST* AST_parseStmt(AST* ast, char* stmt) { char* num = NULL; char* left = NULL; char* right = NULL; + char* import = NULL; right = stmt; /* solve check direct */ @@ -1087,6 +1097,12 @@ AST* AST_parseStmt(AST* ast, char* stmt) { obj_setStr(ast, (char*)"ref", ref); goto exit; } + /* solve import stmt */ + if (STMT_import == stmtType) { + import = strsGetLastToken(&buffs, right, ' '); + obj_setStr(ast, (char*)"import", import); + goto exit; + } /* solve str stmt */ if (STMT_string == stmtType) { str = right; @@ -1619,6 +1635,7 @@ char* AST_appandPikaASM(AST* ast, AST* subAst, Args* outBuffs, char* pikaAsm) { char* str = obj_getStr(subAst, "string"); char* bytes = obj_getStr(subAst, "bytes"); char* num = obj_getStr(subAst, "num"); + char* import = obj_getStr(subAst, "import"); char* buff = args_getBuff(&buffs, PIKA_SPRINTF_BUFF_SIZE); if (NULL != list) { __platform_sprintf(buff, "%d LST \n", deepth); @@ -1652,6 +1669,10 @@ char* AST_appandPikaASM(AST* ast, AST* subAst, Args* outBuffs, char* pikaAsm) { __platform_sprintf(buff, "%d OUT %s\n", deepth, left); pikaAsm = strsAppend(&buffs, pikaAsm, buff); } + if (NULL != import) { + __platform_sprintf(buff, "%d IMP %s\n", deepth, import); + pikaAsm = strsAppend(&buffs, pikaAsm, buff); + } obj_setInt(ast, "deepth", deepth - 1); goto exit; exit: diff --git a/src/PikaParser.h b/src/PikaParser.h index 37d09cbde..961df98ae 100644 --- a/src/PikaParser.h +++ b/src/PikaParser.h @@ -47,6 +47,7 @@ enum StmtType { STMT_number, STMT_method, STMT_operator, + STMT_import, STMT_list, STMT_none, }; diff --git a/src/PikaVM.c b/src/PikaVM.c index 160a559bd..777ab8710 100644 --- a/src/PikaVM.c +++ b/src/PikaVM.c @@ -907,6 +907,10 @@ exit: return NULL; } +static Arg* VM_instruction_handler_IMP(PikaObj* self, VMState* vs, char* data) { + return NULL; +} + const VM_instruct_handler VM_instruct_handler_table[__INSTRCUTION_CNT] = { #define __INS_TABLE #include "__instruction_table.cfg" diff --git a/src/__instruction_table.cfg b/src/__instruction_table.cfg index 5c42c3299..c72d64563 100644 --- a/src/__instruction_table.cfg +++ b/src/__instruction_table.cfg @@ -52,3 +52,4 @@ def_ins(NEW) def_ins(CLS) def_ins(BYT) def_ins(LST) +def_ins(IMP)