add best effort guesses for many builtin error messages

This commit is contained in:
tankorsmash 2025-02-05 19:40:27 -05:00
parent dd5d17ca83
commit 63ee20b6fe
9 changed files with 37 additions and 37 deletions

View File

@ -236,4 +236,4 @@ bool eequal(B w, B x) { // doesn't consume
if (we==el_f64 && xe==el_f64) return eequalFloat(f64any_ptr(w), f64any_ptr(x), ia); if (we==el_f64 && xe==el_f64) return eequalFloat(f64any_ptr(w), f64any_ptr(x), ia);
if (RARE(we==el_B || xe==el_B)) return eequalSlow(w, x, ia); if (RARE(we==el_B || xe==el_B)) return eequalSlow(w, x, ia);
return equalTyped(w, x, we, xe, ia); return equalTyped(w, x, we, xe, ia);
} }

View File

@ -103,13 +103,13 @@ static i64 (*const sum_small_fns[])(void*, usz) = { sum_small_i8, sum_small_i16,
static f64 (*const sum_fns[])(void*, usz, f64) = { sum_i8, sum_i16, sum_i32, sum_f64 }; static f64 (*const sum_fns[])(void*, usz, f64) = { sum_i8, sum_i16, sum_i32, sum_f64 };
B sum_c1(B t, B x) { B sum_c1(B t, B x) {
if (isAtm(x) || RNK(x)!=1) thrF("•math.Sum𝕩: Argument must be a list (%H ≡ ≢𝕩)", x); if (isAtm(x) || RNK(x)!=1) thrF("•math.Sum𝕩: 𝕩 must be a list (%H ≡ ≢𝕩)", x);
usz ia = IA(x); usz ia = IA(x);
if (ia==0) { decG(x); return m_f64(0); } if (ia==0) { decG(x); return m_f64(0); }
u8 xe = TI(x,elType); u8 xe = TI(x,elType);
if (!elNum(xe)) { if (!elNum(xe)) {
x = any_squeeze(x); xe = TI(x,elType); x = any_squeeze(x); xe = TI(x,elType);
if (!elNum(xe)) thrF("•math.Sum𝕩: Argument elements must be numbers", x); if (!elNum(xe)) thrF("•math.Sum𝕩: 𝕩 elements must be numbers", x);
} }
f64 r; f64 r;
void* xv = tyany_ptr(x); void* xv = tyany_ptr(x);
@ -180,7 +180,7 @@ static f64 (*const min_fns[])(void*, usz) = { min_i8, min_i16, min_i32, min_f64
static f64 (*const max_fns[])(void*, usz) = { max_i8, max_i16, max_i32, max_f64 }; static f64 (*const max_fns[])(void*, usz) = { max_i8, max_i16, max_i32, max_f64 };
B fold_c1(Md1D* d, B x) { B f = d->f; B fold_c1(Md1D* d, B x) { B f = d->f;
if (isAtm(x) || RNK(x)!=1) thrF("´𝕩: Argument must be a list (%H ≡ ≢𝕩)", x); if (isAtm(x) || RNK(x)!=1) thrF("´𝕩: 𝕩 must be a list (%H ≡ ≢𝕩)", x);
usz ia = IA(x); usz ia = IA(x);
if (ia<=2) { if (ia<=2) {
if (ia==2) { if (ia==2) {

View File

@ -204,7 +204,7 @@ extern i8 (*const simd_count_i8)(u16*, u16*, void*, u64, i8);
#define SORT_C1 CAT(GRADE_UD(and,or),c1) #define SORT_C1 CAT(GRADE_UD(and,or),c1)
B SORT_C1(B t, B x) { B SORT_C1(B t, B x) {
if (isAtm(x) || RNK(x)==0) thrM(GRADE_UD("","")": Argument cannot have rank 0"); if (isAtm(x) || RNK(x)==0) thrM(GRADE_UD("","")"𝕩: 𝕩 cannot have rank 0");
usz n = *SH(x); usz n = *SH(x);
if (n <= 1 || FL_HAS(x,GRADE_UD(fl_asc,fl_dsc))) return x; if (n <= 1 || FL_HAS(x,GRADE_UD(fl_asc,fl_dsc))) return x;
if (RNK(x)!=1) return IA(x)<=1? x : bqn_merge(SORT_C1(t, toCells(x)), 0); if (RNK(x)!=1) return IA(x)<=1? x : bqn_merge(SORT_C1(t, toCells(x)), 0);
@ -278,7 +278,7 @@ extern B grade_bool(B x, usz ia, bool up); // slash.c
#define GRADE_CHR GRADE_UD("⍋","⍒") #define GRADE_CHR GRADE_UD("⍋","⍒")
B GRADE_CAT(c1)(B t, B x) { B GRADE_CAT(c1)(B t, B x) {
if (isAtm(x) || RNK(x)==0) thrM(GRADE_CHR": Argument cannot be a unit"); if (isAtm(x) || RNK(x)==0) thrM(GRADE_CHR"𝕩: 𝕩 cannot be a unit");
if (RNK(x)>1) x = toCells(x); if (RNK(x)>1) x = toCells(x);
usz ia = IA(x); usz ia = IA(x);
B r; B r;
@ -292,7 +292,7 @@ B GRADE_CAT(c1)(B t, B x) {
u8 xe = TI(x,elType); u8 xe = TI(x,elType);
if (xe==el_bit) return grade_bool(x, ia, GRADE_UD(1,0)); if (xe==el_bit) return grade_bool(x, ia, GRADE_UD(1,0));
if (ia>I32_MAX) thrM(GRADE_CHR": Argument too large"); if (ia>I32_MAX) thrM(GRADE_CHR"𝕩: 𝕩 too large");
i32* rp; r = m_i32arrv(&rp, ia); i32* rp; r = m_i32arrv(&rp, ia);
if (xe==el_i8 && ia>8) { if (xe==el_i8 && ia>8) {
i8* xp = i8any_ptr(x); usz n=ia; i8* xp = i8any_ptr(x); usz n=ia;
@ -421,13 +421,13 @@ extern B select_c2(B,B,B);
extern B mul_c2(B,B,B); extern B mul_c2(B,B,B);
B GRADE_CAT(c2)(B t, B w, B x) { B GRADE_CAT(c2)(B t, B w, B x) {
if (isAtm(w) || RNK(w)==0) thrM(GRADE_CHR": 𝕨 must have rank≥1"); if (isAtm(w) || RNK(w)==0) thrM("𝕨"GRADE_CHR"𝕩: 𝕨 must have rank≥1");
if (isAtm(x)) x = m_unit(x); if (isAtm(x)) x = m_unit(x);
ur wr = RNK(w); ur wr = RNK(w);
if (wr > 1) { if (wr > 1) {
ur xr = RNK(x); ur xr = RNK(x);
if (wr > xr+1) thrM(GRADE_CHR": =𝕨 cannot be greater than =𝕩"); if (wr > xr+1) thrM("𝕨"GRADE_CHR"𝕩": =𝕨 cannot be greater than =𝕩");
i32 nxr = xr-wr+1; i32 nxr = xr-wr+1;
x = toKCells(x, nxr); x = toKCells(x, nxr);
w = toCells(w); w = toCells(w);
@ -466,11 +466,11 @@ B GRADE_CAT(c2)(B t, B w, B x) {
} }
goto done; goto done;
} }
if (wia>I32_MAX-10) thrM(GRADE_CHR": 𝕨 too big"); if (wia>I32_MAX-10) thrM("𝕨"GRADE_CHR"𝕩: 𝕨 too big");
u8 fl = GRADE_UD(fl_asc,fl_dsc); u8 fl = GRADE_UD(fl_asc,fl_dsc);
if (CHECK_VALID && !FL_HAS(w,fl)) { if (CHECK_VALID && !FL_HAS(w,fl)) {
if (!CAT(isSorted,GRADE_UD(Up,Down))(w)) thrM(GRADE_CHR": 𝕨 must be sorted"GRADE_UD(," in descending order")); if (!CAT(isSorted,GRADE_UD(Up,Down))(w)) thrM("𝕨"GRADE_CHR"𝕩: 𝕨 must be sorted"GRADE_UD(," in descending order"));
FL_SET(w, fl); FL_SET(w, fl);
} }

View File

@ -77,7 +77,7 @@ static B group_simple(B w, B x, ur xr, usz wia, usz xn, usz* xsh, u8 we) {
case el_bit: ria = xn? 1+bit_has(wp0,xn,1) : wia? bitp_get(wp0,0) : 0; break; case el_bit: ria = xn? 1+bit_has(wp0,xn,1) : wia? bitp_get(wp0,0) : 0; break;
} }
#undef CASE #undef CASE
if (bad) thrM("⊔: 𝕨 can't contain elements less than ¯1"); if (bad) thrM("𝕨𝕩: 𝕨 can't contain elements less than ¯1");
if (ria > (i64)(USZ_MAX)) thrOOM(); if (ria > (i64)(USZ_MAX)) thrOOM();
Arr* r = m_fillarr0p(ria); Arr* r = m_fillarr0p(ria);
@ -261,7 +261,7 @@ static B group_simple(B w, B x, ur xr, usz wia, usz xn, usz* xsh, u8 we) {
extern GLOBAL B rt_group; extern GLOBAL B rt_group;
B group_c2(B t, B w, B x) { B group_c2(B t, B w, B x) {
if (isAtm(x)) thrM("⊔: 𝕩 must be an array"); if (isAtm(x)) thrM("𝕨𝕩: 𝕩 must be an array");
ur xr = RNK(x); ur xr = RNK(x);
if (isArr(w) && RNK(w)==1 && xr>=1) { if (isArr(w) && RNK(w)==1 && xr>=1) {
u8 we = TI(w,elType); u8 we = TI(w,elType);
@ -273,7 +273,7 @@ B group_c2(B t, B w, B x) {
usz wia = IA(w); usz wia = IA(w);
usz* xsh = SH(x); usz* xsh = SH(x);
usz xn = *xsh; usz xn = *xsh;
if (wia-(u64)xn > 1) thrF("⊔: ≠𝕨 must be either ≠𝕩 or one bigger (%s≡≠𝕨, %s≡≠𝕩)", wia, xn); if (wia-(u64)xn > 1) thrF("𝕨𝕩: ≠𝕨 must be either ≠𝕩 or one bigger (%s≡≠𝕨, %s≡≠𝕩)", wia, xn);
return group_simple(w, x, xr, wia, xn, xsh, we); return group_simple(w, x, xr, wia, xn, xsh, we);
} }
} }

View File

@ -85,9 +85,9 @@ FOR_VARIATION(F)
STATIC_GLOBAL B listVariations_def; STATIC_GLOBAL B listVariations_def;
B listVariations_c2(B t, B w, B x) { B listVariations_c2(B t, B w, B x) {
if (!isArr(x)) thrM("•internal.ListVariations: 𝕩 must be an array"); if (!isArr(x)) thrM("𝕨•internal.ListVariations𝕩: 𝕩 must be an array");
if (!isArr(w) || RNK(w)!=1) thrM("•internal.ListVariations: 𝕨 must be a list"); if (!isArr(w) || RNK(w)!=1) thrM("𝕨•internal.ListVariations𝕩: 𝕨 must be a list");
usz wia = IA(w); usz wia = IA(w);
SGetU(w) SGetU(w)
bool c_incr=false, c_rmFill=false; bool c_incr=false, c_rmFill=false;
@ -95,7 +95,7 @@ B listVariations_c2(B t, B w, B x) {
u32 c = o2c(GetU(w, i)); u32 c = o2c(GetU(w, i));
if (c=='i') c_incr=true; if (c=='i') c_incr=true;
else if (c=='f') c_rmFill=true; else if (c=='f') c_rmFill=true;
else thrF("internal.ListVariations: Unknown option '%c' in 𝕨", c); else thrF("𝕨internal.ListVariations𝕩: Unknown option '%c' in 𝕨", c);
} }
decG(w); decG(w);
@ -164,13 +164,13 @@ static bool u8_get(u8** cv, u8* cE, const char* x) {
STATIC_GLOBAL B variation_refs; STATIC_GLOBAL B variation_refs;
B variation_c2(B t, B w, B x) { B variation_c2(B t, B w, B x) {
if (!isArr(w)) thrM("•internal.Variation: Non-array 𝕨"); if (!isArr(w)) thrM("𝕨•internal.Variation𝕩: Non-array 𝕨");
if (!isArr(x)) thrM("•internal.Variation: Non-array 𝕩"); if (!isArr(x)) thrM("𝕨•internal.Variation𝕩: Non-array 𝕩");
usz xia = IA(x); usz xia = IA(x);
C8Arr* wc = toC8Arr(w); C8Arr* wc = toC8Arr(w);
u8* wp = c8arrv_ptr(wc); u8* wp = c8arrv_ptr(wc);
u8* wpE = wp+PIA(wc); u8* wpE = wp+PIA(wc);
if (PIA(wc)==0) thrM("•internal.Variation: Zero-length 𝕨"); if (PIA(wc)==0) thrM("𝕨•internal.Variation𝕩: Zero-length 𝕨");
B res; B res;
if (*wp == 'A' || *wp == 'S') { if (*wp == 'A' || *wp == 'S') {
bool slice = *wp == 'S'; bool slice = *wp == 'S';
@ -192,7 +192,7 @@ B variation_c2(B t, B w, B x) {
NOGC_E; NOGC_E;
res = taga(r); res = taga(r);
} else thrF("•internal.Variation: Bad type \"%R\"", taga(wc)); } else thrF("𝕨•internal.Variation𝕩: Bad type \"%R\"", taga(wc));
if (slice) { if (slice) {
Arr* slice = TI(res,slice)(incG(res), 0, IA(res)); Arr* slice = TI(res,slice)(incG(res), 0, IA(res));
@ -207,8 +207,8 @@ B variation_c2(B t, B w, B x) {
} }
variation_refs = vec_addN(variation_refs, incG(res)); variation_refs = vec_addN(variation_refs, incG(res));
} }
if (wp!=wpE) thrM("•internal.Variation: Bad 𝕨"); if (wp!=wpE) thrM("𝕨•internal.Variation𝕩: Bad 𝕨");
} else thrM("•internal.Variation: Bad start of 𝕨"); } else thrM("𝕨•internal.Variation𝕩: Bad start of 𝕨");
decG(x); decG(x);
ptr_dec(wc); ptr_dec(wc);
return res; return res;
@ -257,7 +257,7 @@ static B unshare(B x) {
for (usz i = 0; i < xia; i++) rp[i] = unshare(xp[i]); for (usz i = 0; i < xia; i++) rp[i] = unshare(xp[i]);
return unshareShape(r); return unshareShape(r);
} }
default: thrF("•internal.Unshare: Cannot unshare array with type %i=%S", TY(x), type_repr(TY(x))); default: thrF("𝕨•internal.Unshare𝕩: Cannot unshare array with type %i=%S", TY(x), type_repr(TY(x)));
} }
} }
@ -384,7 +384,7 @@ B iPureKeep_c1(B t, B x) { return x; }
B iKeep_c1(B t, B x) { return x; } B iKeep_c1(B t, B x) { return x; }
B iProperties_c2(B t, B w, B x) { B iProperties_c2(B t, B w, B x) {
if (w.u!=m_c32(0).u || x.u != m_c32(0).u) thrM("•internal.Properties: bad arg"); if (w.u!=m_c32(0).u || x.u != m_c32(0).u) thrM("𝕨•internal.Properties𝕩: bad arg");
i32* rp; i32* rp;
B r = m_i32arrv(&rp, 3); B r = m_i32arrv(&rp, 3);
rp[0] = sizeof(usz)*8; rp[0] = sizeof(usz)*8;
@ -394,7 +394,7 @@ B iProperties_c2(B t, B w, B x) {
} }
B unshare_c1(B t, B x) { B unshare_c1(B t, B x) {
if (!isArr(x)) thrM("•internal.Unshare: Argument must be an array"); if (!isArr(x)) thrM("•internal.Unshare𝕩: 𝕩 must be an array");
B r = unshare(x); B r = unshare(x);
decG(x); decG(x);
return r; return r;

View File

@ -70,7 +70,7 @@ B tbl_c2(Md1D* d, B w, B x) { B f = d->f;
ur wr = RNK(w); usz wia = IA(w); ur wr = RNK(w); usz wia = IA(w);
ur xr = RNK(x); usz xia = IA(x); ur xr = RNK(x); usz xia = IA(x);
ur rr = wr+xr; usz ria = uszMul(wia, xia); ur rr = wr+xr; usz ria = uszMul(wia, xia);
if (rr<xr) thrF("⌜: Result rank too large (%i≡=𝕨, %i≡=𝕩)", wr, xr); if (rr<xr) thrF("𝕨𝕩: Result rank too large (%i≡=𝕨, %i≡=𝕩)", wr, xr);
B r; B r;
usz* rsh; usz* rsh;
@ -154,7 +154,7 @@ B swap_c2(Md1D* d, B w, B x) { return c2(d->f, x , w); }
B timed_c2(Md1D* d, B w, B x) { B f = d->f; B timed_c2(Md1D* d, B w, B x) { B f = d->f;
i64 am = o2i64(w); i64 am = o2i64(w);
if (am<=0) thrM("•_timed: 𝕨 must be an integer greater than 1"); if (am<=0) thrM("𝕨•_timed𝕩: 𝕨 must be an integer greater than 1");
incBy(x, am-1); incBy(x, am-1);
FC1 fc1 = c1fn(f); FC1 fc1 = c1fn(f);
u64 sns = nsTime(); u64 sns = nsTime();

View File

@ -144,8 +144,8 @@ B pick_c2(B t, B w, B x);
B cond_c1(Md2D* d, B x) { B f=d->f; B g=d->g; B cond_c1(Md2D* d, B x) { B f=d->f; B g=d->g;
B fr = c1iX(f, x); B fr = c1iX(f, x);
if (isNum(fr)) { if (isNum(fr)) {
if (isAtm(g)||RNK(g)!=1) thrM(": 𝕘 must have rank 1 when index is a number"); if (isAtm(g)||RNK(g)!=1) thrM("𝕩: 𝕘 must have rank 1 when index is a number");
usz fri = WRAP(o2i64(fr), IA(g), thrM(": Index out of bounds of 𝕘")); usz fri = WRAP(o2i64(fr), IA(g), thrM("𝕩: Index out of bounds of 𝕘"));
return c1(IGetU(g, fri), x); return c1(IGetU(g, fri), x);
} else { } else {
B fn = C2(pick, fr, inc(g)); B fn = C2(pick, fr, inc(g));
@ -157,8 +157,8 @@ B cond_c1(Md2D* d, B x) { B f=d->f; B g=d->g;
B cond_c2(Md2D* d, B w, B x) { B g=d->g; B cond_c2(Md2D* d, B w, B x) { B g=d->g;
B fr = c2iWX(d->f, w, x); B fr = c2iWX(d->f, w, x);
if (isNum(fr)) { if (isNum(fr)) {
if (isAtm(g)||RNK(g)!=1) thrM("◶: 𝕘 must have rank 1 when index is a number"); if (isAtm(g)||RNK(g)!=1) thrM("𝕨𝕩: 𝕘 must have rank 1 when index is a number");
usz fri = WRAP(o2i64(fr), IA(g), thrM("◶: Index out of bounds of 𝕘")); usz fri = WRAP(o2i64(fr), IA(g), thrM("𝕨𝕩: Index out of bounds of 𝕘"));
return c2(IGetU(g, fri), w, x); return c2(IGetU(g, fri), w, x);
} else { } else {
B fn = C2(pick, fr, inc(g)); B fn = C2(pick, fr, inc(g));

View File

@ -229,7 +229,7 @@ static B scan_plus(f64 r0, B x, u8 xe, usz ia) {
extern B scan_arith(B f, B w, B x, usz* xsh); // from cells.c extern B scan_arith(B f, B w, B x, usz* xsh); // from cells.c
B scan_c1(Md1D* d, B x) { B f = d->f; B scan_c1(Md1D* d, B x) { B f = d->f;
if (isAtm(x) || RNK(x)==0) thrM("`: Argument cannot have rank 0"); if (isAtm(x) || RNK(x)==0) thrM("`𝕩: 𝕩 cannot have rank 0");
ur xr = RNK(x); ur xr = RNK(x);
usz ia = IA(x); usz ia = IA(x);
if (*SH(x)<=1 || ia==0) return x; if (*SH(x)<=1 || ia==0) return x;
@ -306,9 +306,9 @@ B scan_c1(Md1D* d, B x) { B f = d->f;
} }
B scan_c2(Md1D* d, B w, B x) { B f = d->f; B scan_c2(Md1D* d, B w, B x) { B f = d->f;
if (isAtm(x) || RNK(x)==0) thrM("`: 𝕩 cannot have rank 0"); if (isAtm(x) || RNK(x)==0) thrM("𝕨`𝕩: 𝕩 cannot have rank 0");
ur xr = RNK(x); usz* xsh = SH(x); usz ia = IA(x); ur xr = RNK(x); usz* xsh = SH(x); usz ia = IA(x);
if (isArr(w)? !ptr_eqShape(SH(w), RNK(w), xsh+1, xr-1) : xr!=1) thrF("`: Shape of 𝕨 must match the cell of 𝕩 (%H ≡ ≢𝕨, %H ≡ ≢𝕩)", w, x); if (isArr(w)? !ptr_eqShape(SH(w), RNK(w), xsh+1, xr-1) : xr!=1) thrF("𝕨`𝕩: Shape of 𝕨 must match the cell of 𝕩 (%H ≡ ≢𝕨, %H ≡ ≢𝕩)", w, x);
if (ia==0) { dec(w); return x; } if (ia==0) { dec(w); return x; }
if (RARE(!isFun(f))) { if (RARE(!isFun(f))) {
if (isMd(f)) thrM("Calling a modifier"); if (isMd(f)) thrM("Calling a modifier");

View File

@ -154,11 +154,11 @@ static NOINLINE B2 splitCells(B n, B p, u8 mode) { // 0:∊ 1:⊐ 2:⊒
#define SYMB (mode==0? "∊" : mode==1? "⊐" : "⊒") #define SYMB (mode==0? "∊" : mode==1? "⊐" : "⊒")
#define ARG_N (mode? "𝕩" : "𝕨") #define ARG_N (mode? "𝕩" : "𝕨")
#define ARG_P (mode? "𝕨" : "𝕩") #define ARG_P (mode? "𝕨" : "𝕩")
if (isAtm(p) || RNK(p)==0) thrF("%U: %U cannot have rank 0", SYMB, ARG_P); if (isAtm(p) || RNK(p)==0) thrF("𝕨%U𝕩: %U cannot have rank 0", SYMB, ARG_P);
ur pr = RNK(p); ur pr = RNK(p);
if (isAtm(n)) n = m_unit(n); if (isAtm(n)) n = m_unit(n);
ur nr = RNK(n); ur nr = RNK(n);
if (nr < pr-1) thrF("%U: Rank of %U must be at least the cell rank of %U (%H ≡ ≢𝕨, %H ≡ ≢𝕩)", SYMB, ARG_N, ARG_P, mode?p:n, mode?n:p); if (nr < pr-1) thrF("𝕨%U𝕩: Rank of %U must be at least the cell rank of %U (%H ≡ ≢𝕨, %H ≡ ≢𝕩)", SYMB, ARG_N, ARG_P, mode?p:n, mode?n:p);
ur pcr = pr-1; ur pcr = pr-1;
ur nco = nr-pcr; ur nco = nr-pcr;
if (nco>0 && eqShPart(SH(n)+nco, SH(p)+1, pcr)) { if (nco>0 && eqShPart(SH(n)+nco, SH(p)+1, pcr)) {