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