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