diff --git a/src/builtins/sfns.c b/src/builtins/sfns.c index 61999968..fad482b5 100644 --- a/src/builtins/sfns.c +++ b/src/builtins/sfns.c @@ -147,6 +147,7 @@ B shape_c2(B t, B w, B x) { i64 div = nia/xia; i64 mod = nia%xia; for (i64 i = 0; i < div; i++) mut_copyG(m, i*xia, x, 0, xia); + if (fill && mod && noFill(xf)) thrM("⥊: 𝕩 had no fill element"); if (fill) mut_fill(m, div*xia, xf, mod); else mut_copyG(m, div*xia, x, 0, mod); dec(x); diff --git a/src/ns.c b/src/ns.c index e0be9b32..b3885d66 100644 --- a/src/ns.c +++ b/src/ns.c @@ -58,6 +58,26 @@ B ns_getU(B ns, B cNL, i32 nameID) { VTY(ns, t_ns); } thrM("No key found"); } +B ns_qgetU(B ns, B cNL, i32 nameID) { VTY(ns, t_ns); // TODO somehow merge impl with ns_getU + NS* n = c(NS, ns); + NSDesc* d = n->desc; + i32 dVarAm = d->varAm; + assert((u64)nameID < a(cNL)->ia && nameID>=0); + B dNL = d->nameList; + if (cNL.u != dNL.u) { + B cName = TI(cNL,getU)(cNL, nameID); + BS2B dNLgetU = TI(dNL,getU); + for (i32 i = 0; i < dVarAm; i++) { + i32 dID = d->expIDs[i]; + if (dID>=0 && equal(dNLgetU(dNL, dID), cName)) return n->sc->vars[i]; + } + } else { + for (i32 i = 0; i < dVarAm; i++) { + if (d->expIDs[i]==nameID) return n->sc->vars[i]; + } + } + return bi_N; +} B ns_getNU(B ns, B name) { VTY(ns, t_ns); NS* n = c(NS, ns); NSDesc* d = n->desc; diff --git a/src/ns.h b/src/ns.h index 9f00b0e1..1c258d5e 100644 --- a/src/ns.h +++ b/src/ns.h @@ -17,6 +17,7 @@ typedef struct NS { void m_nsDesc(Body* body, bool imm, u8 ty, B nameList, B varIDs, B exported); // consumes nameList B m_ns(Scope* sc, NSDesc* desc); // consumes both B ns_getU(B ns, B nameList, i32 nameID); // doesn't consume anything, doesn't increment result +B ns_qgetU(B ns, B nameList, i32 nameID); // ns_getU but return bi_N on fail B ns_getNU(B ns, B name); // doesn't consume anything, doesn't increment result void ns_set(B ns, B name, B val); // consumes val i32 ns_pos(B ns, B name); // consumes name; returns an index in sc->vars for any variable, exported or local diff --git a/src/vm.c b/src/vm.c index e9dce008..fc6e48fb 100644 --- a/src/vm.c +++ b/src/vm.c @@ -478,12 +478,14 @@ NOINLINE bool v_sethR(Scope* pscs[], B s, B x) { if (isVar(c)) { Scope* sc = pscs[(u16)(c.u>>32)]; i32 nameID = sc->body->varIDs[(u32)c.u]; - if (!v_seth(pscs, c, ns_getU(x, sc->body->nsDesc->nameList, nameID))) return false; + B g = ns_qgetU(x, sc->body->nsDesc->nameList, nameID); + if (q_N(g) || !v_seth(pscs, c, g)) return false; } else if (isObj(c) && v(c)->type==t_fldAlias) { assert(v(c)->type == t_fldAlias); Scope* sc = pscs[0]; FldAlias* cf = c(FldAlias,c); - if (!v_seth(pscs, cf->obj, ns_getU(x, sc->body->nsDesc->nameList, cf->p))) return false; + B g = ns_qgetU(x, sc->body->nsDesc->nameList, cf->p); + if (q_N(g) || !v_seth(pscs, cf->obj, g)) return false; } else return false; } return true;