From 60b2844436fd151900419a142e2ebdf5744632cf Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=A9mie=20Astor?= Date: Wed, 30 Dec 2020 23:22:14 +0100 Subject: [PATCH] :art: Remove addref for ops --- src/emit/emit.c | 15 ++++++++++----- src/lib/array.c | 12 ++++++------ src/lib/event.c | 1 - src/lib/modules.c | 1 - src/lib/object_op.c | 4 ---- src/lib/ptr.c | 3 ++- src/lib/string.c | 2 -- src/lib/ugen.c | 2 -- src/vm/vm.c | 2 +- 9 files changed, 19 insertions(+), 23 deletions(-) diff --git a/src/emit/emit.c b/src/emit/emit.c index ec0d441c..39a9c8be 100644 --- a/src/emit/emit.c +++ b/src/emit/emit.c @@ -987,9 +987,9 @@ ANN static m_bool emit_exp_binary(const Emitter emit, const Exp_Binary* bin) { const Exp rhs = bin->rhs; CHECK_BB(emit_exp_pop_next(emit, lhs)) CHECK_BB(emit_exp_pop_next(emit, rhs)) - const m_int size = exp_size(rhs); - emit_exp_addref1(emit, lhs, -exp_size(lhs) - size); - emit_exp_addref1(emit, rhs, -size); +// const m_int size = exp_size(rhs); +// emit_exp_addref1(emit, lhs, -exp_size(lhs) - size); +// emit_exp_addref1(emit, rhs, -size); struct Op_Import opi = { .op=bin->op, .lhs=lhs->type, .rhs=rhs->type, .pos=exp_self(bin)->pos, .data=(uintptr_t)bin, .op_type=op_binary }; return op_emit(emit, &opi); @@ -1009,7 +1009,6 @@ ANN static m_bool emit_exp_post(const Emitter emit, const Exp_Postfix* post) { struct Op_Import opi = { .op=post->op, .lhs=post->exp->type, .data=(uintptr_t)post, .op_type=op_postfix }; CHECK_BB(emit_exp(emit, post->exp)) - emit_exp_addref(emit, post->exp, -exp_totalsize(post->exp)); return op_emit(emit, &opi); } @@ -1372,7 +1371,6 @@ ANN static m_bool emit_exp_unary(const Emitter emit, const Exp_Unary* unary) { struct Op_Import opi = { .op=unary->op, .data=(uintptr_t)unary, .op_type=op_unary }; if(unary->unary_type == unary_exp && unary->op != insert_symbol("spork") && unary->op != insert_symbol("fork")) { CHECK_BB(emit_exp_pop_next(emit, unary->exp)) - emit_exp_addref1(emit, unary->exp, -exp_size(unary->exp)); opi.rhs = unary->exp->type; } return op_emit(emit, &opi); @@ -1483,6 +1481,13 @@ ANN2(1) /*static */m_bool emit_exp(const Emitter emit, /* const */Exp e) { CHECK_BB(emit_exp_func[exp->exp_type](emit, &exp->d)) if(exp->cast_to) CHECK_BB(emit_implicit_cast(emit, exp, exp->cast_to)) + if(isa(e->type, emit->gwion->type[et_object]) > 0 && + (e->cast_to ? isa(e->cast_to, emit->gwion->type[et_object]) > 0 : 1) && + e->exp_type == ae_exp_decl && GET_FLAG(e->d.exp_decl.td, late) && !exp_getvar(e)) { + const Instr instr = emit_add_instr(emit, GWOP_EXCEPT); + instr->m_val = -SZ_INT; + } + } while((exp = exp->next)); return GW_OK; } diff --git a/src/lib/array.c b/src/lib/array.c index e356907f..d3b62012 100644 --- a/src/lib/array.c +++ b/src/lib/array.c @@ -217,8 +217,6 @@ static INSTR(ArrayConcatLeft) { } m_bit *data = more->ptr + ARRAY_OFFSET; memmove(ARRAY_PTR(base) + (len - 1) * sz, data, sz); - release(obase, shred); - release(omore, shred); } static INSTR(ArrayConcatRight) { @@ -235,8 +233,6 @@ static INSTR(ArrayConcatRight) { } memmove(ARRAY_PTR(base) + (ARRAY_LEN(more) + len - 1) * sz, ARRAY_PTR(base), len * sz); memmove(ARRAY_PTR(base), ARRAY_PTR(more), ARRAY_LEN(more) * sz); - release(obase, shred); - release(omore, shred); } static OP_EMIT(opem_array_sr) { @@ -245,7 +241,8 @@ static OP_EMIT(opem_array_sr) { return emit_array_shift(emit, ArrayConcatRight); const Instr pop = emit_add_instr(emit, RegMove); pop->m_val = -SZ_INT; - emit_gc(emit, 0); + if(isa(bin->rhs->type, emit->gwion->type[et_object]) > 0) + emit_add_instr(emit, RegAddRef); (void)emit_add_instr(emit, ArrayAppendFront); return GW_OK; } @@ -256,7 +253,10 @@ static OP_EMIT(opem_array_sl) { return emit_array_shift(emit, ArrayConcatLeft); const Instr pop = emit_add_instr(emit, RegMove); pop->m_val = -bin->rhs->type->size; - emit_gc(emit, -SZ_INT); + if(isa(bin->rhs->type, emit->gwion->type[et_object]) > 0){ + const Instr ref = emit_add_instr(emit, RegAddRef); + ref->m_val = -SZ_INT; + } emit_add_instr(emit, ArrayAppend); return GW_OK; } diff --git a/src/lib/event.c b/src/lib/event.c index 0d7c09d4..04ae61f7 100644 --- a/src/lib/event.c +++ b/src/lib/event.c @@ -24,7 +24,6 @@ static INSTR(EventWait) { const Vector v = EV_SHREDS(event); vector_add(v, (vtype)shred); *(m_int*)REG(-SZ_INT) = 1; - _release(event, shred); } static MFUN(event_signal) { diff --git a/src/lib/modules.c b/src/lib/modules.c index 4120a760..ba336327 100644 --- a/src/lib/modules.c +++ b/src/lib/modules.c @@ -255,7 +255,6 @@ static INSTR(UsrUGenTick) { free_vm_shred(uu->shred); UGEN(o)->module.gen.tick = usrugen_tick; const VM_Code code = *(VM_Code*)(shred->reg-offset); - release(o, shred); if(!code) Except(shred, "[NullTickException]"); uu->shred = new_vm_shred(shred->info->vm->gwion->mp, *(VM_Code*)(shred->reg-offset)); diff --git a/src/lib/object_op.c b/src/lib/object_op.c index 3ad5a6b7..f851ae69 100644 --- a/src/lib/object_op.c +++ b/src/lib/object_op.c @@ -22,8 +22,6 @@ static INSTR(name##Object) { \ const M_Object lhs = *(M_Object*)REG(-SZ_INT); \ const M_Object rhs = *(M_Object*)REG(0); \ *(m_uint*)REG(-SZ_INT) = (lhs op rhs); \ - release(lhs, shred); \ - release(rhs, shred); \ } describe_logical(Eq, ==) @@ -295,8 +293,6 @@ ANN void struct_release(const VM_Shred shred, const Type base, const m_bit *ptr) static OP_EMIT(opem_not_object) { const Vector v = &emit->code->instr; - const Instr last = (Instr)vector_pop(v); - mp_free(emit->gwion->mp, Instr, last); const Instr back = (Instr)vector_back(v); if(back->opcode == eGWOP_EXCEPT) { vector_pop(v); diff --git a/src/lib/ptr.c b/src/lib/ptr.c index cbb1793e..069662bc 100644 --- a/src/lib/ptr.c +++ b/src/lib/ptr.c @@ -51,7 +51,8 @@ static INSTR(instr_ptr_assign) { static INSTR(instr_ptr_assign_obj) { m_bit **o = *(m_bit***)REG(0); - release(*(M_Object*)o, shred); + //release(*(M_Object*)o, shred); + // addref to object? *o = *(m_bit**)REG(-SZ_INT); } diff --git a/src/lib/string.c b/src/lib/string.c index 56cc864d..fce5cff9 100644 --- a/src/lib/string.c +++ b/src/lib/string.c @@ -21,8 +21,6 @@ static INSTR(String_##name) { \ const M_Object lhs = *(M_Object*)REG(-SZ_INT); \ const M_Object rhs = *(M_Object*)REG(0); \ *(m_int*)REG(-SZ_INT) = action; \ - release(lhs, shred); \ - release(rhs, shred); \ } describe_string_logical(eq, (lhs && rhs && STRING(lhs) == STRING(rhs)) || (!lhs && !rhs)) describe_string_logical(neq, !(lhs && rhs && STRING(lhs) == STRING(rhs)) || (!lhs && !rhs)) diff --git a/src/lib/ugen.c b/src/lib/ugen.c index a7ad949a..0cdfc8c1 100644 --- a/src/lib/ugen.c +++ b/src/lib/ugen.c @@ -154,8 +154,6 @@ describe_connect(C,vector_add) describe_connect(Disc,vector_rem2) ANN static void release_connect(const VM_Shred shred) { - _release(*(M_Object*)REG(0), shred); - _release(*(M_Object*)REG(SZ_INT), shred); *(M_Object*)REG(0) = *(M_Object*)REG(SZ_INT); PUSH_REG(shred, SZ_INT); } diff --git a/src/vm/vm.c b/src/vm/vm.c index c84c024f..fe7bc61b 100644 --- a/src/vm/vm.c +++ b/src/vm/vm.c @@ -776,9 +776,9 @@ objassign: { const M_Object o = **(M_Object**)(reg -SZ_INT); if(o) { - --o->ref; _release(o, shred); } + ++(*(M_Object*)(reg -SZ_INT*2))->ref; } assign: reg -= SZ_INT; -- 2.43.0