Type to macro

This commit is contained in:
dzaima 2021-09-25 13:08:25 +03:00
parent c492de413f
commit 749b3e1e81
2 changed files with 31 additions and 36 deletions

View File

@ -444,24 +444,9 @@ void slice_print(B x) { arr_print(x); }
char* format_type(u8 u) {
switch(u) { default: return"(unknown type)";
case t_empty:return"empty"; case t_shape:return"shape";
case t_funBI:return"builtin fun"; case t_fun_block:return"fun block";
case t_md1BI:return"builtin md1"; case t_md1_block:return"md1 block";
case t_md2BI:return"builtin md2"; case t_md2_block:return"md2 block";
case t_fork:return"fork"; case t_atop:return"atop";
case t_md1D:return"md1D"; case t_md2D:return"md2D"; case t_md2H:return"md2H";
case t_i8arr :return"i8arr" ; case t_i16arr :return"i16arr" ; case t_i32arr :return"i32arr" ;
case t_i8slice:return"i8slice"; case t_i16slice:return"i16slice"; case t_i32slice:return"i32slice";
case t_c8arr :return"c8arr" ; case t_c16arr :return"c16arr" ; case t_c32arr :return"c32arr" ;
case t_c8slice:return"c8slice"; case t_c16slice:return"c16slice"; case t_c32slice:return"c32slice";
case t_harr :return"harr" ; case t_fillarr :return"fillarr" ; case t_f64arr :return"f64arr" ;
case t_hslice:return"hslice"; case t_fillslice:return"fillslice"; case t_f64slice:return"f64slice";
case t_comp:return"comp"; case t_block:return"block"; case t_body:return"body"; case t_scope:return"scope"; case t_scopeExt:return"scope extension"; case t_blBlocks: return "block list";
case t_ns:return"ns"; case t_nsDesc:return"nsDesc"; case t_fldAlias:return"alias"; case t_hashmap:return"hashmap"; case t_temp:return"temporary"; case t_nfn:return"nfn"; case t_nfnDesc:return"nfnDesc";
case t_freed:return"(freed by GC)"; case t_harrPartial:return"partHarr";
#ifdef RT_WRAP
case t_funWrap:return"wrapped function"; case t_md1Wrap:return"wrapped 1-modifier"; case t_md2Wrap:return "wrapped 2-modifier";
#endif
#define F(X) case t_##X: return #X;
FOR_TYPE(F)
#undef F
}
}
bool isPureFn(B x) { // doesn't consume

46
src/h.h
View File

@ -170,25 +170,35 @@ typedef union B {
} B;
#define b(x) ((B)(x))
#ifdef RT_WRAP
#define IF_RT_WRAP(X) X
#else
#define IF_RT_WRAP(X)
#endif
#define FOR_TYPE(F) \
/* 0*/ F(empty) \
/* 1*/ F(funBI) F(fun_block) \
/* 3*/ F(md1BI) F(md1_block) \
/* 5*/ F(md2BI) F(md2_block) \
/* 7*/ F(shape) /* doesn't get F(visited) shouldn't be unallocated by gc */ \
\
/* 8*/ F(fork) F(atop) \
/*10*/ F(md1D) F(md2D) F(md2H) \
\
/*13*/ F(harr ) F(i8arr ) F(i16arr ) F(i32arr ) F(fillarr ) F(c8arr ) F(c16arr ) F(c32arr ) F(f64arr ) \
/*19*/ F(hslice) F(i8slice) F(i16slice) F(i32slice) F(fillslice) F(c8slice) F(c16slice) F(c32slice) F(f64slice) \
\
/*25*/ F(comp) F(block) F(body) F(scope) F(scopeExt) F(blBlocks) \
/*31*/ F(ns) F(nsDesc) F(fldAlias) F(vfyObj) F(hashmap) F(temp) F(nfn) F(nfnDesc) \
/*38*/ F(freed) F(harrPartial) \
\
/*40*/ IF_RT_WRAP(F(funWrap) F(md1Wrap) F(md2Wrap))
enum Type {
/* 0*/ t_empty, // empty bucket placeholder
/* 1*/ t_funBI, t_fun_block,
/* 3*/ t_md1BI, t_md1_block,
/* 5*/ t_md2BI, t_md2_block,
/* 7*/ t_shape, // doesn't get visited, shouldn't be unallocated by gcWMd1
/* 8*/ t_fork, t_atop,
/*10*/ t_md1D, t_md2D, t_md2H,
/*13*/ t_i8arr , t_i16arr , t_i32arr , t_c8arr , t_c16arr , t_c32arr , t_f64arr , t_harr , t_fillarr ,
/*19*/ t_i8slice, t_i16slice, t_i32slice, t_c8slice, t_c16slice, t_c32slice, t_f64slice, t_hslice, t_fillslice,
/*25*/ t_comp, t_block, t_body, t_scope, t_scopeExt, t_blBlocks,
/*31*/ t_ns, t_nsDesc, t_fldAlias, t_vfyObj, t_hashmap, t_temp, t_nfn, t_nfnDesc,
/*39*/ t_freed, t_harrPartial,
#ifdef RT_WRAP
/*41*/ t_funWrap, t_md1Wrap, t_md2Wrap,
#endif
#define F(X) t_##X,
FOR_TYPE(F)
#undef F
t_COUNT
};