xref: /csrg-svn/usr.bin/pascal/px/vars.h (revision 48108)
1*48108Sbostic /*-
2*48108Sbostic  * Copyright (c) 1980 The Regents of the University of California.
3*48108Sbostic  * All rights reserved.
422159Sdist  *
5*48108Sbostic  * %sccs.include.redist.c%
6*48108Sbostic  *
7*48108Sbostic  *	@(#)vars.h	5.4 (Berkeley) 04/16/91
822159Sdist  */
92084Smckusick 
102084Smckusick #include <stdio.h>
112084Smckusick 
122084Smckusick /*
132084Smckusick  * px - Berkeley Pascal interpreter
142084Smckusick  *
152084Smckusick  * Version 4.0, January 1981
162084Smckusick  *
172084Smckusick  * Original version by Ken Thompson
182084Smckusick  *
192084Smckusick  * Substantial revisions by Bill Joy and Chuck Haley
202084Smckusick  * November-December 1976
212084Smckusick  *
222084Smckusick  * Rewritten for VAX 11/780 by Kirk McKusick
232084Smckusick  * Fall 1978
242084Smckusick  *
252084Smckusick  * Rewritten in ``C'' using libpc by Kirk McKusick
262084Smckusick  * Winter 1981
272084Smckusick  *
282084Smckusick  * Px is described in detail in the "PX 4.0 Implementation Notes"
292084Smckusick  * The source code for px is in several major pieces:
302084Smckusick  *
312084Smckusick  *	int.c		C main program which reads in interpreter code
322084Smckusick  *	interp.c	Driver including main interpreter loop and
332084Smckusick  *			the interpreter instructions grouped by their
342084Smckusick  *			positions in the interpreter table.
352084Smckusick  *	utilities.c	Interpreter exit, backtrace, and runtime statistics.
362084Smckusick  *
372084Smckusick  * In addition there are several headers defining mappings for panic
382084Smckusick  * names into codes, and a definition of the interpreter transfer
392084Smckusick  * table. These are made by the script make.ed1 in this directory and
402084Smckusick  * the routine opc.c from ${PASCALDIR}. (see the makefile for details)
412084Smckusick  */
422084Smckusick #define PXPFILE		"pmon.out"
432084Smckusick #define	BITSPERBYTE	8
442084Smckusick #define	BITSPERLONG	(BITSPERBYTE * sizeof(long))
4510237Smckusick #define HZ		100
462084Smckusick #define NAMSIZ		76
472084Smckusick #define MAXFILES	32
482084Smckusick #define PREDEF		2
4910236Smckusick #ifdef ADDR32
5029987Smckusick #ifndef tahoe
512084Smckusick #define STDLVL		((struct iorec *)(0x7ffffff1))
522084Smckusick #define GLVL		((struct iorec *)(0x7ffffff0))
5329987Smckusick #else tahoe
5429987Smckusick #define STDLVL		((struct iorec *)(0xbffffff1))
5529987Smckusick #define GLVL		((struct iorec *)(0xbffffff0))
5629987Smckusick #endif tahoe
5710236Smckusick #endif ADDR32
5810236Smckusick #ifdef ADDR16
592953Smckusic #define STDLVL		((struct iorec *)(0xfff1))
602953Smckusic #define GLVL		((struct iorec *)(0xfff0))
6110236Smckusick #endif ADDR16
622084Smckusick #define FILNIL		((struct iorec *)(0))
632084Smckusick #define INPUT		((struct iorec *)(&input))
642084Smckusick #define OUTPUT		((struct iorec *)(&output))
652084Smckusick #define ERR		((struct iorec *)(&_err))
662084Smckusick #define	PX	0	/* normal run of px */
672084Smckusick #define	PIX	1	/* load and go */
682084Smckusick #define	PIPE	2	/* bootstrap via a pipe */
695660Slinton #define	PDX	3	/* invoked by the debugger "pdx" */
702084Smckusick #define releq 0
712110Smckusic #define relne 2
722110Smckusic #define rellt 4
732110Smckusic #define relgt 6
742110Smckusic #define relle 8
752110Smckusic #define relge 10
762953Smckusic typedef enum {FALSE, TRUE} bool;
772084Smckusick 
782084Smckusick /*
792084Smckusick  * interrupt and allocation routines
802084Smckusick  */
812084Smckusick extern long createtime;
822084Smckusick extern char *PALLOC();
832084Smckusick extern char *malloc();
842953Smckusic extern long time();
852084Smckusick extern intr();
862084Smckusick extern memsize();
872084Smckusick extern syserr();
882084Smckusick extern liberr();
892084Smckusick 
902084Smckusick /*
912234Smckusic  * stack routines and structures
922084Smckusick  */
932234Smckusic struct sze8 {
942234Smckusic 	char element[8];
952234Smckusic };
962084Smckusick 
972084Smckusick /*
982084Smckusick  * emulated pc types
992084Smckusick  */
1002084Smckusick union progcntr {
1012084Smckusick 	char *cp;
1022084Smckusick 	unsigned char *ucp;
1032084Smckusick 	short *sp;
1042084Smckusick 	unsigned short *usp;
1052084Smckusick 	long *lp;
1062953Smckusic 	double *dbp;
1072084Smckusick 	struct hdr *hdrp;
10836537Smckusick 	struct sze8 *s8p;
1092084Smckusick };
1102084Smckusick 
1112084Smckusick /*
1122084Smckusick  * THE RUNTIME DISPLAY
1132084Smckusick  *
1142084Smckusick  * The entries in the display point to the active static block marks.
1152084Smckusick  * The first entry in the display is for the global variables,
1162084Smckusick  * then the procedure or function at level one, etc.
1172084Smckusick  * Each display entry points to a stack frame as shown:
1182084Smckusick  *
1192084Smckusick  *		base of stack frame
1202084Smckusick  *		  ---------------
1212084Smckusick  *		  |		|
1222084Smckusick  *		  | block mark  |
1232084Smckusick  *		  |		|
1242110Smckusic  *		  ---------------  <-- display entry "stp" points here
1252110Smckusic  *		  |             |  <-- display entry "locvars" points here
1262084Smckusick  *		  |   local	|
1272084Smckusick  *		  |  variables  |
1282084Smckusick  *		  |		|
1292084Smckusick  *		  ---------------
1302084Smckusick  *		  |		|
1312084Smckusick  *		  |  expression |
1322084Smckusick  *		  |  temporary  |
1332084Smckusick  *		  |  storage	|
1342084Smckusick  *		  |		|
1352084Smckusick  *		  - - - - - - - -
1362084Smckusick  *
1372084Smckusick  * The information in the block mark is thus at positive offsets from
1382110Smckusic  * the display.stp pointer entries while the local variables are at negative
1392110Smckusic  * offsets from display.locvars. The block mark actually consists of
1402110Smckusic  * two parts. The first part is created at CALL and the second at entry,
1412110Smckusic  * i.e. BEGIN. Thus:
1422084Smckusick  *
1432084Smckusick  *		-------------------------
1442084Smckusick  *		|			|
1452084Smckusick  *		|  Saved lino		|
1462084Smckusick  *		|  Saved lc		|
1472084Smckusick  *		|  Saved dp		|
1482084Smckusick  *		|			|
1492084Smckusick  *		-------------------------
1502084Smckusick  *		|			|
1512084Smckusick  *		|  Saved (dp)		|
1522084Smckusick  *		|			|
1532110Smckusic  *		|  Pointer to current 	|
1542110Smckusic  *		|   routine header info	|
1552084Smckusick  *		|			|
1562110Smckusic  *		|  Saved value of	|
1572110Smckusic  *		|   "curfile"		|
1582084Smckusick  *		|			|
1592084Smckusick  *		|  Empty tos value	|
1602084Smckusick  *		|			|
1612084Smckusick  *		-------------------------
1622084Smckusick  */
1632084Smckusick 
1642084Smckusick /*
1652084Smckusick  * program variables
1662084Smckusick  */
16710574Smckusick extern union display	_display;	/* runtime display */
16810574Smckusick extern struct dispsave	*_dp;		/* ptr to active frame */
1692110Smckusic extern long		_lino;		/* current line number */
1702110Smckusic extern int		_argc;		/* number of passed args */
1712110Smckusic extern char		**_argv;	/* values of passed args */
1722953Smckusic extern bool		_nodump;	/* TRUE => no post mortum dump */
17310574Smckusick extern long		_runtst;	/* TRUE => runtime tests */
1742110Smckusic extern long		_mode;		/* execl by PX, PIPE, or PIX */
1752110Smckusic extern long		_stlim;		/* statement limit */
1762110Smckusic extern long		_stcnt;		/* statement count */
1772176Smckusic extern long		_seed;		/* random number seed */
1782110Smckusic extern char		*_maxptr;	/* maximum valid pointer */
1792110Smckusic extern char		*_minptr;	/* minimum valid pointer */
1802110Smckusic extern long		*_pcpcount;	/* pointer to pxp buffer */
1812110Smckusic extern long		_cntrs;		/* number of counters */
1822110Smckusic extern long		_rtns;		/* number of routine cntrs */
1832110Smckusic 
1842084Smckusick /*
1852084Smckusick  * The file i/o routines maintain a notion of a "current file".
1862084Smckusick  * A pointer to this file structure is kept in "curfile".
1872084Smckusick  *
1882084Smckusick  * file structures
1892084Smckusick  */
1902084Smckusick struct iorechd {
1912084Smckusick 	char		*fileptr;	/* ptr to file window */
1922084Smckusick 	long		lcount;		/* number of lines printed */
1932084Smckusick 	long		llimit;		/* maximum number of text lines */
1942084Smckusick 	FILE		*fbuf;		/* FILE ptr */
1952084Smckusick 	struct iorec	*fchain;	/* chain to next file */
1962084Smckusick 	struct iorec	*flev;		/* ptr to associated file variable */
1972084Smckusick 	char		*pfname;	/* ptr to name of file */
1982084Smckusick 	short		funit;		/* file status flags */
1992084Smckusick 	short		fblk;		/* index into active file table */
2002084Smckusick 	long		fsize;		/* size of elements in the file */
2012084Smckusick 	char		fname[NAMSIZ];	/* name of associated UNIX file */
2022084Smckusick };
2032084Smckusick 
2042084Smckusick struct iorec {
2052084Smckusick 	char		*fileptr;	/* ptr to file window */
2062084Smckusick 	long		lcount;		/* number of lines printed */
2072084Smckusick 	long		llimit;		/* maximum number of text lines */
2082084Smckusick 	FILE		*fbuf;		/* FILE ptr */
2092084Smckusick 	struct iorec	*fchain;	/* chain to next file */
2102084Smckusick 	struct iorec	*flev;		/* ptr to associated file variable */
2112084Smckusick 	char		*pfname;	/* ptr to name of file */
2122084Smckusick 	short		funit;		/* file status flags */
2132084Smckusick 	short		fblk;		/* index into active file table */
2142084Smckusick 	long		fsize;		/* size of elements in the file */
2152084Smckusick 	char		fname[NAMSIZ];	/* name of associated UNIX file */
2162084Smckusick 	char		buf[BUFSIZ];	/* I/O buffer */
2172084Smckusick 	char		window[1];	/* file window element */
2182084Smckusick };
2192110Smckusic 
2202084Smckusick /*
2212084Smckusick  * unit flags
2222084Smckusick  */
2232084Smckusick #define	FDEF	0x80	/* 1 => reserved file name */
2242084Smckusick #define	FTEXT	0x40	/* 1 => text file, process EOLN */
2252084Smckusick #define	FWRITE	0x20	/* 1 => open for writing */
2262084Smckusick #define	FREAD	0x10	/* 1 => open for reading */
2272084Smckusick #define	TEMP	0x08	/* 1 => temporary file */
2282084Smckusick #define	SYNC	0x04	/* 1 => window is out of sync */
2292084Smckusick #define	EOLN	0x02	/* 1 => at end of line */
2302084Smckusick #define	EOFF	0x01	/* 1 => at end of file */
2312084Smckusick 
2322084Smckusick /*
2332084Smckusick  * file routines
2342084Smckusick  */
2352084Smckusick extern struct iorec	*GETNAME();
2362084Smckusick extern char		*MKTEMP();
2372084Smckusick 
2382084Smckusick /*
2392084Smckusick  * file record variables
2402084Smckusick  */
2412084Smckusick extern struct iorechd	_fchain;	/* head of active file chain */
2422084Smckusick extern struct iorec	*_actfile[];	/* table of active files */
2432084Smckusick extern long		_filefre;	/* last used entry in _actfile */
2442084Smckusick 
2452084Smckusick /*
2462084Smckusick  * standard files
2472084Smckusick  */
2482084Smckusick extern struct iorechd	input;
2492084Smckusick extern struct iorechd	output;
2502084Smckusick extern struct iorechd	_err;
2512110Smckusic 
2522084Smckusick /*
2532110Smckusic  * Px execution profile array
2542084Smckusick  */
2552110Smckusic #ifdef PROFILE
2562110Smckusic #define	NUMOPS 256
2572110Smckusic extern long _profcnts[NUMOPS];
2582110Smckusic #endif PROFILE
259