From: Jérémie Astor Date: Tue, 27 Apr 2021 20:50:07 +0000 (+0200) Subject: :art: uncures type_check macros X-Git-Tag: nightly~712 X-Git-Url: http://10.10.0.4:5575/?a=commitdiff_plain;h=8564340197d1261fe837dc3e6227e5238fa24dee;p=gwion.git :art: uncures type_check macros --- diff --git a/include/operator.h b/include/operator.h index aa82cb6e..80168864 100644 --- a/include/operator.h +++ b/include/operator.h @@ -3,14 +3,14 @@ #define OP_ANY_TYPE (Type)1 #define ERR_N(a, b, ...) do { env_err(env, (a), (b), ## __VA_ARGS__); return env->gwion->type[et_error]; } while(0) -#define DECL_ON(decl, f, exp) decl f exp; { if(!f) return env->gwion->type[et_error]; } -#define DECL_BN(decl, f, exp) decl f exp; { if(f < 0) return env->gwion->type[et_error]; } -#define DECL_NN(decl, f, exp) decl f exp; { if(f == env->gwion->type[et_error]) return env->gwion->type[et_error]; } -#define CHECK_ON(f) { if(!f) return env->gwion->type[et_error]; } -#define CHECK_NB(f) { if(f == env->gwion->type[et_error]) return GW_ERROR; } -#define CHECK_NO(f) { if(f == env->gwion->type[et_error]) return NULL; } -#define CHECK_BN(f) { if(f < 0) return env->gwion->type[et_error]; } -#define CHECK_NN(f) { if(f == env->gwion->type[et_error]) return env->gwion->type[et_error]; } +#define DECL_ON(decl, f, exp) decl f exp; do { if(!f) return env->gwion->type[et_error]; } while(0) +#define DECL_BN(decl, f, exp) decl f exp; do { if(f < 0) return env->gwion->type[et_error]; } while(0) +#define DECL_NN(decl, f, exp) decl f exp; do { if(f == env->gwion->type[et_error]) return env->gwion->type[et_error]; } while(0) +#define CHECK_ON(f) do { if(!f) return env->gwion->type[et_error]; } while(0) +#define CHECK_NB(f) do { if(f == env->gwion->type[et_error]) return GW_ERROR; } while(0) +#define CHECK_NO(f) do { if(f == env->gwion->type[et_error]) return NULL; } while(0) +#define CHECK_BN(f) do { if(f < 0) return env->gwion->type[et_error]; } while(0) +#define CHECK_NN(f) do { if(f == env->gwion->type[et_error]) return env->gwion->type[et_error]; } while(0) typedef Type (*opck)(const Env, void*); typedef m_bool (*opem)(const Emitter, void*); diff --git a/plug b/plug index 15e194f8..7680ae9a 160000 --- a/plug +++ b/plug @@ -1 +1 @@ -Subproject commit 15e194f8060ba4b94a4d3ae5ac985a92a8f92663 +Subproject commit 7680ae9aa87eb19cf084c5aa1b83b47b08a85732 diff --git a/src/lib/array.c b/src/lib/array.c index fc9d3f44..5c0077dc 100644 --- a/src/lib/array.c +++ b/src/lib/array.c @@ -295,7 +295,7 @@ static OP_CHECK(opck_array) { const Array_Sub array = (Array_Sub)data; const Type t_int = env->gwion->type[et_int]; Exp e = array->exp; - do CHECK_BN(check_implicit(env, e, t_int)) + do CHECK_BN(check_implicit(env, e, t_int)); while((e = e->next)); const Type t = array->type->array_depth ? array->type : typedef_base(array->type); if(t->array_depth >= array->depth) diff --git a/src/lib/lib_func.c b/src/lib/lib_func.c index d2964485..244b8b30 100644 --- a/src/lib/lib_func.c +++ b/src/lib/lib_func.c @@ -272,13 +272,13 @@ static OP_CHECK(opck_fptr_at) { bin->rhs->type->info->func->def->base->tmpl->call) { struct FptrInfo info = { bin->lhs->type->info->func, bin->rhs->type->info->parent->info->func, bin->lhs, exp_self(bin)->pos }; - CHECK_BN(fptr_do(env, &info)) + CHECK_BN(fptr_do(env, &info)); exp_setvar(bin->rhs, 1); return bin->rhs->type; } struct FptrInfo info = { bin->lhs->type->info->func, bin->rhs->type->info->func, bin->lhs, exp_self(bin)->pos }; - CHECK_BN(fptr_do(env, &info)) + CHECK_BN(fptr_do(env, &info)); exp_setvar(bin->rhs, 1); return bin->rhs->type; } @@ -288,7 +288,7 @@ static OP_CHECK(opck_fptr_cast) { const Type t = exp_self(cast)->type; struct FptrInfo info = { cast->exp->type->info->func, t->info->func, cast->exp, exp_self(cast)->pos }; - CHECK_BN(fptr_do(env, &info)) + CHECK_BN(fptr_do(env, &info)); return t; } @@ -316,7 +316,7 @@ static OP_CHECK(opck_fptr_impl) { struct Implicit *impl = (struct Implicit*)data; struct FptrInfo info = { impl->e->type->info->func, impl->t->info->func, impl->e, impl->e->pos }; - CHECK_BN(fptr_do(env, &info)) + CHECK_BN(fptr_do(env, &info)); return impl->t; } @@ -414,7 +414,7 @@ static inline void op_impl_ensure_types(const Env env, const Func func) { static OP_CHECK(opck_op_impl){ struct Implicit *impl = (struct Implicit*)data; const Func func = impl->t->info->func; - CHECK_BN(op_impl_narg(env, func->def, impl->e->pos)) + CHECK_BN(op_impl_narg(env, func->def, impl->e->pos)); op_impl_ensure_types(env, func); const Symbol lhs_sym = insert_symbol("@lhs"); const Symbol rhs_sym = insert_symbol("@rhs"); @@ -427,8 +427,8 @@ static OP_CHECK(opck_op_impl){ self.d.exp_binary.op = impl->e->d.prim.d.var; struct Op_Import opi = { .op=impl->e->d.prim.d.var, .lhs=func->def->base->args->type, .rhs=func->def->base->args->next->type, .data=(uintptr_t)&self.d.exp_binary, .pos=impl->e->pos }; - DECL_ON(const Type, t, = op_check(env, &opi)) - CHECK_BN(isa(t, func->def->base->ret_type)) + DECL_ON(const Type, t, = op_check(env, &opi)); + CHECK_BN(isa(t, func->def->base->ret_type)); // Find if the function exists Value v = nspc_lookup_value0(opi.nspc, impl->e->d.prim.d.var); if(v) { @@ -516,7 +516,7 @@ static OP_CHECK(opck_spork) { const m_bool ret = check_stmt(env, unary->code); nspc_pop_value(env->gwion->mp, env->curr); --env->scope->depth; - CHECK_BN(ret) + CHECK_BN(ret); return env->gwion->type[unary->op == insert_symbol("spork") ? et_shred : et_fork]; } ERR_O(exp_self(unary)->pos, _("only function calls can be sporked...")) diff --git a/src/lib/modules.c b/src/lib/modules.c index 9add9a64..c1c22207 100644 --- a/src/lib/modules.c +++ b/src/lib/modules.c @@ -216,7 +216,7 @@ static OP_CHECK(opck_usrugen) { ERR_N(exp_self(bin)->pos, _("Tick function must return float")); if(bin->lhs->type->info->func->value_ref->from->owner_class) CHECK_BN(isa(bin->lhs->type->info->func->value_ref->from->owner_class, - bin->rhs->type)) + bin->rhs->type)); return bin->rhs->type; } diff --git a/src/lib/object_op.c b/src/lib/object_op.c index 40a1365b..ad914876 100644 --- a/src/lib/object_op.c +++ b/src/lib/object_op.c @@ -34,7 +34,7 @@ static OP_CHECK(opck_object_at) { if(bin->rhs->exp_type == ae_exp_decl) SET_FLAG(bin->rhs->d.exp_decl.list->self->value, late); exp_setvar(bin->rhs, 1); - CHECK_BN(isa(bin->lhs->type , bin->rhs->type)) + CHECK_BN(isa(bin->lhs->type , bin->rhs->type)); return bin->rhs->type; } @@ -177,7 +177,7 @@ OP_CHECK(opck_object_dot) { did_you_mean_type(the_base, str); return env->gwion->type[et_error]; } - CHECK_BN(not_from_owner_class(env, the_base, value, exp_self(member)->pos)) + CHECK_BN(not_from_owner_class(env, the_base, value, exp_self(member)->pos)); if(!env->class_def || isa(env->class_def, value->from->owner_class) < 0) { if(GET_FLAG(value, private)) ERR_N(exp_self(member)->pos, diff --git a/src/lib/opfunc.c b/src/lib/opfunc.c index c4979b66..1d5e4a8b 100644 --- a/src/lib/opfunc.c +++ b/src/lib/opfunc.c @@ -35,7 +35,7 @@ OP_CHECK(opck_usr_implicit) { .type=f->value_ref->type }; struct Op_Import opi = { .op=insert_symbol("@func_check"), .rhs=f->value_ref->type, .pos=imp->e->pos, .data=(uintptr_t)&call }; - CHECK_NN(op_check(env, &opi)) + CHECK_NN(op_check(env, &opi)); } } */ @@ -98,7 +98,7 @@ ANN Type check_td(const Env env, Type_Decl *td); OP_CHECK(opck_new) { const Exp_Unary* unary = (Exp_Unary*)data; - DECL_ON(const Type, t, = known_type(env, unary->td)) + DECL_ON(const Type, t, = known_type(env, unary->td)); if(isa(t, env->gwion->type[et_object]) < 0) ERR_N(exp_self(unary)->pos, _("can't use 'new' on non-object types...\n")); if(type_ref(t)) @@ -106,7 +106,7 @@ OP_CHECK(opck_new) { if(GET_FLAG(t, abstract)) ERR_N(unary->td->pos, _("can't use 'new' on abstract type '%s'\n"), t->name); if(unary->td->array) - CHECK_BN(check_subscripts(env, unary->td->array, 1)) + CHECK_BN(check_subscripts(env, unary->td->array, 1)); return t; } diff --git a/src/lib/prim.c b/src/lib/prim.c index 595d0262..38375143 100644 --- a/src/lib/prim.c +++ b/src/lib/prim.c @@ -176,7 +176,7 @@ static OP_CHECK(opck_##ntype##_##name) { \ const Type t = env->gwion->type[TYPE]; \ if(!exp_self(unary)->pos.first.line || !func(unary->exp)) \ return t; \ - CHECK_NN(opck_unary_meta(env, data))\ + CHECK_NN(opck_unary_meta(env, data)); \ const ctype num = OP unary->exp->d.prim.d.member; \ exp_self(unary)->exp_type = ae_exp_primary; \ exp_self(unary)->d.prim.prim_type = exptype; \ @@ -413,7 +413,7 @@ static inline int is_now(const Env env, const Exp exp) { static OP_CHECK(opck_now) { const Exp_Binary* bin = (Exp_Binary*)data; if(!is_now(env, bin->rhs)) - CHECK_NN(opck_const_rhs(env, data)) + CHECK_NN(opck_const_rhs(env, data)); exp_setvar(bin->rhs, 1); return bin->rhs->type; } diff --git a/src/lib/ptr.c b/src/lib/ptr.c index 049dc80e..86414867 100644 --- a/src/lib/ptr.c +++ b/src/lib/ptr.c @@ -29,8 +29,8 @@ ANN static inline Type ptr_base(const Env env, const Type t) { static OP_CHECK(opck_ptr_assign) { const Exp_Binary* bin = (Exp_Binary*)data; - CHECK_BN(ptr_access(env, bin->lhs)) - CHECK_BN(ptr_access(env, bin->rhs)) + CHECK_BN(ptr_access(env, bin->lhs)); + CHECK_BN(ptr_access(env, bin->rhs)); exp_setvar(bin->lhs, 1); exp_setvar(bin->rhs, 1); Type t = bin->lhs->type; @@ -63,9 +63,9 @@ static OP_CHECK(opck_ptr_cast) { const Exp_Cast* cast = (Exp_Cast*)data; if(!cast->td->types || !cast->td->types->td) ERR_N(exp_self(cast)->pos, "'Ptr' needs types to cast"); - DECL_ON(const Type, t, = known_type(env, cast->td)) + DECL_ON(const Type, t, = known_type(env, cast->td)); if(t->info->cdef && !tflag(t, tflag_check)) - CHECK_BN(ensure_traverse(env, t)) + CHECK_BN(ensure_traverse(env, t)); const Type to = known_type(env, cast->td->types->td); exp_setvar(cast->exp, 1); if(isa(cast->exp->type, to) > 0) diff --git a/src/lib/ref.c b/src/lib/ref.c index dd33309e..eabcb74d 100644 --- a/src/lib/ref.c +++ b/src/lib/ref.c @@ -27,7 +27,7 @@ static m_bool ref_access(const Env env, const Exp e) { static OP_CHECK(opck_implicit_similar) { const struct Implicit *imp = (struct Implicit*)data; - CHECK_BN(ref_access(env, imp->e)) + CHECK_BN(ref_access(env, imp->e)); exp_setvar(imp->e, 1); return imp->t; } diff --git a/src/lib/tmpl_info.c b/src/lib/tmpl_info.c index 83ca3bf7..9a805fe4 100644 --- a/src/lib/tmpl_info.c +++ b/src/lib/tmpl_info.c @@ -81,7 +81,7 @@ ANN Type tmpl_exists(const Env env, struct tmpl_info *const info) { if(template_match(info->list, info->td->types) < 0) // invalid template ERR_N(info->td->pos, _("invalid template types number")); if(!info->name) { - DECL_ON(const Symbol, name, = info->name = template_id(env, info)) + DECL_ON(const Symbol, name, = info->name = template_id(env, info)); return _tmpl_exists(env, name); } return _tmpl_exists(env, info->name); diff --git a/src/lib/union.c b/src/lib/union.c index b3dc30f1..a826bbc0 100644 --- a/src/lib/union.c +++ b/src/lib/union.c @@ -19,7 +19,7 @@ static GACK(gack_none) { static OP_CHECK(opck_none) { Exp_Binary *bin = (Exp_Binary*)data; - CHECK_NN(opck_rassign(env, data)) + CHECK_NN(opck_rassign(env, data)); exp_setvar(bin->rhs, 1); return bin->rhs->type; } @@ -94,7 +94,7 @@ static OP_CHECK(opck_union_is) { free_exp(env->gwion->mp, exp_func); free_exp(env->gwion->mp, exp_args); e->d.exp_binary.op = insert_symbol(env->gwion->st, "=="); - CHECK_ON(check_exp(env, e)) + CHECK_ON(check_exp(env, e)); return e->type; } } @@ -123,7 +123,7 @@ static OP_CHECK(opck_union_ctor) { name->d.prim.prim_type = ae_prim_num; name->d.prim.d.num = i; name->type = env->gwion->type[et_int]; - DECL_ON(const Type, t, = check_exp(env, val)) + DECL_ON(const Type, t, = check_exp(env, val)); if(isa(t, v->type) < 0) { ERR_N(val->pos, "Invalid type '%s' for '%s', should be '%s'", t->name, v->name, v->type->name); diff --git a/src/parse/check.c b/src/parse/check.c index 9a21d52f..f141fe98 100644 --- a/src/parse/check.c +++ b/src/parse/check.c @@ -735,7 +735,7 @@ ANN m_bool func_check(const Env env, Exp_Call *const exp) { const Exp e = exp_self(exp); struct Op_Import opi = { .op=insert_symbol("@func_check"), .rhs=t, .pos=e->pos, .data=(uintptr_t)e }; - CHECK_NB(op_check(env, &opi)) // doesn't really return NULL + CHECK_NB(op_check(env, &opi)); // doesn't really return NULL if(e->exp_type != ae_exp_call) return 0; return e->type != env->gwion->type[et_error] ?