From 1f2d4c56e7c54f767e05957918d88b5291d4ab17 Mon Sep 17 00:00:00 2001 From: fennecdjay Date: Tue, 1 Oct 2019 23:22:44 +0200 Subject: [PATCH] :art: Dont' forget to Remove pos from Implicit --- src/emit/emit.c | 4 +++- src/parse/check.c | 25 +++++++++---------------- 2 files changed, 12 insertions(+), 17 deletions(-) diff --git a/src/emit/emit.c b/src/emit/emit.c index 568a533e..7f8aabf7 100644 --- a/src/emit/emit.c +++ b/src/emit/emit.c @@ -1102,7 +1102,7 @@ ANN static m_bool emit_exp_unary(const Emitter emit, const Exp_Unary* unary) { ANN static m_bool emit_implicit_cast(const Emitter emit, const restrict Exp from, const restrict Type to) { - const struct Implicit imp = { .e=from, .t=to }; + const struct Implicit imp = { from, to, from->pos }; struct Op_Import opi = { .op=insert_symbol("@implicit"), .lhs=from->type, .rhs=to, .data=(m_uint)&imp }; return op_emit_bool(emit, &opi); } @@ -1424,6 +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); +puts(emit->env->name); +// SET_FLAG(udef->xid ? udef->value->type : udef->type, emit); return GW_OK; } diff --git a/src/parse/check.c b/src/parse/check.c index 21b79e2b..fbb4fc07 100644 --- a/src/parse/check.c +++ b/src/parse/check.c @@ -28,10 +28,10 @@ ANN static Type check_exp(const Env env, Exp exp); ANN static m_bool check_stmt_list(const Env env, Stmt_List list); ANN m_bool check_class_def(const Env env, const Class_Def class_def); -ANN static m_bool check_implicit(const Env env, const Symbol sym, +ANN static m_bool check_implicit(const Env env, const m_str str, const Exp e, const Type t) { - struct Implicit imp = { .e=e, .t=t }; - struct Op_Import opi = { .op=sym, .lhs=e->type, + struct Implicit imp = { .e=e, .t=t, .pos=e->pos }; + struct Op_Import opi = { .op=insert_symbol(str), .lhs=e->type, .rhs=t, .data=(uintptr_t)&imp, .pos=e->pos }; CHECK_OB(op_check(env, &opi)) e->nspc = env->curr; @@ -39,7 +39,6 @@ ANN static m_bool check_implicit(const Env env, const Symbol sym, } ANN m_bool check_exp_array_subscripts(Env env, Exp exp) { -// TODO: use "@access" check_implicit CHECK_OB(check_exp(env, exp)) do if(isa(exp->type, env->gwion->type[et_int]) < 0) ERR_B(exp->pos, _("incompatible array subscript type '%s' ..."), exp->type->name) @@ -180,8 +179,7 @@ ANN static m_bool prim_array_inner(const Env env, Type type, const Exp e) { const Type common = find_common_anc(e->type, type); if(common) return GW_OK; - const Symbol sym = insert_symbol("@implicit"); - if(check_implicit(env, sym, e, type) < 0) + if(check_implicit(env, "@implicit", e, type) < 0) ERR_B(e->pos, _("array init [...] contains incompatible types ...")) set_cast(env, type, e); // ??? return GW_OK; @@ -282,9 +280,8 @@ ANN static Type prim_id(const Env env, Exp_Primary* primary) { ANN static m_bool vec_value(const Env env, Exp e) { int count = 1; CHECK_OB(check_exp(env, e)) - const Symbol sym = insert_symbol("@implicit"); do { - if(check_implicit(env, sym, e, env->gwion->type[et_float]) < 0) + if(check_implicit(env, "@implicit", e, env->gwion->type[et_float]) < 0) ERR_B(e->pos, _("invalid type '%s' in value #%d...\n"), e->type->name, count) ++count; } while((e = e->next)); @@ -458,10 +455,8 @@ ANN static m_bool func_match_inner(const Env env, const Exp e, const Type t, insert_symbol(t->e->owner->name)); return check_lambda(env, owner, &e->d.exp_lambda, t->e->d.func->def); } - if(implicit) { - const Symbol sym = insert_symbol("@implicit"); - return check_implicit(env, sym, e, t); - } + if(implicit) + return check_implicit(env, "@implicit", e, t); } return match ? 1 : -1; } @@ -1044,8 +1039,7 @@ ANN static m_bool do_stmt_auto(const Env env, const Stmt_Auto stmt) { } ANN static inline m_bool cond_type(const Env env, const Exp e) { - const Symbol sym = insert_symbol("@repeat"); - return check_implicit(env, sym, e, env->gwion->type[et_int]); + return check_implicit(env, "@repeat", e, env->gwion->type[et_int]); } #define stmt_func_xxx(name, type, prolog, exp) describe_stmt_func(check, name, type, prolog, exp) @@ -1080,8 +1074,7 @@ ANN static m_bool check_stmt_return(const Env env, const Stmt_Exp stmt) { } if(isa(ret_type, env->func->def->base->ret_type) > 0) return GW_OK; - const Symbol sym = insert_symbol("@implicit"); - return check_implicit(env, sym, stmt->val, env->func->def->base->ret_type); + return check_implicit(env, "@implicit", stmt->val, env->func->def->base->ret_type); } #define describe_check_stmt_stack(stack, name) \ -- 2.43.0