ElType cleanup

This commit is contained in:
dzaima 2021-09-09 17:18:47 +03:00
parent d568363144
commit 0913d3b8f2
4 changed files with 22 additions and 25 deletions

View File

@ -4,14 +4,14 @@ B asFill(B x) { // consumes
if (isArr(x)) {
u8 xe = TI(x,elType);
usz ia = a(x)->ia;
if (xe<=el_f64) {
if (elNum(xe)) {
i8* rp; B r = m_i8arrc(&rp, x);
for (usz i = 0; i < ia; i++) rp[i] = 0;
dec(x);
return r;
}
if (xe==el_c32) {
u32* rp; B r = m_c32arrc(&rp, x);
if (elChr(xe)) {
u8* rp; B r = m_c8arrc(&rp, x);
for (usz i = 0; i < ia; i++) rp[i] = ' ';
dec(x);
return r;
@ -92,9 +92,7 @@ NOINLINE bool fillEqualR(B w, B x) { // doesn't consume; both args must be array
u8 we = TI(w,elType);
u8 xe = TI(x,elType);
if (we!=el_B && xe!=el_B) {
if (we==el_c32 ^ xe==el_c32) return false;
assert(we==el_c32 & xe==el_c32 || we<=el_f64 & xe<=el_f64);
return true;
return elChr(we) == elChr(xe);
}
BS2B xgetU = TI(x,getU);
BS2B wgetU = TI(w,getU);
@ -131,12 +129,11 @@ B withFill(B x, B fill) { // consumes both
usz ia = a(x)->ia;
if (isNum(fill)) {
B r = num_squeeze(x);
if (TI(r,elType)<=el_f64) return r;
if (elNum(TI(r,elType))) return r;
x = r;
} else if (isC32(fill)) {
B r = chr_squeeze(x);
u8 re = TI(r,elType);
if (re>=el_c8 && re<=el_c32) return r;
if (elChr(TI(r,elType))) return r;
x = r;
}
FillArr* r = m_arr(fsizeof(FillArr,a,B,ia), t_fillarr, ia);

View File

@ -91,7 +91,8 @@ static B m_v1(B a ); // consumes all
static B m_v2(B a, B b ); // consumes all
static B m_v3(B a, B b, B c ); // consumes all
static B m_v4(B a, B b, B c, B d); // consumes all
static bool isNumEl(u8 elt) { return elt<=el_f64; }
// random stuff
static bool uszMul(usz* c, usz n) {
return __builtin_mul_overflow(*c, n, c);
@ -101,6 +102,18 @@ static usz uszMulT(usz a, usz b) {
return a;
}
static u8 selfElType(B x) { // guaranteed to fit fill
if (isF64(x)) return q_i16(x)? (q_i8(x)? el_i8 : el_i16) : (q_i32(x)? el_i32 : el_f64);
if (isC32(x)) return el_c32;
return el_B;
}
static bool elChr(u8 x) {
return x>=el_c8 && x<=el_c32;
}
static bool elNum(u8 x) {
return x<=el_f64;
}
// string stuff
B m_str8l(char* s);

13
src/h.h
View File

@ -539,16 +539,3 @@ static inline u64 nsTime() {
clock_gettime(CLOCK_REALTIME, &t);
return (u64)(t.tv_sec*1000000000ll + t.tv_nsec);
}
static u8 fillElType(B x) {
if (isNum(x)) return el_i32; // TODO move to 8
if (isC32(x)) return el_c32;
return el_B;
}
static u8 selfElType(B x) { // guaranteed to fit fill
if (isF64(x)) return q_i16(x)? (q_i8(x)? el_i8 : el_i16) : (q_i32(x)? el_i32 : el_f64);
if (isC32(x)) return el_c32;
return el_B;
}

View File

@ -53,8 +53,8 @@ void mutF_init() {
for (u8 j = 0; j <= el_MAX; j++) {
u8 el;
if (i==el_MAX|j==el_MAX) el = i>j?j:i;
else if (i<=el_f64 && j<=el_f64) el = i>j?i:j;
else if (i>=el_c8 && i<=el_c32 && j>=el_c8 && j<=el_c32) el = i>j?i:j;
else if (elNum(i) && elNum(j)) el = i>j?i:j;
else if (elChr(i) && elChr(j)) el = i>j?i:j;
else el = el_B;
el_orArr[i*16 + j] = el;
}