Skip to content

Commit

Permalink
Make inflected DDBGN/DDEND not a single word; default enable DD
Browse files Browse the repository at this point in the history
  • Loading branch information
HenryHRich committed Oct 19, 2020
1 parent 5019491 commit 691c216
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
2 changes: 1 addition & 1 deletion jsrc/i.c
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ if(((-1) >> 1) != -1)*(I *)4 = 104;
#endif
jt->asgzomblevel = 1; // allow premature change to zombie names, but not data-dependent errors
jt->assert = 1;
jt->directdef = 0; // scaf
jt->directdef = 1; // scaf
RZ(jt->bxa=cstr("+++++++++|-")); jt->bx=CAV(jt->bxa);
jt->cctdefault=jt->cct= 1.0-FUZZ; jt->fuzz=FUZZ;
jt->disp[0]=1; jt->disp[1]=5;
Expand Down
10 changes: 7 additions & 3 deletions jsrc/r.c
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ DF1(jtfx){A f,fs,g,h,p,q,*wv,y,*yv;C id;I m,n=0;
// w is a string block, and so is the result.
// If w is abandoned (which it is for recursive calls), the result is formed inplace over w
// result is always incorpable
static A jtunDD(J jt, A w){PROLOG(676);F1PREFIP;
static A jtunDD(J jt, A w){F1PREFIP;
// quick scan for 9 :; if not, return the input
I scan; for(scan=2;scan<=AN(w)-8;++scan)if(CAV(w)[scan]=='9'&&CAV(w)[scan+2]==':')break;
if(scan<=AN(w)-8){ // if there is possibly a DD...
Expand Down Expand Up @@ -155,8 +155,10 @@ static A jtunDD(J jt, A w){PROLOG(676);F1PREFIP;
}
wilx=wilx>AS(wil)[0]-5?AS(wil)[0]:wilx; // if no more DDs possible, pick entire rest of input
// pack everything before the ( 9 : string ) down into the result
if(inx!=outx){DQ(wilv[wilx-1][1]-inx, wv[outx++]=wv[inx++];)}
if(inx!=outx){DQ(wilv[wilx-1][1]-inx, wv[outx++]=wv[inx++];)}else{inx=outx=wilv[wilx-1][1];}
if(wilx==AS(wil)[0])break; // break if no more DDs
// install leading DD delimiter
wv[outx++]='{'; wv[outx++]='{'; wv[outx++]=' ';
// dequote the string and move it down into the result
I startddx=outx; // remember where the DD starts, because its length may be reduced
inx=wilv[wilx+3][0]+1; I endx=wilv[wilx+3][1]-1; while(inx<endx){if(wv[inx]=='\'')++inx; wv[outx++]=wv[inx++];}
Expand All @@ -167,14 +169,16 @@ static A jtunDD(J jt, A w){PROLOG(676);F1PREFIP;
// the recursion leaves the DD in place, but it may have become shorter if it too contained DDs (the {{ }}
// overhead is always less than the ( 9 : '' ) overhead)
outx=startddx+AN(z);
// install trailing DD delimiter
wv[outx++]=' '; wv[outx++]='}'; wv[outx++]='}';
// skip wordlist pointer to the next candidate
wilx+=5;
}
// Install the length of the final result
AN(w)=AS(w)[0]=outx; // number of chars we transferred
}
// make result incorpable
EPILOG(incorp(w));
RETF(incorp(w));
}

static A jtunparse1(J jt,CW*c,A x,I j,A y){A q,z;C*s;I t;
Expand Down
8 changes: 7 additions & 1 deletion jsrc/w.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
#define EN 1 // start of next word - save position
#define EZ 2 // end and start together - +$ eg

#define UNDD 4 // inflection found on {{ }} - abort the DD state, revert to individual primitives

typedef C ST;
#define SE(s,e) (((s)<<4)|((((s)==S99))<<3)|(e)) // set bit 3 inside followon numeric

Expand All @@ -47,7 +49,7 @@ static const ST state[SDDD+1][16]={
/*SU */ {[CX]=SE(SX,EZ),[CDD]=SE(SDD,EZ),[CDDZ]=SE(SDDZ,EZ),[CU]=SE(SU,EZ),[CS]=SE(SS,EI),[CA]=SE(SA,EZ),[CN]=SE(SN,EZ),[CB]=SE(SA,EZ),[C9]=SE(S9,EZ),[CD]=SE(SX,EZ),[CC]=SE(SX,EZ),[CQ]=SE(SQ,EZ)},
/*SDD*/ {[CX]=SE(SX,EZ),[CDD]=SE(SDDD,E0),[CDDZ]=SE(SX,EZ),[CU]=SE(SU,EZ),[CS]=SE(SS,EI),[CA]=SE(SA,EZ),[CN]=SE(SN,EZ),[CB]=SE(SA,EZ),[C9]=SE(S9,EZ),[CD]=SE(SX,E0),[CC]=SE(SX,E0),[CQ]=SE(SQ,EZ)},
/*SDDZ*/ {[CX]=SE(SX,EZ),[CDD]=SE(SX,EZ),[CDDZ]=SE(SDDD,E0),[CU]=SE(SU,EZ),[CS]=SE(SS,EI),[CA]=SE(SA,EZ),[CN]=SE(SN,EZ),[CB]=SE(SA,EZ),[C9]=SE(S9,EZ),[CD]=SE(SX,E0),[CC]=SE(SX,E0),[CQ]=SE(SQ,EZ)},
/*SDDD*/ {[CX]=SE(SX,EZ),[CDD]=SE(SDD,EZ),[CDDZ]=SE(SDDZ,EZ),[CU]=SE(SU,EZ),[CS]=SE(SS,EI),[CA]=SE(SA,EZ),[CN]=SE(SN,EZ),[CB]=SE(SA,EZ),[C9]=SE(S9,EZ),[CD]=SE(SX,EZ),[CC]=SE(SX,EZ),[CQ]=SE(SQ,EZ)},
/*SDDD*/ {[CX]=SE(SX,EZ),[CDD]=SE(SDD,EZ),[CDDZ]=SE(SDDZ,EZ),[CU]=SE(SU,EZ),[CS]=SE(SS,EI),[CA]=SE(SA,EZ),[CN]=SE(SN,EZ),[CB]=SE(SA,EZ),[C9]=SE(S9,EZ),[CD]=SE(SX,E0)+UNDD,[CC]=SE(SX,E0)+UNDD,[CQ]=SE(SQ,EZ)},
};

// w points to a string A-block
Expand All @@ -71,6 +73,10 @@ if(!jt->directdef&&(currc==CDD||currc==CDDZ))currc=CX; // scaf if direct def d
// obsolete currc+=16-CX; currc&=16; prevs=2*prevs+1; currc&=prevs; // set currc to 16 iff CX/CS/CQ; move 'followon numeric' flag to bit 4; combine
// obsolete // the +1 is to trick the compiler. Without it it moves the &16 onto prevs, but prevs is the critical path
// obsolete x=(I*)((I)x-(currc>>(3-LGSZI))); // subtract from x, to move x back 2 positions if coming out of followon numeric with a number
// handle {{. etc. It looked like a DD but turns out to be inflected. We have outed the start for the first character;
// we also outed the second character but did not accept the word. We accept it now by advancing x over it
// Use an IF because this is rare and we don't want it in the normal path
if(unlikely(s&UNDD))x+=2;
// do two stores, and advance over any that are to be emitted. 0, 1, or 2 may be emitted (0 when the state has no action, 1 when the
// state is an end+1 or start value, and 2 if an end+1 AND start value)
x[0]=i; x[1]=i; x+=s&3;
Expand Down

0 comments on commit 691c216

Please sign in to comment.