summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cgen.c3
-rw-r--r--decls_cgen.c3
-rw-r--r--main.c1
-rw-r--r--sdecls_cgen.c4
-rw-r--r--test.toc6
-rw-r--r--types.h2
6 files changed, 12 insertions, 7 deletions
diff --git a/cgen.c b/cgen.c
index a193d6d..62fd4fc 100644
--- a/cgen.c
+++ b/cgen.c
@@ -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, " ");
diff --git a/main.c b/main.c
index 3e9ee3d..0f84c4e 100644
--- a/main.c
+++ b/main.c
@@ -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;
}
diff --git a/test.toc b/test.toc
index 32c2955..7b57b1b 100644
--- a/test.toc
+++ b/test.toc
@@ -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();
diff --git a/types.h b/types.h
index c81fdfa..f0f6025 100644
--- a/types.h
+++ b/types.h
@@ -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 {