Skip to content

Commit e0e1c36

Browse files
authored
Merge pull request #178 from herwinw/extract_bool
Refactor Bnum lookups
2 parents b525595 + 9a45de7 commit e0e1c36

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

74 files changed

+314
-306
lines changed

jsrc/adverbs/a.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ jtbdot2(J jt, A a, A w, A self) {
6565

6666
static A
6767
jtbdot1(J jt, A w, A self) {
68-
return jtbdot2(jt, num(0), w, self);
68+
return jtbdot2(jt, jfalse, w, self);
6969
}
7070

7171
static A

jsrc/adverbs/ab.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ BITWISE(jtbitwiseshifta, I, BWSHIFTA)
162162

163163
A
164164
jtbitwise1(J jt, A w, A self) {
165-
return CALL2(FAV(self)->valencefns[1], zeroionei(0), w, self);
165+
return CALL2(FAV(self)->valencefns[1], num(0), w, self);
166166
} // inplaceable - don't touch jt
167167

168168
static AHDR2FN* bwC[16] = {(AHDR2FN*)bw0000CC,

jsrc/adverbs/af.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ jtfixa(J jt, A a, A w) {
248248
}
249249
} /* 0=a if fix names; 1=a if fix names only if does not contain $: */
250250

251-
// On internal calls, self is an integer whose value contains flags. Otherwise zeroionei is used
251+
// On internal calls, self is an integer whose value contains flags. Otherwise num is used
252252
A
253253
jtfix(J jt, A w, A self) {
254254
PROLOG(0005);
@@ -259,7 +259,7 @@ jtfix(J jt, A w, A self) {
259259
}
260260
// only verbs/noun can get in through the parser, but internally we also vet adv/conj
261261
ASSERT(AT(w) & NAME + VERB + ADV + CONJ, EVDOMAIN);
262-
self = AT(self) & NOUN ? self : zeroionei(0); // default to 0 if noun not given
262+
self = AT(self) & NOUN ? self : num(0); // default to 0 if noun not given
263263
// To avoid infinite recursion we keep an array of names that we have looked up. We create that array here,
264264
// initialized to empty. To pass it into fixa, we create a faux INT block to hold the value, and use AM in that
265265
// block to point to the list of names

jsrc/adverbs/ai.c

+22-22
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ jtinvfork(J jt, A w) {
5252
c = 1 && NOUN & AT(f);
5353
b = c || consf(f);
5454
ASSERT(b != consf(h), EVDOMAIN);
55-
RZ(k = c ? f : df1(gi, num(0), b ? f : h));
55+
RZ(k = c ? f : df1(gi, jfalse, b ? f : h));
5656
RZ(gi = invrecur(b ? jtamp(jt, k, g) : jtamp(jt, g, k)));
5757
RZ(fi = invrecur(b ? h : f));
5858
if (CAMP == ID(gi)) {
@@ -117,7 +117,7 @@ jtbminv(J jt, A w) {
117117
ws = AS(w);
118118
wv = AAV(w);
119119
if (1 >= wr) return jtraze(jt, w);
120-
if (!wn) return jtiota(jt, jtreshape(jt, jtsc(jt, wr), num(0)));
120+
if (!wn) return jtiota(jt, jtreshape(jt, jtsc(jt, wr), jfalse));
121121
GATV0(x, INT, wr, 1);
122122
u = AV(x);
123123
memset(u, C0, wr * SZI);
@@ -256,7 +256,7 @@ jtinvamp(J jt, A w) {
256256
case CQCO:
257257
if (nf) {
258258
ASSERT(!AR(x), EVRANK);
259-
return jtobverse(jt, jteval(jt, all1(lt(x, zeroionei(0))) ? "*/@(^/)\"2" : "(p:@i.@# */ .^ ])\"1"), w);
259+
return jtobverse(jt, jteval(jt, all1(lt(x, num(0))) ? "*/@(^/)\"2" : "(p:@i.@# */ .^ ])\"1"), w);
260260
}
261261
break;
262262
case CFIT:
@@ -310,7 +310,7 @@ jtinvamp(J jt, A w) {
310310
}
311311
break;
312312
case CQQ:
313-
if (ng && jtequ(jt, x, num(1)) && jtequ(jt, f, jteval(jt, "i.\"1"))) return jthook(jt, ds(CFROM), ds(CEQ));
313+
if (ng && jtequ(jt, x, jtrue) && jtequ(jt, f, jteval(jt, "i.\"1"))) return jthook(jt, ds(CFROM), ds(CEQ));
314314
break;
315315
case CBSLASH:
316316
if (nf && (n = jti0(jt, x), 0 > n) && (d = ID(u->fgh[0]), (d & -2) == CLEFT))
@@ -351,7 +351,7 @@ jtinvamp(J jt, A w) {
351351
break;
352352
case CPOLY:
353353
if (nf && 1 == AR(x) && 2 == AN(x) && NUMERIC & AT(x) &&
354-
!jtequ(jt, zeroionei(0), jttail(jt, x))) { // linear polynomial only
354+
!jtequ(jt, num(0), jttail(jt, x))) { // linear polynomial only
355355
RZ(y = jtrecip(jt, jttail(jt, x)));
356356
return jtamp(jt, apip(tymes(y, jtnegate(jt, jthead(jt, x))), y), h);
357357
}
@@ -478,7 +478,7 @@ jtinv(J jt, A w, I recur) {
478478
p = jti0(jt, f);
479479
q = jti0(jt, g);
480480
if (3 == p && 1 == q) return jtforeign(jt, f, num(2));
481-
if (3 == p && 2 == q) return jtforeign(jt, f, num(1));
481+
if (3 == p && 2 == q) return jtforeign(jt, f, jtrue);
482482
if (3 == p && 3 == q) return jtforeign(jt, f, num(2));
483483
break;
484484
case CHOOK:
@@ -489,7 +489,7 @@ jtinv(J jt, A w, I recur) {
489489
// But only fix once, at the top recursion level, (1) to avoid an infinite loop if
490490
// there is a circular reference that leaves names in the fixed form of w; (2) to avoid
491491
// repeated fixing of lower branches, which will only be tried again when higher levels are fixed
492-
if (!recur && !nameless(w)) return invrecur(jtfix(jt, w, zeroionei(0)));
492+
if (!recur && !nameless(w)) return invrecur(jtfix(jt, w, num(0)));
493493
ASSERT(0, EVDOMAIN);
494494
}
495495

@@ -509,14 +509,14 @@ jtneutral(J jt, A w) {
509509
b = jtequ(jt, y, CALL2(v->valencefns[1], x, y, w));
510510
RESETERR;
511511
if (b) return x;
512-
x = zeroionei(0);
512+
x = num(0);
513513
b = jtequ(jt, y, CALL2(v->valencefns[1], x, y, w));
514514
RESETERR;
515-
if (b) return num(0);
516-
x = zeroionei(1);
515+
if (b) return jfalse;
516+
x = num(1);
517517
b = jtequ(jt, y, CALL2(v->valencefns[1], x, y, w));
518518
RESETERR;
519-
if (b) return num(1);
519+
if (b) return jtrue;
520520
RZ(x = jtscf(jt, infm));
521521
b = jtequ(jt, y, CALL2(v->valencefns[1], y, x, w));
522522
RESETERR;
@@ -525,22 +525,22 @@ jtneutral(J jt, A w) {
525525
b = jtequ(jt, y, CALL2(v->valencefns[1], y, x, w));
526526
RESETERR;
527527
if (b) return x;
528-
x = zeroionei(0);
528+
x = num(0);
529529
b = jtequ(jt, y, CALL2(v->valencefns[1], y, x, w));
530530
RESETERR;
531-
if (b) return num(0);
532-
x = zeroionei(1);
531+
if (b) return jfalse;
532+
x = num(1);
533533
b = jtequ(jt, y, CALL2(v->valencefns[1], y, x, w));
534534
RESETERR;
535-
if (b) return num(1);
535+
if (b) return jtrue;
536536
ASSERT(0, EVDOMAIN);
537537
} /* neutral of arbitrary rank-0 function */
538538

539539
A
540540
jtiden(J jt, A w) {
541541
A f, g, x = 0;
542542
V *u, *v;
543-
RZ(w = jtfix(jt, w, zeroionei(0)));
543+
RZ(w = jtfix(jt, w, num(0)));
544544
ASSERT(VERB & AT(w), EVDOMAIN);
545545
v = FAV(w);
546546
f = v->fgh[0];
@@ -565,7 +565,7 @@ jtiden(J jt, A w) {
565565
case CLT:
566566
case CPLUSDOT:
567567
case CJDOT:
568-
case CRDOT: x = num(0); break;
568+
case CRDOT: x = jfalse; break;
569569
case CSTAR:
570570
case CDIV:
571571
case CEXP:
@@ -574,7 +574,7 @@ jtiden(J jt, A w) {
574574
case CEQ:
575575
case CGE:
576576
case CLE:
577-
case CSTARDOT: x = num(1); break;
577+
case CSTARDOT: x = jtrue; break;
578578
case CMAX: x = jtscf(jt, infm); break;
579579
case CMIN: x = ainf; break;
580580
case CUNDER:;
@@ -585,8 +585,8 @@ jtiden(J jt, A w) {
585585
if (CAMP == ID(f) && (u = FAV(f), NOUN & AT(u->fgh[0]) && !AR(u->fgh[0]) && CSTILE == ID(u->fgh[1])))
586586
switch (ID(g)) {
587587
case CSTAR:
588-
case CEXP: x = num(1); break;
589-
case CPLUS: x = num(0);
588+
case CEXP: x = jtrue; break;
589+
case CPLUS: x = jfalse;
590590
}
591591
break;
592592
case CBDOT:; // canned inverses for (bt b.)
@@ -599,7 +599,7 @@ jtiden(J jt, A w) {
599599
bi = -1;
600600
bi = INV0 & (1LL << bt) ? 0 : bi;
601601
bi = INV1 & (1LL << bt) ? 1 : bi;
602-
x = num(bi);
602+
x = numbool(bi);
603603
}
604604
break;
605605
}
@@ -611,7 +611,7 @@ A
611611
jtidensb(J jt, A w) {
612612
A f, g, x = 0, w0 = w;
613613
V* v;
614-
RZ(w = jtfix(jt, w, zeroionei(0)));
614+
RZ(w = jtfix(jt, w, num(0)));
615615
ASSERT(VERB & AT(w), EVDOMAIN);
616616
v = FAV(w);
617617
f = v->fgh[0];

jsrc/adverbs/am.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,7 @@ jtjstd(J jt, A w, A ind, I *cellframelen) {
431431
ws = AS(w);
432432
b = -AN(ind) & SGNIF(AT(ind), BOXX); // b<0 = indexes are boxed and nonempty
433433
if (!wr) {
434-
x = jtfrom(jt, ind, zeroionei(0));
434+
x = jtfrom(jt, ind, num(0));
435435
*cellframelen = 0;
436436
return x;
437437
} // if w is an atom, the best you can get is indexes of 0. No axes are used
@@ -466,7 +466,7 @@ jtjstd(J jt, A w, A ind, I *cellframelen) {
466466
ASSERT(1 >= r, EVINDEX); // not a table
467467
ASSERT(n <= wr, EVINDEX); // not too many axes
468468
DQ(n, if (!jtequ(jt, ds(CACE), v[i])) break; --n;); // discard trailing (boxed) empty axes
469-
j = zeroionei(0); // init list to a single 0 offset
469+
j = num(0); // init list to a single 0 offset
470470
for (i = 0; i < n; ++i) { // for each axis, grow the cartesian product of the specified offsets
471471
x = v[i];
472472
d = ws[i];

jsrc/adverbs/am1.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ jtscube(J jt, A z, A i1, A p) {
257257
zp = PAV(z);
258258
a = SPA(zp, a);
259259
y = SPA(zp, i);
260-
return !AN(a) && !*AS(y) ? jttake(jt, num(1), mtm) : jtover(jt, jtscubb(jt, z, i1), jtscubc(jt, z, i1, p));
260+
return !AN(a) && !*AS(y) ? jttake(jt, jtrue, mtm) : jtover(jt, jtscubb(jt, z, i1), jtscubc(jt, z, i1, p));
261261
} /* new rows for the index matrix of z */
262262

263263
static A

jsrc/adverbs/ao.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -277,9 +277,9 @@ jtkeysp(J jt, A a, A w, A self) {
277277
*AS(q) = n; /* q=: 0 by}1$.n;0;1 */
278278
p = PAV(q);
279279
SPB(p, a, iv0);
280-
SPB(p, e, num(1));
280+
SPB(p, e, jtrue);
281281
SPB(p, i, by);
282-
SPB(p, x, jtreshape(jt, tally(jt, by), num(0)));
282+
SPB(p, x, jtreshape(jt, tally(jt, by), jfalse));
283283
RZ(z = jtover(jt, df1(b, jtrepeat(jt, q, w), VAV(self)->fgh[0]), x));
284284
z = j ? jtcdot2(jt, jtbox(jt, IX(1 + j)), z) : z;
285285
EPILOG(z);

jsrc/adverbs/ap.c

+5-5
Original file line numberDiff line numberDiff line change
@@ -622,7 +622,7 @@ jtinfix(J jt, A a, A w, A self) {
622622
// Create fill-cell of shape s; apply u to it
623623
RZ(df1(x, jtreshape(jt, s, jtfiller(jt, w)), fs));
624624
// Prepend leading axis of 0 to the result
625-
z = jtreshape(jt, jtover(jt, zeroionei(0), shape(jt, x)), x);
625+
z = jtreshape(jt, jtover(jt, num(0), shape(jt, x)), x);
626626
}
627627
EPILOG(z);
628628
}
@@ -657,7 +657,7 @@ jtginfix(J jt, A a, A w, A self) {
657657
RZ(s = AR(w) ? shape(jt, w) : jtca(jt, iv0));
658658
AV(s)[0] = ABS(m);
659659
RZ(df1(x, jtreshape(jt, s, jtfiller(jt, w)), *hv));
660-
return jtreshape(jt, jtover(jt, zeroionei(0), shape(jt, x)), x);
660+
return jtreshape(jt, jtover(jt, num(0), shape(jt, x)), x);
661661
}
662662
}
663663

@@ -864,14 +864,14 @@ jtinfixprefix2(J jt, A a, A w, A self) {
864864
// for prefix, 0 items of fill
865865
// for infix +, invabs items of fill
866866
// for infix -, 0 items of fill
867-
RZ(z = jtreitem(jt, zeroionei(0), w)); // create 0 items of the type of w
867+
RZ(z = jtreitem(jt, num(0), w)); // create 0 items of the type of w
868868
if (ilnval >= 0) {
869869
ilnval = (ilnval == IMAX) ? (wi + 1) : ilnval;
870870
RZ(z = jttake(jt, jtsc(jt, ilnval), z));
871871
} // if items needed, create them. For compatibility, treat _ as 1 more than #items in w
872872
WITHDEBUGOFF(zz = CALL1(f1, z, fs);) if (EMSK(jt->jerr) & EXIGENTERROR) RZ(zz);
873873
RESETERR;
874-
RZ(zz = jtreshape(jt, jtover(jt, zeroionei(0), shape(jt, zz ? zz : mtv)), zz ? zz : zeroionei(0)));
874+
RZ(zz = jtreshape(jt, jtover(jt, num(0), shape(jt, zz ? zz : mtv)), zz ? zz : num(0)));
875875
}
876876

877877
// result is now in zz
@@ -909,7 +909,7 @@ jtpscan(J jt, A w, A self) {
909909
SETICFR(w, f, r, n); // wn=0 doesn't matter
910910
// If there are 0 or 1 items, or w is empty, return the input unchanged, except: if rank 0, return (($w),1)($,)w -
911911
// if atomic op, do it right here, otherwise call the routine to get the shape of result cell
912-
if (((1 - n) & -wn) >= 0) { return r ? w : jtreshape(jt, apip(shape(jt, w), zeroionei(1)), w); } // n<2 or wn=0
912+
if (((1 - n) & -wn) >= 0) { return r ? w : jtreshape(jt, apip(shape(jt, w), num(1)), w); } // n<2 or wn=0
913913
VARPS adocv;
914914
varps(adocv, self, wt, 1); // fetch info for f/\ and this type of arg
915915
if (!adocv.f)

0 commit comments

Comments
 (0)