summaryrefslogtreecommitdiff
path: root/src/codegen/codegen_stmt.c
diff options
context:
space:
mode:
authorZuhaitz Méndez Fernández de Aránguiz <zuhaitz@debian>2026-01-27 01:22:42 +0000
committerZuhaitz Méndez Fernández de Aránguiz <zuhaitz@debian>2026-01-27 01:22:42 +0000
commit938773d9cc062fd028f6560b1127a2ecd23f61c3 (patch)
tree403aacd629975440ba23a645975c34a141d634ee /src/codegen/codegen_stmt.c
parent2f47bdf7f49f05bd421e4182635f489c8cae01b3 (diff)
Fixed constant hex/oct bug + Fixed some of the examples (work in progress) + added bootloader example (I will add some docs)
Diffstat (limited to 'src/codegen/codegen_stmt.c')
-rw-r--r--src/codegen/codegen_stmt.c35
1 files changed, 35 insertions, 0 deletions
diff --git a/src/codegen/codegen_stmt.c b/src/codegen/codegen_stmt.c
index 43e5bb5..6e41109 100644
--- a/src/codegen/codegen_stmt.c
+++ b/src/codegen/codegen_stmt.c
@@ -697,6 +697,41 @@ void codegen_node_single(ParserContext *ctx, ASTNode *node, FILE *out)
fprintf(out, "{\n");
char *prev_ret = g_current_func_ret_type;
g_current_func_ret_type = node->func.ret_type;
+
+ // Initialize drop flags for arguments that implement Drop
+ for (int i = 0; i < node->func.arg_count; i++)
+ {
+ Type *arg_type = node->func.arg_types[i];
+ char *arg_name = node->func.param_names[i];
+ if (arg_type && arg_name)
+ {
+ // Check if type implements Drop
+ int has_drop = 0;
+ if (arg_type->kind == TYPE_STRUCT && arg_type->name)
+ {
+ ASTNode *def = find_struct_def(ctx, arg_type->name);
+ if (def && def->type == NODE_STRUCT && def->type_info &&
+ def->type_info->traits.has_drop)
+ {
+ has_drop = 1;
+ }
+ else if (def)
+ {
+ // No drop needed
+ }
+ else
+ {
+ // No struct def found
+ }
+ }
+
+ if (has_drop)
+ {
+ fprintf(out, " int __z_drop_flag_%s = 1;\n", arg_name);
+ }
+ }
+ }
+
codegen_walker(ctx, node->func.body, out);
for (int i = defer_count - 1; i >= 0; i--)
{