summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/ast/ast.h1
-rw-r--r--src/codegen/codegen_decl.c6
-rw-r--r--src/codegen/codegen_stmt.c3
-rw-r--r--src/parser/parser_core.c14
-rw-r--r--src/parser/parser_stmt.c16
5 files changed, 37 insertions, 3 deletions
diff --git a/src/ast/ast.h b/src/ast/ast.h
index c971d54..967f27f 100644
--- a/src/ast/ast.h
+++ b/src/ast/ast.h
@@ -422,6 +422,7 @@ struct ASTNode
int is_packed; // @packed attribute.
int align; // @align(N) attribute, 0 = default.
int is_incomplete; // Forward declaration (prototype)
+ int is_export; // @export attribute
char **used_structs; // Names of structs used/mixed-in
int used_struct_count;
} strct;
diff --git a/src/codegen/codegen_decl.c b/src/codegen/codegen_decl.c
index aecf45e..eb53911 100644
--- a/src/codegen/codegen_decl.c
+++ b/src/codegen/codegen_decl.c
@@ -380,10 +380,14 @@ void emit_struct_defs(ParserContext *ctx, ASTNode *node, FILE *out)
{
fprintf(out, " __attribute__((packed))");
}
- else if (node->strct.align)
+ if (node->strct.align)
{
fprintf(out, " __attribute__((aligned(%d)))", node->strct.align);
}
+ if (node->strct.is_export)
+ {
+ fprintf(out, " __attribute__((visibility(\"default\")))");
+ }
fprintf(out, ";\n\n");
}
else if (node->type == NODE_ENUM)
diff --git a/src/codegen/codegen_stmt.c b/src/codegen/codegen_stmt.c
index 1679d97..c823b13 100644
--- a/src/codegen/codegen_stmt.c
+++ b/src/codegen/codegen_stmt.c
@@ -653,7 +653,7 @@ void codegen_node_single(ParserContext *ctx, ASTNode *node, FILE *out)
int has_attrs = node->func.constructor || node->func.destructor ||
node->func.noinline || node->func.unused || node->func.weak ||
node->func.cold || node->func.hot || node->func.noreturn ||
- node->func.pure || node->func.section;
+ node->func.pure || node->func.section || node->func.is_export;
if (has_attrs)
{
fprintf(out, "__attribute__((");
@@ -675,6 +675,7 @@ void codegen_node_single(ParserContext *ctx, ASTNode *node, FILE *out)
EMIT_ATTR(node->func.hot, "hot");
EMIT_ATTR(node->func.noreturn, "noreturn");
EMIT_ATTR(node->func.pure, "pure");
+ EMIT_ATTR(node->func.is_export, "visibility(\"default\")");
if (node->func.section)
{
if (!first)
diff --git a/src/parser/parser_core.c b/src/parser/parser_core.c
index d575693..ac578a1 100644
--- a/src/parser/parser_core.c
+++ b/src/parser/parser_core.c
@@ -516,6 +516,20 @@ ASTNode *parse_program_nodes(ParserContext *ctx, Lexer *l)
}
}
+ if (s && s->type == NODE_STRUCT)
+ {
+ s->strct.is_export = attr_export;
+ s->strct.is_packed = attr_packed || s->strct.is_packed;
+ if (attr_align)
+ {
+ s->strct.align = attr_align;
+ }
+ if (attr_deprecated && s->strct.name)
+ {
+ register_deprecated_func(ctx, s->strct.name, deprecated_msg);
+ }
+ }
+
if (s)
{
if (!h)
diff --git a/src/parser/parser_stmt.c b/src/parser/parser_stmt.c
index 6250392..ab5b89c 100644
--- a/src/parser/parser_stmt.c
+++ b/src/parser/parser_stmt.c
@@ -3178,6 +3178,21 @@ char *run_comptime_block(ParserContext *ctx, Lexer *l)
curr = next;
}
+ {
+ StructRef *ref = ctx->parsed_funcs_list;
+ while (ref)
+ {
+ ASTNode *fn = ref->node;
+ if (fn && fn->type == NODE_FUNCTION && fn->func.is_comptime)
+ {
+ emit_func_signature(f, fn, NULL);
+ fprintf(f, ";\n");
+ codegen_node_single(ctx, fn, f);
+ }
+ ref = ref->next;
+ }
+ }
+
fprintf(f, "int main() {\n");
curr = stmts;
while (curr)
@@ -3241,7 +3256,6 @@ char *run_comptime_block(ParserContext *ctx, Lexer *l)
output_src = xstrdup(""); // Empty output is valid
}
- // Cleanup
remove(filename);
remove(bin);
remove(out_file);