From e1b557118a67455b43ef77600c8e39682ca2fd60 Mon Sep 17 00:00:00 2001 From: fennecdjay Date: Thu, 26 Sep 2019 02:28:16 +0200 Subject: [PATCH] :art: Fix t_shred reference --- src/emit/emit.c | 20 ++++++++++++-------- src/vm/vm.c | 10 +++++++--- 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/src/emit/emit.c b/src/emit/emit.c index d2e5cdc1..e07b5b88 100644 --- a/src/emit/emit.c +++ b/src/emit/emit.c @@ -675,11 +675,8 @@ ANN static m_bool emit_exp_decl_global(const Emitter emit, const Var_Decl var_de if(is_obj && (is_array || !is_ref)) { const Instr assign = emit_add_instr(emit, Assign); assign->m_val = emit_var; -// TODO: (test type)watch me: am I needed ? - if(isa(type, emit->gwion->type[et_fork]) < 0) { // beware fork - const Instr instr = emit_add_instr(emit, RegAddRef); - instr->m_val = emit_var; - } + const Instr instr = emit_add_instr(emit, RegAddRef); + instr->m_val = emit_var; } return GW_OK; } @@ -1067,8 +1064,14 @@ ANN Instr emit_exp_spork(const Emitter emit, const Exp_Unary* unary) { const Instr push = emit_add_instr(emit, RegPush); push->m_val = SZ_INT; } +if(is_spork) { + const Instr spork = emit_add_instr(emit, is_spork ? SporkExp : ForkEnd); + spork->m_val = emit->code->stack_depth; +} else { const Instr spork = emit_add_instr(emit, is_spork ? SporkExp : ForkEnd); - spork->m_val = emit->code->stack_depth; + spork->m_val = exp_self(unary)->emit_var; +// spork->m_val2 = f->def->base->ret_type->size; +} } else { if(GET_FLAG(f, member) && is_fptr(emit->gwion, f->value_ref->type)) { const m_uint depth = f->def->stack_depth; @@ -1079,6 +1082,7 @@ ANN Instr emit_exp_spork(const Emitter emit, const Exp_Unary* unary) { } else emit_exp_spork_finish(emit, f->def->stack_depth); const Instr end = emit_add_instr(emit, is_spork ? SporkEnd : ForkEnd); + end->m_val = exp_self(unary)->emit_var; end->m_val2 = f->def->base->ret_type->size; } return ini; @@ -1145,7 +1149,7 @@ DECL_EXP_FUNC(emit) ANN2(1) static m_bool emit_exp(const Emitter emit, Exp exp, const m_bool ref) { do { CHECK_BB(exp_func[exp->exp_type](emit, &exp->d)) - if(ref && isa(exp->type, emit->gwion->type[et_object]) > 0 && isa(exp->type, emit->gwion->type[et_shred]) < 0 ) { // beware fork + if(ref && isa(exp->type, emit->gwion->type[et_object]) > 0) { const Instr instr = emit_add_instr(emit, RegAddRef); instr->m_val = exp->emit_var; } @@ -1194,7 +1198,7 @@ ANN static m_bool emit_stmt_return(const Emitter emit, const Stmt_Exp stmt) { if(stmt->val->exp_type == ae_exp_call && emit->env->func == stmt->val->d.exp_call.m_func) return optimize_taill_call(emit, &stmt->val->d.exp_call); CHECK_BB(emit_exp_pop_next(emit, stmt->val, 0)) - if(isa(stmt->val->type, emit->gwion->type[et_object]) > 0 && isa(stmt->val->type , emit->gwion->type[et_shred]) < 0) // beware shred + if(isa(stmt->val->type, emit->gwion->type[et_object]) > 0) emit_add_instr(emit, RegAddRef); } vector_add(&emit->code->stack_return, (vtype)emit_add_instr(emit, Goto)); diff --git a/src/vm/vm.c b/src/vm/vm.c index 4da59501..d6313b24 100644 --- a/src/vm/vm.c +++ b/src/vm/vm.c @@ -117,6 +117,7 @@ ANN static inline m_bool overflow_(const m_bit* mem, const VM_Shred c) { ANN static inline VM_Shred init_spork_shred(const VM_Shred shred, const VM_Code code) { const VM_Shred sh = new_shred_base(shred, code); vm_add_shred(shred->info->vm, sh); + vector_add(&shred->gc, sh->info->me); sh->tick->parent = shred->tick; if(!shred->tick->child.ptr) vector_init(&shred->tick->child); @@ -127,6 +128,8 @@ ANN static inline VM_Shred init_spork_shred(const VM_Shred shred, const VM_Code ANN static inline VM_Shred init_fork_shred(const VM_Shred shred, const VM_Code code) { const VM_Shred sh = new_shred_base(shred, code); vm_fork(shred->info->vm, sh); + assert(sh->info->me); + vector_add(&shred->gc, sh->info->me); return sh; } @@ -650,8 +653,6 @@ sporkmemberfptr: *(m_uint*)(a.child->reg+VAL-SZ_INT*2) = *(m_uint*)(reg-SZ_INT*2); a.child->reg += VAL; DISPATCH() - -//exit(2); sporkexp: // LOOP_OPTIM for(m_uint i = 0; i < VAL; i+= SZ_INT) @@ -660,7 +661,10 @@ sporkexp: forkend: fork_launch(vm, a.child->info->me, VAL2); sporkend: - *(M_Object*)(reg-SZ_INT) = a.child->info->me; + if(!VAL) + *(M_Object*)(reg-SZ_INT) = a.child->info->me; + else + *(M_Object**)(reg-SZ_INT) = &a.child->info->me; DISPATCH() brancheqint: reg -= SZ_INT; -- 2.43.0