BSD 4_3_Net_2 release
[unix-history] / usr / src / usr.bin / pascal / src / put.c
index 4334bcb..551bdb4 100644 (file)
@@ -1,6 +1,39 @@
-/* Copyright (c) 1979 Regents of the University of California */
+/*-
+ * Copyright (c) 1980 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *     This product includes software developed by the University of
+ *     California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
 
 
-static char sccsid[] = "@(#)put.c 1.9 %G%";
+#ifndef lint
+static char sccsid[] = "@(#)put.c      5.4 (Berkeley) 4/16/91";
+#endif /* not lint */
 
 #include "whoami.h"
 #include "opcode.h"
 
 #include "whoami.h"
 #include "opcode.h"
@@ -8,9 +41,10 @@ static        char sccsid[] = "@(#)put.c 1.9 %G%";
 #include "objfmt.h"
 #ifdef PC
 #   include    "pc.h"
 #include "objfmt.h"
 #ifdef PC
 #   include    "pc.h"
-#endif PC
-
-short  *obufp  = obuf;
+#   include    "align.h"
+#else
+    short      *obufp  = obuf;
+#endif
 
 /*
  * If DEBUG is defined, include the table
 
 /*
  * If DEBUG is defined, include the table
@@ -20,17 +54,24 @@ short       *obufp  = obuf;
 #include "OPnames.h"
 #endif
 
 #include "OPnames.h"
 #endif
 
+char showit[] = "'x'";
+
 #ifdef OBJ
 /*
  * Put is responsible for the interpreter equivalent of code
  * generation.  Since the interpreter is specifically designed
  * for Pascal, little work is required here.
 #ifdef OBJ
 /*
  * Put is responsible for the interpreter equivalent of code
  * generation.  Since the interpreter is specifically designed
  * for Pascal, little work is required here.
+ *
+ * FIXME, this should be converted to use <varargs.h> or <stdarg.h>.
  */
  */
+/*VARARGS*/
 put(a)
 {
        register int *p, i;
        register char *cp;
 put(a)
 {
        register int *p, i;
        register char *cp;
-       int n, subop, suboppr, op, oldlc, w;
+       register short *sp;
+       register long *lp;
+       int n, subop, suboppr, op, oldlc;
        char *string;
        static int casewrd;
 
        char *string;
        static int casewrd;
 
@@ -42,15 +83,15 @@ put(a)
         * relational operators could be used
         * etc.
         */
         * relational operators could be used
         * etc.
         */
-       oldlc = lc;
-       if (cgenflg < 0)
+       oldlc = (int) lc; /* its either this or change put to return a char * */
+       if ( !CGENNING )
                /*
                 * code disabled - do nothing
                 */
                return (oldlc);
        p = &a;
        n = *p++;
                /*
                 * code disabled - do nothing
                 */
                return (oldlc);
        p = &a;
        n = *p++;
-       suboppr = subop = (*p>>8) & 0377;
+       suboppr = subop = (*p >> 8) & 0377;
        op = *p & 0377;
        string = 0;
 #ifdef DEBUG
        op = *p & 0377;
        string = 0;
 #ifdef DEBUG
@@ -65,27 +106,53 @@ put(a)
                        break;
                case O_AS:
                        switch(p[1]) {
                        break;
                case O_AS:
                        switch(p[1]) {
+                       case 0:
+                               break;
                        case 2:
                                op = O_AS2;
                        case 2:
                                op = O_AS2;
+                               n = 1;
                                break;
                        case 4:
                                op = O_AS4;
                                break;
                        case 4:
                                op = O_AS4;
+                               n = 1;
                                break;
                        case 8:
                                op = O_AS8;
                                break;
                        case 8:
                                op = O_AS8;
+                               n = 1;
                                break;
                        default:
                                goto pack;
                        }
                                break;
                        default:
                                goto pack;
                        }
-                       n = 1;
-                       cp = otext[op];
+#                      ifdef DEBUG
+                               cp = otext[op];
+#                      endif DEBUG
                        break;
                        break;
+               case O_FOR1U:
+               case O_FOR2U:
+               case O_FOR4U:
+               case O_FOR1D:
+               case O_FOR2D:
+               case O_FOR4D:
+                       /* relative addressing */
+                       p[1] -= ( unsigned ) lc + sizeof(short);
+                       /* try to pack the jump */
+                       if (p[1] <= 127 && p[1] >= -128) {
+                               suboppr = subop = p[1];
+                               p++;
+                               n--;
+                       } else {
+                               /* have to allow for extra displacement */
+                               p[1] -= sizeof(short);
+                       }
+                       break;
+               case O_CONG:
+               case O_LVCON:
+               case O_CON:
                case O_LINO:
                case O_NEW:
                case O_DISPOSE:
                case O_LINO:
                case O_NEW:
                case O_DISPOSE:
+               case O_DFDISP:
                case O_IND:
                case O_IND:
-               case O_LVCON:
-               case O_CON:
                case O_OFF:
                case O_INX2:
                case O_INX4:
                case O_OFF:
                case O_INX2:
                case O_INX4:
@@ -99,6 +166,7 @@ put(a)
                case O_CASE4OP:
                case O_FRTN:
                case O_WRITES:
                case O_CASE4OP:
                case O_FRTN:
                case O_WRITES:
+               case O_WRITEC:
                case O_WRITEF:
                case O_MAX:
                case O_MIN:
                case O_WRITEF:
                case O_MAX:
                case O_MIN:
@@ -118,31 +186,39 @@ put(a)
                case O_CON2:
                case O_CON24:
                pack:
                case O_CON2:
                case O_CON24:
                pack:
-                       if (p[1] < 128 && p[1] >= -128) {
+                       if (p[1] <= 127 && p[1] >= -128) {
                                suboppr = subop = p[1];
                                p++;
                                n--;
                                if (op == O_CON2) {
                                        op = O_CON1;
                                suboppr = subop = p[1];
                                p++;
                                n--;
                                if (op == O_CON2) {
                                        op = O_CON1;
-                                       cp = otext[O_CON1];
+#                                      ifdef DEBUG
+                                               cp = otext[O_CON1];
+#                                      endif DEBUG
                                }
                                if (op == O_CON24) {
                                        op = O_CON14;
                                }
                                if (op == O_CON24) {
                                        op = O_CON14;
-                                       cp = otext[O_CON14];
+#                                      ifdef DEBUG
+                                               cp = otext[O_CON14];
+#                                      endif DEBUG
                                }
                        }
                        break;
                case O_CON8:
                    {
                                }
                        }
                        break;
                case O_CON8:
                    {
-                       short   *sp = &p[1];
+                       short   *sp = (short *) (&p[1]);
 
 #ifdef DEBUG
                        if ( opt( 'k' ) )
 
 #ifdef DEBUG
                        if ( opt( 'k' ) )
-                           printf ( ")#%5d\tCON8\t%10.3f\n" ,
+                           printf ( "%5d\tCON8\t%22.14e\n" ,
                                        lc - HEADER_BYTES ,
                                        * ( ( double * ) &p[1] ) );
 #endif
                                        lc - HEADER_BYTES ,
                                        * ( ( double * ) &p[1] ) );
 #endif
-                       word ( op );
+#                      ifdef DEC11
+                           word(op);
+#                      else
+                           word(op << 8);
+#                      endif DEC11
                        for ( i = 1 ; i <= 4 ; i ++ )
                            word ( *sp ++ );
                        return ( oldlc );
                        for ( i = 1 ; i <= 4 ; i ++ )
                            word ( *sp ++ );
                        return ( oldlc );
@@ -167,46 +243,20 @@ put(a)
                        /* relative addressing */
                        p[1] -= ( unsigned ) lc + sizeof(short);
                        break;
                        /* relative addressing */
                        p[1] -= ( unsigned ) lc + sizeof(short);
                        break;
-               case O_FOR1U:
-               case O_FOR2U:
-               case O_FOR1D:
-               case O_FOR2D:
-                       /* relative addressing */
-                       p[3] -= ( unsigned ) lc + 3 * sizeof(short);
-                       break;
-               case O_CONG:
-                       i = p[1];
-                       cp = * ( ( char ** ) &p[2] ) ;
-#ifdef DEBUG
-                       if (opt('k'))
-                               printf(")#%5d\tCONG:%d\t%s\n",
-                                       lc - HEADER_BYTES, i, cp);
-#endif
-                       if (i <= 127)
-                               word(O_CON | i << 8);
-                       else {
-                               word(O_CON);
-                               word(i);
-                       }
-                       while (i > 0) {
-                               w = *cp ? *cp++ : ' ';
-                               w |= (*cp ? *cp++ : ' ') << 8;
-                               word(w);
-                               i -= 2;
-                       }
-                       return (oldlc);
                case O_CONC:
 #ifdef DEBUG
                case O_CONC:
 #ifdef DEBUG
-                       (string = "'x'")[1] = p[1];
+                       (string = showit)[1] = p[1];
 #endif
                        suboppr = 0;
                        op = O_CON1;
 #endif
                        suboppr = 0;
                        op = O_CON1;
-                       cp = otext[O_CON1];
+#                      ifdef DEBUG
+                               cp = otext[O_CON1];
+#                      endif DEBUG
                        subop = p[1];
                        goto around;
                case O_CONC4:
 #ifdef DEBUG
                        subop = p[1];
                        goto around;
                case O_CONC4:
 #ifdef DEBUG
-                       (string = "'x'")[1] = p[1];
+                       (string = showit)[1] = p[1];
 #endif
                        suboppr = 0;
                        op = O_CON14;
 #endif
                        suboppr = 0;
                        op = O_CON14;
@@ -230,9 +280,8 @@ around:
                case O_CASE1:
 #ifdef DEBUG
                        if (opt('k'))
                case O_CASE1:
 #ifdef DEBUG
                        if (opt('k'))
-                               printf(")#%5d\tCASE1\t%d\n"
-                                       , lc - HEADER_BYTES
-                                       , ( int ) *( ( long * ) &p[1] ) );
+                               printf("%5d\tCASE1\t%d\n"
+                                       , lc - HEADER_BYTES, p[1]);
 #endif
                        /*
                         * this to build a byte size case table 
 #endif
                        /*
                         * this to build a byte size case table 
@@ -241,42 +290,47 @@ around:
                         */
                        lc++;
                        if ((unsigned) lc & 1)
                         */
                        lc++;
                        if ((unsigned) lc & 1)
-                               casewrd = *( ( long * ) &p[1] ) & 0377;
+#                              ifdef DEC11
+                                   casewrd = p[1] & 0377;
+#                              else
+                                   casewrd = (p[1] & 0377) << 8;
+#                              endif DEC11
                        else {
                                lc -= 2;
                        else {
                                lc -= 2;
-                               word (   casewrd
-                                      | ( ( int ) *( ( long * ) &p[1] ) << 8 ) );
+#                              ifdef DEC11
+                                   word(((p[1] & 0377) << 8) | casewrd);
+#                              else
+                                   word((p[1] & 0377) | casewrd);
+#                              endif DEC11
                        }
                        return (oldlc);
                case O_CASE2:
 #ifdef DEBUG
                        if (opt('k'))
                        }
                        return (oldlc);
                case O_CASE2:
 #ifdef DEBUG
                        if (opt('k'))
-                               printf(")#%5d\tCASE2\t%d\n"
-                                       , lc - HEADER_BYTES
-                                       , ( int ) *( ( long * ) &p[1] ) );
+                               printf("%5d\tCASE2\t%d\n"
+                                       , lc - HEADER_BYTES , p[1]);
 #endif
 #endif
-                       word( ( short ) *( ( long * ) &p[1] ) );
+                       word(p[1]);
                        return (oldlc);
                        return (oldlc);
-               case O_FCALL:
-                       if (p[1] == 0)
-                               goto longgen;
-                       /* and fall through */
                case O_PUSH:
                case O_PUSH:
-                       if (p[1] == 0)
+                       lp = (long *)&p[1];
+                       if (*lp == 0)
                                return (oldlc);
                                return (oldlc);
-                       if (p[1] < 128 && p[1] >= -128) {
-                               suboppr = subop = p[1];
-                               p++;
+                       /* and fall through */
+               case O_RANG4:
+               case O_RANG24:
+               case O_RSNG4:
+               case O_RSNG24:
+               case O_SUCC4:
+               case O_PRED4:
+                       /* sub opcode optimization */
+                       lp = (long *)&p[1];
+                       if (*lp < 128 && *lp >= -128 && *lp != 0) {
+                               suboppr = subop = *lp;
+                               p += (sizeof(long) / sizeof(int));
                                n--;
                                n--;
-                               break;
                        }
                        goto longgen;
                        }
                        goto longgen;
-               case O_FOR4U:
-               case O_FOR4D:
-                       /* relative addressing */
-                       p[3] -= ( unsigned ) lc +
-                               (sizeof(short) + 2 * sizeof(long));
-                       goto longgen;
                case O_TRA4:
                case O_CALL:
                case O_FSAV:
                case O_TRA4:
                case O_CALL:
                case O_FSAV:
@@ -284,7 +338,8 @@ around:
                case O_NAM:
                case O_READE:
                        /* absolute long addressing */
                case O_NAM:
                case O_READE:
                        /* absolute long addressing */
-                       p[1] -= HEADER_BYTES;
+                       lp = (long *)&p[1];
+                       *lp -= HEADER_BYTES;
                        goto longgen;
                case O_RV1:
                case O_RV14:
                        goto longgen;
                case O_RV1:
                case O_RV14:
@@ -303,57 +358,63 @@ around:
                                subop++;
                                suboppr++;
                        }
                                subop++;
                                suboppr++;
                        }
-                       /*
-                        * offsets out of range of word addressing
-                        * must use long offset opcodes
-                        */
-                       if (p[1] < SHORTADDR && p[1] >= -SHORTADDR)
-                               break;
-                       else {
+#                      ifdef PDP11
+                           break;
+#                      else
+                           /*
+                            * offsets out of range of word addressing
+                            * must use long offset opcodes
+                            */
+                           if (p[1] < SHORTADDR && p[1] >= -SHORTADDR)
+                                   break;
+                           else {
                                op += O_LRV - O_RV;
                                op += O_LRV - O_RV;
-                               cp = otext[op];
-                       }
-                       /* and fall through */
+#                              ifdef DEBUG
+                                   cp = otext[op];
+#                              endif DEBUG
+                           }
+                           /* and fall through */
+#                      endif PDP11
                case O_BEG:
                case O_NODUMP:
                case O_CON4:
                case O_CASE4:
                case O_BEG:
                case O_NODUMP:
                case O_CON4:
                case O_CASE4:
-               case O_RANG4:
-               case O_RANG24:
-               case O_RSNG4:
-               case O_RSNG24:
-               case O_SUCC4:
-               case O_PRED4:
                longgen:
                longgen:
-                   {
-                       short   *sp = &p[1];
-                       long    *lp = &p[1];
-
                        n = (n << 1) - 1;
                        n = (n << 1) - 1;
-                       if ( op == O_LRV || op == O_FOR4U || op == O_FOR4D)
+                       if ( op == O_LRV ) {
                                n--;
                                n--;
+#                              if defined(ADDR32) && !defined(DEC11)
+                                   p[n / 2] <<= 16;
+#                              endif
+                       }
 #ifdef DEBUG
 #ifdef DEBUG
-                       if (opt('k'))
-                           {
-                               printf( ")#%5d\t%s" , lc - HEADER_BYTES , cp+1 );
+                       if (opt('k')) {
+                               printf("%5d\t%s", lc - HEADER_BYTES, cp+1);
                                if (suboppr)
                                if (suboppr)
-                                       printf(":%1d", suboppr);
-                               for ( i = ; i < n 
+                                       printf(":%d", suboppr);
+                               for ( i = 2, lp = (long *)&p[1]; i < n 
                                    ; i += sizeof ( long )/sizeof ( short ) )
                                        printf( "\t%D " , *lp ++ );
                                    ; i += sizeof ( long )/sizeof ( short ) )
                                        printf( "\t%D " , *lp ++ );
+                               if (i == n) {
+                                       sp = (short *)lp;
+                                       printf( "\t%d ", *sp );
+                               }
                                pchr ( '\n' );
                                pchr ( '\n' );
-                           }
+                       }
 #endif
                        if ( op != O_CASE4 )
 #endif
                        if ( op != O_CASE4 )
-                           word ( op | subop<<8 );
-                       for ( i = 1 ; i < n ; i ++ )
-                           word ( *sp ++ );
+#                              ifdef DEC11
+                                   word((op & 0377) | subop << 8);
+#                              else
+                                   word(op << 8 | (subop & 0377));
+#                              endif DEC11
+                       for ( i = 1, sp = (short *)&p[1]; i < n; i++)
+                               word ( *sp ++ );
                        return ( oldlc );
                        return ( oldlc );
-                   }
        }
 #ifdef DEBUG
        if (opt('k')) {
        }
 #ifdef DEBUG
        if (opt('k')) {
-               printf(")#%5d\t%s", lc - HEADER_BYTES, cp+1);
+               printf("%5d\t%s", lc - HEADER_BYTES, cp+1);
                if (suboppr)
                        printf(":%d", suboppr);
                if (string)
                if (suboppr)
                        printf(":%d", suboppr);
                if (string)
@@ -361,12 +422,16 @@ around:
                if (n > 1)
                        pchr('\t');
                for (i=1; i<n; i++)
                if (n > 1)
                        pchr('\t');
                for (i=1; i<n; i++)
-                       printf("%d ", ( short ) p[i]);
+                       printf("%d ", p[i]);
                pchr('\n');
        }
 #endif
        if (op != NIL)
                pchr('\n');
        }
 #endif
        if (op != NIL)
-               word(op | subop << 8);
+#              ifdef DEC11
+                   word((op & 0377) | subop << 8);
+#              else
+                   word(op << 8 | (subop & 0377));
+#              endif DEC11
        for (i=1; i<n; i++)
                word(p[i]);
        return (oldlc);
        for (i=1; i<n; i++)
                word(p[i]);
        return (oldlc);
@@ -384,11 +449,14 @@ listnames(ap)
        register struct nl *ap;
 {
        struct nl *next;
        register struct nl *ap;
 {
        struct nl *next;
-       register int oldlc, len;
+#ifdef OBJ
+       register int oldlc;
+#endif
+       register int len;
        register unsigned w;
        register char *strptr;
 
        register unsigned w;
        register char *strptr;
 
-       if (cgenflg < 0)
+       if ( !CGENNING )
                /* code is off - do nothing */
                return(NIL);
        if (ap->class != TYPE)
                /* code is off - do nothing */
                return(NIL);
        if (ap->class != TYPE)
@@ -398,21 +466,21 @@ listnames(ap)
                return( ap -> value[ NL_ELABEL ] );
        }
 #      ifdef OBJ
                return( ap -> value[ NL_ELABEL ] );
        }
 #      ifdef OBJ
-           oldlc = lc;
-           put(2, O_TRA, lc);
-           ap->value[ NL_ELABEL ] = lc;
+           oldlc = (int) lc; /* same problem as put */
+           (void) put(2, O_TRA, lc);
+           ap->value[ NL_ELABEL ] = (int) lc;
 #      endif OBJ
 #      ifdef PC
 #      endif OBJ
 #      ifdef PC
-           putprintf( "        .data" , 0 );
-           putprintf( "        .align 1" , 0 );
-           ap -> value[ NL_ELABEL ] = getlab();
-           putlab( ap -> value[ NL_ELABEL ] );
+           putprintf(" .data", 0);
+           aligndot(A_STRUCT);
+           ap -> value[ NL_ELABEL ] = (int) getlab();
+           (void) putlab((char *) ap -> value[ NL_ELABEL ] );
 #      endif PC
        /* number of scalars */
        next = ap->type;
        len = next->range[1]-next->range[0]+1;
 #      ifdef OBJ
 #      endif PC
        /* number of scalars */
        next = ap->type;
        len = next->range[1]-next->range[0]+1;
 #      ifdef OBJ
-           put(2, O_CASE2, len);
+           (void) put(2, O_CASE2, len);
 #      endif OBJ
 #      ifdef PC
            putprintf( "        .word %d" , 0 , len );
 #      endif OBJ
 #      ifdef PC
            putprintf( "        .word %d" , 0 , len );
@@ -420,7 +488,7 @@ listnames(ap)
        /* offsets of each scalar name */
        len = (len+1)*sizeof(short);
 #      ifdef OBJ
        /* offsets of each scalar name */
        len = (len+1)*sizeof(short);
 #      ifdef OBJ
-           put(2, O_CASE2, len);
+           (void) put(2, O_CASE2, len);
 #      endif OBJ
 #      ifdef PC
            putprintf( "        .word %d" , 0 , len );
 #      endif OBJ
 #      ifdef PC
            putprintf( "        .word %d" , 0 , len );
@@ -431,7 +499,7 @@ listnames(ap)
                        continue;
                len++;
 #              ifdef OBJ
                        continue;
                len++;
 #              ifdef OBJ
-                   put(2, O_CASE2, len);
+                   (void) put(2, O_CASE2, len);
 #              endif OBJ
 #              ifdef PC
                    putprintf( "        .word %d" , 0 , len );
 #              endif OBJ
 #              ifdef PC
                    putprintf( "        .word %d" , 0 , len );
@@ -441,16 +509,24 @@ listnames(ap)
        strptr = getnext(ap, &next);
 #      ifdef OBJ
            do  {
        strptr = getnext(ap, &next);
 #      ifdef OBJ
            do  {
-                   w = (unsigned) *strptr;
+#                  ifdef DEC11
+                       w = (unsigned) *strptr;
+#                  else
+                       w = *strptr << 8;
+#                  endif DEC11
                    if (!*strptr++)
                            strptr = getnext(next, &next);
                    if (!*strptr++)
                            strptr = getnext(next, &next);
-                   w |= *strptr << 8;
+#                  ifdef DEC11
+                       w |= *strptr << 8;
+#                  else
+                       w |= (unsigned) *strptr;
+#                  endif DEC11
                    if (!*strptr++)
                            strptr = getnext(next, &next);
                    if (!*strptr++)
                            strptr = getnext(next, &next);
-                   word(w);
+                   word((int) w);
            } while (next);
            /* jump over the mess */
            } while (next);
            /* jump over the mess */
-           patch(oldlc);
+           patch((PTR_DCL) oldlc);
 #      endif OBJ
 #      ifdef PC
            while ( next ) {
 #      endif OBJ
 #      ifdef PC
            while ( next ) {
@@ -469,6 +545,7 @@ listnames(ap)
        return( ap -> value[ NL_ELABEL ] );
 }
 
        return( ap -> value[ NL_ELABEL ] );
 }
 
+char *
 getnext(next, new)
 
        struct nl *next, **new;
 getnext(next, new)
 
        struct nl *next, **new;
@@ -477,11 +554,11 @@ getnext(next, new)
                next = next->chain;
                *new = next;
        }
                next = next->chain;
                *new = next;
        }
-       if (next == NIL)
+       if (next == NLNIL)
                return("");
 #ifdef OBJ
                return("");
 #ifdef OBJ
-       if (opt('k') && cgenflg >= 0)
-               printf(")#%5d\t\t\"%s\"\n", lc-HEADER_BYTES, next->symbol);
+       if (opt('k') && CGENNING )
+               printf("%5d\t\t\"%s\"\n", lc-HEADER_BYTES, next->symbol);
 #endif OBJ
        return(next->symbol);
 }
 #endif OBJ
        return(next->symbol);
 }
@@ -497,16 +574,16 @@ putspace(n)
 {
        register i;
 
 {
        register i;
 
-       if (cgenflg < 0)
+       if ( !CGENNING )
                /*
                 * code disabled - do nothing
                 */
                /*
                 * code disabled - do nothing
                 */
-               return(lc);
+               return;
 #ifdef DEBUG
        if (opt('k'))
 #ifdef DEBUG
        if (opt('k'))
-               printf(")#%5d\t.=.+%d\n", lc - HEADER_BYTES, n);
+               printf("%5d\t.=.+%d\n", lc - HEADER_BYTES, n);
 #endif
 #endif
-       for (i = even(n); i > 0; i -= 2)
+       for (i = n; i > 0; i -= 2)
                word(0);
 }
 
                word(0);
 }
 
@@ -519,47 +596,79 @@ putstr(sptr, padding)
        register char *strptr = sptr;
        register int pad = padding;
 
        register char *strptr = sptr;
        register int pad = padding;
 
-       if (cgenflg < 0)
+       if ( !CGENNING )
                /*
                 * code disabled - do nothing
                 */
                /*
                 * code disabled - do nothing
                 */
-               return(lc);
+               return;
 #ifdef DEBUG
        if (opt('k'))
 #ifdef DEBUG
        if (opt('k'))
-               printf(")#%5D\t\t\"%s\"\n", lc-HEADER_BYTES, strptr);
+               printf("%5d\t\t\"%s\"\n", lc-HEADER_BYTES, strptr);
 #endif
        if (pad == 0) {
                do      {
 #endif
        if (pad == 0) {
                do      {
-                       w = (unsigned short) * strptr;
+#                      ifdef DEC11
+                           w = (unsigned short) * strptr;
+#                      else
+                           w = (unsigned short)*strptr<<8;
+#                      endif DEC11
                        if (w)
                        if (w)
-                               w |= *++strptr << 8;
-                       word(w);
+#                              ifdef DEC11
+                                   w |= *++strptr << 8;
+#                              else
+                                   w |= *++strptr;
+#                              endif DEC11
+                       word((int) w);
                } while (*strptr++);
        } else {
                } while (*strptr++);
        } else {
-               do      {
-                       w = (unsigned short) * strptr;
-                       if (w) {
-                               if (*++strptr)
-                                       w |= *strptr << 8;
-                               else {
-                                       w |= ' ' << 8;
-                                       pad--;
-                               }
-                               word(w);
-                       }
-               } while (*strptr++);
+#              ifdef DEC11
+                   do  {
+                           w = (unsigned short) * strptr;
+                           if (w) {
+                                   if (*++strptr)
+                                           w |= *strptr << 8;
+                                   else {
+                                           w |= ' ' << 8;
+                                           pad--;
+                                   }
+                                   word((int) w);
+                           }
+                   } while (*strptr++);
+#              else
+                   do  {
+                           w = (unsigned short)*strptr<<8;
+                           if (w) {
+                                   if (*++strptr)
+                                           w |= *strptr;
+                                   else {
+                                           w |= ' ';
+                                           pad--;
+                                   }
+                                   word(w);
+                           }
+                   } while (*strptr++);
+#              endif DEC11
                while (pad > 1) {
                while (pad > 1) {
-                       word('  ');
+#                      ifdef DEC11
+                           word(' ' | (' ' << 8));
+#                      else
+                           word((' ' << 8) | ' ');
+#                      endif DEC11
                        pad -= 2;
                }
                if (pad == 1)
                        pad -= 2;
                }
                if (pad == 1)
-                       word(' ');
+#                      ifdef DEC11
+                           word(' ');
+#                      else
+                           word(' ' << 8);
+#                      endif DEC11
                else
                        word(0);
        }
 }
 #endif OBJ
 
                else
                        word(0);
        }
 }
 #endif OBJ
 
+#ifndef PC
 lenstr(sptr, padding)
 
        char *sptr;
 lenstr(sptr, padding)
 
        char *sptr;
@@ -575,6 +684,7 @@ lenstr(sptr, padding)
        } while (*strptr++);
        return((++cnt) & ~1);
 }
        } while (*strptr++);
        return((++cnt) & ~1);
 }
+#endif
 \f
 /*
  * Patch repairs the branch
 \f
 /*
  * Patch repairs the branch
@@ -585,52 +695,65 @@ lenstr(sptr, padding)
  *     lets here it for two pass assemblers.
  */
 patch(loc)
  *     lets here it for two pass assemblers.
  */
 patch(loc)
+    PTR_DCL loc;
 {
 
 #      ifdef OBJ
 {
 
 #      ifdef OBJ
-           patchfil(loc, lc-loc-2, 1);
+           patchfil(loc, (long)(lc-loc-2), 1);
 #      endif OBJ
 #      ifdef PC
 #      endif OBJ
 #      ifdef PC
-           putlab( loc );
+           (void) putlab((char *) loc );
 #      endif PC
 }
 
 #ifdef OBJ
 patch4(loc)
 #      endif PC
 }
 
 #ifdef OBJ
 patch4(loc)
+PTR_DCL loc;
 {
 {
-
-       patchfil(loc, lc - HEADER_BYTES, 2);
+       patchfil(loc, (long)(lc - HEADER_BYTES), 2);
 }
 
 /*
 }
 
 /*
- * Patchfil makes loc+2 have value
+ * Patchfil makes loc+2 have jmploc
  * as its contents.
  */
  * as its contents.
  */
-patchfil(loc, value, words)
+patchfil(loc, jmploc, words)
        PTR_DCL loc;
        PTR_DCL loc;
-       int value, words;
+       long jmploc;
+       int words;
 {
        register i;
 {
        register i;
+       extern long lseek();
+       short val;
 
 
-       if (cgenflg < 0)
+       if ( !CGENNING )
                return;
        if (loc > (unsigned) lc)
                panic("patchfil");
 #ifdef DEBUG
        if (opt('k'))
                return;
        if (loc > (unsigned) lc)
                panic("patchfil");
 #ifdef DEBUG
        if (opt('k'))
-               printf(")#\tpatch %u %d\n", loc - HEADER_BYTES, value);
+               printf("\tpatch %u %D\n", loc - HEADER_BYTES, jmploc);
 #endif
 #endif
+       val = jmploc;
        do {
        do {
+#              ifndef DEC11
+                   if (words > 1)
+                           val = jmploc >> 16;
+                   else
+                           val = jmploc;
+#              endif DEC11
                i = ((unsigned) loc + 2 - ((unsigned) lc & ~01777))/2;
                i = ((unsigned) loc + 2 - ((unsigned) lc & ~01777))/2;
-               if (i >= 0 && i < 1024)
-                       obuf[i] = value;
-               else {
-                       lseek(ofil, (long) loc+2, 0);
-                       write(ofil, &value, 2);
-                       lseek(ofil, (long) 0, 2);
+               if (i >= 0 && i < 1024) {
+                       obuf[i] = val;
+               else {
+                       (void) lseek(ofil, (long) loc+2, 0);
+                       write(ofil, (char *) (&val), 2);
+                       (void) lseek(ofil, (long) 0, 2);
                }
                loc += 2;
                }
                loc += 2;
-               value = value >> 16;
+#              ifdef DEC11
+                   val = jmploc >> 16;
+#              endif DEC11
        } while (--words);
 }
 \f
        } while (--words);
 }
 \f
@@ -657,7 +780,7 @@ pflush()
        register i;
 
        i = (obufp - ( ( short * ) obuf ) ) * 2;
        register i;
 
        i = (obufp - ( ( short * ) obuf ) ) * 2;
-       if (i != 0 && write(ofil, obuf, i) != i)
+       if (i != 0 && write(ofil, (char *) obuf, i) != i)
                perror(obj), pexit(DIED);
        obufp = obuf;
 }
                perror(obj), pexit(DIED);
        obufp = obuf;
 }
@@ -668,6 +791,7 @@ pflush()
  * included here for the eventual code generator.
  *     for PC, thank you!
  */
  * included here for the eventual code generator.
  *     for PC, thank you!
  */
+char *
 getlab()
 {
 #      ifdef OBJ
 getlab()
 {
 #      ifdef OBJ
@@ -677,7 +801,7 @@ getlab()
 #      ifdef PC
            static long lastlabel;
 
 #      ifdef PC
            static long lastlabel;
 
-           return ( ++lastlabel );
+           return ( (char *) ++lastlabel );
 #      endif PC
 }
 
 #      endif PC
 }
 
@@ -685,14 +809,14 @@ getlab()
  * Putlab - lay down a label.
  *     for PC, just print the label name with a colon after it.
  */
  * Putlab - lay down a label.
  *     for PC, just print the label name with a colon after it.
  */
+char *
 putlab(l)
 putlab(l)
-       int l;
+       char *l;
 {
 
 #      ifdef PC
 {
 
 #      ifdef PC
-           putprintf( PREFIXFORMAT , 1 , LABELPREFIX , l );
+           putprintf( PREFIXFORMAT , 1 , (int) LABELPREFIX , (int) l );
            putprintf( ":" , 0 );
 #      endif PC
        return (l);
 }
            putprintf( ":" , 0 );
 #      endif PC
        return (l);
 }
-