diff options
Diffstat (limited to 'src/main.c')
-rw-r--r-- | src/main.c | 16 |
1 files changed, 15 insertions, 1 deletions
@@ -867,6 +867,7 @@ type_inference(Analyzer *a, Node *node, Scope *scope) { | |||
867 | node->type = cstr("str"); | 867 | node->type = cstr("str"); |
868 | return node->type; | 868 | return node->type; |
869 | } break; | 869 | } break; |
870 | case NODE_ARR_TYPE: | ||
870 | case NODE_TYPE: { | 871 | case NODE_TYPE: { |
871 | SymbolMap *type = find_type(scope, node->value.str); | 872 | SymbolMap *type = find_type(scope, node->value.str); |
872 | if (!type) { | 873 | if (!type) { |
@@ -1077,9 +1078,15 @@ type_inference(Analyzer *a, Node *node, Scope *scope) { | |||
1077 | Node *param = node->func_params[i]; | 1078 | Node *param = node->func_params[i]; |
1078 | Str symbol = param->param_name->value.str; | 1079 | Str symbol = param->param_name->value.str; |
1079 | Str type = param->param_type->value.str; | 1080 | Str type = param->param_type->value.str; |
1081 | if (param->param_type->is_ptr) { | ||
1082 | type = str_concat(cstr("@"), type, a->storage); | ||
1083 | } | ||
1084 | if (param->param_type->kind == NODE_ARR_TYPE) { | ||
1085 | type = str_concat(cstr("@"), type, a->storage); | ||
1086 | } | ||
1080 | param->param_name->type = | 1087 | param->param_name->type = |
1081 | type_inference(a, param->param_type, scope); | 1088 | type_inference(a, param->param_type, scope); |
1082 | param->type = param->param_name->type; | 1089 | param->type = type; |
1083 | symmap_insert(&scope->symbols, symbol, | 1090 | symmap_insert(&scope->symbols, symbol, |
1084 | (Symbol){.name = type, .kind = SYM_PARAM}, | 1091 | (Symbol){.name = type, .kind = SYM_PARAM}, |
1085 | a->storage); | 1092 | a->storage); |
@@ -1097,6 +1104,12 @@ type_inference(Analyzer *a, Node *node, Scope *scope) { | |||
1097 | for (sz i = 0; i < array_size(node->func_ret); i++) { | 1104 | for (sz i = 0; i < array_size(node->func_ret); i++) { |
1098 | Node *expr = node->func_ret[i]; | 1105 | Node *expr = node->func_ret[i]; |
1099 | Str type = type_inference(a, expr, scope); | 1106 | Str type = type_inference(a, expr, scope); |
1107 | if (expr->is_ptr) { | ||
1108 | type = str_concat(cstr("@"), type, a->storage); | ||
1109 | } | ||
1110 | if (expr->kind == NODE_ARR_TYPE) { | ||
1111 | type = str_concat(cstr("@"), type, a->storage); | ||
1112 | } | ||
1100 | ret_type = str_concat(ret_type, type, a->storage); | 1113 | ret_type = str_concat(ret_type, type, a->storage); |
1101 | if (i != array_size(node->func_ret) - 1) { | 1114 | if (i != array_size(node->func_ret) - 1) { |
1102 | ret_type = str_concat(ret_type, cstr(","), a->storage); | 1115 | ret_type = str_concat(ret_type, cstr(","), a->storage); |
@@ -1163,6 +1176,7 @@ type_inference(Analyzer *a, Node *node, Scope *scope) { | |||
1163 | emit_semantic_error(a, node, | 1176 | emit_semantic_error(a, node, |
1164 | cstr("type inference not implemented for this " | 1177 | cstr("type inference not implemented for this " |
1165 | "kind of expression")); | 1178 | "kind of expression")); |
1179 | println("KIND: %s", node_str[node->kind]); | ||
1166 | } break; | 1180 | } break; |
1167 | } | 1181 | } |
1168 | return cstr(""); | 1182 | return cstr(""); |