uint16_t ref;
};
-ANN void free_context(const Context, struct Gwion_*const);
-ANN static inline void context_addref(const Context c) { ++c->ref; }
-ANN static inline void context_remref(const Context c, struct Gwion_ *const gwion) { if(!--c->ref) free_context(c, gwion); }
+REF_FUNC(Context, context)
ANN2(1,3) ANEW Context new_context(MemPool p, const Ast, const m_str);
ANN void load_context(const Context, const Env);
ANN void unload_context(const Context, const Env);
enum fflag fflag;
};
-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); }
+REF_FUNC(Func, func)
FLAG_FUNC(Func, f)
ANEW ANN Func new_func(MemPool, const m_str, const Func_Def);
uint16_t ref;
};
-ANN void free_nspc(const Nspc, struct Gwion_*const);
-ANN static inline void nspc_addref(const Nspc n) { ++n->ref; }
-ANN static inline void nspc_remref(const Nspc n, struct Gwion_ *const gwion) { if(!--n->ref) free_nspc(n, gwion); }
+REF_FUNC(Nspc, nspc)
extern ANEW ANN Nspc new_nspc(MemPool p, const m_str name);
extern ANN void nspc_commit(const Nspc);
typedef struct Value_ * Value;
typedef struct Func_ * Func;
+#define REF_FUNC(A, b) \
+ANN void free_##b(const A, struct Gwion_*const); \
+ANN static inline void b##_addref(const A a) { ++a->ref; } \
+ANN static inline void b##_remref(const A a, struct Gwion_ *const gwion) { if(!--a->ref) free_##b(a, gwion); }
#endif
enum tflag tflag;
};
-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); }
+REF_FUNC(Type, type)
FLAG_FUNC(Type, t)
ANN2(1,3) ANEW Type new_type(MemPool, const m_uint xid, const m_str name, const Type);
enum vflag vflag;
};
-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); }
-
+REF_FUNC(Value, value)
FLAG_FUNC(Value, v)
ANEW ANN Value new_value(MemPool p, const Type type, const m_str name);
struct ShredTick_ * tick;
struct ShredInfo_ * info;
};
-
-ANN void free_vm_code(const VM_Code, struct Gwion_*const);
-ANN static inline void vmcode_addref(const VM_Code c) { ++c->ref; }
-ANN static inline void vmcode_remref(const VM_Code c, struct Gwion_ *const gwion) { if(!--c->ref) free_vm_code(c, gwion); }
-ANN2(1,5) ANEW VM_Code new_vm_code(MemPool p, const Vector instr, const m_uint stack_depth, const int builtin, const m_str name);
+REF_FUNC(VM_Code, vmcode)
+ANN2(1,5) ANEW VM_Code new_vmcode(MemPool p, const Vector instr, const m_uint stack_depth, const int builtin, const m_str name);
ANN VM_Shred shreduler_get(const Shreduler s) __attribute__((hot));
ANN void shreduler_remove(const Shreduler s, const VM_Shred out, const m_bool erase)__attribute__((hot));
static ANEW ANN VM_Code emit_code(const Emitter emit) {
Code* const c = emit->code;
- const VM_Code code = new_vm_code(emit->gwion->mp, &c->instr, c->stack_depth, 0, c->name);
+ const VM_Code code = new_vmcode(emit->gwion->mp, &c->instr, c->stack_depth, 0, c->name);
return code;
}
ANN void builtin_func(const MemPool mp, const Func f, void* func_ptr) {
set_vflag(f->value_ref, vflag_builtin);
- f->code = new_vm_code(mp, NULL, f->def->stack_depth, 1, f->name);
+ f->code = new_vmcode(mp, NULL, f->def->stack_depth, 1, f->name);
f->code->native_func = (m_uint)func_ptr;
}
}
ANN static void gwion_cleaner(const Gwion gwion) {
- const VM_Code code = new_vm_code(gwion->mp, NULL, 0, 1, "in code dtor");
+ const VM_Code code = new_vmcode(gwion->mp, NULL, 0, 1, "in code dtor");
gwion->vm->cleaner_shred = new_vm_shred(gwion->mp, code);
vm_ini_shred(gwion->vm, gwion->vm->cleaner_shred);
}
ANN static m_bool mk_xtor(MemPool p, const Type type, const m_uint d, const enum tflag e) {
VM_Code* code = e == tflag_ctor ? &type->nspc->pre_ctor : &type->nspc->dtor;
const m_str name = type->name;
- *code = new_vm_code(p, NULL, SZ_INT, 1, name);
+ *code = new_vmcode(p, NULL, SZ_INT, 1, name);
(*code)->native_func = (m_uint)d;
type->tflag |= e;
return GW_OK;
}
ANN static m_bool mk_gack(MemPool p, const Type type, const f_gack d) {
- const VM_Code code = new_vm_code(p, NULL, SZ_INT, 1, "@gack");
+ const VM_Code code = new_vmcode(p, NULL, SZ_INT, 1, "@gack");
code->native_func = (m_uint)d;
type->info->gack = code;
return GW_OK;
DECL_ON(const Type, t, = (Type)scan_class(env, ts->t, ts->td))
const Type base = known_type(env, t->info->cdef->base.tmpl->call->td);
if(isa(base, env->gwion->type[et_compound]) > 0) {
- t->nspc->dtor = new_vm_code(env->gwion->mp, NULL, SZ_INT, 1, "@PtrDtor");
+ t->nspc->dtor = new_vmcode(env->gwion->mp, NULL, SZ_INT, 1, "@PtrDtor");
if(!tflag(base, tflag_struct))
t->nspc->dtor->native_func = (m_uint)ptr_object_dtor;
else
free_vector(gwion->mp, v);
}
-ANN void free_vm_code(VM_Code a, Gwion gwion) {
+ANN void free_vmcode(VM_Code a, Gwion gwion) {
if(a->memoize)
memoize_end(gwion->mp, a->memoize);
if(!a->builtin) {
}
-VM_Code new_vm_code(MemPool p, const Vector instr, const m_uint stack_depth,
+VM_Code new_vmcode(MemPool p, const Vector instr, const m_uint stack_depth,
const int builtin, const m_str name) {
VM_Code code = mp_calloc(p, VM_Code);
if(instr) {