From ba453a2650e0ac555ea4c3b8c5459e908f0a3bea Mon Sep 17 00:00:00 2001 From: fennecdjay Date: Thu, 15 Aug 2019 01:40:00 +0200 Subject: [PATCH] :bomb: Fix static object issues --- src/emit/emit.c | 4 +++- src/parse/check.c | 14 +++++++++++--- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/emit/emit.c b/src/emit/emit.c index 1bf61461..2a474550 100644 --- a/src/emit/emit.c +++ b/src/emit/emit.c @@ -588,6 +588,8 @@ ANN static m_bool decl_static(const Emitter emit, const Var_Decl var_decl, const CHECK_BB(emit_instantiate_object(emit, v->type, var_decl->array, is_ref)) CHECK_BB(emit_dot_static_data(emit, v, 1)) emit_add_instr(emit, Assign); + emit_add_instr(emit, RegAddRef); + regpop(emit, SZ_INT); emit->code = code; return GW_OK; } @@ -1470,7 +1472,7 @@ ANN static m_bool emit_union_def(const Emitter emit, const Union_Def udef) { SET_FLAG(udef->l->self->d.exp_decl.list->self->value, enum); } if(udef->xid) - regpop(emit, !GET_FLAG(udef, static) ? SZ_INT : SZ_INT*2); + regpop(emit, SZ_INT); emit_union_offset(udef->l, udef->o); if(udef->xid || udef->type_xid || global) emit_pop(emit, scope); diff --git a/src/parse/check.c b/src/parse/check.c index 48cfaf0a..b2851273 100644 --- a/src/parse/check.c +++ b/src/parse/check.c @@ -222,14 +222,22 @@ ANN static Type check_exp_prim_this(const Env env, const Exp_Primary* primary) { return env->class_def; } + +ANN static inline Value prim_str_value(const Env env, const Symbol sym) { + const Value v = nspc_lookup_value0(env->global_nspc, sym); + if(v) + return v; + const Value value = new_value(env->gwion->mp, t_string, s_name(sym)); + map_set(&env->global_nspc->info->value->map, (vtype)sym, (vtype)value); + return value; +} + ANN static Type prim_str(const Env env, Exp_Primary *const prim) { if(!prim->value) { const m_str str = prim->d.str; - const Value v = new_value(env->gwion->mp, t_string, str); char c[strlen(str) + 8]; sprintf(c, "%s:string", str); - nspc_add_value(env_nspc(env), insert_symbol(c), v); - prim->value = v; + prim->value = prim_str_value(env, insert_symbol(c)); } return t_string; } -- 2.43.0