From c317110a12cbffe08996341825c629db116719a6 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=A9mie=20Astor?= Date: Mon, 26 Jul 2021 12:23:48 +0200 Subject: [PATCH] :allow curry --- ast | 2 +- src/lib/lib_func.c | 1 + src/lib/opfunc.c | 14 +++++++++----- src/parse/check.c | 2 +- 4 files changed, 12 insertions(+), 7 deletions(-) diff --git a/ast b/ast index 440d41a1..45c938d4 160000 --- a/ast +++ b/ast @@ -1 +1 @@ -Subproject commit 440d41a1a4ecc73788ffb74ef0558ce99fda6c6f +Subproject commit 45c938d4ea5b0c768e1ea9eae671f9c49eaacc08 diff --git a/src/lib/lib_func.c b/src/lib/lib_func.c index bf7c6332..ba782e4b 100644 --- a/src/lib/lib_func.c +++ b/src/lib/lib_func.c @@ -16,6 +16,7 @@ static OP_CHECK(opck_func_call) { Exp_Binary *bin = (Exp_Binary *)data; Exp_Call call = {.func = bin->rhs, .args = bin->lhs}; + call.allow_curry = true; Exp e = exp_self(bin); e->exp_type = ae_exp_call; memcpy(&e->d.exp_call, &call, sizeof(Exp_Call)); diff --git a/src/lib/opfunc.c b/src/lib/opfunc.c index cd3ee0d0..79b6c091 100644 --- a/src/lib/opfunc.c +++ b/src/lib/opfunc.c @@ -99,6 +99,12 @@ ANN Type check_td(const Env env, Type_Decl *td); OP_CHECK(opck_new) { Exp_Unary *unary = (Exp_Unary *)data; DECL_ON(const Type, t, = known_type(env, unary->ctor.td)); + if (type_ref(t)) + ERR_N(unary->ctor.td->pos, _("can't use 'new' on ref type '%s'\n"), t->name); + if (tflag(t, tflag_infer)) + ERR_N(unary->ctor.td->pos, _("can't use 'new' on '%s'\n"), + t->name); + if (unary->ctor.td->array) CHECK_BN(check_subscripts(env, unary->ctor.td->array, 1)); if(unary->ctor.exp) { const Exp self = exp_self(unary); const Exp args = cpy_exp(env->gwion->mp, unary->ctor.exp); @@ -108,19 +114,17 @@ base->type = t; self->d.exp_call.func = func; self->d.exp_call.args = args; self->d.exp_call.tmpl = NULL; + self->d.exp_call.allow_curry = 0; self->exp_type = ae_exp_call; CHECK_BN(traverse_exp(env, self)); return self->type; // unarytype } - if (isa(t, env->gwion->type[et_object]) < 0) - ERR_N(exp_self(unary)->pos, _("can't use 'new' on non-object types...\n")); - if (type_ref(t)) - ERR_N(unary->ctor.td->pos, _("can't use 'new' on ref type '%s'\n"), t->name); if (GET_FLAG(t, abstract)) ERR_N(unary->ctor.td->pos, _("can't use 'new' on abstract type '%s'\n"), t->name); - if (unary->ctor.td->array) CHECK_BN(check_subscripts(env, unary->ctor.td->array, 1)); + if (isa(t, env->gwion->type[et_object]) < 0) + ERR_N(exp_self(unary)->pos, _("can't use 'new' on non-object types...\n")); return t; } diff --git a/src/parse/check.c b/src/parse/check.c index 1ee979c5..c8f29420 100644 --- a/src/parse/check.c +++ b/src/parse/check.c @@ -908,7 +908,7 @@ ANN2(1) static inline bool curried(const Env env, Exp exp) { } ANN static Type check_exp_call(const Env env, Exp_Call *exp) { - if (curried(env, exp->args)) + if (exp->allow_curry && curried(env, exp->args)) return env->gwion->type[et_curry]; if (exp->tmpl) { DECL_BO(const m_bool, ret, = func_check(env, exp)); -- 2.43.0