harec

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

commit 99fc143b4b307573d7262f75757828e79e7bf508
parent 9e9311de0eed67358355ce7623b5e6ee1a5b166a
Author: Drew DeVault <sir@cmpwn.com>
Date:   Wed, 20 Jan 2021 16:28:30 -0500

typedef: emit @symbol

Diffstat:
Minclude/check.h | 1+
Msrc/check.c | 2++
Msrc/typedef.c | 14+++++++++++---
3 files changed, 14 insertions(+), 3 deletions(-)

diff --git a/include/check.h b/include/check.h @@ -46,6 +46,7 @@ enum declaration_type { struct declaration { enum declaration_type type; struct identifier ident; + char *symbol; bool exported; union { struct function_decl func; diff --git a/src/check.c b/src/check.c @@ -1207,6 +1207,7 @@ check_function(struct context *ctx, if (afndecl->symbol) { decl->ident.name = strdup(afndecl->symbol); + decl->symbol = strdup(afndecl->symbol); } else { mkident(ctx, &decl->ident, &afndecl->ident); } @@ -1293,6 +1294,7 @@ check_global(struct context *ctx, if (agdecl->symbol) { decl->ident.name = strdup(agdecl->symbol); + decl->symbol = strdup(agdecl->symbol); } else { mkident(ctx, &decl->ident, &agdecl->ident); } diff --git a/src/typedef.c b/src/typedef.c @@ -53,7 +53,11 @@ emit_func(struct declaration *decl, FILE *out) { char *ident = identifier_unparse(&decl->ident); // TODO: Emit @symbol const struct type *fntype = decl->func.type; - fprintf(out, "export%s fn %s(", + fprintf(out, "export"); + if (decl->symbol) { + fprintf(out, " @symbol(\"%s\")", decl->symbol); + } + fprintf(out, "%s fn %s(", (fntype->func.flags & FN_NORETURN) ? " @noreturn" : "", ident); @@ -74,8 +78,12 @@ emit_func(struct declaration *decl, FILE *out) static void emit_global(struct declaration *decl, FILE *out) { - char *ident = identifier_unparse(&decl->ident); // TODO: Emit @symbol - fprintf(out, "export let %s: ", ident); + char *ident = identifier_unparse(&decl->ident); + fprintf(out, "export"); + if (decl->symbol) { + fprintf(out, " @symbol(\"%s\") ", decl->symbol); + } + fprintf(out, " let %s: ", ident); emit_type(decl->global.type, out); fprintf(out, ";\n"); }