add IS_TYSLICE & SLICE_TO_ARR, clean up array/slice check names
IS_SLICE → ARR_IS_SLICE as it assumes the argument type is already an array type
This commit is contained in:
parent
ede87b4800
commit
1c77e3b06d
@ -1480,7 +1480,7 @@ static u8 typeOfCast(CastType t) {
|
||||
}
|
||||
static B set_bit_result(B r, u8 rt, ur rr, usz rl, usz *sh) {
|
||||
// Cast to output type
|
||||
v(r)->type = IS_SLICE(v(r)->type) ? TO_SLICE(rt) : rt;
|
||||
v(r)->type = ARR_IS_SLICE(v(r)->type) ? ARR_TO_SLICE(rt) : rt;
|
||||
// Adjust shape
|
||||
Arr* a = a(r);
|
||||
if (rr<=1) {
|
||||
@ -1513,7 +1513,7 @@ B bitcast_impl(B el0, B el1, B x) {
|
||||
if (rl>=USZ_MAX) thrM("•bit._cast: output too large");
|
||||
B r = convert(xct, x);
|
||||
u8 rt = typeOfCast(rct);
|
||||
if (rt==t_bitarr && (!reusable(r) || IS_SLICE(TY(r)))) {
|
||||
if (rt==t_bitarr && (!reusable(r) || ARR_IS_SLICE(TY(r)))) {
|
||||
r = taga(copy(xct, r));
|
||||
} else if (!reusable(r)) {
|
||||
B r0 = incG(r);
|
||||
@ -1580,7 +1580,7 @@ B bitop1(B f, B x, enum BitOp1 op, char* name) {
|
||||
u8 rt = typeOfCast((CastType){ rw, 0 });
|
||||
u64* xp = tyany_ptr(x);
|
||||
B r; u64* rp;
|
||||
if (!reusable(x) || IS_SLICE(TY(x))) {
|
||||
if (!reusable(x) || ARR_IS_SLICE(TY(x))) {
|
||||
Arr* ra = m_arr(offsetof(TyArr,a) + (n+7)/8, rt, n>>rws);
|
||||
arr_shCopyUnchecked(ra, x);
|
||||
r = taga(ra); rp = tyany_ptr(r);
|
||||
|
||||
@ -14,15 +14,15 @@ static B* arr_bptr(B x) { Arr* xa=a(x); if (HEURISTIC(true)) { ARRV_BPTR_BODY; }
|
||||
static B* arrv_bptr(Arr* xa) { if (HEURISTIC(true)) { ARRV_BPTR_BODY; } return NULL; }
|
||||
|
||||
static void* tyarrv_ptr(TyArr* x) {
|
||||
assert(IS_ANY_ARR(PTY(x)) && !IS_SLICE(PTY(x)));
|
||||
assert(IS_ANY_ARR(PTY(x)) && !IS_TYSLICE(PTY(x)));
|
||||
return x->a;
|
||||
}
|
||||
static void* tyanyv_ptr(Arr* x) {
|
||||
assert(IS_ANY_ARR(PTY(x)));
|
||||
return IS_SLICE(PTY(x))? ((TySlice*)x)->a : ((TyArr*)x)->a;
|
||||
return ARR_IS_SLICE(PTY(x))? ((TySlice*)x)->a : ((TyArr*)x)->a;
|
||||
}
|
||||
static void* tyslicev_ptr(Arr* x) {
|
||||
assert(IS_SLICE(PTY(x)));
|
||||
assert(IS_TYSLICE(PTY(x)));
|
||||
return ((TySlice*)x)->a;
|
||||
}
|
||||
|
||||
@ -74,7 +74,7 @@ extern u8 const arrTypeBitsLog[];
|
||||
SHOULD_INLINE void arr_check_size(u64 sz, u8 type, u64 ia) {
|
||||
if (DEBUG) {
|
||||
assert(IS_ANY_ARR(type) || type==t_harrPartial);
|
||||
if (!IS_SLICE(type)) {
|
||||
if (!ARR_IS_SLICE(type)) {
|
||||
if (type==t_harr || type==t_harrPartial) assert(sz >= fsizeof(HArr,a,B,ia));
|
||||
else assert(sz >= offsetof(TyArr,a) + (((ia<<arrTypeBitsLog(type))+7)>>3));
|
||||
}
|
||||
@ -95,7 +95,7 @@ SHOULD_INLINE u8 kCellWidthLog(B x, ur k) {
|
||||
SHOULD_INLINE u8 cellWidthLog(B x) { return kCellWidthLog(x, 1); }
|
||||
|
||||
static Arr* m_tyslice(void* data, Arr* parent, u8 type, ux ia) {
|
||||
assert(IS_ANY_ARR(type) && IS_SLICE(type));
|
||||
assert(IS_ANY_ARR(type) && ARR_IS_SLICE(type));
|
||||
Arr* a = m_arr(sizeof(TySlice), type, ia);
|
||||
((TySlice*) a)->p = parent;
|
||||
((TySlice*) a)->a = data;
|
||||
|
||||
@ -140,7 +140,7 @@ B withFill(B x, B fill) { // consumes both
|
||||
B* xbp = arr_bptr(x);
|
||||
if (xbp!=NULL) {
|
||||
Arr* xa = a(x);
|
||||
if (IS_SLICE(PTY(xa))) xa = ptr_inc(((Slice*)xa)->p);
|
||||
if (ARR_IS_SLICE(PTY(xa))) xa = ptr_inc(((Slice*)xa)->p);
|
||||
else ptr_inc(xa);
|
||||
r = m_fillslice(xa, xbp, ia, fill);
|
||||
} else {
|
||||
|
||||
10
src/h.h
10
src/h.h
@ -267,10 +267,12 @@ enum Type {
|
||||
#undef F
|
||||
t_COUNT
|
||||
};
|
||||
#define IS_ANY_ARR(T) ((T)>=t_hslice & (T)<=t_bitarr)
|
||||
#define IS_DIRECT_TYARR(T) (((T)>=t_i8arr) & ((T)<=t_bitarr))
|
||||
#define IS_SLICE(T) ((T)<=t_f64slice)
|
||||
#define TO_SLICE(T) ((T) + t_hslice - t_harr) // Assumes T!=t_bitarr
|
||||
#define IS_ANY_ARR(T) ({ u8 ct_=(T); ct_>=t_hslice & ct_<=t_bitarr; })
|
||||
#define IS_DIRECT_TYARR(T) ({ u8 ct_=(T); ct_>=t_i8arr & ct_<=t_bitarr; })
|
||||
#define ARR_IS_SLICE(T) ((T)<=t_f64slice)
|
||||
#define IS_TYSLICE(T) ({ u8 ct_=(T); ct_>=t_i8slice & ct_<=t_f64slice; })
|
||||
#define ARR_TO_SLICE(T) ((T) + t_hslice - t_harr) // requires T!=t_bitarr
|
||||
#define SLICE_TO_ARR(T) ((T) + t_harr - t_hslice)
|
||||
|
||||
enum ElType { // if X can store a superset of elements of Y, X > Y
|
||||
el_bit=0,
|
||||
|
||||
Loading…
Reference in New Issue
Block a user