From c0dbfec91dd9781afa867675dd7a1d9cdc034c74 Mon Sep 17 00:00:00 2001 From: Bad Diode Date: Fri, 22 Apr 2022 14:56:37 -0300 Subject: Add some TODOs --- TODO.md | 10 +++++++--- src/semantic.c | 7 +++++++ src/viz.c | 5 ++--- 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/TODO.md b/TODO.md index 86b7e31..0c68e0f 100644 --- a/TODO.md +++ b/TODO.md @@ -1,12 +1,16 @@ # Currently open issues -- [~] Fill up symbol tables/environments/types. -- [~] Add type checking. +- [ ] Start transformation of parse tree into a simple linear IR. - [ ] Write a proper spec. - [ ] Write proper typing rules. - [ ] Write numeric type coercion rules. -- [ ] Add user defined function calls (Only builtin calls currently supported). +- [ ] Ensure numeric constants fit within the given types. +- [ ] Change type annotations to allow annotating any expression. +- [ ] Improve error messages to be more descriptive and practical. +- [ ] Add references. - [ ] Use bump allocators to avoid a large number of `malloc` calls. - [ ] Free memory. Not important for now, since it will be cleaned up at exit. - [ ] Add structs. - [ ] Add arrays and darrays. +- [ ] Add type inference and generic types. +- [ ] 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) { // Check that all arguments are nums. for (size_t i = 0; i < array_size(node->builtin.args); ++i) { Node *arg = node->builtin.args[i]; + // TODO: Make sure all arguments have the same type, + // like with numeric expressions. if (!type_is_numeric(arg->expr_type)) { push_error(ERR_TYPE_PARSER, ERR_WRONG_TYPE_NUM, arg->line, arg->col); @@ -313,6 +315,7 @@ resolve_type(ParseTree *ast, Scope *scope, Node *node) { node->expr_type = type; } break; case NODE_FUN: { + // TODO: don't allow parameters of type void node->expr_type = &default_types[TYPE_VOID]; // Fill up new scope with parameters @@ -368,6 +371,8 @@ resolve_type(ParseTree *ast, Scope *scope, Node *node) { node->expr_type = last_expr->expr_type; } break; case NODE_IF: { + // TODO: If we don't have an else, ifexpr.expr_true + // must be void for consistency. if (!resolve_type(ast, scope, node->ifexpr.cond)) { return false; } @@ -419,6 +424,7 @@ resolve_type(ParseTree *ast, Scope *scope, Node *node) { } } break; case NODE_DEF: { + // TODO: don't allow assignment of expressions that return void // Prepare value for symbol table. Symbol *var = alloc_symval(node->def.symbol, SYMBOL_VAR); var->var.type = node->def.type; @@ -450,6 +456,7 @@ resolve_type(ParseTree *ast, Scope *scope, Node *node) { // numbers must fit in the given range (e.g. no negative constants // inside a u64, no numbers bigger than 255 in a u8, etc.). if (node->number.fractional != 0) { + // TODO: 1.0 should also be checked as float. node->expr_type = &default_types[TYPE_F64]; } else { node->expr_type = &default_types[TYPE_S64]; diff --git a/src/viz.c b/src/viz.c index d57ece5..ea8a817 100644 --- a/src/viz.c +++ b/src/viz.c @@ -161,6 +161,7 @@ viz_ast(Root *roots) { printf("ranksep=\"0.95 equally\";\n"); printf("nodesep=\"0.5 equally\";\n"); printf("overlap=scale;\n"); + printf("bgcolor=\"transparent\";\n"); for (size_t i = 0; i < array_size(roots); ++i) { printf("subgraph %zu {\n", i); Node *root = roots[array_size(roots) - 1 - i]; @@ -174,9 +175,7 @@ void viz_symtables(Scope **scopes) { printf("digraph symtables {\n"); printf("rankdir=RL;\n"); - printf("ranksep=\"0.95 equally\";\n"); - printf("nodesep=\"0.5 equally\";\n"); - printf("overlap=scale;\n"); + printf("bgcolor=\"transparent\";\n"); for (size_t i = 0; i < array_size(scopes); ++i) { Scope *scope = scopes[i]; if (array_size(scope->symbols->pairs) == 0) { -- cgit v1.2.1