From f8f2ad5995ec67fd9b7a48411e0de2eec3f99486 Mon Sep 17 00:00:00 2001 From: fennecdjay Date: Wed, 19 Oct 2022 13:10:16 +0200 Subject: [PATCH] :art: dissalow return in defer statements --- ast | 2 +- include/emit.h | 1 - src/emit/emit.c | 21 +++------------------ 3 files changed, 4 insertions(+), 20 deletions(-) diff --git a/ast b/ast index f6c9ae7f..d341be4f 160000 --- a/ast +++ b/ast @@ -1 +1 @@ -Subproject commit f6c9ae7feb355a64345da5c99c479a32a310df11 +Subproject commit d341be4f3a787e5c4dd80f7ab8bc919a7ca807ec diff --git a/include/emit.h b/include/emit.h index 5cbe4241..942f67d4 100644 --- a/include/emit.h +++ b/include/emit.h @@ -50,7 +50,6 @@ 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 9f1a497e..f0f8883e 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,14 +202,7 @@ ANN static m_bool _emit_defers(const Emitter emit) { return GW_OK; } -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) { +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; @@ -218,13 +211,6 @@ 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)); @@ -2065,8 +2051,7 @@ 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) { - if(!emit->status.in_defer) - CHECK_BB(emit_defers2(emit)); + 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; -- 2.43.0