From 3bb995c989508a2204edaaaa21015f415f78b80c Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=A9mie=20Astor?= Date: Sun, 22 Nov 2020 09:15:23 +0100 Subject: [PATCH] :art: Use generator for flags --- ast | 2 +- include/env/func.h | 28 +--------------------------- include/env/type.h | 25 +------------------------ include/env/value.h | 14 +------------- 4 files changed, 4 insertions(+), 65 deletions(-) diff --git a/ast b/ast index 7497ebfb..209581d7 160000 --- a/ast +++ b/ast @@ -1 +1 @@ -Subproject commit 7497ebfbb141e592ffde20246a01a754a6c31e76 +Subproject commit 209581d7d804fab314f54ee35cf68210aabc0674 diff --git a/include/env/func.h b/include/env/func.h index fbde81bb..026ab7c0 100644 --- a/include/env/func.h +++ b/include/env/func.h @@ -25,33 +25,7 @@ struct Func_ { ANN void free_func(const Func, struct Gwion_*const); ANN static inline void func_addref(const Func f) { ++f->ref; } ANN static inline void func_remref(const Func f, struct Gwion_ *const gwion) { if(!--f->ref) free_func(f, gwion); } - -static inline int fflag(const Func f, const enum fflag flag) { - return (f->fflag & flag) == flag; -} - -static inline int safe_fflag(const Func f, const enum fflag flag) { - return f ? ((f->fflag & flag) == flag) : 0; -} -#ifndef __cplusplus -static inline void set_fflag(const Func f, const enum fflag flag) { - f->fflag |= flag; -} - -static inline void unset_fflag(const Func f, const enum fflag flag) { - f->fflag &= ~flag; -} -#else -static inline void set_fflag(const Func f, const enum fflag flag) { - const auto ff = f->fflag | flag; - f->fflag = static_cast(ff); -} - -static inline void unset_fflag(const Func f, const enum fflag flag) { - const auto ff = f->fflag & ~flag; - f->fflag = static_cast(ff); -} -#endif +FLAG_FUNC(Func, f) 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); diff --git a/include/env/type.h b/include/env/type.h index b6400d90..9e1abbaa 100644 --- a/include/env/type.h +++ b/include/env/type.h @@ -54,31 +54,8 @@ struct Type_ { ANN void free_type(const Type, struct Gwion_*const); ANN static inline void type_addref(const Type t) { ++t->ref; } ANN static inline void type_remref(const Type t, struct Gwion_ *const gwion) { if(!--t->ref) free_type(t, gwion); } -ANN static inline int tflag(const Type t, const enum tflag flag) { - return (t->tflag & flag) == flag; -} -static inline int safe_tflag(const Type t, const enum tflag flag) { - return t ? ((t->tflag & flag) == flag) : 0; -} -#ifndef __cplusplus -ANN static inline void set_tflag(const Type t, const enum tflag flag) { - t->tflag |= flag; -} - -static inline void unset_tflag(const Type t, const enum tflag flag) { - t->tflag &= ~flag; -} -#else -ANN static inline void set_tflag(const Type t, const enum tflag flag) { - auto ff = t->tflag | flag; - t->tflag = static_cast(ff); -} +FLAG_FUNC(Type, t) -static inline void unset_tflag(const Type t, const enum tflag flag) { - const auto ff = t->tflag & ~flag; - t->tflag = static_cast(tt); -} -#endif ANN2(1,3) ANEW Type new_type(MemPool, const m_uint xid, const m_str name, const Type); ANEW ANN Type type_copy(MemPool, const Type type); ANN m_str get_type_name(const Env, const Type t, const m_uint); diff --git a/include/env/value.h b/include/env/value.h index 912eed82..b49cd631 100644 --- a/include/env/value.h +++ b/include/env/value.h @@ -38,20 +38,8 @@ struct Value_ { ANN void free_value(const Value, struct Gwion_*const); ANN static inline void value_addref(const Value v) { ++v->ref; } ANN static inline void value_remref(const Value v, struct Gwion_ *const gwion) { if(!--v->ref) free_value(v, gwion); } -static inline int vflag(const Value v, const enum vflag flag) { - return (v->vflag & flag) == flag; -} -#ifndef __cplusplus -static inline void set_vflag(const Value v, const enum vflag flag) { - v->vflag |= flag; -} -#else -static inline void set_vflag(const Value v, const enum vflag flag) { - auto ff = v->vflag | flag; - v->vflag = static_cast(ff); -} -#endif +FLAG_FUNC(Value, v) ANEW ANN Value new_value(MemPool p, const Type type, const m_str name); ANN void valuefrom(const Env, struct ValueFrom_*); -- 2.43.0