diff options
author | Bad Diode <bd@badd10de.dev> | 2024-06-23 21:03:53 +0200 |
---|---|---|
committer | Bad Diode <bd@badd10de.dev> | 2024-06-23 21:03:53 +0200 |
commit | 42046a947e1ad636a1ee23be58ce0be2d8abbab2 (patch) | |
tree | 72217b0fef433f0106d31a436fc258b6366eae57 | |
parent | c46596607e8ea5b37ac1bc145902b5c59dbce4e9 (diff) | |
download | bdl-42046a947e1ad636a1ee23be58ce0be2d8abbab2.tar.gz bdl-42046a947e1ad636a1ee23be58ce0be2d8abbab2.zip |
Add set typechecking
-rw-r--r-- | src/main.c | 23 | ||||
-rw-r--r-- | tests/semantics.bad | 18 |
2 files changed, 33 insertions, 8 deletions
@@ -253,6 +253,12 @@ type_inference(Analyzer *a, Node *node, TypeScope *scope) { | |||
253 | } | 253 | } |
254 | return node->type; | 254 | return node->type; |
255 | } break; | 255 | } break; |
256 | case NODE_SET: { | ||
257 | type_inference(a, node->var_name, scope); | ||
258 | type_inference(a, node->var_val, scope); | ||
259 | node->type = cstr("nil"); | ||
260 | return node->type; | ||
261 | } break; | ||
256 | case NODE_IF: { | 262 | case NODE_IF: { |
257 | Type cond_type = type_inference(a, node->cond_if, scope); | 263 | Type cond_type = type_inference(a, node->cond_if, scope); |
258 | if (!str_eq(cond_type, cstr("bool"))) { | 264 | if (!str_eq(cond_type, cstr("bool"))) { |
@@ -281,6 +287,7 @@ type_inference(Analyzer *a, Node *node, TypeScope *scope) { | |||
281 | return cstr(""); | 287 | return cstr(""); |
282 | } | 288 | } |
283 | } | 289 | } |
290 | return node->type; | ||
284 | } break; | 291 | } break; |
285 | case NODE_WHILE: { | 292 | case NODE_WHILE: { |
286 | Type cond_type = type_inference(a, node->while_cond, scope); | 293 | Type cond_type = type_inference(a, node->while_cond, scope); |
@@ -402,6 +409,22 @@ type_inference(Analyzer *a, Node *node, TypeScope *scope) { | |||
402 | node->type = type->val; | 409 | node->type = type->val; |
403 | return node->type; | 410 | return node->type; |
404 | } | 411 | } |
412 | return node->type; | ||
413 | } break; | ||
414 | case NODE_FUNCALL: { | ||
415 | // TODO: ... | ||
416 | // Str symbol = node->value.str; | ||
417 | // if (find_symbol(scope, symbol) == NULL) { | ||
418 | // eprintln( | ||
419 | // "%s:%d:%d: error: symbol '%s' doesn't exists in current " | ||
420 | // " scope ", | ||
421 | // a->file_name, node->line, node->col, symbol); | ||
422 | // return; | ||
423 | // } | ||
424 | // for (sz i = 0; i < array_size(node->elements); i++) { | ||
425 | // Node *expr = node->elements[i]; | ||
426 | // analyzer_symbols(a, expr, scope); | ||
427 | // } | ||
405 | } break; | 428 | } break; |
406 | case NODE_BLOCK: { | 429 | case NODE_BLOCK: { |
407 | scope = typescope_alloc(a, scope); | 430 | scope = typescope_alloc(a, scope); |
diff --git a/tests/semantics.bad b/tests/semantics.bad index a66c8ba..a938979 100644 --- a/tests/semantics.bad +++ b/tests/semantics.bad | |||
@@ -12,19 +12,21 @@ | |||
12 | ; a + 3 | 12 | ; a + 3 |
13 | ; } | 13 | ; } |
14 | 14 | ||
15 | let maybe = if (1 == 2) { | 15 | ; let maybe = if (1 == 2) { |
16 | 32 | 16 | ; 32 |
17 | } else { | 17 | ; } else { |
18 | 44 | 18 | ; 44 |
19 | } | 19 | ; } |
20 | 20 | ||
21 | let single = if (true) { | 21 | let single = if (true) { |
22 | 123 | 22 | 123 |
23 | } | 23 | } |
24 | 24 | ||
25 | while (!true) { | 25 | ; while (!true) { |
26 | "asjdflasdjf" | 26 | ; "asjdflasdjf" |
27 | } | 27 | ; } |
28 | |||
29 | set single = 32 | ||
28 | 30 | ||
29 | ; enum test { | 31 | ; enum test { |
30 | ; a = 1 | 32 | ; a = 1 |