From adafebbaf4727481cfacf54684d153dba39aed39 Mon Sep 17 00:00:00 2001 From: fennecdjay Date: Mon, 12 Feb 2024 18:25:45 +0100 Subject: [PATCH] :fire: progress --- include/env/env.h | 6 +- include/operator.h | 4 +- include/parse.h | 17 +- include/partial.h | 2 +- include/template.h | 2 +- include/tmp_resolve.h | 1 - include/traverse.h | 32 +-- src/emit/emit.c | 8 +- src/env/type.c | 2 +- src/import/import_checker.c | 2 +- src/import/import_enum.c | 4 +- src/import/import_fdef.c | 6 +- src/import/import_item.c | 2 +- src/import/import_tdef.c | 6 +- src/import/import_udef.c | 2 +- src/lib/array.c | 10 +- src/lib/closure.c | 18 +- src/lib/dict.c | 10 +- src/lib/object_op.c | 4 +- src/lib/opfunc.c | 6 +- src/lib/sift.c | 6 +- src/lib/union.c | 6 +- src/lib/xork.c | 4 +- src/parse/check.c | 476 ++++++++++++++++++---------------- src/parse/check_traits.c | 2 +- src/parse/compat_func.c | 12 +- src/parse/did_you_mean.c | 2 +- src/parse/func_resolve_tmpl.c | 17 +- src/parse/operator.c | 24 +- src/parse/partial.c | 4 +- src/parse/scan0.c | 2 - src/parse/scan2.c | 4 +- src/parse/template.c | 27 +- src/parse/traverse.c | 87 ++++--- src/parse/type_decl.c | 6 +- src/pass.c | 2 +- 36 files changed, 429 insertions(+), 396 deletions(-) diff --git a/include/env/env.h b/include/env/env.h index d7e245c5..c10f9e61 100644 --- a/include/env/env.h +++ b/include/env/env.h @@ -50,12 +50,12 @@ ANN static inline m_uint env_push_global(const Env env) { ANN void env_pop(const Env, const m_uint); ANN Type scan_type(const Env, const Type, Type_Decl *); ANN Value mk_class(const Env env, const Type base, const loc_t); -ANN m_bool compat_func(const __restrict__ Func_Def, +ANN bool compat_func(const __restrict__ Func_Def, const __restrict__ Func_Def); ANN Type known_type(const Env env, Type_Decl *); ANN Type prim_ref(const Env env, const Type t, const Type_Decl *td); -ANN bool env_access(const Env env, const ae_flag flag, const loc_t); -ANN bool env_storage(const Env env, ae_flag flag, const loc_t); +ANN bool env_access(const Env env, const ae_flag flag, const loc_t); +ANN bool env_storage(const Env env, ae_flag flag, const loc_t); ANN void env_add_type(const Env, const Type, const loc_t); ANN Type find_type(const Env, Type_Decl *); ANN m_bool traverse_func_template(const Env, const Func_Def); diff --git a/include/operator.h b/include/operator.h index 648d3c74..916e343c 100644 --- a/include/operator.h +++ b/include/operator.h @@ -81,7 +81,7 @@ ANN bool add_op(const Gwion gwion, const struct Op_Import *); ANN void* op_get(const Env env, struct Op_Import *opi); ANN Type op_check(const Env, struct Op_Import *); ANN m_bool op_emit(const Emitter, const struct Op_Import *); -ANN m_bool operator_set_func(const struct Op_Import *); +ANN bool operator_set_func(const struct Op_Import *); ANN void free_op_map(Map map, struct Gwion_ *gwion); ANN void free_op_tmpl(Vector v, struct Gwion_ *gwion); @@ -97,5 +97,5 @@ ANN static inline void set_decl_ref(Exp* e) { } ANN void func_operator(const Func_Def fdef, struct Op_Import *opi); -ANN m_bool add_op_func_check(const Env env, const Type t, const struct Op_Func *opfunc, const m_uint idx); +ANN bool add_op_func_check(const Env env, const Type t, const struct Op_Func *opfunc, const m_uint idx); #endif diff --git a/include/parse.h b/include/parse.h index a91f97cd..0d415056 100644 --- a/include/parse.h +++ b/include/parse.h @@ -95,8 +95,8 @@ RET_NSPC_B(exp) \ } -ANN m_bool check_stmt(const Env env, Stmt* stmt); -ANN m_bool check_stmt_list(const Env env, const Stmt_List); +//ANN m_bool check_stmt(const Env env, Stmt* stmt); +ANN bool check_stmt_list(const Env env, const Stmt_List); typedef m_bool (*_exp_func)(const void *, const void *); ANN m_bool scanx_body(const Env env, const Class_Def cdef, const _exp_func f, @@ -136,6 +136,8 @@ static inline m_bool prefix##_union_def_b(const Env env, const Union_Def udef) { xxx_cdef_b(scan0); xxx_cdef_b(scan1); xxx_cdef_b(scan2); +xxx_cdef_b(check); +xxx_cdef_b(traverse); #define xxx_cdef(prefix) \ static inline m_bool prefix##_cdef(const Env env, const Type t) { \ @@ -143,18 +145,15 @@ xxx_cdef_b(scan2); (_exp_func)prefix##_union_def); \ } -xxx_cdef(check); -xxx_cdef(traverse); - ANN m_bool scanx_fdef(const Env, void *, const Func_Def, const _exp_func); ANN bool scanx_fdef_b(const Env, void *, const Func_Def, const _exp_func_b); -ANN m_bool check_subscripts(const Env, const Array_Sub, const m_bool is_decl); -ANN m_bool check_implicit(const Env env, Exp* e, const Type t); -ANN m_bool ensure_traverse(const Env env, const Type t); -ANN m_bool check_traverse_fdef(const Env env, const Func_Def fdef); +ANN bool check_subscripts(const Env, const Array_Sub, const bool is_decl); +ANN bool check_implicit(const Env env, Exp* e, const Type t); +ANN bool ensure_traverse(const Env env, const Type t); +ANN bool check_traverse_fdef(const Env env, const Func_Def fdef); ANN static inline void env_weight(const Env env, const uint16_t weight) { if (env->func) diff --git a/include/partial.h b/include/partial.h index fed277cf..0590a2a5 100644 --- a/include/partial.h +++ b/include/partial.h @@ -9,7 +9,7 @@ ANN static inline bool func_match_inner(const Env env, Exp* e, const bool specific) { if (specific ? e->type == t : isa(e->type, t) > 0) // match return true; - return !implicit ? false : check_implicit(env, e, t) > 0; + return !implicit ? false : check_implicit(env, e, t); } ANN static inline bool is_typed_hole(const Env env, Exp* exp) { diff --git a/include/template.h b/include/template.h index d15e4600..b4e4dc74 100644 --- a/include/template.h +++ b/include/template.h @@ -27,5 +27,5 @@ ANN static inline Tmpl* get_tmpl(const Type t) { return (a); \ } -ANN m_bool const_generic_typecheck(const Env env, const Specialized *spec, const TmplArg *targ); +ANN bool const_generic_typecheck(const Env env, const Specialized *spec, const TmplArg *targ); #endif diff --git a/include/tmp_resolve.h b/include/tmp_resolve.h index f88e75b2..fe9729be 100644 --- a/include/tmp_resolve.h +++ b/include/tmp_resolve.h @@ -3,5 +3,4 @@ ANN Func find_template_match(const Env env, const Value value, Exp_Call *const exp); ANN Func find_func_match(const Env env, const Func up, Exp_Call *const exp); -ANN2(1,2) m_bool check_tmpl(const Env env, const TmplArg_List tl, const Specialized_List sl, const loc_t loc, const bool is_spread); #endif diff --git a/include/traverse.h b/include/traverse.h index f9665d69..f1bb1164 100644 --- a/include/traverse.h +++ b/include/traverse.h @@ -1,18 +1,18 @@ #ifndef __TRAVERSE #define __TRAVERSE -ANN m_bool traverse_ast(const Env, Ast *const); -ANN m_bool traverse_class_def(const Env, const Class_Def); -ANN m_bool traverse_func_def(const Env, const Func_Def); -ANN m_bool traverse_union_def(const Env, const Union_Def); -ANN m_bool traverse_enum_def(const Env, const Enum_Def); -ANN m_bool traverse_fptr_def(const Env, const Fptr_Def); -ANN m_bool traverse_type_def(const Env env, const Type_Def); -ANN m_bool traverse_exp(const Env, Exp*); +ANN bool traverse_ast(const Env, Ast *const); +ANN bool traverse_class_def(const Env, const Class_Def); +ANN bool traverse_func_def(const Env, const Func_Def); +ANN bool traverse_union_def(const Env, const Union_Def); +ANN bool traverse_enum_def(const Env, const Enum_Def); +ANN bool traverse_fptr_def(const Env, const Fptr_Def); +ANN bool traverse_type_def(const Env env, const Type_Def); +ANN bool traverse_exp(const Env, Exp*); ANN bool scan0_ast(const Env, Ast*); ANN bool scan1_ast(const Env, Ast*); ANN bool scan2_ast(const Env, Ast*); -ANN m_bool check_ast(const Env, Ast*); +ANN bool check_ast(const Env, Ast*); ANN bool scan1_exp(const Env, Exp*); ANN bool scan2_exp(const Env, Exp*); @@ -21,32 +21,32 @@ ANN Type check_exp(const Env, Exp*); ANN bool scan0_func_def(const Env, const Func_Def); ANN bool scan1_func_def(const Env, const Func_Def); ANN bool scan2_func_def(const Env, const Func_Def); -ANN m_bool check_func_def(const Env, const Func_Def); +ANN bool check_func_def(const Env, const Func_Def); ANN bool scan0_fptr_def(const Env, const Fptr_Def); ANN bool scan1_fptr_def(const Env, const Fptr_Def); ANN bool scan2_fptr_def(const Env, const Fptr_Def); -ANN m_bool check_fptr_def(const Env, const Fptr_Def); +ANN bool check_fptr_def(const Env, const Fptr_Def); ANN bool scan0_union_def(const Env, const Union_Def); ANN bool scan1_union_def(const Env, const Union_Def); ANN bool scan2_union_def(const Env, const Union_Def); -ANN m_bool check_union_def(const Env, const Union_Def); +ANN bool check_union_def(const Env, const Union_Def); ANN bool scan0_enum_def(const Env, const Enum_Def); ANN bool scan1_enum_def(const Env, const Enum_Def); -// ANN m_bool scan2_enum_def(const Env, const Enum_Def); -ANN m_bool check_enum_def(const Env, const Enum_Def); +// ANN bool scan2_enum_def(const Env, const Enum_Def); +ANN bool check_enum_def(const Env, const Enum_Def); ANN bool scan0_type_def(const Env, const Type_Def); ANN bool scan1_type_def(const Env, const Type_Def); ANN bool scan2_type_def(const Env, const Type_Def); -ANN m_bool check_type_def(const Env, const Type_Def); +ANN bool check_type_def(const Env, const Type_Def); ANN bool scan0_class_def(const Env, const Class_Def); ANN bool scan1_class_def(const Env, const Class_Def); ANN bool scan2_class_def(const Env, const Class_Def); -ANN m_bool check_class_def(const Env, const Class_Def); +ANN bool check_class_def(const Env, const Class_Def); ANN Type check_exp_call1(const Env env, Exp_Call *const exp); ANN bool scan0_prim_def(const Env env, const Prim_Def pdef); diff --git a/src/emit/emit.c b/src/emit/emit.c index 45b6c0da..4c2d0222 100644 --- a/src/emit/emit.c +++ b/src/emit/emit.c @@ -636,7 +636,7 @@ ANN static m_bool emit_prim_dict(const Emitter emit, Exp* *data) { e->next = NULL; Exp func = { .exp_type = ae_exp_primary, .d = { .prim = { .prim_type = ae_prim_id, .d = { .var = insert_symbol("hash") }} }}; Exp call = { .exp_type = ae_exp_call, .d = { .exp_call = { .func = &func, .args = e}}}; - CHECK_BB(traverse_exp(emit->env, &call)); + CHECK_b(traverse_exp(emit->env, &call)); e->next = next; m_uint count = 0; do { @@ -1420,7 +1420,7 @@ ANN static m_bool emit_exp_post(const Emitter emit, const Exp_Postfix *post) { ANN static inline m_bool traverse_emit_func_def(const Emitter emit, const Func_Def fdef) { - if (!fdef->base->ret_type) CHECK_BB(traverse_func_def(emit->env, fdef)); + if (!fdef->base->ret_type) CHECK_b(traverse_func_def(emit->env, fdef)); return emit_func_def(emit, fdef); } @@ -1435,11 +1435,11 @@ ANN m_bool traverse_dot_tmpl(const Emitter emit, const Func_Def fdef, const Valu .flag = tflag_emit}; CHECK_BB(envset_pushv(&es, v)); (void)emit_push(emit, v->from->owner_class, v->from->owner); - const m_bool ret = traverse_emit_func_def(emit, fdef); + const bool ret = traverse_emit_func_def(emit, fdef); emit_pop(emit, scope); envset_pop(&es, v->from->owner_class); emit->env->scope->shadowing = shadowing; - return ret; + return ret ? GW_OK : GW_ERROR; } static INSTR(fptr_call) { diff --git a/src/env/type.c b/src/env/type.c index 9df5af53..889c180a 100644 --- a/src/env/type.c +++ b/src/env/type.c @@ -11,7 +11,7 @@ #include "operator.h" #include "import.h" -ANN static inline m_bool freeable(const Type a) { +ANN static inline bool freeable(const Type a) { return tflag(a, tflag_tmpl) || GET_FLAG(a, global); } diff --git a/src/import/import_checker.c b/src/import/import_checker.c index fa412af0..7846300d 100644 --- a/src/import/import_checker.c +++ b/src/import/import_checker.c @@ -317,7 +317,7 @@ ANN static m_bool td_info_run(const Env env, struct td_info *info) { td_fullname(env, &info->fmt->ls->text, t); else { Exp* exp = td2exp(gwion->mp, targ->d.td); - if(traverse_exp(env, exp) > 0) { + if(traverse_exp(env, exp)) { if(is_class(gwion, exp->type)) { td_fullname(env, &info->fmt->ls->text, exp->type); free_exp(gwion->mp, exp); diff --git a/src/import/import_enum.c b/src/import/import_enum.c index d05b4687..c4dcf79c 100644 --- a/src/import/import_enum.c +++ b/src/import/import_enum.c @@ -47,9 +47,9 @@ ANN Type gwi_enum_end(const Gwi gwi) { new_enum_def(gwion->mp, gwi->ck->tmpl, gwi->ck->xid, gwi->loc); // clean the vector gwi->ck->tmpl = NULL; - const m_bool ret = traverse_enum_def(gwion->env, edef); + const bool ret = traverse_enum_def(gwion->env, edef); if (gwi->gwion->data->cdoc) gwfmt_enum_def(gwi->gwfmt, edef); - const Type t = ret > 0 ? edef->type : NULL; + const Type t = ret ? edef->type : NULL; free_enum_def(gwion->mp, edef); ck_end(gwi); return t; diff --git a/src/import/import_fdef.c b/src/import/import_fdef.c index 2cdfcddd..21a7d6c1 100644 --- a/src/import/import_fdef.c +++ b/src/import/import_fdef.c @@ -77,7 +77,7 @@ ANN m_int gwi_func_valid(const Gwi gwi, ImportCK *ck) { fdef->d.dl_func_ptr = ck->addr; return GW_OK; } - if (traverse_func_def(gwi->gwion->env, fdef) < 0) + if (!traverse_func_def(gwi->gwion->env, fdef)) return error_fdef(gwi, fdef); builtin_func(gwi->gwion, fdef->base->func, ck->addr); return GW_OK; @@ -136,10 +136,10 @@ ANN Type gwi_fptr_end(const Gwi gwi, const ae_flag flag) { ck_end(gwi); return (Type)GW_OK; } - const m_bool ret = traverse_fptr_def(gwi->gwion->env, fptr); + const bool ret = traverse_fptr_def(gwi->gwion->env, fptr); // if (fptr->base->func) // is it needed ? // set_vflag(fptr->base->func->value_ref, vflag_builtin); - const Type t = ret > 0 ? fptr->cdef->base.type : NULL; + const Type t = ret ? fptr->cdef->base.type : NULL; free_fptr_def(gwi->gwion->mp, fptr); ck_end(gwi); return t; diff --git a/src/import/import_item.c b/src/import/import_item.c index 4dc49f17..2f1f73ca 100644 --- a/src/import/import_item.c +++ b/src/import/import_item.c @@ -41,7 +41,7 @@ m_int gwi_item_end(const Gwi gwi, const ae_flag flag, union value_data addr) { } if (env->class_def && tflag(env->class_def, tflag_tmpl)) return gwi_item_tmpl(gwi); - CHECK_BB(traverse_exp(env, gwi->ck->exp)); + CHECK_b(traverse_exp(env, gwi->ck->exp)); const Value value = gwi->ck->exp->d.exp_decl.var.vd.value; value->d = addr; set_vflag(value, vflag_builtin); diff --git a/src/import/import_tdef.c b/src/import/import_tdef.c index 336d7929..005fd68a 100644 --- a/src/import/import_tdef.c +++ b/src/import/import_tdef.c @@ -28,18 +28,18 @@ ANN Type gwi_typedef_end(const Gwi gwi, const ae_flag flag) { if (gwi->ck->tmpl) tdef->tmpl = gwi_tmpl(gwi); gwi->ck->td = NULL; gwi->ck->tmpl = NULL; - const m_bool ret = traverse_type_def(gwi->gwion->env, tdef); + const bool ret = traverse_type_def(gwi->gwion->env, tdef); if (gwi->gwion->data->cdoc) { gwfmt_indent(gwi->gwfmt); gwfmt_type_def(gwi->gwfmt, tdef); } const Type t = tdef->type; - if (ret > 0) + if (ret) set_tflag(t, tflag_scan0 | tflag_scan1 | tflag_scan2 | tflag_check | tflag_emit); free_type_def(gwi->gwion->mp, tdef); ck_end(gwi); - return ret > 0 ? t : NULL; + return ret ? t : NULL; } ANN void ck_clean_tdef(MemPool mp, ImportCK *ck) { diff --git a/src/import/import_udef.c b/src/import/import_udef.c index d9fd81c7..28f7bcd7 100644 --- a/src/import/import_udef.c +++ b/src/import/import_udef.c @@ -48,7 +48,7 @@ ANN m_int gwi_union_add(const Gwi gwi, const restrict m_str type, ANN static Type union_type(const Gwi gwi, const Union_Def udef) { CHECK_O(scan0_union_def(gwi->gwion->env, udef)); - CHECK_BO(traverse_union_def(gwi->gwion->env, udef)); + CHECK_O(traverse_union_def(gwi->gwion->env, udef)); // if(!udef->tmpl) // emit_union_offset(udef->l, udef->o); // if(gwi->gwion->env->class_def && !GET_FLAG(udef, static)) diff --git a/src/lib/array.c b/src/lib/array.c index 1a7d3b09..73efbf16 100644 --- a/src/lib/array.c +++ b/src/lib/array.c @@ -269,7 +269,7 @@ static OP_CHECK(opck_array_cast) { parent = parent->info->parent; } Exp e = { .type = l, .loc = cast->exp->loc }; - CHECK_BN(check_implicit(env, &e, r)); + CHECK_ON(check_implicit(env, &e, r)); return t; } @@ -378,7 +378,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_ON(check_implicit(env, e, t_int)); while ((e = e->next)); const Type t = get_array_type(array->type); if (t->array_depth >= array->depth) @@ -833,11 +833,11 @@ static OP_CHECK(opck_array_scan) { SET_FLAG(t, abstract); else UNSET_FLAG(t, abstract); - const m_bool ret = traverse_cdef(env, t); + const bool ret = traverse_cdef(env, t); UNSET_FLAG(t, abstract); env_pop(env, scope); env->context = ctx; - if (ret == GW_ERROR) return NULL; + if (!ret) return NULL; set_tflag(t, tflag_emit); t->array_depth = base->array_depth + 1; t->info->base_type = array_base(base); @@ -901,7 +901,7 @@ ANN static inline Type foreach_type(const Env env, Exp* exp) { static OP_CHECK(opck_array_each_val) { Exp* exp = (Exp*) data; DECL_ON(const Type, base, = foreach_type(env, exp)); - CHECK_BN(ensure_traverse(env, base)); + CHECK_ON(ensure_traverse(env, base)); return ref_type(env->gwion, base, exp->loc); } diff --git a/src/lib/closure.c b/src/lib/closure.c index 08c99c77..b3815599 100644 --- a/src/lib/closure.c +++ b/src/lib/closure.c @@ -43,7 +43,7 @@ ANN static Exp* uncurry(const Env env, const Exp_Binary *bin) { } args = args->next; } - if(traverse_exp(env, base) > 0) { + if(traverse_exp(env, base)) { free_exp(env->gwion->mp, bin->lhs); return base; } @@ -331,7 +331,7 @@ ANN static m_bool _check_lambda(const Env env, Exp_Lambda *l, const bool shadowing = env->scope->shadowing; env->scope->shadowing = true; if(env->class_def)SET_FLAG(l->def->base, static); - const m_bool ret = traverse_func_def(env, l->def); + const bool ret = traverse_func_def(env, l->def); env->scope->shadowing = shadowing; env->scope->depth = scope; @@ -348,7 +348,7 @@ ANN static m_bool _check_lambda(const Env env, Exp_Lambda *l, owner = owner->info->value->from->owner_class; } envset_pop(&es, owner); - if(ret < 0) { + if(!ret) { if(args) { for(uint32_t i = 0; i < bases->len; i++) { Arg *arg = mp_vector_at(args, Arg, i); @@ -381,7 +381,7 @@ ANN static m_bool fptr_do(const Env env, struct FptrInfo *info) { ANN static Type partial2auto(const Env env, const Exp_Binary *bin) { const Func_Def fdef = bin->lhs->d.exp_lambda.def; unset_fbflag(fdef->base, fbflag_lambda); - CHECK_BN(traverse_func_def(env, fdef)); + CHECK_ON(traverse_func_def(env, fdef)); set_fbflag(fdef->base, fbflag_lambda); const Type actual = fdef->base->func->value_ref->type; set_fbflag(fdef->base, fbflag_lambda); @@ -414,13 +414,13 @@ static OP_CHECK(opck_auto_fptr) { sprintf(name, "generated@%s@%u:%u", env->curr->name, bin->rhs->loc.first.line, bin->rhs->loc.first.column); fptr_def->base->tag.sym = insert_symbol(name); - const m_bool ret = traverse_fptr_def(env, fptr_def); + const bool ret = traverse_fptr_def(env, fptr_def); const Type t = fptr_def->cdef->base.type; free_fptr_def(env->gwion->mp, fptr_def); Var_Decl vd = bin->rhs->d.exp_decl.var.vd; vd.value->type = bin->rhs->type = bin->rhs->d.exp_decl.type = t; - return ret > 0 ? t : env->gwion->type[et_error]; + return ret ? t : env->gwion->type[et_error]; } static OP_CHECK(opck_fptr_assign) { @@ -689,8 +689,8 @@ static OP_CHECK(opck_closure_scan) { .flag = tflag_scan0}; const Type owner = ts->t; CHECK_BO(envset_pushv(&es, owner->info->value)); - const m_bool ret = traverse_fptr_def(env, fdef); - const Type t = ret > 0 ? fdef->cdef->base.type : NULL; + const bool ret = traverse_fptr_def(env, fdef); + const Type t = ret ? fdef->cdef->base.type : NULL; envset_pop(&es, owner->info->value->from->owner_class); free_fptr_def(env->gwion->mp, fdef); // clean? if(t) set_tflag(t, tflag_emit); @@ -704,7 +704,7 @@ static CTOR(fptr_ctor) { ANN bool tmpl_fptr(const Env env, const Fptr_Def fptr, const Func_Def fdef) { fptr->cdef->base.type->nspc->offset += SZ_INT * 3; env_push_type(env, fptr->cdef->base.type); - CHECK_B(traverse_func_def(env, fdef)); + CHECK_b(traverse_func_def(env, fdef)); builtin_func(env->gwion, fdef->base->func, fptr_ctor); set_tflag(fdef->base->func->value_ref->type, tflag_ftmpl); env_pop(env, 0); diff --git a/src/lib/dict.c b/src/lib/dict.c index 40dc7501..9cd68b0a 100644 --- a/src/lib/dict.c +++ b/src/lib/dict.c @@ -348,7 +348,7 @@ struct Op_Import opi = { }; -CHECK_BB(traverse_exp(env, &call)); +CHECK_B(traverse_exp(env, &call)); if(info->is_var) { const Instr instr = emit_add_instr(emit, hmap_grow); @@ -424,7 +424,7 @@ static OP_EMIT(opem_dict_remove) { .data = (m_uint)&_bin }; - CHECK_BB(traverse_exp(env, &call)); + CHECK_B(traverse_exp(env, &call)); CHECK_BB(emit_dict_iter(emit, hinfo, &opi, &call, bin->lhs)); const Instr pushval = emit_add_instr(emit, hmap_remove); pushval->m_val2 = hinfo->key->size; @@ -479,7 +479,7 @@ struct Op_Import opi = { }; - CHECK_BN(traverse_exp(env, &call)); + CHECK_ON(traverse_exp(env, &call)); CHECK_ON(op_check(env, &opi)); if(!array->exp->next) return hinfo->val; @@ -576,7 +576,7 @@ static OP_CHECK(opck_dict_scan) { CHECK_ON(scan0_class_def(env, cdef)); const Type t = cdef->base.type; t->nspc->class_data_size = sizeof(struct HMapInfo); - const m_bool ret = traverse_cdef(env, t); + const bool ret = traverse_cdef(env, t); set_tflag(t, tflag_cdef); if(is_global) { env_pop(env, scope); @@ -607,7 +607,7 @@ static OP_CHECK(opck_dict_scan) { CHECK_ON(add_op(env->gwion, &opi)); } - return ret > 0 ? t : NULL; + return ret ? t : NULL; } GWION_IMPORT(dict) { diff --git a/src/lib/object_op.c b/src/lib/object_op.c index 81e38d5a..c1aacea8 100644 --- a/src/lib/object_op.c +++ b/src/lib/object_op.c @@ -170,7 +170,7 @@ ANN static inline void emit_struct_data(const Emitter emit, const Value v, if (!emit_addr) emit_regmove(emit, v->type->size - SZ_INT); } -ANN m_bool not_from_owner_class(const Env env, const Type t, const Value v, +ANN bool not_from_owner_class(const Env env, const Type t, const Value v, const loc_t loc); ANN static inline Value get_value(const Env env, const Exp_Dot *member, @@ -220,7 +220,7 @@ OP_CHECK(opck_object_dot) { if (member->base->type->nspc) did_you_mean_type(the_base, str); return env->gwion->type[et_error]; } - CHECK_BN(not_from_owner_class(env, the_base, value, self->loc)); + CHECK_ON(not_from_owner_class(env, the_base, value, self->loc)); CHECK_BN(member_access(env, self, value)); if ((base_static && vflag(value, vflag_member)) || (value->from->owner_class != env->class_def && isa(value->from->owner_class, env->class_def) > 0)) diff --git a/src/lib/opfunc.c b/src/lib/opfunc.c index 527e5d51..13df8d00 100644 --- a/src/lib/opfunc.c +++ b/src/lib/opfunc.c @@ -126,14 +126,14 @@ OP_CHECK(opck_new) { if(GET_FLAG(base, abstract)) CHECK_BN(check_array_instance(env, unary->ctor.td, unary->ctor.exp)); } - CHECK_BN(ensure_traverse(env, t)); + CHECK_ON(ensure_traverse(env, t)); if (type_ref(t)) ERR_N(unary->ctor.td->tag.loc, _("can't use 'new' on ref type '%s'\n"), t->name); if (tflag(t, tflag_infer)) ERR_N(unary->ctor.td->tag.loc, _("can't use 'new' on '%s'\n"), t->name); if (array) { - CHECK_BN(check_subscripts(env, array, 1)); + CHECK_ON(check_subscripts(env, array, 1)); } if(unary->ctor.exp) { Exp* self = exp_self(unary); @@ -145,7 +145,7 @@ OP_CHECK(opck_new) { self->d.exp_call.args = args; self->d.exp_call.tmpl = NULL; self->exp_type = ae_exp_call; - CHECK_BN(traverse_exp(env, self)); + CHECK_ON(traverse_exp(env, self)); return self->type; } if (GET_FLAG(t, abstract) && diff --git a/src/lib/sift.c b/src/lib/sift.c index 5d7a7c1f..f59cb2bd 100644 --- a/src/lib/sift.c +++ b/src/lib/sift.c @@ -17,7 +17,7 @@ static OP_CHECK(opck_sift) { Stmt* fst = mp_vector_at(stmt->d.stmt_flow.body->d.stmt_code.stmt_list, Stmt, 0); const Symbol chuck = insert_symbol(env->gwion->st, "=>"); Exp* next = new_exp_binary(env->gwion->mp, fst->d.stmt_exp.val, chuck, bin->rhs, bin->rhs->loc); - CHECK_BN(traverse_exp(env, next)); // how do we free it? + CHECK_ON(traverse_exp(env, next)); // how do we free it? fst->d.stmt_exp.val = next; Exp* exp = exp_self(bin); exp->exp_type = lhs->exp_type; @@ -41,13 +41,13 @@ static OP_CHECK(opck_ctrl) { Exp* call = new_exp_call(mp, dot, NULL, func->loc); func->d.exp_binary.lhs = call; func->d.exp_binary.op = chuck; - CHECK_BN(traverse_exp(env, func)); + CHECK_ON(traverse_exp(env, func)); Stmt one = MK_STMT_EXP(func->loc, func); Exp* samp = new_prim_id(mp, insert_symbol(env->gwion->st, "samp"), func->loc); Exp* _now = new_prim_id(mp, insert_symbol(env->gwion->st, "now"), func->loc); Exp* time = new_exp_binary(mp, samp, chuck, _now, func->loc); - CHECK_BN(traverse_exp(env, time)); + CHECK_ON(traverse_exp(env, time)); Stmt two = MK_STMT_EXP(func->loc, time); free_exp(mp, bin->lhs); free_exp(mp, bin->rhs); diff --git a/src/lib/union.c b/src/lib/union.c index 63829678..960879d8 100644 --- a/src/lib/union.c +++ b/src/lib/union.c @@ -141,7 +141,7 @@ static OP_CHECK(opck_union_new) { if (val->next) ERR_N(call->func->loc, "too many arguments for union constructor"); DECL_ON(const Type, t, = check_exp(env, val)); - if (check_implicit(env, val, v->type) < 0) { // add implicit + if (!check_implicit(env, val, v->type)) { ERR_N(val->loc, "Invalid type '%s' for '%s', should be '%s'", t->name, v->name, v->type->name); } @@ -192,10 +192,10 @@ ANN GWION_IMPORT(union) { GWI_BB(gwi_class_end(gwi)) const struct Op_Func opfunc0 = {.ck = opck_union_is}; - GWI_BB(add_op_func_check(gwi->gwion->env, t_union, &opfunc0, 0)); + CHECK_b(add_op_func_check(gwi->gwion->env, t_union, &opfunc0, 0)); const struct Op_Func opfunc1 = {.ck = opck_union_new}; - GWI_BB(add_op_func_check(gwi->gwion->env, t_union, &opfunc1, 1)); + CHECK_b(add_op_func_check(gwi->gwion->env, t_union, &opfunc1, 1)); GWI_BB(gwi_oper_ini(gwi, "union", (m_str)OP_ANY_TYPE, NULL)) GWI_BB(gwi_oper_emi(gwi, opem_union_dot)) diff --git a/src/lib/xork.c b/src/lib/xork.c index f337a721..037ddccd 100644 --- a/src/lib/xork.c +++ b/src/lib/xork.c @@ -67,11 +67,11 @@ static OP_CHECK(opck_spork) { struct Func_ func = { .name = "in spork", .def = &fdef, .value_ref = &value}; env->func = &func; // scope depth? - const m_bool ret = check_stmt_list(env, unary->code); + const bool ret = check_stmt_list(env, unary->code); env->func = f; free_scope(env->gwion->mp, env->curr->info->value); env->curr->info->value = upvalues.values; - CHECK_BN(ret); + CHECK_ON(ret); return env->gwion ->type[unary->op == insert_symbol("spork") ? et_shred : et_fork]; } diff --git a/src/parse/check.c b/src/parse/check.c index 1c709323..8165e586 100644 --- a/src/parse/check.c +++ b/src/parse/check.c @@ -18,8 +18,16 @@ #include "spread.h" #include "array.h" -ANN 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); +#undef ERR_B +#define ERR_B(a, b, ...) \ + { \ + env_err(env, (a), (b), ##__VA_ARGS__); \ + return false; \ + } + + +ANN bool check_stmt(const Env env, Stmt*); +ANN bool check_class_def(const Env env, const Class_Def class_def); ANN static Type check_internal(const Env env, const Symbol sym, Exp* e, const Type t) { @@ -32,36 +40,36 @@ ANN static Type check_internal(const Env env, const Symbol sym, Exp* e, return op_check(env, &opi); } -ANN m_bool check_implicit(const Env env, Exp* e, const Type t) { - if (e->type == t) return GW_OK; - if (isa(e->type, t) > 0) return GW_OK; +ANN bool check_implicit(const Env env, Exp* e, const Type t) { + if (e->type == t) return true; + if (isa(e->type, t) > 0) return true; const Symbol sym = insert_symbol("@implicit"); - return (e->cast_to = check_internal(env, sym, e, t)) ? GW_OK : GW_ERROR; + return !!(e->cast_to = check_internal(env, sym, e, t)); } -ANN m_bool check_subscripts(Env env, const Array_Sub array, - const m_bool is_decl) { - CHECK_OB(check_exp(env, array->exp)); +ANN bool check_subscripts(Env env, const Array_Sub array, + const bool is_decl) { + CHECK_B(check_exp(env, array->exp)); m_uint depth = 0; Exp* e = array->exp; do { if (is_decl) { - if(check_implicit(env, e, env->gwion->type[et_int]) < 0) + if(!check_implicit(env, e, env->gwion->type[et_int])) ERR_B(array->exp->loc, _("invalid array declaration index type.")) } } while (++depth && (e = e->next)); if (depth != array->depth) ERR_B(array->exp->loc, _("invalid array access expression.")) - return GW_OK; + return true; } -ANN static inline m_bool check_exp_decl_parent(const Env env, +ANN static inline bool check_exp_decl_parent(const Env env, const Var_Decl *var) { const Value value = find_value(env->class_def->info->parent, var->tag.sym); if (value) { env_err(env, var->tag.loc, _("Value defined in parent class")); defined_here(value); - return GW_ERROR; + return false; } return GW_OK; } @@ -96,14 +104,14 @@ ANN static void var_effects(const Env env, const Type t, const Symbol sym, const env_add_effect(env, (Symbol)vector_at(v, i), loc); } -ANN static m_bool check_var(const Env env, const Var_Decl *var) { +ANN static bool check_var(const Env env, const Var_Decl *var) { if (env->class_def && !env->scope->depth && env->class_def->info->parent) - CHECK_BB(check_exp_decl_parent(env, var)); + CHECK_B(check_exp_decl_parent(env, var)); var_effects(env, var->value->type, insert_symbol("@ctor"), var->tag.loc); return GW_OK; } -ANN static m_bool check_var_td(const Env env, const Var_Decl *var, +ANN static bool check_var_td(const Env env, const Var_Decl *var, Type_Decl *const td) { const Value v = var->value; if (env->class_def) { @@ -116,21 +124,21 @@ ANN static m_bool check_var_td(const Env env, const Var_Decl *var, return GW_OK; } -ANN static m_bool check_decl(const Env env, const Exp_Decl *decl) { +ANN static bool check_decl(const Env env, const Exp_Decl *decl) { const Var_Decl *vd = &decl->var.vd; - CHECK_BB(check_var(env, vd)); - CHECK_BB(check_var_td(env, vd, decl->var.td)); + CHECK_B(check_var(env, vd)); + CHECK_B(check_var_td(env, vd, decl->var.td)); if (decl->var.td->array && decl->var.td->array->exp) { - CHECK_BB(check_subscripts(env, decl->var.td->array, true)); + CHECK_B(check_subscripts(env, decl->var.td->array, true)); if (GET_FLAG(array_base(decl->type), abstract)) - CHECK_BB(check_array_instance(env, decl->var.td, decl->args)); + CHECK_B(check_array_instance(env, decl->var.td, decl->args)); } valid_value(env, vd->tag.sym, vd->value); // set_vflag(var->value, vflag_used)); return GW_OK; } -ANN /*static inline*/ m_bool ensure_check(const Env env, const Type t) { +ANN /*static inline*/ bool ensure_check(const Env env, const Type t) { if (tflag(t, tflag_check) || !(tflag(t, tflag_cdef) || tflag(t, tflag_udef))) return GW_OK; if(!tflag(t, tflag_tmpl)) return GW_OK; @@ -142,10 +150,10 @@ ANN /*static inline*/ m_bool ensure_check(const Env env, const Type t) { return envset_run(&es, t); } -ANN m_bool ensure_traverse(const Env env, const Type t) { +ANN bool ensure_traverse(const Env env, const Type t) { if (tflag(t, tflag_check) || !(tflag(t, tflag_cdef) || tflag(t, tflag_udef))) - return GW_OK; - if(!tflag(t, tflag_tmpl)) return GW_OK; + return true; + if(!tflag(t, tflag_tmpl)) return true; struct EnvSet es = {.env = env, .data = env, .func = (_exp_func)traverse_cdef, @@ -154,7 +162,7 @@ ANN m_bool ensure_traverse(const Env env, const Type t) { return envset_run(&es, t); } -ANN static inline m_bool inferable(const Env env, const Type t, +ANN static inline bool inferable(const Env env, const Type t, const loc_t loc) { if (!tflag(t, tflag_infer)) return GW_OK; ERR_B(loc, _("can't infer type.")) @@ -171,20 +179,20 @@ ANN Type check_exp_decl(const Env env, Exp_Decl *const decl) { } if (decl->var.td->tag.sym == insert_symbol("auto")) { // should be better CHECK_O(scan1_exp(env, exp_self(decl))); - CHECK_BO(scan2_exp(env, exp_self(decl))); + CHECK_O(scan2_exp(env, exp_self(decl))); } if (!decl->type) ERR_O(decl->var.td->tag.loc, _("can't find type")); { - CHECK_BO(ensure_check(env, decl->type)); - if(inferable(env, decl->type, decl->var.td->tag.loc) < 0) { + CHECK_O(ensure_check(env, decl->type)); + if(!inferable(env, decl->type, decl->var.td->tag.loc)) { if(!tflag(decl->type, tflag_check) && decl->type->ref > 1 && env->class_def && !env->scope->depth) type_remref(decl->type, env->gwion); return NULL; } } - const m_bool global = GET_FLAG(decl->var.td, global); + const bool global = GET_FLAG(decl->var.td, global); const m_uint scope = !global ? env->scope->depth : env_push_global(env); - const m_bool ret = check_decl(env, decl); + const bool ret = check_decl(env, decl); if (global) { env_pop(env, scope); set_vflag(decl->var.vd.value, vflag_direct); @@ -193,11 +201,11 @@ ANN Type check_exp_decl(const Env env, Exp_Decl *const decl) { return ret > 0 ? decl->var.vd.value->type : NULL; } -ANN static m_bool check_collection(const Env env, Type type, Exp* e, +ANN static bool check_collection(const Env env, Type type, Exp* e, const loc_t loc) { const Type common = find_common_anc(e->type, type); if (common) return GW_OK; - if (check_implicit(env, e, type) > 0) return GW_OK; + if (check_implicit(env, e, type)) return true; char fst[20 + strlen(type->name)]; sprintf(fst, "expected `{+/}%s{0}`", type->name); @@ -207,7 +215,7 @@ ANN static m_bool check_collection(const Env env, Type type, Exp* e, char sec[16 + strlen(e->type->name)]; sprintf(sec, "got `{+/}%s{0}`", e->type->name); gwerr_secondary(sec, env->name, e->loc); - return GW_ERROR; + return false; } ANN static inline Type prim_array_match(const Env env, Exp* e) { @@ -215,7 +223,7 @@ ANN static inline Type prim_array_match(const Env env, Exp* e) { bool err = false; const loc_t loc = e->loc; do - if (check_collection(env, type, e, loc) < 0) err = true; + if (!check_collection(env, type, e, loc)) err = true; while ((e = e->next)); if (!err) return array_type(env, array_base_simple(type), type->array_depth + 1, loc); env_set_error(env, true); @@ -232,9 +240,9 @@ ANN static Type check_prim_array(const Env env, const Array_Sub *data) { return array->type = prim_array_match(env, e); } -ANN static m_bool check_range(const Env env, Range *range) { - if (range->start) CHECK_OB(check_exp(env, range->start)); - if (range->end) CHECK_OB(check_exp(env, range->end)); +ANN static bool check_range(const Env env, Range *range) { + if (range->start) CHECK_B(check_exp(env, range->start)); + if (range->end) CHECK_B(check_exp(env, range->end)); if (range->start && range->end) { if (isa(range->end->type, range->start->type) < 0) ERR_B(range->start->loc, _("range types do not match")) @@ -244,7 +252,7 @@ ANN static m_bool check_range(const Env env, Range *range) { ANN static Type check_prim_range(const Env env, Range **data) { Range *range = *data; - CHECK_BO(check_range(env, range)); + CHECK_O(check_range(env, range)); env_weight(env, 1); Exp* e = range->start ?: range->end; assert(e); @@ -266,22 +274,22 @@ ANN static Type check_prim_dict(const Env env, Exp* *data) { Exp* e = base; env_weight(env, 1); do { - if (check_collection(env, key, e, loc) < 0) err = true; + if (!check_collection(env, key, e, loc)) err = true; e = e->next; - if (check_collection(env, val, e, loc) < 0) err = true; + if (!check_collection(env, val, e, loc)) err = true; } while ((e = e->next)); if (!err) return dict_type(env->gwion, key, val, loc); env_set_error(env, true); return NULL; } -ANN m_bool not_from_owner_class(const Env env, const Type t, const Value v, +ANN bool not_from_owner_class(const Env env, const Type t, const Value v, const loc_t loc) { if (!v->from->owner_class || isa(t, v->from->owner_class) < 0) { if(!is_class(env->gwion, v->type)) ERR_B(loc, _("'%s' from owner namespace '%s' used in '%s'."), v->name, v->from->owner ? v->from->owner->name : "?", t->name) } - return GW_OK; + return true; } ANN static inline Value get_value(const Env env, const Symbol sym) { @@ -327,7 +335,7 @@ ANN static Value check_non_res_value(const Env env, const Symbol *data) { if (env->class_def) { if (value) { if(value->from->owner_class) - CHECK_BO(not_from_owner_class(env, + CHECK_O(not_from_owner_class(env, env->class_def, value, prim_pos(data))); } const Value v = value ?: find_value(env->class_def, var); @@ -361,14 +369,14 @@ ANN static Type check_dot(const Env env, const Exp_Dot *member) { return op_check(env, &opi); } -ANN static m_bool check_upvalue(const Env env, const Exp_Primary *prim, const Value v) { +ANN static bool check_upvalue(const Env env, const Exp_Primary *prim, const Value v) { if(not_upvalue(env, v)) return GW_OK; gwerr_basic(_("value not in lambda scope"), NULL, NULL, env->name, exp_self(prim)->loc, 4242); declared_here(v); gw_err("{-}hint:{0} try adding it to capture list"); env_set_error(env, true); - return GW_ERROR; + return false; } ANN static Type prim_owned(const Env env, const Symbol *data) { @@ -400,7 +408,7 @@ ANN static Type prim_id_non_res(const Env env, const Symbol *data) { if (env->func && fbflag(env->func->def->base, fbflag_lambda) && env->func->def->base->values) { const Value v = upvalues_lookup(env->func->def->base->values, sym); if(v) { - CHECK_BO(check_upvalue(env, prim_self(data), v)); + CHECK_O(check_upvalue(env, prim_self(data), v)); return v->type; } } @@ -445,7 +453,7 @@ ANN static Type prim_id_non_res(const Env env, const Symbol *data) { if (!GET_FLAG(v, const) && v->from->owner) unset_fflag(env->func, fflag_pure); if (fbflag(env->func->def->base, fbflag_lambda)) - CHECK_BO(check_upvalue(env, prim_self(data), v)); + CHECK_O(check_upvalue(env, prim_self(data), v)); } // set_vflag(v->vflag, vflag_used); return v->type; @@ -519,14 +527,14 @@ ANN Type check_array_access(const Env env, const Array_Sub array) { static ANN Type check_exp_array(const Env env, const Exp_Array *array) { CHECK_OO((array->array->type = check_exp(env, array->base))); - CHECK_BO(check_subscripts(env, array->array, 0)); + CHECK_O(check_subscripts(env, array->array, 0)); if(exp_getmeta(array->base)) exp_setmeta(exp_self(array), true); return check_array_access(env, array->array); } static ANN Type check_exp_slice(const Env env, const Exp_Slice *range) { CHECK_OO(check_exp(env, range->base)); - CHECK_BO(check_range(env, range->range)); + CHECK_O(check_range(env, range->range)); env_weight(env, 1); const Symbol sym = insert_symbol("[:]"); Exp* e = range->range->start ?: range->range->end; @@ -652,7 +660,7 @@ ANN Func find_func_match(const Env env, const Func up, Exp_Call *const call) { : NULL; } -ANN m_bool check_traverse_fdef(const Env env, const Func_Def fdef) { +ANN bool check_traverse_fdef(const Env env, const Func_Def fdef) { struct Vector_ v = {}; const m_uint scope = env->scope->depth; env->scope->depth = 0; @@ -661,7 +669,7 @@ ANN m_bool check_traverse_fdef(const Env env, const Func_Def fdef) { m_uint i = vector_size(w); while (i-- > 1) vector_add(&v, vector_at(w, i)); VLEN(w) = 1; - const m_bool ret = traverse_func_def(env, fdef); + const bool ret = traverse_func_def(env, fdef); for (m_uint i = vector_size(&v) + 1; --i;) vector_add(w, vector_at(&v, i - 1)); vector_release(&v); @@ -669,12 +677,12 @@ ANN m_bool check_traverse_fdef(const Env env, const Func_Def fdef) { return ret; } -ANN static m_bool check_func_args(const Env env, Arg_List args) { +ANN static bool check_func_args(const Env env, Arg_List args) { for(uint32_t i = 0; i < args->len; i++) { Arg *arg = mp_vector_at(args, Arg, i); const Var_Decl *decl = &arg->var.vd; const Value v = decl->value; - if(decl->tag.sym) CHECK_b(already_defined(env, decl->tag.sym, decl->tag.loc)); + if(decl->tag.sym) CHECK_B(already_defined(env, decl->tag.sym, decl->tag.loc)); valid_value(env, decl->tag.sym, v); } return GW_OK; @@ -750,9 +758,9 @@ ANN static Type check_predefined(const Env env, Exp_Call *exp, const Value v, .flag = tflag_check}; CHECK_BO(envset_pushv(&es, v)); func->def->base->fbflag |= fbflag_internal; - const m_bool ret = check_traverse_fdef(env, func->def); + const bool ret = check_traverse_fdef(env, func->def); envset_pop(&es, v->from->owner_class); - CHECK_BO(ret); + CHECK_O(ret); } exp->func->type = func->value_ref->type; return func->def->base->ret_type; @@ -858,17 +866,17 @@ ANN static Type check_exp_call_template(const Env env, Exp_Call *exp) { ANN Type upvalue_type(const Env env, Capture *cap); -ANN static m_bool lambda_args_ref(const Env env, Exp_Call *const call) { +ANN static bool lambda_args_ref(const Env env, Exp_Call *const call) { Exp* e = call->args; - CHECK_OB(check_exp(env, e)); + CHECK_B(check_exp(env, e)); do if(tflag(e->type, tflag_ref) && !safe_tflag(exp_self(e)->cast_to, tflag_ref)) exp_setvar(e, true); while((e = e->next)); return GW_OK; } -ANN2(1) static m_bool lambda_append_args(const Env env, Exp_Call *const call, Exp* add) { - if(!add) return GW_ERROR; +ANN2(1) static bool lambda_append_args(const Env env, Exp_Call *const call, Exp* add) { + if(!add) return false; if (call->args) { Exp* e = call->args; while(e->next) e = e->next; @@ -906,9 +914,9 @@ ANN static Exp* check_lambda_captures(const Env env, const Func_Def fdef) { ANN static Type check_lambda_call(const Env env, Exp_Call *const exp) { const Func_Def fdef = exp->func->d.exp_lambda.def; const bool captures = !!fdef->captures; - if (exp->args) CHECK_BO(lambda_args_ref(env, exp)); + if (exp->args) CHECK_O(lambda_args_ref(env, exp)); Exp* _args = !captures ? NULL : check_lambda_captures(env, fdef); - if(captures) CHECK_BO(lambda_append_args(env, exp, _args)); + if(captures) CHECK_O(lambda_append_args(env, exp, _args)); Exp_Lambda *l = &exp->func->d.exp_lambda; Arg_List args = l->def->base->args; Exp* e = exp->args; @@ -927,7 +935,7 @@ ANN static Type check_lambda_call(const Env env, Exp_Call *const exp) { if(env->func && env->func->def->base->values) upvalues.parent = env->func->def->base->values; l->def->base->values = &upvalues; - const m_bool ret = traverse_func_def(env, l->def); + const bool ret = traverse_func_def(env, l->def); if (l->def->base->func) { free_scope(env->gwion->mp, env->curr->info->value); env->curr->info->value = l->def->base->values->values; @@ -939,17 +947,17 @@ ANN static Type check_lambda_call(const Env env, Exp_Call *const exp) { return ret > 0 ? l->def->base->ret_type : NULL; } -ANN m_bool func_check(const Env env, Exp_Call *const exp) { +ANN bool func_check(const Env env, Exp_Call *const exp, bool *mod) { exp->func->is_call = true; - CHECK_OB(check_exp(env, exp->func)); + CHECK_B(check_exp(env, exp->func)); if (exp->func->exp_type == ae_exp_decl) ERR_B(exp->func->loc, _("Can't call late function pointer at declaration " "site. did you meant to use `:=>`?")) const Type t = actual_type(env->gwion, exp->func->type); if (is_func(env->gwion, t) && exp->func->exp_type == ae_exp_dot && // is_callable !t->info->value->from->owner_class) { - if (exp->args) CHECK_OB(check_exp(env, exp->args)); - return call2ufcs(env, exp, t->info->func->value_ref) ? GW_OK : GW_ERROR; + if (exp->args) CHECK_B(check_exp(env, exp->args)); + return !!call2ufcs(env, exp, t->info->func->value_ref); } Exp* e = exp_self(exp); struct Op_Import opi = {.op = insert_symbol("@func_check"), @@ -957,9 +965,12 @@ ANN m_bool func_check(const Env env, Exp_Call *const exp) { .loc = e->loc, .data = (uintptr_t)e}; if(op_get(env, &opi)) - CHECK_OB(op_check(env, &opi)); - if (e->exp_type != ae_exp_call) return 0; - return e->type != env->gwion->type[et_error] ? GW_OK : GW_ERROR; + CHECK_B(op_check(env, &opi)); + if (e->exp_type != ae_exp_call) { + *mod = true; + return true; + } + return e->type != env->gwion->type[et_error]; } ANN void call_add_effect(const Env env, const Func func, const loc_t loc) { @@ -1039,8 +1050,9 @@ ANN static Type check_static(const Env env, Exp* e) { } ANN Type check_exp_call1(const Env env, Exp_Call *const exp) { - DECL_BO(const m_bool, ret, = func_check(env, exp)); - if (!ret) return exp_self(exp)->type; + bool mod = false; + CHECK_O(func_check(env, exp, &mod)); + if (mod) return exp_self(exp)->type; const Type t = exp->func->type; CHECK_OO(check_static(env, exp->func)); const Type _ret = _check_exp_call1(env, exp); @@ -1066,7 +1078,7 @@ ANN static Type check_exp_binary(const Env env, const Exp_Binary *bin) { bin->lhs->d.exp_call.other = bin->rhs; } CHECK_OO(check_exp(env, bin->lhs)); - const m_bool is_auto = //bin->op == insert_symbol(":=>") && + const bool is_auto = //bin->op == insert_symbol(":=>") && bin->rhs->exp_type == ae_exp_decl && bin->rhs->d.exp_decl.type == env->gwion->type[et_auto]; if (is_auto) bin->rhs->d.exp_decl.type = bin->lhs->type; @@ -1131,7 +1143,7 @@ ANN static Type check_exp_post(const Env env, const Exp_Postfix *post) { return t; } -ANN static m_bool predefined_call(const Env env, const Type t, +ANN static bool predefined_call(const Env env, const Type t, const loc_t loc) { const m_str str = tl2str(env->gwion, t->info->func->def->base->tmpl->call, loc); @@ -1142,7 +1154,7 @@ ANN static m_bool predefined_call(const Env env, const Type t, gwerr_secondary("from definition:", env->name, t->info->func->def->base->tag.loc); } - return GW_ERROR; + return false; } ANN2(1) static inline bool is_partial(const Env env, Exp* exp) { @@ -1178,7 +1190,7 @@ ANN static Type check_exp_call_tmpl(const Env env, Exp_Call *exp, const Type t) } else { if(tl_match(env, t->info->func->def->base->tmpl->call, exp->tmpl->call)) return check_exp_call1(env, exp); - CHECK_BO(predefined_call(env, t, exp_self(exp)->loc)); + CHECK_O(predefined_call(env, t, exp_self(exp)->loc)); } } const Value v = type_value(env->gwion, t); @@ -1197,8 +1209,9 @@ ANN static Type check_exp_call(const Env env, Exp_Call *exp) { return op_check(env, &opi); } if (exp->tmpl) { - DECL_BO(const m_bool, ret, = func_check(env, exp)); - if (!ret) return exp_self(exp)->type; + bool mod = false; + CHECK_O(func_check(env, exp, &mod)); + if (mod) return exp_self(exp)->type; Type t = actual_type(env->gwion, exp->func->type); if(isa(exp->func->type, env->gwion->type[et_closure]) > 0) { t = typedef_base(t); @@ -1227,7 +1240,7 @@ ANN static Type check_exp_unary(const Env env, const Exp_Unary *unary) { return ret; } -ANN static Type _flow(const Env env, Exp* e, const m_bool b) { +ANN static Type _flow(const Env env, Exp* e, const bool b) { DECL_OO(const Type, type, = check_exp(env, e)); struct Op_Import opi = { .op = insert_symbol(b ? "@conditional" : "@unconditional"), @@ -1270,7 +1283,7 @@ ANN static Type check_exp_dot(const Env env, Exp_Dot *member) { return check_dot(env, member); } -ANN m_bool check_type_def(const Env env, const Type_Def tdef) { +ANN bool check_type_def(const Env env, const Type_Def tdef) { if (tdef->when) { set_tflag(tdef->type, tflag_contract); struct Var_Decl_ decl = { .tag = MK_TAG(insert_symbol("self"), tdef->when->loc) }; @@ -1291,7 +1304,7 @@ ANN m_bool check_type_def(const Env env, const Type_Def tdef) { mp_vector_set(code, Stmt, 1, MK_STMT_EXP(when->loc, NULL)); const Func_Def fdef = new_func_def(env->gwion->mp, fb, code); tdef->when_def = fdef; - CHECK_BB(traverse_func_def(env, fdef)); + CHECK_B(traverse_func_def(env, fdef)); if (isa(when->type, env->gwion->type[et_bool]) < 0) { char explain[strlen(when->type->name) + 20]; sprintf(explain, "found `{/+}%s{0}`", when->type->name); @@ -1301,7 +1314,7 @@ ANN m_bool check_type_def(const Env env, const Type_Def tdef) { sprintf(from, "in `{/+}%s{0}` definition", tdef->type->name); gwerr_secondary(from, env->name, tdef->tag.loc); env_set_error(env, true); - return GW_ERROR; + return false; } // we handle the return after, so that we don't get *cant' use implicit // casting while defining it* @@ -1334,20 +1347,25 @@ DECL_EXP_FUNC(check, Type, Env) ANN Type check_exp(const Env env, Exp* exp) { Exp* curr = exp; - if (!exp->type) { - env_weight(env, 1); - do { - CHECK_OO((curr->type = check_exp_func[curr->exp_type](env, &curr->d))); - if (env->func && !is_class(env->gwion, curr->type) && - is_func(env->gwion, curr->type) && - !safe_fflag(curr->type->info->func, fflag_pure)) - unset_fflag(env->func, fflag_pure); - } while ((curr = curr->next)); - } - return exp->type; + bool ok = true; + env_weight(env, 1); + do { + if(curr->type) continue; + if(curr->poison) continue; + if(!(curr->type = check_exp_func[curr->exp_type](env, &curr->d))) { + curr->poison = true; + ok = false; + continue; + } + if (env->func && !is_class(env->gwion, curr->type) && + is_func(env->gwion, curr->type) && + !safe_fflag(curr->type->info->func, fflag_pure)) + unset_fflag(env->func, fflag_pure); + } while ((curr = curr->next)); + return ok ? exp->type : NULL; } -ANN m_bool check_enum_def(const Env env, const Enum_Def edef) { +ANN bool check_enum_def(const Env env, const Enum_Def edef) { const m_uint scope = env_push_type(env, edef->type); ID_List list = edef->list; for(uint32_t i = 0; i < list->len; i++) { @@ -1358,29 +1376,29 @@ ANN m_bool check_enum_def(const Env env, const Enum_Def edef) { return GW_OK; } -ANN static m_bool check_stmt_code(const Env env, const Stmt_Code stmt) { - if (stmt->stmt_list) { RET_NSPC(check_stmt_list(env, stmt->stmt_list)) } +ANN static bool check_stmt_code(const Env env, const Stmt_Code stmt) { + if (stmt->stmt_list) { RET_NSPC_B(check_stmt_list(env, stmt->stmt_list)) } return GW_OK; } -ANN static inline m_bool _check_breaks(const Env env, Stmt* b) { - RET_NSPC(check_stmt(env, b))} +ANN static inline bool _check_breaks(const Env env, Stmt* b) { + RET_NSPC_B(check_stmt(env, b))} -ANN static m_bool check_breaks(const Env env, Stmt* a, Stmt* b) { +ANN static bool check_breaks(const Env env, Stmt* a, Stmt* b) { vector_add(&env->scope->breaks, (vtype)a); - const m_bool ret = _check_breaks(env, b); + const bool ret = _check_breaks(env, b); vector_pop(&env->scope->breaks); return ret; } -ANN static m_bool check_conts(const Env env, Stmt* a, Stmt* b) { +ANN static bool check_conts(const Env env, Stmt* a, Stmt* b) { vector_add(&env->scope->conts, (vtype)a); - CHECK_BB(check_breaks(env, a, b)); + CHECK_B(check_breaks(env, a, b)); vector_pop(&env->scope->conts); return GW_OK; } -ANN static inline m_bool for_empty(const Env env, const Stmt_For stmt) { +ANN static inline bool for_empty(const Env env, const Stmt_For stmt) { if (!stmt->c2 || !stmt->c2->d.stmt_exp.val) ERR_B(stmt_self(stmt)->loc, _("empty for loop condition..." @@ -1397,7 +1415,7 @@ ANN static void check_idx(const Env env, const Type base, struct EachIdx_ *const /** sets for the key expression value with eg type *int* for an array or the *Key* type of a Dict **/ -ANN static m_bool check_each_idx(const Env env, Exp* exp, struct EachIdx_ *const idx) { +ANN static bool check_each_idx(const Env env, Exp* exp, struct EachIdx_ *const idx) { struct Op_Import opi = { .lhs = exp->type, .op = insert_symbol("@each_idx"), @@ -1421,58 +1439,58 @@ ANN static Type check_each_val(const Env env, Exp* exp) { return op_check(env, &opi); } -ANN static m_bool do_stmt_each(const Env env, const Stmt_Each stmt) { - CHECK_OB(check_exp(env, stmt->exp)); +ANN static bool do_stmt_each(const Env env, const Stmt_Each stmt) { + CHECK_B(check_exp(env, stmt->exp)); if (stmt->idx) - CHECK_BB(check_each_idx(env, stmt->exp, stmt->idx)); + CHECK_B(check_each_idx(env, stmt->exp, stmt->idx)); DECL_OB(const Type, ret, = check_each_val(env, stmt->exp)); stmt->var.value = new_value(env, ret, stmt->tag); valid_value(env, stmt->tag.sym, stmt->var.value); return check_conts(env, stmt_self(stmt), stmt->body); } -ANN static m_bool do_stmt_repeat(const Env env, const Stmt_Loop stmt) { +ANN static bool do_stmt_repeat(const Env env, const Stmt_Loop stmt) { if (stmt->idx) check_idx(env, env->gwion->type[et_int], stmt->idx); return check_conts(env, stmt_self(stmt), stmt->body); } -ANN static inline m_bool repeat_type(const Env env, Exp* e) { +ANN static inline bool repeat_type(const Env env, Exp* e) { const Type t_int = env->gwion->type[et_int]; - if (check_implicit(env, e, t_int) < 0) { + if (!check_implicit(env, e, t_int)) { char explain[40 + strlen(e->type->name)]; sprintf(explain, "expected `{/+}int{0}`, got `{/+}%s{0}`", e->type->name); gwerr_basic(_("invalid repeat condition type"), explain, _("use an integer or cast to int if possible"), env->name, e->loc, 0); env_set_error(env, true); - return GW_ERROR; + return false; } return GW_OK; } #define stmt_func_xxx(name, type, prolog, exp) \ - describe_stmt_func(check, name, type, prolog, exp) + describe_stmt_func_b(check, name, type, prolog, exp) stmt_func_xxx(if, Stmt_If,, !(!check_flow(env, stmt->cond) || - check_stmt(env, stmt->if_body) < 0 || - (stmt->else_body && check_stmt(env, stmt->else_body) < 0)) ? 1 : -1) + !check_stmt(env, stmt->if_body) || + (stmt->else_body && !check_stmt(env, stmt->else_body))) ? true : false) stmt_func_xxx(flow, Stmt_Flow, env_inline_mult(env, 1.5), !(!check_exp(env, stmt->cond) || !_flow(env, stmt->cond, !stmt->is_do ? stmt_self(stmt)->stmt_type == ae_stmt_while : stmt_self(stmt)->stmt_type != ae_stmt_while) || - check_conts(env, stmt_self(stmt), stmt->body) < 0) ? 1 : -1) + !check_conts(env, stmt_self(stmt), stmt->body)) ? true : false) stmt_func_xxx(for, Stmt_For, env_inline_mult(env, 1.5), !( - for_empty(env, stmt) < 0 || - check_stmt(env, stmt->c1) < 0 || + !for_empty(env, stmt) || + !check_stmt(env, stmt->c1) || !check_flow(env, stmt->c2->d.stmt_exp.val) || (stmt->c3 && !check_exp(env, stmt->c3)) || - check_conts(env, stmt_self(stmt), stmt->body) < 0) ? 1 : -1) + !check_conts(env, stmt_self(stmt), stmt->body)) ? true : false) stmt_func_xxx(loop, Stmt_Loop, env_inline_mult(env, 1.5); check_idx(env, stmt->idx), !(!check_exp(env, stmt->cond) || - repeat_type(env, stmt->cond) < 0 || - do_stmt_repeat(env, stmt) < 0) ? 1 : -1) + !repeat_type(env, stmt->cond) || + !do_stmt_repeat(env, stmt)) ? true : false) stmt_func_xxx(each, Stmt_Each, env_inline_mult(env, 1.5), do_stmt_each(env, stmt)) -ANN static m_bool check_stmt_return(const Env env, const Stmt_Exp stmt) { +ANN static bool check_stmt_return(const Env env, const Stmt_Exp stmt) { if (is_new(env->func->def)) { if(stmt->val) ERR_B(stmt_self(stmt)->loc, @@ -1495,7 +1513,7 @@ ANN static m_bool check_stmt_return(const Env env, const Stmt_Exp stmt) { ret_type == arg->type) ERR_B(stmt_self(stmt)->loc, _("can't use implicit casting while defining it")) - if (check_implicit(env, stmt->val, env->func->def->base->ret_type) > 0) + if (check_implicit(env, stmt->val, env->func->def->base->ret_type)) return GW_OK; ERR_B(stmt_self(stmt)->loc, _("invalid return type: got '%s', expected '%s'"), ret_type->name, @@ -1507,7 +1525,7 @@ ANN static m_bool check_stmt_return(const Env env, const Stmt_Exp stmt) { } #define describe_check_stmt_stack(stack, name) \ - ANN static m_bool check_stmt_##name(const Env env, const Stmt* stmt) { \ + ANN static bool check_stmt_##name(const Env env, const Stmt* stmt) { \ if (!vector_size(&env->scope->stack)) \ ERR_B(stmt->loc, _("'" #name "' found outside of for/while/until...")) \ return GW_OK; \ @@ -1515,22 +1533,22 @@ ANN static m_bool check_stmt_return(const Env env, const Stmt_Exp stmt) { describe_check_stmt_stack(conts, continue); describe_check_stmt_stack(breaks, break); -ANN m_bool check_union_def(const Env env NUSED, const Union_Def udef) { +ANN bool check_union_def(const Env env NUSED, const Union_Def udef) { if (tmpl_base(udef->tmpl)) // there's a func for this return GW_OK; set_tflag(udef->type, tflag_check); return GW_OK; } -ANN static m_bool check_stmt_exp(const Env env, const Stmt_Exp stmt) { +ANN static bool check_stmt_exp(const Env env, const Stmt_Exp stmt) { if(stmt->val) { - CHECK_OB(check_exp(env, stmt->val)); + CHECK_B(check_exp(env, stmt->val)); if(stmt->val->exp_type == ae_exp_lambda) { const loc_t loc = stmt->val->d.exp_lambda.def->base->tag.loc; env_warn(env, loc, _("Partial application not used")); } } - return stmt->val ? check_exp(env, stmt->val) ? 1 : -1 : 1; + return stmt->val ? !!check_exp(env, stmt->val) : true; } ANN static Value match_value(const Env env, const Type base, @@ -1579,7 +1597,7 @@ ANN static Symbol case_op(const Env env, const Type base, Exp* e) { return case_basic_op(env, base, e); } -ANN static m_bool match_case_exp(const Env env, Exp* e) { +ANN static bool match_case_exp(const Env env, Exp* e) { Exp* last = e; for (m_uint i = 0; i < vector_size(&env->scope->match->cond); e = e->next, ++i) { if (!e) ERR_B(last->loc, _("no enough to match")) @@ -1591,51 +1609,51 @@ ANN static m_bool match_case_exp(const Env env, Exp* e) { e->next = NULL; const Type t = check_exp(env, e); e->next = next; - CHECK_OB(t); + CHECK_B(t); Exp_Binary bin = {.lhs = cpy_exp(env->gwion->mp, base), .rhs = cpy_exp(env->gwion->mp, e), .op = op}; Exp ebin = {.d = {.exp_binary = bin}, .exp_type = ae_exp_binary, .loc = e->loc }; - CHECK_BB(traverse_exp(env, &ebin)); + CHECK_B(traverse_exp(env, &ebin)); const Type ret = ebin.type; if(ebin.exp_type == ae_exp_binary) { free_exp(env->gwion->mp, bin.lhs); free_exp(env->gwion->mp, bin.rhs); } - CHECK_OB(ret); + CHECK_B(ret); } } if (e) ERR_B(e->loc, _("too many expression to match")) return GW_OK; } -ANN static m_bool _check_stmt_case(const Env env, const Stmt_Match stmt) { - CHECK_BB(match_case_exp(env, stmt->cond)); - if (stmt->when) CHECK_OB(check_flow(env, stmt->when)); +ANN static bool _check_stmt_case(const Env env, const Stmt_Match stmt) { + CHECK_B(match_case_exp(env, stmt->cond)); + if (stmt->when) CHECK_B(check_flow(env, stmt->when)); return check_stmt_list(env, stmt->list); } -ANN static m_bool check_stmt_case(const Env env, const Stmt_Match stmt) { - RET_NSPC(_check_stmt_case(env, stmt))} +ANN static bool check_stmt_case(const Env env, const Stmt_Match stmt) { + RET_NSPC_B(_check_stmt_case(env, stmt))} -ANN static m_bool case_loop(const Env env, const Stmt_Match stmt) { +ANN static bool case_loop(const Env env, const Stmt_Match stmt) { for(m_uint i = 0; i < stmt->list->len; i++) { Stmt* s = mp_vector_at(stmt->list, Stmt, i); - CHECK_BB(check_stmt_case(env, &s->d.stmt_match)); + CHECK_B(check_stmt_case(env, &s->d.stmt_match)); } return GW_OK; } -ANN static inline m_bool check_handler(const restrict Env env, +ANN static inline bool check_handler(const restrict Env env, const Handler *handler) { - RET_NSPC(check_stmt(env, handler->stmt)); + RET_NSPC_B(check_stmt(env, handler->stmt)); } -ANN static inline m_bool check_handler_list(const restrict Env env, +ANN static inline bool check_handler_list(const restrict Env env, const Handler_List handlers) { const bool in_try = env->scope->in_try; env->scope->in_try = true; for(uint32_t i = 0; i < handlers->len; i++) { Handler *handler = mp_vector_at(handlers, Handler, i); - CHECK_BB(check_handler(env, handler)); + CHECK_B(check_handler(env, handler)); } env->scope->in_try = in_try; return GW_OK; @@ -1650,15 +1668,15 @@ ANN static inline bool find_handler(const Handler_List handlers, const Symbol xi return false; } -ANN static inline m_bool check_stmt_try_start(const restrict Env env, +ANN static inline bool check_stmt_try_start(const restrict Env env, const Stmt_Try stmt) { - RET_NSPC(check_stmt(env, stmt->stmt)) + RET_NSPC_B(check_stmt(env, stmt->stmt)) } -ANN static inline m_bool check_stmt_try(const restrict Env env, const Stmt_Try stmt) { - CHECK_BB(check_handler_list(env, stmt->handler)); +ANN static inline bool check_stmt_try(const restrict Env env, const Stmt_Try stmt) { + CHECK_B(check_handler_list(env, stmt->handler)); vector_add(&env->scope->effects, 0); - const m_bool ret = check_stmt_try_start(env, stmt); + const bool ret = check_stmt_try_start(env, stmt); MP_Vector *const v = (MP_Vector*)vector_pop(&env->scope->effects); if (v) { for (m_uint i = 0; i < v->len; i++) { @@ -1671,27 +1689,27 @@ ANN static inline m_bool check_stmt_try(const restrict Env env, const Stmt_Try s return ret; } -ANN static m_bool _check_stmt_match(const Env env, const Stmt_Match stmt) { - CHECK_OB(check_exp(env, stmt->cond)); +ANN static bool _check_stmt_match(const Env env, const Stmt_Match stmt) { + CHECK_B(check_exp(env, stmt->cond)); MATCH_INI(env->scope) - const m_bool ret = case_loop(env, stmt); + const bool ret = case_loop(env, stmt); MATCH_END(env->scope) return ret; } -ANN static inline m_bool handle_where(const Env env, const Stmt_Match stmt) { - if (stmt->where) CHECK_BB(check_stmt(env, stmt->where)); - RET_NSPC(_check_stmt_match(env, stmt)) +ANN static inline bool handle_where(const Env env, const Stmt_Match stmt) { + if (stmt->where) CHECK_B(check_stmt(env, stmt->where)); + RET_NSPC_B(_check_stmt_match(env, stmt)) } -ANN static m_bool check_stmt_match(const Env env, const Stmt_Match stmt) { - RET_NSPC(handle_where(env, stmt)) +ANN static bool check_stmt_match(const Env env, const Stmt_Match stmt) { + RET_NSPC_B(handle_where(env, stmt)) } #define check_stmt_while check_stmt_flow #define check_stmt_until check_stmt_flow -ANN static m_bool check_stmt_pp(const Env env, const Stmt_PP stmt) { +ANN static bool check_stmt_pp(const Env env, const Stmt_PP stmt) { if (stmt->pp_type == ae_pp_include) env->name = stmt->data; // check for memoization else if (env->func && stmt->pp_type == ae_pp_pragma && @@ -1704,33 +1722,33 @@ ANN static m_bool check_stmt_pp(const Env env, const Stmt_PP stmt) { arg->next = stmt->exp; Exp* call = new_exp_call(env->gwion->mp, id, arg, loc); stmt->exp = call; - CHECK_BB(traverse_exp(env, id)); - CHECK_OB(partial_type(env, &call->d.exp_call)); + CHECK_B(traverse_exp(env, id)); + CHECK_B(partial_type(env, &call->d.exp_call)); } return GW_OK; } -ANN static m_bool check_stmt_defer(const Env env, const Stmt_Defer stmt) { +ANN static bool check_stmt_defer(const Env env, const Stmt_Defer stmt) { return check_stmt(env, stmt->stmt); } -#define check_stmt_retry dummy_func -#define check_stmt_spread dummy_func -DECL_STMT_FUNC(check, m_bool, Env) +#define check_stmt_retry bdummy_func +#define check_stmt_spread bdummy_func +DECL_STMT_FUNC(check, bool, Env) -ANN m_bool check_stmt(const Env env, Stmt* stmt) { +ANN bool check_stmt(const Env env, Stmt* stmt) { return check_stmt_func[stmt->stmt_type](env, &stmt->d); } -ANN m_bool check_stmt_list(const Env env, Stmt_List l) { +ANN bool check_stmt_list(const Env env, Stmt_List l) { for(m_uint i = 0; i < l->len; i++) { Stmt* s = mp_vector_at(l, Stmt, i); - CHECK_BB(check_stmt(env, s)); + CHECK_B(check_stmt(env, s)); } return GW_OK; } -ANN static m_bool check_signature_match(const Env env, const Func_Def fdef, +ANN static bool check_signature_match(const Env env, const Func_Def fdef, const Func parent) { if (GET_FLAG(parent->def->base, final)) ERR_B(fdef->base->td->tag.loc, _("can't override final function '%s'\n"), @@ -1750,16 +1768,16 @@ ANN static m_bool check_signature_match(const Env env, const Func_Def fdef, gwerr_basic_from("invalid overriding", NULL, NULL, fdef->base->func->value_ref->from, 0); gwerr_secondary_from("does not match", parent->value_ref->from); env_set_error(env, true); - return GW_ERROR; + return false; } -ANN static m_bool parent_match_actual(const Env env, +ANN static bool parent_match_actual(const Env env, const restrict Func_Def fdef, const restrict Func func) { Func parent_func = func; do { - if (parent_func->def->base && compat_func(fdef, parent_func->def) > 0) { - CHECK_BB(check_signature_match(env, fdef, parent_func)); + if (parent_func->def->base && compat_func(fdef, parent_func->def)) { + CHECK_B(check_signature_match(env, fdef, parent_func)); if (!fdef->base->tmpl) { fdef->vt_index = parent_func->def->vt_index; vector_set(&env->curr->vtable, fdef->vt_index, @@ -1771,14 +1789,14 @@ ANN static m_bool parent_match_actual(const Env env, return 0; } -ANN static m_bool check_parent_match(const Env env, const Func_Def fdef) { +ANN static bool check_parent_match(const Env env, const Func_Def fdef) { const Func func = fdef->base->func; const Type parent = env->class_def->info->parent; if (!env->curr->vtable.ptr) vector_init(&env->curr->vtable); if (parent) { const Value v = find_value(parent, fdef->base->tag.sym); if (v && is_func(env->gwion, v->type)) { - const m_bool match = parent_match_actual(env, fdef, v->d.func_ref); + const bool match = parent_match_actual(env, fdef, v->d.func_ref); if (match) return match; } } @@ -1794,13 +1812,13 @@ ANN static inline Func get_overload(const Env env, const Func_Def fdef, return nspc_lookup_func1(env->curr, sym); } -ANN static m_bool check_func_overload(const Env env, const Func_Def fdef) { +ANN static bool check_func_overload(const Env env, const Func_Def fdef) { const Value v = fdef->base->func->value_ref; for (m_uint i = 0; i <= v->from->offset; ++i) { const Func f1 = get_overload(env, fdef, i); for (m_uint j = i + 1; f1 && j <= v->from->offset; ++j) { const Func f2 = get_overload(env, fdef, j); - if (f2 && compat_func(f1->def, f2->def) > 0 && + if (f2 && compat_func(f1->def, f2->def) && fbflag(f1->def->base, fbflag_op) == fbflag(f2->def->base, fbflag_op) && fbflag(f1->def->base, fbflag_unary) == @@ -1826,7 +1844,7 @@ ANN static bool check_effect_overload(const Vector base, const Func override) { return true; } -ANN static m_bool check_func_def_override(const Env env, const Func_Def fdef, +ANN static bool check_func_def_override(const Env env, const Func_Def fdef, Value *ov) { const Func func = fdef->base->func; if (env->class_def && env->class_def->info->parent) { @@ -1842,11 +1860,11 @@ ANN static m_bool check_func_def_override(const Env env, const Func_Def fdef, } if (func->value_ref->from->offset && (!fdef->base->tmpl /*|| !fdef->base->tmpl->base*/)) - CHECK_BB(check_func_overload(env, fdef)); + CHECK_B(check_func_overload(env, fdef)); return GW_OK; } -ANN static m_bool check_fdef_effects(const Env env, const Func_Def fdef) { +ANN static bool check_fdef_effects(const Env env, const Func_Def fdef) { MP_Vector *v = (MP_Vector*)vector_back(&env->scope->effects); if (v) { if (fdef->base->tag.sym == insert_symbol("@dtor")) @@ -1872,7 +1890,7 @@ ANN static void fdef_const_generic_value(const Env env, const Type owner, const v->from->owner_class = owner; } -ANN static m_bool check_fdef_const_generic(const Env env, const Func_Def fdef) { +ANN static bool check_fdef_const_generic(const Env env, const Func_Def fdef) { const Tmpl *tmpl = fdef->base->tmpl; if(tmplarg_ntypes(tmpl->call) == tmpl->call->len) return GW_OK; const Type t = fdef->base->func->value_ref->type; @@ -1885,36 +1903,36 @@ ANN static m_bool check_fdef_const_generic(const Env env, const Func_Def fdef) { // spec could be null cause of spread ops const Specialized *spec = mp_vector_at(fdef->base->tmpl->list, Specialized, i); if(!spec) break; - CHECK_BB(const_generic_typecheck(env, spec, targ)); + CHECK_B(const_generic_typecheck(env, spec, targ)); fdef_const_generic_value(env, t, targ->d.exp->type, spec->tag); } return GW_OK; } -ANN static m_bool check_fdef_code(const Env env, const Func_Def fdef) { +ANN static bool check_fdef_code(const Env env, const Func_Def fdef) { const bool ctor = is_ctor(fdef); if(!ctor) { nspc_push_value(env->gwion->mp, env->curr); env->scope->depth++; } - const m_bool ret = check_stmt_list(env, fdef->d.code); + const bool ret = check_stmt_list(env, fdef->d.code); if(!ctor) { env->scope->depth--; nspc_pop_value(env->gwion->mp, env->curr); } - CHECK_BB(check_fdef_effects(env, fdef)); + CHECK_B(check_fdef_effects(env, fdef)); return ret; } -ANN m_bool check_fdef(const Env env, const Func_Def fdef) { - if (fdef->base->args) CHECK_BB(check_func_args(env, fdef->base->args)); - if (fdef->base->tmpl) CHECK_BB(check_fdef_const_generic(env, fdef)); +ANN bool check_fdef(const Env env, const Func_Def fdef) { + if (fdef->base->args) CHECK_B(check_func_args(env, fdef->base->args)); + if (fdef->base->tmpl) CHECK_B(check_fdef_const_generic(env, fdef)); if (fdef->builtin) return GW_OK; - if (fdef->d.code) CHECK_BB(check_fdef_code(env, fdef)); + if (fdef->d.code) CHECK_B(check_fdef_code(env, fdef)); return GW_OK; } -ANN static m_bool check_ctor(const Env env, const Func func) { +ANN static bool check_ctor(const Env env, const Func func) { if(!func->def->builtin && !GET_FLAG(func, const)) { const Type_Decl *td = env->class_def->info->cdef->base.ext; const m_uint depth = !td || !td->array @@ -1929,7 +1947,7 @@ ANN static m_bool check_ctor(const Env env, const Func func) { return GW_OK; } -ANN m_bool _check_func_def(const Env env, const Func_Def f) { +ANN bool _check_func_def(const Env env, const Func_Def f) { if (tmpl_base(f->base->tmpl) && fbflag(f->base, fbflag_op)) return GW_OK; const Func func = f->base->func; const Func_Def fdef = func->def; @@ -1937,10 +1955,10 @@ ANN m_bool _check_func_def(const Env env, const Func_Def f) { set_fflag(func, fflag_valid); assert(func == fdef->base->func); if (env->class_def && !fbflag(func->def->base, fbflag_lambda)) - CHECK_BB(check_parent_match(env, fdef)); + CHECK_B(check_parent_match(env, fdef)); if (tmpl_base(fdef->base->tmpl)) return GW_OK; Value override = NULL; - CHECK_BB(check_func_def_override(env, fdef, &override)); + CHECK_B(check_func_def_override(env, fdef, &override)); DECL_BB(const m_int, scope, = GET_FLAG(fdef->base, global) ? env_push_global(env) : env->scope->depth); @@ -1963,7 +1981,7 @@ ANN m_bool _check_func_def(const Env env, const Func_Def f) { } } vector_add(&env->scope->effects, 0); - const m_bool ret = scanx_fdef(env, env, fdef, (_exp_func)check_fdef); + const bool ret = scanx_fdef_b(env, env, fdef, (_exp_func_b)check_fdef); vector_pop(&env->scope->effects); if (fbflag(fdef->base, fbflag_op)) operator_resume(&opi); nspc_pop_value(env->gwion->mp, env->curr); @@ -1976,7 +1994,7 @@ ANN m_bool _check_func_def(const Env env, const Func_Def f) { ERR_B(fdef->base->tag.loc, _("too much effects in override."), s_name(fdef->base->tag.sym)) if(is_new(f) && !tflag(env->class_def, tflag_struct)) - CHECK_BB(check_ctor(env, func)); + CHECK_B(check_ctor(env, func)); } if (GET_FLAG(fdef->base, global)) env_pop(env, scope); if (func->value_ref->from->owner_class) @@ -1986,16 +2004,16 @@ ANN m_bool _check_func_def(const Env env, const Func_Def f) { return ret; } -ANN m_bool check_func_def(const Env env, const Func_Def fdef) { +ANN bool check_func_def(const Env env, const Func_Def fdef) { const uint16_t depth = env->scope->depth; env->scope->depth = 0; - const m_bool ret = _check_func_def(env, fdef); + const bool ret = _check_func_def(env, fdef); env->scope->depth = depth; return ret; } ANN bool check_trait_requests(const Env env, const Type t, const ID_List list, const ValueFrom *from); -ANN static m_bool check_extend_def(const Env env, const Extend_Def xdef) { +ANN static bool check_extend_def(const Env env, const Extend_Def xdef) { const Type t = xdef->type; ValueFrom from = { .filename = env->name, .loc=xdef->td->tag.loc, .ctx=env->context, .owner = env->curr, .owner_class = env->class_def @@ -2016,10 +2034,10 @@ ANN static m_bool check_extend_def(const Env env, const Extend_Def xdef) { } return GW_OK; } - return GW_ERROR; + return false; } -ANN static m_bool _check_trait_def(const Env env, const Trait_Def pdef) { +ANN static bool _check_trait_def(const Env env, const Trait_Def pdef) { const Trait trait = nspc_lookup_trait1(env->curr, pdef->tag.sym); Ast ast = pdef->body; if(!ast) return GW_OK; @@ -2031,7 +2049,7 @@ ANN static m_bool _check_trait_def(const Env env, const Trait_Def pdef) { for(m_uint i = 0; i < l->len; i++) { const Stmt* stmt = mp_vector_at(l, Stmt, i); if (stmt->stmt_type == ae_stmt_exp) { - CHECK_BB(traverse_exp(env, stmt->d.stmt_exp.val)); + CHECK_B(traverse_exp(env, stmt->d.stmt_exp.val)); Var_Decl vd = stmt->d.stmt_exp.val->d.exp_decl.var.vd; const Value value = vd.value; valuefrom(env, value->from); @@ -2045,40 +2063,40 @@ ANN static m_bool _check_trait_def(const Env env, const Trait_Def pdef) { return GW_OK; } -ANN static m_bool check_trait_def(const Env env, const Trait_Def pdef) { - RET_NSPC(_check_trait_def(env, pdef)); +ANN static bool check_trait_def(const Env env, const Trait_Def pdef) { + RET_NSPC_B(_check_trait_def(env, pdef)); } -ANN m_bool check_fptr_def(const Env env, const Fptr_Def fptr) { +ANN bool check_fptr_def(const Env env, const Fptr_Def fptr) { if(GET_FLAG(fptr->cdef, global)) env_push_global(env); - const m_bool ret = check_class_def(env, fptr->cdef); + const bool ret = check_class_def(env, fptr->cdef); if(GET_FLAG(fptr->cdef, global)) env_pop(env, 0); return ret; } -#define check_prim_def dummy_func -HANDLE_SECTION_FUNC(check, m_bool, Env) +#define check_prim_def bdummy_func +HANDLE_SECTION_FUNC(check, bool, Env) -ANN static m_bool check_parent(const Env env, const Class_Def cdef) { +ANN static bool check_parent(const Env env, const Class_Def cdef) { const Type parent = cdef->base.type->info->parent; const Type_Decl *td = cdef->base.ext; if (td->array && td->array->exp) - CHECK_BB(check_subscripts(env, td->array, 1)); - CHECK_BB(ensure_traverse(env, parent)); + CHECK_B(check_subscripts(env, td->array, 1)); + CHECK_B(ensure_traverse(env, parent)); if(GET_FLAG(parent, abstract)) SET_FLAG(cdef->base.type, abstract); return GW_OK; } -ANN static m_bool cdef_parent(const Env env, const Class_Def cdef) { +ANN static bool cdef_parent(const Env env, const Class_Def cdef) { const bool tmpl = !!cdef->base.tmpl; if (tmpl) CHECK_B(template_push_types(env, cdef->base.tmpl)); - const m_bool ret = check_parent(env, cdef); + const bool ret = check_parent(env, cdef); if (tmpl) nspc_pop_type(env->gwion->mp, env->curr); return ret; } -ANN m_bool check_abstract(const Env env, const Class_Def cdef) { +ANN bool check_abstract(const Env env, const Class_Def cdef) { if (!cdef->base.type->nspc->vtable.ptr) return GW_OK; bool err = false; for (m_uint i = 0; i < vector_size(&cdef->base.type->nspc->vtable); ++i) { @@ -2096,7 +2114,7 @@ ANN m_bool check_abstract(const Env env, const Class_Def cdef) { env_set_error(env, true); } } - return !err ? GW_OK : GW_ERROR; + return !err; } ANN static bool class_def_has_body(Ast ast) { @@ -2126,7 +2144,7 @@ ANN static inline bool type_is_recurs(const Type t, const Type tgt) { return isa(tgt, t) > 0 || isa(t, tgt) > 0 || (tgt->info->tuple && vector_find(&tgt->info->tuple->contains, (m_uint)t) > -1); } -ANN static m_bool recursive_type_base(const Env env, const Type t); +ANN static bool recursive_type_base(const Env env, const Type t); ANN static bool recursive_type(const Env env, const Type t, const Type tgt); ANN static bool recursive_value(const Env env, const Type t, const Value v) { const Type tgt = array_base(v->type); @@ -2180,7 +2198,7 @@ ANN static bool recursive_type(const Env env, const Type t, const Type tgt) { return error; } -ANN static m_bool recursive_type_base(const Env env, const Type t) { +ANN static bool recursive_type_base(const Env env, const Type t) { Value value; bool error = false; struct scope_iter iter = {t->nspc->info->value, 0, 0}; @@ -2194,17 +2212,17 @@ ANN static m_bool recursive_type_base(const Env env, const Type t) { } } } - return error; + return !error; } ANN bool check_trait_requests(const Env env, const Type t, const ID_List list, const ValueFrom *from); -ANN static m_bool check_class_tmpl(const Env env, const Tmpl *tmpl, const Nspc nspc) { +ANN static bool check_class_tmpl(const Env env, const Tmpl *tmpl, const Nspc nspc) { if(tmplarg_ntypes(tmpl->list) != tmpl->list->len) { for(uint32_t i = 0; i < tmpl->list->len; i++) { const TmplArg targ = *mp_vector_at(tmpl->call, TmplArg, i); if(likely(targ.type == tmplarg_td)) continue; - CHECK_OB(check_exp(env, targ.d.exp)); + CHECK_B(check_exp(env, targ.d.exp)); const Specialized spec = *mp_vector_at(tmpl->list, Specialized, i); const Value v = new_value(env, targ.d.exp->type, MK_TAG(spec.tag.sym, targ.d.exp->loc)); valuefrom(env, v->from); @@ -2217,33 +2235,33 @@ ANN static m_bool check_class_tmpl(const Env env, const Tmpl *tmpl, const Nspc n return GW_OK; } -ANN static m_bool _check_class_def(const Env env, const Class_Def cdef) { +ANN static bool _check_class_def(const Env env, const Class_Def cdef) { const Type t = cdef->base.type; - if (cdef->base.ext) CHECK_BB(cdef_parent(env, cdef)); + if (cdef->base.ext) CHECK_B(cdef_parent(env, cdef)); if (!tflag(t, tflag_struct)) inherit(t); - if(cdef->base.tmpl) CHECK_BB(check_class_tmpl(env, cdef->base.tmpl, cdef->base.type->nspc)); + if(cdef->base.tmpl) CHECK_B(check_class_tmpl(env, cdef->base.tmpl, cdef->base.type->nspc)); if (cdef->body) { - CHECK_BB(env_body(env, cdef, check_section)); + CHECK_B(env_body_b(env, cdef, check_section)); if (cflag(cdef, cflag_struct) || class_def_has_body(cdef->body)) // if (class_def_has_body(cdef->body)) set_tflag(t, tflag_ctor); } - if (!GET_FLAG(cdef, abstract)) CHECK_BB(check_abstract(env, cdef)); + if (!GET_FLAG(cdef, abstract)) CHECK_B(check_abstract(env, cdef)); if (cdef->traits) { ID_List list = cdef->traits; if (!check_trait_requests(env, t, list, t->info->value->from)) { env->class_def = t; env_error_footer(env); env_set_error(env, true); - return GW_ERROR; + return false; } } - CHECK_BB(recursive_type_base(env, t)); + CHECK_B(recursive_type_base(env, t)); nspc_allocdata(env->gwion->mp, t->nspc); return GW_OK; } -ANN m_bool check_class_def(const Env env, const Class_Def cdef) { +ANN bool check_class_def(const Env env, const Class_Def cdef) { if (tmpl_base(cdef->base.tmpl)) return GW_OK; const Type t = cdef->base.type; if (tflag(t, tflag_check)) return GW_OK; @@ -2276,14 +2294,14 @@ ANN static void check_extend(const Env env, Ast ast) { env->context->extend = NULL; } -ANN m_bool check_ast(const Env env, Ast *ast) { +ANN bool check_ast(const Env env, Ast *ast) { Ast a = *ast; for(m_uint i = 0; i < a->len; i++) { Section * section = mp_vector_at(a, Section, i); -if(section->poison) continue; - if(check_section(env, section) < 0) { - section->poison = GW_OK; - return GW_ERROR; + if(section->poison) return false; + if(!check_section(env, section)) { + section->poison = true; + return false; } } if(vector_size(&env->scope->effects)) check_unhandled(env); diff --git a/src/parse/check_traits.c b/src/parse/check_traits.c index 91063e6a..1478b074 100644 --- a/src/parse/check_traits.c +++ b/src/parse/check_traits.c @@ -57,7 +57,7 @@ ANN static bool trait_inherit(const Env env, const Type t, const Func_Def req) { nspc_add_type(env->curr, insert_symbol("Self"), t); const Func_Def cpy = cpy_func_def(env->gwion->mp, req); if(global) SET_FLAG(cpy->base, global); - const m_bool ret = traverse_func_def(env, cpy); + const bool ret = traverse_func_def(env, cpy); nspc_pop_type(env->gwion->mp, env->curr); Section section = MK_SECTION(func, func_def, cpy); if(!env->context->extend) diff --git a/src/parse/compat_func.c b/src/parse/compat_func.c index 6b59d49c..716912b9 100644 --- a/src/parse/compat_func.c +++ b/src/parse/compat_func.c @@ -2,20 +2,20 @@ #include "gwion_ast.h" #include "gwion_env.h" -ANN m_bool compat_func(const restrict Func_Def lhs, +ANN bool compat_func(const restrict Func_Def lhs, const restrict Func_Def rhs) { Arg_List args0 = lhs->base->args; Arg_List args1 = rhs->base->args; if(!args0 && !args1) - return GW_OK; + return true; if((!args0 && args1) || (args0 && !args1)) - return GW_ERROR; + return false; if(args0->len != args1->len) - return GW_ERROR; + return false; for(uint32_t i = 0; i < args0->len; i++) { Arg *arg0 = mp_vector_at(args0, Arg, i); Arg *arg1 = mp_vector_at(args1, Arg, i); - if (arg0->type != arg1->type) return GW_ERROR; + if (arg0->type != arg1->type) return false; } - return GW_OK; + return true; } diff --git a/src/parse/did_you_mean.c b/src/parse/did_you_mean.c index 4f8fd219..430d2576 100644 --- a/src/parse/did_you_mean.c +++ b/src/parse/did_you_mean.c @@ -10,7 +10,7 @@ #define min2(a, b) ((a) < (b) ? (a) : (b)) #define min(a, b, c) (min2(min2((a), (b)), (c))) -static m_bool wagner_fisher(const char *s, const char *t) { +static bool wagner_fisher(const char *s, const char *t) { const size_t m = strlen(s); const size_t n = strlen(t); unsigned int d[m][n]; diff --git a/src/parse/func_resolve_tmpl.c b/src/parse/func_resolve_tmpl.c index 46e4c9c8..45d1ee1b 100644 --- a/src/parse/func_resolve_tmpl.c +++ b/src/parse/func_resolve_tmpl.c @@ -34,7 +34,7 @@ tmpl_valid(const Env env, const Func_Def fdef, const m_str filename) { if (safe_fflag(fdef->base->func, fflag_valid)) return true; const m_str old_file = env->name; env->name = filename; - const bool ret = check_traverse_fdef(env, fdef) > 0; + const bool ret = check_traverse_fdef(env, fdef); env->name = old_file; if(!fdef->base->func) free_func_def(env->gwion->mp, fdef); return ret; @@ -57,7 +57,7 @@ ANN static Func ensure_tmpl(const Env env, const Func_Def fdef, ANN static inline Func ensure_fptr(const Env env, struct ResolverArgs *ra, const Fptr_Def fptr) { - CHECK_BO(traverse_fptr_def(env, fptr)); + CHECK_O(traverse_fptr_def(env, fptr)); const Func_Def fdef = mp_vector_at(fptr->cdef->base.type->info->cdef->body, struct Section_ , 0)->d.func_def; return find_func_match(env, fdef->base->func, ra->e); } @@ -210,16 +210,23 @@ ANN static Func _find_template_match(const Env env, const Value v, return f; } -ANN static inline m_bool check_call(const Env env, const Exp_Call *exp) { +#undef ERR_B +#define ERR_B(a, b, ...) \ + { \ + env_err(env, (a), (b), ##__VA_ARGS__); \ + return false; \ + } + +ANN static inline bool check_call(const Env env, const Exp_Call *exp) { const ae_exp_t et = exp->func->exp_type; if (et != ae_exp_primary && et != ae_exp_dot && et != ae_exp_cast) ERR_B(exp->func->loc, _("invalid expression for function call.")) - return GW_OK; + return true; } ANN Func find_template_match(const Env env, const Value value, Exp_Call *const exp) { - CHECK_BO(check_call(env, exp)); + CHECK_O(check_call(env, exp)); const Func f = _find_template_match(env, value, exp); if (f) return f; Type t = value->from->owner_class; diff --git a/src/parse/operator.c b/src/parse/operator.c index 1e4b82b7..132fa894 100644 --- a/src/parse/operator.c +++ b/src/parse/operator.c @@ -53,8 +53,8 @@ static m_str type_name(const Type t) { return t ? t == OP_ANY_TYPE ? "any" : t->name : ""; } -static m_bool op_match(const restrict Type t, const restrict Type mo) { - if (t == OP_ANY_TYPE || mo == OP_ANY_TYPE) return GW_OK; +static bool op_match(const restrict Type t, const restrict Type mo) { + if (t == OP_ANY_TYPE || mo == OP_ANY_TYPE) return true; return t == mo; } @@ -246,7 +246,7 @@ ANN static Type op_def(const Env env, struct Op_Import *const opi, op_tmpl_set(env->gwion, tmpl_fdef->base->tmpl->call, opi->rhs, opi->loc, 1); } else op_tmpl_set(env->gwion, tmpl_fdef->base->tmpl->call, opi->rhs, opi->loc, 0); - if (traverse_func_def(env, tmpl_fdef) < 0) { + if (!traverse_func_def(env, tmpl_fdef)) { if (!tmpl_fdef->base->func) func_def_cleaner(env->gwion, tmpl_fdef); return NULL; } @@ -366,19 +366,19 @@ ANN Type op_check(const Env env, struct Op_Import *opi) { return NULL; } -ANN m_bool operator_set_func(const struct Op_Import *opi) { +ANN bool operator_set_func(const struct Op_Import *opi) { const Nspc nspc = ((Func)opi->data)->value_ref->from->owner; const m_int idx = map_index(&nspc->operators->map, (vtype)opi->op); const Vector v = (Vector)&VVAL(&nspc->operators->map, idx); - DECL_OB(M_Operator *, mo, = operator_find(v, opi->lhs, opi->rhs)); + DECL_B(M_Operator *, mo, = operator_find(v, opi->lhs, opi->rhs)); mo->func = (Func)opi->data; - return GW_OK; + return true; } -ANN static m_bool handle_instr(const Emitter emit, const M_Operator *mo) { +ANN static bool handle_instr(const Emitter emit, const M_Operator *mo) { if (mo->func) { emit_pushfunc(emit, mo->func); - CHECK_BB(emit_exp_call1(emit, mo->func, + CHECK_B(emit_exp_call1(emit, mo->func, mo->func->def->base->ret_type->size, true)); if (mo->func->def->base->tag.sym == insert_symbol(emit->gwion->st, "@conditional")) @@ -386,10 +386,10 @@ ANN static m_bool handle_instr(const Emitter emit, const M_Operator *mo) { else if (mo->func->def->base->tag.sym == insert_symbol(emit->gwion->st, "@unconditional")) emit_add_instr(emit, BranchNeqInt); - return GW_OK; + return true; } (void)emit_add_instr(emit, mo->instr); - return GW_OK; + return true; } ANN m_bool op_emit(const Emitter emit, const struct Op_Import *opi) { @@ -412,7 +412,7 @@ ANN m_bool op_emit(const Emitter emit, const struct Op_Import *opi) { const m_bool ret = mo->em(emit, (void *)opi->data); if (ret) return ret; } else if (mo->func || mo->instr) - return handle_instr(emit, mo); + return handle_instr(emit, mo) ? GW_OK : GW_ERROR; } } while (r && (r = op_parent(emit->env, r))); } while (l && (l = op_parent(emit->env, l))); @@ -488,7 +488,7 @@ ANN void op_cpy(const Env env, const struct Op_Import *opi) { vector_release(&visited); } -ANN m_bool add_op_func_check(const Env env, const Type t, const struct Op_Func *opfunc, const m_uint idx) { +ANN bool add_op_func_check(const Env env, const Type t, const struct Op_Func *opfunc, const m_uint idx) { const Func f = (Func)vector_at(&t->nspc->vtable, idx); const struct Op_Import opi = { .rhs = f->value_ref->type, diff --git a/src/parse/partial.c b/src/parse/partial.c index f1acab5f..00d54ea1 100644 --- a/src/parse/partial.c +++ b/src/parse/partial.c @@ -221,7 +221,7 @@ ANN Type partial_type(const Env env, Exp_Call *const call) { Exp* exp = exp_self(call); exp->d.exp_lambda.def = new_func_def(env->gwion->mp, fbase, code); exp->exp_type = ae_exp_lambda; - const m_bool ret = traverse_func_def(env, exp->d.exp_lambda.def); + const bool ret = traverse_func_def(env, exp->d.exp_lambda.def); nspc_pop_value(env->gwion->mp, env->curr); - return ret > 0 ? exp->d.exp_lambda.def->base->func->value_ref->type : NULL; + return ret ? exp->d.exp_lambda.def->base->func->value_ref->type : NULL; } diff --git a/src/parse/scan0.c b/src/parse/scan0.c index 2262cc71..6f844334 100644 --- a/src/parse/scan0.c +++ b/src/parse/scan0.c @@ -28,12 +28,10 @@ ANN static inline bool scan0_defined(const Env env, const Tag tag) { if (nspc_lookup_type1(env->curr, tag.sym)) { // ERR_B(tag.loc, _("type '%s' already defined"), s_name(tag.sym)); env_err(env, tag.loc, _("type '%s' already defined"), s_name(tag.sym)); -puts ("yululuy"); return false; } // return already_defined(env, tag.sym, tag.loc); int ret = already_defined(env, tag.sym, tag.loc); -printf("ret %i\n", ret); return ret; } diff --git a/src/parse/scan2.c b/src/parse/scan2.c index 7cd4a657..ce52bd4c 100644 --- a/src/parse/scan2.c +++ b/src/parse/scan2.c @@ -87,7 +87,7 @@ ANN bool scan2_fptr_def(const Env env NUSED, const Fptr_Def fptr) { const bool ret = scan2_class_def(env, fptr->cdef); const Func_Def fdef = mp_vector_at(fptr->cdef->base.type->info->cdef->body, struct Section_ , 0)->d.func_def; if(fdef->base->func) set_fflag(fdef->base->func, fflag_fptr); - else CHECK_b(tmpl_fptr(env, fptr, fdef)); + else CHECK_B(tmpl_fptr(env, fptr, fdef)); if(GET_FLAG(fptr->cdef, global)) env_pop(env, 0); return ret; } @@ -386,7 +386,7 @@ static bool scan2_fdef_tmpl(const Env env, const Func_Def f, ++i; continue; } - if (compat_func(ff->def, f) > 0) { + if (compat_func(ff->def, f)) { if (ff->value_ref->from->owner == env->curr) ERR_B(f->base->tag.loc, "template function '%s' already defined with those arguments " diff --git a/src/parse/template.c b/src/parse/template.c index bafa91c5..ff53db3e 100644 --- a/src/parse/template.c +++ b/src/parse/template.c @@ -30,7 +30,7 @@ ANN static bool _push_types(const Env env, const Nspc nspc, Specialized *spec = mp_vector_at(sl, Specialized, i); nspc_add_type(nspc, spec->tag.sym, t); }; - if(len != sl->len) return GW_OK; + if(len != sl->len) return true; return tl->len == sl->len; } @@ -101,8 +101,8 @@ else if(spec->tag.sym == targ->d.td->tag.sym) { } } -ANN m_bool const_generic_typecheck(const Env env, const Specialized *spec, const TmplArg *targ) { - CHECK_OB(check_exp(env, targ->d.exp)); +ANN bool const_generic_typecheck(const Env env, const Specialized *spec, const TmplArg *targ) { + CHECK_B(check_exp(env, targ->d.exp)); // check implicits? const Type target = known_type(env, spec->td); if(isa(targ->d.exp->type, target) < 0) { @@ -111,9 +111,9 @@ ANN m_bool const_generic_typecheck(const Env env, const Specialized *spec, const gwerr_basic("invalid type for const generic argument", msg, NULL, env->name, spec->tag.loc, 0); tcol_snprintf(msg, 255, "got {G+}%s{0}", targ->d.exp->type->name); gwerr_secondary(msg, env->name, targ->d.exp->loc); - return GW_ERROR; + return false; } - return GW_OK; + return true; } ANN bool template_push_types(const Env env, const Tmpl *tmpl) { @@ -181,8 +181,15 @@ static ANN bool is_single_variadic(const MP_Vector *v) { return !strcmp(s_name(spec->tag.sym), "..."); } +#undef ERR_B +#define ERR_B(a, b, ...) \ + { \ + env_err(env, (a), (b), ##__VA_ARGS__); \ + return false; \ + } + -ANN2(1,2) m_bool check_tmpl(const Env env, const TmplArg_List tl, const Specialized_List sl, const loc_t loc, const bool is_spread) { +ANN2(1,2) bool check_tmpl(const Env env, const TmplArg_List tl, const Specialized_List sl, const loc_t loc, const bool is_spread) { if (!sl || sl->len > tl->len || (tl->len != sl->len && !is_spread)) ERR_B(loc, "invalid template type number"); for (uint32_t i = 0; i < sl->len; i++) { @@ -215,7 +222,7 @@ ANN2(1,2) m_bool check_tmpl(const Env env, const TmplArg_List tl, const Speciali spec->td ? "constant" : "type"); } - DECL_OB(const Type, t, = known_type(env, targ->d.td)); + DECL_B(const Type, t, = known_type(env, targ->d.td)); if(spec->traits) { Symbol missing = miss_traits(t, spec); if (missing) { @@ -228,10 +235,10 @@ ANN2(1,2) m_bool check_tmpl(const Env env, const TmplArg_List tl, const Speciali ERR_B(loc, "template const argument mismatch. expected %s", spec->td ? "constant" : "type"); } - CHECK_BB(const_generic_typecheck(env, spec, targ)); + CHECK_B(const_generic_typecheck(env, spec, targ)); } } - return GW_OK; + return true; } ANN static Type _scan_type(const Env env, const Type t, Type_Decl *td) { @@ -259,7 +266,7 @@ ANN static Type _scan_type(const Env env, const Type t, Type_Decl *td) { ? tmpl->list : NULL; const bool is_spread = is_spread_tmpl(tmpl); if(!single_variadic) - CHECK_BO(check_tmpl(env, tl, sl, td->tag.loc, is_spread)); + CHECK_O(check_tmpl(env, tl, sl, td->tag.loc, is_spread)); struct Op_Import opi = {.op = insert_symbol("class"), .lhs = t, .data = (uintptr_t)&ts, diff --git a/src/parse/traverse.c b/src/parse/traverse.c index ac3e977d..7ba42c6e 100644 --- a/src/parse/traverse.c +++ b/src/parse/traverse.c @@ -3,69 +3,74 @@ #include "gwion_env.h" #include "traverse.h" -ANN m_bool traverse_ast(const Env env, Ast *const ast) { - CHECK_b(scan0_ast(env, ast)); - CHECK_b(scan1_ast(env, ast)); - CHECK_b(scan2_ast(env, ast)); - return check_ast(env, ast); +ANN bool traverse_ast(const Env env, Ast *const ast) { + CHECK_B(scan0_ast(env, ast)); + CHECK_B(scan1_ast(env, ast)); + CHECK_B(scan2_ast(env, ast)); + CHECK_B(check_ast(env, ast)); + return true; } -ANN m_bool traverse_exp(const Env env, Exp* exp) { - CHECK_b(scan1_exp(env, exp)); - CHECK_b(scan2_exp(env, exp)); - return check_exp(env, exp) ? 1 : -1; +ANN bool traverse_exp(const Env env, Exp* exp) { + CHECK_B(scan1_exp(env, exp)); + CHECK_B(scan2_exp(env, exp)); + CHECK_B(check_exp(env, exp)); + return true; } ANN static m_bool _traverse_func_def(const Env env, const Func_Def fdef) { - CHECK_b(scan0_func_def(env, fdef)); - CHECK_b(scan1_func_def(env, fdef)); - CHECK_b(scan2_func_def(env, fdef)); - return check_func_def(env, fdef); + CHECK_B(scan0_func_def(env, fdef)); + CHECK_B(scan1_func_def(env, fdef)); + CHECK_B(scan2_func_def(env, fdef)); + CHECK_B(check_func_def(env, fdef)); + return true; } -ANN m_bool traverse_func_def(const Env env, const Func_Def fdef) { +ANN bool traverse_func_def(const Env env, const Func_Def fdef) { const Func former = env->func; - const m_bool ret = _traverse_func_def(env, fdef); + const bool ret = _traverse_func_def(env, fdef); env->func = former; return ret; } -ANN m_bool traverse_union_def(const Env env, const Union_Def def) { +ANN bool traverse_union_def(const Env env, const Union_Def def) { // if(!GET_FLAG(def, scan1)) - CHECK_b(scan1_union_def(env, def)); + CHECK_B(scan1_union_def(env, def)); // if(!GET_FLAG(def, scan2)) - CHECK_b(scan2_union_def(env, def)); + CHECK_B(scan2_union_def(env, def)); // if(!GET_FLAG(def, check)) - CHECK_BB(check_union_def(env, def)); - return check_union_def(env, def); + CHECK_B(check_union_def(env, def)); + return true; } -ANN m_bool traverse_enum_def(const Env env, const Enum_Def def) { - CHECK_b(scan0_enum_def(env, def)); - CHECK_b(scan1_enum_def(env, def)); - // CHECK_b(scan2_enum_def(env, def)); - // return check_enum_def(env, def); - return GW_OK; +ANN bool traverse_enum_def(const Env env, const Enum_Def def) { + CHECK_B(scan0_enum_def(env, def)); + CHECK_B(scan1_enum_def(env, def)); + // CHECK_B(scan2_enum_def(env, def)); + // CHECK_B(check_enum_def(env, def)); + return true; } -ANN m_bool traverse_fptr_def(const Env env, const Fptr_Def def) { - CHECK_b(scan0_fptr_def(env, def)); - CHECK_b(scan1_fptr_def(env, def)); - CHECK_b(scan2_fptr_def(env, def)); - return check_fptr_def(env, def); +ANN bool traverse_fptr_def(const Env env, const Fptr_Def def) { + CHECK_B(scan0_fptr_def(env, def)); + CHECK_B(scan1_fptr_def(env, def)); + CHECK_B(scan2_fptr_def(env, def)); + CHECK_B(check_fptr_def(env, def)); + return true; } -ANN m_bool traverse_type_def(const Env env, const Type_Def def) { - CHECK_b(scan0_type_def(env, def)); - CHECK_b(scan1_type_def(env, def)); - CHECK_b(scan2_type_def(env, def)); - return check_type_def(env, def); +ANN bool traverse_type_def(const Env env, const Type_Def def) { + CHECK_B(scan0_type_def(env, def)); + CHECK_B(scan1_type_def(env, def)); + CHECK_B(scan2_type_def(env, def)); + CHECK_B(check_type_def(env, def)); + return true; } -ANN m_bool traverse_class_def(const Env env, const Class_Def def) { +ANN bool traverse_class_def(const Env env, const Class_Def def) { const Type t = def->base.type; - if (!tflag(t, tflag_scan1)) CHECK_b(scan1_class_def(env, def)); - if (!tflag(t, tflag_scan2)) CHECK_b(scan2_class_def(env, def)); - if (!tflag(t, tflag_check)) return check_class_def(env, def); - return GW_OK; + if (!tflag(t, tflag_scan1)) CHECK_B(scan1_class_def(env, def)); + if (!tflag(t, tflag_scan2)) CHECK_B(scan2_class_def(env, def)); + if (!tflag(t, tflag_check)) CHECK_B(check_class_def(env, def)); + return true; } diff --git a/src/parse/type_decl.c b/src/parse/type_decl.c index 3548dbe2..900ecfff 100644 --- a/src/parse/type_decl.c +++ b/src/parse/type_decl.c @@ -87,18 +87,18 @@ ANN static inline Type find(const Env env, Type_Decl *td) { const m_uint scope = env->context ? env_push(env, NULL, env->context->nspc) : env_push_global(env); - const m_bool ret = traverse_fptr_def(env, fptr); + const bool ret = traverse_fptr_def(env, fptr); env_pop(env, scope); const Type t = fptr->cdef->base.type; free_fptr_def(env->gwion->mp, fptr); - return ret > 0 ? t : NULL; + return ret ? t : NULL; } ANN static inline Type find1(const Env env, const Type base, Type_Decl *td) { if (!td->fptr) return scan_type(env, base, td); if (!td->fptr->cdef->base.type) { CHECK_O(scan0_fptr_def(env, td->fptr)); - CHECK_BO(traverse_fptr_def(env, td->fptr)); + CHECK_O(traverse_fptr_def(env, td->fptr)); } return td->fptr->cdef->base.type; } diff --git a/src/pass.c b/src/pass.c index 9d8f0c94..11583d61 100644 --- a/src/pass.c +++ b/src/pass.c @@ -13,7 +13,7 @@ static m_bool typecheck_ast(const Env env, Ast *ast) { env->scope->poison = false; // move me - CHECK_BB(traverse_ast(env, ast)); + CHECK_b(traverse_ast(env, ast)); if(env->scope->poison)env->context->error = true; if(env->context->error)return GW_ERROR; return GW_OK; -- 2.43.0