diff options
-rw-r--r-- | cgen.c | 3 | ||||
-rw-r--r-- | decls_cgen.c | 3 | ||||
-rw-r--r-- | main.c | 1 | ||||
-rw-r--r-- | sdecls_cgen.c | 4 | ||||
-rw-r--r-- | test.toc | 6 | ||||
-rw-r--r-- | types.h | 2 |
6 files changed, 12 insertions, 7 deletions
@@ -562,7 +562,8 @@ static bool cgen_fn_args(CGenerator *g, FnExpr *f, U64 instance, U64 which_are_c static bool cgen_fn_header(CGenerator *g, FnExpr *f, U64 instance, U64 which_are_const) { bool out_param = cgen_uses_ptr(&f->ret_type); assert(cgen_should_gen_fn(f)); - cgen_write(g, "static "); + if (!(f->flags & FN_EXPR_EXPORT)) + cgen_write(g, "static "); if (out_param) { cgen_write(g, "void "); } else { diff --git a/decls_cgen.c b/decls_cgen.c index 5b9bde2..e19da8a 100644 --- a/decls_cgen.c +++ b/decls_cgen.c @@ -195,7 +195,8 @@ static bool cgen_decls_decl(CGenerator *g, Declaration *d) { Identifier ident = d->idents[i]; Type *type = decl_type_at_index(d, i); if (!type_is_compileonly(type)) { - cgen_write(g, "static "); + if (!(d->flags & DECL_EXPORT)) + cgen_write(g, "static "); if (!cgen_type_pre(g, type, d->where)) return false; cgen_write(g, " "); @@ -18,7 +18,6 @@ /* TODO: -make sure #export still works properly check for leaks --- warn about non-anonymous namespace statements of expression with compile-only types (e.g. int;) diff --git a/sdecls_cgen.c b/sdecls_cgen.c index 9ca41c4..b2f3900 100644 --- a/sdecls_cgen.c +++ b/sdecls_cgen.c @@ -88,6 +88,10 @@ static bool cgen_sdecls_decl(CGenerator *g, Declaration *d) { if (d->flags & DECL_HAS_EXPR) { if (!cgen_sdecls_expr(g, &d->expr)) return false; + if (d->flags & DECL_EXPORT) { + if (d->expr.kind == EXPR_FN) + d->expr.fn->flags |= FN_EXPR_EXPORT; + } } return true; } @@ -3,12 +3,12 @@ io ::= nms { }; n ::= nms { - x := 1; - counter ::= fn() int { x += 1; x }; + #export x := 1; + #export counter ::= fn() int { x += 1; x }; }; -main ::= fn() { +#export main ::= fn() { a := n.counter(); b := n.counter(); n.counter(); @@ -612,7 +612,7 @@ typedef struct ForExpr { enum { FN_EXPR_FOREIGN = 0x01, - FN_EXPR_HAS_BEEN_IMPORTED = 0x02 + FN_EXPR_EXPORT = 0x02 /* set by sdecls_cgen.c */ }; typedef struct FnExpr { |