diff options
-rw-r--r-- | cgen.c | 6 | ||||
-rw-r--r-- | main.c | 1 | ||||
-rw-r--r-- | test.toc | 4 | ||||
-rw-r--r-- | types.c | 4 |
4 files changed, 13 insertions, 2 deletions
@@ -1559,6 +1559,9 @@ static void cgen_expr(CGenerator *g, Expression *e) { at least. */ static void cgen_block(CGenerator *g, Block *b, const char *ret_name, U16 flags) { + Block *prev_block = g->block; + g->block = b; + if (!(flags & CGEN_BLOCK_NOBRACES)) { cgen_write(g, "{"); cgen_nl(g); @@ -1576,6 +1579,7 @@ static void cgen_block(CGenerator *g, Block *b, const char *ret_name, U16 flags) } if (!(flags & CGEN_BLOCK_NOBRACES)) cgen_write(g, "}"); + g->block = prev_block; } static void cgen_zero_value(CGenerator *g, Type *t) { @@ -1936,7 +1940,7 @@ static void cgen_stmt(CGenerator *g, Statement *s) { cgen_decl(g, s->decl); break; case STMT_EXPR: - if (!type_is_compileonly(&s->expr.type)) { + if (g->block != NULL && !type_is_compileonly(&s->expr.type)) { cgen_expr_pre(g, &s->expr); cgen_expr(g, &s->expr); cgen_writeln(g, ";"); @@ -9,6 +9,7 @@ /* TODO: run stuff at compile time without assigning it to a constant +only include stuff once- (#include "io.toc", foo + #include "io.toc", bar => #define foo__puts bar__puts ; this is ok because __ is reserved) better #foreign system- something like f := #foreign fn (int,float, #C int); --- constants in structs @@ -7,4 +7,6 @@ main ::= fn() { io.puts("Hello!"); super.puts("hey"); great.puti(1232); -};
\ No newline at end of file +}; + +main();
\ No newline at end of file @@ -2843,6 +2843,10 @@ static Status types_stmt(Typer *tr, Statement *s) { free(str); } } + if (tr->block == NULL) { + if (!eval_stmt(tr->evalr, s)) + return false; + } break; case STMT_DECL: if (!types_decl(tr, s->decl)) { |