From: fennecdjay Date: Wed, 28 Aug 2019 22:59:48 +0000 (+0200) Subject: :bug: Fix nonnull related bugs X-Git-Tag: nightly~2257 X-Git-Url: http://10.10.0.4:5575/?a=commitdiff_plain;h=5bbeac1491b0b9544b5c11ded53cb2d163841456;p=gwion.git :bug: Fix nonnull related bugs --- diff --git a/src/emit/emit.c b/src/emit/emit.c index 8ef5187b..7c5bfd6a 100644 --- a/src/emit/emit.c +++ b/src/emit/emit.c @@ -1132,38 +1132,6 @@ ANN2(1) static m_bool emit_exp(const Emitter emit, Exp exp, const m_bool ref) { return GW_OK; } -ANN static m_bool emit_stmt_if(const Emitter emit, const Stmt_If stmt) { - emit_push_scope(emit); - CHECK_BB(emit_exp(emit, stmt->cond, 0)) - DECL_OB(const Instr, op, = emit_flow(emit, isa(stmt->cond->type, t_object) > 0 ? - t_int : stmt->cond->type, BranchEqInt, BranchEqFloat)) - CHECK_BB(scoped_stmt(emit, stmt->if_body, 1)) - const Instr op2 = emit_add_instr(emit, Goto); - op->m_val = emit_code_size(emit); - if(stmt->else_body) - CHECK_BB(scoped_stmt(emit, stmt->else_body, 1)) - op2->m_val = emit_code_size(emit); - emit_pop_scope(emit); - return GW_OK; -} - -ANN static m_bool emit_stmt_code(const Emitter emit, const Stmt_Code stmt) { - ++emit->env->scope->depth; - const m_bool ret = stmt->stmt_list ? emit_stmt_list(emit, stmt->stmt_list) : 1; - --emit->env->scope->depth; - return ret; -} - -ANN static m_bool optimize_taill_call(const Emitter emit, const Exp_Call* e) { - if(e->args) { - CHECK_BB(emit_exp(emit, e->args, 0)) - regpop(emit, SZ_INT); - emit_args(emit, e->m_func); - } - emit_add_instr(emit, Goto); - return GW_OK; -} - ANN static m_uint get_decl_size(Var_Decl_List a) { m_uint size = 0; do //if(GET_FLAG(a->self->value, used)) @@ -1199,6 +1167,38 @@ ANN static inline m_bool emit_exp_pop_next(const Emitter emit, Exp e) { return GW_OK; } +ANN static m_bool emit_stmt_if(const Emitter emit, const Stmt_If stmt) { + emit_push_scope(emit); + CHECK_BB(emit_exp_pop_next(emit, stmt->cond)) + DECL_OB(const Instr, op, = emit_flow(emit, isa(stmt->cond->type, t_object) > 0 ? + t_int : stmt->cond->type, BranchEqInt, BranchEqFloat)) + CHECK_BB(scoped_stmt(emit, stmt->if_body, 1)) + const Instr op2 = emit_add_instr(emit, Goto); + op->m_val = emit_code_size(emit); + if(stmt->else_body) + CHECK_BB(scoped_stmt(emit, stmt->else_body, 1)) + op2->m_val = emit_code_size(emit); + emit_pop_scope(emit); + return GW_OK; +} + +ANN static m_bool emit_stmt_code(const Emitter emit, const Stmt_Code stmt) { + ++emit->env->scope->depth; + const m_bool ret = stmt->stmt_list ? emit_stmt_list(emit, stmt->stmt_list) : 1; + --emit->env->scope->depth; + return ret; +} + +ANN static m_bool optimize_taill_call(const Emitter emit, const Exp_Call* e) { + if(e->args) { + CHECK_BB(emit_exp(emit, e->args, 0)) + regpop(emit, SZ_INT); + emit_args(emit, e->m_func); + } + emit_add_instr(emit, Goto); + return GW_OK; +} + ANN static m_bool emit_stmt_return(const Emitter emit, const Stmt_Exp stmt) { if(stmt->val) { if(stmt->val->exp_type == ae_exp_call && emit->env->func == stmt->val->d.exp_call.m_func) diff --git a/src/lib/object.c b/src/lib/object.c index 16d74ec3..ded0d4d3 100644 --- a/src/lib/object.c +++ b/src/lib/object.c @@ -124,8 +124,10 @@ static OP_CHECK(at_object) { return t_null; if(check_nonnull(env, l, r, "assign", exp_self(bin)->pos) == t_null) return t_null; - if(bin->rhs->exp_type == ae_exp_decl) + if(bin->rhs->exp_type == ae_exp_decl) { SET_FLAG(bin->rhs->d.exp_decl.td, ref); + SET_FLAG(bin->rhs->d.exp_decl.list->self->value, ref); + } bin->rhs->emit_var = 1; return r; } diff --git a/src/parse/scan1.c b/src/parse/scan1.c index 71605cad..a58dddd5 100644 --- a/src/parse/scan1.c +++ b/src/parse/scan1.c @@ -25,7 +25,8 @@ ANN static Type void_type(const Env env, const Type_Decl* td) { ANN static inline Type get_base_type(const Env env, const Type t) { const m_str decl_name = get_type_name(env, t->name, 0); - return nspc_lookup_type1(env->curr, insert_symbol(decl_name)); + const Type ret = nspc_lookup_type1(env->curr, insert_symbol(decl_name)); + return !SAFE_FLAG(ret, nonnull) ? ret : ret->e->parent; } ANN static inline void type_contains(const Type base, const Type t) { @@ -46,8 +47,8 @@ ANN static m_bool type_recursive(const Env env, Exp_Decl* decl, const Type t) { type_contains(base, decl_base); // NEEDED type_contains(env->class_def, t); if(decl_base->e->contains.ptr) { - for(m_uint i = 0; i < vector_size(&t->e->contains); ++i) { - if(env->class_def == (Type)vector_at(&t->e->contains, i) && !GET_FLAG(decl->td, ref)) + for(m_uint i = 0; i < vector_size(&decl_base->e->contains); ++i) { + if(env->class_def == (Type)vector_at(&decl_base->e->contains, i) && !GET_FLAG(decl->td, ref)) ERR_B(exp_self(decl)->pos, _("%s declared inside %s\n. (make it a ref ?)"), decl_base->name, decl_base == base ? "itself" : base->name); } diff --git a/src/parse/scanx.c b/src/parse/scanx.c index 5ef23120..98e4486d 100644 --- a/src/parse/scanx.c +++ b/src/parse/scanx.c @@ -74,10 +74,11 @@ scanx_parent(const Type t, const _exp_func f, void* d) { ANN m_bool scanx_cdef(const Env env, void* opt, const Class_Def cdef, const _exp_func f_cdef, const _exp_func f_union) { - if(cdef->base.type->e->parent != t_union) - return f_cdef(opt, cdef); - CHECK_BB(template_push_types(env, cdef->base.tmpl)) - const m_bool ret = f_union(opt, cdef->union_def); + const Type t = get_type(cdef->base.type); + if(t->e->parent != t_union) + return f_cdef(opt, t->e->def); + CHECK_BB(template_push_types(env, t->e->def->base.tmpl)) + const m_bool ret = f_union(opt, t->e->def->union_def); nspc_pop_type(env->gwion->mp, env->curr); return ret; } diff --git a/src/parse/type_decl.c b/src/parse/type_decl.c index cf704ace..f619878a 100644 --- a/src/parse/type_decl.c +++ b/src/parse/type_decl.c @@ -25,7 +25,7 @@ ANN Type type_decl_resolve(const Env env, const Type_Decl* td) { if(exist) return exist; const Type t = type_copy(env->gwion->mp, ret); - t->e->parent = ret->e->parent; + t->e->parent = ret; if(t->nspc) ADD_REF(t->nspc) t->name = s_name(sym);