diff options
author | Bad Diode <bd@badd10de.dev> | 2022-04-22 14:56:37 -0300 |
---|---|---|
committer | Bad Diode <bd@badd10de.dev> | 2022-04-22 14:56:37 -0300 |
commit | c0dbfec91dd9781afa867675dd7a1d9cdc034c74 (patch) | |
tree | 4b2720b75062610cf123b02aabf9edc52090cbb4 | |
parent | 0bdf2ff42892b6363f703fe8f00f865a96dde223 (diff) | |
download | bdl-c0dbfec91dd9781afa867675dd7a1d9cdc034c74.tar.gz bdl-c0dbfec91dd9781afa867675dd7a1d9cdc034c74.zip |
Add some TODOs
-rw-r--r-- | TODO.md | 10 | ||||
-rw-r--r-- | src/semantic.c | 7 | ||||
-rw-r--r-- | src/viz.c | 5 |
3 files changed, 16 insertions, 6 deletions
@@ -1,12 +1,16 @@ | |||
1 | # Currently open issues | 1 | # Currently open issues |
2 | 2 | ||
3 | - [~] Fill up symbol tables/environments/types. | 3 | - [ ] Start transformation of parse tree into a simple linear IR. |
4 | - [~] Add type checking. | ||
5 | - [ ] Write a proper spec. | 4 | - [ ] Write a proper spec. |
6 | - [ ] Write proper typing rules. | 5 | - [ ] Write proper typing rules. |
7 | - [ ] Write numeric type coercion rules. | 6 | - [ ] Write numeric type coercion rules. |
8 | - [ ] Add user defined function calls (Only builtin calls currently supported). | 7 | - [ ] Ensure numeric constants fit within the given types. |
8 | - [ ] Change type annotations to allow annotating any expression. | ||
9 | - [ ] Improve error messages to be more descriptive and practical. | ||
10 | - [ ] Add references. | ||
9 | - [ ] Use bump allocators to avoid a large number of `malloc` calls. | 11 | - [ ] Use bump allocators to avoid a large number of `malloc` calls. |
10 | - [ ] Free memory. Not important for now, since it will be cleaned up at exit. | 12 | - [ ] Free memory. Not important for now, since it will be cleaned up at exit. |
11 | - [ ] Add structs. | 13 | - [ ] Add structs. |
12 | - [ ] Add arrays and darrays. | 14 | - [ ] Add arrays and darrays. |
15 | - [ ] Add type inference and generic types. | ||
16 | - [ ] Create a pretty-printer for consistent code styling. | ||
diff --git a/src/semantic.c b/src/semantic.c index 62c1e86..22d290e 100644 --- a/src/semantic.c +++ b/src/semantic.c | |||
@@ -280,6 +280,8 @@ resolve_type(ParseTree *ast, Scope *scope, Node *node) { | |||
280 | // Check that all arguments are nums. | 280 | // Check that all arguments are nums. |
281 | for (size_t i = 0; i < array_size(node->builtin.args); ++i) { | 281 | for (size_t i = 0; i < array_size(node->builtin.args); ++i) { |
282 | Node *arg = node->builtin.args[i]; | 282 | Node *arg = node->builtin.args[i]; |
283 | // TODO: Make sure all arguments have the same type, | ||
284 | // like with numeric expressions. | ||
283 | if (!type_is_numeric(arg->expr_type)) { | 285 | if (!type_is_numeric(arg->expr_type)) { |
284 | push_error(ERR_TYPE_PARSER, ERR_WRONG_TYPE_NUM, | 286 | push_error(ERR_TYPE_PARSER, ERR_WRONG_TYPE_NUM, |
285 | arg->line, arg->col); | 287 | arg->line, arg->col); |
@@ -313,6 +315,7 @@ resolve_type(ParseTree *ast, Scope *scope, Node *node) { | |||
313 | node->expr_type = type; | 315 | node->expr_type = type; |
314 | } break; | 316 | } break; |
315 | case NODE_FUN: { | 317 | case NODE_FUN: { |
318 | // TODO: don't allow parameters of type void | ||
316 | node->expr_type = &default_types[TYPE_VOID]; | 319 | node->expr_type = &default_types[TYPE_VOID]; |
317 | 320 | ||
318 | // Fill up new scope with parameters | 321 | // Fill up new scope with parameters |
@@ -368,6 +371,8 @@ resolve_type(ParseTree *ast, Scope *scope, Node *node) { | |||
368 | node->expr_type = last_expr->expr_type; | 371 | node->expr_type = last_expr->expr_type; |
369 | } break; | 372 | } break; |
370 | case NODE_IF: { | 373 | case NODE_IF: { |
374 | // TODO: If we don't have an else, ifexpr.expr_true | ||
375 | // must be void for consistency. | ||
371 | if (!resolve_type(ast, scope, node->ifexpr.cond)) { | 376 | if (!resolve_type(ast, scope, node->ifexpr.cond)) { |
372 | return false; | 377 | return false; |
373 | } | 378 | } |
@@ -419,6 +424,7 @@ resolve_type(ParseTree *ast, Scope *scope, Node *node) { | |||
419 | } | 424 | } |
420 | } break; | 425 | } break; |
421 | case NODE_DEF: { | 426 | case NODE_DEF: { |
427 | // TODO: don't allow assignment of expressions that return void | ||
422 | // Prepare value for symbol table. | 428 | // Prepare value for symbol table. |
423 | Symbol *var = alloc_symval(node->def.symbol, SYMBOL_VAR); | 429 | Symbol *var = alloc_symval(node->def.symbol, SYMBOL_VAR); |
424 | var->var.type = node->def.type; | 430 | var->var.type = node->def.type; |
@@ -450,6 +456,7 @@ resolve_type(ParseTree *ast, Scope *scope, Node *node) { | |||
450 | // numbers must fit in the given range (e.g. no negative constants | 456 | // numbers must fit in the given range (e.g. no negative constants |
451 | // inside a u64, no numbers bigger than 255 in a u8, etc.). | 457 | // inside a u64, no numbers bigger than 255 in a u8, etc.). |
452 | if (node->number.fractional != 0) { | 458 | if (node->number.fractional != 0) { |
459 | // TODO: 1.0 should also be checked as float. | ||
453 | node->expr_type = &default_types[TYPE_F64]; | 460 | node->expr_type = &default_types[TYPE_F64]; |
454 | } else { | 461 | } else { |
455 | node->expr_type = &default_types[TYPE_S64]; | 462 | node->expr_type = &default_types[TYPE_S64]; |
@@ -161,6 +161,7 @@ viz_ast(Root *roots) { | |||
161 | printf("ranksep=\"0.95 equally\";\n"); | 161 | printf("ranksep=\"0.95 equally\";\n"); |
162 | printf("nodesep=\"0.5 equally\";\n"); | 162 | printf("nodesep=\"0.5 equally\";\n"); |
163 | printf("overlap=scale;\n"); | 163 | printf("overlap=scale;\n"); |
164 | printf("bgcolor=\"transparent\";\n"); | ||
164 | for (size_t i = 0; i < array_size(roots); ++i) { | 165 | for (size_t i = 0; i < array_size(roots); ++i) { |
165 | printf("subgraph %zu {\n", i); | 166 | printf("subgraph %zu {\n", i); |
166 | Node *root = roots[array_size(roots) - 1 - i]; | 167 | Node *root = roots[array_size(roots) - 1 - i]; |
@@ -174,9 +175,7 @@ void | |||
174 | viz_symtables(Scope **scopes) { | 175 | viz_symtables(Scope **scopes) { |
175 | printf("digraph symtables {\n"); | 176 | printf("digraph symtables {\n"); |
176 | printf("rankdir=RL;\n"); | 177 | printf("rankdir=RL;\n"); |
177 | printf("ranksep=\"0.95 equally\";\n"); | 178 | printf("bgcolor=\"transparent\";\n"); |
178 | printf("nodesep=\"0.5 equally\";\n"); | ||
179 | printf("overlap=scale;\n"); | ||
180 | for (size_t i = 0; i < array_size(scopes); ++i) { | 179 | for (size_t i = 0; i < array_size(scopes); ++i) { |
181 | Scope *scope = scopes[i]; | 180 | Scope *scope = scopes[i]; |
182 | if (array_size(scope->symbols->pairs) == 0) { | 181 | if (array_size(scope->symbols->pairs) == 0) { |