xref: /csrg-svn/usr.bin/pascal/px/vars.h (revision 10574)
12084Smckusick /* Copyright (c) 1979 Regents of the University of California */
22084Smckusick 
3*10574Smckusick /* static char sccsid[] = "@(#)vars.h 1.12 01/22/83"; */
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  *	utilities.c	Interpreter exit, backtrace, and runtime statistics.
312084Smckusick  *
322084Smckusick  * In addition there are several headers defining mappings for panic
332084Smckusick  * names into codes, and a definition of the interpreter transfer
342084Smckusick  * table. These are made by the script make.ed1 in this directory and
352084Smckusick  * the routine opc.c from ${PASCALDIR}. (see the makefile for details)
362084Smckusick  */
372084Smckusick #define PXPFILE		"pmon.out"
382084Smckusick #define	BITSPERBYTE	8
392084Smckusick #define	BITSPERLONG	(BITSPERBYTE * sizeof(long))
4010237Smckusick #define HZ		100
412084Smckusick #define NAMSIZ		76
422084Smckusick #define MAXFILES	32
432084Smckusick #define PREDEF		2
4410236Smckusick #ifdef ADDR32
452084Smckusick #define STDLVL		((struct iorec *)(0x7ffffff1))
462084Smckusick #define GLVL		((struct iorec *)(0x7ffffff0))
4710236Smckusick #endif ADDR32
4810236Smckusick #ifdef ADDR16
492953Smckusic #define STDLVL		((struct iorec *)(0xfff1))
502953Smckusic #define GLVL		((struct iorec *)(0xfff0))
5110236Smckusick #endif ADDR16
522084Smckusick #define FILNIL		((struct iorec *)(0))
532084Smckusick #define INPUT		((struct iorec *)(&input))
542084Smckusick #define OUTPUT		((struct iorec *)(&output))
552084Smckusick #define ERR		((struct iorec *)(&_err))
562084Smckusick #define	PX	0	/* normal run of px */
572084Smckusick #define	PIX	1	/* load and go */
582084Smckusick #define	PIPE	2	/* bootstrap via a pipe */
595660Slinton #define	PDX	3	/* invoked by the debugger "pdx" */
602084Smckusick #define releq 0
612110Smckusic #define relne 2
622110Smckusic #define rellt 4
632110Smckusic #define relgt 6
642110Smckusic #define relle 8
652110Smckusic #define relge 10
662953Smckusic typedef enum {FALSE, TRUE} bool;
672084Smckusick 
682084Smckusick /*
692084Smckusick  * interrupt and allocation routines
702084Smckusick  */
712084Smckusick extern long createtime;
722084Smckusick extern char *PALLOC();
732084Smckusick extern char *malloc();
742953Smckusic extern long time();
752084Smckusick extern intr();
762084Smckusick extern memsize();
772084Smckusick extern syserr();
782084Smckusick extern liberr();
792084Smckusick 
802084Smckusick /*
812234Smckusic  * stack routines and structures
822084Smckusick  */
832234Smckusic struct sze8 {
842234Smckusic 	char element[8];
852234Smckusic };
862084Smckusick extern short pop2();
872084Smckusick extern long pop4();
882084Smckusick extern double pop8();
892234Smckusic extern struct sze8 popsze8();
902084Smckusick extern char *pushsp();
912084Smckusick 
922084Smckusick /*
932084Smckusick  * emulated pc types
942084Smckusick  */
952084Smckusick union progcntr {
962084Smckusick 	char *cp;
972084Smckusick 	unsigned char *ucp;
982084Smckusick 	short *sp;
992084Smckusick 	unsigned short *usp;
1002084Smckusick 	long *lp;
1012953Smckusic 	double *dbp;
1022084Smckusick 	struct hdr *hdrp;
1032084Smckusick };
1042084Smckusick 
1052084Smckusick /*
1062084Smckusick  * THE RUNTIME DISPLAY
1072084Smckusick  *
1082084Smckusick  * The entries in the display point to the active static block marks.
1092084Smckusick  * The first entry in the display is for the global variables,
1102084Smckusick  * then the procedure or function at level one, etc.
1112084Smckusick  * Each display entry points to a stack frame as shown:
1122084Smckusick  *
1132084Smckusick  *		base of stack frame
1142084Smckusick  *		  ---------------
1152084Smckusick  *		  |		|
1162084Smckusick  *		  | block mark  |
1172084Smckusick  *		  |		|
1182110Smckusic  *		  ---------------  <-- display entry "stp" points here
1192110Smckusic  *		  |             |  <-- display entry "locvars" points here
1202084Smckusick  *		  |   local	|
1212084Smckusick  *		  |  variables  |
1222084Smckusick  *		  |		|
1232084Smckusick  *		  ---------------
1242084Smckusick  *		  |		|
1252084Smckusick  *		  |  expression |
1262084Smckusick  *		  |  temporary  |
1272084Smckusick  *		  |  storage	|
1282084Smckusick  *		  |		|
1292084Smckusick  *		  - - - - - - - -
1302084Smckusick  *
1312084Smckusick  * The information in the block mark is thus at positive offsets from
1322110Smckusic  * the display.stp pointer entries while the local variables are at negative
1332110Smckusic  * offsets from display.locvars. The block mark actually consists of
1342110Smckusic  * two parts. The first part is created at CALL and the second at entry,
1352110Smckusic  * i.e. BEGIN. Thus:
1362084Smckusick  *
1372084Smckusick  *		-------------------------
1382084Smckusick  *		|			|
1392084Smckusick  *		|  Saved lino		|
1402084Smckusick  *		|  Saved lc		|
1412084Smckusick  *		|  Saved dp		|
1422084Smckusick  *		|			|
1432084Smckusick  *		-------------------------
1442084Smckusick  *		|			|
1452084Smckusick  *		|  Saved (dp)		|
1462084Smckusick  *		|			|
1472110Smckusic  *		|  Pointer to current 	|
1482110Smckusic  *		|   routine header info	|
1492084Smckusick  *		|			|
1502110Smckusic  *		|  Saved value of	|
1512110Smckusic  *		|   "curfile"		|
1522084Smckusick  *		|			|
1532084Smckusick  *		|  Empty tos value	|
1542084Smckusick  *		|			|
1552084Smckusick  *		-------------------------
1562084Smckusick  */
1572084Smckusick 
1582084Smckusick /*
1592084Smckusick  * program variables
1602084Smckusick  */
161*10574Smckusick extern union display	_display;	/* runtime display */
162*10574Smckusick extern struct dispsave	*_dp;		/* ptr to active frame */
1632110Smckusic extern long		_lino;		/* current line number */
1642110Smckusic extern int		_argc;		/* number of passed args */
1652110Smckusic extern char		**_argv;	/* values of passed args */
1662953Smckusic extern bool		_nodump;	/* TRUE => no post mortum dump */
167*10574Smckusick extern long		_runtst;	/* TRUE => runtime tests */
1682110Smckusic extern long		_mode;		/* execl by PX, PIPE, or PIX */
1692110Smckusic extern long		_stlim;		/* statement limit */
1702110Smckusic extern long		_stcnt;		/* statement count */
1712176Smckusic extern long		_seed;		/* random number seed */
1722110Smckusic extern char		*_maxptr;	/* maximum valid pointer */
1732110Smckusic extern char		*_minptr;	/* minimum valid pointer */
1742110Smckusic extern long		*_pcpcount;	/* pointer to pxp buffer */
1752110Smckusic extern long		_cntrs;		/* number of counters */
1762110Smckusic extern long		_rtns;		/* number of routine cntrs */
1772110Smckusic 
1782084Smckusick /*
1792084Smckusick  * The file i/o routines maintain a notion of a "current file".
1802084Smckusick  * A pointer to this file structure is kept in "curfile".
1812084Smckusick  *
1822084Smckusick  * file structures
1832084Smckusick  */
1842084Smckusick struct iorechd {
1852084Smckusick 	char		*fileptr;	/* ptr to file window */
1862084Smckusick 	long		lcount;		/* number of lines printed */
1872084Smckusick 	long		llimit;		/* maximum number of text lines */
1882084Smckusick 	FILE		*fbuf;		/* FILE ptr */
1892084Smckusick 	struct iorec	*fchain;	/* chain to next file */
1902084Smckusick 	struct iorec	*flev;		/* ptr to associated file variable */
1912084Smckusick 	char		*pfname;	/* ptr to name of file */
1922084Smckusick 	short		funit;		/* file status flags */
1932084Smckusick 	short		fblk;		/* index into active file table */
1942084Smckusick 	long		fsize;		/* size of elements in the file */
1952084Smckusick 	char		fname[NAMSIZ];	/* name of associated UNIX file */
1962084Smckusick };
1972084Smckusick 
1982084Smckusick struct iorec {
1992084Smckusick 	char		*fileptr;	/* ptr to file window */
2002084Smckusick 	long		lcount;		/* number of lines printed */
2012084Smckusick 	long		llimit;		/* maximum number of text lines */
2022084Smckusick 	FILE		*fbuf;		/* FILE ptr */
2032084Smckusick 	struct iorec	*fchain;	/* chain to next file */
2042084Smckusick 	struct iorec	*flev;		/* ptr to associated file variable */
2052084Smckusick 	char		*pfname;	/* ptr to name of file */
2062084Smckusick 	short		funit;		/* file status flags */
2072084Smckusick 	short		fblk;		/* index into active file table */
2082084Smckusick 	long		fsize;		/* size of elements in the file */
2092084Smckusick 	char		fname[NAMSIZ];	/* name of associated UNIX file */
2102084Smckusick 	char		buf[BUFSIZ];	/* I/O buffer */
2112084Smckusick 	char		window[1];	/* file window element */
2122084Smckusick };
2132110Smckusic 
2142084Smckusick /*
2152084Smckusick  * unit flags
2162084Smckusick  */
2172084Smckusick #define	FDEF	0x80	/* 1 => reserved file name */
2182084Smckusick #define	FTEXT	0x40	/* 1 => text file, process EOLN */
2192084Smckusick #define	FWRITE	0x20	/* 1 => open for writing */
2202084Smckusick #define	FREAD	0x10	/* 1 => open for reading */
2212084Smckusick #define	TEMP	0x08	/* 1 => temporary file */
2222084Smckusick #define	SYNC	0x04	/* 1 => window is out of sync */
2232084Smckusick #define	EOLN	0x02	/* 1 => at end of line */
2242084Smckusick #define	EOFF	0x01	/* 1 => at end of file */
2252084Smckusick 
2262084Smckusick /*
2272084Smckusick  * file routines
2282084Smckusick  */
2292084Smckusick extern struct iorec	*GETNAME();
2302084Smckusick extern char		*MKTEMP();
2312084Smckusick 
2322084Smckusick /*
2332084Smckusick  * file record variables
2342084Smckusick  */
2352084Smckusick extern struct iorechd	_fchain;	/* head of active file chain */
2362084Smckusick extern struct iorec	*_actfile[];	/* table of active files */
2372084Smckusick extern long		_filefre;	/* last used entry in _actfile */
2382084Smckusick 
2392084Smckusick /*
2402084Smckusick  * standard files
2412084Smckusick  */
2422084Smckusick extern struct iorechd	input;
2432084Smckusick extern struct iorechd	output;
2442084Smckusick extern struct iorechd	_err;
2452110Smckusic 
2462084Smckusick /*
2472110Smckusic  * Px execution profile array
2482084Smckusick  */
2492110Smckusic #ifdef PROFILE
2502110Smckusic #define	NUMOPS 256
2512110Smckusic extern long _profcnts[NUMOPS];
2522110Smckusic #endif PROFILE
253