modify to allow use of px written in `C' and the use of libpc
authorKirk McKusick <mckusic@ucbvax.Berkeley.EDU>
Wed, 7 Jan 1981 09:18:08 +0000 (01:18 -0800)
committerKirk McKusick <mckusic@ucbvax.Berkeley.EDU>
Wed, 7 Jan 1981 09:18:08 +0000 (01:18 -0800)
SCCS-vsn: usr.bin/pascal/src/fdec.c 1.8
SCCS-vsn: usr.bin/pascal/src/flvalue.c 1.3
SCCS-vsn: usr.bin/pascal/src/func.c 1.4
SCCS-vsn: usr.bin/pascal/src/lval.c 1.2
SCCS-vsn: usr.bin/pascal/src/objfmt.h 1.3
SCCS-vsn: usr.bin/pascal/src/proc.c 1.4
SCCS-vsn: usr.bin/pascal/src/put.c 1.5
SCCS-vsn: usr.bin/pascal/src/var.c 1.4

usr/src/usr.bin/pascal/src/fdec.c
usr/src/usr.bin/pascal/src/flvalue.c
usr/src/usr.bin/pascal/src/func.c
usr/src/usr.bin/pascal/src/lval.c
usr/src/usr.bin/pascal/src/objfmt.h
usr/src/usr.bin/pascal/src/proc.c
usr/src/usr.bin/pascal/src/put.c
usr/src/usr.bin/pascal/src/var.c

index 51ea6ec..e85d080 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[] = "@(#)fdec.c 1.7 %G%";
+static char sccsid[] = "@(#)fdec.c 1.8 %G%";
 
 #include "whoami.h"
 #include "0.h"
 
 #include "whoami.h"
 #include "0.h"
@@ -700,15 +700,12 @@ funcend(fp, bundle, endline)
                                continue;
                        }
 #                      ifdef OBJ
                                continue;
                        }
 #                      ifdef OBJ
-                           put(2, O_LV | bn << 8+INDX, iop->value[NL_OFFS]);
+                           put(2, O_CON24, text(iop->type) ? 0 : width(iop->type->type));
                            i = lenstr(p->symbol,0);
                            i = lenstr(p->symbol,0);
+                           put(2, O_CON24, i);
                            put(2, O_LVCON, i);
                            putstr(p->symbol, 0);
                            put(2, O_LVCON, i);
                            putstr(p->symbol, 0);
-                           do {
-                               i--;
-                           } while (p->symbol+i == 0);
-                           put(2, O_CON24, i+1);
-                           put(2, O_CON24, text(iop->type) ? 0 : width(iop->type->type));
+                           put(2, O_LV | bn << 8+INDX, iop->value[NL_OFFS]);
                            put(1, O_DEFNAME);
 #                      endif OBJ
 #                      ifdef PC
                            put(1, O_DEFNAME);
 #                      endif OBJ
 #                      ifdef PC
@@ -762,6 +759,8 @@ funcend(fp, bundle, endline)
                putleaf( P2ICON , cnts , 0 , P2INT , 0 );
                putleaf( P2ICON , pfcnt , 0 , P2INT , 0 );
                putop( P2LISTOP , P2INT );
                putleaf( P2ICON , cnts , 0 , P2INT , 0 );
                putleaf( P2ICON , pfcnt , 0 , P2INT , 0 );
                putop( P2LISTOP , P2INT );
+               putLV( PCPCOUNT , 0 , 0 , P2INT );
+               putop( P2LISTOP , P2INT );
                putop( P2CALL , P2INT );
                putdot( filename , line );
            }
                putop( P2CALL , P2INT );
                putdot( filename , line );
            }
index 2b1e49a..21e8801 100644 (file)
@@ -1,6 +1,6 @@
 /* Copyright (c) 1980 Regents of the University of California */
 
 /* Copyright (c) 1980 Regents of the University of California */
 
-static char sccsid[] = "@(#)flvalue.c 1.2 %G%";
+static char sccsid[] = "@(#)flvalue.c 1.3 %G%";
 
 #include "whoami.h"
 #include "0.h"
 
 #include "whoami.h"
 #include "0.h"
@@ -13,11 +13,11 @@ static      char sccsid[] = "@(#)flvalue.c 1.2 %G%";
 #endif PC
 #ifdef OBJ
 /*
 #endif PC
 #ifdef OBJ
 /*
- * define the display structure for purposes of allocating
- * a temporary
+ * runtime display structure
  */
 struct dispsave {
  */
 struct dispsave {
-       char    *ptr;
+       char *locvars;          /* pointer to local variables */
+       struct stack *stp;      /* pointer to local stack frame */
 };
 #endif OBJ
 
 };
 #endif OBJ
 
index 04c78c3..fdb6270 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[] = "@(#)func.c 1.3 %G%";
+static char sccsid[] = "@(#)func.c 1.4 %G%";
 
 #include "whoami.h"
 #ifdef OBJ
 
 #include "whoami.h"
 #ifdef OBJ
@@ -107,7 +107,10 @@ funccod(r)
        /*
         * Evaluate the argmument
         */
        /*
         * Evaluate the argmument
         */
-       p1 = stkrval((int *) argv[1], NLNIL , RREQ );
+       if (op == O_EOF || op == O_EOLN)
+               p1 = stklval((int *) argv[1], NLNIL , LREQ );
+       else
+               p1 = stkrval((int *) argv[1], NLNIL , RREQ );
        if (p1 == NIL)
                return (NIL);
        switch (op) {
        if (p1 == NIL)
                return (NIL);
        switch (op) {
index 3638862..346680d 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[] = "@(#)lval.c 1.1 %G%";
+static char sccsid[] = "@(#)lval.c 1.2 %G%";
 
 #include "whoami.h"
 #include "0.h"
 
 #include "whoami.h"
 #include "0.h"
@@ -135,7 +135,28 @@ lvalue(r, modflag , required )
                                        goto bad;
                                }
                                if (f) {
                                        goto bad;
                                }
                                if (f) {
-                                   put(2, PTR_RV | bn <<8+INDX , o );
+                                   if (p->class == FILET && bn != 0)
+                                       put(2, O_LV | bn <<8+INDX , o );
+                                   else
+                                       /*
+                                        * this is the indirection from
+                                        * the address of the pointer 
+                                        * to the pointer itself.
+                                        * kirk sez:
+                                        * fnil doesn't want this.
+                                        * and does it itself for files
+                                        * since only it knows where the
+                                        * actual window is.
+                                        * but i have to do this for
+                                        * regular pointers.
+                                        * This is further complicated by
+                                        * the fact that global variables
+                                        * are referenced through pointers
+                                        * on the stack. Thus an RV on a
+                                        * global variable is the same as
+                                        * an LV of a non-global one ?!?
+                                        */
+                                       put(2, PTR_RV | bn <<8+INDX , o );
                                } else {
                                        if (o) {
                                            put2(O_OFF, o);
                                } else {
                                        if (o) {
                                            put2(O_OFF, o);
@@ -167,7 +188,15 @@ lvalue(r, modflag , required )
                                        goto bad;
                                }
                                if (f) {
                                        goto bad;
                                }
                                if (f) {
-                                       put2(O_LV | bn<<8+INDX, o);
+                                       if (bn == 0)
+                                               /*
+                                                * global variables are
+                                                * referenced through pointers
+                                                * on the stack
+                                                */
+                                               put2(PTR_RV | bn<<8+INDX, o);
+                                       else
+                                               put2(O_LV | bn<<8+INDX, o);
                                } else {
                                        if (o) {
                                            put2(O_OFF, o);
                                } else {
                                        if (o) {
                                            put2(O_OFF, o);
@@ -219,7 +248,14 @@ lvalue(r, modflag , required )
                }
        }
        if (f) {
                }
        }
        if (f) {
-               put2(O_LV | bn<<8+INDX, o);
+               if (bn == 0)
+                       /*
+                        * global variables are referenced through
+                        * pointers on the stack
+                        */
+                       put2(PTR_RV | bn<<8+INDX, o);
+               else
+                       put2(O_LV | bn<<8+INDX, o);
        } else {
                if (o) {
                    put2(O_OFF, o);
        } else {
                if (o) {
                    put2(O_OFF, o);
index 2c2e067..6b97196 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[] = "@(#)objfmt.h 1.2 %G%"; */
+/* static      char sccsid[] = "@(#)objfmt.h 1.3 %G%"; */
 
 #ifdef OBJ
        /*
 
 #ifdef OBJ
        /*
@@ -15,6 +15,7 @@
 #   define     HEADER_BYTES    1024            /* the size of px_header */
 #   define PX_HEADER "/usr/lib/px_header"      /* px_header's name */
 #   define PX_INTRP "/usr/ucb/px"              /* the interpreter's name */
 #   define     HEADER_BYTES    1024            /* the size of px_header */
 #   define PX_HEADER "/usr/lib/px_header"      /* px_header's name */
 #   define PX_INTRP "/usr/ucb/px"              /* the interpreter's name */
+#   define INDX 0                              /* amt to shift display index */
 #endif OBJ
 
     /*
 #endif OBJ
 
     /*
@@ -33,7 +34,6 @@
             *  these are because of varying sizes of pointers
             */
 #ifdef VAX
             *  these are because of varying sizes of pointers
             */
 #ifdef VAX
-#      define INDX 2                           /* log2 of sizeof( * ) */
 #      define PTR_AS O_AS4
 #      define PTR_RV O_RV4
 #      define PTR_IND O_IND4
 #      define PTR_AS O_AS4
 #      define PTR_RV O_RV4
 #      define PTR_IND O_IND4
@@ -73,7 +73,6 @@
 #endif VAX
 
 #ifdef PDP11
 #endif VAX
 
 #ifdef PDP11
-#      define INDX 1
 #      define PTR_AS O_AS2
 #      define PTR_RV O_RV2
 #      define PTR_IND O_IND2
 #      define PTR_AS O_AS2
 #      define PTR_RV O_RV2
 #      define PTR_IND O_IND2
index b521c39..930c292 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[] = "@(#)proc.c 1.3 %G%";
+static char sccsid[] = "@(#)proc.c 1.4 %G%";
 
 #include "whoami.h"
 #ifdef OBJ
 
 #include "whoami.h"
 #ifdef OBJ
@@ -118,7 +118,7 @@ proc(r)
                        error("flush takes at most one argument");
                        return;
                }
                        error("flush takes at most one argument");
                        return;
                }
-               ap = stkrval(argv[1], NIL , RREQ );
+               ap = stklval(argv[1], NIL , LREQ );
                if (ap == NIL)
                        return;
                if (ap->class != FILET) {
                if (ap == NIL)
                        return;
                if (ap->class != FILET) {
@@ -170,7 +170,7 @@ proc(r)
                                 */
                                file = argv[1];
                                filetype = ap->type;
                                 */
                                file = argv[1];
                                filetype = ap->type;
-                               stkrval(argv[1], NIL , RREQ );
+                               stklval(argv[1], NIL , LREQ );
                                put(1, O_UNIT);
                                /*
                                 * Skip over the first argument
                                put(1, O_UNIT);
                                /*
                                 * Skip over the first argument
@@ -290,7 +290,7 @@ proc(r)
                                 * Generalized write, i.e.
                                 * to a non-textfile.
                                 */
                                 * Generalized write, i.e.
                                 * to a non-textfile.
                                 */
-                               stkrval(file, NIL , RREQ );
+                               stklval(file, NIL , LREQ );
                                put(1, O_FNIL);
                                /*
                                 * file^ := ...
                                put(1, O_FNIL);
                                /*
                                 * file^ := ...
@@ -359,6 +359,13 @@ proc(r)
                                break;
                        case TCHAR:
                             tchar:
                                break;
                        case TCHAR:
                             tchar:
+                               if (fmtspec == NIL) {
+                                       put(1, O_FILE);
+                                       ap = stkrval(alv, NIL , RREQ );
+                                       put(1, O_WRITEC);
+                                       fmtspec = SKIP;
+                                       break;
+                               }
                                ap = stkrval(alv, NIL , RREQ );
                                stkcnt++;
                                fmt = 'c';
                                ap = stkrval(alv, NIL , RREQ );
                                stkcnt++;
                                fmt = 'c';
@@ -514,15 +521,11 @@ proc(r)
                        switch (fmtspec) {
                        default:
                                panic("fmt2");
                        switch (fmtspec) {
                        default:
                                panic("fmt2");
-                       case NIL:
-                               if (fmt == 'c')
-                                       put(1, O_WRITEC);
-                               else  {
-                                       sprintf(&format[1], "%%%c", fmt);
-                                       goto fmtgen;
-                               }
                        case SKIP:
                                break;
                        case SKIP:
                                break;
+                       case NIL:
+                               sprintf(&format[1], "%%%c", fmt);
+                               goto fmtgen;
                        case CONWIDTH:
                                sprintf(&format[1], "%%%1D%c", field, fmt);
                                goto fmtgen;
                        case CONWIDTH:
                                sprintf(&format[1], "%%%1D%c", field, fmt);
                                goto fmtgen;
@@ -618,7 +621,7 @@ proc(r)
                                 */
                                file = argv[1];
                                filetype = ap->type;
                                 */
                                file = argv[1];
                                filetype = ap->type;
-                               stkrval(argv[1], NIL , RREQ );
+                               stklval(argv[1], NIL , LREQ );
                                put(1, O_UNIT);
                                argv = argv[2];
                                argc--;
                                put(1, O_UNIT);
                                argv = argv[2];
                                argc--;
@@ -666,9 +669,9 @@ proc(r)
                                 * var := file ^;
                                 */
                                if (file != NIL)
                                 * var := file ^;
                                 */
                                if (file != NIL)
-                                       stkrval(file, NIL , RREQ );
+                                       stklval(file, NIL , LREQ );
                                else /* Magic */
                                else /* Magic */
-                                       put(2, O_RV2, input->value[0]);
+                                       put(2, PTR_RV, input->value[0]);
                                put(1, O_FNIL);
                                put(2, O_IND, width(filetype));
                                convert(filetype, ap);
                                put(1, O_FNIL);
                                put(2, O_IND, width(filetype));
                                convert(filetype, ap);
@@ -726,7 +729,7 @@ proc(r)
                        error("%s expects one argument", p->symbol);
                        return;
                }
                        error("%s expects one argument", p->symbol);
                        return;
                }
-               ap = stkrval(argv[1], NIL , RREQ );
+               ap = stklval(argv[1], NIL , LREQ );
                if (ap == NIL)
                        return;
                if (ap->class != FILET) {
                if (ap == NIL)
                        return;
                if (ap->class != FILET) {
@@ -747,13 +750,16 @@ proc(r)
                        standard();
                        error("Two argument forms of reset and rewrite are non-standard");
                }
                        standard();
                        error("Two argument forms of reset and rewrite are non-standard");
                }
+               codeoff();
                ap = stklval(argv[1], MOD|NOUSE);
                ap = stklval(argv[1], MOD|NOUSE);
+               codeon();
                if (ap == NIL)
                        return;
                if (ap->class != FILET) {
                        error("First argument to %s must be a file, not %s", p->symbol, nameof(ap));
                        return;
                }
                if (ap == NIL)
                        return;
                if (ap->class != FILET) {
                        error("First argument to %s must be a file, not %s", p->symbol, nameof(ap));
                        return;
                }
+               put(2, O_CON24, text(ap) ? 0: width(ap->type));
                if (argc == 2) {
                        /*
                         * Optional second argument
                if (argc == 2) {
                        /*
                         * Optional second argument
@@ -761,20 +767,23 @@ proc(r)
                         * UNIX (R) file to be associated.
                         */
                        al = argv[2];
                         * UNIX (R) file to be associated.
                         */
                        al = argv[2];
+                       codeoff();
                        al = stkrval(al[1], NOFLAGS , RREQ );
                        al = stkrval(al[1], NOFLAGS , RREQ );
+                       codeon();
                        if (al == NIL)
                                return;
                        if (classify(al) != TSTR) {
                                error("Second argument to %s must be a string, not %s", p->symbol, nameof(al));
                                return;
                        }
                        if (al == NIL)
                                return;
                        if (classify(al) != TSTR) {
                                error("Second argument to %s must be a string, not %s", p->symbol, nameof(al));
                                return;
                        }
-                       strnglen = width(al);
+                       put(2, O_CON24, width(al));
+                       al = argv[2];
+                       al = stkrval(al[1], NOFLAGS , RREQ );
                } else {
                } else {
+                       put(2, O_CON24, 0);
                        put(2, O_CON24, NIL);
                        put(2, O_CON24, NIL);
-                       strnglen = 0;
                }
                }
-               put(2, O_CON24, strnglen);
-               put(2, O_CON24, text(ap) ? 0: width(ap->type));
+               ap = stklval(argv[1], MOD|NOUSE);
                put(1, op);
                return;
 
                put(1, op);
                return;
 
@@ -899,7 +908,9 @@ proc(r)
                        error("remove expects one argument");
                        return;
                }
                        error("remove expects one argument");
                        return;
                }
+               codeoff();
                ap = stkrval(argv[1], NOFLAGS , RREQ );
                ap = stkrval(argv[1], NOFLAGS , RREQ );
+               codeon();
                if (ap == NIL)
                        return;
                if (classify(ap) != TSTR) {
                if (ap == NIL)
                        return;
                if (classify(ap) != TSTR) {
@@ -907,6 +918,7 @@ proc(r)
                        return;
                }
                put(2, O_CON24, width(ap));
                        return;
                }
                put(2, O_CON24, width(ap));
+               ap = stkrval(argv[1], NOFLAGS , RREQ );
                put(1, op);
                return;
 
                put(1, op);
                return;
 
@@ -915,13 +927,6 @@ proc(r)
                        error("linelimit expects two arguments");
                        return;
                }
                        error("linelimit expects two arguments");
                        return;
                }
-               ap = stklval(argv[1], NOFLAGS|NOUSE);
-               if (ap == NIL)
-                       return;
-               if (!text(ap)) {
-                       error("linelimit's first argument must be a text file, not %s", nameof(ap));
-                       return;
-               }
                al = argv[2];
                ap = stkrval(al[1], NIL , RREQ );
                if (ap == NIL)
                al = argv[2];
                ap = stkrval(al[1], NIL , RREQ );
                if (ap == NIL)
@@ -930,6 +935,13 @@ proc(r)
                        error("linelimit's second argument must be an integer, not %s", nameof(ap));
                        return;
                }
                        error("linelimit's second argument must be an integer, not %s", nameof(ap));
                        return;
                }
+               ap = stklval(argv[1], NOFLAGS|NOUSE);
+               if (ap == NIL)
+                       return;
+               if (!text(ap)) {
+                       error("linelimit's first argument must be a text file, not %s", nameof(ap));
+                       return;
+               }
                put(1, op);
                return;
        case O_PAGE:
                put(1, op);
                return;
        case O_PAGE:
@@ -937,7 +949,7 @@ proc(r)
                        error("page expects one argument");
                        return;
                }
                        error("page expects one argument");
                        return;
                }
-               ap = stkrval(argv[1], NIL , RREQ );
+               ap = stklval(argv[1], NIL , LREQ );
                if (ap == NIL)
                        return;
                if (!text(ap)) {
                if (ap == NIL)
                        return;
                if (!text(ap)) {
@@ -968,17 +980,16 @@ proc(r)
                pua = (al = al[2])[1];
                pui = (al = al[2])[1];
 packunp:
                pua = (al = al[2])[1];
                pui = (al = al[2])[1];
 packunp:
-               ap = stkrval((int *) pui, NLNIL , RREQ );
-               if (ap == NIL)
-                       return;
+               codeoff();
                ap = stklval(pua, op == O_PACK ? NOFLAGS : MOD|NOUSE);
                ap = stklval(pua, op == O_PACK ? NOFLAGS : MOD|NOUSE);
+               al = (struct nl *) stklval(puz, op == O_UNPACK ? NOFLAGS : MOD|NOUSE);
+               codeon();
                if (ap == NIL)
                        return;
                if (ap->class != ARRAY) {
                        error("%s requires a to be an unpacked array, not %s", pu, nameof(ap));
                        return;
                }
                if (ap == NIL)
                        return;
                if (ap->class != ARRAY) {
                        error("%s requires a to be an unpacked array, not %s", pu, nameof(ap));
                        return;
                }
-               al = (struct nl *) stklval(puz, op == O_UNPACK ? NOFLAGS : MOD|NOUSE);
                if (al->class != ARRAY) {
                        error("%s requires z to be a packed array, not %s", pu, nameof(ap));
                        return;
                if (al->class != ARRAY) {
                        error("%s requires z to be a packed array, not %s", pu, nameof(ap));
                        return;
@@ -1016,7 +1027,16 @@ packunp:
                 */
                i -= j;
                j = ap->range[0];
                 */
                i -= j;
                j = ap->range[0];
-               put(5, op, itemwidth , j, i, k);
+               put(2, O_CON24, k);
+               put(2, O_CON24, i);
+               put(2, O_CON24, j);
+               put(2, O_CON24, itemwidth);
+               al = (struct nl *) stklval(puz, op == O_UNPACK ? NOFLAGS : MOD|NOUSE);
+               ap = stklval(pua, op == O_PACK ? NOFLAGS : MOD|NOUSE);
+               ap = stkrval((int *) pui, NLNIL , RREQ );
+               if (ap == NIL)
+                       return;
+               put(1, op);
                return;
        case 0:
                error("%s is an unimplemented 6400 extension", p->symbol);
                return;
        case 0:
                error("%s is an unimplemented 6400 extension", p->symbol);
index d0b418c..6914464 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[] = "@(#)put.c 1.4 %G%";
+static char sccsid[] = "@(#)put.c 1.5 %G%";
 
 #include "whoami.h"
 #include "opcode.h"
 
 #include "whoami.h"
 #include "opcode.h"
@@ -91,8 +91,6 @@ put(a)
                case O_WRITEF:
                case O_MAX:
                case O_MIN:
                case O_WRITEF:
                case O_MAX:
                case O_MIN:
-               case O_PACK:
-               case O_UNPACK:
                case O_ARGV:
                case O_CTTOT:
                case O_INCT:
                case O_ARGV:
                case O_CTTOT:
                case O_INCT:
index 2f8aff8..3607296 100644 (file)
@@ -1,14 +1,14 @@
 /* Copyright (c) 1979 Regents of the University of California */
 
 /* Copyright (c) 1979 Regents of the University of California */
 
-static char sccsid[] = "@(#)var.c 1.3 %G%";
+static char sccsid[] = "@(#)var.c 1.4 %G%";
 
 #include "whoami.h"
 #include "0.h"
 #include "align.h"
 
 #include "whoami.h"
 #include "0.h"
 #include "align.h"
+#include "iorec.h"
 #ifdef PC
 #   include    "pc.h"
 #   include    "pcops.h"
 #ifdef PC
 #   include    "pc.h"
 #   include    "pcops.h"
-#   include    "iorec.h"
 #endif PC
 
 /*
 #endif PC
 
 /*
@@ -202,13 +202,7 @@ loop:
                case PTR:
                        return ( sizeof ( int * ) );
                case FILET:
                case PTR:
                        return ( sizeof ( int * ) );
                case FILET:
-#                      ifdef OBJ
-                           return ( sizeof ( int * ) );
-#                      endif OBJ
-#                      ifdef PC
-                           return ( sizeof(struct iorec)
-                                   + lwidth( p -> type ) );
-#                      endif PC
+                       return ( sizeof(struct iorec) + lwidth( p -> type ) );
                case RANGE:
                        if (p->type == nl+TDOUBLE)
 #ifdef DEBUG
                case RANGE:
                        if (p->type == nl+TDOUBLE)
 #ifdef DEBUG