add DEC11 mode
[unix-history] / usr / src / usr.bin / pascal / px / vars.h
CommitLineData
1e2b51bb
KM
1/* Copyright (c) 1979 Regents of the University of California */
2
796c7f60 3/* static char sccsid[] = "@(#)vars.h 1.5 %G%"; */
1e2b51bb
KM
4
5#include <stdio.h>
6
7/*
8 * px - Berkeley Pascal interpreter
9 *
10 * Version 4.0, January 1981
11 *
12 * Original version by Ken Thompson
13 *
14 * Substantial revisions by Bill Joy and Chuck Haley
15 * November-December 1976
16 *
17 * Rewritten for VAX 11/780 by Kirk McKusick
18 * Fall 1978
19 *
20 * Rewritten in ``C'' using libpc by Kirk McKusick
21 * Winter 1981
22 *
23 * Px is described in detail in the "PX 4.0 Implementation Notes"
24 * The source code for px is in several major pieces:
25 *
26 * int.c C main program which reads in interpreter code
27 * interp.c Driver including main interpreter loop and
28 * the interpreter instructions grouped by their
29 * positions in the interpreter table.
30 * except.c Handlers for interpreter specific errors not
31 * included in libpc.
32 * utilities.c Interpreter exit, backtrace, and runtime statistics.
33 *
34 * In addition there are several headers defining mappings for panic
35 * names into codes, and a definition of the interpreter transfer
36 * table. These are made by the script make.ed1 in this directory and
37 * the routine opc.c from ${PASCALDIR}. (see the makefile for details)
38 */
39#define PXPFILE "pmon.out"
40#define BITSPERBYTE 8
41#define BITSPERLONG (BITSPERBYTE * sizeof(long))
42#define HZ 60
43#define TRUE 1
44#define FALSE 0
45#define MAXLVL 20
46#define NAMSIZ 76
47#define MAXFILES 32
48#define PREDEF 2
49#define STDLVL ((struct iorec *)(0x7ffffff1))
50#define GLVL ((struct iorec *)(0x7ffffff0))
51#define FILNIL ((struct iorec *)(0))
52#define INPUT ((struct iorec *)(&input))
53#define OUTPUT ((struct iorec *)(&output))
54#define ERR ((struct iorec *)(&_err))
55#define PX 0 /* normal run of px */
56#define PIX 1 /* load and go */
57#define PIPE 2 /* bootstrap via a pipe */
58#define releq 0
15834a19
KM
59#define relne 2
60#define rellt 4
61#define relgt 6
62#define relle 8
63#define relge 10
1e2b51bb
KM
64
65/*
66 * interrupt and allocation routines
67 */
68extern long createtime;
69extern char *PALLOC();
70extern char *malloc();
71extern intr();
72extern memsize();
73extern except();
74extern syserr();
75extern liberr();
76
77/*
796c7f60 78 * stack routines and structures
1e2b51bb 79 */
796c7f60
KM
80struct sze8 {
81 char element[8];
82};
1e2b51bb
KM
83extern short pop2();
84extern long pop4();
85extern double pop8();
796c7f60 86extern struct sze8 popsze8();
1e2b51bb
KM
87extern char *pushsp();
88
89/*
90 * emulated pc types
91 */
92union progcntr {
93 char *cp;
94 unsigned char *ucp;
95 short *sp;
96 unsigned short *usp;
97 long *lp;
98 double *dp;
99 struct hdr *hdrp;
100};
101\f
102/*
103 * THE RUNTIME DISPLAY
104 *
105 * The entries in the display point to the active static block marks.
106 * The first entry in the display is for the global variables,
107 * then the procedure or function at level one, etc.
108 * Each display entry points to a stack frame as shown:
109 *
110 * base of stack frame
111 * ---------------
112 * | |
113 * | block mark |
114 * | |
15834a19
KM
115 * --------------- <-- display entry "stp" points here
116 * | | <-- display entry "locvars" points here
1e2b51bb
KM
117 * | local |
118 * | variables |
119 * | |
120 * ---------------
121 * | |
122 * | expression |
123 * | temporary |
124 * | storage |
125 * | |
126 * - - - - - - - -
127 *
128 * The information in the block mark is thus at positive offsets from
15834a19
KM
129 * the display.stp pointer entries while the local variables are at negative
130 * offsets from display.locvars. The block mark actually consists of
131 * two parts. The first part is created at CALL and the second at entry,
132 * i.e. BEGIN. Thus:
1e2b51bb
KM
133 *
134 * -------------------------
135 * | |
136 * | Saved lino |
137 * | Saved lc |
138 * | Saved dp |
139 * | |
140 * -------------------------
141 * | |
142 * | Saved (dp) |
143 * | |
15834a19
KM
144 * | Pointer to current |
145 * | routine header info |
1e2b51bb 146 * | |
15834a19
KM
147 * | Saved value of |
148 * | "curfile" |
1e2b51bb
KM
149 * | |
150 * | Empty tos value |
151 * | |
152 * -------------------------
153 */
154\f
155/*
156 * runtime display structure
157 */
158struct disp {
159 char *locvars; /* pointer to local variables */
160 struct stack *stp; /* pointer to local stack frame */
161};
162
163struct stack {
164 char *tos; /* pointer to top of stack frame */
165 struct iorec *file; /* pointer to active file name */
166 struct hdr {
167 long framesze; /* number of bytes of local vars */
168 long nargs; /* number of bytes of arguments */
89060898 169 short tests; /* TRUE => perform runtime tests */
1e2b51bb
KM
170 short offset; /* offset of procedure in source file */
171 char name[1]; /* name of active procedure */
172 } *entry;
173 struct disp odisp; /* previous display value for this level */
174 struct disp *dp; /* pointer to active display entry */
175 union progcntr pc; /* previous location counter */
176 long lino; /* previous line number */
177};
178
15834a19
KM
179union disply {
180 struct disp frame[MAXLVL];
181 char *raw[2*MAXLVL];
182};
183
1e2b51bb
KM
184/*
185 * formal routine structure
186 */
187struct formalrtn {
188 char *entryaddr;
189 long cbn;
190 struct disp disp[2*MAXLVL];
191};
192
193/*
194 * program variables
195 */
15834a19
KM
196extern union disply _display; /* runtime display */
197extern struct disp *_dp; /* ptr to active frame */
198extern long _lino; /* current line number */
199extern int _argc; /* number of passed args */
200extern char **_argv; /* values of passed args */
50d6e33c
KM
201extern long _nodump; /* TRUE => no post mortum dump */
202extern long _runtst; /* TRUE => runtime tests */
15834a19
KM
203extern long _mode; /* execl by PX, PIPE, or PIX */
204extern long _stlim; /* statement limit */
205extern long _stcnt; /* statement count */
50d6e33c 206extern long _seed; /* random number seed */
15834a19
KM
207extern char *_maxptr; /* maximum valid pointer */
208extern char *_minptr; /* minimum valid pointer */
209extern long *_pcpcount; /* pointer to pxp buffer */
210extern long _cntrs; /* number of counters */
211extern long _rtns; /* number of routine cntrs */
212\f
1e2b51bb
KM
213/*
214 * The file i/o routines maintain a notion of a "current file".
215 * A pointer to this file structure is kept in "curfile".
216 *
217 * file structures
218 */
219struct iorechd {
220 char *fileptr; /* ptr to file window */
221 long lcount; /* number of lines printed */
222 long llimit; /* maximum number of text lines */
223 FILE *fbuf; /* FILE ptr */
224 struct iorec *fchain; /* chain to next file */
225 struct iorec *flev; /* ptr to associated file variable */
226 char *pfname; /* ptr to name of file */
227 short funit; /* file status flags */
228 short fblk; /* index into active file table */
229 long fsize; /* size of elements in the file */
230 char fname[NAMSIZ]; /* name of associated UNIX file */
231};
232
233struct iorec {
234 char *fileptr; /* ptr to file window */
235 long lcount; /* number of lines printed */
236 long llimit; /* maximum number of text lines */
237 FILE *fbuf; /* FILE ptr */
238 struct iorec *fchain; /* chain to next file */
239 struct iorec *flev; /* ptr to associated file variable */
240 char *pfname; /* ptr to name of file */
241 short funit; /* file status flags */
242 short fblk; /* index into active file table */
243 long fsize; /* size of elements in the file */
244 char fname[NAMSIZ]; /* name of associated UNIX file */
245 char buf[BUFSIZ]; /* I/O buffer */
246 char window[1]; /* file window element */
247};
15834a19 248\f
1e2b51bb
KM
249/*
250 * unit flags
251 */
252#define FDEF 0x80 /* 1 => reserved file name */
253#define FTEXT 0x40 /* 1 => text file, process EOLN */
254#define FWRITE 0x20 /* 1 => open for writing */
255#define FREAD 0x10 /* 1 => open for reading */
256#define TEMP 0x08 /* 1 => temporary file */
257#define SYNC 0x04 /* 1 => window is out of sync */
258#define EOLN 0x02 /* 1 => at end of line */
259#define EOFF 0x01 /* 1 => at end of file */
260
261/*
262 * file routines
263 */
264extern struct iorec *GETNAME();
265extern char *MKTEMP();
266
267/*
268 * file record variables
269 */
270extern struct iorechd _fchain; /* head of active file chain */
271extern struct iorec *_actfile[]; /* table of active files */
272extern long _filefre; /* last used entry in _actfile */
273
274/*
275 * standard files
276 */
277extern struct iorechd input;
278extern struct iorechd output;
279extern struct iorechd _err;
15834a19 280
1e2b51bb 281/*
15834a19 282 * Px execution profile array
1e2b51bb 283 */
15834a19
KM
284#ifdef PROFILE
285#define NUMOPS 256
286extern long _profcnts[NUMOPS];
287#endif PROFILE