From: fennecdjay Date: Sat, 16 Jul 2022 11:09:55 +0000 (+0200) Subject: :art: More robust value scope X-Git-Tag: nightly~264^2~97 X-Git-Url: http://10.10.0.4:5575/?a=commitdiff_plain;h=d8d1b0a9307ea6dc8bfa4993cf83ad2bfba89694;p=gwion.git :art: More robust value scope --- diff --git a/examples/auto.gw b/examples/auto.gw index c4056df1..7ae6e710 100644 --- a/examples/auto.gw +++ b/examples/auto.gw @@ -1,3 +1,3 @@ -var Object i[4]; +var Object[4] i; foreach(a: i) <<< a >>>; diff --git a/include/env/type.h b/include/env/type.h index 821fa183..d7a234a0 100644 --- a/include/env/type.h +++ b/include/env/type.h @@ -13,6 +13,7 @@ struct TypeInfo_ { struct TupleForm_ *tuple; struct VM_Code_ * gack; ID_List traits; + Scope values; }; enum tflag { diff --git a/src/emit/emit.c b/src/emit/emit.c index 4f170060..c38377cf 100644 --- a/src/emit/emit.c +++ b/src/emit/emit.c @@ -900,7 +900,7 @@ ANN static m_bool emit_prim_locale(const Emitter emit, const Symbol *id) { const VM_Code code = finalyze(emit, EOC); const VM_Shred shred = new_vm_shred(emit->gwion->mp, code); vm_add_shred(emit->gwion->vm, shred); - shred->info->me->ref++; +// shred->info->me->ref++; vm_run(emit->gwion->vm); emit->gwion->vm->bbq->is_running = true; const m_float ret = *(m_float*)shred->reg; @@ -2008,8 +2008,8 @@ ANN static m_bool emit_stmt_return(const Emitter emit, const Stmt_Exp stmt) { if (stmt->val->exp_type == ae_exp_call && emit->env->func == f) return optimize_tail_call(emit, &stmt->val->d.exp_call); } - if(!stmt->val->ref && isa(stmt->val->type, emit->gwion->type[et_compound]) > 0) - emit_local(emit, stmt->val->type); +// if(!stmt->val->ref && isa(stmt->val->type, emit->gwion->type[et_compound]) > 0) +// emit_local(emit, stmt->val->type); CHECK_BB(emit_exp(emit, stmt->val)); } vector_add(&emit->code->stack_return, (vtype)emit_add_instr(emit, Goto)); diff --git a/src/lib/closure.c b/src/lib/closure.c index ef5f8165..43a66c48 100644 --- a/src/lib/closure.c +++ b/src/lib/closure.c @@ -334,6 +334,7 @@ ANN static m_bool _check_lambda(const Env env, Exp_Lambda *l, Upvalues upvalues = { .values = env->curr->info->value }; + if(env->class_def) env->class_def->info->values = env->curr->info->value; env->curr->info->value = new_scope(env->gwion->mp); l->def->base->values = &upvalues; const m_uint scope = env->scope->depth; diff --git a/src/lib/object_op.c b/src/lib/object_op.c index 10e346c7..e1087dd8 100644 --- a/src/lib/object_op.c +++ b/src/lib/object_op.c @@ -183,6 +183,8 @@ ANN static inline Value get_value(const Env env, const Exp_Dot *member, return value; if (env->func && env->func->def->base->values) return upvalues_lookup(env->func->def->base->values, member->xid); + if(t->info->values) + return (Value)scope_lookup1(t->info->values, (m_uint)member->xid); return NULL; } diff --git a/src/lib/xork.c b/src/lib/xork.c index 423b0bb6..997d9cb2 100644 --- a/src/lib/xork.c +++ b/src/lib/xork.c @@ -50,6 +50,7 @@ static OP_CHECK(opck_spork) { Upvalues upvalues = { .values = env->curr->info->value }; if(env->func && env->func->def->base->values) upvalues.parent = env->func->def->base->values; + if(env->class_def) env->class_def->info->values = env->curr->info->value; env->curr->info->value = new_scope(env->gwion->mp); if(unary->captures) { for(uint32_t i = 0; i < unary->captures->len; i++) { diff --git a/src/parse/check.c b/src/parse/check.c index 3c867395..b2097a0a 100644 --- a/src/parse/check.c +++ b/src/parse/check.c @@ -120,6 +120,7 @@ ANN /*static inline*/ m_bool ensure_check(const Env env, const Type t) { ANN m_bool ensure_traverse(const Env env, const Type t) { if (tflag(t, tflag_check) || !(tflag(t, tflag_cdef) || tflag(t, tflag_udef))) return GW_OK; + if(!tflag(t, tflag_tmpl)) return GW_OK; struct EnvSet es = {.env = env, .data = env, .func = (_exp_func)traverse_cdef, @@ -1041,8 +1042,6 @@ ANN static Type check_exp_unary(const Env env, const Exp_Unary *unary) { .data = (uintptr_t)unary, .pos = exp_self(unary)->pos}; DECL_OO(const Type, ret, = op_check(env, &opi)); - const Type t = actual_type(env->gwion, ret); - CHECK_BO(ensure_traverse(env, t)); return ret; } @@ -1090,6 +1089,8 @@ ANN static Type check_exp_dot(const Env env, Exp_Dot *member) { } ANN m_bool check_type_def(const Env env, const Type_Def tdef) { + if(tdef->ext->array && tdef->ext->array->exp) + CHECK_OB(check_exp(env, tdef->type->info->cdef->base.ext->array->exp)); if (tdef->when) { set_tflag(tdef->type, tflag_contract); struct Var_Decl_ decl = { .xid = insert_symbol("self"), .pos = tdef->when->pos }; @@ -1144,6 +1145,7 @@ ANN m_bool check_type_def(const Env env, const Type_Def tdef) { } return GW_OK; } + ANN static Type check_exp_lambda(const Env env, const Exp_If *exp_if NUSED) { return env->gwion->type[et_function]; } diff --git a/src/parse/scan2.c b/src/parse/scan2.c index a56afd61..dfda9c33 100644 --- a/src/parse/scan2.c +++ b/src/parse/scan2.c @@ -306,8 +306,10 @@ ANN static Func scan_new_func(const Env env, const Func_Def f, const Func func = new_func(env->gwion->mp, name, f); if (env->class_def && tflag(env->class_def, tflag_tmpl)) set_fflag(func, fflag_ftmpl); - if (fbflag(f->base, fbflag_lambda)) + if (fbflag(f->base, fbflag_lambda)) { + if(env->class_def) env->class_def->info->values = env->curr->info->value; env->curr->info->value = new_scope(env->gwion->mp); + } return func; }