Skip to content

Commit

Permalink
Require ARs in m} and ^:gerund to encode verbs
Browse files Browse the repository at this point in the history
  • Loading branch information
HenryHRich committed Oct 27, 2024
1 parent 7cf53e5 commit 08504f9
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 14 deletions.
2 changes: 1 addition & 1 deletion jsrc/ab.c
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ B jtbitwisecharamp(J jt,UC*t,I n,UC*wv,UC*zv){I p;UC c,i,j,*pv,s[256];AHDR2FN* a
pv=(UC*)&p; DO(SZI, pv[i]=c;); // scaf slow
ado AH2A(1,2*(256/SZI)+0,AV(ds(CALP)),pv,s,jt); if(memcmpne(s,t,256L))R 0; // see if the table we are given exactly matches the function we inferred. If not, abort
ado AH2A(1,2*((n+SZI-1)>>LGSZI)+0,wv,pv,zv,jt); // if we found the function, apply it wordwise
// obsolete zv[n]=0; // scaf not needed
// obsolete zv[n]=0;
R 1;
} // scaf kludge this should be scrapped in favor of wordlong ops

Expand Down
4 changes: 3 additions & 1 deletion jsrc/ar.c
Original file line number Diff line number Diff line change
Expand Up @@ -1237,7 +1237,9 @@ static DF2(jtfoldx){F2PREFIP;A z,vz;
loopend:;

ASSERTGOTO(AN(zz)!=0,EVNORESULT,exitpop) // error if we never added to the result
if(dmfr&STATEMULT)AS(zz)[0]=AN(zz); zz=ope(zz); // set AS(0) right; open zz to give unboxed result scaf need PRISTINE flag
if(dmfr&STATEMULT)AS(zz)[0]=AN(zz); zz=ope(zz); // set AS(0) right; open zz to give unboxed result
// if zz is boxed, it might be PRISTINE. We take the trouble to check, because there's a good chance the user is going to use &.> next
if(AT(zz)&BOX){DO(AN(zz), A c=C(AAV(zz)[i]); if(!(AT(c)&DIRECT)||AC(c)>ACUC1)goto noprist;) AFLAGORLOCAL(zz,AFPRISTINE); noprist:;}

abortexit:; // exit, returning whatever is in zz
jt->afoldinfo=stkfoldinfo;
Expand Down
2 changes: 1 addition & 1 deletion jsrc/ca.c
Original file line number Diff line number Diff line change
Expand Up @@ -550,7 +550,7 @@ F2(jtampco){F2PREFIP;AF f1=on1cell,f2=on2cell;C c,d;I flag,flag2=0,linktype=0;V*
// be repeated; preserve the inplacing of the argument given (i. e. move w to a for u&n). Bit 1 of jtinplace is always 0 for monad.
// We marked the derived verb inplaceable only if the dyad of u/v was inplaceable
// This supports IRS so that it can pass the rank on to the called function; no need to revalidate here. jt is inplaceable but we don't use it except to fiddle with flags
// We pass the WILLOPEN flags through scaf don't need full IRS2 because jt->ranks is known to be OK for the monad
// We pass the WILLOPEN flags through. We don't need full IRS2 because jt->ranks is known to be OK for the monad
// obsolete static DF1(withl){A fs=FAV(self)->fgh[0]; AF f2=FAV(fs)->valencefns[1];A gs=FAV(self)->fgh[1]; AF g2=FAV(gs)->valencefns[1]; F1PREFIP;A z; I r=(RANKT)jt->ranks; IRSIP2(fs,w,gs,RMAX,(RANKT)jt->ranks,g2,z); RETF(z);}
// obsolete static DF1(withr){A fs=FAV(self)->fgh[0]; AF f2=FAV(fs)->valencefns[1];A gs=FAV(self)->fgh[1]; AF g2=FAV(gs)->valencefns[1]; F1PREFIP; jtinplace=(J)(intptr_t)((I)jtinplace+((I)jtinplace&JTINPLACEW)); A z; I r=(RANKT)jt->ranks; IRSIP2(w,gs,fs,(RANKT)jt->ranks,RMAX,f2,z); RETF(z);}
static DF1(withl){AF f2=FAV(self)->localuse.lu1.bondfn; F1PREFIP; ((C*)&jt->ranks)[1]=RMAX; A z=f2(jtinplace,FAV(self)->fgh[0],w,FAV(self)->fgh[1]); RETF(z);} // m&v. Leave inplacing of w
Expand Down
7 changes: 4 additions & 3 deletions jsrc/cg.c
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ PRIM jtfxself[2]={

// run jtfx on each box in w, turning AR into an A block
// self is a parm passed through to jtfx, coming from jtfxself above. if AK(self) is nonzero, we return nouns as is
// Result claims to be an array of boxes, but each box holds a function
// Result claims to be an array of boxes, but each box holds an A with possibly a function type
DF1(jtfxeach){RETF(every(w,self));}

static DF1(jtcon1){A h,*hv,*x,z;V*sv;
Expand Down Expand Up @@ -384,7 +384,7 @@ F2(jtagendai){F2PREFIP;I flag;
// sv->id is the original conjunction, executed a second time now that we have the selector/power
// this is a conjunction execution, executing a u^:n form, and creates a derived verb to perform that function; call that verb ff
// then we execute gerund v2 on y (with self set to v2)
// then we execute ff on the result of (v2 y), with self set to ff
// then we execute ff on the result of (v2 y), with self set to ff scaf combine all 4 into 1
static DF1(jtgcl1){V* RESTRICT sv=FAV(self); A gs=sv->fgh[1]; A ff,z0,z1,*hv=AAV(sv->fgh[2]);
STACKCHKOFL RZ(df1(z0,w,C(hv[1]))) df2(ff,z0,gs,ds(sv->id));
RZ(df1(z1,w,C(hv[2]))) R df1(z0,z1,ff);
Expand Down Expand Up @@ -416,7 +416,8 @@ A jtgconj(J jt,A a,A w,C id){A hs,y;B na;I n;
ASSERT(1>=AR(y),EVRANK);
ASSERT((n&-2)==2,EVLENGTH); // length is 2 or 3
ASSERT(BOX&AT(y),EVDOMAIN);
RZ(hs=fxeach(3==n?y:jlink(scc(CLBKTC),y),(A)&jtfxself[0]));
// obsolete RZ(hs=fxeach(3==n?y:jlink(scc(CLBKTC),y),(A)&jtfxself[0]));
RZ(hs=fxeachv(1,3==n?y:jlink(scc(CLBKTC),y)));
R fdef(0,id,VERB, na?jtgcl1:jtgcr1,na?jtgcl2:jtgcr2, a,w,hs, na?VGERL:VGERR, RMAX,RMAX,RMAX);
}

Expand Down
10 changes: 5 additions & 5 deletions jsrc/cp.c
Original file line number Diff line number Diff line change
Expand Up @@ -299,10 +299,10 @@ static DF1(jtinverr){F1PREFIP;ASSERT(0,EVDOMAIN);} // used for uninvertible mon
// old static CS2(jtply2, df1(z,w,powop(amp(a,fs),gs,0)),0107) // dyad adds x to make x&u, and then reinterpret the compound. We could interpret u differently now that it has been changed (x {~^:a: y)
DF2(jtply2){PROLOG(107);A fs=FAV(self)->fgh[0]; A gs=FAV(self)->fgh[1]; A z, zz; z=(df1(zz,w,powop(amp(a,fs),gs,0))); EPILOG(z);} // scaf remove


static DF1(jtpowg1){A z,h=FAV(self)->fgh[2]; R df1(z, w,C(AAV(h)[0]));} // scaf bivalent
static DF2(jtpowg2){A z,h=FAV(self)->fgh[2]; R df2(z,a,w,C(AAV(h)[0]));}

// obsolete
// obsolete static DF1(jtpowg1){A z,h=FAV(self)->fgh[2]; R df1(z, w,C(AAV(h)[0]));}
// obsolete static DF2(jtpowg2){A z,h=FAV(self)->fgh[2]; R df2(z,a,w,C(AAV(h)[0]));}
// obsolete
// When u^:v is encountered, we replace it with a verb that comes to one of these.
// This creates a verb, jtpowxx, which calls jtdf1 within a PROLOG/EPILOG pair, after creating several names:
// sv->self data; fs=sv->fgh[0] (the A block for the f operand); f1=f1 in sv->fgh[0] (0 if sv->fgh[0]==0); f2=f2 in sv->fgh[0] (0 if sv->fgh[0]==0);
Expand Down Expand Up @@ -475,7 +475,7 @@ DF2(jtpowop){F2PREFIP;B b;V*v;
} // end of 'u^:n'
// obsolete I m=AN(hs); // m=#atoms of n; n=1st atom; r=n has rank>0
// obsolete fdeffill(z,0,CPOWOP,VERB, f1,jtply2, a,w,hs,flag, RMAX,RMAX,RMAX); // Create derived verb: pass in integer powers as h
fdeffill(z,0,CPOWOP,VERB, f1,f2, a,w,h,flag, RMAX,RMAX,RMAX); // Create derived verb: pass in integer powers as h
fdeffill(z,0,CPOWOP,VERB, f1,f2, a,w,h,flag, RMAX,RMAX,RMAX); // Create derived verb: pass in integer powers or inverse as h
FAV(z)->localuse.lu1.poweratom=encn; // pass power info for powatom12, garbage for others
RETF(z);
}
2 changes: 1 addition & 1 deletion jsrc/ja.h
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@
#define detxm(x,y) jtdetxm(jt,(x),(y))
#define detz(x) jtdetz(jt,(x))
#define df1(r,x,y) (r=((r=(y))?(FAV(r)->valencefns[0])((J)((I)jt|(AT(r)&(ADV|CONJ)?JTXDEFMODIFIER:0)),(x),r,r):r)) // y is self; if not 0, execute (x,self,self). Put result into r, set r 0 if self=0.
// r must not = x. self is evaluated only once. If we call a modifier, set that flag
// r must not = x. self is evaluated only once. If we call a modifier, set that flag scaf should replace with df[mv][12] forms
#define dfv1(r,x,y) (r=((r=(y))?(FAV(r)->valencefns[0])(jt,(x),r,r):r)) // z is self, always a verb
// r must not = x. self is evaluated only once. If we call a modifier, set that flag
#define dfv2(r,x,y,z) (r=((r=(z))?(FAV(r)->valencefns[1])(jt,(x),(y),r):r)) // z is self, always a verb Put result into r, set r 0 if self=0. r must not = x or y. self is evaluated only once
Expand Down
2 changes: 1 addition & 1 deletion jsrc/jt.h
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ struct __attribute__((aligned(JTFLAGMSK+1))) JTTstruct {
I1 fillvlen; // length of fill pointed to by fillv (max 16). Modified only within primitives, so inheritance/init immaterial
S etxn; // strlen(etx) but set negative to freeze changes to the error line
S etxn1; // last non-zero etxn
// obsolete B foldrunning; // 1 if fold is running (allows Z:) scaf will go away
// obsolete B foldrunning; // 1 if fold is running (allows Z:)
UC jerr; // error number (0 means no error)
UC jerr1; // last non-zero jerr
C namecaching; // 0=off 1=(either 2 or 4 set) 2=for script 4=on
Expand Down
2 changes: 1 addition & 1 deletion jsrc/r.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ static DF1(jtfxchar){A y;C c,d,id,*s;I m,n;
R box(w); // If top level, we have to make sure (<,'&')` doesn't replace the left part with bare &
}

// Convert an AR to an A block. w is a gerund that has been opened. If it originally came from a verb it can't be a pyx, but it may contain pyxes
// Convert an AR to an A block. w is an AR that has been opened. If it originally came from a verb it can't be a pyx, but it may contain pyxes
// self is normally 0; if nonzero, we return a noun type ('0';<value) as is rather than returning value, and leave adv/conj ARs looking like nouns
DF1(jtfx){A f,fs,g,h,p,q,*wv,y,*yv;C id;I m,n=0;
ARGCHK1(w);
Expand Down

0 comments on commit 08504f9

Please sign in to comment.