diff options
-rw-r--r-- | main.c | 6 | ||||
-rw-r--r-- | sdecls_cgen.c | 4 | ||||
-rw-r--r-- | test.toc | 11 | ||||
-rw-r--r-- | types.c | 11 |
4 files changed, 15 insertions, 17 deletions
@@ -8,7 +8,6 @@ /* TODO: -#if variadic fns #foreign variadic fns #returns_code (function/struct body is a block, to be evaluated at compile time, which returns the actual statements -- you can use this for implementation of printf) @@ -16,15 +15,14 @@ break continue switch enums +typeof macros --- switch to / add as an alternative: libffi X ::= newtype(int); or something don't allow while {3; 5} or for 0..10 { 3; 5 } (once break is added) -do we need was_expr? (now that, presumably, we have struct arguments) any odd number of "s for a string -make sure futurely/currently-declared types are only used by pointer/slice -allow omission of trailing ; in foo ::= fn() {...} or foo ::= nms {...} or foo ::= struct { ... }? +allow omission of trailing ; in foo ::= fn() {...} or foo ::= nms {...} or foo ::= struct { ... } consider- should #sizeof always take a Type? it would be more verbose, but we might not actually need #sizeof that much, given that we have new. */ diff --git a/sdecls_cgen.c b/sdecls_cgen.c index ce89ad6..e490fc8 100644 --- a/sdecls_cgen.c +++ b/sdecls_cgen.c @@ -93,7 +93,9 @@ static void cgen_sdecls_expr(CGenerator *g, Expression *e) { } break; default: break; } - cgen_recurse_subexprs(g, e, cgen_sdecls_expr, cgen_sdecls_block, cgen_sdecls_decl); + if (e->kind != EXPR_IDENT) { + cgen_recurse_subexprs(g, e, cgen_sdecls_expr, cgen_sdecls_block, cgen_sdecls_decl); + } if (e->kind == EXPR_NMS) { arr_remove_last(&g->nms_prefixes); } @@ -1,9 +1,12 @@ #include "std/io.toc", io; main ::= fn() { - #if 3 > 5 { - io.puts("3 > 5"); - } else { - io.puts("5 >= 3"); + #if 0 { + io.puts("hi"); + } elif 0 { + io.put(); + } elif 0 { + io.puts("Hi"); } + io.puts("hey"); }; @@ -1632,14 +1632,11 @@ static Status types_expr(Typer *tr, Expression *e) { if (cond) { if (!types_expr(tr, cond)) return false; - if (!types_block(tr, &curr->body)) - return false; if (!eval_expr(tr->evalr, cond, &v)) return false; } if (!cond || val_truthiness(v, &cond->type)) { - Block *true_block = typer_malloc(tr, sizeof *true_block); - *true_block = curr->body; + Block *true_block = &curr->body; e->kind = EXPR_BLOCK; e->block = true_block; break; @@ -1654,10 +1651,7 @@ static Status types_expr(Typer *tr, Expression *e) { e->block->where = e->where; idents_create(&e->block->idents, tr->allocr, e->block); } - /* re-type */ - if (!types_expr(tr, e)) - return false; - return true; + goto expr_block; } Type *curr_type = t; bool has_else = false; @@ -2171,6 +2165,7 @@ static Status types_expr(Typer *tr, Expression *e) { free(order); *t = *ret_type; } break; + expr_block: case EXPR_BLOCK: { Block *b = e->block; if (!types_block(tr, b)) |