]> Nishi Git Mirror - gwion.git/commitdiff
:art: Fix typeof on arrays
authorfennecdjay <astor.jeremie@wanadoo.fr>
Tue, 5 Nov 2019 19:27:19 +0000 (20:27 +0100)
committerfennecdjay <astor.jeremie@wanadoo.fr>
Tue, 5 Nov 2019 19:27:19 +0000 (20:27 +0100)
examples/typeof_array.gw [new file with mode: 0644]
src/emit/emit.c
src/lib/array.c
src/lib/gack.c
src/parse/check.c

diff --git a/examples/typeof_array.gw b/examples/typeof_array.gw
new file mode 100644 (file)
index 0000000..1a1222d
--- /dev/null
@@ -0,0 +1,3 @@
+int i[2];
+<<< typeof(i) >>>;
+<<< typeof(1) >>>;
index d679478ae789d61bc85babbd8fa826d0c2e77e84..f9319a8d2a13237debb08f57280117d065a87c92 100644 (file)
@@ -1163,7 +1163,10 @@ ANN static m_bool emit_exp_lambda(const Emitter emit, const Exp_Lambda * lambda)
 }
 
 ANN static m_bool emit_exp_typeof(const Emitter emit, const Exp_Typeof *exp) {
-  regpushi(emit, (m_uint)(actual_type(emit->gwion, exp->exp->type)));
+  if(!exp->exp->type->array_depth)
+    regpushi(emit, (m_uint)(actual_type(emit->gwion, exp->exp->type)));
+  else
+    regpushi(emit, (m_uint)exp->exp->type);
   return GW_OK;
 }
 
index ef98ac41f3a633675dcd54fae10207c9d0601d8c..bd350c26e37ae8ef5c3cbd3c8280864a6a41829f 100644 (file)
@@ -192,11 +192,15 @@ static FREEARG(freearg_array) {
   mp_free(((Gwion)gwion)->mp, ArrayInfo, info);
 }
 
+static GACK(gack_array) {
+  printf("%s", t->name);
+}
+
 GWION_IMPORT(array) {
   const Type t_array  = gwi_class_ini(gwi, "@Array", NULL);
   gwi->gwion->type[et_array] = t_array;
   gwi_class_xtor(gwi, NULL, array_dtor);
-
+  GWI_BB(gwi_gack(gwi, t_array, gack_array))
   GWI_BB(gwi_item_ini(gwi, "@internal", "@array"))
   GWI_BB(gwi_item_end(gwi, 0, NULL))
 
index f610ad1bf975b62943f450134392e9aaaa7b50d9..9b0d3620cde8b4e156608524a9eb3323ebb91dbd 100644 (file)
 #include "gack.h"
 
 ANN void gack(const VM_Shred shred, const Instr instr) {
-  Type t = (Type)instr->m_val;
+  Type base = (Type)instr->m_val, t = base;
   do {
     if(t->e->gack) {
       if(GET_FLAG(t->e->gack, builtin))
-        ((f_gack)t->e->gack->native_func)(t, (shred->reg - t->size), shred);
+        ((f_gack)t->e->gack->native_func)(base, (shred->reg - t->size), shred);
       else {
         shred->mem += instr->m_val2;
         *(m_uint*)(shred->mem+ SZ_INT) = instr->m_val2 + SZ_INT;
index 15823cd13222e93f98b99b02df053d0e40049124..7ba64b307c7d68864738504ac524f0aaf54bc084 100644 (file)
@@ -939,8 +939,11 @@ ANN static Type check_exp_lambda(const Env env,
 
 ANN static Type check_exp_typeof(const Env env, const Exp_Typeof *exp) {
   DECL_OO(const Type, t, = check_exp(env, exp->exp))
-  DECL_OO(Value, v, = nspc_lookup_value1(t->e->owner, insert_symbol(t->name)))
-  return v->type;
+  if(!t->array_depth) {
+    DECL_OO(Value, v, = nspc_lookup_value1(t->e->owner, insert_symbol(t->name)))
+    return v->type;
+  }
+  return t;
 }
 
 static const _type_func exp_func[] = {