summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLeo Tenenbaum <pommicket@gmail.com>2020-03-03 16:47:10 -0500
committerLeo Tenenbaum <pommicket@gmail.com>2020-03-03 16:47:10 -0500
commit0a3bb0c9ce4a2e96c7be3d0519aa0f5fa458c1af (patch)
tree4cf57d0ae757a295c8eb2300f7f26b1d2aed21d1
parent153001dd24eece3aa38b57ae2dced25fc0856d0c (diff)
static if
-rw-r--r--main.c6
-rw-r--r--sdecls_cgen.c4
-rw-r--r--test.toc11
-rw-r--r--types.c11
4 files changed, 15 insertions, 17 deletions
diff --git a/main.c b/main.c
index e4e1a18..b3528f2 100644
--- a/main.c
+++ b/main.c
@@ -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);
}
diff --git a/test.toc b/test.toc
index 987f3c7..6b44da4 100644
--- a/test.toc
+++ b/test.toc
@@ -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");
};
diff --git a/types.c b/types.c
index 9095bc9..74c11ff 100644
--- a/types.c
+++ b/types.c
@@ -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))