xref: /csrg-svn/usr.bin/pascal/px/vars.h (revision 10237)
12084Smckusick /* Copyright (c) 1979 Regents of the University of California */
22084Smckusick 
3*10237Smckusick /* static char sccsid[] = "@(#)vars.h 1.11 01/10/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))
40*10237Smckusick #define HZ		100
412084Smckusick #define	MAXLVL		20
422084Smckusick #define NAMSIZ		76
432084Smckusick #define MAXFILES	32
442084Smckusick #define PREDEF		2
4510236Smckusick #ifdef ADDR32
462084Smckusick #define STDLVL		((struct iorec *)(0x7ffffff1))
472084Smckusick #define GLVL		((struct iorec *)(0x7ffffff0))
4810236Smckusick #endif ADDR32
4910236Smckusick #ifdef ADDR16
502953Smckusic #define STDLVL		((struct iorec *)(0xfff1))
512953Smckusic #define GLVL		((struct iorec *)(0xfff0))
5210236Smckusick #endif ADDR16
532084Smckusick #define FILNIL		((struct iorec *)(0))
542084Smckusick #define INPUT		((struct iorec *)(&input))
552084Smckusick #define OUTPUT		((struct iorec *)(&output))
562084Smckusick #define ERR		((struct iorec *)(&_err))
572084Smckusick #define	PX	0	/* normal run of px */
582084Smckusick #define	PIX	1	/* load and go */
592084Smckusick #define	PIPE	2	/* bootstrap via a pipe */
605660Slinton #define	PDX	3	/* invoked by the debugger "pdx" */
612084Smckusick #define releq 0
622110Smckusic #define relne 2
632110Smckusic #define rellt 4
642110Smckusic #define relgt 6
652110Smckusic #define relle 8
662110Smckusic #define relge 10
672953Smckusic typedef enum {FALSE, TRUE} bool;
682084Smckusick 
692084Smckusick /*
702084Smckusick  * interrupt and allocation routines
712084Smckusick  */
722084Smckusick extern long createtime;
732084Smckusick extern char *PALLOC();
742084Smckusick extern char *malloc();
752953Smckusic extern long time();
762084Smckusick extern intr();
772084Smckusick extern memsize();
782084Smckusick extern syserr();
792084Smckusick extern liberr();
802084Smckusick 
812084Smckusick /*
822234Smckusic  * stack routines and structures
832084Smckusick  */
842234Smckusic struct sze8 {
852234Smckusic 	char element[8];
862234Smckusic };
872084Smckusick extern short pop2();
882084Smckusick extern long pop4();
892084Smckusick extern double pop8();
902234Smckusic extern struct sze8 popsze8();
912084Smckusick extern char *pushsp();
922084Smckusick 
932084Smckusick /*
942084Smckusick  * emulated pc types
952084Smckusick  */
962084Smckusick union progcntr {
972084Smckusick 	char *cp;
982084Smckusick 	unsigned char *ucp;
992084Smckusick 	short *sp;
1002084Smckusick 	unsigned short *usp;
1012084Smckusick 	long *lp;
1022953Smckusic 	double *dbp;
1032084Smckusick 	struct hdr *hdrp;
1042084Smckusick };
1052084Smckusick 
1062084Smckusick /*
1072084Smckusick  * THE RUNTIME DISPLAY
1082084Smckusick  *
1092084Smckusick  * The entries in the display point to the active static block marks.
1102084Smckusick  * The first entry in the display is for the global variables,
1112084Smckusick  * then the procedure or function at level one, etc.
1122084Smckusick  * Each display entry points to a stack frame as shown:
1132084Smckusick  *
1142084Smckusick  *		base of stack frame
1152084Smckusick  *		  ---------------
1162084Smckusick  *		  |		|
1172084Smckusick  *		  | block mark  |
1182084Smckusick  *		  |		|
1192110Smckusic  *		  ---------------  <-- display entry "stp" points here
1202110Smckusic  *		  |             |  <-- display entry "locvars" points here
1212084Smckusick  *		  |   local	|
1222084Smckusick  *		  |  variables  |
1232084Smckusick  *		  |		|
1242084Smckusick  *		  ---------------
1252084Smckusick  *		  |		|
1262084Smckusick  *		  |  expression |
1272084Smckusick  *		  |  temporary  |
1282084Smckusick  *		  |  storage	|
1292084Smckusick  *		  |		|
1302084Smckusick  *		  - - - - - - - -
1312084Smckusick  *
1322084Smckusick  * The information in the block mark is thus at positive offsets from
1332110Smckusic  * the display.stp pointer entries while the local variables are at negative
1342110Smckusic  * offsets from display.locvars. The block mark actually consists of
1352110Smckusic  * two parts. The first part is created at CALL and the second at entry,
1362110Smckusic  * i.e. BEGIN. Thus:
1372084Smckusick  *
1382084Smckusick  *		-------------------------
1392084Smckusick  *		|			|
1402084Smckusick  *		|  Saved lino		|
1412084Smckusick  *		|  Saved lc		|
1422084Smckusick  *		|  Saved dp		|
1432084Smckusick  *		|			|
1442084Smckusick  *		-------------------------
1452084Smckusick  *		|			|
1462084Smckusick  *		|  Saved (dp)		|
1472084Smckusick  *		|			|
1482110Smckusic  *		|  Pointer to current 	|
1492110Smckusic  *		|   routine header info	|
1502084Smckusick  *		|			|
1512110Smckusic  *		|  Saved value of	|
1522110Smckusic  *		|   "curfile"		|
1532084Smckusick  *		|			|
1542084Smckusick  *		|  Empty tos value	|
1552084Smckusick  *		|			|
1562084Smckusick  *		-------------------------
1572084Smckusick  */
1582084Smckusick 
1592084Smckusick /*
1602084Smckusick  * runtime display structure
1612084Smckusick  */
1622084Smckusick struct disp {
1632084Smckusick 	char *locvars;		/* pointer to local variables */
1642084Smckusick 	struct stack *stp;	/* pointer to local stack frame */
1652084Smckusick };
1662084Smckusick 
1672084Smckusick struct stack {
1682084Smckusick 	char *tos;		/* pointer to top of stack frame */
1692084Smckusick 	struct iorec *file;	/* pointer to active file name */
1702084Smckusick 	struct hdr {
1712084Smckusick 		long framesze;	/* number of bytes of local vars */
1722084Smckusick 		long nargs;	/* number of bytes of arguments */
1732953Smckusic 		bool tests;	/* TRUE => perform runtime tests */
1742084Smckusick 		short offset;	/* offset of procedure in source file */
1752084Smckusick 		char name[1];	/* name of active procedure */
1762084Smckusick 	} *entry;
1772084Smckusick 	struct disp odisp;	/* previous display value for this level */
1782084Smckusick 	struct disp *dp;	/* pointer to active display entry */
1792084Smckusick 	union progcntr pc;	/* previous location counter */
1802084Smckusick 	long lino;		/* previous line number */
1812084Smckusick };
1822084Smckusick 
1832110Smckusic union disply {
1842110Smckusic 	struct disp frame[MAXLVL];
1852110Smckusic 	char *raw[2*MAXLVL];
1862110Smckusic };
1872110Smckusic 
1882084Smckusick /*
1892084Smckusick  * formal routine structure
1902084Smckusick  */
1912084Smckusick struct formalrtn {
1923435Smckusic 	char		*fentryaddr;		/* formal entry point */
1933435Smckusic 	long		fbn;			/* block number of function */
1943435Smckusic 	struct disp	fdisp[ MAXLVL ];	/* saved at first passing */
1952084Smckusick };
1962084Smckusick 
1972084Smckusick /*
1982084Smckusick  * program variables
1992084Smckusick  */
2002110Smckusic extern union disply	_display;	/* runtime display */
2012110Smckusic extern struct disp	*_dp;		/* ptr to active frame */
2022110Smckusic extern long		_lino;		/* current line number */
2032110Smckusic extern int		_argc;		/* number of passed args */
2042110Smckusic extern char		**_argv;	/* values of passed args */
2052953Smckusic extern bool		_nodump;	/* TRUE => no post mortum dump */
2062953Smckusic extern bool		_runtst;	/* TRUE => runtime tests */
2072110Smckusic extern long		_mode;		/* execl by PX, PIPE, or PIX */
2082110Smckusic extern long		_stlim;		/* statement limit */
2092110Smckusic extern long		_stcnt;		/* statement count */
2102176Smckusic extern long		_seed;		/* random number seed */
2112110Smckusic extern char		*_maxptr;	/* maximum valid pointer */
2122110Smckusic extern char		*_minptr;	/* minimum valid pointer */
2132110Smckusic extern long		*_pcpcount;	/* pointer to pxp buffer */
2142110Smckusic extern long		_cntrs;		/* number of counters */
2152110Smckusic extern long		_rtns;		/* number of routine cntrs */
2162110Smckusic 
2172084Smckusick /*
2182084Smckusick  * The file i/o routines maintain a notion of a "current file".
2192084Smckusick  * A pointer to this file structure is kept in "curfile".
2202084Smckusick  *
2212084Smckusick  * file structures
2222084Smckusick  */
2232084Smckusick struct iorechd {
2242084Smckusick 	char		*fileptr;	/* ptr to file window */
2252084Smckusick 	long		lcount;		/* number of lines printed */
2262084Smckusick 	long		llimit;		/* maximum number of text lines */
2272084Smckusick 	FILE		*fbuf;		/* FILE ptr */
2282084Smckusick 	struct iorec	*fchain;	/* chain to next file */
2292084Smckusick 	struct iorec	*flev;		/* ptr to associated file variable */
2302084Smckusick 	char		*pfname;	/* ptr to name of file */
2312084Smckusick 	short		funit;		/* file status flags */
2322084Smckusick 	short		fblk;		/* index into active file table */
2332084Smckusick 	long		fsize;		/* size of elements in the file */
2342084Smckusick 	char		fname[NAMSIZ];	/* name of associated UNIX file */
2352084Smckusick };
2362084Smckusick 
2372084Smckusick struct iorec {
2382084Smckusick 	char		*fileptr;	/* ptr to file window */
2392084Smckusick 	long		lcount;		/* number of lines printed */
2402084Smckusick 	long		llimit;		/* maximum number of text lines */
2412084Smckusick 	FILE		*fbuf;		/* FILE ptr */
2422084Smckusick 	struct iorec	*fchain;	/* chain to next file */
2432084Smckusick 	struct iorec	*flev;		/* ptr to associated file variable */
2442084Smckusick 	char		*pfname;	/* ptr to name of file */
2452084Smckusick 	short		funit;		/* file status flags */
2462084Smckusick 	short		fblk;		/* index into active file table */
2472084Smckusick 	long		fsize;		/* size of elements in the file */
2482084Smckusick 	char		fname[NAMSIZ];	/* name of associated UNIX file */
2492084Smckusick 	char		buf[BUFSIZ];	/* I/O buffer */
2502084Smckusick 	char		window[1];	/* file window element */
2512084Smckusick };
2522110Smckusic 
2532084Smckusick /*
2542084Smckusick  * unit flags
2552084Smckusick  */
2562084Smckusick #define	FDEF	0x80	/* 1 => reserved file name */
2572084Smckusick #define	FTEXT	0x40	/* 1 => text file, process EOLN */
2582084Smckusick #define	FWRITE	0x20	/* 1 => open for writing */
2592084Smckusick #define	FREAD	0x10	/* 1 => open for reading */
2602084Smckusick #define	TEMP	0x08	/* 1 => temporary file */
2612084Smckusick #define	SYNC	0x04	/* 1 => window is out of sync */
2622084Smckusick #define	EOLN	0x02	/* 1 => at end of line */
2632084Smckusick #define	EOFF	0x01	/* 1 => at end of file */
2642084Smckusick 
2652084Smckusick /*
2662084Smckusick  * file routines
2672084Smckusick  */
2682084Smckusick extern struct iorec	*GETNAME();
2692084Smckusick extern char		*MKTEMP();
2702084Smckusick 
2712084Smckusick /*
2722084Smckusick  * file record variables
2732084Smckusick  */
2742084Smckusick extern struct iorechd	_fchain;	/* head of active file chain */
2752084Smckusick extern struct iorec	*_actfile[];	/* table of active files */
2762084Smckusick extern long		_filefre;	/* last used entry in _actfile */
2772084Smckusick 
2782084Smckusick /*
2792084Smckusick  * standard files
2802084Smckusick  */
2812084Smckusick extern struct iorechd	input;
2822084Smckusick extern struct iorechd	output;
2832084Smckusick extern struct iorechd	_err;
2842110Smckusic 
2852084Smckusick /*
2862110Smckusic  * Px execution profile array
2872084Smckusick  */
2882110Smckusic #ifdef PROFILE
2892110Smckusic #define	NUMOPS 256
2902110Smckusic extern long _profcnts[NUMOPS];
2912110Smckusic #endif PROFILE
292