From 09c84f4b45a55016643dc334404b2f98293341ae Mon Sep 17 00:00:00 2001 From: fennecdjay Date: Wed, 9 Oct 2019 00:45:11 +0200 Subject: [PATCH] :art: set_decl_ref --- include/operator.h | 7 +++++++ src/emit/emit.c | 2 +- src/lib/array.c | 1 + src/lib/complex.c | 1 + src/lib/engine.c | 1 + src/lib/event.c | 1 + src/lib/gack.c | 1 + src/lib/instr.c | 1 + src/lib/modules.c | 1 + src/lib/prim.c | 1 + src/lib/ptr.c | 1 + src/lib/shred.c | 1 + src/lib/string.c | 1 + src/lib/tuple.c | 20 ++++++++++++-------- src/lib/ugen.c | 1 + src/lib/vararg.c | 1 + src/lib/vec.c | 1 + src/oo/env.c | 1 + src/pass.c | 2 +- src/plug.c | 1 + src/vm/vm.c | 1 + src/vm/vm_code.c | 1 + 22 files changed, 39 insertions(+), 10 deletions(-) diff --git a/include/operator.h b/include/operator.h index 30969337..a0466b5e 100644 --- a/include/operator.h +++ b/include/operator.h @@ -32,4 +32,11 @@ ANN Type op_check(const Env, struct Op_Import*); ANN struct Instr_* op_emit(const Emitter, const struct Op_Import*); ANN m_bool operator_set_func(const struct Op_Import*); ANN void free_op_map(Map map, struct Gwion_* gwion); + +ANN static inline void set_decl_ref(const Exp e) { + if(e->exp_type == ae_exp_decl) { + SET_FLAG(e->d.exp_decl.td, ref); + SET_FLAG(e->d.exp_decl.list->self->value, ref); + } +} #endif diff --git a/src/emit/emit.c b/src/emit/emit.c index 085c6dc4..a3b8b166 100644 --- a/src/emit/emit.c +++ b/src/emit/emit.c @@ -1893,7 +1893,7 @@ ANN static m_bool emit_class_def(const Emitter emit, const Class_Def cdef) { CHECK_BB(emit_array_extend(emit, type->e->parent, cdef->base.ext->array->exp)) if(cdef->body) CHECK_BB(scanx_body(emit->env, cdef, (_exp_func)emit_section, emit)) - emit_class_finish(emit, type->nspc); + emit_class_finish(emit, nspc); SET_FLAG(type, emit); return GW_OK; } diff --git a/src/lib/array.c b/src/lib/array.c index 862041fd..d16810c3 100644 --- a/src/lib/array.c +++ b/src/lib/array.c @@ -11,6 +11,7 @@ #include "object.h" #include "array.h" #include "emit.h" +#include "value.h" #include "operator.h" #include "import.h" #include "traverse.h" diff --git a/src/lib/complex.c b/src/lib/complex.c index 07629856..1ed8f00e 100644 --- a/src/lib/complex.c +++ b/src/lib/complex.c @@ -8,6 +8,7 @@ #include "instr.h" #include "object.h" #include "gwion.h" +#include "value.h" #include "operator.h" #include "import.h" diff --git a/src/lib/engine.c b/src/lib/engine.c index 6fd67801..d29ef4cc 100644 --- a/src/lib/engine.c +++ b/src/lib/engine.c @@ -12,6 +12,7 @@ #include "env.h" #include "vm.h" #include "gwion.h" +#include "value.h" #include "operator.h" #include "import.h" #include "gwi.h" diff --git a/src/lib/event.c b/src/lib/event.c index 99f79beb..1ca394df 100644 --- a/src/lib/event.c +++ b/src/lib/event.c @@ -7,6 +7,7 @@ #include "type.h" #include "instr.h" #include "object.h" +#include "value.h" #include "operator.h" #include "import.h" #include "gwi.h" diff --git a/src/lib/gack.c b/src/lib/gack.c index 4d07a03c..f610ad1b 100644 --- a/src/lib/gack.c +++ b/src/lib/gack.c @@ -11,6 +11,7 @@ #include "object.h" #include "instr.h" #include "gwion.h" +#include "value.h" #include "operator.h" #include "import.h" #include "gack.h" diff --git a/src/lib/instr.c b/src/lib/instr.c index 3ee791f7..66d305c6 100644 --- a/src/lib/instr.c +++ b/src/lib/instr.c @@ -13,6 +13,7 @@ #include "nspc.h" #include "shreduler_private.h" #include "gwion.h" +#include "value.h" #include "operator.h" #include "import.h" #include "cpy_ast.h" diff --git a/src/lib/modules.c b/src/lib/modules.c index 3cf3af3f..71dd15d6 100644 --- a/src/lib/modules.c +++ b/src/lib/modules.c @@ -9,6 +9,7 @@ #include "type.h" #include "instr.h" #include "object.h" +#include "value.h" #include "operator.h" #include "import.h" #include "ugen.h" diff --git a/src/lib/prim.c b/src/lib/prim.c index d1a3232e..f7085b69 100644 --- a/src/lib/prim.c +++ b/src/lib/prim.c @@ -8,6 +8,7 @@ #include "instr.h" #include "object.h" #include "emit.h" +#include "value.h" #include "operator.h" #include "import.h" #include "gwi.h" diff --git a/src/lib/ptr.c b/src/lib/ptr.c index 59a0d477..fd8188ca 100644 --- a/src/lib/ptr.c +++ b/src/lib/ptr.c @@ -10,6 +10,7 @@ #include "nspc.h" #include "instr.h" #include "object.h" +#include "value.h" #include "operator.h" #include "import.h" #include "emit.h" diff --git a/src/lib/shred.c b/src/lib/shred.c index 41aeed37..8ab29424 100644 --- a/src/lib/shred.c +++ b/src/lib/shred.c @@ -10,6 +10,7 @@ #include "object.h" #include "shreduler_private.h" #include "gwion.h" +#include "value.h" #include "operator.h" #include "import.h" #include "emit.h" diff --git a/src/lib/string.c b/src/lib/string.c index 0562c3c9..9805a95b 100644 --- a/src/lib/string.c +++ b/src/lib/string.c @@ -11,6 +11,7 @@ #include "instr.h" #include "object.h" #include "gwion.h" +#include "value.h" #include "operator.h" #include "import.h" #include "emit.h" diff --git a/src/lib/tuple.c b/src/lib/tuple.c index 8af9b3d8..7cab9c00 100644 --- a/src/lib/tuple.c +++ b/src/lib/tuple.c @@ -11,6 +11,7 @@ #include "env.h" #include "vm.h" #include "gwion.h" +#include "value.h" #include "operator.h" #include "import.h" #include "gwi.h" @@ -162,6 +163,7 @@ static OP_CHECK(opck_at_tuple_object) { if(tuple_match(env, bin->rhs->type, bin->lhs->type) < 0) return env->gwion->type[et_null]; bin->rhs->emit_var = 1; + set_decl_ref(bin->rhs); return bin->rhs->type; } @@ -173,10 +175,9 @@ static OP_CHECK(opck_cast_tuple_object) { } static INSTR(Tuple2Object) { -// const M_Object o = *(M_Object*)(shred->reg - SZ_INT*2); const M_Object o = *(M_Object*)(shred->reg - instr->m_val2); const Type t = (Type)instr->m_val; - if(isa(o->type_ref, t) < 0) + if(o && isa(o->type_ref, t) < 0) // TODO: pass position by m_val2 // Except(shred, "can't cast %s to %s\n", o->type_ref->name, t->name); Except(shred, _("can't cast\n")); @@ -191,12 +192,15 @@ static OP_EMIT(opem_##name##_tuple_object) { \ instr->m_val2 = SZ_INT; \ return instr; \ } -static OP_EMIT(opem_at_tuple_object) { \ - const Exp_Binary *bin = (Exp_Binary*)data; \ - const Instr instr = emit_add_instr(emit, Tuple2Object); \ - instr->m_val = (m_uint)bin->rhs->type; \ - instr->m_val2 = SZ_INT*2; \ - return emit_add_instr(emit, ObjectAssign); \ +static OP_EMIT(opem_at_tuple_object) { \ + const Exp_Binary *bin = (Exp_Binary*)data; \ + const Instr instr = emit_add_instr(emit, Tuple2Object); \ + instr->m_val = (m_uint)bin->rhs->type; \ + instr->m_val2 = SZ_INT*2; \ + + const Instr assign = emit_add_instr(emit, ObjectAssign); \ + +return assign; } mk_opem_tuple2object(cast, Exp_Cast *, exp_self(exp)->type) diff --git a/src/lib/ugen.c b/src/lib/ugen.c index 1fec7ae6..51220b7c 100644 --- a/src/lib/ugen.c +++ b/src/lib/ugen.c @@ -8,6 +8,7 @@ #include "type.h" #include "instr.h" #include "object.h" +#include "value.h" #include "operator.h" #include "import.h" #include "gwi.h" diff --git a/src/lib/vararg.c b/src/lib/vararg.c index 35d0fca7..250823ce 100644 --- a/src/lib/vararg.c +++ b/src/lib/vararg.c @@ -11,6 +11,7 @@ #include "object.h" #include "vararg.h" #include "gwion.h" +#include "value.h" #include "operator.h" #include "import.h" #include "gwi.h" diff --git a/src/lib/vec.c b/src/lib/vec.c index 20597042..a2848c99 100644 --- a/src/lib/vec.c +++ b/src/lib/vec.c @@ -7,6 +7,7 @@ #include "instr.h" #include "object.h" #include "gwion.h" +#include "value.h" #include "operator.h" #include "import.h" #include "driver.h" diff --git a/src/oo/env.c b/src/oo/env.c index 870d5913..1ca42590 100644 --- a/src/oo/env.c +++ b/src/oo/env.c @@ -5,6 +5,7 @@ #include "vm.h" #include "env.h" #include "gwion.h" +#include "value.h" #include "operator.h" #include "value.h" #include "traverse.h" diff --git a/src/pass.c b/src/pass.c index 9a2434cb..9c2684f8 100644 --- a/src/pass.c +++ b/src/pass.c @@ -25,7 +25,7 @@ ANN m_bool pass_set(const Gwion gwion, const Vector passes) { const Symbol sym = insert_symbol(gwion->st, name); const compilation_pass pass = (compilation_pass)map_get(&gwion->data->pass_map, (vtype)sym); if(!pass) { - gw_err("Failed to set compilation passes, back to default"); + gw_err("Failed to set compilation passes, back to default\n"); pass_default(gwion); return GW_ERROR; } diff --git a/src/plug.c b/src/plug.c index c0dd2193..dd11e1aa 100644 --- a/src/plug.c +++ b/src/plug.c @@ -11,6 +11,7 @@ #include "env.h" #include "vm.h" #include "gwion.h" +#include "value.h" #include "operator.h" #include "instr.h" #include "object.h" diff --git a/src/vm/vm.c b/src/vm/vm.c index 51742e90..5eb145ff 100644 --- a/src/vm/vm.c +++ b/src/vm/vm.c @@ -15,6 +15,7 @@ #include "shreduler_private.h" #include "emit.h" #include "gwion.h" +#include "value.h" #include "operator.h" #include "import.h" #include "map_private.h" diff --git a/src/vm/vm_code.c b/src/vm/vm_code.c index 3335c0e6..597007f5 100644 --- a/src/vm/vm_code.c +++ b/src/vm/vm_code.c @@ -12,6 +12,7 @@ #include "array.h" #include "memoize.h" #include "gwion.h" +#include "value.h" #include "operator.h" #include "import.h" -- 2.43.0