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

@ -2294,17 +2294,14 @@ TEST(parser, multiLine_import) {
printf("%s", pikaAsm); printf("%s", pikaAsm);
EXPECT_STREQ(pikaAsm, EXPECT_STREQ(pikaAsm,
"B0\n" "B0\n"
"1 REF TEE\n" "0 IMP TEE\n"
"0 OPT import \n"
"B0\n" "B0\n"
"1 REF EE\n" "0 IMP EE\n"
"0 OPT import \n"
"B0\n" "B0\n"
"0 REF EE.C\n" "0 REF EE.C\n"
"0 OUT C\n" "0 OUT C\n"
"B0\n" "B0\n"
"1 REF PikaStdLib\n" "0 IMP PikaStdLib\n"
"0 OPT import \n"
"B0\n" "B0\n"
"0 REF PikaStdLib.MemChecker\n" "0 REF PikaStdLib.MemChecker\n"
"0 OUT MC\n" "0 OUT MC\n"
@ -2583,8 +2580,7 @@ TEST(parser, import_as) {
printf("%s", pikaAsm); printf("%s", pikaAsm);
EXPECT_STREQ(pikaAsm, EXPECT_STREQ(pikaAsm,
"B0\n" "B0\n"
"1 REF PikaStdLib\n" "0 IMP PikaStdLib\n"
"0 OPT import \n"
"B0\n" "B0\n"
"0 REF PikaStdLib\n" "0 REF PikaStdLib\n"
"0 OUT std\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_number = 0;
uint8_t is_get_symbol = 0; uint8_t is_get_symbol = 0;
uint8_t is_get_index = 0; uint8_t is_get_index = 0;
uint8_t is_get_import = 0;
ParserState_forEachToken(ps, rightWithoutSubStmt) { ParserState_forEachToken(ps, rightWithoutSubStmt) {
ParserState_iterStart(&ps); ParserState_iterStart(&ps);
/* collect type */ /* collect type */
if (strEqu(ps.token1.pyload, " import ")) {
is_get_import = 1;
goto iter_continue;
}
if (strEqu(ps.token1.pyload, "[")) { if (strEqu(ps.token1.pyload, "[")) {
is_get_index = 1; is_get_index = 1;
goto iter_continue; goto iter_continue;
@ -197,6 +202,10 @@ static enum StmtType Lexer_matchStmtType(char* right) {
iter_continue: iter_continue:
ParserState_iterEnd(&ps); ParserState_iterEnd(&ps);
} }
if (is_get_import) {
stmtType = STMT_import;
goto exit;
}
if (is_get_operator) { if (is_get_operator) {
stmtType = STMT_operator; stmtType = STMT_operator;
goto exit; goto exit;
@ -933,6 +942,7 @@ AST* AST_parseStmt(AST* ast, char* stmt) {
char* num = NULL; char* num = NULL;
char* left = NULL; char* left = NULL;
char* right = NULL; char* right = NULL;
char* import = NULL;
right = stmt; right = stmt;
/* solve check direct */ /* solve check direct */
@ -1087,6 +1097,12 @@ AST* AST_parseStmt(AST* ast, char* stmt) {
obj_setStr(ast, (char*)"ref", ref); obj_setStr(ast, (char*)"ref", ref);
goto exit; goto exit;
} }
/* solve import stmt */
if (STMT_import == stmtType) {
import = strsGetLastToken(&buffs, right, ' ');
obj_setStr(ast, (char*)"import", import);
goto exit;
}
/* solve str stmt */ /* solve str stmt */
if (STMT_string == stmtType) { if (STMT_string == stmtType) {
str = right; str = right;
@ -1619,6 +1635,7 @@ char* AST_appandPikaASM(AST* ast, AST* subAst, Args* outBuffs, char* pikaAsm) {
char* str = obj_getStr(subAst, "string"); char* str = obj_getStr(subAst, "string");
char* bytes = obj_getStr(subAst, "bytes"); char* bytes = obj_getStr(subAst, "bytes");
char* num = obj_getStr(subAst, "num"); char* num = obj_getStr(subAst, "num");
char* import = obj_getStr(subAst, "import");
char* buff = args_getBuff(&buffs, PIKA_SPRINTF_BUFF_SIZE); char* buff = args_getBuff(&buffs, PIKA_SPRINTF_BUFF_SIZE);
if (NULL != list) { if (NULL != list) {
__platform_sprintf(buff, "%d LST \n", deepth); __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); __platform_sprintf(buff, "%d OUT %s\n", deepth, left);
pikaAsm = strsAppend(&buffs, pikaAsm, buff); 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); obj_setInt(ast, "deepth", deepth - 1);
goto exit; goto exit;
exit: exit:

View File

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

View File

@ -907,6 +907,10 @@ exit:
return NULL; 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] = { const VM_instruct_handler VM_instruct_handler_table[__INSTRCUTION_CNT] = {
#define __INS_TABLE #define __INS_TABLE
#include "__instruction_table.cfg" #include "__instruction_table.cfg"

View File

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