add "ap" and "fp" notion, fix SUCC and PRED
authorKirk McKusick <mckusic@ucbvax.Berkeley.EDU>
Sun, 11 Jan 1981 10:25:16 +0000 (02:25 -0800)
committerKirk McKusick <mckusic@ucbvax.Berkeley.EDU>
Sun, 11 Jan 1981 10:25:16 +0000 (02:25 -0800)
SCCS-vsn: usr.bin/pascal/px/interp.c 1.2
SCCS-vsn: usr.bin/pascal/px/Makefile 1.2
SCCS-vsn: usr.bin/pascal/px/utilities.c 1.2
SCCS-vsn: usr.bin/pascal/px/vars.h 1.2

usr/src/usr.bin/pascal/px/Makefile
usr/src/usr.bin/pascal/px/interp.c
usr/src/usr.bin/pascal/px/utilities.c
usr/src/usr.bin/pascal/px/vars.h

index cf208f9..b4b26ed 100644 (file)
@@ -1,6 +1,7 @@
-SCCSID = "@(#)Makefile 1.1 %G%"
+SCCSID = "@(#)Makefile 1.2 %G%"
 
 
-CFLAGS = -O -DVAX -DOBJ
+CFLAGS = -O
+DEFS = -DVAX -DOBJ
 DESTDIR =/usr/ucb
 LIBDIR =/usr/lib
 PASCALDIR = /usr/src/cmd/pascal
 DESTDIR =/usr/ucb
 LIBDIR =/usr/lib
 PASCALDIR = /usr/src/cmd/pascal
@@ -9,36 +10,43 @@ CC = cc
 AS = as
 RM = rm -f
 
 AS = as
 RM = rm -f
 
-PXHDR =        ${PASCALDIR}/OPnames.h ${PASCALDIR}/objfmt.h\
-       ${LIBPCDIR}/libpc.h ${LIBPCDIR}/h01errs.h\
-       newvars.h machdep.h
+PSHDR =        OPnames.h objfmt.h opc.c pic.c
+PCHDR =        libpc.h h01errs.h
+
+PXHDR =        vars.h machdep.h
 
 PXSRC =        int.c interp.c except.c utilities.c
 
 PXOBJ =        int.o interp.o except.o utilities.o
 
 
 PXSRC =        int.c interp.c except.c utilities.c
 
 PXOBJ =        int.o interp.o except.o utilities.o
 
-PXUTL =        ${PASCALDIR}/opc.c ${PASCALDIR}/pic.c ${PASCALDIR}/version.c\
-       make.ed1 panics interp.sed clean.sed
+PXUTL =        make.ed1 panics interp.sed clean.sed version.c
 
 sources: ${PXHDR} ${PXSRC} ${PXUTL}
 
 sources: ${PXHDR} ${PXSRC} ${PXUTL}
-${PXHDR} ${PXUTL}:
-       cp $@ .
+${PSHDR}:
+       cp ${PASCALDIR}/$@ $@
+${PCHDR}:
+       cp ${LIBPCDIR}/$@ $@
+
+.c.o:
+       ${CC} ${CFLAGS} ${DEFS} -c $*.c
 
 px: Version.c ${PXOBJ}
 
 px: Version.c ${PXOBJ}
-       ${CC} -O -o px Version.c ${PXOBJ} /usr/src/lib/libpc/pclib -lm
-Version.c: ${PASCALDIR}/version.c
-       ${CC} -o version ${PASCALDIR}/version.c
+       ${CC} ${CFLAGS} -o px Version.c ${PXOBJ} /usr/src/lib/libpc/libpc -lm
+Version.c: version.c
+       ${CC} ${CFLAGS} -o version version.c
        ./version >Version.c
        ${RM}  version
 interp.o interp.s: interp.c
        ./version >Version.c
        ${RM}  version
 interp.o interp.s: interp.c
-       ${CC} -S interp.c
+       ${CC} ${DEFS} -S interp.c
        sed -f interp.sed <interp.s >tmp
        sed -f interp.sed <interp.s >tmp
+       /usr/lib/pc2 <tmp >interp.s
+       /lib/c2 interp.s tmp
        mv tmp interp.s
        as -o interp.o interp.s
 panics.h: panics make.ed1
        ex - <make.ed1
        mv tmp interp.s
        as -o interp.o interp.s
 panics.h: panics make.ed1
        ex - <make.ed1
-h02opcs.h: ${PASCALDIR}/OPnames.h ${PASCALDIR}/opc.c
-       ${CC} ${PASCALDIR}/opc.c -o opc
+h02opcs.h: OPnames.h opc.c
+       ${CC} ${CFLAGS} opc.c -o opc
        ./opc >h02opcs.h
        ${RM} opc
 
        ./opc >h02opcs.h
        ${RM} opc
 
@@ -54,9 +62,9 @@ prt: interp.s
 
 grind: sources
        @vpr READ_ME makefile
 
 grind: sources
        @vpr READ_ME makefile
-       @${CC} -o pic pic.c
+       @${CC} ${CFLAGS} -o pic pic.c
        @./pic | vpr
        @./pic | vpr
-       @/usr/ucb/vgrind newvars.h objfmt.h machdep.h
+       @/usr/ucb/vgrind vars.h objfmt.h machdep.h
        @/usr/ucb/vgrind ${PXSRC}
        @${RM} pic*
 
        @/usr/ucb/vgrind ${PXSRC}
        @${RM} pic*
 
@@ -78,19 +86,16 @@ depend:     sources
 # DO NOT DELETE THIS LINE -- make depend uses it
 # DEPENDENCIES MUST END AT END OF FILE
 except.o: panics.h
 # DO NOT DELETE THIS LINE -- make depend uses it
 # DEPENDENCIES MUST END AT END OF FILE
 except.o: panics.h
-int.o: newvars.h
+except.o: vars.h
+int.o: vars.h
 int.o: objfmt.h
 int.o: objfmt.h
-interp.o: newvars.h
+interp.o: vars.h
 interp.o: panics.h
 interp.o: h02opcs.h
 interp.o: machdep.h
 interp.o: panics.h
 interp.o: h02opcs.h
 interp.o: machdep.h
+interp.o: h01errs.h
 interp.o: libpc.h
 interp.o: libpc.h
-opc.o: OPnames.h
-panic.o: newvars.h
-panic.o: panics.h
-pic.o: OPnames.h
-stats.o: newvars.h
-utilities.o: newvars.h
+utilities.o: vars.h
 utilities.o: panics.h
 utilities.o: h02opcs.h
 # DEPENDENCIES MUST END AT END OF FILE
 utilities.o: panics.h
 utilities.o: h02opcs.h
 # DEPENDENCIES MUST END AT END OF FILE
index d4e50dc..51f5c94 100644 (file)
@@ -1,6 +1,6 @@
 /* Copyright (c) 1979 Regents of the University of California */
 
 /* Copyright (c) 1979 Regents of the University of California */
 
-static char sccsid[] = "@(#)interp.c 1.1 %G%";
+static char sccsid[] = "@(#)interp.c 1.2 %G%";
 
 #include <math.h>
 #include "vars.h"
 
 #include <math.h>
 #include "vars.h"
@@ -10,14 +10,10 @@ static char sccsid[] = "@(#)interp.c 1.1 %G%";
 #include "h01errs.h"
 #include "libpc.h"
 
 #include "h01errs.h"
 #include "libpc.h"
 
-/* debugging variables */
-char opc[10];
-long opcptr = 9;
-
 /*
  * program variables
  */
 /*
  * program variables
  */
-struct disp    _display[MAXLVL];
+union disply   _display;
 struct disp    *_dp;
 long   _lino = 0;
 int    _argc;
 struct disp    *_dp;
 long   _lino = 0;
 int    _argc;
@@ -87,6 +83,21 @@ struct iorechd       _err = {
        1                       /* fsize   */
 };
 
        1                       /* fsize   */
 };
 
+/*
+ * Px profile array
+ */
+#ifdef PROFILE
+long _profcnts[NUMOPS];
+#endif PROFILE
+
+/*
+ * debugging variables
+ */
+#ifdef DEBUG
+char opc[10];
+long opcptr = 9;
+#endif DEBUG
+\f
 interpreter(base)
        char *base;
 {
 interpreter(base)
        char *base;
 {
@@ -117,54 +128,59 @@ interpreter(base)
        /*
         * set up global environment, then ``call'' the main program
         */
        /*
         * set up global environment, then ``call'' the main program
         */
-       _display[0].locvars = pushsp(2 * sizeof(struct iorec *));
-       *(struct iorec **)(_display[0].locvars + 4) = OUTPUT;
-       *(struct iorec **)(_display[0].locvars) = INPUT;
-       _display[0].locvars += 8;       /* >>> kludge <<< */
-       asm("   bispsw  $0xe0");        /* enable overflow traps */
+       _display.frame[0].locvars = pushsp(2 * sizeof(struct iorec *));
+       _display.frame[0].locvars += 8; /* local offsets are negative */
+       *(struct iorec **)(_display.frame[0].locvars - 4) = OUTPUT;
+       *(struct iorec **)(_display.frame[0].locvars - 8) = INPUT;
+       enableovrflo();
        stp = (struct stack *)pushsp(sizeof(struct stack));
        stp = (struct stack *)pushsp(sizeof(struct stack));
-       _dp = &_display[0];
+       _dp = &_display.frame[0];
        pc.cp = base;
        for(;;) {
        pc.cp = base;
        for(;;) {
+#              ifdef DEBUG
                if (++opcptr == 10)
                        opcptr = 0;
                opc[opcptr] = *pc.ucp;
                if (++opcptr == 10)
                        opcptr = 0;
                opc[opcptr] = *pc.ucp;
+#              endif DEBUG
+#              ifdef PROFILE
+               _profcnts[*pc.ucp]++;
+#              endif PROFILE
                switch (*pc.ucp++) {
                default:
                        panic(PBADOP);
                        continue;
                case O_NODUMP:
                        _nodump++;
                switch (*pc.ucp++) {
                default:
                        panic(PBADOP);
                        continue;
                case O_NODUMP:
                        _nodump++;
-                       asm("   bicpsw  $0xe0");/* disable overflow checks */
+                       disableovrflo();
                        /* and fall through */
                case O_BEG:
                        _dp += 1;               /* enter local scope */
                        stp->odisp = *_dp;      /* save old display value */
                        tl = *pc.ucp++;         /* tl = name size */
                        stp->entry = pc.hdrp;   /* pointer to entry info */
                        /* and fall through */
                case O_BEG:
                        _dp += 1;               /* enter local scope */
                        stp->odisp = *_dp;      /* save old display value */
                        tl = *pc.ucp++;         /* tl = name size */
                        stp->entry = pc.hdrp;   /* pointer to entry info */
-                       tl1 = -*pc.lp++;        /* tl1 = local variable size */
+                       tl1 = *pc.lp++;         /* tl1 = local variable size */
                        pc.lp++;                /* skip over number of args */
                        _lino = *pc.usp++;      /* set new lino */
                        pc.cp += tl;            /* skip over name text */
                        stp->file = curfile;    /* save active file */
                        tcp = pushsp(tl1);      /* tcp = new top of stack */
                        blkclr(tl1, tcp);       /* zero stack frame */
                        pc.lp++;                /* skip over number of args */
                        _lino = *pc.usp++;      /* set new lino */
                        pc.cp += tl;            /* skip over name text */
                        stp->file = curfile;    /* save active file */
                        tcp = pushsp(tl1);      /* tcp = new top of stack */
                        blkclr(tl1, tcp);       /* zero stack frame */
+                       tcp += tl1;             /* offsets of locals are neg */
+                       _dp->locvars = tcp;     /* set new display pointer */
+                       _dp->stp = stp;
                        stp->tos = pushsp(0);   /* set top of stack pointer */
                        stp->tos = pushsp(0);   /* set top of stack pointer */
-                       _dp->stp = stp;         /* set new display pointer */
-                       /* _dp->locvars = tcp; */
-                       _dp->locvars = (char *)stp; /* kludge, use prev line */
                        continue;
                case O_END:
                        PCLOSE(_dp->locvars);   /* flush & close local files */
                        stp = _dp->stp;
                        curfile = stp->file;    /* restore old active file */
                        *_dp = stp->odisp;      /* restore old display entry */
                        continue;
                case O_END:
                        PCLOSE(_dp->locvars);   /* flush & close local files */
                        stp = _dp->stp;
                        curfile = stp->file;    /* restore old active file */
                        *_dp = stp->odisp;      /* restore old display entry */
-                       if (_dp == &_display[1])
+                       if (_dp == &_display.frame[1])
                                return;         /* exiting main proc ??? */
                        _lino = stp->lino;      /* restore lino, pc, dp */
                        pc.cp = stp->pc.cp;
                        _dp = stp->dp;
                                return;         /* exiting main proc ??? */
                        _lino = stp->lino;      /* restore lino, pc, dp */
                        pc.cp = stp->pc.cp;
                        _dp = stp->dp;
-                       popsp(-stp->entry->framesze +   /* pop local vars */
+                       popsp(stp->entry->framesze +    /* pop local vars */
                              sizeof(struct stack) +    /* pop stack frame */
                              stp->entry->nargs);       /* pop parms */
                        continue;
                              sizeof(struct stack) +    /* pop stack frame */
                              stp->entry->nargs);       /* pop parms */
                        continue;
@@ -177,7 +193,7 @@ interpreter(base)
                        stp->lino = _lino;      /* save lino, pc, dp */
                        stp->pc.cp = pc.cp;
                        stp->dp = _dp;
                        stp->lino = _lino;      /* save lino, pc, dp */
                        stp->pc.cp = pc.cp;
                        stp->dp = _dp;
-                       _dp = &_display[tl];    /* set up new display ptr */
+                       _dp = &_display.frame[tl]; /* set up new display ptr */
                        pc.cp = tcp;
                        continue;
                case O_FCALL:
                        pc.cp = tcp;
                        continue;
                case O_FCALL:
@@ -199,11 +215,11 @@ interpreter(base)
                                        tl -= sizeof(int) - 1;
                                ERROR(ENARGS, tl / sizeof(int));
                        }
                                        tl -= sizeof(int) - 1;
                                ERROR(ENARGS, tl / sizeof(int));
                        }
-                       _dp = &_display[tfp->cbn];/* set up new display ptr */
+                       _dp = &_display.frame[tfp->cbn];/* new display ptr */
                        blkcpy(sizeof(struct disp) * tfp->cbn,
                        blkcpy(sizeof(struct disp) * tfp->cbn,
-                               &_display[1], &tfp->disp[tfp->cbn]);
+                               &_display.frame[1], &tfp->disp[tfp->cbn]);
                        blkcpy(sizeof(struct disp) * tfp->cbn,
                        blkcpy(sizeof(struct disp) * tfp->cbn,
-                               &tfp->disp[0], &_display[1]);
+                               &tfp->disp[0], &_display.frame[1]);
                        continue;
                case O_FRTN:
                        tl = *pc.cp++;          /* tl = size of return obj */
                        continue;
                case O_FRTN:
                        tl = *pc.cp++;          /* tl = size of return obj */
@@ -214,7 +230,7 @@ interpreter(base)
                        blkcpy(tl, tcp, tcp + sizeof(struct formalrtn *));
                        popsp(sizeof(struct formalrtn *));
                        blkcpy(sizeof(struct disp) * tfp->cbn,
                        blkcpy(tl, tcp, tcp + sizeof(struct formalrtn *));
                        popsp(sizeof(struct formalrtn *));
                        blkcpy(sizeof(struct disp) * tfp->cbn,
-                               &tfp->disp[tfp->cbn], &_display[1]);
+                               &tfp->disp[tfp->cbn], &_display.frame[1]);
                        continue;
                case O_FSAV:
                        tfp = (struct formalrtn *)popaddr();
                        continue;
                case O_FSAV:
                        tfp = (struct formalrtn *)popaddr();
@@ -223,7 +239,7 @@ interpreter(base)
                        tcp += sizeof(short);
                        tfp->entryaddr = base + *(long *)tcp;
                        blkcpy(sizeof(struct disp) * tfp->cbn,
                        tcp += sizeof(short);
                        tfp->entryaddr = base + *(long *)tcp;
                        blkcpy(sizeof(struct disp) * tfp->cbn,
-                               &_display[1], &tfp->disp[0]);
+                               &_display.frame[1], &tfp->disp[0]);
                        pushaddr(tfp);
                        continue;
                case O_SDUP2:
                        pushaddr(tfp);
                        continue;
                case O_SDUP2:
@@ -247,11 +263,12 @@ interpreter(base)
                        pc.cp = base + *pc.lp;
                        continue;
                case O_GOTO:
                        pc.cp = base + *pc.lp;
                        continue;
                case O_GOTO:
-                       tstp = _display[*pc.cp++].stp; /* ptr to exit frame */
+                       tstp = _display.frame[*pc.cp++].stp; /* ptr to
+                                                               exit frame */
                        pc.cp = base + *pc.lp;
                        stp = _dp->stp;
                        while (tstp != stp) {
                        pc.cp = base + *pc.lp;
                        stp = _dp->stp;
                        while (tstp != stp) {
-                               if (_dp == &_display[1])
+                               if (_dp == &_display.frame[1])
                                        ERROR(EGOTO); /* exiting prog ??? */
                                PCLOSE(_dp->locvars); /* close local files */
                                curfile = stp->file;  /* restore active file */
                                        ERROR(EGOTO); /* exiting prog ??? */
                                PCLOSE(_dp->locvars); /* close local files */
                                curfile = stp->file;  /* restore active file */
@@ -511,7 +528,7 @@ interpreter(base)
                                tl = *pc.usp++;
                        tl1 = pop2();           /* index */
                        tl2 = *pc.sp++;
                                tl = *pc.usp++;
                        tl1 = pop2();           /* index */
                        tl2 = *pc.sp++;
-                       SUBSC(tl1, tl2, tl2 + *pc.usp++); /* range check */
+                       SUBSC(tl1, tl2, *pc.usp++); /* range check */
                        pushaddr(popaddr() + (tl1 - tl2) * tl);
                        continue;
                case O_INX4:
                        pushaddr(popaddr() + (tl1 - tl2) * tl);
                        continue;
                case O_INX4:
@@ -520,7 +537,7 @@ interpreter(base)
                                tl = *pc.usp++;
                        tl1 = pop4();           /* index */
                        tl2 = *pc.sp++;
                                tl = *pc.usp++;
                        tl1 = pop4();           /* index */
                        tl2 = *pc.sp++;
-                       SUBSC(tl1, tl2, tl2 + *pc.usp++); /* range check */
+                       SUBSC(tl1, tl2, *pc.usp++); /* range check */
                        pushaddr(popaddr() + (tl1 - tl2) * tl);
                        continue;
                case O_OFF:
                        pushaddr(popaddr() + (tl1 - tl2) * tl);
                        continue;
                case O_OFF:
@@ -789,73 +806,73 @@ interpreter(base)
                        push8(pop4() / td);
                        continue;
                case O_RV1:
                        push8(pop4() / td);
                        continue;
                case O_RV1:
-                       tcp = _display[*pc.ucp++].locvars;
+                       tcp = _display.raw[*pc.ucp++];
                        push2(*(tcp + *pc.sp++));
                        continue;
                case O_RV14:
                        push2(*(tcp + *pc.sp++));
                        continue;
                case O_RV14:
-                       tcp = _display[*pc.ucp++].locvars;
+                       tcp = _display.raw[*pc.ucp++];
                        push4(*(tcp + *pc.sp++));
                        continue;
                case O_RV2:
                        push4(*(tcp + *pc.sp++));
                        continue;
                case O_RV2:
-                       tcp = _display[*pc.ucp++].locvars;
+                       tcp = _display.raw[*pc.ucp++];
                        push2(*(short *)(tcp + *pc.sp++));
                        continue;
                case O_RV24:
                        push2(*(short *)(tcp + *pc.sp++));
                        continue;
                case O_RV24:
-                       tcp = _display[*pc.ucp++].locvars;
+                       tcp = _display.raw[*pc.ucp++];
                        push4(*(short *)(tcp + *pc.sp++));
                        continue;
                case O_RV4:
                        push4(*(short *)(tcp + *pc.sp++));
                        continue;
                case O_RV4:
-                       tcp = _display[*pc.ucp++].locvars;
+                       tcp = _display.raw[*pc.ucp++];
                        push4(*(long *)(tcp + *pc.sp++));
                        continue;
                case O_RV8:
                        push4(*(long *)(tcp + *pc.sp++));
                        continue;
                case O_RV8:
-                       tcp = _display[*pc.ucp++].locvars;
+                       tcp = _display.raw[*pc.ucp++];
                        push8(*(double *)(tcp + *pc.sp++));
                        continue;
                case O_RV:
                        push8(*(double *)(tcp + *pc.sp++));
                        continue;
                case O_RV:
-                       tcp = _display[*pc.ucp++].locvars;
+                       tcp = _display.raw[*pc.ucp++];
                        tcp += *pc.sp++;
                        tl = *pc.usp++;
                        tcp1 = pushsp(tl);
                        blkcpy(tl, tcp, tcp1);
                        continue;
                case O_LV:
                        tcp += *pc.sp++;
                        tl = *pc.usp++;
                        tcp1 = pushsp(tl);
                        blkcpy(tl, tcp, tcp1);
                        continue;
                case O_LV:
-                       tcp = _display[*pc.ucp++].locvars;
+                       tcp = _display.raw[*pc.ucp++];
                        pushaddr(tcp + *pc.sp++);
                        continue;
                case O_LRV1:
                        pushaddr(tcp + *pc.sp++);
                        continue;
                case O_LRV1:
-                       tcp = _display[*pc.ucp++].locvars;
+                       tcp = _display.raw[*pc.ucp++];
                        push2(*(tcp + *pc.lp++));
                        continue;
                case O_LRV14:
                        push2(*(tcp + *pc.lp++));
                        continue;
                case O_LRV14:
-                       tcp = _display[*pc.ucp++].locvars;
+                       tcp = _display.raw[*pc.ucp++];
                        push4(*(tcp + *pc.lp++));
                        continue;
                case O_LRV2:
                        push4(*(tcp + *pc.lp++));
                        continue;
                case O_LRV2:
-                       tcp = _display[*pc.ucp++].locvars;
+                       tcp = _display.raw[*pc.ucp++];
                        push2(*(short *)(tcp + *pc.lp++));
                        continue;
                case O_LRV24:
                        push2(*(short *)(tcp + *pc.lp++));
                        continue;
                case O_LRV24:
-                       tcp = _display[*pc.ucp++].locvars;
+                       tcp = _display.raw[*pc.ucp++];
                        push4(*(short *)(tcp + *pc.lp++));
                        continue;
                case O_LRV4:
                        push4(*(short *)(tcp + *pc.lp++));
                        continue;
                case O_LRV4:
-                       tcp = _display[*pc.ucp++].locvars;
+                       tcp = _display.raw[*pc.ucp++];
                        push4(*(long *)(tcp + *pc.lp++));
                        continue;
                case O_LRV8:
                        push4(*(long *)(tcp + *pc.lp++));
                        continue;
                case O_LRV8:
-                       tcp = _display[*pc.ucp++].locvars;
+                       tcp = _display.raw[*pc.ucp++];
                        push8(*(double *)(tcp + *pc.lp++));
                        continue;
                case O_LRV:
                        push8(*(double *)(tcp + *pc.lp++));
                        continue;
                case O_LRV:
-                       tcp = _display[*pc.ucp++].locvars;
+                       tcp = _display.raw[*pc.ucp++];
                        tcp += *pc.lp++;
                        tl = *pc.usp++;
                        tcp1 = pushsp(tl);
                        blkcpy(tl, tcp, tcp1);
                        continue;
                case O_LLV:
                        tcp += *pc.lp++;
                        tl = *pc.usp++;
                        tcp1 = pushsp(tl);
                        blkcpy(tl, tcp, tcp1);
                        continue;
                case O_LLV:
-                       tcp = _display[*pc.ucp++].locvars;
+                       tcp = _display.raw[*pc.ucp++];
                        pushaddr(tcp + *pc.lp++);
                        continue;
                case O_IND1:
                        pushaddr(tcp + *pc.lp++);
                        continue;
                case O_IND1:
@@ -1112,7 +1129,7 @@ interpreter(base)
                        continue;
                case O_ASRT:
                        pc.cp++;
                        continue;
                case O_ASRT:
                        pc.cp++;
-                       ASRT(pop2());
+                       ASRT(pop2(), "");
                        continue;
                case O_FOR1U:
                        pc.cp++;
                        continue;
                case O_FOR1U:
                        pc.cp++;
@@ -1260,6 +1277,10 @@ interpreter(base)
                        PFLUSH();
                        curfile = ERR;
                        continue;
                        PFLUSH();
                        curfile = ERR;
                        continue;
+               case O_PUT:
+                       pc.cp++;
+                       PUT(curfile);
+                       continue;
                case O_GET:
                        pc.cp++;
                        GET(curfile);
                case O_GET:
                        pc.cp++;
                        GET(curfile);
@@ -1394,64 +1415,46 @@ interpreter(base)
                        push2(pop4() & 1);
                        continue;
                case O_SUCC2:
                        push2(pop4() & 1);
                        continue;
                case O_SUCC2:
-                       /* Pi should be fixed to gen code for:
-                        *      tl = *pc.cp++;
-                        *      if (tl == 0)
-                        *              tl = *pc.sp++;
-                        *      tl1 = pop4();
-                        *      push2(SUCC(tl1, tl, *pc.sp++));
-                        */
-                       pc.cp++;
-                       push2(pop4() + 1);
+                       tl = *pc.cp++;
+                       if (tl == 0)
+                               tl = *pc.sp++;
+                       tl1 = pop4();
+                       push2(SUCC(tl1, tl, *pc.sp++));
                        continue;
                case O_SUCC24:
                        continue;
                case O_SUCC24:
-                       /* Pi should be fixed to gen code for:
-                        *      tl = *pc.cp++;
-                        *      if (tl == 0)
-                        *              tl = *pc.sp++;
-                        *      tl1 = pop4();
-                        *      push4(SUCC(tl1, tl, *pc.sp++));
-                        */
+                       tl = *pc.cp++;
+                       if (tl == 0)
+                               tl = *pc.sp++;
+                       tl1 = pop4();
+                       push4(SUCC(tl1, tl, *pc.sp++));
+                       continue;
                case O_SUCC4:
                case O_SUCC4:
-                       /* Pi should be fixed to gen code for:
-                        *      tl = *pc.cp++;
-                        *      if (tl == 0)
-                        *              tl = *pc.lp++;
-                        *      tl1 = pop4();
-                        *      push4(SUCC(tl1, tl, *pc.lp++));
-                        */
-                       pc.cp++;
-                       push4(pop4() + 1);
+                       tl = *pc.cp++;
+                       if (tl == 0)
+                               tl = *pc.lp++;
+                       tl1 = pop4();
+                       push4(SUCC(tl1, tl, *pc.lp++));
                        continue;
                case O_PRED2:
                        continue;
                case O_PRED2:
-                       /* Pi should be fixed to gen code for:
-                        *      tl = *pc.cp++;
-                        *      if (tl == 0)
-                        *              tl = *pc.sp++;
-                        *      tl1 = pop4();
-                        *      push2(PRED(tl1, tl, *pc.sp++));
-                        */
-                       pc.cp++;
-                       push2(pop4() - 1);
+                       tl = *pc.cp++;
+                       if (tl == 0)
+                               tl = *pc.sp++;
+                       tl1 = pop4();
+                       push2(PRED(tl1, tl, *pc.sp++));
                        continue;
                case O_PRED24:
                        continue;
                case O_PRED24:
-                       /* Pi should be fixed to gen code for:
-                        *      tl = *pc.cp++;
-                        *      if (tl == 0)
-                        *              tl = *pc.sp++;
-                        *      tl1 = pop4();
-                        *      push4(PRED(tl1, tl, *pc.sp++));
-                        */
+                       tl = *pc.cp++;
+                       if (tl == 0)
+                               tl = *pc.sp++;
+                       tl1 = pop4();
+                       push4(PRED(tl1, tl, *pc.sp++));
+                       continue;
                case O_PRED4:
                case O_PRED4:
-                       /* Pi should be fixed to gen code for:
-                        *      tl = *pc.cp++;
-                        *      if (tl == 0)
-                        *              tl = *pc.lp++;
-                        *      tl1 = pop4();
-                        *      push4(PRED(tl1, tl, *pc.lp++));
-                        */
-                       pc.cp++;
-                       push4(pop4() - 1);
+                       tl = *pc.cp++;
+                       if (tl == 0)
+                               tl = *pc.lp++;
+                       tl1 = pop4();
+                       push4(PRED(tl1, tl, *pc.lp++));
                        continue;
                case O_SEED:
                        pc.cp++;
                        continue;
                case O_SEED:
                        pc.cp++;
index 11966f6..0a5fe69 100644 (file)
@@ -1,6 +1,6 @@
 /* Copyright (c) 1979 Regents of the University of California */
 
 /* Copyright (c) 1979 Regents of the University of California */
 
-static char sccsid[] = "@(#)utilities.c 1.1 %G%";
+static char sccsid[] = "@(#)utilities.c 1.2 %G%";
 
 #include       "vars.h"
 #include       "panics.h"
 
 #include       "vars.h"
 #include       "panics.h"
@@ -13,39 +13,47 @@ stats()
                long    sys_time;
                long    child_usr_time;
                long    child_sys_time;
                long    sys_time;
                long    child_usr_time;
                long    child_sys_time;
-               } tbuf;
+       } tbuf;
        register double l;
        register long count;
        register double l;
        register long count;
+#      ifdef PROFILE
+#      define  proffile        "/vb/grad/mckusick/px/profile/pcnt.out"
+       struct cntrec {
+               double  counts[NUMOPS]; /* instruction counts */
+               long    runs;           /* number of interpreter runs */
+               long    startdate;      /* date profile started */
+               long    usrtime;        /* total user time consumed */
+               long    systime;        /* total system time consumed */
+               double  stmts;          /* number of pascal stmts executed */
+       } profdata;
+       FILE *datafile;
+#      endif PROFILE
 
        if (_nodump)
                return(0);
        times(&tbuf);
 
        if (_nodump)
                return(0);
        times(&tbuf);
-#ifdef profile
+#      ifdef PROFILE
        datafile = fopen(proffile,"r");
        datafile = fopen(proffile,"r");
-       if (datafile != NULL) {
-               count = fread(&profdata,sizeof(profdata),1,datafile);
-               if (count != 1) {
-                       for (count = 0;  count < numops;  count++)
-                               profdata.counts[count] = 0.0;
-                       profdata.runs = 0;
-                       profdata.startdate = time(0);
-                       profdata.usrtime = 0;
-                       profdata.systime = 0;
-                       profdata.stmts = 0;
-               }
-               for (count = 0;  count < numops;  count++)
-                       profdata.counts[count] += profcnts[count];
-               profdata.runs += 1;
-               profdata.stmts += stcnt;
-               profdata.usrtime += tbuf.usr_time;
-               profdata.systime += tbuf.sys_time;
-               datafile = freopen(proffile,"w",datafile);
-               if (datafile != NULL) {
-                       fwrite(&profdata,sizeof(profdata),1,datafile);
-                       fclose(datafile);
-               }
-       }
-#endif
+       if (datafile == NULL)
+               goto skipprof;
+       count = fread(&profdata,1,sizeof(profdata),datafile);
+       if (count != sizeof(profdata))
+               goto skipprof;
+       for (count = 0;  count < NUMOPS;  count++)
+               profdata.counts[count] += _profcnts[count];
+       profdata.runs += 1;
+       profdata.stmts += _stcnt;
+       profdata.usrtime += tbuf.usr_time;
+       profdata.systime += tbuf.sys_time;
+       datafile = freopen(proffile,"w",datafile);
+       if (datafile == NULL)
+               goto skipprof;
+       count = fwrite(&profdata,1,sizeof(profdata),datafile);
+       if (count != sizeof(profdata))
+               goto skipprof;
+       fclose(datafile);
+skipprof:
+#      endif PROFILE
        l = tbuf.usr_time;
        l = l / HZ;
        fprintf(stderr,
        l = tbuf.usr_time;
        l = l / HZ;
        fprintf(stderr,
@@ -60,14 +68,13 @@ backtrace(errnum)
        register struct stack *ap;
        register char *cp;
        register long i, linum;
        register struct stack *ap;
        register char *cp;
        register long i, linum;
-       struct disp disp[MAXLVL];
+       struct disply disp;
 
        if (_lino <= 0) {
                fputs("Program was not executed.\n",stderr);
                return;
        }
 
        if (_lino <= 0) {
                fputs("Program was not executed.\n",stderr);
                return;
        }
-       for (i=0; i<MAXLVL; i++)
-               disp[i] = _display[i];
+       disp = _display;
        if (errnum == PINTR)
                fputs("\n\tInterrupted in \"",stderr);
        else if (errnum == PHALT)
        if (errnum == PINTR)
                fputs("\n\tInterrupted in \"",stderr);
        else if (errnum == PHALT)
@@ -84,9 +91,8 @@ backtrace(errnum)
                        fprintf(stderr,"+%1d near line %1d.",i,linum);
                fputc('\n',stderr);
                *mydp = (ap)->odisp;
                        fprintf(stderr,"+%1d near line %1d.",i,linum);
                fputc('\n',stderr);
                *mydp = (ap)->odisp;
-               if (mydp <= &_display[1]){
-                       for (i=0; i<MAXLVL; i++)
-                               _display[i] = disp[i];
+               if (mydp <= &_display.frame[1]){
+                       _display = disp;
                        psexit(errnum);
                }
                mydp = (ap)->dp;
                        psexit(errnum);
                }
                mydp = (ap)->dp;
index 4dbeaf6..6310e20 100644 (file)
@@ -1,6 +1,6 @@
 /* Copyright (c) 1979 Regents of the University of California */
 
 /* Copyright (c) 1979 Regents of the University of California */
 
-/* static char sccsid[] = "@(#)vars.h 1.1 %G%"; */
+/* static char sccsid[] = "@(#)vars.h 1.2 %G%"; */
 
 #include <stdio.h>
 
 
 #include <stdio.h>
 
 #define        PIX     1       /* load and go */
 #define        PIPE    2       /* bootstrap via a pipe */
 #define releq 0
 #define        PIX     1       /* load and go */
 #define        PIPE    2       /* bootstrap via a pipe */
 #define releq 0
-#define relne 1
-#define rellt 2
-#define relgt 3
-#define relle 4
-#define relge 5
+#define relne 2
+#define rellt 4
+#define relgt 6
+#define relle 8
+#define relge 10
 
 /*
  * interrupt and allocation routines
 
 /*
  * interrupt and allocation routines
@@ -108,8 +108,8 @@ union progcntr {
  *               |             |
  *               | block mark  |
  *               |             |
  *               |             |
  *               | block mark  |
  *               |             |
- *               ---------------  <-- display entry points here
- *               |             |
+ *               ---------------  <-- display entry "stp" points here
+ *               |             |  <-- display entry "locvars" points here
  *               |   local     |
  *               |  variables  |
  *               |             |
  *               |   local     |
  *               |  variables  |
  *               |             |
@@ -122,9 +122,10 @@ union progcntr {
  *               - - - - - - - -
  *
  * The information in the block mark is thus at positive offsets from
  *               - - - - - - - -
  *
  * The information in the block mark is thus at positive offsets from
- * the display pointer entries while the local variables are at negative
- * offsets. The block mark actually consists of two parts. The first
- * part is created at CALL and the second at entry, i.e. BEGIN. Thus:
+ * the display.stp pointer entries while the local variables are at negative
+ * offsets from display.locvars. The block mark actually consists of
+ * two parts. The first part is created at CALL and the second at entry,
+ * i.e. BEGIN. Thus:
  *
  *             -------------------------
  *             |                       |
  *
  *             -------------------------
  *             |                       |
@@ -136,11 +137,11 @@ union progcntr {
  *             |                       |
  *             |  Saved (dp)           |
  *             |                       |
  *             |                       |
  *             |  Saved (dp)           |
  *             |                       |
- *             |  Current section name |
- *             |   and entry line ptr  |
+ *             |  Pointer to current   |
+ *             |   routine header info |
  *             |                       |
  *             |                       |
- *             |  Saved file name and  |
- *             |   file buffer ptr     |
+ *             |  Saved value of       |
+ *             |   "curfile"           |
  *             |                       |
  *             |  Empty tos value      |
  *             |                       |
  *             |                       |
  *             |  Empty tos value      |
  *             |                       |
@@ -170,6 +171,11 @@ struct stack {
        long lino;              /* previous line number */
 };
 
        long lino;              /* previous line number */
 };
 
+union disply {
+       struct disp frame[MAXLVL];
+       char *raw[2*MAXLVL];
+};
+
 /*
  * formal routine structure
  */
 /*
  * formal routine structure
  */
@@ -182,21 +188,21 @@ struct formalrtn {
 /*
  * program variables
  */
 /*
  * program variables
  */
-extern struct disp     _display[MAXLVL];       /* runtime display */
-extern struct disp     *_dp;                   /* runtime display */
-extern long            _lino;                  /* current line number */
-extern int             _argc;                  /* number of passed args */
-extern char            **_argv;                /* values of passed args */
-extern long            _nodump;                /* 1 => no post mortum dump */
-extern long            _mode;                  /* execl by PX, PIPE, or PIX */
-extern long            _stlim;                 /* statement limit */
-extern long            _stcnt;                 /* statement count */
-extern char            *_maxptr;               /* maximum valid pointer */
-extern char            *_minptr;               /* minimum valid pointer */
-extern long            *_pcpcount;             /* pointer to pxp buffer */
-extern long            _cntrs;                 /* number of counters */
-extern long            _rtns;                  /* number of routine cntrs */
-
+extern union disply    _display;       /* runtime display */
+extern struct disp     *_dp;           /* ptr to active frame */
+extern long            _lino;          /* current line number */
+extern int             _argc;          /* number of passed args */
+extern char            **_argv;        /* values of passed args */
+extern long            _nodump;        /* 1 => no post mortum dump */
+extern long            _mode;          /* execl by PX, PIPE, or PIX */
+extern long            _stlim;         /* statement limit */
+extern long            _stcnt;         /* statement count */
+extern char            *_maxptr;       /* maximum valid pointer */
+extern char            *_minptr;       /* minimum valid pointer */
+extern long            *_pcpcount;     /* pointer to pxp buffer */
+extern long            _cntrs;         /* number of counters */
+extern long            _rtns;          /* number of routine cntrs */
+\f
 /*
  * The file i/o routines maintain a notion of a "current file".
  * A pointer to this file structure is kept in "curfile".
 /*
  * The file i/o routines maintain a notion of a "current file".
  * A pointer to this file structure is kept in "curfile".
@@ -232,7 +238,7 @@ struct iorec {
        char            buf[BUFSIZ];    /* I/O buffer */
        char            window[1];      /* file window element */
 };
        char            buf[BUFSIZ];    /* I/O buffer */
        char            window[1];      /* file window element */
 };
-
+\f
 /*
  * unit flags
  */
 /*
  * unit flags
  */
@@ -264,23 +270,11 @@ extern long               _filefre;       /* last used entry in _actfile */
 extern struct iorechd  input;
 extern struct iorechd  output;
 extern struct iorechd  _err;
 extern struct iorechd  input;
 extern struct iorechd  output;
 extern struct iorechd  _err;
-\f
-#ifdef profile
+
 /*
 /*
- * Px execution profile data
+ * Px execution profile array
  */
  */
-#define        numops 256
-struct cntrec {
-       double  counts[numops]; /* instruction counts */
-       long    runs;           /* number of interpreter runs */
-       long    startdate;      /* date profile started */
-       long    usrtime;        /* total user time consumed */
-       long    systime;        /* total system time consumed */
-       double  stmts;          /* number of pascal statements executed */
-       } profdata;
-long   profcnts[numops];
-#define        proffile        "/usr/grad/mckusick/px/profile/pcnt.out"
-FILE   *datafile;              /* input datafiles */
-#else
-int    profcnts;       /* dummy just to keep the linker happy */
-#endif
+#ifdef PROFILE
+#define        NUMOPS 256
+extern long _profcnts[NUMOPS];
+#endif PROFILE