From 1289ed37e2437f2c77f9d94ea74c697d6bd825cb Mon Sep 17 00:00:00 2001 From: fennecdjay Date: Wed, 2 Oct 2019 00:53:31 +0200 Subject: [PATCH] :art: this for now --- include/operator.h | 2 +- src/emit/emit.c | 2 +- src/parse/check.c | 13 +++++-------- 3 files changed, 7 insertions(+), 10 deletions(-) diff --git a/include/operator.h b/include/operator.h index 149a584c..f401301d 100644 --- a/include/operator.h +++ b/include/operator.h @@ -19,8 +19,8 @@ struct Op_Import { struct Implicit { Exp e; Type t; + loc_t pos; }; - ANN m_bool add_op(const Gwion gwion, const struct Op_Import*); ANN Type op_check(const Env, struct Op_Import*); ANN struct Instr_* op_emit(const Emitter, const struct Op_Import*); diff --git a/src/emit/emit.c b/src/emit/emit.c index 90022be6..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); } diff --git a/src/parse/check.c b/src/parse/check.c index 530e7377..eecbe7c2 100644 --- a/src/parse/check.c +++ b/src/parse/check.c @@ -30,7 +30,7 @@ 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, const Exp e, const Type t) { - struct Implicit imp = { .e=e, .t=t }; + 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)) @@ -40,7 +40,7 @@ ANN static m_bool _check_implicit(const Env env, const m_str str, 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 }; + 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)) @@ -56,8 +56,7 @@ ANN static inline m_bool check_implicit(const Env env, const Exp e, const Type t ANN m_bool check_exp_array_subscripts(Env env, Exp exp) { CHECK_OB(check_exp(env, exp)) - const Type t_int = env->gwion->type[et_int]; - do if(isa(exp->type, t_int) < 0) + do if(isa(exp->type, env->gwion->type[et_int]) < 0) ERR_B(exp->pos, _("incompatible array subscript type '%s' ..."), exp->type->name) while((exp = exp->next)); return GW_OK; @@ -420,8 +419,7 @@ ANN static Type at_depth(const Env env, const Array_Sub array) { static inline m_bool index_is_int(const Env env, Exp e, m_uint *depth) { // TODO: use "@access" - const Type t_int = env->gwion->type[et_int]; - do if(isa(e->type, t_int) < 0) + do if(isa(e->type, env->gwion->type[et_int]) < 0) ERR_B(e->pos, _("array index %i must be of type 'int', not '%s'"), *depth, e->type->name) while(++(*depth) && (e = e->next)); @@ -1057,8 +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) { - const Type t_int = env->gwion->type[et_int]; - return _check_implicit(env, "@repeat", e, t_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) -- 2.43.0