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 (unkPos!=-1) thrM("⥊: 𝕨 contained multiple computed axes");
unkPos = i;
if (!isPrim(c)) thrM("⥊: 𝕨 must consist of natural numbers or ∘ ⌊ ⌽ ↑");
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) {
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);
}
B primInd_c1(B t, B x) {
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);
return m_i32(rtLen);
}
@ -49,21 +49,21 @@ B glyph_c1(B t, B x) {
#ifdef RT_WRAP
x = rtWrap_unwrap(x);
#endif
u8 fl = v(x)->flags;
if (fl==0 || fl>rtLen) {
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_md1BI) { B r = fromUTF8l(format_pm1(c(Md1,x)->extra)); dec(x); return r; }
if (ty==t_md2BI) { B r = fromUTF8l(format_pm2(c(Md2,x)->extra)); dec(x); return r; }
if (ty==t_nfn) { B r = nfn_name(x); dec(x); return r; }
if (ty==t_fun_block) { dec(x); return m_str8l("(function block)"); }
if (ty==t_md1_block) { dec(x); return m_str8l("(1-modifier block)"); }
if (ty==t_md2_block) { dec(x); return m_str8l("(2-modifier block)"); }
if (ty==t_ns) return nsFmt(x);
return m_str32(U"(•Glyph: given object with unexpected type)");
if (isPrim(x)) {
B r = m_c32(U"+-×÷⋆√⌊⌈|¬∧∨<>≠=≤≥≡≢⊣⊢⥊∾≍↑↓↕«»⌽⍉/⍋⍒⊏⊑⊐⊒∊⍷⊔!˙˜˘¨⌜⁼´˝`∘○⊸⟜⌾⊘◶⎉⚇⍟⎊"[v(x)->flags-1]);
dec(x);
return r;
}
dec(x);
return m_c32(U"+-×÷⋆√⌊⌈|¬∧∨<>≠=≤≥≡≢⊣⊢⥊∾≍↑↓↕«»⌽⍉/⍋⍒⊏⊑⊐⊒∊⍷⊔!˙˜˘¨⌜⁼´˝`∘○⊸⟜⌾⊘◶⎉⚇⍟⎊"[fl-1]);
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_md1BI) { B r = fromUTF8l(format_pm1(c(Md1,x)->extra)); dec(x); return r; }
if (ty==t_md2BI) { B r = fromUTF8l(format_pm2(c(Md2,x)->extra)); dec(x); return r; }
if (ty==t_nfn) { B r = nfn_name(x); dec(x); return r; }
if (ty==t_fun_block) { dec(x); return m_str8l("(function block)"); }
if (ty==t_md1_block) { dec(x); return m_str8l("(1-modifier block)"); }
if (ty==t_md2_block) { dec(x); return m_str8l("(2-modifier block)"); }
if (ty==t_ns) return nsFmt(x);
return m_str32(U"(•Glyph: given object with unexpected type)");
}
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
if (isCallable(x)) {
if (v(x)->flags) return true;
if (isPrim(x)) return true;
B2B dcf = TI(x,decompose);
B xd = dcf(inc(x));
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 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
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_i64(B x) { return isF64(x) && x.f==(f64)(i64)x.f; }
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 {
@ -437,8 +440,6 @@ typedef B (*M2C2)(Md2D*, B, B);
#define IGet(X,N)({ Arr* x_ = a(X); TIv(x_,get)(x_,N); })
#define Get(X,N) X##_get(X##_arr,N)
static bool q_N(B b) { return b.u==bi_N.u; }
// refcount
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)