xref: /csrg-svn/usr.bin/pascal/px/vars.h (revision 2234)
12084Smckusick /* Copyright (c) 1979 Regents of the University of California */
22084Smckusick 
3*2234Smckusic /* static char sccsid[] = "@(#)vars.h 1.5 01/26/81"; */
42084Smckusick 
52084Smckusick #include <stdio.h>
62084Smckusick 
72084Smckusick /*
82084Smckusick  * px - Berkeley Pascal interpreter
92084Smckusick  *
102084Smckusick  * Version 4.0, January 1981
112084Smckusick  *
122084Smckusick  * Original version by Ken Thompson
132084Smckusick  *
142084Smckusick  * Substantial revisions by Bill Joy and Chuck Haley
152084Smckusick  * November-December 1976
162084Smckusick  *
172084Smckusick  * Rewritten for VAX 11/780 by Kirk McKusick
182084Smckusick  * Fall 1978
192084Smckusick  *
202084Smckusick  * Rewritten in ``C'' using libpc by Kirk McKusick
212084Smckusick  * Winter 1981
222084Smckusick  *
232084Smckusick  * Px is described in detail in the "PX 4.0 Implementation Notes"
242084Smckusick  * The source code for px is in several major pieces:
252084Smckusick  *
262084Smckusick  *	int.c		C main program which reads in interpreter code
272084Smckusick  *	interp.c	Driver including main interpreter loop and
282084Smckusick  *			the interpreter instructions grouped by their
292084Smckusick  *			positions in the interpreter table.
302084Smckusick  *	except.c	Handlers for interpreter specific errors not
312084Smckusick  *			included in libpc.
322084Smckusick  *	utilities.c	Interpreter exit, backtrace, and runtime statistics.
332084Smckusick  *
342084Smckusick  * In addition there are several headers defining mappings for panic
352084Smckusick  * names into codes, and a definition of the interpreter transfer
362084Smckusick  * table. These are made by the script make.ed1 in this directory and
372084Smckusick  * the routine opc.c from ${PASCALDIR}. (see the makefile for details)
382084Smckusick  */
392084Smckusick #define PXPFILE		"pmon.out"
402084Smckusick #define	BITSPERBYTE	8
412084Smckusick #define	BITSPERLONG	(BITSPERBYTE * sizeof(long))
422084Smckusick #define HZ		60
432084Smckusick #define	TRUE		1
442084Smckusick #define	FALSE		0
452084Smckusick #define	MAXLVL		20
462084Smckusick #define NAMSIZ		76
472084Smckusick #define MAXFILES	32
482084Smckusick #define PREDEF		2
492084Smckusick #define STDLVL		((struct iorec *)(0x7ffffff1))
502084Smckusick #define GLVL		((struct iorec *)(0x7ffffff0))
512084Smckusick #define FILNIL		((struct iorec *)(0))
522084Smckusick #define INPUT		((struct iorec *)(&input))
532084Smckusick #define OUTPUT		((struct iorec *)(&output))
542084Smckusick #define ERR		((struct iorec *)(&_err))
552084Smckusick #define	PX	0	/* normal run of px */
562084Smckusick #define	PIX	1	/* load and go */
572084Smckusick #define	PIPE	2	/* bootstrap via a pipe */
582084Smckusick #define releq 0
592110Smckusic #define relne 2
602110Smckusic #define rellt 4
612110Smckusic #define relgt 6
622110Smckusic #define relle 8
632110Smckusic #define relge 10
642084Smckusick 
652084Smckusick /*
662084Smckusick  * interrupt and allocation routines
672084Smckusick  */
682084Smckusick extern long createtime;
692084Smckusick extern char *PALLOC();
702084Smckusick extern char *malloc();
712084Smckusick extern intr();
722084Smckusick extern memsize();
732084Smckusick extern except();
742084Smckusick extern syserr();
752084Smckusick extern liberr();
762084Smckusick 
772084Smckusick /*
78*2234Smckusic  * stack routines and structures
792084Smckusick  */
80*2234Smckusic struct sze8 {
81*2234Smckusic 	char element[8];
82*2234Smckusic };
832084Smckusick extern short pop2();
842084Smckusick extern long pop4();
852084Smckusick extern double pop8();
86*2234Smckusic extern struct sze8 popsze8();
872084Smckusick extern char *pushsp();
882084Smckusick 
892084Smckusick /*
902084Smckusick  * emulated pc types
912084Smckusick  */
922084Smckusick union progcntr {
932084Smckusick 	char *cp;
942084Smckusick 	unsigned char *ucp;
952084Smckusick 	short *sp;
962084Smckusick 	unsigned short *usp;
972084Smckusick 	long *lp;
982084Smckusick 	double *dp;
992084Smckusick 	struct hdr *hdrp;
1002084Smckusick };
1012084Smckusick 
1022084Smckusick /*
1032084Smckusick  * THE RUNTIME DISPLAY
1042084Smckusick  *
1052084Smckusick  * The entries in the display point to the active static block marks.
1062084Smckusick  * The first entry in the display is for the global variables,
1072084Smckusick  * then the procedure or function at level one, etc.
1082084Smckusick  * Each display entry points to a stack frame as shown:
1092084Smckusick  *
1102084Smckusick  *		base of stack frame
1112084Smckusick  *		  ---------------
1122084Smckusick  *		  |		|
1132084Smckusick  *		  | block mark  |
1142084Smckusick  *		  |		|
1152110Smckusic  *		  ---------------  <-- display entry "stp" points here
1162110Smckusic  *		  |             |  <-- display entry "locvars" points here
1172084Smckusick  *		  |   local	|
1182084Smckusick  *		  |  variables  |
1192084Smckusick  *		  |		|
1202084Smckusick  *		  ---------------
1212084Smckusick  *		  |		|
1222084Smckusick  *		  |  expression |
1232084Smckusick  *		  |  temporary  |
1242084Smckusick  *		  |  storage	|
1252084Smckusick  *		  |		|
1262084Smckusick  *		  - - - - - - - -
1272084Smckusick  *
1282084Smckusick  * The information in the block mark is thus at positive offsets from
1292110Smckusic  * the display.stp pointer entries while the local variables are at negative
1302110Smckusic  * offsets from display.locvars. The block mark actually consists of
1312110Smckusic  * two parts. The first part is created at CALL and the second at entry,
1322110Smckusic  * i.e. BEGIN. Thus:
1332084Smckusick  *
1342084Smckusick  *		-------------------------
1352084Smckusick  *		|			|
1362084Smckusick  *		|  Saved lino		|
1372084Smckusick  *		|  Saved lc		|
1382084Smckusick  *		|  Saved dp		|
1392084Smckusick  *		|			|
1402084Smckusick  *		-------------------------
1412084Smckusick  *		|			|
1422084Smckusick  *		|  Saved (dp)		|
1432084Smckusick  *		|			|
1442110Smckusic  *		|  Pointer to current 	|
1452110Smckusic  *		|   routine header info	|
1462084Smckusick  *		|			|
1472110Smckusic  *		|  Saved value of	|
1482110Smckusic  *		|   "curfile"		|
1492084Smckusick  *		|			|
1502084Smckusick  *		|  Empty tos value	|
1512084Smckusick  *		|			|
1522084Smckusick  *		-------------------------
1532084Smckusick  */
1542084Smckusick 
1552084Smckusick /*
1562084Smckusick  * runtime display structure
1572084Smckusick  */
1582084Smckusick struct disp {
1592084Smckusick 	char *locvars;		/* pointer to local variables */
1602084Smckusick 	struct stack *stp;	/* pointer to local stack frame */
1612084Smckusick };
1622084Smckusick 
1632084Smckusick struct stack {
1642084Smckusick 	char *tos;		/* pointer to top of stack frame */
1652084Smckusick 	struct iorec *file;	/* pointer to active file name */
1662084Smckusick 	struct hdr {
1672084Smckusick 		long framesze;	/* number of bytes of local vars */
1682084Smckusick 		long nargs;	/* number of bytes of arguments */
1692183Smckusic 		short tests;	/* TRUE => perform runtime tests */
1702084Smckusick 		short offset;	/* offset of procedure in source file */
1712084Smckusick 		char name[1];	/* name of active procedure */
1722084Smckusick 	} *entry;
1732084Smckusick 	struct disp odisp;	/* previous display value for this level */
1742084Smckusick 	struct disp *dp;	/* pointer to active display entry */
1752084Smckusick 	union progcntr pc;	/* previous location counter */
1762084Smckusick 	long lino;		/* previous line number */
1772084Smckusick };
1782084Smckusick 
1792110Smckusic union disply {
1802110Smckusic 	struct disp frame[MAXLVL];
1812110Smckusic 	char *raw[2*MAXLVL];
1822110Smckusic };
1832110Smckusic 
1842084Smckusick /*
1852084Smckusick  * formal routine structure
1862084Smckusick  */
1872084Smckusick struct formalrtn {
1882084Smckusick 	char		*entryaddr;
1892084Smckusick 	long		cbn;
1902084Smckusick 	struct disp	disp[2*MAXLVL];
1912084Smckusick };
1922084Smckusick 
1932084Smckusick /*
1942084Smckusick  * program variables
1952084Smckusick  */
1962110Smckusic extern union disply	_display;	/* runtime display */
1972110Smckusic extern struct disp	*_dp;		/* ptr to active frame */
1982110Smckusic extern long		_lino;		/* current line number */
1992110Smckusic extern int		_argc;		/* number of passed args */
2002110Smckusic extern char		**_argv;	/* values of passed args */
2012176Smckusic extern long		_nodump;	/* TRUE => no post mortum dump */
2022176Smckusic extern long		_runtst;	/* TRUE => runtime tests */
2032110Smckusic extern long		_mode;		/* execl by PX, PIPE, or PIX */
2042110Smckusic extern long		_stlim;		/* statement limit */
2052110Smckusic extern long		_stcnt;		/* statement count */
2062176Smckusic extern long		_seed;		/* random number seed */
2072110Smckusic extern char		*_maxptr;	/* maximum valid pointer */
2082110Smckusic extern char		*_minptr;	/* minimum valid pointer */
2092110Smckusic extern long		*_pcpcount;	/* pointer to pxp buffer */
2102110Smckusic extern long		_cntrs;		/* number of counters */
2112110Smckusic extern long		_rtns;		/* number of routine cntrs */
2122110Smckusic 
2132084Smckusick /*
2142084Smckusick  * The file i/o routines maintain a notion of a "current file".
2152084Smckusick  * A pointer to this file structure is kept in "curfile".
2162084Smckusick  *
2172084Smckusick  * file structures
2182084Smckusick  */
2192084Smckusick struct iorechd {
2202084Smckusick 	char		*fileptr;	/* ptr to file window */
2212084Smckusick 	long		lcount;		/* number of lines printed */
2222084Smckusick 	long		llimit;		/* maximum number of text lines */
2232084Smckusick 	FILE		*fbuf;		/* FILE ptr */
2242084Smckusick 	struct iorec	*fchain;	/* chain to next file */
2252084Smckusick 	struct iorec	*flev;		/* ptr to associated file variable */
2262084Smckusick 	char		*pfname;	/* ptr to name of file */
2272084Smckusick 	short		funit;		/* file status flags */
2282084Smckusick 	short		fblk;		/* index into active file table */
2292084Smckusick 	long		fsize;		/* size of elements in the file */
2302084Smckusick 	char		fname[NAMSIZ];	/* name of associated UNIX file */
2312084Smckusick };
2322084Smckusick 
2332084Smckusick struct iorec {
2342084Smckusick 	char		*fileptr;	/* ptr to file window */
2352084Smckusick 	long		lcount;		/* number of lines printed */
2362084Smckusick 	long		llimit;		/* maximum number of text lines */
2372084Smckusick 	FILE		*fbuf;		/* FILE ptr */
2382084Smckusick 	struct iorec	*fchain;	/* chain to next file */
2392084Smckusick 	struct iorec	*flev;		/* ptr to associated file variable */
2402084Smckusick 	char		*pfname;	/* ptr to name of file */
2412084Smckusick 	short		funit;		/* file status flags */
2422084Smckusick 	short		fblk;		/* index into active file table */
2432084Smckusick 	long		fsize;		/* size of elements in the file */
2442084Smckusick 	char		fname[NAMSIZ];	/* name of associated UNIX file */
2452084Smckusick 	char		buf[BUFSIZ];	/* I/O buffer */
2462084Smckusick 	char		window[1];	/* file window element */
2472084Smckusick };
2482110Smckusic 
2492084Smckusick /*
2502084Smckusick  * unit flags
2512084Smckusick  */
2522084Smckusick #define	FDEF	0x80	/* 1 => reserved file name */
2532084Smckusick #define	FTEXT	0x40	/* 1 => text file, process EOLN */
2542084Smckusick #define	FWRITE	0x20	/* 1 => open for writing */
2552084Smckusick #define	FREAD	0x10	/* 1 => open for reading */
2562084Smckusick #define	TEMP	0x08	/* 1 => temporary file */
2572084Smckusick #define	SYNC	0x04	/* 1 => window is out of sync */
2582084Smckusick #define	EOLN	0x02	/* 1 => at end of line */
2592084Smckusick #define	EOFF	0x01	/* 1 => at end of file */
2602084Smckusick 
2612084Smckusick /*
2622084Smckusick  * file routines
2632084Smckusick  */
2642084Smckusick extern struct iorec	*GETNAME();
2652084Smckusick extern char		*MKTEMP();
2662084Smckusick 
2672084Smckusick /*
2682084Smckusick  * file record variables
2692084Smckusick  */
2702084Smckusick extern struct iorechd	_fchain;	/* head of active file chain */
2712084Smckusick extern struct iorec	*_actfile[];	/* table of active files */
2722084Smckusick extern long		_filefre;	/* last used entry in _actfile */
2732084Smckusick 
2742084Smckusick /*
2752084Smckusick  * standard files
2762084Smckusick  */
2772084Smckusick extern struct iorechd	input;
2782084Smckusick extern struct iorechd	output;
2792084Smckusick extern struct iorechd	_err;
2802110Smckusic 
2812084Smckusick /*
2822110Smckusic  * Px execution profile array
2832084Smckusick  */
2842110Smckusic #ifdef PROFILE
2852110Smckusic #define	NUMOPS 256
2862110Smckusic extern long _profcnts[NUMOPS];
2872110Smckusic #endif PROFILE
288