Merge pull request #5558 from odin-lang/bill/init-fini-changes

`@(init)` & `@(finit)` Changes.
This commit is contained in:
gingerBill
2025-08-10 12:47:15 +01:00
committed by GitHub
67 changed files with 226 additions and 136 deletions

View File

@@ -1851,6 +1851,12 @@ gb_internal void check_entity_decl(CheckerContext *ctx, Entity *e, DeclInfo *d,
c.scope = d->scope;
c.decl = d;
c.type_level = 0;
c.curr_proc_calling_convention = ProcCC_Contextless;
auto prev_flags = c.scope->flags;
defer (c.scope->flags = prev_flags);
c.scope->flags &= ~ScopeFlag_ContextDefined;
e->parent_proc_decl = c.curr_proc_decl;
e->state = EntityState_InProgress;

View File

@@ -8169,8 +8169,12 @@ gb_internal ExprKind check_call_expr(CheckerContext *c, Operand *operand, Ast *c
if (pt->kind == Type_Proc && pt->Proc.calling_convention == ProcCC_Odin) {
if ((c->scope->flags & ScopeFlag_ContextDefined) == 0) {
ERROR_BLOCK();
error(call, "'context' has not been defined within this scope, but is required for this procedure call");
error_line("\tSuggestion: 'context = runtime.default_context()'");
if (c->scope->flags & ScopeFlag_File) {
error(call, "Procedures requiring a 'context' cannot be called at the global scope");
} else {
error(call, "'context' has not been defined within this scope, but is required for this procedure call");
error_line("\tSuggestion: 'context = runtime.default_context()'");
}
}
}

View File

@@ -2675,6 +2675,10 @@ gb_internal void generate_minimum_dependency_set_internal(Checker *c, Entity *st
is_init = false;
}
if (t->Proc.calling_convention != ProcCC_Contextless) {
error(e->token, "@(init) procedures must be declared as \"contextless\"");
}
if ((e->scope->flags & (ScopeFlag_File|ScopeFlag_Pkg)) == 0) {
error(e->token, "@(init) procedures must be declared at the file scope");
is_init = false;
@@ -2689,6 +2693,7 @@ gb_internal void generate_minimum_dependency_set_internal(Checker *c, Entity *st
error(e->token, "An @(init) procedure must not use a blank identifier as its name");
}
if (is_init) {
add_dependency_to_set(c, e);
array_add(&c->info.init_procedures, e);
@@ -2706,6 +2711,10 @@ gb_internal void generate_minimum_dependency_set_internal(Checker *c, Entity *st
is_fini = false;
}
if (t->Proc.calling_convention != ProcCC_Contextless) {
error(e->token, "@(fini) procedures must be declared as \"contextless\"");
}
if ((e->scope->flags & (ScopeFlag_File|ScopeFlag_Pkg)) == 0) {
error(e->token, "@(fini) procedures must be declared at the file scope");
is_fini = false;