diff options
Diffstat (limited to 'type_checker.c')
| -rw-r--r-- | type_checker.c | 68 |
1 files changed, 9 insertions, 59 deletions
diff --git a/type_checker.c b/type_checker.c index 538f51d..2842ea2 100644 --- a/type_checker.c +++ b/type_checker.c @@ -11,6 +11,7 @@ exit(1);\ } +static struct ast* ast_ref; static struct scope* scope; static void type_check_expr(struct expr_node* node); @@ -38,74 +39,20 @@ static const struct type_def* resolve_type_ref(struct type_ref_node* node) { return node->def_ref; } -/* TODO: we likely want some shortcut to access char, int, double, long, etc. */ static const struct type_def* resolve_int_lit(struct int_lit_node* node) { - const struct type_def* resolved_type; - scope_get_type(scope, &resolved_type, &(struct type_key) { - .name = "int", - .how_long = 1, - .marked_signed = false, - .marked_unsigned = false, - }); - - if (resolved_type == NULL) - TYPE_PANIC( - "no integral type exists, " - "ensure install_default_types was called."); - - return resolved_type; + return ast_ref->integral_type; } static const struct type_def* resolve_float_lit(struct float_lit_node* node) { - const struct type_def* resolved_type; - scope_get_type(scope, &resolved_type, &(struct type_key) { - .name = "float", - .how_long = 0, - .marked_signed = false, - .marked_unsigned = false, - }); - - if (resolved_type == NULL) - TYPE_PANIC( - "no floating point type exists, " - "ensure install_default_types was called."); - - return resolved_type; + return ast_ref->decimal_type; } static const struct type_def* resolve_char_lit(struct char_lit_node* node) { - const struct type_def* resolved_type; - scope_get_type(scope, &resolved_type, &(struct type_key) { - .name = "char", - .how_long = 0, - .marked_signed = false, - .marked_unsigned = false, - }); - - if (resolved_type == NULL) - TYPE_PANIC( - "no character type exists, " - "ensure install_default_types was called."); - - return resolved_type; + return ast_ref->char_type; } static const struct type_def* resolve_str_lit(struct str_lit_node* node) { - /* TODO: pointer types */ - const struct type_def* resolved_type; - scope_get_type(scope, &resolved_type, &(struct type_key) { - .name = "int", - .how_long = 1, - .marked_signed = false, - .marked_unsigned = true, - }); - - if (resolved_type == NULL) - TYPE_PANIC( - "no string type exists, " - "ensure install_default_types was called."); - - return resolved_type; + return ast_ref->string_type; } static const struct type_def* resolve_var_ref(struct var_ref_node* node) { @@ -213,7 +160,6 @@ static void type_check_return(struct return_node* node) { } static void type_check_if(struct if_node* node) { - printf("tc if\n"); type_check_expr(node->cond); type_check_stmt(node->true_branch); if (node->false_branch != NULL) type_check_stmt(node->false_branch); @@ -277,6 +223,7 @@ static void type_check_root(struct root_node* node) { } void type_check(struct ast* ast) { + ast_ref = ast; scope = ast->root_scope; struct root_node* node = ast->root_node; @@ -284,4 +231,7 @@ void type_check(struct ast* ast) { type_check_root(node); node = node->next; } + + ast_ref = NULL; + scope = NULL; } |
