diff options
author | Bad Diode <bd@badd10de.dev> | 2024-06-26 16:22:16 +0200 |
---|---|---|
committer | Bad Diode <bd@badd10de.dev> | 2024-06-26 16:22:16 +0200 |
commit | 56510571a9d2c6c1242d5efc26c4ab2905269930 (patch) | |
tree | 822f11beede8454e6b817e8a247e2ed6460c8173 /src/main.c | |
parent | 8194ea8fb891ecda56e9efc0069a27ae37ba0a1b (diff) | |
download | bdl-56510571a9d2c6c1242d5efc26c4ab2905269930.tar.gz bdl-56510571a9d2c6c1242d5efc26c4ab2905269930.zip |
Fill up main symbol table with everything we need
Diffstat (limited to 'src/main.c')
-rw-r--r-- | src/main.c | 13 |
1 files changed, 10 insertions, 3 deletions
@@ -10,6 +10,7 @@ | |||
10 | // TODO: unions | 10 | // TODO: unions |
11 | // TODO: match deconstruct enums | 11 | // TODO: match deconstruct enums |
12 | // TODO: arrays and pointers | 12 | // TODO: arrays and pointers |
13 | // TODO: if we have errors make sure we mark the analyzer as such | ||
13 | 14 | ||
14 | typedef enum ExecMode { | 15 | typedef enum ExecMode { |
15 | RUN_NORMAL, | 16 | RUN_NORMAL, |
@@ -325,6 +326,9 @@ typecheck_field(Analyzer *a, Node *node, Scope *scope, Str symbol) { | |||
325 | .val = node->field_val, | 326 | .val = node->field_val, |
326 | }, | 327 | }, |
327 | a->storage); | 328 | a->storage); |
329 | symmap_insert(&scope->symbols, field_name, | ||
330 | (Symbol){.name = field_type, .kind = SYM_STRUCT_FIELD}, | ||
331 | a->storage); | ||
328 | node->type = field_type; | 332 | node->type = field_type; |
329 | } | 333 | } |
330 | } | 334 | } |
@@ -575,6 +579,10 @@ type_inference(Analyzer *a, Node *node, Scope *scope) { | |||
575 | } | 579 | } |
576 | enummap_insert(&scope->enums, field_name, | 580 | enummap_insert(&scope->enums, field_name, |
577 | (Enum){.name = field_name}, a->storage); | 581 | (Enum){.name = field_name}, a->storage); |
582 | symmap_insert( | ||
583 | &scope->symbols, field_name, | ||
584 | (Symbol){.name = field_name, .kind = SYM_ENUM_FIELD}, | ||
585 | a->storage); | ||
578 | field->type = cstr("int"); | 586 | field->type = cstr("int"); |
579 | } | 587 | } |
580 | symmap_insert(&scope->symbols, symbol, | 588 | symmap_insert(&scope->symbols, symbol, |
@@ -629,6 +637,7 @@ type_inference(Analyzer *a, Node *node, Scope *scope) { | |||
629 | } break; | 637 | } break; |
630 | case NODE_COND: | 638 | case NODE_COND: |
631 | case NODE_MATCH: { | 639 | case NODE_MATCH: { |
640 | // TODO: proper typecheck matchcase expressions here... | ||
632 | if (node->match_expr) { | 641 | if (node->match_expr) { |
633 | type_inference(a, node->match_expr, scope); | 642 | type_inference(a, node->match_expr, scope); |
634 | } | 643 | } |
@@ -644,7 +653,6 @@ type_inference(Analyzer *a, Node *node, Scope *scope) { | |||
644 | } | 653 | } |
645 | previous = next; | 654 | previous = next; |
646 | } | 655 | } |
647 | // TODO: proper typecheck matchcase expressions here... | ||
648 | node->type = previous; | 656 | node->type = previous; |
649 | return node->type; | 657 | return node->type; |
650 | } break; | 658 | } break; |
@@ -911,8 +919,7 @@ type_inference(Analyzer *a, Node *node, Scope *scope) { | |||
911 | args = cstr("nil"); | 919 | args = cstr("nil"); |
912 | } | 920 | } |
913 | Str expected = fun->val.param_type; | 921 | Str expected = fun->val.param_type; |
914 | bool err = !str_eq(args, expected); | 922 | if (!str_eq(args, expected) && !str_eq(expected, cstr("..."))) { |
915 | if (err) { | ||
916 | eprintln( | 923 | eprintln( |
917 | "%s:%d:%d: error: mismatched parameter types: %s expected " | 924 | "%s:%d:%d: error: mismatched parameter types: %s expected " |
918 | "%s", | 925 | "%s", |