From 1fd927b58471b2052799fb3c1db1ffd4a3a90c94 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=A9mie=20Astor?= Date: Thu, 12 Mar 2020 20:19:29 +0100 Subject: [PATCH] :art: vargarg coverage and simplification --- src/lib/vararg.c | 22 ++++++---------------- src/vm/vm.c | 2 +- tests/new/vararg_cpy.gw | 5 +++++ 3 files changed, 12 insertions(+), 17 deletions(-) create mode 100644 tests/new/vararg_cpy.gw diff --git a/src/lib/vararg.c b/src/lib/vararg.c index e54b3d0b..b6b37f2e 100644 --- a/src/lib/vararg.c +++ b/src/lib/vararg.c @@ -34,8 +34,8 @@ static DTOR(vararg_dtor) { free_vararg(shred->info->vm->gwion->mp, arg); } -ANN static M_Object vararg_cpy(VM_Shred shred, struct Vararg_* src) { - const M_Object o = new_object(shred->info->mp, shred, shred->info->vm->gwion->type[et_vararg]); +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->l = src->l; @@ -51,12 +51,9 @@ ANN static M_Object vararg_cpy(VM_Shred shred, struct Vararg_* src) { arg->s = vector_size(&arg->t); arg->i = src->i; arg->o = src->o; - *(struct Vararg_**)o->data = arg; - return o; -} - -static MFUN(mfun_vararg_cpy) { - *(M_Object*)RETURN = vararg_cpy(shred, *(struct Vararg_**)o->data); + const M_Object obj = new_object(shred->info->mp, shred, o->type_ref); + *(struct Vararg_**)obj->data = arg; + *(M_Object*)RETURN = obj; } INSTR(VarargIni) { @@ -95,10 +92,6 @@ static OP_CHECK(opck_vararg_cast) { return known_type(env, cast->td); } -static OP_CHECK(opck_vararg_at) { - return env->gwion->type[et_null]; -} - static INSTR(VarargCast) { const M_Object o = *(M_Object*)REG(-SZ_INT); if(!*(m_uint*)(o->data + SZ_INT)) @@ -159,15 +152,12 @@ GWION_IMPORT(vararg) { CHECK_BB(gwi_func_ini(gwi, "Vararg", "cpy")) CHECK_BB(gwi_func_end(gwi, mfun_vararg_cpy, ae_flag_none)) GWI_BB(gwi_class_end(gwi)) - SET_FLAG(t_vararg, abstract | ae_flag_const); + SET_FLAG(t_vararg, abstract); CHECK_BB(gwi_set_global_type(gwi, t_vararg, et_vararg)) GWI_BB(gwi_oper_ini(gwi, "nonnull Vararg", (m_str)OP_ANY_TYPE, NULL)) GWI_BB(gwi_oper_add(gwi, opck_vararg_cast)) GWI_BB(gwi_oper_emi(gwi, opem_vararg_cast)) GWI_BB(gwi_oper_end(gwi, "$", NULL)) - GWI_BB(gwi_oper_ini(gwi, "Vararg", (m_str)OP_ANY_TYPE, NULL)) - GWI_BB(gwi_oper_add(gwi, opck_vararg_at)) - GWI_BB(gwi_oper_end(gwi, "@=>", NULL)) gwi_register_freearg(gwi, VarargIni, freearg_vararg); struct SpecialId_ spid = { .type=t_vararg, .is_const=1, .ck=idck_vararg, .em=idem_vararg}; gwi_specialid(gwi, "vararg", &spid); diff --git a/src/vm/vm.c b/src/vm/vm.c index 599c3dfe..33ea94a2 100644 --- a/src/vm/vm.c +++ b/src/vm/vm.c @@ -766,7 +766,7 @@ remref: release(*(M_Object*)(mem + VAL), shred); DISPATCH() setobj: - a.obj = *(M_Object*)(reg-SZ_INT-VAL); + a.obj = *(M_Object*)(reg-SZ_INT-(m_int)VAL); DISPATCH(); except: /* TODO: Refactor except instruction * diff --git a/tests/new/vararg_cpy.gw b/tests/new/vararg_cpy.gw new file mode 100644 index 00000000..baedc594 --- /dev/null +++ b/tests/new/vararg_cpy.gw @@ -0,0 +1,5 @@ +fun void test(...) { + <<< vararg >>>; + <<< vararg.cpy() @=> Vararg ref new_arg >>>; +} +test(1); -- 2.43.0