aboutsummaryrefslogtreecommitdiffstats
path: root/src/semantic.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/semantic.c')
-rw-r--r--src/semantic.c7
1 files changed, 7 insertions, 0 deletions
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];