more precise flags usage

This commit is contained in:
dzaima 2021-09-16 21:54:24 +03:00
parent cd5f50e3eb
commit 427d508324
4 changed files with 22 additions and 20 deletions

View File

@ -94,6 +94,7 @@ B shape_c2(B t, B w, B x) {
if (isArr(c) || !isVal(c)) thrM("⥊: 𝕨 must consist of natural numbers or ∘ ⌊ ⌽ ↑"); if (isArr(c) || !isVal(c)) thrM("⥊: 𝕨 must consist of natural numbers or ∘ ⌊ ⌽ ↑");
if (unkPos!=-1) thrM("⥊: 𝕨 contained multiple computed axes"); if (unkPos!=-1) thrM("⥊: 𝕨 contained multiple computed axes");
unkPos = i; unkPos = i;
if (!isPrim(c)) thrM("⥊: 𝕨 must consist of natural numbers or ∘ ⌊ ⌽ ↑");
unkInd = ((i32)v(c)->flags) - 1; unkInd = ((i32)v(c)->flags) - 1;
} }
} }

View File

@ -29,13 +29,13 @@ B type_c1(B t, B x) {
B decp_c1(B t, B x) { B decp_c1(B t, B x) {
if (!isVal(x)) return m_v2(m_i32(-1), x); if (!isVal(x)) return m_v2(m_i32(-1), x);
if (v(x)->flags) return m_v2(m_i32(0), x); if (isPrim(x)) return m_v2(m_i32(0), x);
return TI(x,decompose)(x); return TI(x,decompose)(x);
} }
B primInd_c1(B t, B x) { B primInd_c1(B t, B x) {
if (!isVal(x)) return m_i32(rtLen); if (!isVal(x)) return m_i32(rtLen);
if (v(x)->flags) { B r = m_i32(v(x)->flags-1); dec(x); return r; } if (isPrim(x)) { B r = m_i32(v(x)->flags-1); dec(x); return r; }
dec(x); dec(x);
return m_i32(rtLen); return m_i32(rtLen);
} }
@ -49,8 +49,11 @@ B glyph_c1(B t, B x) {
#ifdef RT_WRAP #ifdef RT_WRAP
x = rtWrap_unwrap(x); x = rtWrap_unwrap(x);
#endif #endif
u8 fl = v(x)->flags; if (isPrim(x)) {
if (fl==0 || fl>rtLen) { B r = m_c32(U"+-×÷⋆√⌊⌈|¬∧∨<>≠=≤≥≡≢⊣⊢⥊∾≍↑↓↕«»⌽⍉/⍋⍒⊏⊑⊐⊒∊⍷⊔!˙˜˘¨⌜⁼´˝`∘○⊸⟜⌾⊘◶⎉⚇⍟⎊"[v(x)->flags-1]);
dec(x);
return r;
}
u8 ty = v(x)->type; u8 ty = v(x)->type;
if (ty==t_funBI) { B r = fromUTF8l(format_pf (c(Fun,x)->extra)); dec(x); return r; } if (ty==t_funBI) { B r = fromUTF8l(format_pf (c(Fun,x)->extra)); dec(x); return r; }
if (ty==t_md1BI) { B r = fromUTF8l(format_pm1(c(Md1,x)->extra)); dec(x); return r; } if (ty==t_md1BI) { B r = fromUTF8l(format_pm1(c(Md1,x)->extra)); dec(x); return r; }
@ -61,9 +64,6 @@ B glyph_c1(B t, B x) {
if (ty==t_md2_block) { dec(x); return m_str8l("(2-modifier block)"); } if (ty==t_md2_block) { dec(x); return m_str8l("(2-modifier block)"); }
if (ty==t_ns) return nsFmt(x); if (ty==t_ns) return nsFmt(x);
return m_str32(U"(•Glyph: given object with unexpected type)"); return m_str32(U"(•Glyph: given object with unexpected type)");
}
dec(x);
return m_c32(U"+-×÷⋆√⌊⌈|¬∧∨<>≠=≤≥≡≢⊣⊢⥊∾≍↑↓↕«»⌽⍉/⍋⍒⊏⊑⊐⊒∊⍷⊔!˙˜˘¨⌜⁼´˝`∘○⊸⟜⌾⊘◶⎉⚇⍟⎊"[fl-1]);
} }
B repr_c1(B t, B x) { B repr_c1(B t, B x) {

View File

@ -459,7 +459,7 @@ char* format_type(u8 u) {
} }
bool isPureFn(B x) { // doesn't consume bool isPureFn(B x) { // doesn't consume
if (isCallable(x)) { if (isCallable(x)) {
if (v(x)->flags) return true; if (isPrim(x)) return true;
B2B dcf = TI(x,decompose); B2B dcf = TI(x,decompose);
B xd = dcf(inc(x)); B xd = dcf(inc(x));
B* xdp = harr_ptr(xd); B* xdp = harr_ptr(xd);

View File

@ -338,7 +338,8 @@ static inline bool isNum(B x) { return isF64(x); }
static inline bool isAtm(B x) { return !isArr(x); } static inline bool isAtm(B x) { return !isArr(x); }
static inline bool isCallable(B x) { return isMd(x) | isFun(x); } static inline bool isCallable(B x) { return isMd(x) | isFun(x); }
static inline bool noFill(B x) { return x.u == bi_noFill.u; } static inline bool isPrim(B x) { return isCallable(x) && v(x)->flags; }
// make objects // make objects
static B m_f64(f64 n) { assert(isF64(b(n))); return b(n); } // assert just to make sure we're actually creating a float static B m_f64(f64 n) { assert(isF64(b(n))); return b(n); } // assert just to make sure we're actually creating a float
@ -366,6 +367,8 @@ static bool q_i16(B x) { return isF64(x) && x.f==(f64)(i16)x.f; }
static bool q_i32(B x) { return isF64(x) && x.f==(f64)(i32)x.f; } static bool q_i32(B x) { return isF64(x) && x.f==(f64)(i32)x.f; }
static bool q_i64(B x) { return isF64(x) && x.f==(f64)(i64)x.f; } static bool q_i64(B x) { return isF64(x) && x.f==(f64)(i64)x.f; }
static bool q_f64(B x) { return isF64(x); } static bool q_f64(B x) { return isF64(x); }
static bool q_N (B x) { return x.u==bi_N.u; } // is ·
static bool noFill(B x) { return x.u == bi_noFill.u; }
typedef struct Slice { typedef struct Slice {
@ -437,8 +440,6 @@ typedef B (*M2C2)(Md2D*, B, B);
#define IGet(X,N)({ Arr* x_ = a(X); TIv(x_,get)(x_,N); }) #define IGet(X,N)({ Arr* x_ = a(X); TIv(x_,get)(x_,N); })
#define Get(X,N) X##_get(X##_arr,N) #define Get(X,N) X##_get(X##_arr,N)
static bool q_N(B b) { return b.u==bi_N.u; }
// refcount // refcount
static bool reusable(B x) { return v(x)->refc==1; } static bool reusable(B x) { return v(x)->refc==1; }
#define DEF_FREE(TY) static inline void TY##_freeO(Value* x); static void TY##_freeF(Value* x) { TY##_freeO(x); mm_free(x); } static inline void TY##_freeO(Value* x) #define DEF_FREE(TY) static inline void TY##_freeO(Value* x); static void TY##_freeF(Value* x) { TY##_freeO(x); mm_free(x); } static inline void TY##_freeO(Value* x)