From 18631ffa1f1a97b8484e1a1d5407e700bb5abef4 Mon Sep 17 00:00:00 2001 From: fennecdjay Date: Tue, 8 Oct 2019 14:42:16 +0200 Subject: [PATCH] :art: Fixes and tests --- src/lib/array.c | 2 +- src/lib/prim.c | 20 +------------------- src/lib/ptr.c | 4 ++-- src/parse/check.c | 2 +- tests/error/array_cast_err.gw | 2 ++ tests/error/array_failure.gw | 2 ++ tests/error/invalid_pointer_cast.gw | 2 ++ tests/tree/array_test.gw | 3 ++- tests/tuple/object2tuple.gw | 11 +++-------- tests/tuple/object2tuple_err2.gw | 8 ++++++++ 10 files changed, 24 insertions(+), 32 deletions(-) create mode 100644 tests/error/array_cast_err.gw create mode 100644 tests/error/array_failure.gw create mode 100644 tests/error/invalid_pointer_cast.gw create mode 100644 tests/tuple/object2tuple_err2.gw diff --git a/src/lib/array.c b/src/lib/array.c index 5150ff02..862041fd 100644 --- a/src/lib/array.c +++ b/src/lib/array.c @@ -180,7 +180,7 @@ static OP_CHECK(opck_array_cast) { l = l->e->parent; while(!r->e->d.base_type) r = r->e->parent; - if(l->array_depth == r->array_depth || isa(l->e->d.base_type, r->e->d.base_type) > 0) + if(get_depth(cast->exp->type) == get_depth(exp_self(cast)->type) && isa(l->e->d.base_type, r->e->d.base_type) > 0) return l; return env->gwion->type[et_null]; } diff --git a/src/lib/prim.c b/src/lib/prim.c index fda939d5..d1a3232e 100644 --- a/src/lib/prim.c +++ b/src/lib/prim.c @@ -131,16 +131,9 @@ static GWION_IMPORT(values) { gwi_item_end(gwi, ae_flag_const, hour); gwi_item_ini(gwi, "time", "t_zero"); gwi_item_end(gwi, ae_flag_const, t_zero); -// gwi_item_ini(gwi, "@now", "now"); -// gwi_item_end(gwi, ae_flag_const, NULL); return GW_OK; } -/* -static OP_CHECK(opck_chuck_now) { - Exp_Binary* bin = (Exp_Binary*)data; - ERR_N(exp_self(bin)->pos, _("can't assign 'now' to 'now'")) -} -*/ + static OP_CHECK(opck_implicit_f2i) { return env->gwion->type[et_null]; } @@ -155,15 +148,6 @@ static OP_CHECK(opck_implicit_i2f) { return imp->e->cast_to = env->gwion->type[et_float]; } -// can't it be just declared? -static OP_EMIT(opem_i2f) { - return emit_add_instr(emit, CastI2F); -} - -static OP_EMIT(opem_f2i) { - return emit_add_instr(emit, CastF2I); -} - #define CHECK_FF(op, check, func) _CHECK_OP(op, check, float_##func) #define CHECK_IF(op, check, func) _CHECK_OP(op, check, int_float_##func) #define CHECK_FI(op, check, func) _CHECK_OP(op, check, float_int_##func) @@ -188,7 +172,6 @@ static GWION_IMPORT(intfloat) { CHECK_IF("-=>", rassign, r_minus) CHECK_IF("*=>", rassign, r_mul) CHECK_IF("/=>", rassign, r_div) - GWI_BB(gwi_oper_emi(gwi, opem_i2f)) _CHECK_OP("$", basic_cast, CastI2F) _CHECK_OP("@implicit", implicit_i2f, CastI2F) return GW_OK; @@ -214,7 +197,6 @@ static GWION_IMPORT(floatint) { CHECK_FI("-=>", rassign, r_minus) CHECK_FI("*=>", rassign, r_mul) CHECK_FI("/=>", rassign, r_div) - GWI_BB(gwi_oper_emi(gwi, opem_f2i)) _CHECK_OP("$", basic_cast, CastF2I) _CHECK_OP("@implicit", implicit_f2i, CastF2I) _CHECK_OP("@repeat", repeat_f2i, CastF2I) diff --git a/src/lib/ptr.c b/src/lib/ptr.c index f79123a4..f6629c16 100644 --- a/src/lib/ptr.c +++ b/src/lib/ptr.c @@ -46,7 +46,7 @@ static OP_CHECK(opck_ptr_deref) { const Exp_Unary* unary = (Exp_Unary*)data; return exp_self(unary)->type = nspc_lookup_type1(unary->exp->type->e->owner, insert_symbol(get_type_name(env, unary->exp->type->name, 1))); } -#include "tuple.h" + static OP_CHECK(opck_ptr_cast) { const Exp_Cast* cast = (Exp_Cast*)data; DECL_ON(const Type, t, = type_decl_resolve(env, cast->td)) @@ -54,7 +54,7 @@ static OP_CHECK(opck_ptr_cast) { assert(t->e->def); CHECK_BN(traverse_class_def(env, t->e->def)) } - const Type to = (Type)vector_at(&t->e->tuple->types, 0); + const Type to = known_type(env, cast->td->types->td); if(isa(cast->exp->type, to) > 0) return t; ERR_N(exp_self(cast)->pos, "invalid pointer cast") diff --git a/src/parse/check.c b/src/parse/check.c index d7926439..81b3eb28 100644 --- a/src/parse/check.c +++ b/src/parse/check.c @@ -138,7 +138,7 @@ ANN static m_bool check_var_td(const Env env, const Var_Decl var, Type_Decl *con if(env->class_def) { if(GET_FLAG(td, member)) { decl_member(env, v); - if(isa(env->class_def, env->gwion->type[et_object]) > 0) + if(isa(env->class_def, env->gwion->type[et_object]) > 0) tuple_info(env, td, var); } else if(GET_FLAG(td, static)) decl_static(env, v); diff --git a/tests/error/array_cast_err.gw b/tests/error/array_cast_err.gw new file mode 100644 index 00000000..a270eb01 --- /dev/null +++ b/tests/error/array_cast_err.gw @@ -0,0 +1,2 @@ +#! [contains] no match found for operator +<<< [ 1 ] $ int[][] >>>; diff --git a/tests/error/array_failure.gw b/tests/error/array_failure.gw new file mode 100644 index 00000000..a23c78b7 --- /dev/null +++ b/tests/error/array_failure.gw @@ -0,0 +1,2 @@ +#! [contains] NegativeArraySize +int i[2][-1]; diff --git a/tests/error/invalid_pointer_cast.gw b/tests/error/invalid_pointer_cast.gw new file mode 100644 index 00000000..1694e2b7 --- /dev/null +++ b/tests/error/invalid_pointer_cast.gw @@ -0,0 +1,2 @@ +#! [contains] invalid pointer cast +<<< 1 $ <~Object~>Ptr >>>; diff --git a/tests/tree/array_test.gw b/tests/tree/array_test.gw index 8da945dd..01f4d745 100644 --- a/tests/tree/array_test.gw +++ b/tests/tree/array_test.gw @@ -3,7 +3,7 @@ fun void print_array(int a[]){ <<< a[i] >>>; } -int i[3][3]; +int i[5][3]; 1 => i[2][0]; <<< i.size() >>>; @@ -16,3 +16,4 @@ i.remove(1); <<< i.depth() >>>; <<< i.cap() >>>; print_array(i[1]); +i.remove(0); diff --git a/tests/tuple/object2tuple.gw b/tests/tuple/object2tuple.gw index d62b0534..407b2371 100644 --- a/tests/tuple/object2tuple.gw +++ b/tests/tuple/object2tuple.gw @@ -1,8 +1,3 @@ -class Person { - "Phil" @=> string @name; - 45 => int age; -} - -Person p @=> <~string,int~>Tuple @t; -<<>>; -<<>>; +class C { int i; } +C c @=> <~int~>Tuple @t; +t @=> C @d; diff --git a/tests/tuple/object2tuple_err2.gw b/tests/tuple/object2tuple_err2.gw new file mode 100644 index 00000000..14d412da --- /dev/null +++ b/tests/tuple/object2tuple_err2.gw @@ -0,0 +1,8 @@ +class Person { + "Phil" @=> string @name; + 45 => int age; +} + +Person p @=> <~string,int,float~>Tuple @t; +<<>>; +<<>>; -- 2.43.0