Move operator infos to Core_Ctx

This commit is contained in:
Krzosa Karol
2023-01-01 16:14:47 +01:00
parent 34928e3977
commit d441abcddb
5 changed files with 153 additions and 172 deletions

View File

@@ -23,72 +23,72 @@ core_init_compiler(Core_Ctx *ctx, Allocator *allocator) {
ctx->tokens = array_make<Token>(ctx->heap, 4096 * 4);
ctx->interns = intern_table_make(ctx->perm, ctx->heap, 2048);
/*#import meta
for i in meta.keywords:
print(f'pctx->keyword_{i.lower()} = pctx->intern("{i}"_s);')
print(f'pctx->interns.first_keyword = keyword_{meta.keywords[0].lower()}.str;')
print(f'pctx->interns.last_keyword = keyword_{meta.keywords[-1].lower()}.str;')
/*#import meta
for i in meta.keywords:
print(f'pctx->keyword_{i.lower()} = pctx->intern("{i}"_s);')
print(f'pctx->interns.first_keyword = pctx->keyword_{meta.keywords[0].lower()}.str;')
print(f'pctx->interns.last_keyword = pctx->keyword_{meta.keywords[-1].lower()}.str;')
for i in meta.interns:
print(f'pctx->intern_{i.lower()} = pctx->intern("{i}"_s);')
for i in meta.interns:
print(f'pctx->intern_{i.lower()} = pctx->intern("{i}"_s);')
index = 0
for i in meta.token_simple_expr:
if i[1] != "SPECIAL":
print(f'op_info_table[{index}].op = pctx->intern("{i[1]}"_s);')
index += 1
index = 0
for i in meta.token_simple_expr:
if i[1] != "SPECIAL":
print(f'pctx->op_info_table[{index}] = {{pctx->intern("{i[1]}"_s), "{i[0].upper()}"_s, TK_{i[0]}, {int(i[2]&meta.BINARY_EXPR>0)}, {int(i[2]&meta.UNARY_EXPR>0)}}};')
index += 1
*/
pctx->keyword_struct = ctx->intern("struct"_s);
pctx->keyword_union = ctx->intern("union"_s);
pctx->keyword_true = ctx->intern("true"_s);
pctx->keyword_default = ctx->intern("default"_s);
pctx->keyword_break = ctx->intern("break"_s);
pctx->keyword_false = ctx->intern("false"_s);
pctx->keyword_return = ctx->intern("return"_s);
pctx->keyword_switch = ctx->intern("switch"_s);
pctx->keyword_assert = ctx->intern("Assert"_s);
pctx->keyword_if = ctx->intern("if"_s);
pctx->keyword_elif = ctx->intern("elif"_s);
pctx->keyword_pass = ctx->intern("pass"_s);
pctx->keyword_else = ctx->intern("else"_s);
pctx->keyword_for = ctx->intern("for"_s);
pctx->keyword_enum = ctx->intern("enum"_s);
pctx->interns.first_keyword = pctx->keyword_struct.str;
pctx->interns.last_keyword = pctx->keyword_enum.str;
pctx->intern_typeof = ctx->intern("TypeOf"_s);
pctx->intern_sizeof = ctx->intern("SizeOf"_s);
pctx->intern_len = ctx->intern("Len"_s);
pctx->intern_alignof = ctx->intern("AlignOf"_s);
pctx->intern_foreign = ctx->intern("foreign"_s);
pctx->intern_strict = ctx->intern("strict"_s);
pctx->intern_void = ctx->intern("void"_s);
pctx->intern_flag = ctx->intern("flag"_s);
pctx->intern_it = ctx->intern("it"_s);
pctx->intern_load = ctx->intern("load"_s);
pctx->intern_import = ctx->intern("import"_s);
pctx->intern_link = ctx->intern("link"_s);
op_info_table[0].op = ctx->intern("*"_s);
op_info_table[1].op = ctx->intern("/"_s);
op_info_table[2].op = ctx->intern("%"_s);
op_info_table[3].op = ctx->intern("<<"_s);
op_info_table[4].op = ctx->intern(">>"_s);
op_info_table[5].op = ctx->intern("+"_s);
op_info_table[6].op = ctx->intern("-"_s);
op_info_table[7].op = ctx->intern("=="_s);
op_info_table[8].op = ctx->intern("<="_s);
op_info_table[9].op = ctx->intern(">="_s);
op_info_table[10].op = ctx->intern("<"_s);
op_info_table[11].op = ctx->intern(">"_s);
op_info_table[12].op = ctx->intern("!="_s);
op_info_table[13].op = ctx->intern("&"_s);
op_info_table[14].op = ctx->intern("|"_s);
op_info_table[15].op = ctx->intern("^"_s);
op_info_table[16].op = ctx->intern("&&"_s);
op_info_table[17].op = ctx->intern("||"_s);
op_info_table[18].op = ctx->intern("~"_s);
op_info_table[19].op = ctx->intern("!"_s);
/*END*/
*/
pctx->keyword_struct = pctx->intern("struct"_s);
pctx->keyword_union = pctx->intern("union"_s);
pctx->keyword_true = pctx->intern("true"_s);
pctx->keyword_default = pctx->intern("default"_s);
pctx->keyword_break = pctx->intern("break"_s);
pctx->keyword_false = pctx->intern("false"_s);
pctx->keyword_return = pctx->intern("return"_s);
pctx->keyword_switch = pctx->intern("switch"_s);
pctx->keyword_assert = pctx->intern("Assert"_s);
pctx->keyword_if = pctx->intern("if"_s);
pctx->keyword_elif = pctx->intern("elif"_s);
pctx->keyword_pass = pctx->intern("pass"_s);
pctx->keyword_else = pctx->intern("else"_s);
pctx->keyword_for = pctx->intern("for"_s);
pctx->keyword_enum = pctx->intern("enum"_s);
pctx->interns.first_keyword = pctx->keyword_struct.str;
pctx->interns.last_keyword = pctx->keyword_enum.str;
pctx->intern_typeof = pctx->intern("TypeOf"_s);
pctx->intern_sizeof = pctx->intern("SizeOf"_s);
pctx->intern_len = pctx->intern("Len"_s);
pctx->intern_alignof = pctx->intern("AlignOf"_s);
pctx->intern_foreign = pctx->intern("foreign"_s);
pctx->intern_strict = pctx->intern("strict"_s);
pctx->intern_void = pctx->intern("void"_s);
pctx->intern_flag = pctx->intern("flag"_s);
pctx->intern_it = pctx->intern("it"_s);
pctx->intern_load = pctx->intern("load"_s);
pctx->intern_import = pctx->intern("import"_s);
pctx->intern_link = pctx->intern("link"_s);
pctx->op_info_table[0] = {pctx->intern("*"_s), "MUL"_s, TK_Mul, 1, 0};
pctx->op_info_table[1] = {pctx->intern("/"_s), "DIV"_s, TK_Div, 1, 0};
pctx->op_info_table[2] = {pctx->intern("%"_s), "MOD"_s, TK_Mod, 1, 0};
pctx->op_info_table[3] = {pctx->intern("<<"_s), "LEFTSHIFT"_s, TK_LeftShift, 1, 0};
pctx->op_info_table[4] = {pctx->intern(">>"_s), "RIGHTSHIFT"_s, TK_RightShift, 1, 0};
pctx->op_info_table[5] = {pctx->intern("+"_s), "ADD"_s, TK_Add, 1, 1};
pctx->op_info_table[6] = {pctx->intern("-"_s), "SUB"_s, TK_Sub, 1, 1};
pctx->op_info_table[7] = {pctx->intern("=="_s), "EQUALS"_s, TK_Equals, 1, 0};
pctx->op_info_table[8] = {pctx->intern("<="_s), "LESSERTHENOREQUAL"_s, TK_LesserThenOrEqual, 1, 0};
pctx->op_info_table[9] = {pctx->intern(">="_s), "GREATERTHENOREQUAL"_s, TK_GreaterThenOrEqual, 1, 0};
pctx->op_info_table[10] = {pctx->intern("<"_s), "LESSERTHEN"_s, TK_LesserThen, 1, 0};
pctx->op_info_table[11] = {pctx->intern(">"_s), "GREATERTHEN"_s, TK_GreaterThen, 1, 0};
pctx->op_info_table[12] = {pctx->intern("!="_s), "NOTEQUALS"_s, TK_NotEquals, 1, 0};
pctx->op_info_table[13] = {pctx->intern("&"_s), "BITAND"_s, TK_BitAnd, 1, 0};
pctx->op_info_table[14] = {pctx->intern("|"_s), "BITOR"_s, TK_BitOr, 1, 0};
pctx->op_info_table[15] = {pctx->intern("^"_s), "BITXOR"_s, TK_BitXor, 1, 0};
pctx->op_info_table[16] = {pctx->intern("&&"_s), "AND"_s, TK_And, 1, 0};
pctx->op_info_table[17] = {pctx->intern("||"_s), "OR"_s, TK_Or, 1, 0};
pctx->op_info_table[18] = {pctx->intern("~"_s), "NEG"_s, TK_Neg, 0, 1};
pctx->op_info_table[19] = {pctx->intern("!"_s), "NOT"_s, TK_Not, 0, 1};
/*END*/
init_type();