From: fennecdjay Date: Tue, 24 Sep 2019 12:49:49 +0000 (+0200) Subject: :art: Fix gc detection and introduce NoOp X-Git-Tag: nightly~2210 X-Git-Url: http://10.10.0.4:5575/?a=commitdiff_plain;h=2537032a0c8709f25f6cf2fad31879853fe9584e;p=gwion.git :art: Fix gc detection and introduce NoOp --- diff --git a/include/instr.h b/include/instr.h index 9a545cbe..6ad3d4ed 100644 --- a/include/instr.h +++ b/include/instr.h @@ -58,6 +58,7 @@ INSTR(PopArrayClass); INSTR(DotTmpl); INSTR(GTmpl); +#define NoOp (f_instr)256 struct dottmpl_ { size_t len; diff --git a/src/emit/emit.c b/src/emit/emit.c index e305a59a..42deaa1d 100644 --- a/src/emit/emit.c +++ b/src/emit/emit.c @@ -1014,12 +1014,13 @@ static inline void stack_alloc_this(const Emitter emit) { static m_bool scoped_stmt(const Emitter emit, const Stmt stmt, const m_bool pop) { ++emit->env->scope->depth; emit_push_scope(emit); - const m_bool pure = !vector_back(&emit->info->pure); - if(!pure) - emit_add_instr(emit, GcIni); + const Instr gc = emit_add_instr(emit, NoOp); CHECK_BB(emit_stmt(emit, stmt, pop)) - if(!pure) + const m_bool pure = !vector_back(&emit->info->pure); + if(!pure) { + gc->opcode = eGcIni; emit_add_instr(emit, GcEnd); + } emit_pop_scope(emit); --emit->env->scope->depth; return GW_OK; diff --git a/src/vm/vm_code.c b/src/vm/vm_code.c index bcb1e2bc..3335c0e6 100644 --- a/src/vm/vm_code.c +++ b/src/vm/vm_code.c @@ -15,7 +15,7 @@ #include "operator.h" #include "import.h" -ANN /*static*/ void free_code_instr(const Vector v, const Gwion gwion) { +ANN void free_code_instr(const Vector v, const Gwion gwion) { for(m_uint i = vector_size(v) + 1; --i;) { const Instr instr = (Instr)vector_at(v, i - 1); const f_freearg f = (f_freearg)(map_get(&gwion->data->freearg, instr->opcode) ?: @@ -30,6 +30,7 @@ ANN static void _free_code_instr(const Vector v, const Gwion gwion) { free_code_instr(v, gwion); free_vector(gwion->mp, v); } + ANN static void free_vm_code(VM_Code a, Gwion gwion) { if(a->memoize) memoize_end(gwion->mp, a->memoize); @@ -63,6 +64,8 @@ ANN static m_bit* tobytecode(MemPool p, const VM_Code code) { if(instr->opcode < eGack) memcpy(ptr + i*BYTECODE_SZ, instr, BYTECODE_SZ); else { + if(instr->execute == NoOp) + continue; *(m_bit*)(ptr + (i*BYTECODE_SZ)) = instr->opcode; *(Instr*)(ptr + (i*BYTECODE_SZ) + SZ_INT) = instr; *(f_instr*)(ptr + (i*BYTECODE_SZ) + SZ_INT*2) = instr->execute;