diff options
author | Leo Tenenbaum <pommicket@gmail.com> | 2020-02-27 10:46:13 -0500 |
---|---|---|
committer | Leo Tenenbaum <pommicket@gmail.com> | 2020-02-27 10:46:13 -0500 |
commit | 5ae9274e34a6a33753d453e18072c8de2e7686f8 (patch) | |
tree | c8bddd7c98c8865c3d2ef98da3abadffe2cbf1b6 | |
parent | 82f19b0b7c3c709b6561e4229cc3c9713a999611 (diff) |
running stuff at compile time without assigning it to a constant
-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)) { |