diff --git a/src/PikaObj.c b/src/PikaObj.c index b31d07ce5..7848cbbce 100644 --- a/src/PikaObj.c +++ b/src/PikaObj.c @@ -443,14 +443,14 @@ PikaObj* _arg_to_obj(Arg* self, PIKA_BOOL* pIsTemp) { PikaObj* New_PikaStdData_String(Args * args); PikaObj* obj = newNormalObj(New_PikaStdData_String); obj_setStr(obj, "str", arg_getStr(self)); - *pIsTemp = 1; + *pIsTemp = PIKA_TRUE; return obj; } if (arg_getType(self) == ARG_TYPE_BYTES) { PikaObj* New_PikaStdData_ByteArray(Args * args); PikaObj* obj = newNormalObj(New_PikaStdData_ByteArray); obj_setArg(obj, "raw", self); - *pIsTemp = 1; + *pIsTemp = PIKA_TRUE; return obj; } #endif diff --git a/src/PikaParser.c b/src/PikaParser.c index 8bc2f4d59..72b175cc5 100644 --- a/src/PikaParser.c +++ b/src/PikaParser.c @@ -2080,6 +2080,8 @@ static char* Suger_multiAssign(Args* out_buffs, char* line) { Arg* out_list = arg_newStr(""); Arg* out_item = arg_newStr(""); Arg* line_out_arg = arg_newStr(""); + char* line_item = NULL; + char* out_list_str = NULL; int out_num = 0; Cursor_forEachToken(cs, line) { Cursor_iterStart(&cs); @@ -2107,11 +2109,11 @@ static char* Suger_multiAssign(Args* out_buffs, char* line) { goto exit; } - char* line_item = + line_item = strsFormat(&buffs, PIKA_LINE_BUFF_SIZE, "$tmp= %s\n", arg_getStr(stmt)); line_out_arg = arg_strAppend(line_out_arg, line_item); - char* out_list_str = arg_getStr(out_list); + out_list_str = arg_getStr(out_list); while (1) { char* item = Cursor_popToken(&buffs, &out_list_str, ","); if (item[0] == '\0') { @@ -2547,6 +2549,25 @@ char* GenRule_toAsm(GenRule rule, } char* AST_genAsm(AST* ast, Args* outBuffs) { + + const GenRule rules_topAst[] = { + {.ins = "CTN", .type = VAL_NONEVAL, .ast = "continue"}, + {.ins = "BRK", .type = VAL_NONEVAL, .ast = "break"}, + {.ins = "DEL", .type = VAL_DYNAMIC, .ast = "del"}, + {.ins = "GLB", .type = VAL_DYNAMIC, .ast = "global"}, + {.ins = "RIS", .type = VAL_DYNAMIC, .ast = "raise"}, + {.ins = "ASS", .type = VAL_NONEVAL, .ast = "assert"}, + {.ins = "RET", .type = VAL_NONEVAL, .ast = "return"}}; + + /* generate code for block ast */ + const GenRule rules_block[] = { + {.ins = "TRY", .type = VAL_NONEVAL, .ast = "try"}, + {.ins = "EXP", .type = VAL_NONEVAL, .ast = "except"}, + {.ins = "NEL", .type = VAL_STATIC_, .ast = "else", .val = "1"}, + {.ins = "JEZ", .type = VAL_STATIC_, .ast = "if", .val = "1"}, + {.ins = "JEZ", .type = VAL_STATIC_, .ast = "while", .val = "2"}, + }; + Args buffs = {0}; char* pikaAsm = strsCopy(&buffs, ""); QueueObj* exitBlock; @@ -2777,14 +2798,7 @@ char* AST_genAsm(AST* ast, Args* outBuffs) { is_block_matched = 1; goto exit; } - /* generate code for block ast */ - const GenRule rules_block[] = { - {.ins = "TRY", .type = VAL_NONEVAL, .ast = "try"}, - {.ins = "EXP", .type = VAL_NONEVAL, .ast = "except"}, - {.ins = "NEL", .type = VAL_STATIC_, .ast = "else", .val = "1"}, - {.ins = "JEZ", .type = VAL_STATIC_, .ast = "if", .val = "1"}, - {.ins = "JEZ", .type = VAL_STATIC_, .ast = "while", .val = "2"}, - }; + for (size_t i = 0; i < sizeof(rules_block) / sizeof(GenRule); i++) { GenRule rule = rules_block[i]; @@ -2795,15 +2809,6 @@ char* AST_genAsm(AST* ast, Args* outBuffs) { } } - const GenRule rules_topAst[] = { - {.ins = "CTN", .type = VAL_NONEVAL, .ast = "continue"}, - {.ins = "BRK", .type = VAL_NONEVAL, .ast = "break"}, - {.ins = "DEL", .type = VAL_DYNAMIC, .ast = "del"}, - {.ins = "GLB", .type = VAL_DYNAMIC, .ast = "global"}, - {.ins = "RIS", .type = VAL_DYNAMIC, .ast = "raise"}, - {.ins = "ASS", .type = VAL_NONEVAL, .ast = "assert"}, - {.ins = "RET", .type = VAL_NONEVAL, .ast = "return"}}; - /* generate code for top level ast */ for (size_t i = 0; i < sizeof(rules_topAst) / sizeof(rules_topAst[0]); i++) { diff --git a/src/PikaVM.c b/src/PikaVM.c index 624e02863..ea427fa7e 100644 --- a/src/PikaVM.c +++ b/src/PikaVM.c @@ -244,7 +244,7 @@ static void VMState_delLReg(VMState* vm, uint8_t index) { static void VMState_initReg(VMState* vm) { for (uint8_t i = 0; i < PIKA_REGIST_SIZE; i++) { vm->lreg[i] = NULL; - vm->ireg[i] = 0; + vm->ireg[i] = PIKA_FALSE; } } @@ -286,7 +286,7 @@ Arg* __vm_get(PikaObj* self, Arg* key, Arg* obj) { } if (ARG_TYPE_STRING == type) { #if PIKA_STRING_UTF8_ENABLE - PIKA_BOOL is_temp = 0; + PIKA_BOOL is_temp = PIKA_FALSE; obj_new = arg_newObj(_arg_to_obj(obj, &is_temp)); type = arg_getType(obj_new); #else @@ -417,7 +417,7 @@ Arg* __vm_slice(PikaObj* self, Arg* end, Arg* obj, Arg* start, int step) { PikaObj* New_PikaStdData_Tuple(Args * args); if (arg_obj->constructor == New_PikaStdData_List || arg_obj->constructor == New_PikaStdData_Tuple) { - PikaObj* sliced_obj = newNormalObj(arg_obj->constructor); + PikaObj* sliced_obj = newNormalObj((NewFun)arg_obj->constructor); __vm_List___init__(sliced_obj); for (int i = start_i; i < end_i; i++) { Arg* i_arg = arg_newInt(i); @@ -1050,8 +1050,8 @@ static Arg* VM_instruction_handler_RUN(PikaObj* self, /* support for super() */ if (strEqu(run_path, "super")) { run_path = _find_super_class_name(vm); - vm->in_super = 1; - skip_init = 1; + vm->in_super = PIKA_TRUE; + skip_init = PIKA_TRUE; } #endif @@ -1418,7 +1418,7 @@ static Arg* _VM_JEZ(PikaObj* self, int pika_assert) { int thisBlockDeepth = VMState_getBlockDeepthNow(vm); int jmp_expect = fast_atoi(data); - vm->ireg[thisBlockDeepth] = !pika_assert; + vm->ireg[thisBlockDeepth] = (PIKA_BOOL)!pika_assert; if (0 == pika_assert) { /* jump */ diff --git a/src/__instruction_table.cfg b/src/__instruction_table.cfg index 6f648486d..e69baf288 100644 --- a/src/__instruction_table.cfg +++ b/src/__instruction_table.cfg @@ -95,4 +95,4 @@ def_ins(ASS) /* expect */ def_ins(EXP) /* jump no zero */ -def_ins(JNZ) \ No newline at end of file +def_ins(JNZ)