From: fennecdjay Date: Mon, 17 Oct 2022 17:53:58 +0000 (+0200) Subject: :art: defer in defer X-Git-Tag: nightly~212 X-Git-Url: http://10.10.0.4:5575/?a=commitdiff_plain;h=ad3e1e9807862b2a441fe3fba95b1c3371600555;p=gwion.git :art: defer in defer --- diff --git a/include/emit.h b/include/emit.h index 942f67d4..5cbe4241 100644 --- a/include/emit.h +++ b/include/emit.h @@ -50,6 +50,7 @@ typedef struct EmitterStatus { uint16_t line; uint32_t effect; // offset of last throw effect bool in_return; + bool in_defer; } EmitterStatus; struct Emitter_ { diff --git a/src/emit/emit.c b/src/emit/emit.c index f0f8883e..9f1a497e 100644 --- a/src/emit/emit.c +++ b/src/emit/emit.c @@ -194,7 +194,7 @@ ANN static void struct_pop(const Emitter emit, const Type type, ANN static m_bool emit_stmt(const Emitter emit, const Stmt stmt); -ANN static m_bool emit_defers(const Emitter emit) { +ANN static m_bool _emit_defers(const Emitter emit) { if (!vector_size(&emit->code->frame->defer)) return GW_OK; Stmt stmt; while ((stmt = (Stmt)vector_pop(&emit->code->frame->defer))) @@ -202,7 +202,14 @@ ANN static m_bool emit_defers(const Emitter emit) { return GW_OK; } -ANN static m_bool emit_defers2(const Emitter emit) { +ANN static m_bool emit_defers(const Emitter emit) { + emit->status.in_defer = true; + const m_bool ret = _emit_defers(emit); + emit->status.in_defer = false; + return ret; +} + +ANN static m_bool _emit_defers2(const Emitter emit) { for (m_uint i = vector_size(&emit->code->frame->defer) + 1; --i;) { const Stmt stmt = (Stmt)vector_at(&emit->code->frame->defer, i - 1); if (!stmt) break; @@ -211,6 +218,13 @@ ANN static m_bool emit_defers2(const Emitter emit) { return GW_OK; } +ANN static m_bool emit_defers2(const Emitter emit) { + emit->status.in_defer = true; + const m_bool ret = _emit_defers2(emit); + emit->status.in_defer = false; + return ret; +} + ANN static m_int _frame_pop(const Emitter emit) { Frame *frame = emit->code->frame; DECL_OB(const Local *, l, = (Local *)vector_pop(&frame->stack)); @@ -2051,7 +2065,8 @@ ANN static m_bool optimize_tail_call(const Emitter emit, const Exp_Call *e) { } ANN static m_bool emit_stmt_return(const Emitter emit, const Stmt_Exp stmt) { - CHECK_BB(emit_defers2(emit)); + if(!emit->status.in_defer) + CHECK_BB(emit_defers2(emit)); if (stmt->val) { if (stmt->val->exp_type == ae_exp_call) { const Func f = stmt->val->d.exp_call.func->type->info->func;