From: fennecdjay Date: Wed, 2 Oct 2019 00:14:55 +0000 (+0200) Subject: :art: Add some operator defines X-Git-Tag: nightly~2198^2~179 X-Git-Url: http://10.10.0.4:5575/?a=commitdiff_plain;h=c9ebc66a7aee1a52b42ba022c7e7a865b196f919;p=gwion.git :art: Add some operator defines --- diff --git a/include/operator.h b/include/operator.h index c3b0abdc..0e3f9500 100644 --- a/include/operator.h +++ b/include/operator.h @@ -3,6 +3,12 @@ #define OP_ANY_TYPE (Type)1 #define ERR_N(a, b, ...) { env_err(env, (a), (b), ## __VA_ARGS__); return env->gwion->type[et_null]; } +#define DECL_ON(decl, f, exp) decl f exp; { if(!f) return env->gwion->type[et_null]; } +#define DECL_BN(decl, f, exp) decl f exp; { if(f < 0) return env->gwion->type[et_null]; } +#define DECL_NN(decl, f, exp) decl f exp; { if(f == env->gwion->type[et_null) return env->gwion->type[et_null]; } +#define CHECK_ON(f) { if(!f) return env->gwion->type[et_null]; } +#define CHECK_BN(f) { if(f < 0) return env->gwion->type[et_null]; } +#define CHECK_NN(f) { if(f == env->gwion->type[et_null] return env->gwion->type[et_null]; } typedef Type (*opck)(const Env, void*, m_bool*); typedef struct Instr_* (*opem)(const Emitter, void*); diff --git a/src/lib/opfunc.c b/src/lib/opfunc.c index db560281..30f69192 100644 --- a/src/lib/opfunc.c +++ b/src/lib/opfunc.c @@ -93,14 +93,14 @@ OP_CHECK(opck_post) { OP_CHECK(opck_new) { const Exp_Unary* unary = (Exp_Unary*)data; SET_FLAG(unary->td, ref); - DECL_OO(const Type, t, = known_type(env, unary->td)) + DECL_ON(const Type, t, = known_type(env, unary->td)) if(isa(t, env->gwion->type[et_object]) < 0 && isa(t, env->gwion->type[et_function]) < 0) - ERR_O(exp_self(unary)->pos, _("primitive types cannot be used as reference (@)...\n")) + ERR_N(exp_self(unary)->pos, _("primitive types cannot be used as reference (@)...\n")) if(type_ref(t)) ERR_N(td_pos(unary->td), _("can't use 'new' on ref type '%s'\n"), t->name) UNSET_FLAG(unary->td, ref); if(unary->td->array) - CHECK_BO(check_subscripts(env, unary->td->array)) + CHECK_BN(check_subscripts(env, unary->td->array)) return t; }