slice checking macro refactor

This commit is contained in:
dzaima 2023-04-29 13:22:39 +03:00
parent ba1b853936
commit 229a32237a
2 changed files with 7 additions and 7 deletions

View File

@ -14,11 +14,11 @@ static B* arrV_bptr(Arr* x) {
if (PTY(x)==t_fillslice) return ((FillSlice*)x)->a;
return NULL;
}
static void* tyarr_ptr(B x) { assert(IS_ARR(TY(x))); return c(TyArr,x)->a; }
static void* tyslice_ptr(B x) { assert(IS_SLICE(TY(x))); return c(TySlice,x)->a; }
static void* tyany_ptr(B x) { assert(IS_ARR(TY(x)) || IS_SLICE(TY(x)));
u8 t = TY(x);
return IS_SLICE(t)? c(TySlice,x)->a : c(TyArr,x)->a;
static void* tyarr_ptr(B x) { assert(IS_ANY_ARR(TY(x)) && !IS_SLICE(TY(x))); return c(TyArr,x)->a; }
static void* tyslice_ptr(B x) { assert(IS_ANY_ARR(TY(x)) && IS_SLICE(TY(x))); return c(TySlice,x)->a; }
static void* tyany_ptr(B x) {
assert(IS_ANY_ARR(TY(x)));
return IS_SLICE(TY(x))? c(TySlice,x)->a : c(TyArr,x)->a;
}
#define M_TYARR(WM, OVER, MID, RV, PRE) { PRE \

View File

@ -293,8 +293,8 @@ enum Type {
#undef F
t_COUNT
};
#define IS_SLICE(T) ((T)>=t_hslice & (T)<=t_f64slice)
#define IS_ARR(T) ((T)>=t_harr & (T)<=t_bitarr)
#define IS_ANY_ARR(T) ((T)>=t_hslice & (T)<=t_bitarr)
#define IS_SLICE(T) ((T)<=t_f64slice)
#define TO_SLICE(T) ((T) + t_hslice - t_harr) // Assumes T!=t_bitarr
enum ElType { // a⌈b shall return the type that can store both, if possible