summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cgen.c6
-rw-r--r--main.c1
-rw-r--r--test.toc4
-rw-r--r--types.c4
4 files changed, 13 insertions, 2 deletions
diff --git a/cgen.c b/cgen.c
index 81e13b6..d9a9edb 100644
--- a/cgen.c
+++ b/cgen.c
@@ -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, ";");
diff --git a/main.c b/main.c
index 1a88831..8d14dfb 100644
--- a/main.c
+++ b/main.c
@@ -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
diff --git a/test.toc b/test.toc
index 91b8cbc..e9ab36b 100644
--- a/test.toc
+++ b/test.toc
@@ -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
diff --git a/types.c b/types.c
index 472acf3..91fe1fa 100644
--- a/types.c
+++ b/types.c
@@ -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)) {