int inscoerc=0;
int procarg[2];
#ifdef ALLOW_NEXTEM
- int paniced;
- char *savebp;
+ static int paniced;
+ char *savebp = 0;
#endif
state_t state;
#define SAVEST savestatus(&state)
#ifndef ALLOW_NEXTEM
bp = nextem(toplevel);
#else
- paniced=0;
+ if (toplevel) paniced=0;
savebp = nextem(toplevel);
panic:
bp = savebp;
if (dist<mindistance) {
if(dist==0)
goto gotit;
+#ifdef ALLOW_NEXTEM
+ if (! paniced) {
+#endif
npos=0;
mindistance = dist;
+#ifdef ALLOW_NEXTEM
+ }
+#endif
}
+#ifdef ALLOW_NEXTEM
+ if (dist < MAXINT)
+#endif
pos[npos++] = cindex;
}
}
RESTST;
}
FREEST;
- if (totalcost+mincost>costlimit)
+ if (totalcost+mincost>costlimit) {
BROKE();
+ }
} else {
cindex = pos[0];
}
myfree(regls[j]);
#ifndef ALLOW_NEXTEM
assert(!toplevel);
- BROKE();
#else
assert(!(toplevel&&paniced));
- goto normalfailed;
+ if (paniced) goto normalfailed;
#endif
+ BROKE();
}
if (cp->c3_prop<0) {
totalcost+=docoerc(tp,cp,ply,toplevel,0);
besttup=0;
for (; tup != 0; tup = ntup) {
#ifndef NDEBUG
-if(Debug>1) fprintf(stderr,"Next tuple %d,%d,%d,%d\n",
+if(Debug>1) { fprintf(stderr,"Next tuple %d,%d,%d,%d\n",
tup->p_rar[0],
tup->p_rar[1],
tup->p_rar[2],
tup->p_rar[3]);
+ fprintf(stderr, "totalcost = %u, costlimit = %u, mincost = %u\n",
+ totalcost, costlimit, mincost);
+ }
#endif
ntup = tup->p_next;
for (i=0,t=0;i<nregneeded && t<mincost; i++)
t += docoerc(regtp[i],regcp[i],ply,FALSE,tup->p_rar[i]);
+#ifndef NDEBUG
+if (Debug > 1) fprintf(stderr, "cost after coercions: %u\n", t);
+#endif
if ( t<mincost && tokpatlen<=stackheight ) {
#ifndef NDEBUG
if (Debug>2)
goto nextmatch;
}
totalcost += mincost;
-#ifndef ALLOW_NEXTEM
- BROKE();
-#else
- if (toplevel && !paniced) {
- stackheight=0;
- paniced++;
- DEBUG("PANIC!");
- goto panic;
- } else
- BROKE();
-#endif
+ BROKE();
}
for (i=0;i<nregneeded;i++)
totalcost += docoerc(regtp[i],regcp[i],ply,toplevel,besttup->p_rar[i]);
case DO_RETURN:
DEBUG("RETURN");
assert(origcp!=startupcode);
- doreturn:
#ifndef NDEBUG
level--;
#endif
return(totalcost);
}
}
+ doreturn:
+#ifdef ALLOW_NEXTEM
+ if (toplevel && totalcost == INFINITY && ! paniced) {
+ totalcost += stackupto(&fakestack[stackheight-1], ply, toplevel);
+ paniced = 1;
+ DEBUG("PANIC!");
+ goto panic;
+ }
+#endif
+#ifndef NDEBUG
+ level--;
+#endif
+ return(totalcost);
}
readcodebytes() {
#if MAXMEMBERS!=0
int r_members[MAXMEMBERS]; /* register contained within this reg */
short r_clash[REGSETSIZE]; /* set of clashing registers */
+ int r_iclash; /* index in clashlist; other represen-
+ tation of r_clash
+ */
#endif
int r_refcount; /* Times in use */
token_t r_contents; /* Current contents */
move(tp1,tp2,ply,toplevel,maxcost) token_p tp1,tp2; unsigned maxcost; {
register move_p mp;
- register unsigned t;
+ unsigned t;
register struct reginfo *rp;
- tkdef_p tdp;
+ register byte *tdpb;
int i;
unsigned codegen();
&machregs[tp2->t_att[0].ar].r_contents) &&
machregs[tp1->t_att[0].ar].r_contents.t_token!=0)
return(0);
- erasereg(tp2->t_att[0].ar);
- machregs[tp2->t_att[0].ar].r_contents =
- machregs[tp1->t_att[0].ar].r_contents ;
-
} else {
if (eqtoken(&machregs[tp2->t_att[0].ar].r_contents,tp1))
return(0);
- erasereg(tp2->t_att[0].ar);
- machregs[tp2->t_att[0].ar].r_contents = *tp1;
- }
- for (rp=machregs+1;rp<machregs+NREGS;rp++) {
- if (rp->r_contents.t_token == 0)
- continue;
- assert(rp->r_contents.t_token > 0);
- tdp = &tokens[rp->r_contents.t_token];
- for (i=0;i<TOKENSIZE;i++)
- if (tdp->t_type[i] == EV_REG &&
- clash(rp->r_contents.t_att[i].ar,tp2->t_att[0].ar)) {
- erasereg(rp-machregs);
- break;
- }
}
+ erasereg(tp2->t_att[0].ar);
} else if (tp1->t_token == -1) {
if (eqtoken(tp2,&machregs[tp1->t_att[0].ar].r_contents))
return(0);
- machregs[tp1->t_att[0].ar].r_contents = *tp2;
}
/*
* If we arrive here the move must really be executed
t = codegen(&coderules[mp->m_cindex],ply,toplevel,maxcost,0);
tokpatlen -= 2;
stackheight -= 2;
+ if (tp2->t_token == -1) {
+ rp = &machregs[tp2->t_att[0].ar];
+ if (tp1->t_token == -1) {
+ rp->r_contents =
+ machregs[tp1->t_att[0].ar].r_contents ;
+ }
+ else rp->r_contents = *tp1;
+ if (rp->r_contents.t_token > 0) {
+ tdpb = &(tokens[rp->r_contents.t_token].t_type[0]);
+ for (i=0;i<TOKENSIZE;i++)
+ if (*tdpb++ == EV_REG &&
+ clash(rp->r_contents.t_att[i].ar,tp2->t_att[0].ar)) {
+ rp->r_contents.t_token = 0;
+ for (i = 0; i < TOKENSIZE; i++)
+ rp->r_contents.t_att[i].aw = 0;
+ break;
+ }
+ }
+ }
+ else if (tp1->t_token == -1)
+ machregs[tp1->t_att[0].ar].r_contents = *tp2;
return(t);
}
test(tp,ply,toplevel,maxcost) token_p tp; unsigned maxcost; {
register test_p mp;
- register unsigned t;
- register struct reginfo *rp;
- tkdef_p tdp;
- int i;
+ unsigned t;
unsigned codegen();
if (cocoreg.t_token!=0) {
}
erasereg(regno) {
- register struct reginfo *rp;
+ register struct reginfo *rp = &machregs[regno];
register int i;
- rp = &machregs[regno];
+#if MAXMEMBERS==0
rp->r_contents.t_token = 0;
for (i=0;i<TOKENSIZE;i++)
rp->r_contents.t_att[i].aw = 0;
-#if MAXMEMBERS==0
awayreg(regno);
#else
- for (rp=machregs+1;rp<machregs+NREGS;rp++)
- if (rp->r_clash[regno>>4]&(1<<(regno&017))) {
- rp->r_contents.t_token = 0;
- for (i=0;i<TOKENSIZE;i++)
- rp->r_contents.t_att[i].aw = 0;
- awayreg(rp-machregs);
- }
+ extern short clashlist[];
+ register short *sp = &clashlist[rp->r_iclash];
+
+ rp->r_contents.t_token = 0;
+ while (*sp) {
+ rp = &machregs[*sp];
+ rp->r_contents.t_token = 0;
+ for (i=0;i<TOKENSIZE;i++)
+ rp->r_contents.t_att[i].aw = 0;
+ awayreg(*sp++);
+ }
#endif
}
awayreg(regno) {
register struct reginfo *rp;
- register tkdef_p tdp;
+ register byte *tdpb;
register i;
/* Now erase recursively all registers containing
*/
for (rp=machregs;rp<machregs+NREGS;rp++) {
if (rp->r_contents.t_token == -1) {
- if (rp->r_contents.t_att[0].ar == regno)
- erasereg(rp-machregs);
+ if (rp->r_contents.t_att[0].ar == regno) {
+ /* erasereg(rp-machregs);
+ replaced by the following three
+ lines
+ */
+ rp->r_contents.t_token = 0;
+ for (i=0;i<TOKENSIZE;i++)
+ rp->r_contents.t_att[i].aw = 0;
+ }
} else if (rp->r_contents.t_token > 0) {
- tdp= & tokens[rp->r_contents.t_token];
+ tdpb= & (tokens[rp->r_contents.t_token].t_type[0]);
for (i=0;i<TOKENSIZE;i++)
- if (tdp->t_type[i] == EV_REG &&
+ if (*tdpb++ == EV_REG &&
rp->r_contents.t_att[i].ar == regno) {
- erasereg(rp-machregs);
+ /* erasereg(rp-machregs);
+ replaced by the following three
+ lines
+ */
+ rp->r_contents.t_token = 0;
+ for (i=0;i<TOKENSIZE;i++)
+ rp->r_contents.t_att[i].aw = 0;
break;
}
}
chkregs() {
register struct reginfo *rp;
register token_p tp;
- register tkdef_p tdp;
+ register byte *tdpb;
int i;
for (rp=machregs+1;rp<machregs+NREGS;rp++) {
if (tp->t_token == -1)
inctcount(tp->t_att[0].ar);
else {
- tdp = &tokens[tp->t_token];
+ tdpb = &(tokens[tp->t_token].t_type[0]);
for (i=0;i<TOKENSIZE;i++)
- if (tdp->t_type[i]==EV_REG)
+ if (*tdpb++==EV_REG)
inctcount(tp->t_att[i].ar);
}
}