From fb041033528ca03d1a3240cd1e4712b0d57a959c Mon Sep 17 00:00:00 2001 From: gingerBill Date: Wed, 19 Jul 2023 15:37:33 +0100 Subject: Add `defer` statements; add implicit `context` pointer to context stack --- src/tilde_proc.cpp | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) (limited to 'src/tilde_proc.cpp') diff --git a/src/tilde_proc.cpp b/src/tilde_proc.cpp index 2bb18a2de..e2764bc50 100644 --- a/src/tilde_proc.cpp +++ b/src/tilde_proc.cpp @@ -181,11 +181,8 @@ gb_internal void cg_procedure_begin(cgProcedure *p) { GB_ASSERT(p->type->kind == Type_Proc); TypeProc *pt = &p->type->Proc; - if (pt->params == nullptr) { - return; - } int param_index = 0; - for (Entity *e : pt->params->Tuple.variables) { + if (pt->params != nullptr) for (Entity *e : pt->params->Tuple.variables) { if (e->kind != Entity_Variable) { continue; } @@ -247,6 +244,28 @@ gb_internal void cg_procedure_begin(cgProcedure *p) { // } // } } + + if (p->type->Proc.calling_convention == ProcCC_Odin) { + // NOTE(bill): Push context on to stack from implicit parameter + + String name = str_lit("__.context_ptr"); + + Entity *e = alloc_entity_param(nullptr, make_token_ident(name), t_context_ptr, false, false); + e->flags |= EntityFlag_NoAlias; + + TB_Node *param = p->param_nodes[p->param_nodes.count-1]; + param = tb_inst_load(p->func, TB_TYPE_PTR, param, cast(TB_CharUnits)build_context.ptr_size, false); + + cgValue local = cg_value(param, t_context_ptr); + cgAddr addr = cg_addr(local); + map_set(&p->variable_map, e, addr); + + + cgContextData *cd = array_add_and_get(&p->context_stack); + cd->ctx = addr; + cd->scope_index = -1; + cd->uses = +1; // make sure it has been used already + } } gb_internal void cg_procedure_end(cgProcedure *p) { -- cgit v1.2.3