From 0913d3b8f2666b5822a80ede97dae233c95292db Mon Sep 17 00:00:00 2001 From: dzaima Date: Thu, 9 Sep 2021 17:18:47 +0300 Subject: [PATCH] ElType cleanup --- src/core/fillarr.c | 15 ++++++--------- src/core/stuff.h | 15 ++++++++++++++- src/h.h | 13 ------------- src/utils/mut.c | 4 ++-- 4 files changed, 22 insertions(+), 25 deletions(-) diff --git a/src/core/fillarr.c b/src/core/fillarr.c index fe46bd44..ecc910e8 100644 --- a/src/core/fillarr.c +++ b/src/core/fillarr.c @@ -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); diff --git a/src/core/stuff.h b/src/core/stuff.h index b0f6884d..11efa47c 100644 --- a/src/core/stuff.h +++ b/src/core/stuff.h @@ -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); diff --git a/src/h.h b/src/h.h index 4a740a8e..9c2efea9 100644 --- a/src/h.h +++ b/src/h.h @@ -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; -} diff --git a/src/utils/mut.c b/src/utils/mut.c index 84c646f7..b7da93ca 100644 --- a/src/utils/mut.c +++ b/src/utils/mut.c @@ -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; }