From c62e7a3846751cdcf41364ba1a519b020e92be37 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=A9mie=20Astor?= Date: Sun, 19 Sep 2021 19:17:17 +0200 Subject: [PATCH] :art: Updates --- src/emit/emit.c | 12 ++++++++---- src/lib/object_op.c | 21 +++++++++++++++------ src/lib/shred.c | 2 +- src/lib/vararg.c | 9 ++++++--- src/parse/check.c | 4 +--- src/vm/vm.c | 3 +-- tests/plug/enum_fail3.c | 2 +- tests/plug/func_tmpl.c | 2 +- 8 files changed, 34 insertions(+), 21 deletions(-) diff --git a/src/emit/emit.c b/src/emit/emit.c index 87f4fdf5..60f113c5 100644 --- a/src/emit/emit.c +++ b/src/emit/emit.c @@ -1819,7 +1819,7 @@ ANN static m_bool emit_implicit_cast(const Emitter emit, ANN static Instr _flow(const Emitter emit, const Exp e, const m_bool b) { CHECK_BO(emit_exp_pop_next(emit, e)); - emit_exp_addref1(emit, e, -exp_size(e)); // ???? +// emit_exp_addref1(emit, e, -exp_size(e)); // ???? struct Op_Import opi = { .op = insert_symbol(b ? "@conditional" : "@unconditional"), .rhs = e->type, @@ -2412,9 +2412,9 @@ ANN static inline m_bool emit_exp1(const Emitter emit, const Exp e) { ANN static m_bool emit_case_head(const Emitter emit, const Exp base, const Exp e, const Symbol op, const Vector v) { CHECK_BB(emit_exp1(emit, base)); - emit_exp_addref1(emit, base, -exp_size(base)); +// emit_exp_addref1(emit, base, -exp_size(base)); CHECK_BB(emit_exp1(emit, e)); - emit_exp_addref1(emit, e, -exp_size(e)); +// emit_exp_addref1(emit, e, -exp_size(e)); const Exp_Binary bin = {.lhs = base, .rhs = e, .op = op}; struct Exp_ ebin = { .d = {.exp_binary = bin}, @@ -2460,7 +2460,7 @@ ANN static Symbol case_op(const Emitter emit, const Exp base, const Exp e, if (!nspc_lookup_value1(emit->env->curr, e->d.prim.d.var)) { if (!n) { CHECK_BO(emit_exp(emit, base)); - emit_exp_addref(emit, base, -exp_totalsize(base)); +// emit_exp_addref(emit, base, -exp_totalsize(base)); regpop(emit, base->type->size); } CHECK_BO(case_value(emit, base, e)); @@ -2679,6 +2679,10 @@ ANN static inline VM_Code _emit_func_def_code(const Emitter emit, const Func func) { if(!strcmp(s_name(func->def->base->xid), "new")) emit_add_instr(emit, RegPushMem); + if (fbflag(func->def->base, fbflag_variadic)) { + Instr instr = emit_add_instr(emit, ObjectRelease); + instr->m_val = func->def->stack_depth - SZ_INT; + } return !fbflag(func->def->base, fbflag_internal) ? finalyze(emit, FuncReturn) : emit_internal(emit, func); } diff --git a/src/lib/object_op.c b/src/lib/object_op.c index 0850151e..f41a24d4 100644 --- a/src/lib/object_op.c +++ b/src/lib/object_op.c @@ -34,6 +34,8 @@ static OP_CHECK(opck_object_at) { SET_FLAG(bin->rhs->d.exp_decl.list->self->value, late); exp_setvar(bin->rhs, 1); CHECK_BO(isa(bin->lhs->type, bin->rhs->type)); + bin->lhs->ref = bin->rhs; +// bin->rhs-> = bin->lhs; return bin->rhs->type; } /* @@ -45,13 +47,19 @@ static bool exp_func(const Exp exp) { // !strcmp(s_name(exp->d.exp_call.func->type->info->func->def->base->xid), "new"): } */ + +ANN void unset_local(const Emitter emit, void *const l); static OP_EMIT(opem_object_at) { -// const Exp_Binary *bin = (Exp_Binary *)data; -// if(!exp_func(bin->lhs)) { - const Instr addref = emit_add_instr(emit, RegAddRef); - addref->m_val = -SZ_INT * 2; -// } - (void)emit_add_instr(emit, ObjectAssign); + const Exp_Binary *bin = (Exp_Binary *)data; + + if(!bin->rhs->data) { + const Instr addref = emit_add_instr(emit, RegAddRef); + addref->m_val = -SZ_INT * 2; + } else unset_local(emit, bin->rhs->data); + if (bin->rhs->exp_type != ae_exp_decl) + (void)emit_add_instr(emit, ObjectAssign); + else + (void)emit_add_instr(emit, Assign); return GW_OK; } @@ -222,6 +230,7 @@ OP_CHECK(opck_object_dot) { _("cannot access member '%s.%s' without object instance..."), the_base->name, str); if (GET_FLAG(value, const)) exp_setmeta(exp_self(member), 1); + exp_self(member)->acquire = 1; return value->type; } diff --git a/src/lib/shred.c b/src/lib/shred.c index b52f8397..5ac2accf 100644 --- a/src/lib/shred.c +++ b/src/lib/shred.c @@ -52,7 +52,7 @@ ANN M_Object new_fork(const VM_Shred shred, const VM_Code code, const Type t) { vm->parent = parent; const M_Object o = sh->info->me = fork_object(shred, t); ME(o) = sh; - ++o->ref; +// ++o->ref; shreduler_add(vm->shreduler, sh); return o; } diff --git a/src/lib/vararg.c b/src/lib/vararg.c index 26994c12..58467f8c 100644 --- a/src/lib/vararg.c +++ b/src/lib/vararg.c @@ -43,8 +43,9 @@ static DTOR(vararg_dtor) { static MFUN(mfun_vararg_cpy) { struct Vararg_ *src = *(struct Vararg_ **)o->data; struct Vararg_ *arg = mp_calloc(shred->info->mp, Vararg); - vector_copy2(&src->t, &arg->t); - arg->d = (m_bit *)xmalloc(round2szint(*(m_uint *)(o->data + SZ_INT * 2))); + if(*(m_uint*)(o->data + SZ_INT * 2)) { + vector_copy2(&src->t, &arg->t); + arg->d = (m_bit *)xmalloc(round2szint(*(m_uint *)(o->data + SZ_INT * 2))); m_uint offset = 0; for (m_uint i = 0; i < vector_size(&arg->t); ++i) { const Type t = (Type)vector_at(&arg->t, *(m_uint *)(o->data + SZ_INT * 4)); @@ -53,12 +54,13 @@ static MFUN(mfun_vararg_cpy) { ++(*(M_Object *)(arg->d + offset))->ref; offset += t->size; } + } const M_Object obj = new_object(shred->info->mp, o->type_ref); *(struct Vararg_ **)obj->data = arg; *(m_uint *)(obj->data + SZ_INT * 2) = *(m_uint *)(o->data + SZ_INT * 2); *(m_uint *)(obj->data + SZ_INT * 3) = *(m_uint *)(o->data + SZ_INT * 3); *(m_uint *)(obj->data + SZ_INT * 4) = *(m_uint *)(o->data + SZ_INT * 4); - *(m_uint *)(obj->data + SZ_INT * 4) = vector_size(&arg->t); // can we copy? + *(m_uint *)(obj->data + SZ_INT * 4) = arg->t.ptr ? vector_size(&arg->t) : 0; // can we copy? *(M_Object *)RETURN = obj; } @@ -84,6 +86,7 @@ INSTR(VarargIni) { *(m_uint *)(o->data + SZ_INT * 5) = vector_size(kinds); } *(M_Object *)REG(-SZ_INT) = o; +// ++o->ref; } static INSTR(VarargEnd) { diff --git a/src/parse/check.c b/src/parse/check.c index 12e57540..03136e57 100644 --- a/src/parse/check.c +++ b/src/parse/check.c @@ -1165,7 +1165,7 @@ ANN static inline m_bool for_empty(const Env env, const Stmt_For stmt) { ERR_B(stmt_self(stmt)->pos, _("empty for loop condition..." "...(note: explicitly use 'true' if it's the intent)" - "...(e.g., 'for(; true;{{ /*...*/ }')")) + "...(e.g., 'for(; true;){{ /*...*/ }')")) return GW_OK; } @@ -1830,8 +1830,6 @@ ANN static bool recursive_value(const Env env, const Type t, const Value v) { // tgt : t; v->type : t; -printf("%s %s\n", first->name, second->name); - if(first != second) { const Map m1 = &first->info->value->from->owner->info->type->map; map_remove(m1, (m_uint)insert_symbol(first->name)); diff --git a/src/vm/vm.c b/src/vm/vm.c index 45787982..8cbc14d3 100644 --- a/src/vm/vm.c +++ b/src/vm/vm.c @@ -117,8 +117,7 @@ ANN static void trace(VM_Shred shred, const m_uint size) { const m_uint line = vector_at(&shred->info->line, size - 1); m_uint i; bool can_skip = false; -//printf("size %lu\n", size); -if(!size)return; + if(!size)return; for (i = size; --i;) { const m_uint val = VPTR(&shred->info->line, i - 1); if (!val) diff --git a/tests/plug/enum_fail3.c b/tests/plug/enum_fail3.c index 73453467..03c16b22 100644 --- a/tests/plug/enum_fail3.c +++ b/tests/plug/enum_fail3.c @@ -11,6 +11,6 @@ GWION_IMPORT(enum_test) { GWI_BB(gwi_enum_ini(gwi, "test")) GWI_BB(gwi_enum_add(gwi, "adc", 0)) - GWI_BB(gwi_enum_ini(gwi, NULL)) + GWI_BB(gwi_enum_ini(gwi, "error")) return GW_OK; } diff --git a/tests/plug/func_tmpl.c b/tests/plug/func_tmpl.c index 4c0e8da8..61e76c3a 100644 --- a/tests/plug/func_tmpl.c +++ b/tests/plug/func_tmpl.c @@ -12,7 +12,7 @@ static SFUN(func_tmpl_xfun) {} GWION_IMPORT(func_tmpl) { - GWI_BB(gwi_func_ini(gwi, "int[]", "test:[A]")) + GWI_BB(gwi_func_ini(gwi, "int", "test:[A]")) GWI_BB(gwi_func_arg(gwi, "A", "i")) GWI_BB(gwi_func_end(gwi, func_tmpl_xfun, ae_flag_none)) return GW_OK; -- 2.43.0