dyadic •BQN

This commit is contained in:
dzaima 2021-10-10 17:48:39 +03:00
parent debc4e2afe
commit 2c77470d99
2 changed files with 30 additions and 13 deletions

View File

@ -8,7 +8,7 @@
/* sort.c*/A(gradeUp,"") A(gradeDown,"") \
/* everything before the definition of •Type is defined to be pure, and everything after is not */ \
/* sysfn.c*/M(type,"•Type") M(decp,"•Decompose") M(primInd,"•PrimInd") M(glyph,"•Glyph") A(fill,"•FillFn") M(sys,"•getsys") A(grLen,"•GroupLen") D(grOrd,"•GroupOrd") \
/* sysfn.c*/M(repr,"•Repr") M(fmt,"•Fmt") A(asrt,"!") A(casrt,"!") M(out,"•Out") M(show,"•Show") M(bqn,"•BQN") M(sh,"•SH") M(fromUtf8,"•FromUTF8") \
/* sysfn.c*/M(repr,"•Repr") M(fmt,"•Fmt") A(asrt,"!") A(casrt,"!") M(out,"•Out") M(show,"•Show") A(bqn,"•BQN") M(sh,"•SH") M(fromUtf8,"•FromUTF8") \
/* sysfn.c*/D(cmp,"•Cmp") A(hash,"•Hash") M(unixTime,"•UnixTime") M(monoTime,"•MonoTime") M(delay,"•Delay") M(makeRand,"•MakeRand") M(reBQN,"•ReBQN") M(exit,"•Exit") M(getLine,"•GetLine") \
/*internal.c*/M(itype,"•internal.Type") M(refc,"•internal.Refc") M(squeeze,"•internal.Squeeze") M(deepSqueeze,"•internal.DeepSqueeze") M(isPure,"•internal.IsPure") A(info,"•internal.Info") \
/*internal.c*/D(variation,"•internal.Variation") A(listVariations,"•internal.ListVariations") M(clearRefs,"•internal.ClearRefs") M(unshare,"•internal.Unshare")

View File

@ -233,16 +233,39 @@ B show_c1(B t, B x) {
return x;
}
B bqn_c1(B t, B x) {
if (isAtm(x) || rnk(x)!=1) thrM("•BQN: Argument must be a character vector");
extern B replPath; // defined in main.c
static B args_path(B* fullpath, B w, char* name) { // consumes w, returns args, writes to fullpath
if (!isArr(w) || rnk(w)!=1 || a(w)->ia>3) thrF("%U: 𝕨 must be a vector with at most 3 items, but had shape %H", name, w);
usz ia = a(w)->ia;
SGet(w)
B path = ia>0? Get(w,0) : inc(replPath);
B file = ia>1? Get(w,1) : emptyCVec();
B args = ia>2? Get(w,2) : emptySVec();
*fullpath = vec_join(vec_add(path, m_c32('/')), file);
dec(w);
return args;
}
static void vfyStr(B x, char* name) {
if (isAtm(x) || rnk(x)!=1) thrF("%U: Argument must be a character vector", name);
if (a(x)->type!=t_c32arr && a(x)->type!=t_c32slice) {
usz ia = a(x)->ia;
SGetU(x)
for (usz i = 0; i < ia; i++) if (!isC32(GetU(x,i))) thrM("•BQN: Argument must be a character vector");
for (usz i = 0; i < ia; i++) if (!isC32(GetU(x,i))) thrF("%U: Argument must be a character vector", name);
}
}
B bqn_c1(B t, B x) {
vfyStr(x, "•BQN");
return bqn_exec(x, bi_N, bi_N);
}
B bqn_c2(B t, B w, B x) {
vfyStr(x, "•BQN");
B fullpath;
B args = args_path(&fullpath, w, "•BQN");
return bqn_exec(x, fullpath, args);
}
B cmp_c2(B t, B w, B x) {
B r = m_i32(compare(w, x));
dec(w); dec(x);
@ -470,7 +493,6 @@ B getRandNS() {
}
return incG(randNS);
}
extern B replPath; // defined in main.c
static NFnDesc* reBQNDesc;
B reBQN_c1(B t, B x) {
if (!isNsp(x)) thrM("•ReBQN: Argument must be a namespace");
@ -491,19 +513,14 @@ B reBQN_c1(B t, B x) {
return m_nfn(reBQNDesc, m_v2(m_f64(replVal), scVal));
}
B repl_c2(B t, B w, B x) {
vfyStr(x, "REPL");
B o = nfn_objU(t);
B* op = harr_ptr(o);
i32 replMode = o2iu(op[0]);
Scope* sc = c(Scope, op[1]);
if (!isArr(w) || rnk(w)!=1 || a(w)->ia>3) thrM("REPL: 𝕨 must be a vector with at most 3 items");
usz ia = a(w)->ia;
SGet(w)
B path = ia>0? Get(w,0) : inc(replPath);
B file = ia>1? Get(w,1) : emptyCVec();
B args = ia>2? Get(w,2) : emptySVec();
B fullpath = vec_join(vec_add(path, m_c32('/')), file);
dec(w);
B fullpath;
B args = args_path(&fullpath, w, "REPL");
B res;
if (replMode>0) {