move mm_free call into virtual function so dec is simpler
This commit is contained in:
parent
36afe7f533
commit
c00834cf15
@ -30,14 +30,16 @@ static Arr* c32slice_slice(B x, usz s) { Arr* r = m_c32slice(inc(c(Slice,x)->p),
|
||||
|
||||
static B c32arr_get (B x, usz n) { VTY(x,t_c32arr ); return m_c32(c(C32Arr ,x)->a[n]); }
|
||||
static B c32slice_get(B x, usz n) { VTY(x,t_c32slice); return m_c32(c(C32Slice,x)->a[n]); }
|
||||
static void c32arr_free(Value* x) { decSh(x); }
|
||||
static bool c32arr_canStore(B x) { return isC32(x); }
|
||||
|
||||
|
||||
|
||||
void c32arr_init() {
|
||||
TIi(t_c32arr,get) = c32arr_get; TIi(t_c32slice,get) = c32slice_get;
|
||||
TIi(t_c32arr,getU) = c32arr_get; TIi(t_c32slice,getU) = c32slice_get;
|
||||
TIi(t_c32arr,slice) = c32arr_slice; TIi(t_c32slice,slice) = c32slice_slice;
|
||||
TIi(t_c32arr,free) = c32arr_free; TIi(t_c32slice,free) = slice_free;
|
||||
TIi(t_c32arr,freeO) = tyarr_freeO; TIi(t_c32slice,freeO) = slice_freeO;
|
||||
TIi(t_c32arr,freeF) = tyarr_freeF; TIi(t_c32slice,freeF) = slice_freeF;
|
||||
TIi(t_c32arr,visit) = noop_visit; TIi(t_c32slice,visit) = slice_visit;
|
||||
TIi(t_c32arr,print) = arr_print; TIi(t_c32slice,print) = arr_print;
|
||||
TIi(t_c32arr,isArr) = true; TIi(t_c32slice,isArr) = true;
|
||||
|
||||
@ -1,10 +1,10 @@
|
||||
#include "../core.h"
|
||||
|
||||
static void md1D_free(Value* x) { dec(((Md1D*)x)->m1); dec(((Md1D*)x)->f); }
|
||||
static void md2D_free(Value* x) { dec(((Md2D*)x)->m2); dec(((Md2D*)x)->f); dec(((Md2D*)x)->g); }
|
||||
static void md2H_free(Value* x) { dec(((Md2H*)x)->m2); dec(((Md2H*)x)->g); }
|
||||
static void fork_free(Value* x) { dec(((Fork*)x)->f ); dec(((Fork*)x)->g); dec(((Fork*)x)->h); }
|
||||
static void atop_free(Value* x) { dec(((Atop*)x)->g); dec(((Atop*)x)->h); }
|
||||
DEF_FREE(md1D) { dec(((Md1D*)x)->m1); dec(((Md1D*)x)->f); }
|
||||
DEF_FREE(md2D) { dec(((Md2D*)x)->m2); dec(((Md2D*)x)->f); dec(((Md2D*)x)->g); }
|
||||
DEF_FREE(md2H) { dec(((Md2H*)x)->m2); dec(((Md2H*)x)->g); }
|
||||
DEF_FREE(fork) { dec(((Fork*)x)->f ); dec(((Fork*)x)->g); dec(((Fork*)x)->h); }
|
||||
DEF_FREE(atop) { dec(((Atop*)x)->g); dec(((Atop*)x)->h); }
|
||||
|
||||
static void md1D_visit(Value* x) { mm_visit(((Md1D*)x)->m1); mm_visit(((Md1D*)x)->f); }
|
||||
static void md2D_visit(Value* x) { mm_visit(((Md2D*)x)->m2); mm_visit(((Md2D*)x)->f); mm_visit(((Md2D*)x)->g); }
|
||||
@ -45,11 +45,11 @@ static B md2D_uc1(B t, B o, B x) {
|
||||
|
||||
|
||||
void derv_init() {
|
||||
TIi(t_md1D,free) = md1D_free; TIi(t_md1D,visit) = md1D_visit; TIi(t_md1D,print) = md1D_print; TIi(t_md1D,decompose) = md1D_decompose;
|
||||
TIi(t_md2D,free) = md2D_free; TIi(t_md2D,visit) = md2D_visit; TIi(t_md2D,print) = md2D_print; TIi(t_md2D,decompose) = md2D_decompose; TIi(t_md2D,fn_uc1) = md2D_uc1;
|
||||
TIi(t_md2H,free) = md2H_free; TIi(t_md2H,visit) = md2H_visit; TIi(t_md2H,print) = md2H_print; TIi(t_md2H,decompose) = md2H_decompose;
|
||||
TIi(t_fork,free) = fork_free; TIi(t_fork,visit) = fork_visit; TIi(t_fork,print) = fork_print; TIi(t_fork,decompose) = fork_decompose;
|
||||
TIi(t_atop,free) = atop_free; TIi(t_atop,visit) = atop_visit; TIi(t_atop,print) = atop_print; TIi(t_atop,decompose) = atop_decompose;
|
||||
TIi(t_md1D,freeO) = md1D_freeO; TIi(t_md1D,freeF) = md1D_freeF; TIi(t_md1D,visit) = md1D_visit; TIi(t_md1D,print) = md1D_print; TIi(t_md1D,decompose) = md1D_decompose;
|
||||
TIi(t_md2D,freeO) = md2D_freeO; TIi(t_md2D,freeF) = md2D_freeF; TIi(t_md2D,visit) = md2D_visit; TIi(t_md2D,print) = md2D_print; TIi(t_md2D,decompose) = md2D_decompose; TIi(t_md2D,fn_uc1) = md2D_uc1;
|
||||
TIi(t_md2H,freeO) = md2H_freeO; TIi(t_md2H,freeF) = md2H_freeF; TIi(t_md2H,visit) = md2H_visit; TIi(t_md2H,print) = md2H_print; TIi(t_md2H,decompose) = md2H_decompose;
|
||||
TIi(t_fork,freeO) = fork_freeO; TIi(t_fork,freeF) = fork_freeF; TIi(t_fork,visit) = fork_visit; TIi(t_fork,print) = fork_print; TIi(t_fork,decompose) = fork_decompose;
|
||||
TIi(t_atop,freeO) = atop_freeO; TIi(t_atop,freeF) = atop_freeF; TIi(t_atop,visit) = atop_visit; TIi(t_atop,print) = atop_print; TIi(t_atop,decompose) = atop_decompose;
|
||||
TIi(t_md1BI,m1_d) = m_md1D;
|
||||
TIi(t_md2BI,m2_d) = m_md2D;
|
||||
}
|
||||
|
||||
@ -17,14 +17,14 @@ static Arr* f64slice_slice(B x, usz s) { Arr* r = m_f64slice(inc(c(Slice,x)->p),
|
||||
|
||||
static B f64arr_get (B x, usz n) { VTY(x,t_f64arr ); return m_f64(c(F64Arr ,x)->a[n]); }
|
||||
static B f64slice_get(B x, usz n) { VTY(x,t_f64slice); return m_f64(c(F64Slice,x)->a[n]); }
|
||||
static void f64arr_free(Value* x) { decSh(x); }
|
||||
static bool f64arr_canStore(B x) { return q_f64(x); }
|
||||
|
||||
void f64arr_init() {
|
||||
TIi(t_f64arr,get) = f64arr_get; TIi(t_f64slice,get) = f64slice_get;
|
||||
TIi(t_f64arr,getU) = f64arr_get; TIi(t_f64slice,getU) = f64slice_get;
|
||||
TIi(t_f64arr,slice) = f64arr_slice; TIi(t_f64slice,slice) = f64slice_slice;
|
||||
TIi(t_f64arr,free) = f64arr_free; TIi(t_f64slice,free) = slice_free;
|
||||
TIi(t_f64arr,freeO) = tyarr_freeO; TIi(t_f64slice,freeO) = slice_freeO;
|
||||
TIi(t_f64arr,freeF) = tyarr_freeF; TIi(t_f64slice,freeF) = slice_freeF;
|
||||
TIi(t_f64arr,visit) = noop_visit; TIi(t_f64slice,visit) = slice_visit;
|
||||
TIi(t_f64arr,print) = arr_print; TIi(t_f64slice,print) = arr_print;
|
||||
TIi(t_f64arr,isArr) = true; TIi(t_f64slice,isArr) = true;
|
||||
|
||||
@ -45,7 +45,7 @@ static B fillarr_get (B x, usz n) { VTY(x,t_fillarr ); return inc(c(FillArr
|
||||
static B fillslice_get (B x, usz n) { VTY(x,t_fillslice); return inc(c(FillSlice,x)->a[n]); }
|
||||
static B fillarr_getU (B x, usz n) { VTY(x,t_fillarr ); return c(FillArr ,x)->a[n] ; }
|
||||
static B fillslice_getU(B x, usz n) { VTY(x,t_fillslice); return c(FillSlice,x)->a[n] ; }
|
||||
static void fillarr_free(Value* x) {
|
||||
DEF_FREE(fillarr) {
|
||||
decSh(x);
|
||||
B* p = ((FillArr*)x)->a;
|
||||
dec(((FillArr*)x)->fill);
|
||||
@ -63,7 +63,8 @@ void fillarr_init() {
|
||||
TIi(t_fillarr,get) = fillarr_get; TIi(t_fillslice,get) = fillslice_get;
|
||||
TIi(t_fillarr,getU) = fillarr_getU; TIi(t_fillslice,getU) = fillslice_getU;
|
||||
TIi(t_fillarr,slice) = fillarr_slice; TIi(t_fillslice,slice) = fillslice_slice;
|
||||
TIi(t_fillarr,free) = fillarr_free; TIi(t_fillslice,free) = slice_free;
|
||||
TIi(t_fillarr,freeO) = fillarr_freeO; TIi(t_fillslice,freeO) = slice_freeO;
|
||||
TIi(t_fillarr,freeF) = fillarr_freeF; TIi(t_fillslice,freeF) = slice_freeF;
|
||||
TIi(t_fillarr,visit) = fillarr_visit; TIi(t_fillslice,visit) = slice_visit;
|
||||
TIi(t_fillarr,print) = arr_print; TIi(t_fillslice,print) = arr_print;
|
||||
TIi(t_fillarr,isArr) = true; TIi(t_fillslice,isArr) = true;
|
||||
|
||||
@ -104,7 +104,7 @@ static B harr_get (B x, usz n) { VTY(x,t_harr ); return inc(c(HArr ,x)->a[n]
|
||||
static B hslice_get (B x, usz n) { VTY(x,t_hslice); return inc(c(HSlice,x)->a[n]); }
|
||||
static B harr_getU (B x, usz n) { VTY(x,t_harr ); return c(HArr ,x)->a[n] ; }
|
||||
static B hslice_getU(B x, usz n) { VTY(x,t_hslice); return c(HSlice,x)->a[n] ; }
|
||||
static void harr_free(Value* x) {
|
||||
DEF_FREE(harr) {
|
||||
decSh(x);
|
||||
B* p = ((HArr*)x)->a; // don't use harr_ptr so type isn't checked
|
||||
usz ia = ((Arr*)x)->ia;
|
||||
@ -118,7 +118,7 @@ static bool harr_canStore(B x) { return true; }
|
||||
|
||||
|
||||
|
||||
static void harrP_free(Value* x) { assert(x->type==t_harrPartial|x->type==t_freed);
|
||||
DEF_FREE(harrP) { assert(x->type==t_harrPartial|x->type==t_freed);
|
||||
assert(prnk(x)>1? true : ((Arr*)x)->sh!=&((Arr*)x)->ia);
|
||||
B* p = ((HArr*)x)->a;
|
||||
usz am = *((HArr*)x)->sh;
|
||||
@ -149,7 +149,8 @@ void harr_init() {
|
||||
TIi(t_harr,get) = harr_get; TIi(t_hslice,get) = hslice_get; TIi(t_harrPartial,get) = harrP_get;
|
||||
TIi(t_harr,getU) = harr_getU; TIi(t_hslice,getU) = hslice_getU; TIi(t_harrPartial,getU) = harrP_get;
|
||||
TIi(t_harr,slice) = harr_slice; TIi(t_hslice,slice) = hslice_slice;
|
||||
TIi(t_harr,free) = harr_free; TIi(t_hslice,free) = slice_free; TIi(t_harrPartial,free) = harrP_free;
|
||||
TIi(t_harr,freeO) = harr_freeO; TIi(t_hslice,freeO) = slice_freeO; TIi(t_harrPartial,freeO) = harrP_freeO;
|
||||
TIi(t_harr,freeF) = harr_freeF; TIi(t_hslice,freeF) = slice_freeF; TIi(t_harrPartial,freeF) = harrP_freeF;
|
||||
TIi(t_harr,visit) = harr_visit; TIi(t_hslice,visit) = slice_visit; TIi(t_harrPartial,visit) = harrP_visit;
|
||||
TIi(t_harr,print) = arr_print; TIi(t_hslice,print) = arr_print; TIi(t_harrPartial,print) = harrP_print;
|
||||
TIi(t_harr,isArr) = true; TIi(t_hslice,isArr) = true;
|
||||
|
||||
@ -17,14 +17,14 @@ static Arr* i32slice_slice(B x, usz s) { Arr* r = m_i32slice(inc(c(Slice,x)->p),
|
||||
|
||||
static B i32arr_get (B x, usz n) { VTY(x,t_i32arr ); return m_i32(c(I32Arr ,x)->a[n]); }
|
||||
static B i32slice_get(B x, usz n) { VTY(x,t_i32slice); return m_i32(c(I32Slice,x)->a[n]); }
|
||||
static void i32arr_free(Value* x) { decSh(x); }
|
||||
static bool i32arr_canStore(B x) { return q_i32(x); }
|
||||
|
||||
void i32arr_init() {
|
||||
TIi(t_i32arr,get) = i32arr_get; TIi(t_i32slice,get) = i32slice_get;
|
||||
TIi(t_i32arr,getU) = i32arr_get; TIi(t_i32slice,getU) = i32slice_get;
|
||||
TIi(t_i32arr,slice) = i32arr_slice; TIi(t_i32slice,slice) = i32slice_slice;
|
||||
TIi(t_i32arr,free) = i32arr_free; TIi(t_i32slice,free) = slice_free;
|
||||
TIi(t_i32arr,freeO) = tyarr_freeO; TIi(t_i32slice,freeO) = slice_freeO;
|
||||
TIi(t_i32arr,freeF) = tyarr_freeF; TIi(t_i32slice,freeF) = slice_freeF;
|
||||
TIi(t_i32arr,visit) = noop_visit; TIi(t_i32slice,visit) = slice_visit;
|
||||
TIi(t_i32arr,print) = arr_print; TIi(t_i32slice,print) = arr_print;
|
||||
TIi(t_i32arr,isArr) = true; TIi(t_i32slice,isArr) = true;
|
||||
|
||||
@ -401,7 +401,10 @@ u64 depth(B x) { // doesn't consume
|
||||
}
|
||||
return r+1;
|
||||
}
|
||||
void slice_free(Value* x) { dec(((Slice*)x)->p); decSh(x); }
|
||||
void tyarr_freeO(Value* x) { decSh(x); }
|
||||
void slice_freeO(Value* x) { dec(((Slice*)x)->p); decSh(x); }
|
||||
void tyarr_freeF(Value* x) { tyarr_freeO(x); mm_free(x); }
|
||||
void slice_freeF(Value* x) { slice_freeO(x); mm_free(x); }
|
||||
void slice_visit(Value* x) { mm_visit(((Slice*)x)->p); }
|
||||
void slice_print(B x) { arr_print(x); }
|
||||
|
||||
|
||||
11
src/h.h
11
src/h.h
@ -346,7 +346,8 @@ typedef struct Slice {
|
||||
struct Arr;
|
||||
B p;
|
||||
} Slice;
|
||||
void slice_free(Value* x);
|
||||
void tyarr_freeO(Value* x); void tyarr_freeF(Value* x);
|
||||
void slice_freeO(Value* x); void slice_freeF(Value* x);
|
||||
void slice_visit(Value* x);
|
||||
void slice_print(B x);
|
||||
|
||||
@ -364,7 +365,7 @@ typedef B (* BBBBB2B)(B, B, B, B, B);
|
||||
typedef B (*BBBBBB2B)(B, B, B, B, B, B);
|
||||
|
||||
#define FOR_TI(F) \
|
||||
F(V2v, free) /* expects refc==0, type may be cleared to t_empty for garbage collection */ \
|
||||
F(V2v, freeF) /* expects refc==0, includes mm_free */ \
|
||||
F(BS2B, get) /* increments result, doesn't consume arg; TODO figure out if this should never allocate, so GC wouldn't happen */ \
|
||||
F(BS2B, getU) /* like get, but doesn't increment result (mostly equivalent to `B t=get(…); dec(t); t`) */ \
|
||||
F(BB2B, m1_d) /* consume all args; (m, f) */ \
|
||||
@ -384,6 +385,7 @@ typedef B (*BBBBBB2B)(B, B, B, B, B, B);
|
||||
\
|
||||
F(B2v, print) /* doesn't consume */ \
|
||||
F(V2v, visit) /* call mm_visit for all referents */ \
|
||||
F(V2v, freeO) /* like freeF, but doesn't call mm_free for GC to be able to clear cycles */ \
|
||||
F(B2B, decompose) /* consumes; must return a HArr */ \
|
||||
F(bool, isArr) /* whether this type would have an ARR_TAG tag, in cases where the tag is unknown */ \
|
||||
F(bool, arrD1) /* is always an array with depth 1 */ \
|
||||
@ -401,9 +403,10 @@ static void mm_free(Value* x);
|
||||
|
||||
// refcount
|
||||
static bool reusable(B x) { return v(x)->refc==1; }
|
||||
#define DEF_FREE(TY) static inline void TY##_freeO(Value* x); static void TY##_freeF(Value* x) { TY##_freeO(x); mm_free(x); } static inline void TY##_freeO(Value* x)
|
||||
static inline void value_free(Value* x) {
|
||||
TIv(x,free)(x);
|
||||
mm_free(x);
|
||||
// TIv(x,freeO)(x); mm_free(x);
|
||||
TIv(x,freeF)(x);
|
||||
}
|
||||
void value_freeR(Value* x);
|
||||
static void dec(B x) {
|
||||
|
||||
12
src/load.c
12
src/load.c
@ -366,7 +366,7 @@ static void freed_visit(Value* x) {
|
||||
}
|
||||
static void empty_free(Value* x) { err("FREEING EMPTY\n"); }
|
||||
static void builtin_free(Value* x) { err("FREEING BUILTIN\n"); }
|
||||
static void def_free(Value* x) { }
|
||||
DEF_FREE(def) { }
|
||||
static void def_visit(Value* x) { printf("(no visit for %d=%s)\n", x->type, format_type(x->type)); }
|
||||
static void def_print(B x) { printf("(%d=%s)", v(x)->type, format_type(v(x)->type)); }
|
||||
static bool def_canStore(B x) { return false; }
|
||||
@ -393,7 +393,8 @@ static B empty_getU(B x, usz n) {
|
||||
|
||||
void base_init() { // very first init function
|
||||
for (u64 i = 0; i < t_COUNT; i++) {
|
||||
TIi(i,free) = def_free;
|
||||
TIi(i,freeO) = def_freeO;
|
||||
TIi(i,freeF) = def_freeF;
|
||||
TIi(i,visit) = def_visit;
|
||||
TIi(i,get) = def_get;
|
||||
TIi(i,getU) = def_getU;
|
||||
@ -414,8 +415,8 @@ void base_init() { // very first init function
|
||||
TIi(i,m2_uc1) = def_m2_uc1;
|
||||
TIi(i,m2_ucw) = def_m2_ucw;
|
||||
}
|
||||
TIi(t_empty,free) = empty_free;
|
||||
TIi(t_freed,free) = def_free;
|
||||
TIi(t_empty,freeO) = empty_free; TIi(t_freed,freeO) = def_freeO;
|
||||
TIi(t_empty,freeF) = empty_free; TIi(t_freed,freeF) = def_freeF;
|
||||
TIi(t_freed,visit) = freed_visit;
|
||||
#ifdef DONT_FREE
|
||||
TIi(t_empty,get) = empty_get;
|
||||
@ -423,7 +424,8 @@ void base_init() { // very first init function
|
||||
#endif
|
||||
TIi(t_shape,visit) = noop_visit;
|
||||
TIi(t_funBI,visit) = TIi(t_md1BI,visit) = TIi(t_md2BI,visit) = noop_visit;
|
||||
TIi(t_funBI,free) = TIi(t_md1BI,free) = TIi(t_md2BI,free) = builtin_free;
|
||||
TIi(t_funBI,freeO) = TIi(t_md1BI,freeO) = TIi(t_md2BI,freeO) = builtin_free;
|
||||
TIi(t_funBI,freeF) = TIi(t_md1BI,freeF) = TIi(t_md2BI,freeF) = builtin_free;
|
||||
assert((MD1_TAG>>1) == (MD2_TAG>>1)); // just to be sure it isn't changed incorrectly, `isMd` depends on this
|
||||
|
||||
#define FA(N,X) { BFn* f = mm_alloc(sizeof(BFn), t_funBI); f->c2=N##_c2 ; f->c1=N##_c1 ; f->extra=pf_##N; f->ident=bi_N; f->uc1=def_fn_uc1; f->ucw=def_fn_ucw; gc_add(bi_##N = tag(f,FUN_TAG)); }
|
||||
|
||||
@ -35,10 +35,10 @@ B nfn_name(B x) { VTY(x, t_nfn);
|
||||
return inc(c(NFnDesc,TI(nfn_list,getU)(nfn_list,c(NFn,x)->id))->name);
|
||||
}
|
||||
|
||||
void nfn_free(Value* x) { dec(((NFn*)x)->obj); }
|
||||
DEF_FREE(nfn) { dec(((NFn*)x)->obj); }
|
||||
void nfn_visit(Value* x) { mm_visit(((NFn*)x)->obj); }
|
||||
void nfn_print(B x) { printRaw(c(NFnDesc,TI(nfn_list,getU)(nfn_list,c(NFn,x)->id))->name); }
|
||||
void nfnDesc_free(Value* x) { err("nfnDesc shouldn't be freed!"); }
|
||||
DEF_FREE(nfnDesc) { err("nfnDesc shouldn't be freed!"); }
|
||||
void nfnDesc_visit(Value* x) { mm_visit(((NFnDesc*)x)->name); }
|
||||
void nfnDesc_print(B x) { printf("(native function description)"); }
|
||||
|
||||
@ -47,7 +47,8 @@ void nfn_gcFn() {
|
||||
}
|
||||
void nfn_init() {
|
||||
nfn_list = emptyHVec();
|
||||
TIi(t_nfn,free) = nfn_free; TIi(t_nfnDesc,free) = nfnDesc_free;
|
||||
TIi(t_nfn,freeO) = nfn_freeO; TIi(t_nfnDesc,freeO) = nfnDesc_freeO;
|
||||
TIi(t_nfn,freeF) = nfn_freeF; TIi(t_nfnDesc,freeF) = nfnDesc_freeF;
|
||||
TIi(t_nfn,visit) = nfn_visit; TIi(t_nfnDesc,visit) = nfnDesc_visit;
|
||||
TIi(t_nfn,print) = nfn_print; TIi(t_nfnDesc,print) = nfnDesc_print;
|
||||
gc_addFn(nfn_gcFn);
|
||||
|
||||
21
src/ns.c
21
src/ns.c
@ -104,17 +104,17 @@ B ns_nameList(NSDesc* d) {
|
||||
|
||||
|
||||
|
||||
void ns_free(Value* x) {
|
||||
DEF_FREE(ns) {
|
||||
NS* c = (NS*)x;
|
||||
ptr_decR(c->desc);
|
||||
ptr_decR(c->sc);
|
||||
}
|
||||
void ns_visit(Value* x) {
|
||||
static void ns_visit(Value* x) {
|
||||
NS* c = (NS*)x;
|
||||
mm_visitP(c->desc);
|
||||
mm_visitP(c->sc);
|
||||
}
|
||||
void ns_print(B x) {
|
||||
static void ns_print(B x) {
|
||||
putchar('{');
|
||||
NSDesc* desc = c(NS,x)->desc;
|
||||
Scope* sc = c(NS,x)->sc;
|
||||
@ -134,20 +134,15 @@ void ns_print(B x) {
|
||||
putchar('}');
|
||||
}
|
||||
|
||||
void nsDesc_free(Value* x) {
|
||||
decR(((NSDesc*)x)->nameList);
|
||||
}
|
||||
void nsDesc_visit(Value* x) {
|
||||
mm_visit(((NSDesc*)x)->nameList);
|
||||
}
|
||||
void nsDesc_print(B x) {
|
||||
printf("(namespace description)");
|
||||
}
|
||||
DEF_FREE(nsDesc) { decR(((NSDesc*)x)->nameList); }
|
||||
static void nsDesc_visit(Value* x) { mm_visit(((NSDesc*)x)->nameList); }
|
||||
static void nsDesc_print(B x) { printf("(namespace description)"); }
|
||||
|
||||
|
||||
|
||||
void ns_init() {
|
||||
TIi(t_ns,free) = ns_free; TIi(t_nsDesc,free) = nsDesc_free;
|
||||
TIi(t_ns,freeO) = ns_freeO; TIi(t_nsDesc,freeO) = nsDesc_freeO;
|
||||
TIi(t_ns,freeF) = ns_freeF; TIi(t_nsDesc,freeF) = nsDesc_freeF;
|
||||
TIi(t_ns,visit) = ns_visit; TIi(t_nsDesc,visit) = nsDesc_visit;
|
||||
TIi(t_ns,print) = ns_print; TIi(t_nsDesc,print) = nsDesc_print;
|
||||
}
|
||||
|
||||
@ -42,7 +42,7 @@ void gc_tryFree(Value* v) {
|
||||
#endif
|
||||
v->type = t_freed;
|
||||
ptr_inc(v); // required as otherwise the object may free itself while not done reading its own fields
|
||||
TIi(t,free)(v);
|
||||
TIi(t,freeO)(v);
|
||||
ptr_dec(v);
|
||||
// Object may not be immediately freed if it's not a part of a cycle, but instead a descendant of one.
|
||||
// It will be freed when the cycle is freed, and the t_freed type ensures it doesn't double-free itself
|
||||
|
||||
40
src/vm.c
40
src/vm.c
@ -779,7 +779,7 @@ B m_md2Block(Block* bl, Scope* psc) {
|
||||
return tag(r, MD2_TAG);
|
||||
}
|
||||
|
||||
void scope_free(Value* x) {
|
||||
DEF_FREE(scope) {
|
||||
Scope* c = (Scope*)x;
|
||||
if (LIKELY(c->psc!=NULL)) ptr_decR(c->psc);
|
||||
if (RARE (c->ext!=NULL)) ptr_decR(c->ext);
|
||||
@ -787,7 +787,7 @@ void scope_free(Value* x) {
|
||||
u16 am = c->varAm;
|
||||
for (u32 i = 0; i < am; i++) dec(c->vars[i]);
|
||||
}
|
||||
void body_free(Value* x) {
|
||||
DEF_FREE(body) {
|
||||
Body* c = (Body*)x;
|
||||
#if JIT_START!=-1
|
||||
if(c->nvm) nvm_free(c->nvm);
|
||||
@ -795,7 +795,7 @@ void body_free(Value* x) {
|
||||
#endif
|
||||
if(c->nsDesc) ptr_decR(c->nsDesc);
|
||||
}
|
||||
void block_free(Value* x) {
|
||||
DEF_FREE(block) {
|
||||
Block* c = (Block*)x;
|
||||
ptr_decR(c->comp);
|
||||
if(c->blocks) ptr_decR(RFLD(c->blocks,BlBlocks,a));
|
||||
@ -804,13 +804,13 @@ void block_free(Value* x) {
|
||||
i32 am = c->bodyCount;
|
||||
for (i32 i = 0; i < am; i++) ptr_decR(c->bodies[i]);
|
||||
}
|
||||
void comp_free(Value* x) { Comp* c = (Comp *)x; ptr_decR(c->objs); decR(c->bc); decR(c->src); decR(c->indices); decR(c->path); }
|
||||
void funBl_free(Value* x) { FunBlock* c = (FunBlock*)x; ptr_decR(c->sc); ptr_decR(c->bl); }
|
||||
void md1Bl_free(Value* x) { Md1Block* c = (Md1Block*)x; ptr_decR(c->sc); ptr_decR(c->bl); }
|
||||
void md2Bl_free(Value* x) { Md2Block* c = (Md2Block*)x; ptr_decR(c->sc); ptr_decR(c->bl); }
|
||||
void alias_free(Value* x) { dec(((FldAlias*)x)->obj); }
|
||||
void bBlks_free(Value* x) { BlBlocks* c = (BlBlocks*)x; u16 am = c->am; for (i32 i = 0; i < am; i++) ptr_dec(c->a[i]); }
|
||||
void scExt_free(Value* x) { ScopeExt* c = (ScopeExt*)x; u16 am = c->varAm*2; for (i32 i = 0; i < am; i++) dec(c->vars[i]); }
|
||||
DEF_FREE(comp) { Comp* c = (Comp *)x; ptr_decR(c->objs); decR(c->bc); decR(c->src); decR(c->indices); decR(c->path); }
|
||||
DEF_FREE(funBl) { FunBlock* c = (FunBlock*)x; ptr_decR(c->sc); ptr_decR(c->bl); }
|
||||
DEF_FREE(md1Bl) { Md1Block* c = (Md1Block*)x; ptr_decR(c->sc); ptr_decR(c->bl); }
|
||||
DEF_FREE(md2Bl) { Md2Block* c = (Md2Block*)x; ptr_decR(c->sc); ptr_decR(c->bl); }
|
||||
DEF_FREE(alias) { dec(((FldAlias*)x)->obj); }
|
||||
DEF_FREE(bBlks) { BlBlocks* c = (BlBlocks*)x; u16 am = c->am; for (i32 i = 0; i < am; i++) ptr_dec(c->a[i]); }
|
||||
DEF_FREE(scExt) { ScopeExt* c = (ScopeExt*)x; u16 am = c->varAm*2; for (i32 i = 0; i < am; i++) dec(c->vars[i]); }
|
||||
|
||||
void scope_visit(Value* x) {
|
||||
Scope* c = (Scope*)x;
|
||||
@ -886,16 +886,16 @@ void print_vmStack() {
|
||||
|
||||
|
||||
void comp_init() {
|
||||
TIi(t_comp ,free) = comp_free; TIi(t_comp ,visit) = comp_visit; TIi(t_comp ,print) = comp_print;
|
||||
TIi(t_body ,free) = body_free; TIi(t_body ,visit) = body_visit; TIi(t_body ,print) = body_print;
|
||||
TIi(t_block ,free) = block_free; TIi(t_block ,visit) = block_visit; TIi(t_block ,print) = block_print;
|
||||
TIi(t_scope ,free) = scope_free; TIi(t_scope ,visit) = scope_visit; TIi(t_scope ,print) = scope_print;
|
||||
TIi(t_scopeExt ,free) = scExt_free; TIi(t_scopeExt ,visit) = scExt_visit; TIi(t_scopeExt ,print) = scExt_print;
|
||||
TIi(t_blBlocks ,free) = bBlks_free; TIi(t_blBlocks ,visit) = bBlks_visit; TIi(t_blBlocks ,print) = bBlks_print;
|
||||
TIi(t_fldAlias ,free) = alias_free; TIi(t_fldAlias ,visit) = alias_visit; TIi(t_fldAlias ,print) = alias_print;
|
||||
TIi(t_fun_block,free) = funBl_free; TIi(t_fun_block,visit) = funBl_visit; TIi(t_fun_block,print) = funBl_print; TIi(t_fun_block,decompose) = block_decompose;
|
||||
TIi(t_md1_block,free) = md1Bl_free; TIi(t_md1_block,visit) = md1Bl_visit; TIi(t_md1_block,print) = md1Bl_print; TIi(t_md1_block,decompose) = block_decompose; TIi(t_md1_block,m1_d)=bl_m1d;
|
||||
TIi(t_md2_block,free) = md2Bl_free; TIi(t_md2_block,visit) = md2Bl_visit; TIi(t_md2_block,print) = md2Bl_print; TIi(t_md2_block,decompose) = block_decompose; TIi(t_md2_block,m2_d)=bl_m2d;
|
||||
TIi(t_comp ,freeO) = comp_freeO; TIi(t_comp ,freeF) = comp_freeF; TIi(t_comp ,visit) = comp_visit; TIi(t_comp ,print) = comp_print;
|
||||
TIi(t_body ,freeO) = body_freeO; TIi(t_body ,freeF) = body_freeF; TIi(t_body ,visit) = body_visit; TIi(t_body ,print) = body_print;
|
||||
TIi(t_block ,freeO) = block_freeO; TIi(t_block ,freeF) = block_freeF; TIi(t_block ,visit) = block_visit; TIi(t_block ,print) = block_print;
|
||||
TIi(t_scope ,freeO) = scope_freeO; TIi(t_scope ,freeF) = scope_freeF; TIi(t_scope ,visit) = scope_visit; TIi(t_scope ,print) = scope_print;
|
||||
TIi(t_scopeExt ,freeO) = scExt_freeO; TIi(t_scopeExt ,freeF) = scExt_freeF; TIi(t_scopeExt ,visit) = scExt_visit; TIi(t_scopeExt ,print) = scExt_print;
|
||||
TIi(t_blBlocks ,freeO) = bBlks_freeO; TIi(t_blBlocks ,freeF) = bBlks_freeF; TIi(t_blBlocks ,visit) = bBlks_visit; TIi(t_blBlocks ,print) = bBlks_print;
|
||||
TIi(t_fldAlias ,freeO) = alias_freeO; TIi(t_fldAlias ,freeF) = alias_freeF; TIi(t_fldAlias ,visit) = alias_visit; TIi(t_fldAlias ,print) = alias_print;
|
||||
TIi(t_fun_block,freeO) = funBl_freeO; TIi(t_fun_block,freeF) = funBl_freeF; TIi(t_fun_block,visit) = funBl_visit; TIi(t_fun_block,print) = funBl_print; TIi(t_fun_block,decompose) = block_decompose;
|
||||
TIi(t_md1_block,freeO) = md1Bl_freeO; TIi(t_md1_block,freeF) = md1Bl_freeF; TIi(t_md1_block,visit) = md1Bl_visit; TIi(t_md1_block,print) = md1Bl_print; TIi(t_md1_block,decompose) = block_decompose; TIi(t_md1_block,m1_d)=bl_m1d;
|
||||
TIi(t_md2_block,freeO) = md2Bl_freeO; TIi(t_md2_block,freeF) = md2Bl_freeF; TIi(t_md2_block,visit) = md2Bl_visit; TIi(t_md2_block,print) = md2Bl_print; TIi(t_md2_block,decompose) = block_decompose; TIi(t_md2_block,m2_d)=bl_m2d;
|
||||
#ifndef GS_REALLOC
|
||||
allocStack((void**)&gStack, (void**)&gStackStart, (void**)&gStackEnd, sizeof(B), GS_SIZE);
|
||||
#endif
|
||||
|
||||
Loading…
Reference in New Issue
Block a user