fix ⟨a‿b⟩←⟨1‿2⟩ and ⟨3‿0,2‿1‿2⟩⊏6‿5⥊↕30

This commit is contained in:
dzaima 2021-04-30 00:55:28 +03:00
parent 6afd425f24
commit f36eddb01c
5 changed files with 19 additions and 15 deletions

View File

@ -133,6 +133,7 @@ bool harr_canStore(B x) { return true; }
NOINLINE void harr_pfree(B x, usz am) { // am - item after last written NOINLINE void harr_pfree(B x, usz am) { // am - item after last written
assert(v(x)->type==t_harr);
B* p = harr_ptr(x); B* p = harr_ptr(x);
for (usz i = 0; i < am; i++) dec(p[i]); for (usz i = 0; i < am; i++) dec(p[i]);
mm_free(v(x)); mm_free(v(x));

View File

@ -54,6 +54,7 @@ u8 el_or(u8 a, u8 b) {
void mut_pfree(Mut* m, usz n) { // free the first n elements void mut_pfree(Mut* m, usz n) { // free the first n elements
if (m->type==el_B) harr_pfree(tag(m->val,ARR_TAG), n); if (m->type==el_B) harr_pfree(tag(m->val,ARR_TAG), n);
else mm_free((Value*) m->val);
} }
// expects x to be an array, each position must be written to precisely once // expects x to be an array, each position must be written to precisely once

View File

@ -286,6 +286,7 @@ B select_c2(B t, B w, B x) {
return withFill(rb,xf); return withFill(rb,xf);
} }
base: base:
dec(xf);
return c2(rt_select, w, x); return c2(rt_select, w, x);
} }

View File

@ -205,7 +205,7 @@ Block* compile(B bcq, B objs, B blocksq) { // consumes all
return ret; return ret;
} }
void v_set(Scope* pscs[], B s, B x, bool upd) { // frees s, doesn't consume x void v_set(Scope* pscs[], B s, B x, bool upd) { // doesn't consume
if (isVar(s)) { if (isVar(s)) {
Scope* sc = pscs[(u16)(s.u>>32)]; Scope* sc = pscs[(u16)(s.u>>32)];
B prev = sc->vars[(u32)s.u]; B prev = sc->vars[(u32)s.u];
@ -218,14 +218,11 @@ void v_set(Scope* pscs[], B s, B x, bool upd) { // frees s, doesn't consume x
sc->vars[(u32)s.u] = inc(x); sc->vars[(u32)s.u] = inc(x);
} else { } else {
VT(s, t_harr); VT(s, t_harr);
if (!eqShape(s, x)) thrM("Assignment: Mismatched shape for spread assignment"); if (!isArr(x) || !eqShape(s, x)) thrM("Assignment: Mismatched shape for spread assignment");
usz ia = a(x)->ia; usz ia = a(x)->ia;
B* sp = harr_ptr(s); B* sp = harr_ptr(s);
BS2B xgetU = TI(x).getU; BS2B xgetU = TI(x).getU;
for (u64 i = 0; i < ia; i++) { for (u64 i = 0; i < ia; i++) v_set(pscs, sp[i], xgetU(x,i), upd);
v_set(pscs, sp[i], xgetU(x,i), upd);
}
dec(s);
} }
} }
B v_get(Scope* pscs[], B s) { // get value representing s, replacing with bi_optOut; doesn't consume B v_get(Scope* pscs[], B s) { // get value representing s, replacing with bi_optOut; doesn't consume
@ -372,12 +369,12 @@ B evalBC(Body* b, Scope* sc) { // doesn't consume
vars[p] = bi_optOut; vars[p] = bi_optOut;
break; break;
} }
case SETN: { P(s) P(x) v_set(pscs, s, x, false); ADD(x); break; } case SETN: { P(s) P(x) v_set(pscs, s, x, false); dec(s); ADD(x); break; }
case SETU: { P(s) P(x) v_set(pscs, s, x, true ); ADD(x); break; } case SETU: { P(s) P(x) v_set(pscs, s, x, true ); dec(s); ADD(x); break; }
case SETM: { P(s)P(f)P(x) case SETM: { P(s)P(f)P(x)
B w = v_get(pscs, s); B w = v_get(pscs, s);
B r = c2(f,w,x); dec(f); B r = c2(f,w,x); dec(f);
v_set(pscs, s, r, true); v_set(pscs, s, r, true); dec(s);
ADD(r); ADD(r);
break; break;
} }

View File

@ -1,5 +1,5 @@
#! /usr/bin/env dbqn #! /usr/bin/env dbqn
"Usage: ./test.bqn path/to/mlochbaum/BQN [-sme] name | ./BQN"!2•args "Usage: ./test.bqn path/to/mlochbaum/BQN [-qsmev] name | ./BQN"!2•args
path•args path•args
args1•args args1•args
opt"" opt""
@ -10,11 +10,15 @@ case←⊑args
case".bqn" case".bqn"
tests •FLines path"/test/cases/"case tests •FLines path"/test/cases/"case
tests/˜ (('#')0<)¨tests tests/˜ (('#')0<)¨tests
{𝕊: tests/˜{"! %"3𝕩}¨tests} 's'opt {𝕊: tests/˜'!'¨tests} 's'opt
{𝕊: tests/˜{"! %"3𝕩}¨tests} 'e'opt {𝕊: tests/˜'!'=¨tests} 'e'opt
Out {•Out'%'{𝕩˜1+𝕩'%'}𝕩} Q {
i𝕩'%'
(('!'𝕩)'v'opt)(1+i) {"(" i𝕩 ") ≡ {" ('#') (1+i)𝕩 " }"} 𝕩
}
Out {•Out'%'Q𝕩}
(('m'opt)Out{•Show𝕩Out𝕩})¨tests (('m'opt)Out{•Show𝕩Out𝕩})¨tests
# ('%'⊸∊∨ '#'= ·⊑ ∾⟜"#")◶•Out‿@¨tests # ('%'⊸∊∨ '#'= ·⊑ ∾⟜"#")◶•Out‿@¨tests
•Out """finished""" •Out(¬'q'opt) """finished"""
•Out "" •Out(¬'q'opt) ""