From 82990fa60f657861e9f2709d68c971d08e9b513c Mon Sep 17 00:00:00 2001 From: Leo Tenenbaum Date: Tue, 4 Feb 2020 14:02:38 -0500 Subject: got cgen to work with namespaces --- cgen.c | 21 ++++++++++++++------- test.toc | 5 +++-- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/cgen.c b/cgen.c index b37d432..563a15c 100644 --- a/cgen.c +++ b/cgen.c @@ -2079,8 +2079,6 @@ static bool cgen_defs_fn(CGenerator *g, FnExpr *f, Type *t) { if (fn_type->constness[i] == CONSTNESS_YES) any_const = true; } - } - if (fn_type->constness) { HashTable *instances = &f->instances; /* generate each instance */ Instance **is = instances->data; @@ -2145,13 +2143,22 @@ static bool cgen_defs_stmt(CGenerator *g, Statement *s) { } static bool cgen_defs_block(CGenerator *g, Block *b) { + Block *prev = g->block; + g->block = b; + bool success = true; arr_foreach(b->stmts, Statement, s) { - if (!cgen_defs_stmt(g, s)) - return false; + if (!cgen_defs_stmt(g, s)) { + success = false; + goto ret; + } } - if (b->ret_expr && !cgen_defs_expr(g, b->ret_expr)) - return false; - return true; + if (b->ret_expr && !cgen_defs_expr(g, b->ret_expr)) { + success = false; + goto ret; + } + ret: + g->block = prev; + return success; } static bool cgen_file(CGenerator *g, ParsedFile *f) { diff --git a/test.toc b/test.toc index 1fb9876..c1fa02c 100644 --- a/test.toc +++ b/test.toc @@ -1,7 +1,8 @@ -yep :: Namespace = nms { -adfasdf ::= fn() {}; +n :: Namespace = nms { +f ::= fn() {}; }; main ::= fn() { + n.f(); }; \ No newline at end of file -- cgit v1.2.3