From d1a7424f6ba7d56609711d1746cf8d1c38d853e4 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=A9mie=20Astor?= Date: Wed, 6 Jan 2021 13:22:26 +0100 Subject: [PATCH] :art: Improve value_data --- include/env/value.h | 3 ++- include/import/item.h | 2 +- src/emit/emit.c | 6 +++--- src/import/import_item.c | 4 ++-- src/lib/object_op.c | 3 ++- src/vm/vm.c | 2 +- 6 files changed, 11 insertions(+), 9 deletions(-) diff --git a/include/env/value.h b/include/env/value.h index 153a3cde..8ee40aaf 100644 --- a/include/env/value.h +++ b/include/env/value.h @@ -26,10 +26,11 @@ struct Value_ { Type type; m_str name; struct ValueFrom_ *from; - union value_data{ + union __attribute__((transparent_union)) value_data { m_uint num; m_float fnum; m_uint* ptr; + struct M_Object_ *obj; Func func_ref; } d; uint16_t ref; diff --git a/include/import/item.h b/include/import/item.h index 48ba820f..5090ad05 100644 --- a/include/import/item.h +++ b/include/import/item.h @@ -2,7 +2,7 @@ #define __IMPORT_ITEM ANN m_int gwi_item_ini(const Gwi gwi, const m_str type, const m_str name); -ANN2(1) m_int gwi_item_end(const Gwi gwi, const ae_flag flag, m_uint *const addr); +ANN2(1) m_int gwi_item_end(const Gwi gwi, const ae_flag flag, union value_data); #define gwi_item_end(a, b, c) gwi_item_end(a, (const ae_flag)(b), (m_uint*const)c) ANN void ck_clean_item(MemPool, ImportCK*); #endif diff --git a/src/emit/emit.c b/src/emit/emit.c index c4cb1406..615b0afc 100644 --- a/src/emit/emit.c +++ b/src/emit/emit.c @@ -619,9 +619,9 @@ ANN static m_bool emit_prim_str(const Emitter emit, const m_str *str) { } else c[0] = '\0'; const Value v = prim_self(str)->value; const Symbol sym = insert_symbol(c); - if(!v->d.ptr) - v->d.ptr = (m_uint*)new_string2(emit->gwion, NULL, s_name(sym)); - regpushi(emit, (m_uint)v->d.ptr); + if(!v->d.obj) + v->d.obj = new_string2(emit->gwion, NULL, s_name(sym)); + regpushi(emit, (m_uint)v->d.obj); emit_object_addref(emit, -SZ_INT, 0); return GW_OK; } diff --git a/src/import/import_item.c b/src/import/import_item.c index dd8311c4..129c35a2 100644 --- a/src/import/import_item.c +++ b/src/import/import_item.c @@ -30,7 +30,7 @@ ANN static m_int gwi_item_tmpl(const Gwi gwi) { } #undef gwi_item_end -ANN2(1) m_int gwi_item_end(const Gwi gwi, const ae_flag flag, m_uint *const addr) { +ANN2(1) m_int gwi_item_end(const Gwi gwi, const ae_flag flag, union value_data addr) { CHECK_BB(ck_ok(gwi, ck_item)) const Env env = gwi->gwion->env; gwi->ck->exp->d.exp_decl.td->flag = flag; @@ -38,7 +38,7 @@ ANN2(1) m_int gwi_item_end(const Gwi gwi, const ae_flag flag, m_uint *const addr return gwi_item_tmpl(gwi); CHECK_BB(traverse_exp(env, gwi->ck->exp)) const Value value = gwi->ck->exp->d.exp_decl.list->self->value; - value->d.ptr = addr; + value->d = addr; set_vflag(value, vflag_builtin); if(!env->class_def) SET_FLAG(value, global); diff --git a/src/lib/object_op.c b/src/lib/object_op.c index 2fdee4b2..6a68ad60 100644 --- a/src/lib/object_op.c +++ b/src/lib/object_op.c @@ -92,7 +92,8 @@ ANN static void emit_dot_static_data(const Emitter emit, const Value v, const ui static const f_instr regpushimm[] = { RegPushImm, RegPushImm2, RegPushImm3, RegPushImm4 }; ANN static void emit_dot_static_import_data(const Emitter emit, const Value v, const uint emit_addr) { - if(v->d.ptr && vflag(v, vflag_builtin) && GET_FLAG(v, const)) { +// if(v->d.ptr && vflag(v, vflag_builtin) && GET_FLAG(v, const)) { + if(vflag(v, vflag_builtin) && GET_FLAG(v, const)) { const m_uint size = v->type->size; const Instr instr = emit_kind(emit, size, emit_addr, regpushimm); instr->m_val = (m_uint)v->d.ptr; diff --git a/src/vm/vm.c b/src/vm/vm.c index 6c076bf0..89c4e8b5 100644 --- a/src/vm/vm.c +++ b/src/vm/vm.c @@ -365,7 +365,7 @@ regpushfloat: regpushother: // LOOP_OPTIM for(m_uint i = 0; i <= VAL2; i+= SZ_INT) - *(m_bit**)(reg+i) = (m_bit*)(VAL + i); + *(m_bit**)(reg+i) = *(m_bit**)(VAL + i); reg += VAL2; DISPATCH(); regpushaddr: -- 2.43.0