From: fennecdjay Date: Sun, 8 Nov 2020 12:33:10 +0000 (+0100) Subject: :art: Improve ARC X-Git-Tag: nightly~1195 X-Git-Url: http://10.10.0.4:5575/?a=commitdiff_plain;h=6bf4d0d027e0421856f2bae6d57396bcfc1d608a;p=gwion.git :art: Improve ARC --- diff --git a/include/env/context.h b/include/env/context.h index 2426e07e..53a12800 100644 --- a/include/env/context.h +++ b/include/env/context.h @@ -6,11 +6,14 @@ struct Context_ { 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); diff --git a/include/env/func.h b/include/env/func.h index fa2d3ea2..e28a706e 100644 --- a/include/env/func.h +++ b/include/env/func.h @@ -16,11 +16,15 @@ struct Func_ { 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; } diff --git a/include/env/nspc.h b/include/env/nspc.h index 9ce2f4f7..1a70d732 100644 --- a/include/env/nspc.h +++ b/include/env/nspc.h @@ -17,9 +17,12 @@ struct Nspc_ { 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); diff --git a/include/env/oo.h b/include/env/oo.h index 1dc06485..ba5d09c7 100644 --- a/include/env/oo.h +++ b/include/env/oo.h @@ -1,6 +1,8 @@ #ifndef __OO #define __OO +typedef struct Gwion_ * Gwion; + typedef struct Type_ * Type; typedef struct Nspc_ * Nspc; typedef struct Value_ * Value; diff --git a/include/env/type.h b/include/env/type.h index dd8b49bb..5314dbb8 100644 --- a/include/env/type.h +++ b/include/env/type.h @@ -48,11 +48,14 @@ struct Type_ { 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; } diff --git a/include/env/value.h b/include/env/value.h index 00f98d37..c3b33433 100644 --- a/include/env/value.h +++ b/include/env/value.h @@ -29,11 +29,14 @@ struct Value_ { 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; } diff --git a/include/vm.h b/include/vm.h index 7eefb167..6dd7c929 100644 --- a/include/vm.h +++ b/include/vm.h @@ -11,7 +11,7 @@ struct VM_Code_ { size_t stack_depth; void* memoize; m_str name; - HAS_OBJ + uint16_t ref; ae_flag flag; int builtin; }; @@ -61,6 +61,10 @@ struct VM_Shred_ { 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)); diff --git a/src/clean.c b/src/clean.c index b037f541..5d64b36e 100644 --- a/src/clean.c +++ b/src/clean.c @@ -62,7 +62,7 @@ ANN static void clean_var_decl(Clean *a, Var_Decl b) { 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) { @@ -171,7 +171,7 @@ ANN static void clean_stmt_each(Clean *a, Stmt_Each 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; } @@ -316,7 +316,7 @@ ANN static void clean_union_def(Clean *a, Union_Def b) { 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) { diff --git a/src/emit/emit.c b/src/emit/emit.c index 42234bb8..5155219c 100644 --- a/src/emit/emit.c +++ b/src/emit/emit.c @@ -1896,7 +1896,7 @@ ANN static void emit_func_def_return(const Emitter emit) { 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); diff --git a/src/env/context.c b/src/env/context.c index 6cf65e90..c78d522e 100644 --- a/src/env/context.c +++ b/src/env/context.c @@ -4,8 +4,8 @@ #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); } @@ -15,12 +15,12 @@ ANN2(2) Context new_context(MemPool p, const Ast ast, const m_str str) { 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; @@ -33,6 +33,6 @@ ANN void unload_context(const Context context, const Env env) { 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); } diff --git a/src/env/env.c b/src/env/env.c index 0dcda890..b7fba815 100644 --- a/src/env/env.c +++ b/src/env/env.c @@ -43,7 +43,7 @@ ANN void env_reset(const Env env) { 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) { @@ -80,7 +80,7 @@ ANN void env_pop(const Env env, const m_uint scope) { 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); @@ -108,7 +108,7 @@ ANN m_bool type_engine_clean_prog(const Env env, m_bool *r) { 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; } diff --git a/src/env/func.c b/src/env/func.c index 05944b08..6417d2a3 100644 --- a/src/env/func.c +++ b/src/env/func.c @@ -5,12 +5,11 @@ #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); } @@ -18,7 +17,7 @@ ANN Func new_func(MemPool p, const m_str name, const Func_Def def) { Func func = mp_calloc(p, Func); func->name = name; func->def = def; - func->ref = new_refcount(p, free_func); + func->ref = 1; return func; } diff --git a/src/env/nspc.c b/src/env/nspc.c index b0c6cdc8..c92cd7bd 100644 --- a/src/env/nspc.c +++ b/src/env/nspc.c @@ -44,7 +44,7 @@ ANN static void free_nspc_value(const Nspc a, Gwion gwion) { 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); } @@ -54,14 +54,14 @@ ANN static void nspc_free_##b(Nspc n, Gwion gwion) {\ 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) @@ -73,9 +73,9 @@ ANN static void free_nspc(Nspc a, Gwion gwion) { 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); } @@ -86,6 +86,6 @@ ANN Nspc new_nspc(MemPool p, const m_str name) { 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; } diff --git a/src/env/tupleform.c b/src/env/tupleform.c index 511ed68a..82fe1df2 100644 --- a/src/env/tupleform.c +++ b/src/env/tupleform.c @@ -28,7 +28,7 @@ ANN void tuple_contains(const Env env, const Value value) { 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); } } @@ -58,7 +58,7 @@ ANN2(1) TupleForm new_tupleform(MemPool p, const Type parent_type) { 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); diff --git a/src/env/type.c b/src/env/type.c index 61c1d508..9da87fe0 100644 --- a/src/env/type.c +++ b/src/env/type.c @@ -12,7 +12,7 @@ ANN static inline m_bool freeable(const Type a) { 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); @@ -20,7 +20,7 @@ ANN static void free_type(Type a, Gwion gwion) { 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); @@ -36,7 +36,7 @@ Type new_type(MemPool p, const m_uint xid, const m_str name, const Type parent) type->e->parent = parent; if(parent) type->size = parent->size; - type->ref = new_refcount(p, free_type); + type->ref = 1; return type; } @@ -113,7 +113,7 @@ ANN Type array_type(const Env env, const Type src, const m_uint depth) { *(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; diff --git a/src/env/type_special.c b/src/env/type_special.c index 668667ec..05db3f35 100644 --- a/src/env/type_special.c +++ b/src/env/type_special.c @@ -19,7 +19,7 @@ typedef struct { 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; diff --git a/src/env/value.c b/src/env/value.c index 217b399b..dfbf80b8 100644 --- a/src/env/value.c +++ b/src/env/value.c @@ -4,7 +4,7 @@ #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) @@ -13,7 +13,7 @@ ANN static void free_value(Value a, Gwion gwion) { 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); } @@ -23,7 +23,7 @@ ANN Value new_value(MemPool p, const Type type, const m_str name) { a->from = mp_calloc(p, ValueFrom); a->type = type; a->name = name; - a->ref = new_refcount(p, free_value); + a->ref = 1; return a; } diff --git a/src/gwion.c b/src/gwion.c index 80b01e72..f4284dcc 100644 --- a/src/gwion.c +++ b/src/gwion.c @@ -167,6 +167,6 @@ ANN void push_global(struct Gwion_ *gwion, const m_str name) { 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; } diff --git a/src/import/import_fdef.c b/src/import/import_fdef.c index cb4f5001..60d39442 100644 --- a/src/import/import_fdef.c +++ b/src/import/import_fdef.c @@ -128,7 +128,7 @@ ANN Type gwi_fptr_end(const Gwi gwi, const ae_flag flag) { 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; } diff --git a/src/lib/lib_func.c b/src/lib/lib_func.c index 2f0d97be..9781373c 100644 --- a/src/lib/lib_func.c +++ b/src/lib/lib_func.c @@ -207,7 +207,7 @@ static OP_CHECK(opck_auto_fptr) { 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]; @@ -336,7 +336,7 @@ static OP_EMIT(opem_spork) { } static FREEARG(freearg_xork) { - REM_REF((VM_Code)instr->m_val, gwion) + vmcode_remref((VM_Code)instr->m_val, gwion); } static FREEARG(freearg_dottmpl) { diff --git a/src/lib/modules.c b/src/lib/modules.c index 76e20ae5..8a1af0bb 100644 --- a/src/lib/modules.c +++ b/src/lib/modules.c @@ -259,7 +259,7 @@ static INSTR(UsrUGenTick) { 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); diff --git a/src/lib/object.c b/src/lib/object.c index d434b41d..2d08cb34 100644 --- a/src/lib/object.c +++ b/src/lib/object.c @@ -53,7 +53,7 @@ M_Object new_string2(const struct Gwion_ *gwion, const VM_Shred shred, const m_s 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); diff --git a/src/lib/shred.c b/src/lib/shred.c index aeac5487..e0948c8a 100644 --- a/src/lib/shred.c +++ b/src/lib/shred.c @@ -22,7 +22,7 @@ static m_int o_fork_thread, o_fork_cond, o_fork_mutex, o_shred_cancel, o_fork_do 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; } @@ -197,7 +197,7 @@ static DTOR(fork_dtor) { 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); } diff --git a/src/parse/func_resolve_tmpl.c b/src/parse/func_resolve_tmpl.c index ca3c573c..e62b98f7 100644 --- a/src/parse/func_resolve_tmpl.c +++ b/src/parse/func_resolve_tmpl.c @@ -83,7 +83,7 @@ ANN static Func fptr_match(const Env env, struct ResolverArgs* f_ptr_args) { 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; diff --git a/src/parse/scan0.c b/src/parse/scan0.c index ce22bae9..30ace78f 100644 --- a/src/parse/scan0.c +++ b/src/parse/scan0.c @@ -86,7 +86,7 @@ ANN m_bool scan0_fptr_def(const Env env, const Fptr_Def fptr) { 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; } @@ -124,7 +124,7 @@ ANN static void typedef_simple(const Env env, const Type_Def tdef, const Type ba 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) @@ -144,7 +144,7 @@ ANN static m_bool typedef_complex(const Env env, const Type_Def tdef, const Type 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); diff --git a/src/parse/scan1.c b/src/parse/scan1.c index f52c2d01..da0e8d3a 100644 --- a/src/parse/scan1.c +++ b/src/parse/scan1.c @@ -405,7 +405,7 @@ ANN static m_bool scan1_union_def_action(const Env env, const Union_Def udef, 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) diff --git a/src/parse/scan2.c b/src/parse/scan2.c index cfdbb07b..618dbc10 100644 --- a/src/parse/scan2.c +++ b/src/parse/scan2.c @@ -345,7 +345,7 @@ ANN2(1,2) static Value func_value(const Env env, const Func f, 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; @@ -385,7 +385,7 @@ ANN2(1, 2) static m_bool scan2_fdef_tmpl(const Env env, const Func_Def f, const "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; @@ -398,7 +398,7 @@ ANN2(1, 2) static m_bool scan2_fdef_tmpl(const Env env, const Func_Def f, const 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 diff --git a/src/parse/template.c b/src/parse/template.c index dac9f8c8..63c159c3 100644 --- a/src/parse/template.c +++ b/src/parse/template.c @@ -66,7 +66,6 @@ static ANN Type scan_func(const Env env, const Type t, const Type_Decl* td) { 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); diff --git a/src/vm/vm_code.c b/src/vm/vm_code.c index 8c0b8c52..3851a5b0 100644 --- a/src/vm/vm_code.c +++ b/src/vm/vm_code.c @@ -26,7 +26,7 @@ ANN static void _free_code_instr(const Vector v, const Gwion gwion) { 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) { @@ -67,7 +67,7 @@ VM_Code new_vm_code(MemPool p, const Vector instr, const m_uint stack_depth, 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; } diff --git a/src/vm/vm_shred.c b/src/vm/vm_shred.c index eca7b796..52795e6c 100644 --- a/src/vm/vm_shred.c +++ b/src/vm/vm_shred.c @@ -45,7 +45,7 @@ void free_vm_shred(VM_Shred shred) { 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);