]> Nishi Git Mirror - gwion.git/commitdiff
:art: Fixes and tests
authorfennecdjay <astor.jeremie@wanadoo.fr>
Tue, 8 Oct 2019 12:42:16 +0000 (14:42 +0200)
committerfennecdjay <astor.jeremie@wanadoo.fr>
Tue, 8 Oct 2019 12:42:16 +0000 (14:42 +0200)
src/lib/array.c
src/lib/prim.c
src/lib/ptr.c
src/parse/check.c
tests/error/array_cast_err.gw [new file with mode: 0644]
tests/error/array_failure.gw [new file with mode: 0644]
tests/error/invalid_pointer_cast.gw [new file with mode: 0644]
tests/tree/array_test.gw
tests/tuple/object2tuple.gw
tests/tuple/object2tuple_err2.gw [new file with mode: 0644]

index 5150ff02e66b80a1be745d773d74f11158d7cf0d..862041fdf8ad42dec209eb13035faeeb49667462 100644 (file)
@@ -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];
 }
index fda939d577eb9b1526a4cf582108a2ec8db2a851..d1a3232e335b16c766c087d4b6b79fd9ee08d979 100644 (file)
@@ -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)
index f79123a4607d0657162fa1228840a9c32a9a4b97..f6629c16662d8aa27658d15d35c7848b10342bc1 100644 (file)
@@ -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")
index d792643942c4ad2269da22fb0fcaf47d991bfa78..81b3eb28a422e67a20c9418ea1efedeb12890fa7 100644 (file)
@@ -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 (file)
index 0000000..a270eb0
--- /dev/null
@@ -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 (file)
index 0000000..a23c78b
--- /dev/null
@@ -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 (file)
index 0000000..1694e2b
--- /dev/null
@@ -0,0 +1,2 @@
+#! [contains] invalid pointer cast
+<<< 1 $ <~Object~>Ptr >>>;
index 8da945dda771e4a6dcfe955ebae7628204b70971..01f4d745ecab787172109912fe71cc51d61a44a4 100644 (file)
@@ -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);
index d62b0534d128bc3e6b2d18d861432c6e66659efd..407b2371ba87f8c3d4431a5a33fee0ccbf757a74 100644 (file)
@@ -1,8 +1,3 @@
-class Person {
-  "Phil" @=> string @name;
-  45 => int age;
-}
-
-Person p @=> <~string,int~>Tuple @t;
-<<<t[0]>>>;
-<<<t[1]>>>;
+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 (file)
index 0000000..14d412d
--- /dev/null
@@ -0,0 +1,8 @@
+class Person {
+  "Phil" @=> string @name;
+  45 => int age;
+}
+
+Person p @=> <~string,int,float~>Tuple @t;
+<<<t[0]>>>;
+<<<t[1]>>>;