From df65508bb084f8a3a95674ce42e3996ccd208602 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=A9mie=20Astor?= Date: Wed, 15 Dec 2021 14:35:54 +0100 Subject: [PATCH] :art: Few fixes --- examples/auto.gw | 2 +- include/opcode.h | 2 ++ opcode.txt | 2 +- src/emit/emit.c | 15 ++++++++++----- src/lib/object.c | 12 +++++++----- src/parse/check.c | 5 ++--- src/vm/vm.c | 5 ++++- tests/functionnal_array/concatmap.gw | 4 ++-- tests/functionnal_array/map.gw | 12 ++++++------ tests/new/array.gw | 2 +- tests/pp/pragma_unroll.gw | 2 +- tests/range/range_char.gw | 2 +- tests/range/range_int.gw | 2 +- tests/tree/auto_array.gw | 2 +- tests/tree/auto_fun.gw | 2 +- tests/tree/auto_ptr.gw | 4 ++-- tests/tree/cpy_ast.gw | 2 +- tests/tree/set_obj.gw | 2 +- tests/tree/typedef_auto_loop.gw | 2 +- 19 files changed, 46 insertions(+), 35 deletions(-) diff --git a/examples/auto.gw b/examples/auto.gw index c4056df1..f13495c6 100644 --- a/examples/auto.gw +++ b/examples/auto.gw @@ -1,3 +1,3 @@ var Object i[4]; -foreach(a: i) +for(a: i) <<< a >>>; diff --git a/include/opcode.h b/include/opcode.h index 356216dd..76b978cb 100644 --- a/include/opcode.h +++ b/include/opcode.h @@ -1090,6 +1090,8 @@ ANN static inline void dump_opcodes(const VM_Code code) { break; case eSetCode: gw_out("{Y}┃{0}{-}% 4lu{0}: SetCode ", j); + gw_out(" {-R}%-14"INT_F"{0}", instr->m_val); + gw_out(" {-M}%-14"INT_F"{0}", instr->m_val2); gw_out("\n"); break; case eRegMove: diff --git a/opcode.txt b/opcode.txt index 38966b4e..1ef10f3b 100644 --- a/opcode.txt +++ b/opcode.txt @@ -143,7 +143,7 @@ CastI2F CastF2I Time_Advance Recurs -SetCode +SetCode~i~i RegMove~i Reg2Mem~u~i Reg2Mem4~u~u diff --git a/src/emit/emit.c b/src/emit/emit.c index 4726224d..c9f1451b 100644 --- a/src/emit/emit.c +++ b/src/emit/emit.c @@ -527,7 +527,6 @@ ANN static m_bool _emit_symbol(const Emitter emit, const Symbol *data) { } return GW_OK; } -// if (!strncmp(v->type->name, "Ref:[", 5) && (!prim_exp(data)->cast_to || strncmp(prim_exp(data)->cast_to->name, "Ref:[", 5))) { if (tflag(v->type, tflag_ref) && !safe_tflag(prim_exp(data)->cast_to, tflag_ref)) { if (exp_getvar(exp_self(prim_self(data)))) { const Instr instr = emit_add_instr(emit, RegPushMem); @@ -901,11 +900,9 @@ ANN static m_bool emit_dot_static_data(const Emitter emit, const Value v, return GW_OK; } -ANN static m_bool decl_static(const Emitter emit, const Exp_Decl *decl, +ANN static m_bool _decl_static(const Emitter emit, const Exp_Decl *decl, const Var_Decl var_decl, const uint is_ref) { const Value v = var_decl->value; - Code * code = emit->code; - emit->code = (Code *)vector_back(&emit->stack); CHECK_BB( emit_instantiate_decl(emit, v->type, decl->td, var_decl->array, is_ref)); CHECK_BB(emit_dot_static_data(emit, v, 1)); @@ -913,10 +910,18 @@ ANN static m_bool decl_static(const Emitter emit, const Exp_Decl *decl, // if(get_depth(var_decl->value->type) && !is_ref) // (void)emit_object_addref(emit, -SZ_INT, 0); regpop(emit, SZ_INT); - emit->code = code; return GW_OK; } +ANN static m_bool decl_static(const Emitter emit, const Exp_Decl *decl, + const Var_Decl var_decl, const uint is_ref) { + Code *const code = emit->code; + emit->code = (Code *)vector_back(&emit->stack); + const m_bool ret = _decl_static(emit, decl, var_decl, is_ref); + emit->code = code; + return ret; +} + ANN static inline int struct_ctor(const Value v) { return tflag(v->type, tflag_struct) && v->type->nspc->pre_ctor; } diff --git a/src/lib/object.c b/src/lib/object.c index 724cf984..8a9aad08 100644 --- a/src/lib/object.c +++ b/src/lib/object.c @@ -100,12 +100,14 @@ static ID_CHECK(opck_this) { if (!env->class_def) ERR_O(exp_self(prim)->pos, _("keyword 'this' can be used only inside class definition...")) - if (env->func && !vflag(env->func->value_ref, vflag_member)) - ERR_O(exp_self(prim)->pos, + if(env->func) { + if (!vflag(env->func->value_ref, vflag_member)) + ERR_O(exp_self(prim)->pos, _("keyword 'this' cannot be used inside static functions...")) - if (!exp_getuse(exp_self(prim)) && env->func && - !strcmp(s_name(env->func->def->base->xid), "@gack")) - return get_gack(env->class_def->info->parent); // get_gack ? + if (!exp_getuse(exp_self(prim)) && + !strcmp(s_name(env->func->def->base->xid), "@gack")) + return get_gack(env->class_def->info->parent); // get_gack ? + } return env->class_def; } diff --git a/src/parse/check.c b/src/parse/check.c index b34cf2ec..a59b4e8f 100644 --- a/src/parse/check.c +++ b/src/parse/check.c @@ -502,9 +502,8 @@ static Func find_func_match_actual(const Env env, Func func, const Exp args, while (e) { if (!e->type) // investigate return NULL; -// if (!strncmp(e->type->name, "Ref:[", 5)) { - if (tflag(e->type, tflag_ref)) { -if(!e->cast_to)e->cast_to = e->type; + if (tflag(e->type, tflag_ref) && isa(e->type, e1->type) > 0) { + if(!e->cast_to)e->cast_to = e1->type; } if (!e1) { if (fbflag(func->def->base, fbflag_variadic)) return func; diff --git a/src/vm/vm.c b/src/vm/vm.c index 738d9ca3..507dfab0 100644 --- a/src/vm/vm.c +++ b/src/vm/vm.c @@ -896,9 +896,12 @@ vm_run(const VM *vm) { // lgtm [cpp/use-of-goto] *(m_float *)(reg - SZ_FLOAT) = (m_float) * (m_int *)(reg - SZ_FLOAT); DISPATCH() ftoi: +{ + const m_float f = * (m_float *)(reg - SZ_FLOAT); reg -= SZ_FLOAT - SZ_INT; - *(m_int *)(reg - SZ_INT) = (m_int) * (m_float *)(reg - SZ_INT); + *(m_int *)(reg - SZ_INT) = (m_int)f; DISPATCH() +} timeadv: reg -= SZ_FLOAT; shredule(s, shred, *(m_float *)(reg - SZ_FLOAT)); diff --git a/tests/functionnal_array/concatmap.gw b/tests/functionnal_array/concatmap.gw index 70b40a9a..c9df7e1c 100644 --- a/tests/functionnal_array/concatmap.gw +++ b/tests/functionnal_array/concatmap.gw @@ -6,7 +6,7 @@ const float ii; 123=> var float f; -foreach(a : [12, 1, 2 ,3].compactMap:[int]( \a { +for(a : [12, 1, 2 ,3].compactMap:[int]( \a { var int?i; 145 => i.val; if(maybe) @@ -24,6 +24,6 @@ fun int? t(int x) { i.val++; return i; } -foreach(a : [12, 1, 2 ,3].compactMap:[int](t)) +for(a : [12, 1, 2 ,3].compactMap:[int](t)) <<< "mapped to => ${a}" >>>; <<< "test" >>>; diff --git a/tests/functionnal_array/map.gw b/tests/functionnal_array/map.gw index c323decf..83e659c3 100644 --- a/tests/functionnal_array/map.gw +++ b/tests/functionnal_array/map.gw @@ -1,13 +1,13 @@ fun float t(float i) { return 2; } -foreach(a : [12., 1, 2 ,3].map:[float](t)) +for(a : [12., 1, 2 ,3].map:[float](t)) <<< "mapped to => ${a}" >>>; -#!foreach(a : [12, 1, 2 ,3].map:[int](t)) +#!for(a : [12, 1, 2 ,3].map:[int](t)) #! <<< "mapped to => ${a}" >>>; -#!foreach(a : [12, 1, 2 ,3].map:[int](t)) +#!for(a : [12, 1, 2 ,3].map:[int](t)) #! <<< "mapped to => ${a}" >>>; -#!foreach(a : [12, 1, 2 ,3].map:[int](t)) +#!for(a : [12, 1, 2 ,3].map:[int](t)) #! <<< "mapped to => ${a}" >>>; -#!foreach(a : [12, 1, 2 ,3].map:[int]( \a {145 => a;return 2;})) +#!for(a : [12, 1, 2 ,3].map:[int]( \a {145 => a;return 2;})) #! <<< "mapped to => ${a}" >>>; -#!foreach(a : [12, 1, 2 ,3].map:[int]( \a {145 => a;return 2;})) +#!for(a : [12, 1, 2 ,3].map:[int]( \a {145 => a;return 2;})) #! <<< "mapped to => ${a}" >>>; diff --git a/tests/new/array.gw b/tests/new/array.gw index 7401126c..b9198e26 100644 --- a/tests/new/array.gw +++ b/tests/new/array.gw @@ -3,5 +3,5 @@ j << 23; i << 2; j >> i; 1234 >> i; -foreach(a : i) +for(a : i) <<< a >>>; diff --git a/tests/pp/pragma_unroll.gw b/tests/pp/pragma_unroll.gw index 9dd92231..560d9f62 100644 --- a/tests/pp/pragma_unroll.gw +++ b/tests/pp/pragma_unroll.gw @@ -1,4 +1,4 @@ #! contains 23 #pragma unroll 2 -foreach(a, i : [ 0, 1, 3 ]) +for(a, i : [ 0, 1, 3 ]) <<< a, i >>>; diff --git a/tests/range/range_char.gw b/tests/range/range_char.gw index 7be54285..0cf7a051 100644 --- a/tests/range/range_char.gw +++ b/tests/range/range_char.gw @@ -1,3 +1,3 @@ #! [contains] b -foreach(a : [ 'a' : 'c' ]) +for(a : [ 'a' : 'c' ]) <<< a >>>; diff --git a/tests/range/range_int.gw b/tests/range/range_int.gw index 870d1fd1..4b9c0914 100644 --- a/tests/range/range_int.gw +++ b/tests/range/range_int.gw @@ -1,3 +1,3 @@ #! [contains] \-5 -foreach(a : [ -1 : -6 ]) +for(a : [ -1 : -6 ]) <<< a >>>; diff --git a/tests/tree/auto_array.gw b/tests/tree/auto_array.gw index 03fdc986..444fd163 100644 --- a/tests/tree/auto_array.gw +++ b/tests/tree/auto_array.gw @@ -1,4 +1,4 @@ var int i[2][2]; -foreach(a : i) +for(a : i) <<< a >>>; <<< i >>>; diff --git a/tests/tree/auto_fun.gw b/tests/tree/auto_fun.gw index 92f23720..e1ef04de 100644 --- a/tests/tree/auto_fun.gw +++ b/tests/tree/auto_fun.gw @@ -4,6 +4,6 @@ class C { var C i[2]; -foreach(a : i) +for(a : i) <<< a >>>; diff --git a/tests/tree/auto_ptr.gw b/tests/tree/auto_ptr.gw index 0da29291..ac842559 100644 --- a/tests/tree/auto_ptr.gw +++ b/tests/tree/auto_ptr.gw @@ -1,5 +1,5 @@ var int i[4]; -foreach(a : i) +for(a : i) <<< 1 => a >>>; -foreach(a : i) +for(a : i) <<< a >>>; diff --git a/tests/tree/cpy_ast.gw b/tests/tree/cpy_ast.gw index 25c18fb6..13588e82 100644 --- a/tests/tree/cpy_ast.gw +++ b/tests/tree/cpy_ast.gw @@ -13,7 +13,7 @@ class C:[A] { for(var int _i; _i < 1; ++_i); var int array[2]; array[0]; - foreach(a : array); + for(a : array); repeat(1); match i,2 { case 12 when 0:; diff --git a/tests/tree/set_obj.gw b/tests/tree/set_obj.gw index ae8180a6..2e599a4d 100644 --- a/tests/tree/set_obj.gw +++ b/tests/tree/set_obj.gw @@ -1,4 +1,4 @@ typedef int[2] Type; Type type; <<>>; -foreach(ref a : type); +for(ref a : type); diff --git a/tests/tree/typedef_auto_loop.gw b/tests/tree/typedef_auto_loop.gw index 9c300b43..5f2a0e97 100644 --- a/tests/tree/typedef_auto_loop.gw +++ b/tests/tree/typedef_auto_loop.gw @@ -1,3 +1,3 @@ typedef int[2] Type; var Type type; -foreach(a : type); +for(a : type); -- 2.43.0