diff --git a/src/builtins/sfns.c b/src/builtins/sfns.c index 7e95ab69..304d71a9 100644 --- a/src/builtins/sfns.c +++ b/src/builtins/sfns.c @@ -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; } } diff --git a/src/builtins/sysfn.c b/src/builtins/sysfn.c index 71cb2899..82bef4cd 100644 --- a/src/builtins/sysfn.c +++ b/src/builtins/sysfn.c @@ -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) { diff --git a/src/core/stuff.c b/src/core/stuff.c index 2a809308..a1e6a35d 100644 --- a/src/core/stuff.c +++ b/src/core/stuff.c @@ -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); diff --git a/src/h.h b/src/h.h index 6960ec50..3b570b20 100644 --- a/src/h.h +++ b/src/h.h @@ -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)