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