diff options
-rw-r--r-- | decls_cgen.c | 4 | ||||
-rw-r--r-- | main.c | 1 | ||||
-rw-r--r-- | sdecls_cgen.c | 4 | ||||
-rw-r--r-- | test.toc | 16 | ||||
-rw-r--r-- | types.h | 12 |
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); @@ -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; } @@ -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(){ + }; +}; @@ -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 { |