Ast tree;
Nspc nspc;
struct Map_ lbls;
- HAS_OBJ
+ uint16_t ref;
m_bool error;
m_bool global;
};
+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); }
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);
Value value_ref;
Func next;
size_t vt_index;
- HAS_OBJ
+ uint16_t ref;
ae_flag flag;
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); }
+
static inline int fflag(const Func f, const enum fflag flag) {
return (f->fflag & flag) == flag;
}
struct VM_Code_* pre_ctor;
struct VM_Code_* dtor;
struct NspcInfo_* info;
- HAS_OBJ
+ 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); }
extern ANEW ANN Nspc new_nspc(MemPool p, const m_str name);
extern ANN void nspc_commit(const Nspc);
#ifndef __OO
#define __OO
+typedef struct Gwion_ * Gwion;
+
typedef struct Type_ * Type;
typedef struct Nspc_ * Nspc;
typedef struct Value_ * Value;
size_t xid;
size_t size;
size_t array_depth;
- HAS_OBJ
+ uint16_t ref;
ae_flag flag;
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); }
ANN static inline int tflag(const Type t, const enum tflag flag) {
return (t->tflag & flag) == flag;
}
m_uint* ptr;
Func func_ref;
} d;
- HAS_OBJ
+ uint16_t ref;
ae_flag flag;
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); }
static inline int vflag(const Value v, const enum vflag flag) {
return (v->vflag & flag) == flag;
}
size_t stack_depth;
void* memoize;
m_str name;
- HAS_OBJ
+ uint16_t ref;
ae_flag flag;
int builtin;
};
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);
ANN VM_Shred shreduler_get(const Shreduler s) __attribute__((hot));
if(b->array)
clean_array_sub(a, b->array);
if(a->scope && b->value)
- REM_REF(b->value, a->gwion)
+ value_remref(b->value, a->gwion);
}
ANN static void clean_var_decl_list(Clean *a, Var_Decl_List b) {
clean_exp(a, b->exp);
clean_stmt(a, b->body);
if(b->v)
- REM_REF(b->v, a->gwion)
+ value_remref(b->v, a->gwion);
--a->scope;
}
ANN static void clean_fptr_def(Clean *a, Fptr_Def b) {
clean_func_base(a, b->base);
if(b->type)
- REM_REF(b->type, a->gwion)
+ type_remref(b->type, a->gwion);
}
ANN static void clean_type_def(Clean *a, Type_Def b) {
ANN static VM_Code emit_internal(const Emitter emit, const Func f) {
if(f->def->base->xid == insert_symbol("@dtor")) {
emit->env->class_def->nspc->dtor = f->code = finalyze(emit, DTOR_EOC);
- ADD_REF(f->code)
+ vmcode_addref(f->code);
return f->code;
} else if(f->def->base->xid == insert_symbol("@gack")) {
regpop(emit, SZ_INT + f->value_ref->from->owner_class->size);
#include "vm.h"
#include "gwion.h"
-ANN static void free_context(const Context a, Gwion gwion) {
- REM_REF(a->nspc, gwion)
+ANN void free_context(const Context a, Gwion gwion) {
+ nspc_remref(a->nspc, gwion);
free_mstr(gwion->mp, a->name);
mp_free(gwion->mp, Context, a);
}
context->name = mstrdup(p, str);
context->nspc = new_nspc(p, context->name);
context->tree = ast;
- context->ref = new_refcount(p, free_context);
+ context->ref = 1;
return context;
}
ANN void load_context(const Context context, const Env env) {
- ADD_REF((env->context = context))
+ context_addref((env->context = context));
vector_add(&env->scope->nspc_stack, (vtype)env->curr);
context->nspc->parent = env->curr;
env->curr = context->nspc;
free_map(env->gwion->mp, (Map)map_at(&context->lbls, i));
map_release(&context->lbls);
}
- REM_REF(context, env->gwion)
+ context_remref(context, env->gwion);
env->curr = (Nspc)vector_pop(&env->scope->nspc_stack);
}
ANN void release_ctx(struct Env_Scope_ *a, struct Gwion_ *gwion) {
const m_uint size = vector_size(&a->known_ctx);
for(m_uint i = size + 1; --i;)
- REM_REF((Context)vector_at(&a->known_ctx, i - 1), gwion);
+ context_remref((Context)vector_at(&a->known_ctx, i - 1), gwion);
}
ANN static void free_env_scope(struct Env_Scope_ *a, Gwion gwion) {
ANN void env_add_type(const Env env, const Type type) {
const Type v_type = type_copy(env->gwion->mp, env->gwion->type[et_class]);
- ADD_REF(v_type);
+ type_addref(v_type);
v_type->e->d.base_type = type;
const Symbol sym = insert_symbol(type->name);
nspc_add_type_front(env->curr, sym, type);
if(ret > 0 || env->context->global)
vector_add(&env->scope->known_ctx, (vtype)ctx);
else //nspc_rollback(env->global_nspc);
- REM_REF(ctx, env->gwion);
+ context_remref(ctx, env->gwion);
unload_context(ctx, env);
return ret;
}
#include "gwion.h"
#include "clean.h"
-ANN static void free_func(Func a, Gwion gwion) {
-// if(GET_FLAG(a, template))
+ANN void free_func(Func a, Gwion gwion) {
if(fflag(a, fflag_tmpl))
func_def_cleaner(gwion, a->def);
if(a->code)
- REM_REF(a->code, gwion);
+ vmcode_remref(a->code, gwion);
mp_free(gwion->mp, Func, a);
}
Func func = mp_calloc(p, Func);
func->name = name;
func->def = def;
- func->ref = new_refcount(p, free_func);
+ func->ref = 1;
return func;
}
nspc_release_object(a, v, gwion);
else if(tflag(v->type, tflag_struct))
nspc_release_struct(a, v, gwion);
- REM_REF(v, gwion);
+ value_remref(v, gwion);
}
free_scope(gwion->mp, a->info->value);
}
struct scope_iter iter = { n->info->b, 0, 0 };\
A a;\
while(scope_iter(&iter, &a) > 0) \
- REM_REF(a, gwion);\
+ b##_remref(a, gwion);\
free_scope(gwion->mp, n->info->b);\
}
describe_nspc_free(Func, func)
describe_nspc_free(Type, type)
-ANN static void free_nspc(Nspc a, Gwion gwion) {
+ANN void free_nspc(const Nspc a, const Gwion gwion) {
free_nspc_value(a, gwion);
nspc_free_func(a, gwion);
if(a->info->op_map.ptr)
vector_release(&a->info->vtable);
mp_free(gwion->mp, NspcInfo, a->info);
if(a->pre_ctor)
- REM_REF(a->pre_ctor, gwion);
+ vmcode_remref(a->pre_ctor, gwion);
if(a->dtor)
- REM_REF(a->dtor, gwion);
+ vmcode_remref(a->dtor, gwion);
mp_free(gwion->mp, Nspc, a);
}
a->info->value = new_scope(p);
a->info->type = new_scope(p);
a->info->func = new_scope(p);
- a->ref = new_refcount(p, free_nspc);
+ a->ref = 1;
return a;
}
const Vector v = &env->class_def->e->tuple->contains;
const m_int idx = vector_size(v) ? vector_find(v, (vtype)t) : -1;
if(idx == -1) {
- ADD_REF(t);
+ type_addref(t);
vector_add(v, (vtype)t);
}
}
ANN void free_tupleform(const TupleForm tuple, const struct Gwion_ *gwion) {
for(m_uint i = 0; i < vector_size(&tuple->contains); ++i)
- REM_REF((Type)vector_at(&tuple->contains, i), (void*)gwion);
+ type_remref((Type)vector_at(&tuple->contains, i), (void*)gwion);
vector_release(&tuple->contains);
vector_release(&tuple->types);
vector_release(&tuple->offset);
return !(tflag(a, tflag_force) || tflag(a, tflag_nonnull)) && (tflag(a, tflag_tmpl) ||GET_FLAG(a, global));
}
-ANN static void free_type(Type a, Gwion gwion) {
+ANN void free_type(const Type a, struct Gwion_ *const gwion) {
if(freeable(a)) {
if(tflag(a, tflag_udef))
free_union_def(gwion->mp, a->e->udef);
class_def_cleaner(gwion, a->e->cdef);
}
if(a->nspc)
- REM_REF(a->nspc, gwion);
+ nspc_remref(a->nspc, gwion);
if(a->e->tuple)
free_tupleform(a->e->tuple, gwion);
mp_free(gwion->mp, TypeInfo, a->e);
type->e->parent = parent;
if(parent)
type->size = parent->size;
- type->ref = new_refcount(p, free_type);
+ type->ref = 1;
return type;
}
*(f_release**)(t->nspc->info->class_data) = (depth > 1 || !tflag(src, tflag_struct)) ?
object_release : struct_release;
} else
- ADD_REF((t->nspc = env->gwion->type[et_array]->nspc))
+ nspc_addref((t->nspc = env->gwion->type[et_array]->nspc));
mk_class(env, t);
nspc_add_type_front(src->e->owner, sym, t);
return t;
ANN static Type specialtype_create(const Env env, const SpecialType *s) {
const Type t = type_copy(env->gwion->mp, s->type);
if(t->nspc)
- ADD_REF(t->nspc)
+ nspc_addref(t->nspc);
t->name = s_name(s->name);
t->flag = s->type->flag;
t->tflag |= s->type->tflag | s->flag;
#include "vm.h"
#include "gwion.h"
-ANN static void free_value(Value a, Gwion gwion) {
+ANN void free_value(Value a, Gwion gwion) {
const Type t = a->type;
if(!vflag(a, vflag_func) && a->d.ptr && !vflag(a, vflag_direct) &&
!(vflag(a, vflag_enum) && vflag(a, vflag_builtin) && a->from->owner_class)
else if(vflag(a, vflag_freeme))
xfree(a->d.ptr);
if(is_class(gwion, t))
- REM_REF(t, gwion)
+ type_remref(t, gwion);
mp_free(gwion->mp, ValueFrom, a->from);
mp_free(gwion->mp, Value, a);
}
a->from = mp_calloc(p, ValueFrom);
a->type = type;
a->name = name;
- a->ref = new_refcount(p, free_value);
+ a->ref = 1;
return a;
}
ANN Nspc pop_global(struct Gwion_ *gwion) {
const Nspc nspc = gwion->env->global_nspc->parent;
- REM_REF(gwion->env->global_nspc, gwion)
+ nspc_remref(gwion->env->global_nspc, gwion);
return gwion->env->curr = gwion->env->global_nspc = nspc;
}
const Type t = ret > 0 ? fptr->type : NULL;
free_fptr_def(gwi->gwion->mp, fptr);
if(fptr->type)
- REM_REF(fptr->type, gwi->gwion)
+ type_remref(fptr->type, gwi->gwion);
ck_end(gwi);
return t;
}
const m_bool ret = traverse_fptr_def(env, fptr_def);
const Type t = fptr_def->type;
free_fptr_def(env->gwion->mp, fptr_def);
- REM_REF(t, env->gwion)
+ type_remref(t, env->gwion);
bin->rhs->d.exp_decl.list->self->value->type = bin->rhs->info->type = bin->rhs->d.exp_decl.type = t;
exp_setvar(bin->rhs, 1);
return ret > 0 ? t : env->gwion->type[et_null];
}
static FREEARG(freearg_xork) {
- REM_REF((VM_Code)instr->m_val, gwion)
+ vmcode_remref((VM_Code)instr->m_val, gwion);
}
static FREEARG(freearg_dottmpl) {
if(!code)
Except(shred, "[NullTickException]");
uu->shred = new_vm_shred(shred->info->vm->gwion->mp, *(VM_Code*)(shred->reg-offset));
- ADD_REF(*(VM_Code*)(shred->reg - offset));
+ vmcode_addref(*(VM_Code*)(shred->reg - offset));
uu->shred->info->vm = shred->info->vm;
code_prepare(uu->shred->code);
shreduler_ini(uu->shred->info->vm->shreduler, uu->shred);
ANN static void handle_dtor(const M_Object o, const VM_Shred shred) {
const VM_Shred sh = new_vm_shred(shred->info->mp, o->type_ref->nspc->dtor);
- ADD_REF(o->type_ref->nspc->dtor);
+ vmcode_addref(o->type_ref->nspc->dtor);
sh->base = shred->base;
*(M_Object*)sh->mem = o;
vm_add_shred(shred->info->vm, sh);
VM_Shred new_shred_base(const VM_Shred shred, const VM_Code code) {
const VM_Shred sh = new_vm_shred(shred->info->mp, code);
- ADD_REF(code)
+ vmcode_addref(code);
sh->base = shred->base;
return sh;
}
if(!parent->gwion->data->child2.ptr)
vector_init(&parent->gwion->data->child2);
vector_add(&parent->gwion->data->child2, (vtype)ME(o)->info->vm->gwion);
- REM_REF(ME(o)->code, ME(o)->info->vm->gwion);
+ vmcode_remref(ME(o)->code, ME(o)->info->vm->gwion);
MUTEX_UNLOCK(parent->shreduler->mutex);
}
nspc_add_type_front(v->from->owner, sym, actual_type(env->gwion, m_func->value_ref->type));
}
if(fptr->type)
- REM_REF(fptr->type, env->gwion)
+ type_remref(fptr->type, env->gwion);
free_fptr_def(env->gwion->mp, fptr);
}
return m_func;
set_vflag(fptr->value, vflag_func);
add_type(env, t->e->owner, t);
mk_class(env, t);
- ADD_REF(t);
+ type_addref(t);
return GW_OK;
}
t->e->owner_class = env->class_def;
tdef->type = t;
if(base->nspc)
- ADD_REF((t->nspc = base->nspc));
+ nspc_addref((t->nspc = base->nspc));
t->flag = tdef->ext->flag;
scan0_implicit_similar(env, t, base);
if(tdef->ext->array && !tdef->ext->array->exp)
ANN static void typedef_fptr(const Env env, const Type_Def tdef, const Type base) {
tdef->type = type_copy(env->gwion->mp, base);
- ADD_REF(tdef->type->nspc)
+ nspc_addref(tdef->type->nspc);
tdef->type->name = s_name(tdef->xid);
tdef->type->e->parent = base;
add_type(env, env->curr, tdef->type);
CHECK_BB(scan1_exp(env, l->self))
Var_Decl_List list = decl.list;
- do ADD_REF(list->self->value)
+ do value_addref(list->self->value);
while((list = list->next));
if(global)
valuefrom(env, v->from);
CHECK_OO(scan2_func_assign(env, f->def, f, v))
if(!overload) {
- ADD_REF(v);
+ value_addref(v);
nspc_add_value_front(env->curr, f->def->base->xid, v);
} else if(overload->d.func_ref) {
f->next = overload->d.func_ref->next;
"template", ff->vt_index);
nspc_add_value(env->curr, sym, value);
if(!overload) {
- ADD_REF(value)
+ value_addref(value);
nspc_add_value(env->curr, f->base->xid, value);
}
func->vt_index = ff->vt_index;
const Symbol sym = func_symbol(env, env->curr->name, name, "template", i);
nspc_add_value(env->curr, sym, value);
if(!overload) {
- ADD_REF(value)
+ value_addref(value);
nspc_add_value(env->curr, f->base->xid, value);
nspc_add_func(env->curr, f->base->xid, func);
} else
if(base_type)
return base_type;
const Type ret = type_copy(env->gwion->mp, t);
- ADD_REF(ret->nspc)
ret->e->parent = t;
ret->name = s_name(sym);
set_tflag(ret, tflag_ftmpl);
free_vector(gwion->mp, v);
}
-ANN static void free_vm_code(VM_Code a, Gwion gwion) {
+ANN void free_vm_code(VM_Code a, Gwion gwion) {
if(a->memoize)
memoize_end(gwion->mp, a->memoize);
if(!a->builtin) {
code->name = mstrdup(p, name);
code->stack_depth = stack_depth;
code->builtin = builtin;
- code->ref = new_refcount(p, free_vm_code);
+ code->ref = 1;
return code;
}
for(m_uint i = vector_size(&shred->gc) + 1; --i;)
release((M_Object)vector_at(&shred->gc, i - 1), shred);
vector_release(&shred->gc);
- REM_REF(shred->info->orig, shred->info->vm->gwion);
+ vmcode_remref(shred->info->orig, shred->info->vm->gwion);
const MemPool mp = shred->info->mp;
mp_free(mp, ShredTick, shred->tick);
free_shredinfo(mp, shred->info);