BSD 4_1_snap release
[unix-history] / usr / src / cmd / pi / case.c
index e1f45b3..5b4e7bb 100644 (file)
@@ -1,13 +1,8 @@
 /* Copyright (c) 1979 Regents of the University of California */
 /* Copyright (c) 1979 Regents of the University of California */
-#
-/*
- * pi - Pascal interpreter code translator
- *
- * Charles Haley, Bill Joy UCB
- * Version 1.2 November 1978
- */
 
 
-#include "whoami"
+static char sccsid[] = "@(#)case.c 1.3 3/8/81";
+
+#include "whoami.h"
 #include "0.h"
 #include "tree.h"
 #include "opcode.h"
 #include "0.h"
 #include "tree.h"
 #include "opcode.h"
@@ -22,6 +17,7 @@ struct ct {
        int     cline;
 };
 
        int     cline;
 };
 
+#ifdef OBJ
 /*
  * Caseop generates the
  * pascal case statement code
 /*
  * Caseop generates the
  * pascal case statement code
@@ -38,7 +34,8 @@ caseop(r)
        char *brtab0;
        char *csend;
        int w, i, j, m, n;
        char *brtab0;
        char *csend;
        int w, i, j, m, n;
-       int nr, goc;
+       int goc;
+       bool nr;
 
        goc = gocnt;
        /*
 
        goc = gocnt;
        /*
@@ -48,7 +45,7 @@ caseop(r)
         *      low     lwb(p)
         *      high    upb(p)
         */
         *      low     lwb(p)
         *      high    upb(p)
         */
-       p = rvalue((int *) r[2], NLNIL);
+       p = rvalue((int *) r[2], NLNIL , RREQ );
        if (p != NIL) {
                if (isnta(p, "bcsi")) {
                        error("Case selectors cannot be %ss", nameof(p));
        if (p != NIL) {
                if (isnta(p, "bcsi")) {
                        error("Case selectors cannot be %ss", nameof(p));
@@ -85,7 +82,7 @@ caseop(r)
         * Allocate case table space
         */
        ctab = i = malloc(n * sizeof *ctab);
         * Allocate case table space
         */
        ctab = i = malloc(n * sizeof *ctab);
-       if (i == -1) {
+       if (i == 0) {
                error("Ran out of memory (case)");
                pexit(DIED);
        }
                error("Ran out of memory (case)");
                pexit(DIED);
        }
@@ -104,7 +101,7 @@ caseop(r)
                        gconst(cs[1]);
                        if (p == NIL || con.ctype == NIL)
                                continue;
                        gconst(cs[1]);
                        if (p == NIL || con.ctype == NIL)
                                continue;
-                       if (incompat(con.ctype, p, NIL)) {
+                       if (incompat(con.ctype, p, NIL )) {
                                cerror("Case label type clashed with case selector expression type");
                                continue;
                        }
                                cerror("Case label type clashed with case selector expression type");
                                continue;
                        }
@@ -136,16 +133,19 @@ caseop(r)
         * branch table
         */
        if (p != NIL) {
         * branch table
         */
        if (p != NIL) {
-               put2(O_CASE1OP + (w >> 1), n);
+               put(2, O_CASE1OP + (w >> 1), n);
                brtab = brtab0 = lc;
                putspace(n * 2);
                brtab = brtab0 = lc;
                putspace(n * 2);
-               put1(O_CASEBEG);
+               put(1, O_CASEBEG);
                for (i=0; i<m; i++)
                for (i=0; i<m; i++)
-                       put( 3 , O_CASE1 + (w >> 1), ctab[i].clong);
-               put1(O_CASEEND);
+                       if (w <= 2)
+                               put(2 ,O_CASE1 + (w >> 1), (int)ctab[i].clong);
+                       else
+                               put(2 ,O_CASE4, ctab[i].clong);
+               put(1, O_CASEEND);
        }
        csend = getlab();
        }
        csend = getlab();
-       put2(O_TRA, csend);
+       put(2, O_TRA, csend);
        /*
         * Free the case
         * table space.
        /*
         * Free the case
         * table space.
@@ -159,23 +159,23 @@ caseop(r)
         * statement with a branch back
         * to the TRA above.
         */
         * statement with a branch back
         * to the TRA above.
         */
-       nr = 1;
+       nr = TRUE;
        for (cl = r[3]; cl != NIL; cl = cl[2]) {
                cs = cl[1];
                if (cs == NIL)
                        continue;
                if (p != NIL)
                        for (cs = cs[2]; cs != NIL; cs = cs[2]) {
        for (cl = r[3]; cl != NIL; cl = cl[2]) {
                cs = cl[1];
                if (cs == NIL)
                        continue;
                if (p != NIL)
                        for (cs = cs[2]; cs != NIL; cs = cs[2]) {
-                               patchfil(brtab - 1, lc - brtab0, 1);
+                               patchfil(brtab - 1, (long)(lc - brtab0), 1);
                                brtab++;
                        }
                cs = cl[1];
                putcnt();
                level++;
                statement(cs[3]);
                                brtab++;
                        }
                cs = cl[1];
                putcnt();
                level++;
                statement(cs[3]);
-               nr &= noreach;
+               nr = (noreach && nr);
                noreach = 0;
                noreach = 0;
-               put2(O_TRA, csend);
+               put(2, O_TRA, csend);
                level--;
                if (gotos[cbn])
                        ungoto();
                level--;
                if (gotos[cbn])
                        ungoto();
@@ -188,3 +188,4 @@ caseop(r)
        if (goc != gocnt)
                putcnt();
 }
        if (goc != gocnt)
                putcnt();
 }
+#endif OBJ