home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / bsd_srcs / usr.bin / pascal / px / vars.h < prev    next >
Encoding:
C/C++ Source or Header  |  1991-04-16  |  8.5 KB  |  285 lines

  1. /*-
  2.  * Copyright (c) 1980 The Regents of the University of California.
  3.  * All rights reserved.
  4.  *
  5.  * Redistribution and use in source and binary forms, with or without
  6.  * modification, are permitted provided that the following conditions
  7.  * are met:
  8.  * 1. Redistributions of source code must retain the above copyright
  9.  *    notice, this list of conditions and the following disclaimer.
  10.  * 2. Redistributions in binary form must reproduce the above copyright
  11.  *    notice, this list of conditions and the following disclaimer in the
  12.  *    documentation and/or other materials provided with the distribution.
  13.  * 3. All advertising materials mentioning features or use of this software
  14.  *    must display the following acknowledgement:
  15.  *    This product includes software developed by the University of
  16.  *    California, Berkeley and its contributors.
  17.  * 4. Neither the name of the University nor the names of its contributors
  18.  *    may be used to endorse or promote products derived from this software
  19.  *    without specific prior written permission.
  20.  *
  21.  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  22.  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  23.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  24.  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  25.  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  26.  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  27.  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  28.  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  29.  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  30.  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  31.  * SUCH DAMAGE.
  32.  *
  33.  *    @(#)vars.h    5.4 (Berkeley) 4/16/91
  34.  */
  35.  
  36. #include <stdio.h>
  37.  
  38. /*
  39.  * px - Berkeley Pascal interpreter
  40.  *
  41.  * Version 4.0, January 1981
  42.  *
  43.  * Original version by Ken Thompson
  44.  *
  45.  * Substantial revisions by Bill Joy and Chuck Haley
  46.  * November-December 1976
  47.  *
  48.  * Rewritten for VAX 11/780 by Kirk McKusick
  49.  * Fall 1978
  50.  *
  51.  * Rewritten in ``C'' using libpc by Kirk McKusick
  52.  * Winter 1981
  53.  *
  54.  * Px is described in detail in the "PX 4.0 Implementation Notes"
  55.  * The source code for px is in several major pieces:
  56.  *
  57.  *    int.c        C main program which reads in interpreter code
  58.  *    interp.c    Driver including main interpreter loop and
  59.  *            the interpreter instructions grouped by their
  60.  *            positions in the interpreter table.
  61.  *    utilities.c    Interpreter exit, backtrace, and runtime statistics.
  62.  *
  63.  * In addition there are several headers defining mappings for panic
  64.  * names into codes, and a definition of the interpreter transfer
  65.  * table. These are made by the script make.ed1 in this directory and 
  66.  * the routine opc.c from ${PASCALDIR}. (see the makefile for details)
  67.  */
  68. #define PXPFILE        "pmon.out"
  69. #define    BITSPERBYTE    8
  70. #define    BITSPERLONG    (BITSPERBYTE * sizeof(long))
  71. #define HZ        100
  72. #define NAMSIZ        76
  73. #define MAXFILES    32
  74. #define PREDEF        2
  75. #ifdef ADDR32
  76. #ifndef tahoe
  77. #define STDLVL        ((struct iorec *)(0x7ffffff1))
  78. #define GLVL        ((struct iorec *)(0x7ffffff0))
  79. #else tahoe
  80. #define STDLVL        ((struct iorec *)(0xbffffff1))
  81. #define GLVL        ((struct iorec *)(0xbffffff0))
  82. #endif tahoe
  83. #endif ADDR32
  84. #ifdef ADDR16
  85. #define STDLVL        ((struct iorec *)(0xfff1))
  86. #define GLVL        ((struct iorec *)(0xfff0))
  87. #endif ADDR16
  88. #define FILNIL        ((struct iorec *)(0))
  89. #define INPUT        ((struct iorec *)(&input))
  90. #define OUTPUT        ((struct iorec *)(&output))
  91. #define ERR        ((struct iorec *)(&_err))
  92. #define    PX    0    /* normal run of px */
  93. #define    PIX    1    /* load and go */
  94. #define    PIPE    2    /* bootstrap via a pipe */
  95. #define    PDX    3    /* invoked by the debugger "pdx" */
  96. #define releq 0
  97. #define relne 2
  98. #define rellt 4
  99. #define relgt 6
  100. #define relle 8
  101. #define relge 10
  102. typedef enum {FALSE, TRUE} bool;
  103.  
  104. /*
  105.  * interrupt and allocation routines
  106.  */
  107. extern long createtime;
  108. extern char *PALLOC();
  109. extern char *malloc();
  110. extern long time();
  111. extern intr();
  112. extern memsize();
  113. extern syserr();
  114. extern liberr();
  115.  
  116. /*
  117.  * stack routines and structures
  118.  */
  119. struct sze8 {
  120.     char element[8];
  121. };
  122.  
  123. /*
  124.  * emulated pc types
  125.  */
  126. union progcntr {
  127.     char *cp;
  128.     unsigned char *ucp;
  129.     short *sp;
  130.     unsigned short *usp;
  131.     long *lp;
  132.     double *dbp;
  133.     struct hdr *hdrp;
  134.     struct sze8 *s8p;
  135. };
  136.  
  137. /*
  138.  * THE RUNTIME DISPLAY
  139.  *
  140.  * The entries in the display point to the active static block marks.
  141.  * The first entry in the display is for the global variables,
  142.  * then the procedure or function at level one, etc.
  143.  * Each display entry points to a stack frame as shown:
  144.  *
  145.  *        base of stack frame
  146.  *          ---------------
  147.  *          |        |
  148.  *          | block mark  |
  149.  *          |        |
  150.  *          ---------------  <-- display entry "stp" points here
  151.  *          |             |  <-- display entry "locvars" points here
  152.  *          |   local    |
  153.  *          |  variables  |
  154.  *          |        |
  155.  *          ---------------
  156.  *          |        |
  157.  *          |  expression |
  158.  *          |  temporary  |
  159.  *          |  storage    |
  160.  *          |        |
  161.  *          - - - - - - - -
  162.  *
  163.  * The information in the block mark is thus at positive offsets from
  164.  * the display.stp pointer entries while the local variables are at negative
  165.  * offsets from display.locvars. The block mark actually consists of
  166.  * two parts. The first part is created at CALL and the second at entry,
  167.  * i.e. BEGIN. Thus:
  168.  *
  169.  *        -------------------------
  170.  *        |            |
  171.  *        |  Saved lino        |
  172.  *        |  Saved lc        |
  173.  *        |  Saved dp        |
  174.  *        |            |
  175.  *        -------------------------
  176.  *        |            |
  177.  *        |  Saved (dp)        |
  178.  *        |            |
  179.  *        |  Pointer to current     |
  180.  *        |   routine header info    |
  181.  *        |            |
  182.  *        |  Saved value of    |
  183.  *        |   "curfile"        |
  184.  *        |            |
  185.  *        |  Empty tos value    |
  186.  *        |            |
  187.  *        -------------------------
  188.  */
  189.  
  190. /*
  191.  * program variables
  192.  */
  193. extern union display    _display;    /* runtime display */
  194. extern struct dispsave    *_dp;        /* ptr to active frame */
  195. extern long        _lino;        /* current line number */
  196. extern int        _argc;        /* number of passed args */
  197. extern char        **_argv;    /* values of passed args */
  198. extern bool        _nodump;    /* TRUE => no post mortum dump */
  199. extern long        _runtst;    /* TRUE => runtime tests */
  200. extern long        _mode;        /* execl by PX, PIPE, or PIX */
  201. extern long        _stlim;        /* statement limit */
  202. extern long        _stcnt;        /* statement count */
  203. extern long        _seed;        /* random number seed */
  204. extern char        *_maxptr;    /* maximum valid pointer */
  205. extern char        *_minptr;    /* minimum valid pointer */
  206. extern long        *_pcpcount;    /* pointer to pxp buffer */
  207. extern long        _cntrs;        /* number of counters */
  208. extern long        _rtns;        /* number of routine cntrs */
  209.  
  210. /*
  211.  * The file i/o routines maintain a notion of a "current file".
  212.  * A pointer to this file structure is kept in "curfile".
  213.  *
  214.  * file structures
  215.  */
  216. struct iorechd {
  217.     char        *fileptr;    /* ptr to file window */
  218.     long        lcount;        /* number of lines printed */
  219.     long        llimit;        /* maximum number of text lines */
  220.     FILE        *fbuf;        /* FILE ptr */
  221.     struct iorec    *fchain;    /* chain to next file */
  222.     struct iorec    *flev;        /* ptr to associated file variable */
  223.     char        *pfname;    /* ptr to name of file */
  224.     short        funit;        /* file status flags */
  225.     short        fblk;        /* index into active file table */
  226.     long        fsize;        /* size of elements in the file */
  227.     char        fname[NAMSIZ];    /* name of associated UNIX file */
  228. };
  229.  
  230. struct iorec {
  231.     char        *fileptr;    /* ptr to file window */
  232.     long        lcount;        /* number of lines printed */
  233.     long        llimit;        /* maximum number of text lines */
  234.     FILE        *fbuf;        /* FILE ptr */
  235.     struct iorec    *fchain;    /* chain to next file */
  236.     struct iorec    *flev;        /* ptr to associated file variable */
  237.     char        *pfname;    /* ptr to name of file */
  238.     short        funit;        /* file status flags */
  239.     short        fblk;        /* index into active file table */
  240.     long        fsize;        /* size of elements in the file */
  241.     char        fname[NAMSIZ];    /* name of associated UNIX file */
  242.     char        buf[BUFSIZ];    /* I/O buffer */
  243.     char        window[1];    /* file window element */
  244. };
  245.  
  246. /*
  247.  * unit flags
  248.  */
  249. #define    FDEF    0x80    /* 1 => reserved file name */
  250. #define    FTEXT    0x40    /* 1 => text file, process EOLN */
  251. #define    FWRITE    0x20    /* 1 => open for writing */
  252. #define    FREAD    0x10    /* 1 => open for reading */
  253. #define    TEMP    0x08    /* 1 => temporary file */
  254. #define    SYNC    0x04    /* 1 => window is out of sync */
  255. #define    EOLN    0x02    /* 1 => at end of line */
  256. #define    EOFF    0x01    /* 1 => at end of file */
  257.  
  258. /*
  259.  * file routines
  260.  */
  261. extern struct iorec    *GETNAME();
  262. extern char        *MKTEMP();
  263.  
  264. /*
  265.  * file record variables
  266.  */
  267. extern struct iorechd    _fchain;    /* head of active file chain */
  268. extern struct iorec    *_actfile[];    /* table of active files */
  269. extern long        _filefre;    /* last used entry in _actfile */
  270.  
  271. /*
  272.  * standard files
  273.  */
  274. extern struct iorechd    input;
  275. extern struct iorechd    output;
  276. extern struct iorechd    _err;
  277.  
  278. /*
  279.  * Px execution profile array
  280.  */
  281. #ifdef PROFILE
  282. #define    NUMOPS 256
  283. extern long _profcnts[NUMOPS];
  284. #endif PROFILE
  285.