From 9239715d1e7e17b1a99fc3dd5bac854125c57838 Mon Sep 17 00:00:00 2001 From: fennecdjay Date: Sun, 7 Jul 2019 21:24:03 +0200 Subject: [PATCH] :art: Still more tests --- include/array.h | 2 +- src/lib/array.c | 20 ++++++-------------- src/lib/prim.c | 11 +++-------- src/parse/scan1.c | 2 +- tests/error/implicit_f2i.gw | 2 ++ tests/error/invalid_array_shift.gw | 6 +++--- 6 files changed, 16 insertions(+), 27 deletions(-) create mode 100644 tests/error/implicit_f2i.gw diff --git a/include/array.h b/include/array.h index a452a0e8..7d4eb41d 100644 --- a/include/array.h +++ b/include/array.h @@ -20,6 +20,6 @@ ANN void m_vector_get(const M_Vector, const m_uint, void*); ANN void m_vector_add(const M_Vector, const void*); ANN m_bit* m_vector_addr(const M_Vector, const m_uint); ANN void m_vector_rem(const M_Vector, const m_uint); -ANEW M_Vector new_m_vector(MemPool, const m_uint); +ANEW M_Vector new_m_vector(MemPool, const m_uint size, const m_uint len); ANN void free_m_vector(MemPool, M_Vector); #endif diff --git a/src/lib/array.c b/src/lib/array.c index a96fcfe8..5f5f1154 100644 --- a/src/lib/array.c +++ b/src/lib/array.c @@ -29,16 +29,7 @@ ANN m_uint m_vector_size(const M_Vector v) { return ARRAY_LEN(v); } -M_Vector new_m_vector(MemPool p, const m_uint size) { - const M_Vector array = mp_calloc(p, M_Vector); - const size_t sz = (ARRAY_OFFSET*SZ_INT) + (2*size); - array->ptr = (m_bit*)xcalloc(1, sz); - ARRAY_CAP(array) = 2; - ARRAY_SIZE(array) = size; - return array; -} - -M_Vector new_m_vector2(MemPool p, const m_uint size, const m_uint len) { +M_Vector new_m_vector(MemPool p, const m_uint size, const m_uint len) { const M_Vector array = mp_calloc(p, M_Vector); const size_t sz = (ARRAY_OFFSET*SZ_INT) + (len*size); array->ptr = (m_bit*)xcalloc(1, sz); @@ -70,7 +61,7 @@ ANN M_Object new_array(MemPool p, const Type t, const m_uint length) { const M_Object a = new_object(p, NULL, t); const m_uint depth = t->array_depth; const m_uint size = depth > 1 ? SZ_INT : array_base(t)->size; - ARRAY(a) = new_m_vector2(p, size,length); + ARRAY(a) = new_m_vector(p, size,length); return a; } @@ -108,7 +99,7 @@ ANN void m_vector_rem(const M_Vector v, m_uint index) { } static MFUN(vm_vector_rem) { - const m_int index = *(m_int*)(shred->reg + SZ_INT); + const m_int index = *(m_int*)(shred->mem + SZ_INT); const M_Vector v = ARRAY(o); if(index < 0 || (m_uint)index >= ARRAY_LEN(v)) return; @@ -156,7 +147,8 @@ static OP_CHECK(opck_array_at) { if(bin->lhs->type->array_depth != bin->rhs->type->array_depth) ERR_N(exp_self(bin)->pos, _("array depths do not match.")) if(bin->rhs->exp_type == ae_exp_decl) { - if(bin->rhs->d.exp_decl.list->self->array->exp) + if(bin->rhs->d.exp_decl.list->self->array && + bin->rhs->d.exp_decl.list->self->array->exp) ERR_N(exp_self(bin)->pos, _("do not provide array for 'xxx @=> declaration'.")) } bin->rhs->emit_var = 1; @@ -166,7 +158,7 @@ static OP_CHECK(opck_array_at) { static OP_CHECK(opck_array_shift) { ARRAY_OPCK if(bin->lhs->type->array_depth != bin->rhs->type->array_depth + 1) - return t_null; + ERR_N(exp_self(bin)->pos, "array depths do not match for '<<'."); return bin->lhs->type; } diff --git a/src/lib/prim.c b/src/lib/prim.c index 2a6f973c..dfcf569d 100644 --- a/src/lib/prim.c +++ b/src/lib/prim.c @@ -127,13 +127,12 @@ static GWION_IMPORT(values) { gwi_reserve(gwi, "now"); return GW_OK; } - +/* static OP_CHECK(opck_chuck_now) { Exp_Binary* bin = (Exp_Binary*)data; - ERR_O(exp_self(bin)->pos, _("can't assign 'now' to 'now'")) - return NULL; + ERR_N(exp_self(bin)->pos, _("can't assign 'now' to 'now'")) } - +*/ static OP_CHECK(opck_implicit_f2i) { return t_null; } @@ -236,10 +235,6 @@ static GWION_IMPORT(time) { CHECK_BB(gwi_oper_end(gwi, "+", FloatPlus)) CHECK_BB(gwi_oper_ini(gwi, "dur", "@now", "time")) _CHECK_OP("=>", rhs_emit_var, Time_Advance) - CHECK_BB(gwi_oper_ini(gwi, "@now", "@now", NULL)) - _CHECK_OP("=>", chuck_now, NULL) - CHECK_BB(gwi_oper_ini(gwi, NULL, "@now", NULL)) - CHECK_BB(gwi_oper_end(gwi, "!", NULL)) CHECK_BB(gwi_oper_ini(gwi, "time", "time", "int")) CHECK_BB(gwi_oper_end(gwi, ">", float_gt)) CHECK_BB(gwi_oper_end(gwi, ">=", float_ge)) diff --git a/src/parse/scan1.c b/src/parse/scan1.c index 9eb17791..daa65b7c 100644 --- a/src/parse/scan1.c +++ b/src/parse/scan1.c @@ -88,7 +88,7 @@ ANN m_bool scan1_exp_decl(const Env env, const Exp_Decl* decl) { CHECK_BB(isres(env, var->xid, exp_self(decl)->pos)) Type t = decl->type; const Value former = nspc_lookup_value0(env->curr, var->xid); - if(former && !decl->td->exp && + if(former && !(decl->td->exp || decl->td->xid)&& (!env->class_def || !(GET_FLAG(env->class_def, template) || GET_FLAG(env->class_def, scan1)))) ERR_B(var->pos, _("variable %s has already been defined in the same scope..."), s_name(var->xid)) diff --git a/tests/error/implicit_f2i.gw b/tests/error/implicit_f2i.gw new file mode 100644 index 00000000..4bbb3343 --- /dev/null +++ b/tests/error/implicit_f2i.gw @@ -0,0 +1,2 @@ +fun void test(int i) {} +2.3 => test; diff --git a/tests/error/invalid_array_shift.gw b/tests/error/invalid_array_shift.gw index b365f6cf..dbe566cc 100644 --- a/tests/error/invalid_array_shift.gw +++ b/tests/error/invalid_array_shift.gw @@ -1,3 +1,3 @@ -#! [contains] array types do not match -int i[2]; -i << 2.3; +#! [contains] array depths do not match +int i[2][2]; +i << 2; -- 2.43.0