From: fennecdjay Date: Sun, 29 Sep 2019 21:06:12 +0000 (+0200) Subject: :bug: Fix some global related stuff X-Git-Tag: nightly~2198^2~215 X-Git-Url: http://10.10.0.4:5575/?a=commitdiff_plain;h=379bbf61eb002f2be5eb7eee2efa70f5522987e2;p=gwion.git :bug: Fix some global related stuff --- diff --git a/src/emit/emit.c b/src/emit/emit.c index c6c618cc..4545bd69 100644 --- a/src/emit/emit.c +++ b/src/emit/emit.c @@ -1390,6 +1390,7 @@ ANN static m_bool emit_union_def(const Emitter emit, const Union_Def udef) { const Var_Decl_List var_decl_list = new_var_decl_list(emit->gwion->mp, var_decl, NULL); const Exp exp = new_exp_decl(emit->gwion->mp, type_decl, var_decl_list); exp->d.exp_decl.type = udef->value->type; + SET_FLAG(udef->value->type, emit); var_decl->value = udef->value; const m_bool ret = emit_exp_decl(emit, &exp->d.exp_decl); free_exp(emit->gwion->mp, exp); @@ -1403,11 +1404,12 @@ ANN static m_bool emit_union_def(const Emitter emit, const Union_Def udef) { scope = emit_push_type(emit, udef->value->type); } else if(udef->type_xid) { union_allocdata(emit->gwion->mp, udef); + SET_FLAG(udef->type, emit); scope = emit_push_type(emit, udef->type); - } else if(emit->env->class_def) { + } else if(emit->env->class_def) {// miss flag ? if(!GET_FLAG(l->self->d.exp_decl.list->self->value, member)) udef->o = emit_local(emit, udef->s, 0); - } else if(global) { + } else if(global) {// miss flag? void* ptr = (void*)xcalloc(1, udef->s); l = udef->l; do { @@ -1422,7 +1424,8 @@ ANN static m_bool emit_union_def(const Emitter emit, const Union_Def udef) { emit_union_offset(udef->l, udef->o); if(udef->xid || udef->type_xid || global) emit_pop(emit, scope); - SET_FLAG(udef->xid ? udef->value->type : udef->type, emit); +puts(emit->env->name); +// SET_FLAG(udef->xid ? udef->value->type : udef->type, emit); return GW_OK; } diff --git a/src/lib/instr.c b/src/lib/instr.c index 6a49ec0c..3ee791f7 100644 --- a/src/lib/instr.c +++ b/src/lib/instr.c @@ -100,15 +100,18 @@ INSTR(DotTmpl) { if(f) { if(!f->code) break; - *(VM_Code*)shred->reg = f->code; - shred->reg += SZ_INT; + if(GET_FLAG(f, member)) + shred->reg += SZ_INT; + *(VM_Code*)(shred->reg-SZ_INT) = f->code; return; } else { const Func_Def def = traverse_tmpl(emit, dt, t->nspc); if(!def) continue; - *(VM_Code*)shred->reg = def->base->func->code; - shred->reg += SZ_INT; + const Func f = def->base->func; + if(GET_FLAG(f, member)) + shred->reg += SZ_INT; + *(VM_Code*)(shred->reg-SZ_INT) = f->code; return; } } while((t = t->e->parent)); diff --git a/src/oo/env.c b/src/oo/env.c index fb5e8bc4..870d5913 100644 --- a/src/oo/env.c +++ b/src/oo/env.c @@ -102,7 +102,7 @@ ANN m_bool type_engine_check_prog(const Env env, const Ast ast) { const m_bool ret = traverse_ast(env, ast); if(ret > 0) //{ nspc_commit(env->curr); - if(ret || env->context->global) + if(ret > 0 || env->context->global) vector_add(&env->scope->known_ctx, (vtype)ctx); else //nspc_rollback(env->global_nspc); REM_REF(ctx, env->gwion); diff --git a/src/oo/type.c b/src/oo/type.c index e9d95231..2f088c78 100644 --- a/src/oo/type.c +++ b/src/oo/type.c @@ -12,7 +12,7 @@ #include "tuple.h" ANN static void free_type(Type a, Gwion gwion) { - if(GET_FLAG(a, template)) { + if(GET_FLAG(a, template) || GET_FLAG(a, global)) { if(GET_FLAG(a, union)) { if(a->e->def->union_def) { if(!GET_FLAG(a, pure)) { // <=> decl_list diff --git a/src/parse/check.c b/src/parse/check.c index e7737ade..2dfe9668 100644 --- a/src/parse/check.c +++ b/src/parse/check.c @@ -518,8 +518,8 @@ ANN static inline Value template_get_ready(const Env env, const Value v, const m } static Func ensure_tmpl(const Env env, const Func_Def fdef, const Exp_Call *exp) { - const m_bool ret = traverse_func_def(env, fdef); - if(ret > 0) { + const m_bool ret = GET_FLAG(fdef, checked) || traverse_func_def(env, fdef) > 0; + if(ret) { const Func f = fdef->base->func; const Func next = f->next; f->next = NULL; @@ -1365,6 +1365,7 @@ ANN m_bool check_func_def(const Env env, const Func_Def fdef) { nspc_pop_value(env->gwion->mp, env->curr); --env->scope->depth; env->func = former; + SET_FLAG(fdef, checked); if(GET_FLAG(fdef, global)) env_pop(env,scope); return ret; diff --git a/src/parse/scan0.c b/src/parse/scan0.c index 6e08e540..859be604 100644 --- a/src/parse/scan0.c +++ b/src/parse/scan0.c @@ -285,22 +285,17 @@ ANN m_bool scan0_union_def(const Env env, const Union_Def udef) { ANN static m_bool scan0_class_def_pre(const Env env, const Class_Def cdef) { CHECK_BB(env_storage(env, cdef->flag, cdef->pos)) - if(GET_FLAG(cdef, global)) { - vector_add(&env->scope->nspc_stack, (vtype)env->curr); - env->curr = env->global_nspc; - env->context->global = 1; - } - CHECK_BB(scan0_defined(env, cdef->base.xid, cdef->pos)) CHECK_BB(isres(env, cdef->base.xid, cdef->pos)) return GW_OK; } ANN static Type scan0_class_def_init(const Env env, const Class_Def cdef) { + CHECK_BO(scan0_defined(env, cdef->base.xid, cdef->pos)) const Type t = scan0_type(env, ++env->scope->type_xid, s_name(cdef->base.xid), env->gwion->type[et_object]); t->e->owner = env->curr; t->nspc = new_nspc(env->gwion->mp, t->name); // t->nspc->parent = GET_FLAG(cdef, global) ? env_nspc(env) : env->curr; - t->nspc->parent = GET_FLAG(cdef, global) ? env->global_nspc : env->curr; + t->nspc->parent = env->curr; t->e->def = cdef; t->flag = cdef->flag; if(!strstr(t->name, "<")) @@ -342,8 +337,13 @@ ANN static m_bool scan0_class_def_inner(const Env env, const Class_Def cdef) { } ANN m_bool scan0_class_def(const Env env, const Class_Def cdef) { - CHECK_BB(scan0_class_def_pre(env, cdef)) - const m_bool ret = scan0_class_def_inner(env, cdef); + if(GET_FLAG(cdef, global)) { + vector_add(&env->scope->nspc_stack, (vtype)env->curr); + env->curr = env->global_nspc; + env->context->global = 1; + } + const m_bool ret = scan0_class_def_pre(env, cdef) > 0 ? + scan0_class_def_inner(env, cdef) : GW_ERROR; if(GET_FLAG(cdef, global)) env->curr = (Nspc)vector_pop(&env->scope->nspc_stack); return ret; diff --git a/src/parse/scan2.c b/src/parse/scan2.c index 2e649635..8323f549 100644 --- a/src/parse/scan2.c +++ b/src/parse/scan2.c @@ -344,7 +344,7 @@ ANN2(1,2) static Value func_value(const Env env, const Func f, CHECK_OO(scan2_func_assign(env, f->def, f, v)) if(!overload) { ADD_REF(v); - nspc_add_value(env->curr, f->def->base->xid, v); + nspc_add_value_front(env->curr, f->def->base->xid, v); } else if(overload->d.func_ref) { f->next = overload->d.func_ref->next; overload->d.func_ref->next = f;