From c2e28acbb73e9c9c4a720664cbeb6b8eb6d4c978 Mon Sep 17 00:00:00 2001 From: Leo Tenenbaum Date: Tue, 14 Jan 2020 14:11:34 -0500 Subject: improved C names of exported things --- cgen.c | 8 ++++---- decls_cgen.c | 21 ++------------------- misc.c | 1 + test.toc | 1 + 4 files changed, 8 insertions(+), 23 deletions(-) diff --git a/cgen.c b/cgen.c index f43d468..e3deeec 100644 --- a/cgen.c +++ b/cgen.c @@ -281,10 +281,14 @@ static bool cgen_uses_ptr(Type *t) { } static void cgen_ident(CGenerator *g, Identifier i) { + if (i->export_id) { + cgen_write(g, "%s__", g->pkg_prefix); + } if (i == g->main_ident) { /* don't conflict with C's main! */ cgen_write(g, "main__"); } else { + cgen_indent(g); fprint_ident_reduced_charset(cgen_writing_to(g), i); } @@ -488,10 +492,6 @@ static bool cgen_fn_header(CGenerator *g, FnExpr *f, Location where, U64 instanc if (!cgen_type_pre(g, &f->ret_type, where)) return false; cgen_write(g, " "); } - if (f->export.id) { - assert(g->pkg_prefix); - cgen_write(g, "%s__", g->pkg_prefix); - } cgen_full_fn_name(g, f, instance); if (!out_param) { if (!cgen_type_post(g, &f->ret_type, where)) return false; diff --git a/decls_cgen.c b/decls_cgen.c index ddb9540..b2ff8a3 100644 --- a/decls_cgen.c +++ b/decls_cgen.c @@ -51,15 +51,6 @@ static bool cgen_fn_decl(CGenerator *g, FnExpr *f, Location where, U64 instance, cgen_write(g, ";"); cgen_nl(g); fn_exit(f); - char *pkg_name = g->evalr->typer->pkg_name; - if (pkg_name && f->export.id) { - /* allow use of function without referring to package in this file */ - cgen_write(g, "#define "); - cgen_full_fn_name(g, f, instance); - cgen_write(g, " %s__", pkg_name); - cgen_full_fn_name(g, f, instance); - cgen_nl(g); - } } return true; } @@ -153,26 +144,18 @@ 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)) { - if (ident->export_name) + if (ident->export_name) { cgen_write(g, "extern "); - else + } else cgen_write(g, "static "); if (!cgen_type_pre(g, type, d->where)) return false; cgen_write(g, " "); - if (ident->export_name) { - cgen_write(g, "%s__", g->pkg_prefix); - } cgen_ident(g, ident); if (!cgen_type_post(g, type, d->where)) return false; cgen_write(g, ";"); cgen_nl(g); - cgen_write(g, "#define "); - cgen_ident(g, ident); - cgen_write(g, " %s__", g->pkg_prefix); - cgen_ident(g, ident); - cgen_nl(g); } } } diff --git a/misc.c b/misc.c index b71b07c..0c817c1 100644 --- a/misc.c +++ b/misc.c @@ -52,3 +52,4 @@ static U32 rand_u32(U32 seed) { U64 seed64 = (U64)seed; return (U32)((seed64 * 0x832f0fda4e1a8642 + 0x41d49cd5459a2ab4) >> 32); } + diff --git a/test.toc b/test.toc index 1adf562..aa5fee8 100644 --- a/test.toc +++ b/test.toc @@ -13,4 +13,5 @@ point ::= pkg "point"; main ::= fn() { x : point.Point = point.mk_point(13, 14); + puti(x.x + x.y); }; \ No newline at end of file -- cgit v1.2.3