From 662fe69f0c2baace96cecb0250b5d00d9fc52633 Mon Sep 17 00:00:00 2001 From: fennecdjay Date: Wed, 2 Oct 2019 00:04:02 +0200 Subject: [PATCH] :art: Dedicated check_implicit --- src/parse/check.c | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/src/parse/check.c b/src/parse/check.c index fbb4fc07..eecbe7c2 100644 --- a/src/parse/check.c +++ b/src/parse/check.c @@ -28,7 +28,7 @@ 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 m_str str, +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, .pos=e->pos }; struct Op_Import opi = { .op=insert_symbol(str), .lhs=e->type, @@ -38,6 +38,22 @@ ANN static m_bool check_implicit(const Env env, const m_str str, return GW_OK; } +ANN static m_bool check_internal(const Env env, const Symbol sym, + const Exp e, const Type t) { + struct Implicit imp = { .e=e, .t=t, .pos=e->pos }; + struct Op_Import opi = { .op=sym, .lhs=e->type, + .rhs=t, .data=(uintptr_t)&imp, .pos=e->pos }; + CHECK_OB(op_check(env, &opi)) + e->nspc = env->curr; + return GW_OK; +} + +ANN static inline m_bool check_implicit(const Env env, const Exp e, const Type t) { + const Symbol sym = insert_symbol("@implicit"); + return check_internal(env, sym, e, t); +} + + ANN m_bool check_exp_array_subscripts(Env env, Exp exp) { CHECK_OB(check_exp(env, exp)) do if(isa(exp->type, env->gwion->type[et_int]) < 0) @@ -179,7 +195,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; - if(check_implicit(env, "@implicit", e, type) < 0) + if(check_implicit(env, e, type) < 0) ERR_B(e->pos, _("array init [...] contains incompatible types ...")) set_cast(env, type, e); // ??? return GW_OK; @@ -281,7 +297,7 @@ ANN static m_bool vec_value(const Env env, Exp e) { int count = 1; CHECK_OB(check_exp(env, e)) do { - if(check_implicit(env, "@implicit", e, env->gwion->type[et_float]) < 0) + if(check_implicit(env, 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)); @@ -456,7 +472,7 @@ ANN static m_bool func_match_inner(const Env env, const Exp e, const Type t, return check_lambda(env, owner, &e->d.exp_lambda, t->e->d.func->def); } if(implicit) - return check_implicit(env, "@implicit", e, t); + return check_implicit(env, e, t); } return match ? 1 : -1; } @@ -1039,7 +1055,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) { - return check_implicit(env, "@repeat", 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) @@ -1074,7 +1090,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; - return check_implicit(env, "@implicit", stmt->val, env->func->def->base->ret_type); + return check_implicit(env, stmt->val, env->func->def->base->ret_type); } #define describe_check_stmt_stack(stack, name) \ -- 2.43.0