From: Brendan Hansen Date: Mon, 22 Jun 2020 16:16:18 +0000 (-0500) Subject: Bug fixes with symbol resolution X-Git-Url: https://git.brendanfh.com/?a=commitdiff_plain;h=43e94e5441c07d0a51ee808e3dce2923c1a87f87;p=onyx.git Bug fixes with symbol resolution --- diff --git a/include/onyxparser.h b/include/onyxparser.h index 39becb23..c9d77e6b 100644 --- a/include/onyxparser.h +++ b/include/onyxparser.h @@ -153,7 +153,7 @@ struct OnyxAstNodeBlock { OnyxTypeInfo *return_type; OnyxAstNode *next; OnyxAstNode *body; - OnyxAstNodeScope *scope; // NOTE: Only set on blocks belonging to functions + OnyxAstNodeScope *scope; }; struct OnyxAstNodeIf { diff --git a/onyx b/onyx index 8cec77eb..8ad5333c 100755 Binary files a/onyx and b/onyx differ diff --git a/progs/new_minimal.onyx b/progs/new_minimal.onyx index cbb7fe06..55cb5174 100644 --- a/progs/new_minimal.onyx +++ b/progs/new_minimal.onyx @@ -1,13 +1,14 @@ print :: foreign "host" "print" proc (value i32) --- -foo :: proc -> i32 { - a := 2 + 4; - a = 5; - bar(a + 1); - print(bar(a)); - return a; -} +diff_square :: proc (a i32, b i32) -> i32 { + // Typechecked + c := a - b; // Mutable + d :: a + b; // Constant + + { + c : i32 = a * 2; + d : i32 = (c + a) * 2; + } -bar :: proc (val i32) -> i32 { - return val + 1; + return c * d; } diff --git a/src/onyxsempass.c b/src/onyxsempass.c index 233646fd..dd2568be 100644 --- a/src/onyxsempass.c +++ b/src/onyxsempass.c @@ -237,6 +237,7 @@ static b32 symres_statement(OnyxSemPassState* state, OnyxAstNode* stmt) { case ONYX_AST_NODE_KIND_IF: symres_if(state, &stmt->as_if); return 0; case ONYX_AST_NODE_KIND_CALL: symres_call(state, stmt); return 0; case ONYX_AST_NODE_KIND_ARGUMENT: symres_expression(state, (OnyxAstNode **) &stmt->left); return 0; + case ONYX_AST_NODE_KIND_BLOCK: symres_block(state, &stmt->as_block); return 0; default: return 0; } @@ -251,7 +252,7 @@ static void symres_statement_chain(OnyxSemPassState* state, OnyxAstNode* walker, walker->next = NULL; walker = tmp; } else { - trailer = &walker; + trailer = &walker->next; walker = walker->next; } } @@ -296,11 +297,6 @@ void onyx_sempass(OnyxSemPassState* state, OnyxAstNode* root_node) { walker = walker->next; } - bh_printf("\n\n"); - bh_table_each_start(SemPassSymbol*, state->symbols) { - bh_printf("%s -> %l\n", key, (u64) value); - } bh_table_each_end; - // NOTE: First, resolve all symbols walker = root_node; while (walker) {