From 7786beeed16f24d2fdcaec70fe2ddd46115cd1b9 Mon Sep 17 00:00:00 2001 From: dzaima Date: Thu, 29 Apr 2021 00:06:27 +0300 Subject: [PATCH] clean up err stuff --- src/derv.c | 4 ++-- src/h.h | 8 ++++---- src/sfns.c | 2 +- src/stuff.c | 6 +++--- src/vm.c | 18 +++++++++--------- 5 files changed, 19 insertions(+), 19 deletions(-) diff --git a/src/derv.c b/src/derv.c index ae9fedce..19989f0b 100644 --- a/src/derv.c +++ b/src/derv.c @@ -67,8 +67,8 @@ B m_fork(B f, B g, B h) { B r = mm_alloc(sizeof(Fork), t_fork, ftag(FUN_TAG)); c B m_atop( B g, B h) { B r = mm_alloc(sizeof(Atop), t_atop, ftag(FUN_TAG)); c(Atop,r)->g = g; c(Atop,r)->h = h; c(Atop,r)->c1=atop_c1; c(Atop,r)->c2=atop_c2; c(Atop,r)->extra=pf_atop; return r; } // consume all args -B m1_d(B m, B f ) { if(isMd1(m)) return TI(m).m1_d(m, f ); return err("Interpreting non-1-modifier as 1-modifier"); } -B m2_d(B m, B f, B g) { if(isMd2(m)) return TI(m).m2_d(m, f, g); return err("Interpreting non-2-modifier as 2-modifier"); } +B m1_d(B m, B f ) { if(isMd1(m)) return TI(m).m1_d(m, f ); thrM("Interpreting non-1-modifier as 1-modifier"); } +B m2_d(B m, B f, B g) { if(isMd2(m)) return TI(m).m2_d(m, f, g); thrM("Interpreting non-2-modifier as 2-modifier"); } B m2_h(B m, B g) { return m_md2H(m, g); } diff --git a/src/h.h b/src/h.h index 3d801903..17dc53e0 100644 --- a/src/h.h +++ b/src/h.h @@ -410,15 +410,15 @@ typedef struct Fun { BBB2B c2; } Fun; -B c1_invalid(B f, B x) { return err("This function can't be called monadically"); } -B c2_invalid(B f, B w, B x) { return err("This function can't be called dyadically"); } +NOINLINE B c1_invalid(B f, B x) { thrM("This function can't be called monadically"); } +NOINLINE B c2_invalid(B f, B w, B x) { thrM("This function can't be called dyadically"); } NOINLINE B c1_rare(B f, B x) { dec(x); - if (isMd(f)) return err("Calling a modifier"); + if (isMd(f)) thrM("Calling a modifier"); return inc(VALIDATE(f)); } NOINLINE B c2_rare(B f, B w, B x) { dec(w); dec(x); - if (isMd(f)) return err("Calling a modifier"); + if (isMd(f)) thrM("Calling a modifier"); return inc(VALIDATE(f)); } B c1(B f, B x) { // BQN-call f monadically; consumes x diff --git a/src/sfns.c b/src/sfns.c index 6b690ba8..84419845 100644 --- a/src/sfns.c +++ b/src/sfns.c @@ -198,7 +198,7 @@ B pick_c1(B t, B x) { B pick_c2(B t, B w, B x) { // usz wu = o2s(w); // if (!isArr(x)) { dec(x); dec(w); thrM("⊑: 𝕩 wasn't an array"); } - // if (wu >= a(x)->ia) err("⊑: 𝕨 is greater than length of 𝕩"); // no bounds check for now + // if (wu >= a(x)->ia) thrM("⊑: 𝕨 is greater than length of 𝕩"); // no bounds check for now B r = TI(x).get(x, o2su(w)); dec(x); return r; diff --git a/src/stuff.c b/src/stuff.c index 25b519a0..d7ec7a0d 100644 --- a/src/stuff.c +++ b/src/stuff.c @@ -166,9 +166,9 @@ void def_print(B x) { printf("(%d=%s)", v(x)->type, format_type(v(x)->type)); } B def_identity(B f) { return bi_N; } B def_get (B x, usz n) { return inc(x); } B def_getU(B x, usz n) { return x; } -B def_m1_d(B m, B f ) { return err("cannot derive this"); } -B def_m2_d(B m, B f, B g) { return err("cannot derive this"); } -B def_slice(B x, usz s) { return err("cannot slice non-array!"); } +B def_m1_d(B m, B f ) { thrM("cannot derive this"); } +B def_m2_d(B m, B f, B g) { thrM("cannot derive this"); } +B def_slice(B x, usz s) { thrM("cannot slice non-array!"); } bool def_canStore(B x) { return false; } static inline void hdr_init() { diff --git a/src/vm.c b/src/vm.c index 88f82fe1..874b6195 100644 --- a/src/vm.c +++ b/src/vm.c @@ -160,11 +160,11 @@ Block* compile(B bcq, B objs, B blocksq) { // consumes all for (usz i = 0; i < bam; i++) { B cbld = blockDefs[i]; - if (a(cbld)->ia != 4) return c(Block,err("bad compile block")); // todo not cast errors here weirdly + if (a(cbld)->ia != 4) thrM("bad compile block"); BS2B bget = TI(cbld).get; - usz ty = o2s(bget(cbld,0)); if (ty<0|ty>2) return c(Block,err("bad block type")); + usz ty = o2s(bget(cbld,0)); if (ty<0|ty>2) thrM("bad block type"); bool imm = o2s(bget(cbld,1)); // todo o2b or something - usz idx = o2s(bget(cbld,2)); if (idx>=bcl) return c(Block,err("oob bytecode index")); + usz idx = o2s(bget(cbld,2)); if (idx>=bcl) thrM("oob bytecode index"); usz vam = o2s(bget(cbld,3)); i32* cbc = bc+idx; @@ -178,7 +178,7 @@ Block* compile(B bcq, B objs, B blocksq) { // consumes all if (scan[1]>mpsc) mpsc = scan[1]; } scan = nextBC(scan); - if (scan-bc >= bcl) return c(Block,err("no RETN/RETD found at end of bytecode")); + if (scan-bc >= bcl) thrM("no RETN/RETD found at end of bytecode"); } if (mpsc>U16_MAX) thrM("LOC_ too deep"); @@ -210,15 +210,15 @@ void v_set(Scope* pscs[], B s, B x, bool upd) { // frees s, doesn't consume x Scope* sc = pscs[(u16)(s.u>>32)]; B prev = sc->vars[(u32)s.u]; if (upd) { - if (prev.u==bi_noVar.u) err("updating undefined variable"); + if (prev.u==bi_noVar.u) thrM("↩: Updating undefined variable"); dec(prev); } else { - if (prev.u!=bi_noVar.u) err("redefining variable"); + if (prev.u!=bi_noVar.u) thrM("←: redefining variable"); } sc->vars[(u32)s.u] = inc(x); } else { VT(s, t_harr); - if (!eqShape(s, x)) err("spread assignment: mismatched shape"); + if (!eqShape(s, x)) thrM("Assignment: Mismatched shape for spread assignment"); usz ia = a(x)->ia; B* sp = harr_ptr(s); BS2B xgetU = TI(x).getU; @@ -559,7 +559,7 @@ void popCatch() { #endif } -void thr(B msg) { +NOINLINE void thr(B msg) { if (cf>cfStart) { catchMessage = msg; cf--; @@ -583,6 +583,6 @@ void thr(B msg) { #endif } -void thrM(char* s) { +NOINLINE void thrM(char* s) { thr(fromUTF8(s, strlen(s))); } \ No newline at end of file