•ns.Get, •ns.Has, •ns.Keys
This commit is contained in:
parent
428064a5c2
commit
7013a9edf9
@ -44,6 +44,10 @@ See [the BQN specification](https://mlochbaum.github.io/BQN/spec/system.html) fo
|
|||||||
|
|
||||||
`•term.OutRaw` and `•term.ErrRaw` output the given bytes directly to the specific stream, without any trailing newline. May be removed once a proper interface for stream I/O has been made.
|
`•term.OutRaw` and `•term.ErrRaw` output the given bytes directly to the specific stream, without any trailing newline. May be removed once a proper interface for stream I/O has been made.
|
||||||
|
|
||||||
|
## `•ns`
|
||||||
|
|
||||||
|
`ns •ns.Get "abc"`, `ns •ns.Has "abc"`, and `•ns.Keys ns` for reading namespace information. Order of `•ns.Keys` result is undefined; `Get` & `Has` currently expect the key name to be normalized (i.e. lowercase & without underscores).
|
||||||
|
|
||||||
## `•_while_`
|
## `•_while_`
|
||||||
|
|
||||||
While `𝕨𝔾𝕩`, execute `𝕩↩𝕨𝔽𝕩`. Equivalent to `{𝕨𝔾𝕩? 𝕨 𝕊 𝕨𝔽𝕩; 𝕩}`.
|
While `𝕨𝔾𝕩`, execute `𝕩↩𝕨𝔽𝕩`. Equivalent to `{𝕨𝔾𝕩? 𝕨 𝕊 𝕨𝔽𝕩; 𝕩}`.
|
||||||
|
|||||||
@ -12,6 +12,7 @@
|
|||||||
/* sysfn.c*/M(type,"•Type") M(decp,"•Decompose") M(repr,"•Repr") M(parseFloat,"•ParseFloat") M(fmt,"•Fmt") A(asrt,"!") A(casrt,"!") M(out,"•Out") M(show,"•Show") A(bqn,"•BQN") \
|
/* sysfn.c*/M(type,"•Type") M(decp,"•Decompose") M(repr,"•Repr") M(parseFloat,"•ParseFloat") M(fmt,"•Fmt") A(asrt,"!") A(casrt,"!") M(out,"•Out") M(show,"•Show") A(bqn,"•BQN") \
|
||||||
/* sysfn.c*/A(sh,"•SH") M(fromUtf8,"•FromUTF8") M(toUtf8,"•ToUTF8") M(currentError,"•CurrentError") D(cmp,"•Cmp") A(hash,"•Hash") M(unixTime,"•UnixTime")\
|
/* sysfn.c*/A(sh,"•SH") M(fromUtf8,"•FromUTF8") M(toUtf8,"•ToUTF8") M(currentError,"•CurrentError") D(cmp,"•Cmp") A(hash,"•Hash") M(unixTime,"•UnixTime")\
|
||||||
/* sysfn.c*/M(monoTime,"•MonoTime") M(delay,"•Delay") M(makeRand,"•MakeRand") M(reBQN,"•ReBQN") M(exit,"•Exit") M(getLine,"•GetLine") \
|
/* sysfn.c*/M(monoTime,"•MonoTime") M(delay,"•Delay") M(makeRand,"•MakeRand") M(reBQN,"•ReBQN") M(exit,"•Exit") M(getLine,"•GetLine") \
|
||||||
|
/* sysfn.c*/D(nGet,"•ns.Get") D(nHas,"•ns.Has") M(nKeys,"•ns.Keys") \
|
||||||
/* sysfn.c*/M(fName,"•file.Name") M(fParent,"•file.Parent") \
|
/* sysfn.c*/M(fName,"•file.Name") M(fParent,"•file.Parent") \
|
||||||
/* sysfn.c*/M(tRawMode,"•term.RawMode") M(tFlush,"•term.Flush") M(tCharB,"•term.CharB") M(tCharN,"•term.CharN") M(tOutRaw,"•term.OutRaw") M(tErrRaw,"•term.ErrRaw") \
|
/* sysfn.c*/M(tRawMode,"•term.RawMode") M(tFlush,"•term.Flush") M(tCharB,"•term.CharB") M(tCharN,"•term.CharN") M(tOutRaw,"•term.OutRaw") M(tErrRaw,"•term.ErrRaw") \
|
||||||
/* inverse.c*/M(setInvReg,"(SetInvReg)") M(setInvSwap,"(SetInvSwap)") M(nativeInvReg,"(NativeInvReg)") M(nativeInvSwap,"(NativeInvSwap)") \
|
/* inverse.c*/M(setInvReg,"(SetInvReg)") M(setInvSwap,"(SetInvSwap)") M(nativeInvReg,"(NativeInvReg)") M(nativeInvSwap,"(NativeInvSwap)") \
|
||||||
|
|||||||
@ -687,8 +687,8 @@ B slash_c2(B t, B w, B x) {
|
|||||||
usz csz = arr_csz(x);
|
usz csz = arr_csz(x);
|
||||||
MAKE_MUT(r0, s*csz) mut_init(r0, TI(x,elType)); MUTG_INIT(r0);
|
MAKE_MUT(r0, s*csz) mut_init(r0, TI(x,elType)); MUTG_INIT(r0);
|
||||||
SGetU(w)
|
SGetU(w)
|
||||||
if (csz==1) { SGetU(x) usz ri=0; for (ux i=0; i<wia; i++) { usz c=o2s(GetU(w, i)); if (c) { mut_fillG(r0, ri, GetU(x, i), c); ri+= c; } } }
|
if (csz!=1) { usz ri=0; for (ux i=0; i<wia; i++) { usz c=o2s(GetU(w, i)); for(ux j=0;j<c;j++) { mut_copyG(r0, ri, x, i*csz, csz); ri+= csz; } } }
|
||||||
else { usz ri=0; for (ux i=0; i<wia; i++) { usz c=o2s(GetU(w, i)); for(ux j=0;j<c;j++) { mut_copyG(r0, ri, x, i*csz, csz); ri+= csz; } } }
|
else { SGetU(x) usz ri=0; for (ux i=0; i<wia; i++) { usz c=o2s(GetU(w, i)); if (c) { mut_fillG(r0, ri, GetU(x, i), c); ri+= c; } } }
|
||||||
Arr* ra = mut_fp(r0);
|
Arr* ra = mut_fp(r0);
|
||||||
if (xr == 1) {
|
if (xr == 1) {
|
||||||
arr_shVec(ra);
|
arr_shVec(ra);
|
||||||
|
|||||||
@ -1110,6 +1110,42 @@ B getTermNS(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
B nKeys_c1(B t, B x) {
|
||||||
|
if (!isNsp(x)) thrM("•ns.Keys: 𝕩 must be a namespace");
|
||||||
|
NSDesc* desc = c(NS,x)->desc;
|
||||||
|
ux am = desc->varAm;
|
||||||
|
HArr_p r = m_harr0v(am);
|
||||||
|
for (ux i = 0; i < am; i++) r.a[i] = incG(gid2str(desc->expGIDs[i]));
|
||||||
|
decG(x);
|
||||||
|
return r.b;
|
||||||
|
}
|
||||||
|
B nGet_c2(B t, B w, B x) {
|
||||||
|
if (!isNsp(w)) thrM("•ns.Has: 𝕨 must be a namespace");
|
||||||
|
vfyStr(x, "•ns.Get", "𝕩");
|
||||||
|
B r = ns_getNU(w, x, true);
|
||||||
|
decG(w); decG(x);
|
||||||
|
return inc(r);
|
||||||
|
}
|
||||||
|
B nHas_c2(B t, B w, B x) {
|
||||||
|
if (!isNsp(w)) thrM("•ns.Has: 𝕨 must be a namespace");
|
||||||
|
vfyStr(x, "•ns.Get", "𝕩");
|
||||||
|
B r = ns_getNU(w, x, false);
|
||||||
|
decG(w); decG(x);
|
||||||
|
return m_i32(!q_N(r));
|
||||||
|
}
|
||||||
|
static B nsNS;
|
||||||
|
B getNsNS(void) {
|
||||||
|
if (nsNS.u == 0) {
|
||||||
|
#define F(X) incG(bi_##X),
|
||||||
|
Body* d = m_nnsDesc("get", "has", "keys");
|
||||||
|
nsNS = m_nns(d,F(nGet)F(nHas)F(nKeys));
|
||||||
|
#undef F
|
||||||
|
gc_add(nsNS);
|
||||||
|
}
|
||||||
|
return incG(nsNS);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
typedef struct CastType { usz s; bool c; } CastType;
|
typedef struct CastType { usz s; bool c; } CastType;
|
||||||
static bool isCharType(u8 t) {
|
static bool isCharType(u8 t) {
|
||||||
@ -1473,7 +1509,8 @@ static Body* file_nsGen;
|
|||||||
F("state", U"•state", tag(15,VAR_TAG)) \
|
F("state", U"•state", tag(15,VAR_TAG)) \
|
||||||
F("args", U"•args", tag(16,VAR_TAG)) \
|
F("args", U"•args", tag(16,VAR_TAG)) \
|
||||||
F("listsys", U"•listsys", tag(17,VAR_TAG)) \
|
F("listsys", U"•listsys", tag(17,VAR_TAG)) \
|
||||||
OPTSYS(NATIVE_COMPILER)(F("compobj", U"•CompObj", tag(18,VAR_TAG)))
|
OPTSYS(NATIVE_COMPILER)(F("compobj", U"•CompObj", tag(18,VAR_TAG))) \
|
||||||
|
F("ns", U"•ns", tag(19,VAR_TAG))
|
||||||
|
|
||||||
NFnDesc* ffiloadDesc;
|
NFnDesc* ffiloadDesc;
|
||||||
B ffiload_c2(B t, B w, B x);
|
B ffiload_c2(B t, B w, B x);
|
||||||
@ -1577,6 +1614,7 @@ B sys_c1(B t, B x) {
|
|||||||
}
|
}
|
||||||
case 17: cr = incG(curr_ns); break; // •listsys
|
case 17: cr = incG(curr_ns); break; // •listsys
|
||||||
case 18: cr = incG(bi_compObj); break; // •CompObj
|
case 18: cr = incG(bi_compObj); break; // •CompObj
|
||||||
|
case 19: cr = getNsNS(); break; // •ns
|
||||||
}
|
}
|
||||||
HARR_ADD(r, i, cr);
|
HARR_ADD(r, i, cr);
|
||||||
}
|
}
|
||||||
@ -1609,6 +1647,7 @@ u32* dsv_text[] = {
|
|||||||
|
|
||||||
U"•internal.ClearRefs",U"•internal.DeepSqueeze",U"•internal.EEqual",U"•internal.ElType",U"•internal.HeapDump",U"•internal.Info",U"•internal.IsPure",U"•internal.ListVariations",U"•internal.Refc",U"•internal.Squeeze",U"•internal.Temp",U"•internal.Type",U"•internal.Unshare",U"•internal.Variation",
|
U"•internal.ClearRefs",U"•internal.DeepSqueeze",U"•internal.EEqual",U"•internal.ElType",U"•internal.HeapDump",U"•internal.Info",U"•internal.IsPure",U"•internal.ListVariations",U"•internal.Refc",U"•internal.Squeeze",U"•internal.Temp",U"•internal.Type",U"•internal.Unshare",U"•internal.Variation",
|
||||||
U"•math.Acos",U"•math.Acosh",U"•math.Asin",U"•math.Asinh",U"•math.Atan",U"•math.Atan2",U"•math.Atanh",U"•math.Cbrt",U"•math.Comb",U"•math.Cos",U"•math.Cosh",U"•math.Erf",U"•math.ErfC",U"•math.Expm1",U"•math.Fact",U"•math.GCD",U"•math.Hypot",U"•math.LCM",U"•math.Log10",U"•math.Log1p",U"•math.Log2",U"•math.LogFact",U"•math.Sin",U"•math.Sinh",U"•math.Sum",U"•math.Tan",U"•math.Tanh",
|
U"•math.Acos",U"•math.Acosh",U"•math.Asin",U"•math.Asinh",U"•math.Atan",U"•math.Atan2",U"•math.Atanh",U"•math.Cbrt",U"•math.Comb",U"•math.Cos",U"•math.Cosh",U"•math.Erf",U"•math.ErfC",U"•math.Expm1",U"•math.Fact",U"•math.GCD",U"•math.Hypot",U"•math.LCM",U"•math.Log10",U"•math.Log1p",U"•math.Log2",U"•math.LogFact",U"•math.Sin",U"•math.Sinh",U"•math.Sum",U"•math.Tan",U"•math.Tanh",
|
||||||
|
U"•ns.Get",U"•ns.Has",U"•ns.Keys",
|
||||||
U"•rand.Deal",U"•rand.Range",U"•rand.Subset",
|
U"•rand.Deal",U"•rand.Range",U"•rand.Subset",
|
||||||
U"•term.CharB",U"•term.CharN",U"•term.ErrRaw",U"•term.Flush",U"•term.OutRaw",U"•term.RawMode",
|
U"•term.CharB",U"•term.CharN",U"•term.ErrRaw",U"•term.Flush",U"•term.OutRaw",U"•term.RawMode",
|
||||||
NULL
|
NULL
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user