From: fennecdjay Date: Wed, 4 Sep 2019 00:23:32 +0000 (+0200) Subject: :bug: Thanks AFL X-Git-Tag: nightly~2236 X-Git-Url: http://10.10.0.4:5575/?a=commitdiff_plain;h=864f9b251a27ccc4537e8f1b8aea7b49ea18d3ee;p=gwion.git :bug: Thanks AFL --- diff --git a/src/emit/emit.c b/src/emit/emit.c index 8e73c0e0..f9002f02 100644 --- a/src/emit/emit.c +++ b/src/emit/emit.c @@ -777,12 +777,47 @@ ANN static m_bool emit_exp_call(const Emitter emit, const Exp_Call* exp_call) { return emit_exp_call1(emit, exp_call->m_func); } +ANN static m_uint get_decl_size(Var_Decl_List a) { + m_uint size = 0; + do //if(GET_FLAG(a->self->value, used)) + size += a->self->value->type->size; + while((a = a->next)); + return size; +} + +ANN static m_uint pop_exp_size(const Emitter emit, Exp e) { + m_uint size = 0; + do { + if(e->exp_type == ae_exp_primary && + e->d.exp_primary.primary_type == ae_primary_hack) { + size += pop_exp_size(emit, e->d.exp_primary.d.exp); + continue; + } + size += (e->exp_type == ae_exp_decl ? + get_decl_size(e->d.exp_decl.list) : e->type->size); + } while((e = e->next)); + return size; +} + +ANN static inline void pop_exp(const Emitter emit, Exp e) { + const m_uint size = pop_exp_size(emit, e); + if(size) + regpop(emit, size); +} + +ANN static inline m_bool emit_exp_pop_next(const Emitter emit, Exp e, const m_bool addref) { + CHECK_BB(emit_exp(emit, e, addref)) + if(e->next) + pop_exp(emit, e->next); + return GW_OK; +} + ANN static m_bool emit_exp_binary(const Emitter emit, const Exp_Binary* bin) { const Exp lhs = bin->lhs; const Exp rhs = bin->rhs; struct Op_Import opi = { .op=bin->op, .lhs=lhs->type, .rhs=rhs->type, .pos=exp_self(bin)->pos, .data = (uintptr_t)bin }; - CHECK_BB(emit_exp(emit, lhs, 1)) - CHECK_BB(emit_exp(emit, rhs, 1)) + CHECK_BB(emit_exp_pop_next(emit, lhs, 1)) + CHECK_BB(emit_exp_pop_next(emit, rhs, 1)) return op_emit(emit, &opi); } @@ -1128,44 +1163,9 @@ ANN2(1) static m_bool emit_exp(const Emitter emit, Exp exp, const m_bool ref) { 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)) - size += a->self->value->type->size; - while((a = a->next)); - return size; -} - -ANN static m_uint pop_exp_size(const Emitter emit, Exp e) { - m_uint size = 0; - do { - if(e->exp_type == ae_exp_primary && - e->d.exp_primary.primary_type == ae_primary_hack) { - size += pop_exp_size(emit, e->d.exp_primary.d.exp); - continue; - } - size += (e->exp_type == ae_exp_decl ? - get_decl_size(e->d.exp_decl.list) : e->type->size); - } while((e = e->next)); - return size; -} - -ANN static inline void pop_exp(const Emitter emit, Exp e) { - const m_uint size = pop_exp_size(emit, e); - if(size) - regpop(emit, size); -} - -ANN static inline m_bool emit_exp_pop_next(const Emitter emit, Exp e) { - CHECK_BB(emit_exp(emit, e, 0)) - if(e->next) - pop_exp(emit, e->next); - 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)) + CHECK_BB(emit_exp_pop_next(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)) @@ -1199,7 +1199,7 @@ 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) return optimize_taill_call(emit, &stmt->val->d.exp_call); - CHECK_BB(emit_exp_pop_next(emit, stmt->val)) + CHECK_BB(emit_exp_pop_next(emit, stmt->val, 0)) if(isa(stmt->val->type, t_object) > 0 && isa(stmt->val->type , t_shred) < 0) // beware shred emit_add_instr(emit, RegAddRef); } @@ -1236,7 +1236,7 @@ ANN static void emit_pop_stack(const Emitter emit, const m_uint index) { } ANN static Instr _flow(const Emitter emit, const Exp e, const m_bool b) { - CHECK_BO(emit_exp_pop_next(emit, e)) + CHECK_BO(emit_exp_pop_next(emit, e, 0)) const f_instr instr_i = b ? BranchEqInt : BranchNeqInt; const f_instr instr_f = b ? BranchEqFloat : BranchNeqFloat; return emit_flow(emit, e->type, instr_i, instr_f); @@ -1266,7 +1266,7 @@ ANN static m_bool emit_stmt_for(const Emitter emit, const Stmt_For stmt) { CHECK_BB(emit_stmt(emit, stmt->c1, 1)) const m_uint index = emit_code_size(emit); if(stmt->c2->stmt_type == ae_stmt_exp) - emit_exp_pop_next(emit, stmt->c2->d.stmt_exp.val); + emit_exp_pop_next(emit, stmt->c2->d.stmt_exp.val, 0); else CHECK_BB(emit_stmt(emit, stmt->c2, 0)) const Instr op = emit_flow(emit, stmt->c2->d.stmt_exp.val->type, @@ -1319,7 +1319,7 @@ ANN static m_bool emit_stmt_auto(const Emitter emit, const Stmt_Auto stmt) { ANN static m_bool emit_stmt_loop(const Emitter emit, const Stmt_Loop stmt) { emit_push_stack(emit); - CHECK_BB(emit_exp_pop_next(emit, stmt->cond)) + CHECK_BB(emit_exp_pop_next(emit, stmt->cond, 0)) const m_uint index = emit_code_size(emit); const Instr cpy = emit_add_instr(emit, Reg2RegAddr); cpy->m_val2 = -SZ_INT; diff --git a/src/lib/instr.c b/src/lib/instr.c index b42b75f2..311d884a 100644 --- a/src/lib/instr.c +++ b/src/lib/instr.c @@ -120,7 +120,7 @@ INSTR(DotTmpl) { *(VM_Code*)shred->reg = def->base->func->code; shred->reg += SZ_INT; return; - } + } else break; } } while((t = t->e->parent)); Except(shred, "MissigTmplException[internal]"); //unreachable diff --git a/src/oo/env.c b/src/oo/env.c index e27284ce..5e0532b5 100644 --- a/src/oo/env.c +++ b/src/oo/env.c @@ -98,7 +98,8 @@ ANN void env_add_type(const Env env, const Type type) { const Value v = new_value(env->gwion->mp, v_type, s_name(sym)); SET_FLAG(v, checked | ae_flag_const | ae_flag_global | ae_flag_builtin); nspc_add_value(env->curr, insert_symbol(type->name), v); - type->e->owner = env->curr; + v->owner = type->e->owner = env->curr; + v->owner_class = env->class_def; type->xid = ++env->scope->type_xid; } diff --git a/src/oo/type.c b/src/oo/type.c index 46b01ed8..37ed44b9 100644 --- a/src/oo/type.c +++ b/src/oo/type.c @@ -124,7 +124,7 @@ ANN Type array_type(const Env env, const Type base, const m_uint depth) { ADD_REF(t->nspc); SET_FLAG(t, checked); t->e->owner = base->e->owner; - nspc_add_type(base->e->owner, sym, t); + map_set(&base->e->owner->info->type->map, (vtype)sym, (vtype)t); return t; } diff --git a/src/parse/check.c b/src/parse/check.c index 9b523c7e..b75a4276 100644 --- a/src/parse/check.c +++ b/src/parse/check.c @@ -113,6 +113,12 @@ ANN Type check_exp_decl(const Env env, const Exp_Decl* decl) { clear_decl(env, decl); CHECK_BO(scan1_exp(env, exp_self(decl))) CHECK_BO(scan2_exp(env, exp_self(decl))) + if(isa(decl->type, t_class) > 0) { + do { + list->self->value->type = t_auto; + } while((list = list->next)); + ((Exp_Decl*)decl)->type = t_auto; + } if(decl->type == t_auto) ERR_O(td_pos(decl->td), _("can't infer type.")); } diff --git a/src/parse/did_you_mean.c b/src/parse/did_you_mean.c index 15495cb7..bfb959f1 100644 --- a/src/parse/did_you_mean.c +++ b/src/parse/did_you_mean.c @@ -42,7 +42,7 @@ ANN static void ressembles(const Vector v, const Nspc nspc, const char* name) { struct scope_iter iter = { nspc->info->value, 0, 0 }; Value value; while(scope_iter(&iter, &value) > 0) { - if(!strcmp(name, value->name)) + if(strcmp(name, value->name)) continue; if(wagner_fisher(name, value->name)) vector_add(v, (vtype)value->name); diff --git a/src/parse/scan1.c b/src/parse/scan1.c index 7580124c..2fa307d5 100644 --- a/src/parse/scan1.c +++ b/src/parse/scan1.c @@ -26,7 +26,7 @@ ANN static inline void type_contains(const Type base, const Type t) { } ANN static m_bool type_recursive(const Env env, const Type_Decl *td, const Type t) { - if(env->class_def) { + if(env->class_def && !env->scope->depth) { type_contains(env->class_def, t); if(t->e->contains.ptr) { for(m_uint i = 0; i < vector_size(&t->e->contains); ++i) { @@ -92,7 +92,8 @@ ANN m_bool scan1_exp_decl(const Env env, const Exp_Decl* decl) { } else if(GET_FLAG(t, abstract) && !GET_FLAG(decl->td, ref)) ERR_B(exp_self(decl)->pos, _("Type '%s' is abstract, declare as ref. (use @)"), t->name) CHECK_OB(prim_ref(env, t, decl->td)) - //assert(!var->value); + if(env->class_def && isa(t, t_object) > 0) + type_contains(env->class_def, t); const Value v = var->value = former ?: new_value(env->gwion->mp, t, s_name(var->xid)); nspc_add_value(nspc, var->xid, v); v->flag = decl->td->flag; diff --git a/src/parse/scan2.c b/src/parse/scan2.c index 37bc6ff5..89e51c96 100644 --- a/src/parse/scan2.c +++ b/src/parse/scan2.c @@ -88,12 +88,10 @@ ANN m_bool scan2_fptr_def(const Env env, const Fptr_Def fptr) { CHECK_BB(scan2_args(env, def)) } else SET_FLAG(fptr->type, func); -// nspc_add_func(fptr->type->e->owner, fptr->base->xid, fptr->base->func); return GW_OK; } ANN m_bool scan2_type_def(const Env env, const Type_Def tdef) { -// return tdef->type->e->def ? scan2_class_def(env, tdef->type->e->def) : GW_OK; if(!tdef->type->e->def) return GW_OK; return isa(tdef->type, t_fptr) < 0 ? scan2_class_def(env, tdef->type->e->def) : GW_OK; } @@ -126,8 +124,6 @@ ANN static inline m_bool scan2_exp_primary(const Env env, const Exp_Primary* pri return scan2_exp(env, prim->d.array->exp); if(prim->primary_type == ae_primary_tuple) return scan2_exp(env, prim->d.tuple.exp); -// if(prim->primary_type == ae_primary_unpack) -// return scan2_exp(env, prim->d.tuple.exp); return GW_OK; } @@ -495,9 +491,10 @@ ANN2(1,2) m_bool scan2_fdef(const Env env, const Func_Def f, const Value overloa ANN m_bool scan2_func_def(const Env env, const Func_Def f) { const m_uint scope = !GET_FLAG(f, global) ? env->scope->depth : env_push_global(env); const Value overload = nspc_lookup_value0(env->curr, f->base->xid); -// const Value res = nspc_lookup_value1(env->global_nspc, f->base->xid); -// if(res) -// ERR_B(f->pos, _("'%s' already declared as type"), s_name(f->base->xid)) + const Value res = nspc_lookup_value1(env->curr, f->base->xid); + if(res && res->owner == env->global_nspc) + ERR_B(f->pos, _("'%s' already declared as value of type '%s'."), + res->name, res->type->name) f->stack_depth = (env->class_def && !GET_FLAG(f, static) && !GET_FLAG(f, global)) ? SZ_INT : 0; if(GET_FLAG(f, variadic)) f->stack_depth += SZ_INT; diff --git a/src/parse/type_decl.c b/src/parse/type_decl.c index f619878a..fd53fd63 100644 --- a/src/parse/type_decl.c +++ b/src/parse/type_decl.c @@ -18,6 +18,8 @@ ANN Type type_decl_resolve(const Env env, const Type_Decl* td) { DECL_OO(const Type, t, = scan_type(env, base, td)) const Type ret = !td->array ? t : array_type(env, t, td->array->depth); if(GET_FLAG(td, nonnull)) { + if(isa(ret, t_object) < 0 && isa(ret, t_function) < 0) + return ret; char c[strlen(t->name) + 9]; sprintf(c, "%s%s", ret->name, STR_NONNULL); const Symbol sym = insert_symbol(c);