From: fennecdjay Date: Mon, 12 Feb 2024 18:24:58 +0000 (+0100) Subject: :fire: even more progress X-Git-Tag: nightly~89 X-Git-Url: http://10.10.0.4:5575/?a=commitdiff_plain;h=c30730728b8b770946dde5a8399b96edb9c652c9;p=gwion.git :fire: even more progress --- diff --git a/include/env/func.h b/include/env/func.h index cd90ee93..17db4102 100644 --- a/include/env/func.h +++ b/include/env/func.h @@ -33,7 +33,6 @@ ANEW ANN Func new_func(MemPool, const m_str, const Func_Def); ANN2(1, 2) Symbol func_symbol(const Env, const m_str, const m_str, const m_str, const m_uint); -ANN m_bool check_lambda(const Env, const Type, Exp_Lambda *); ANN Type check_op_call(const Env env, Exp_Call *const exp); ANN void builtin_func(const Gwion gwion, const Func f, void *func_ptr); diff --git a/src/lib/closure.c b/src/lib/closure.c index 90498dba..d5f6e9f1 100644 --- a/src/lib/closure.c +++ b/src/lib/closure.c @@ -176,41 +176,41 @@ ANN static void _fptr_tmpl_push(const Env env, const Func f) { } } -ANN static m_bool fptr_tmpl_push(const Env env, struct FptrInfo *info) { - if (!info->rhs->def->base->tmpl) return GW_OK; +ANN static bool fptr_tmpl_push(const Env env, struct FptrInfo *info) { + if (!info->rhs->def->base->tmpl) return true; nspc_push_type(env->gwion->mp, env->curr); _fptr_tmpl_push(env, info->rhs); - return GW_OK; + return true; } -static m_bool td_match(const Env env, Type_Decl *id[2]) { - DECL_OB(const Type, t0, = known_type(env, id[0])); - DECL_OB(const Type, t1, = known_type(env, id[1])); - if (isa(t0, t1) > 0) return GW_OK; - return t1 == env->gwion->type[et_auto] ? GW_OK : GW_ERROR; +static bool td_match(const Env env, Type_Decl *id[2]) { + DECL_B(const Type, t0, = known_type(env, id[0])); + DECL_B(const Type, t1, = known_type(env, id[1])); + if (isa(t0, t1) > 0) return true; + return t1 == env->gwion->type[et_auto]; } -ANN static m_bool fptr_args(const Env env, Func_Base *base[2]) { +ANN static bool fptr_args(const Env env, Func_Base *base[2]) { Arg_List args0 = base[0]->args, args1 = base[1]->args; const bool member = vflag(base[0]->func->value_ref, vflag_member); const uint32_t len0 = mp_vector_len(args0) + member; const uint32_t len1 = mp_vector_len(args1); - if(len0 != len1) return GW_ERROR; + if(len0 != len1) return false; if(member) { const Arg *arg = mp_vector_at(args1, Arg, 0); - CHECK_BB(isa(base[0]->func->value_ref->from->owner_class, arg->type)); + CHECK_B(isa(base[0]->func->value_ref->from->owner_class, arg->type)); } for(uint32_t i = member; i < len0; i++) { const Arg *arg0 = mp_vector_at(args0, Arg, (i - member)); const Arg *arg1 = mp_vector_at(args1, Arg, i); if (arg0->type && arg1->type) - CHECK_BB(isa(arg0->type, arg1->type)); + CHECK_B(isa(arg0->type, arg1->type)); else if(!tmpl_base(base[0]->tmpl) && !tmpl_base(base[1]->tmpl)){ Type_Decl *td[2] = {arg0->var.td, arg1->var.td}; - CHECK_BB(td_match(env, td)); + CHECK_B(td_match(env, td)); } } - return GW_OK; + return true; } ANN static bool fptr_effects(const Env env, struct FptrInfo *info) { @@ -230,16 +230,16 @@ ANN static bool fptr_effects(const Env env, struct FptrInfo *info) { return true; } -ANN static m_bool fptr_check(const Env env, struct FptrInfo *info) { +ANN static bool fptr_check(const Env env, struct FptrInfo *info) { // if(!info->lhs->def->base->tmpl != !info->rhs->def->base->tmpl) // return GW_ERROR; if(!info->lhs) - ERR_B(info->exp->loc, + ERR_b(info->exp->loc, _("can't resolve operator")) - return GW_OK; + return true; } -ANN static inline m_bool fptr_rettype(const Env env, struct FptrInfo *info) { +ANN static inline bool fptr_rettype(const Env env, struct FptrInfo *info) { Type_Decl *td[2] = {info->lhs->def->base->td, info->rhs->def->base->td}; return td_match(env, td); } @@ -266,9 +266,9 @@ ANN static Type fptr_type(const Env env, struct FptrInfo *info) { } Type type = NULL; Func_Base *base[2] = {info->lhs->def->base, info->rhs->def->base}; - CHECK_BO(fptr_tmpl_push(env, info)); - if (fptr_rettype(env, info) > 0 && - fptr_args(env, base) > 0 && fptr_effects(env, info)) + CHECK_O(fptr_tmpl_push(env, info)); + if (fptr_rettype(env, info) && + fptr_args(env, base) && fptr_effects(env, info)) type = actual_type(env->gwion, info->lhs->value_ref->type) ?: info->lhs->value_ref->type; if (info->rhs->def->base->tmpl) nspc_pop_type(env->gwion->mp, env->curr); @@ -277,7 +277,14 @@ ANN static Type fptr_type(const Env env, struct FptrInfo *info) { return NULL; } -ANN static m_bool _check_lambda(const Env env, Exp_Lambda *l, +#undef ERR_B +#define ERR_B(a, b, ...) \ + { \ + env_err(env, (a), (b), ##__VA_ARGS__); \ + return false; \ + } + +ANN static bool _check_lambda(const Env env, Exp_Lambda *l, const Func_Def fdef) { Arg_List bases = fdef->base->args; Arg_List args = l->def->base->args; @@ -290,7 +297,7 @@ ANN static m_bool _check_lambda(const Env env, Exp_Lambda *l, Capture *cap = mp_vector_at(l->def->captures, Capture, i); const Value v = nspc_lookup_value1(env->curr, cap->var.tag.sym); if(!v) ERR_B(cap->var.tag.loc, _("unknown value in capture")); - DECL_OB(const Type, t, = upvalue_type(env, cap)); + DECL_B(const Type, t, = upvalue_type(env, cap)); cap->temp = new_value(env, t, cap->var.tag); cap->var.value = v; } @@ -313,11 +320,11 @@ ANN static m_bool _check_lambda(const Env env, Exp_Lambda *l, for(uint32_t i = 0; i < bases->len; i++) { Arg *base = mp_vector_at(bases, Arg, i); Arg *arg = mp_vector_at(args, Arg, i); - DECL_OB(const Type, arg_type, = known_type(env, base->var.td)); + DECL_B(const Type, arg_type, = known_type(env, base->var.td)); arg->var.td = type2td(env->gwion, arg_type, exp_self(l)->loc); } } - DECL_OB(const Type, ret_type, = known_type(env, fdef->base->td)); + DECL_B(const Type, ret_type, = known_type(env, fdef->base->td)); l->def->base->td = type2td(env->gwion, ret_type, exp_self(l)->loc); /*Type*/ owner = fdef->base->func->value_ref->from->owner_class; @@ -360,19 +367,19 @@ ANN static m_bool _check_lambda(const Env env, Exp_Lambda *l, return ret; } -ANN m_bool check_lambda(const Env env, const Type t, Exp_Lambda *l) { +ANN static bool check_lambda(const Env env, const Type t, Exp_Lambda *l) { const Func_Def fdef = t->info->func->def; - CHECK_BB(_check_lambda(env, l, fdef)); + CHECK_B(_check_lambda(env, l, fdef)); exp_self(l)->type = l->def->base->func->value_ref->type; - return GW_OK; + return true; } -ANN static m_bool fptr_do(const Env env, struct FptrInfo *info) { +ANN static bool fptr_do(const Env env, struct FptrInfo *info) { if(info->exp->type->info->func) { - CHECK_BB(fptr_check(env, info)); + CHECK_B(fptr_check(env, info)); if (!(info->exp->type = fptr_type(env, info))) - ERR_B(info->exp->loc, _("no match found")) - return GW_OK; + ERR_b(info->exp->loc, _("no match found")) + return true; } Exp_Lambda *l = &info->exp->d.exp_lambda; return check_lambda(env, actual_type(env->gwion, info->rhs->value_ref->type), l); @@ -429,7 +436,7 @@ static OP_CHECK(opck_fptr_assign) { struct FptrInfo info = {.lhs = bin->lhs->type->info->func, .rhs = rhs->base->func, .exp = bin->lhs}; - CHECK_BN(fptr_do(env, &info)); + CHECK_ON(fptr_do(env, &info)); return bin->rhs->type; } @@ -439,7 +446,7 @@ static OP_CHECK(opck_fptr_impl) { struct FptrInfo info = {.lhs = impl->e->type->info->func, .rhs = f, .exp = impl->e}; - CHECK_BN(fptr_do(env, &info)); + CHECK_ON(fptr_do(env, &info)); return impl->t; } @@ -462,7 +469,7 @@ static OP_CHECK(opck_fptr_cast) { struct FptrInfo info = {.lhs = cast->exp->type->info->func, .rhs = f, .exp = cast->exp}; - CHECK_BN(fptr_do(env, &info)); + CHECK_ON(fptr_do(env, &info)); return t; } @@ -475,19 +482,19 @@ static void op_narg_err(const Env env, const Func_Def fdef, const loc_t loc) { env_set_error(env, true); } } -static m_bool op_call_narg(const Env env, Exp* arg, const loc_t loc) { +static bool op_call_narg(const Env env, Exp* arg, const loc_t loc) { m_uint narg = 0; while (arg) { narg++; arg = arg->next; } - if (narg == 2) return GW_OK; + if (narg == 2) return true; op_narg_err(env, NULL, loc); - return GW_ERROR; + return false; } ANN Type check_op_call(const Env env, Exp_Call *const exp) { - CHECK_BO(op_call_narg(env, exp->args, exp->func->loc)); + CHECK_O(op_call_narg(env, exp->args, exp->func->loc)); Exp* base = exp_self(exp); Exp* op_exp = exp->func; base->exp_type = ae_exp_binary; @@ -500,11 +507,11 @@ ANN Type check_op_call(const Env env, Exp_Call *const exp) { return check_exp(env, base); } -static m_bool op_impl_narg(const Env env, const Func_Def fdef, +static bool op_impl_narg(const Env env, const Func_Def fdef, const loc_t loc) { - if (mp_vector_len(fdef->base->args) == 2) return GW_OK; + if (mp_vector_len(fdef->base->args) == 2) return true; op_narg_err(env, fdef, loc); - return GW_ERROR; + return false; } static inline void op_impl_ensure_types(const Env env, const Func func) { @@ -538,7 +545,7 @@ static OP_EMIT(opem_op_impl) { static OP_CHECK(opck_op_impl) { struct Implicit *impl = (struct Implicit *)data; const Func func = closure_def(impl->t)->base->func; - CHECK_BN(op_impl_narg(env, func->def, impl->e->loc)); + CHECK_ON(op_impl_narg(env, func->def, impl->e->loc)); op_impl_ensure_types(env, func); const Symbol lhs_sym = insert_symbol("@lhs"); const Symbol rhs_sym = insert_symbol("@rhs"); @@ -616,7 +623,7 @@ static OP_CHECK(opck_op_impl) { // or better, some function with envset and traverse const m_uint scope = env_push(env, NULL, opi.nspc); // we assume succes here - /*const m_bool ret = */ traverse_func_def(env, def); + /*const bool ret = */ traverse_func_def(env, def); env_pop(env, scope); def->base->func->value_ref->type->info->parent = env->gwion->type[et_op]; impl->e->type = def->base->func->value_ref->type; diff --git a/src/parse/check.c b/src/parse/check.c index ab9363a2..b69c06e6 100644 --- a/src/parse/check.c +++ b/src/parse/check.c @@ -170,10 +170,10 @@ ANN static inline bool inferable(const Env env, const Type t, ANN Type check_exp_decl(const Env env, Exp_Decl *const decl) { if (decl->var.td->array && decl->var.td->array->exp) - CHECK_OO(check_exp(env, decl->var.td->array->exp)); + CHECK_O(check_exp(env, decl->var.td->array->exp)); if (decl->args) { Exp* e = new_exp_unary2(env->gwion->mp, insert_symbol("new"), cpy_type_decl(env->gwion->mp, decl->var.td), decl->args, decl->var.td->tag.loc); - CHECK_OO(check_exp(env, e)); + CHECK_O(check_exp(env, e)); decl->args = e; e->ref = exp_self(decl); } @@ -235,7 +235,7 @@ ANN static Type check_prim_array(const Env env, const Array_Sub *data) { Exp* e = array->exp; if (!e) ERR_O(prim_pos(data), _("must provide values/expressions for array [...]")) - CHECK_OO(check_exp(env, e)); + CHECK_O(check_exp(env, e)); env_weight(env, 1); return array->type = prim_array_match(env, e); } @@ -266,7 +266,7 @@ ANN static Type check_prim_range(const Env env, Range **data) { ANN static Type check_prim_dict(const Env env, Exp* *data) { Exp* base = *data; - CHECK_OO(check_exp(env, base)); + CHECK_O(check_exp(env, base)); const Type key = base->type; const Type val = base->next->type; bool err = false; @@ -316,9 +316,9 @@ return value; } } if (env->func && env->func->def->base->values) { - DECL_OO(const Value, v, = upvalues_lookup(env->func->def->base->values, sym)); + DECL_O(const Value, v, = upvalues_lookup(env->func->def->base->values, sym)); if(fbflag(env->func->def->base, fbflag_lambda)) - CHECK_OO(not_upvalue(env, v)); + CHECK_O(not_upvalue(env, v)); return v; } return NULL; @@ -481,14 +481,14 @@ ANN static Type check_prim_perform(const Env env, const Symbol *data) { } ANN static Type check_prim_interp(const Env env, Exp* *exp) { - CHECK_OO(check_exp(env, *exp)); + CHECK_O(check_exp(env, *exp)); env_weight(env, 1); return env->gwion->type[et_string]; } ANN static Type check_prim_hack(const Env env, Exp* *data) { if (env->func) unset_fflag(env->func, fflag_pure); - CHECK_OO(check_prim_interp(env, data)); + CHECK_O(check_prim_interp(env, data)); env_weight(env, 1); return env->gwion->type[et_gack]; } @@ -526,14 +526,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_O((array->array->type = check_exp(env, array->base))); 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_O(check_exp(env, range->base)); CHECK_O(check_range(env, range->range)); env_weight(env, 1); const Symbol sym = insert_symbol("[:]"); @@ -599,7 +599,7 @@ static Func find_func_match_actual(const Env env, const Func f, Exp* exp, return NULL; Arg *arg = i < args_len ? mp_vector_at(args, Arg, i++) : NULL; if (!arg) { - CHECK_OO(func->next); + CHECK_O(func->next); return find_func_match_actual(env, func->next, exp, implicit, specific); } @@ -612,7 +612,7 @@ static Func find_func_match_actual(const Env env, const Func f, Exp* exp, if (owner) CHECK_O(template_push(env, owner)); arg->type = known_type(env, arg->var.td); if (owner) nspc_pop_type(env->gwion->mp, env->curr); - CHECK_OO(arg->type); + CHECK_O(arg->type); } if (!func_match_inner(env, e, arg->type, implicit, specific)) break; @@ -634,7 +634,7 @@ ANN static Func call2ufcs(const Env env, Exp_Call *call, const Value v) { call->func->d.prim.d.var = call->func->d.exp_dot.xid; call->func->exp_type = ae_exp_primary; call->func->d.prim.prim_type = ae_prim_id; - CHECK_OO(check_exp_call(env, call)); + CHECK_O(check_exp_call(env, call)); return call->func->type->info->func; } @@ -742,13 +742,13 @@ ANN static Func predefined_func(const Env env, const Value v, Exp_Call *exp, const Tmpl *tm) { Tmpl tmpl = {.call = tm->call}; exp->tmpl = &tmpl; - DECL_OO(const Func, func, = get_template_func(env, exp, v)); + DECL_O(const Func, func, = get_template_func(env, exp, v)); return v->d.func_ref = func; } ANN static Type check_predefined(const Env env, Exp_Call *exp, const Value v, const Tmpl *tm, const Func_Def fdef) { - DECL_OO(const Func, func, + DECL_O(const Func, func, = v->d.func_ref ?: predefined_func(env, v, exp, tm)); if (!fdef->base->ret_type) { // template fptr struct EnvSet es = {.env = env, @@ -779,7 +779,7 @@ ANN static TmplArg_List check_template_args(const Env env, Exp_Call *exp, for(uint32_t i = 0; i < len; i++) { Specialized *spec = mp_vector_at(sl, Specialized, i); if (tmplarg_match(env, spec->tag.sym, fdef->base->td->tag.sym, fdef->base->ret_type)) { - CHECK_OO(check_exp(env, exp->other)); + CHECK_O(check_exp(env, exp->other)); if(!is_func(env->gwion, exp->other->type)) { TmplArg targ = { .type = tmplarg_td, @@ -851,15 +851,15 @@ ANN static Type check_exp_call_template(const Env env, Exp_Call *exp) { const Func_Def fdef = closure_def(t); t = fdef->base->func->value_ref->type; } - DECL_OO(const Value, value, = type_value(env->gwion, t)); + DECL_O(const Value, value, = type_value(env->gwion, t)); const Func_Def fdef = value->d.func_ref ? value->d.func_ref->def : t->info->func->def; Tmpl *tm = fdef->base->tmpl; if (tm->call) return check_predefined(env, exp, value, tm, fdef); - DECL_OO(const TmplArg_List, tl, = check_template_args(env, exp, tm, fdef)); + DECL_O(const TmplArg_List, tl, = check_template_args(env, exp, tm, fdef)); Tmpl tmpl = {.call = tl}; ((Exp_Call *)exp)->tmpl = &tmpl; - DECL_OO(const Func, func, = get_template_func(env, exp, value)); + DECL_O(const Func, func, = get_template_func(env, exp, value)); return func->def->base->ret_type != env->gwion->type[et_auto] ? func->def->base->ret_type : exp->func->d.exp_dot.base->type; } @@ -1020,12 +1020,12 @@ ANN static Type call_return(const Env env, Exp_Call *const exp, } ANN Type _check_exp_call1(const Env env, Exp_Call *const exp) { - DECL_OO(const Type, t, = call_type(env, exp)); + DECL_O(const Type, t, = call_type(env, exp)); if (t == env->gwion->type[et_op]) return check_op_call(env, exp); if (!t->info->func) // TODO: effects? return check_lambda_call(env, exp); if (exp->args) { - CHECK_OO(check_exp(env, exp->args)); + CHECK_O(check_exp(env, exp->args)); Exp* e = exp->args; do exp_setuse(e, true); while((e = e->next)); @@ -1054,7 +1054,7 @@ ANN Type check_exp_call1(const Env env, Exp_Call *const exp) { 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)); + CHECK_O(check_static(env, exp->func)); const Type _ret = _check_exp_call1(env, exp); if(_ret) return _ret; if(isa(exp->func->type, env->gwion->type[et_closure]) > 0) { @@ -1073,11 +1073,11 @@ ANN Type check_exp_call1(const Env env, Exp_Call *const exp) { ANN static Type check_exp_binary(const Env env, const Exp_Binary *bin) { if(bin->lhs->exp_type == ae_exp_call && !bin->lhs->d.exp_call.tmpl) { - CHECK_OO(check_exp(env, bin->lhs->d.exp_call.func)); + CHECK_O(check_exp(env, bin->lhs->d.exp_call.func)); // check is template? bin->lhs->d.exp_call.other = bin->rhs; } - CHECK_OO(check_exp(env, bin->lhs)); + CHECK_O(check_exp(env, bin->lhs)); 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]; @@ -1101,7 +1101,7 @@ ANN static Type check_exp_binary(const Env env, const Exp_Binary *bin) { } if(bin->rhs->exp_type == ae_exp_call && !bin->rhs->d.exp_call.tmpl) bin->rhs->d.exp_call.other = bin->lhs; - CHECK_OO(check_exp(env, bin->rhs)); + CHECK_O(check_exp(env, bin->rhs)); if (is_auto) { assert(bin->rhs->type == bin->lhs->type); set_vflag(bin->rhs->d.exp_decl.var.vd.value, vflag_assigned); @@ -1120,8 +1120,8 @@ ANN static Type check_exp_binary(const Env env, const Exp_Binary *bin) { } ANN static Type check_exp_cast(const Env env, const Exp_Cast *cast) { - DECL_OO(const Type, t, = check_exp(env, cast->exp)); - CHECK_OO((exp_self(cast)->type = known_type(env, cast->td))); + DECL_O(const Type, t, = check_exp(env, cast->exp)); + CHECK_O((exp_self(cast)->type = known_type(env, cast->td))); struct Op_Import opi = {.op = insert_symbol("$"), .lhs = t, .rhs = exp_self(cast)->type, @@ -1135,7 +1135,7 @@ ANN static Type check_exp_post(const Env env, const Exp_Postfix *post) { .lhs = check_exp(env, post->exp), .data = (uintptr_t)post, .loc = exp_self(post)->loc}; - CHECK_OO(opi.lhs); + CHECK_O(opi.lhs); exp_setuse(post->exp, 1); const Type t = op_check(env, &opi); if (t && isa(t, env->gwion->type[et_object]) < 0) @@ -1180,7 +1180,7 @@ ANN static bool tl_match(const Env env, const TmplArg_List tl0, const TmplArg_Li } ANN static Type check_exp_call_tmpl(const Env env, Exp_Call *exp, const Type t) { - if (exp->args) CHECK_OO(check_exp(env, exp->args)); + if (exp->args) CHECK_O(check_exp(env, exp->args)); if (!t->info->func->def->base->tmpl) ERR_O(exp_self(exp)->loc, _("template call of non-template function.")) if (t->info->func->def->base->tmpl->call) { @@ -1194,14 +1194,14 @@ ANN static Type check_exp_call_tmpl(const Env env, Exp_Call *exp, const Type t) } } const Value v = type_value(env->gwion, t); - DECL_OO(const Func, f, = find_template_match(env, v, exp)); + DECL_O(const Func, f, = find_template_match(env, v, exp)); exp->func->type = f->value_ref->type; return f->def->base->ret_type; } ANN static Type check_exp_call(const Env env, Exp_Call *exp) { if (is_partial(env, exp->args)) { - CHECK_OO(check_exp(env, exp->func)); + CHECK_O(check_exp(env, exp->func)); struct Op_Import opi = {.op = insert_symbol("@partial"), .lhs = exp->func->type, .loc = exp->func->loc, @@ -1229,19 +1229,19 @@ ANN static Type check_exp_unary(const Env env, const Exp_Unary *unary) { const Type rhs = unary->unary_type == unary_exp ? check_exp(env, unary->exp) : NULL; if (unary->unary_type == unary_exp) { - CHECK_OO(rhs); + CHECK_O(rhs); exp_setuse(unary->exp, 1); } struct Op_Import opi = {.op = unary->op, .rhs = rhs, .data = (uintptr_t)unary, .loc = exp_self(unary)->loc}; - DECL_OO(const Type, ret, = op_check(env, &opi)); + DECL_O(const Type, ret, = op_check(env, &opi)); return ret; } ANN static Type _flow(const Env env, Exp* e, const bool b) { - DECL_OO(const Type, type, = check_exp(env, e)); + DECL_O(const Type, type, = check_exp(env, e)); struct Op_Import opi = { .op = insert_symbol(b ? "@conditional" : "@unconditional"), .rhs = type, @@ -1257,9 +1257,9 @@ ANN static Type check_exp_if(const Env env, Exp_If *const exp_if) { scan1_exp(env, e); scan2_exp(env, e); } - DECL_OO(const Type, cond, = check_flow(env, exp_if->cond)); - DECL_OO(const Type, if_exp, = check_exp(env, exp_if->if_exp)); - DECL_OO(const Type, else_exp, = check_exp(env, exp_if->else_exp)); + DECL_O(const Type, cond, = check_flow(env, exp_if->cond)); + DECL_O(const Type, if_exp, = check_exp(env, exp_if->if_exp)); + DECL_O(const Type, else_exp, = check_exp(env, exp_if->else_exp)); const uint meta = exp_getmeta(exp_if->if_exp) || exp_getmeta(exp_if->else_exp); @@ -1279,7 +1279,7 @@ ANN static Type check_exp_if(const Env env, Exp_If *const exp_if) { } ANN static Type check_exp_dot(const Env env, Exp_Dot *member) { - CHECK_OO(check_exp(env, member->base)); + CHECK_O(check_exp(env, member->base)); return check_dot(env, member); } @@ -1336,7 +1336,7 @@ ANN static Type check_exp_lambda(const Env env, const Exp_If *exp_if NUSED) { } ANN static Type check_exp_td(const Env env, Type_Decl **td) { - DECL_OO(const Type, t, = known_type(env, *td)); + DECL_O(const Type, t, = known_type(env, *td)); if(t == env->gwion->type[et_class]) ERR_O(exp_self(td)->loc, "can't use {G+}Class{0} in type decl expression"); if (!is_func(env->gwion, t)) return type_class(env->gwion, t); @@ -1422,7 +1422,7 @@ ANN static bool check_each_idx(const Env env, Exp* exp, struct EachIdx_ *const i .data = (m_uint)exp, .loc = idx->var.tag.loc }; - DECL_OB(const Type, t, = op_check(env, &opi)); + DECL_B(const Type, t, = op_check(env, &opi)); check_idx(env, t, idx); return GW_OK; } @@ -1443,7 +1443,7 @@ ANN static bool do_stmt_each(const Env env, const Stmt_Each stmt) { CHECK_B(check_exp(env, stmt->exp)); if (stmt->idx) CHECK_B(check_each_idx(env, stmt->exp, stmt->idx)); - DECL_OB(const Type, ret, = check_each_val(env, stmt->exp)); + DECL_B(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); @@ -1497,7 +1497,7 @@ ANN static bool check_stmt_return(const Env env, const Stmt_Exp stmt) { _("'return' statement inside constructor function should have no expression")) return GW_OK; } - DECL_OB(const Type, ret_type, + DECL_B(const Type, ret_type, = stmt->val ? check_exp(env, stmt->val) : env->gwion->type[et_void]); if (!env->func->def->base->ret_type) { env->func->def->base->ret_type = ret_type; @@ -1959,9 +1959,9 @@ ANN bool _check_func_def(const Env env, const Func_Def f) { if (tmpl_base(fdef->base->tmpl)) return GW_OK; Value override = NULL; CHECK_B(check_func_def_override(env, fdef, &override)); - DECL_BB(const m_int, scope, = GET_FLAG(fdef->base, global) + const m_int scope = GET_FLAG(fdef->base, global) ? env_push_global(env) - : env->scope->depth); + : env->scope->depth; const Func former = env->func; env->func = func; nspc_push_value(env->gwion->mp, env->curr); diff --git a/src/parse/func_resolve_tmpl.c b/src/parse/func_resolve_tmpl.c index 1eb7b549..2e29fd24 100644 --- a/src/parse/func_resolve_tmpl.c +++ b/src/parse/func_resolve_tmpl.c @@ -98,7 +98,7 @@ ANN static Func tmpl_exists(const Env env, struct ResolverArgs *ra, ANN static Func create_tmpl(const Env env, struct ResolverArgs *ra, const m_uint i) { - DECL_OO(const Value, value, = template_get_ready(env, ra->v, "template", i)); + DECL_O(const Value, value, = template_get_ready(env, ra->v, "template", i)); if (value->d.func_ref->def->builtin) set_vflag(value, vflag_builtin); const Func_Def fdef = cpy_func_def(env->gwion->mp, value->d.func_ref->def); fdef->base->tmpl->call = cpy_tmplarg_list(env->gwion->mp, ra->types); @@ -175,7 +175,7 @@ ANN static Func find_tmpl(const Env env, const Value v, Exp_Call *const exp, ANN static Func __find_template_match(const Env env, const Value v, Exp_Call *const exp) { - DECL_OO(const m_str, tmpl_name, + DECL_O(const m_str, tmpl_name, = tl2str(env->gwion, exp->tmpl->call, exp->func->loc)); const Func f = find_tmpl(env, v, exp, tmpl_name); free_mstr(env->gwion->mp, tmpl_name); @@ -184,7 +184,7 @@ ANN static Func __find_template_match(const Env env, const Value v, ANN static Func _find_template_match(const Env env, const Value v, Exp_Call *const exp) { - DECL_OO(const Func, f, = __find_template_match(env, v, exp)); + DECL_O(const Func, f, = __find_template_match(env, v, exp)); TmplArg_List tl = exp->tmpl->call; Specialized_List sl = f->def->base->tmpl->list; for(uint32_t i = 0; i < tl->len; i++) { @@ -202,7 +202,7 @@ ANN static Func _find_template_match(const Env env, const Value v, // check argument in call exp? continue; } - DECL_OO(const Type, t, = known_type(env, arg.d.td)); + DECL_O(const Type, t, = known_type(env, arg.d.td)); if(t->info->traits && miss_traits(t, spec)) return NULL; } diff --git a/src/parse/partial.c b/src/parse/partial.c index 00d54ea1..5db510d7 100644 --- a/src/parse/partial.c +++ b/src/parse/partial.c @@ -92,9 +92,9 @@ ANN Func find_match(const Env env, Func func, Exp* exp, const bool implicit, e->next = NULL; const Type ret = check_exp(env, e); e->next = next; - CHECK_OO(ret); + CHECK_O(ret); } else - CHECK_OO((e->type = known_type(env, e->d.exp_cast.td))); + CHECK_O((e->type = known_type(env, e->d.exp_cast.td))); if (!func_match_inner(env, e, arg->type, implicit, specific)) break; } e = e->next; diff --git a/src/parse/template.c b/src/parse/template.c index ff53db3e..4f57fdb2 100644 --- a/src/parse/template.c +++ b/src/parse/template.c @@ -130,7 +130,7 @@ ANN Tmpl *mk_tmpl(const Env env, const Tmpl *tm, const TmplArg_List types) { } static ANN Type scan_func(const Env env, const Type t, const Type_Decl *td) { - DECL_OO(const m_str, tl_name, = tl2str(env->gwion, td->types, td->tag.loc)); + DECL_O(const m_str, tl_name, = tl2str(env->gwion, td->types, td->tag.loc)); const Symbol sym = func_symbol(env, t->info->value->from->owner->name, t->info->func->name, tl_name, 0); free_mstr(env->gwion->mp, tl_name); @@ -281,10 +281,10 @@ ANN Type scan_type(const Env env, const Type t, Type_Decl *td) { if (td->next) { Type_Decl *next = td->next; td->next = NULL; - DECL_OO(const Type, maybe_array, = known_type(env, td)); + DECL_O(const Type, maybe_array, = known_type(env, td)); const Type owner = array_base_simple(maybe_array); td->next = next; - CHECK_OO(owner); + CHECK_O(owner); if (!owner->nspc) ERR_O(td->tag.loc, "type '%s' has no namespace", owner->name) struct EnvSet es = {.env = env, .data = env, diff --git a/src/parse/type_decl.c b/src/parse/type_decl.c index 900ecfff..287a584e 100644 --- a/src/parse/type_decl.c +++ b/src/parse/type_decl.c @@ -51,8 +51,8 @@ ANN static Symbol symname(const Env env, Func_Base *const base, bool *global) { GwText text; text_init(&text, env->gwion->mp); text_add(&text, "("); - DECL_OO(const Type, t, = known_type(env, base->td)); - DECL_OO(const m_str, name, = type2str(env->gwion, t, base->td->tag.loc)); + DECL_O(const Type, t, = known_type(env, base->td)); + DECL_O(const m_str, name, = type2str(env->gwion, t, base->td->tag.loc)); text_add(&text, name); free_mstr(env->gwion->mp, name); text_add(&text, "("); @@ -61,8 +61,8 @@ ANN static Symbol symname(const Env env, Func_Base *const base, bool *global) { for(uint32_t i = 0; i < base->args->len; i++) { if(i) text_add(&text, ","); Arg *arg = mp_vector_at(base->args, Arg, i); - DECL_OO(const Type, t, = known_type(env, arg->var.td)); - DECL_OO(const m_str, name, = type2str(env->gwion, t, arg->var.td->tag.loc)); + DECL_O(const Type, t, = known_type(env, arg->var.td)); + DECL_O(const m_str, name, = type2str(env->gwion, t, arg->var.td->tag.loc)); text_add(&text, name); free_mstr(env->gwion->mp, name); if(*global) @@ -79,7 +79,7 @@ ANN static Symbol symname(const Env env, Func_Base *const base, bool *global) { ANN static inline Type find(const Env env, Type_Decl *td) { if (!td->fptr) return find_type(env, td); bool global = false; - CHECK_OO((td->tag.sym = symname(env, td->fptr->base, &global))); + CHECK_O((td->tag.sym = symname(env, td->fptr->base, &global))); const Fptr_Def fptr = td->fptr; td->fptr = NULL; const Type exists = find_type(env, td); @@ -106,12 +106,12 @@ ANN static inline Type find1(const Env env, const Type base, Type_Decl *td) { ANN static Type resolve(const Env env, Type_Decl *td) { Type_Decl *last = td; while (last->next) last = last->next; - DECL_OO(const Type, base, = find(env, td)); + DECL_O(const Type, base, = find(env, td)); const Context ctx = base->info->value->from->ctx; if (ctx && ctx->error) ERR_O(td->tag.loc, _("type '%s' is invalid"), base->name) - DECL_OO(const Type, type, = find1(env, base, td)); - DECL_OO(const Type, t, = !td->ref ? type : ref(env, td)); - DECL_OO(const Type, ret, = !td->option ? t : option(env, td)); + DECL_O(const Type, type, = find1(env, base, td)); + DECL_O(const Type, t, = !td->ref ? type : ref(env, td)); + DECL_O(const Type, ret, = !td->option ? t : option(env, td)); const Array_Sub array = last->array; return !array ? ret : array_type(env, ret, array->depth, td->tag.loc); }