add IMP ins

This commit is contained in:
lyon 2022-05-01 12:15:39 +08:00
parent e6c1468248
commit 2ed1750469
5 changed files with 59 additions and 36 deletions

View File

@ -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");

View File

@ -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:

View File

@ -47,6 +47,7 @@ enum StmtType {
STMT_number,
STMT_method,
STMT_operator,
STMT_import,
STMT_list,
STMT_none,
};

View File

@ -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"

View File

@ -52,3 +52,4 @@ def_ins(NEW)
def_ins(CLS)
def_ins(BYT)
def_ins(LST)
def_ins(IMP)