From 632e22a23dc64b6bf5a34ca446f0562b1cd2ff2c Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=A9mie=20Astor?= Date: Sun, 10 May 2020 22:56:13 +0200 Subject: [PATCH] :art: Add missing file --- src/lib/func.c | 2 +- src/lib/vararg.c | 2 +- src/parse/func_operator.c | 21 +++++++++++++++++++++ src/parse/type_decl.c | 4 ++-- 4 files changed, 25 insertions(+), 4 deletions(-) create mode 100644 src/parse/func_operator.c diff --git a/src/lib/func.c b/src/lib/func.c index 105d5678..ce84739e 100644 --- a/src/lib/func.c +++ b/src/lib/func.c @@ -185,7 +185,7 @@ ANN static m_bool fptr_do(const Env env, struct FptrInfo *info) { m_bool nonnull = GET_FLAG(info->exp->info->type, nonnull); CHECK_BB(fptr_check(env, info)) DECL_OB(const Type, t, = fptr_type(env, info)) - info->exp->info->type = !nonnull ? t : type_nonnull(env, t); + info->exp->info->type = !nonnull ? t : nonnul_type(env, t); return GW_OK; } Exp_Lambda *l = &info->exp->d.exp_lambda; diff --git a/src/lib/vararg.c b/src/lib/vararg.c index 9d357c00..2d252686 100644 --- a/src/lib/vararg.c +++ b/src/lib/vararg.c @@ -122,7 +122,7 @@ static FREEARG(freearg_vararg) { static ID_CHECK(idck_vararg) { if(env->func && GET_FLAG(env->func->def, variadic)) - return type_nonnull(env, exp_self(prim)->info->type); + return nonnul_type(env, exp_self(prim)->info->type); ERR_O(exp_self(prim)->pos, _("'vararg' must be used inside variadic function")) } diff --git a/src/parse/func_operator.c b/src/parse/func_operator.c new file mode 100644 index 00000000..82afc43d --- /dev/null +++ b/src/parse/func_operator.c @@ -0,0 +1,21 @@ +#include "gwion_util.h" +#include "gwion_ast.h" +#include "gwion_env.h" +#include "vm.h" +#include "instr.h" +#include "object.h" +#include "gwion.h" +#include "operator.h" + +ANN void func_operator(const Func_Def fdef, struct Op_Import *opi) { + opi->op =fdef->base->xid; + const m_str str = s_name(fdef->base->xid); + const uint is_unary = GET_FLAG(fdef, unary) + + (!strcmp(str, "@conditionnal") || !strcmp(str, "@unconditionnal")); + const Arg_List args = fdef->base->args; + opi->lhs = is_unary ? NULL : + args ? args->var_decl->value->type : NULL; + opi->rhs = args ? is_unary ? args->var_decl->value->type : + args->next ? args->next->var_decl->value->type : + fdef->base->ret_type : NULL; +} diff --git a/src/parse/type_decl.c b/src/parse/type_decl.c index 9771edd9..80649250 100644 --- a/src/parse/type_decl.c +++ b/src/parse/type_decl.c @@ -8,7 +8,7 @@ #define STR_NONNULL ":nonnull" #define STRLEN_NONNULL strlen(STR_NONNULL) -ANN Type type_nonnull(const Env env, const Type base) { +ANN Type nonnul_type(const Env env, const Type base) { char c[strlen(base->name) + 9]; sprintf(c, "%s%s", base->name, STR_NONNULL); const Symbol sym = insert_symbol(c); @@ -58,7 +58,7 @@ ANN Type type_decl_resolve(const Env env, Type_Decl* td) { ERR_O(td_pos(td), _("void types can't be nonnull.")) if(isa(ret, env->gwion->type[et_object]) < 0 && isa(ret, env->gwion->type[et_fptr]) < 0) return ret; - return type_nonnull(env, ret); + return nonnul_type(env, ret); } return ret; } -- 2.43.0