summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLeo Tenenbaum <pommicket@gmail.com>2020-02-08 21:39:03 -0500
committerLeo Tenenbaum <pommicket@gmail.com>2020-02-08 21:39:03 -0500
commitae4bce4e401e972134a29f88f26497e5761a0ee9 (patch)
tree79f2d07dd0dbd32fae9d397fd7f23052fe46d857
parent691c36c872d45315f4d7221bd689e29429a6a30d (diff)
fixed cgen of local fns
-rw-r--r--decls_cgen.c4
-rw-r--r--main.c1
-rw-r--r--sdecls_cgen.c4
-rw-r--r--test.toc16
-rw-r--r--types.h12
5 files changed, 15 insertions, 22 deletions
diff --git a/decls_cgen.c b/decls_cgen.c
index e19da8a..d18f533 100644
--- a/decls_cgen.c
+++ b/decls_cgen.c
@@ -117,11 +117,14 @@ static bool cgen_decls_expr(CGenerator *g, Expression *e) {
}
static bool cgen_decls_block(CGenerator *g, Block *b) {
+ Block *prev_block = g->block;
+ g->block = b;
arr_foreach(b->stmts, Statement, s)
if (!cgen_decls_stmt(g, s))
return false;
if (b->ret_expr && !cgen_decls_expr(g, b->ret_expr))
return false;
+ g->block = prev_block;
return true;
}
@@ -181,7 +184,6 @@ static bool cgen_decls_decl(CGenerator *g, Declaration *d) {
if (!cgen_decls_type(g, &d->type))
return false;
if (cgen_fn_is_direct(g, d)) {
- d->expr.fn->c.name = d->idents[0];
if (!cgen_fn_decl(g, d->expr.fn, &d->expr.type))
return false;
cgen_recurse_subexprs(g, (&d->expr), cgen_decls_expr, cgen_decls_block, cgen_decls_decl);
diff --git a/main.c b/main.c
index 5c31956..9f187bb 100644
--- a/main.c
+++ b/main.c
@@ -18,7 +18,6 @@
/*
TODO:
-make sure that you can't access runtime things from eval
big leak check with tuples (see "TODO: tuples allocated here will never be freed!")
just make the ffmgr use the allocr
---
diff --git a/sdecls_cgen.c b/sdecls_cgen.c
index b2f3900..83c978e 100644
--- a/sdecls_cgen.c
+++ b/sdecls_cgen.c
@@ -37,11 +37,15 @@ static bool cgen_sdecls_type(CGenerator *g, Type *type) {
}
static bool cgen_sdecls_block(CGenerator *g, Block *b) {
+ Block *prev_block = g->block;
+ g->block = b;
+
arr_foreach(b->stmts, Statement, s)
if (!cgen_sdecls_stmt(g, s))
return false;
if (b->ret_expr && !cgen_sdecls_expr(g, b->ret_expr))
return false;
+ g->block = prev_block;
return true;
}
diff --git a/test.toc b/test.toc
index aa31aed..bdb1505 100644
--- a/test.toc
+++ b/test.toc
@@ -1,14 +1,4 @@
-x := 10;
-
-twotothe ::= fn(x: int) int {
- total := 1;
- for i := 0..x-1 {
- total += twotothe(i);
- x += 1;
- }
- total
-};
-
main ::= fn() {
- a ::= twotothe(10);
-}; \ No newline at end of file
+ foo ::= fn(){
+ };
+};
diff --git a/types.h b/types.h
index 64b4fc8..74c469f 100644
--- a/types.h
+++ b/types.h
@@ -804,14 +804,12 @@ typedef struct Declaration {
};
} foreign;
};
- union {
- Value val; /* only for constant decls. */
+ Value val; /* only for constant decls and non-constant globals. */
- /* for eval, for non-constant decls.: */
- /* the pointers to values need to be fixed, which is why this isn't just Value *. */
- /* OPTIM: some block array of values somewhere which we can just use a pointer to, which is freed when the block is exited? */
- Value **val_stack;
- };
+ /* for eval, for non-constant local decls: */
+ /* the pointers to values need to be fixed, which is why this isn't just Value *. */
+ /* OPTIM: some block array of values somewhere which we can just use a pointer to, which is freed when the block is exited? */
+ Value **val_stack;
} Declaration;
typedef enum {