From: fennecdjay Date: Tue, 5 Nov 2019 19:27:19 +0000 (+0100) Subject: :art: Fix typeof on arrays X-Git-Tag: nightly~2115^2~6 X-Git-Url: http://10.10.0.4:5575/?a=commitdiff_plain;h=a854580be42a151188089df56c2190e54043938f;p=gwion.git :art: Fix typeof on arrays --- diff --git a/examples/typeof_array.gw b/examples/typeof_array.gw new file mode 100644 index 00000000..1a1222d4 --- /dev/null +++ b/examples/typeof_array.gw @@ -0,0 +1,3 @@ +int i[2]; +<<< typeof(i) >>>; +<<< typeof(1) >>>; diff --git a/src/emit/emit.c b/src/emit/emit.c index d679478a..f9319a8d 100644 --- a/src/emit/emit.c +++ b/src/emit/emit.c @@ -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; } diff --git a/src/lib/array.c b/src/lib/array.c index ef98ac41..bd350c26 100644 --- a/src/lib/array.c +++ b/src/lib/array.c @@ -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)) diff --git a/src/lib/gack.c b/src/lib/gack.c index f610ad1b..9b0d3620 100644 --- a/src/lib/gack.c +++ b/src/lib/gack.c @@ -17,11 +17,11 @@ #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; diff --git a/src/parse/check.c b/src/parse/check.c index 15823cd1..7ba64b30 100644 --- a/src/parse/check.c +++ b/src/parse/check.c @@ -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[] = {