diff options
author | Bad Diode <bd@badd10de.dev> | 2024-06-24 15:13:50 +0200 |
---|---|---|
committer | Bad Diode <bd@badd10de.dev> | 2024-06-24 15:13:50 +0200 |
commit | 5d3bd237db051902161a919a2efb6ca25de449d9 (patch) | |
tree | 35ce12fd49741f03f3f5f82dadfdf42407a07291 /src | |
parent | c9d686a1a6f49f8c8c4aa698c14448d961a0f024 (diff) | |
download | bdl-5d3bd237db051902161a919a2efb6ca25de449d9.tar.gz bdl-5d3bd237db051902161a919a2efb6ca25de449d9.zip |
Make sure nil return values and parameters are considered as such
Diffstat (limited to 'src')
-rw-r--r-- | src/main.c | 18 |
1 files changed, 16 insertions, 2 deletions
@@ -261,14 +261,16 @@ graph_functions(TypeScope *scope, Arena a) { | |||
261 | "<TD ALIGN=\"left\" > %s </TD>" | 261 | "<TD ALIGN=\"left\" > %s </TD>" |
262 | "<TD ALIGN=\"left\" > %s </TD>" | 262 | "<TD ALIGN=\"left\" > %s </TD>" |
263 | "</TR>", | 263 | "</TR>", |
264 | func->val.name, func->val.name, func->val.param_type, func->val.return_type); | 264 | func->val.name, func->val.name, func->val.param_type, |
265 | func->val.return_type); | ||
265 | func = funmap_next(&iter, &a); | 266 | func = funmap_next(&iter, &a); |
266 | } | 267 | } |
267 | println("</TABLE>>];"); | 268 | println("</TABLE>>];"); |
268 | sz this_id = scope->id; | 269 | sz this_id = scope->id; |
269 | while (scope->parent) { | 270 | while (scope->parent) { |
270 | if (scope->parent->types) { | 271 | if (scope->parent->types) { |
271 | println("fun_%d:e->fun_%d:%s:w;", this_id, scope->parent->id, scope->name); | 272 | println("fun_%d:e->fun_%d:%s:w;", this_id, scope->parent->id, |
273 | scope->name); | ||
272 | break; | 274 | break; |
273 | } else { | 275 | } else { |
274 | scope = scope->parent; | 276 | scope = scope->parent; |
@@ -696,6 +698,9 @@ type_inference(Analyzer *a, Node *node, TypeScope *scope) { | |||
696 | ret_type = str_concat(ret_type, cstr(","), a->storage); | 698 | ret_type = str_concat(ret_type, cstr(","), a->storage); |
697 | } | 699 | } |
698 | } | 700 | } |
701 | if (!ret_type.size) { | ||
702 | ret_type = cstr("nil"); | ||
703 | } | ||
699 | node->type = ret_type; | 704 | node->type = ret_type; |
700 | return node->type; | 705 | return node->type; |
701 | } break; | 706 | } break; |
@@ -735,6 +740,9 @@ type_inference(Analyzer *a, Node *node, TypeScope *scope) { | |||
735 | param_type = str_concat(param_type, cstr(","), a->storage); | 740 | param_type = str_concat(param_type, cstr(","), a->storage); |
736 | } | 741 | } |
737 | } | 742 | } |
743 | if (!param_type.size) { | ||
744 | param_type = cstr("nil"); | ||
745 | } | ||
738 | node->fun_params = param_type; | 746 | node->fun_params = param_type; |
739 | 747 | ||
740 | Type ret_type = cstr(""); | 748 | Type ret_type = cstr(""); |
@@ -746,6 +754,9 @@ type_inference(Analyzer *a, Node *node, TypeScope *scope) { | |||
746 | ret_type = str_concat(ret_type, cstr(","), a->storage); | 754 | ret_type = str_concat(ret_type, cstr(","), a->storage); |
747 | } | 755 | } |
748 | } | 756 | } |
757 | if (!ret_type.size) { | ||
758 | ret_type = cstr("nil"); | ||
759 | } | ||
749 | node->fun_return = ret_type; | 760 | node->fun_return = ret_type; |
750 | 761 | ||
751 | Str symbol = node->func_name->value.str; | 762 | Str symbol = node->func_name->value.str; |
@@ -763,6 +774,9 @@ type_inference(Analyzer *a, Node *node, TypeScope *scope) { | |||
763 | Node *expr = node->func_body->elements[i]; | 774 | Node *expr = node->func_body->elements[i]; |
764 | type = type_inference(a, expr, scope); | 775 | type = type_inference(a, expr, scope); |
765 | } | 776 | } |
777 | if (!type.size) { | ||
778 | type = cstr("nil"); | ||
779 | } | ||
766 | node->func_body->type = type; | 780 | node->func_body->type = type; |
767 | } else { | 781 | } else { |
768 | type_inference(a, node->func_body, scope); | 782 | type_inference(a, node->func_body, scope); |