From: fennecdjay Date: Sat, 30 Jul 2022 14:10:30 +0000 (+0200) Subject: :art: :bug: Update X-Git-Tag: nightly~264^2~64 X-Git-Url: http://10.10.0.4:5575/?a=commitdiff_plain;h=5da7d2287a16ebb694626e66a9400d5292fa64fa;p=gwion.git :art: :bug: Update --- diff --git a/src/emit/emit.c b/src/emit/emit.c index bd45e771..297e8978 100644 --- a/src/emit/emit.c +++ b/src/emit/emit.c @@ -926,26 +926,11 @@ ANN static m_bool emit_dot_static_data(const Emitter emit, const Value v, return GW_OK; } -ANN static m_bool emit_instantiate_new(const Emitter emit, const Exp_Decl *decl) { - struct Exp_ e = { - .d = { .exp_unary = { - .op = insert_symbol("new"), - .ctor = { .td = decl->td, .exp = decl->args }, - .unary_type = unary_td - }}, - .exp_type = ae_exp_unary, - .pos = decl->td->pos - }; - CHECK_BB(traverse_exp(emit->env, &e)); - CHECK_BB(emit_exp(emit, &e)); - 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) { const Value v = var_decl->value; if(!decl->args) CHECK_BB(emit_instantiate_decl(emit, v->type, decl->td, is_ref)); - else CHECK_BB(emit_instantiate_new(emit, decl)); + else CHECK_BB(emit_exp(emit, decl->args)); CHECK_BB(emit_dot_static_data(emit, v, 1)); emit_add_instr(emit, Assign); // if(get_depth(var_decl->value->type) && !is_ref) @@ -1041,7 +1026,7 @@ ANN static m_bool emit_exp_decl_non_static(const Emitter emit, if (is_obj && !is_ref && !exp_self(decl)->ref) { // if (is_obj && ((is_array && !exp_self(decl)->ref) || !is_ref)) if(!decl->args) CHECK_BB(emit_instantiate_decl(emit, type, decl->td, is_ref)); - else CHECK_BB(emit_instantiate_new(emit, decl)); + else CHECK_BB(emit_exp(emit, decl->args)); } f_instr *exec = (f_instr *)allocmember; if (!emit->env->scope->depth) emit_debug(emit, v); @@ -1084,7 +1069,7 @@ ANN static m_bool emit_exp_decl_global(const Emitter emit, const Exp_Decl *decl, const bool emit_addr = (!is_obj || is_ref) ? emit_var : true; if (is_obj && !is_ref) { if(!decl->args) CHECK_BB(emit_instantiate_decl(emit, type, decl->td, is_ref)); - else CHECK_BB(emit_instantiate_new(emit, decl)); + else CHECK_BB(emit_exp(emit, decl->args)); } const Instr instr = emit_dotstatic(emit, v->type->size, !struct_ctor(v) ? emit_addr : 1); diff --git a/src/parse/check.c b/src/parse/check.c index 1ef192f6..2fcea6a9 100644 --- a/src/parse/check.c +++ b/src/parse/check.c @@ -135,20 +135,15 @@ ANN static inline m_bool inferable(const Env env, const Type t, ERR_B(pos, _("can't infer type.")) } -ANN Type check_exp_decl(const Env env, const Exp_Decl *decl) { +ANN Type check_exp_decl(const Env env, Exp_Decl *const decl) { if (decl->td->array && decl->td->array->exp) CHECK_OO(check_exp(env, decl->td->array->exp)); - if (decl->args) { - struct Exp_ e = { - .d = { .exp_unary = { - .op = insert_symbol("new"), - .ctor = { .td = decl->td, .exp = decl->args }, - .unary_type = unary_td - }}, - .exp_type = ae_exp_unary, - .pos = decl->td->pos - }; - CHECK_OO(check_exp(env, &e)); + if (decl->args && !decl->args->type) { // for some reason this can be parsed twice + Exp e = new_exp_unary2(env->gwion->mp, insert_symbol("new"), cpy_type_decl(env->gwion->mp, decl->td), decl->args, decl->td->pos); + CHECK_OO(check_exp(env, e)); + Exp args = decl->args; + decl->args = e; + free_exp(env->gwion->mp, args); } if (decl->td->xid == insert_symbol("auto")) { // should be better CHECK_BO(scan1_exp(env, exp_self(decl))); @@ -166,7 +161,10 @@ ANN Type check_exp_decl(const Env env, const Exp_Decl *decl) { const m_bool global = GET_FLAG(decl->td, global); const m_uint scope = !global ? env->scope->depth : env_push_global(env); const m_bool ret = check_decl(env, decl); - if (global) env_pop(env, scope); + if (global) { + env_pop(env, scope); + set_vflag(decl->vd.value, vflag_direct); + } env_weight(env, 1 + isa(decl->type, env->gwion->type[et_object]) > 0); return ret > 0 ? decl->vd.value->type : NULL; } diff --git a/src/parse/scan1.c b/src/parse/scan1.c index a6094ef3..fb71e5bf 100644 --- a/src/parse/scan1.c +++ b/src/parse/scan1.c @@ -122,8 +122,7 @@ ANN static m_bool scan1_decl(const Env env, Exp_Decl *const decl) { } const Value v = vd->value = vd->value ?: new_value(env, t, s_name(vd->xid), vd->pos); - nspc_add_value(env->curr, vd->xid, v); - if (GET_FLAG(t, abstract) && !GET_FLAG(decl->td, late)) SET_FLAG(v, late); + if (GET_FLAG(t, abstract) && !decl->args && !GET_FLAG(decl->td, late)) SET_FLAG(v, late); v->type = t; if (decl_ref) SET_FLAG(v, late); v->flag |= decl->td->flag; @@ -164,6 +163,7 @@ ANN m_bool scan1_exp_decl(const Env env, Exp_Decl *const decl) { } const m_uint scope = !global ? env->scope->depth : env_push_global(env); const m_bool ret = scan1_decl(env, decl); + valid_value(env, decl->vd.xid, decl->vd.value); if (global) env_pop(env, scope); return ret; } @@ -363,13 +363,13 @@ ANN static inline m_bool scan1_stmt_exp(const Env env, const Stmt_Exp stmt) { ANN m_bool scan1_enum_def(const Env env, const Enum_Def edef) { edef->t->nspc = new_nspc(env->gwion->mp, edef->t->name); - const Nspc nspc = edef->t->nspc; const m_uint scope = env_push_type(env, edef->t); ID_List list = edef->list; for(uint32_t i = 0; i < list->len; i++) { Symbol xid = *mp_vector_at(list, Symbol, i); const Value v = new_value(env, edef->t, s_name(xid), edef->pos); valuefrom(env, v->from); + valid_value(env, xid, v); if (env->class_def) { SET_FLAG(v, static); SET_ACCESS(edef, v) @@ -378,7 +378,6 @@ ANN m_bool scan1_enum_def(const Env env, const Enum_Def edef) { set_vflag(v, vflag_builtin); SET_FLAG(v, const); set_vflag(v, vflag_valid); - nspc_add_value(nspc, xid, v); vector_add(&edef->values, (vtype)v); } env_pop(env, scope);