xref: /csrg-svn/usr.bin/pascal/px/vars.h (revision 22159)
1*22159Sdist /*
2*22159Sdist  * Copyright (c) 1980 Regents of the University of California.
3*22159Sdist  * All rights reserved.  The Berkeley software License Agreement
4*22159Sdist  * specifies the terms and conditions for redistribution.
5*22159Sdist  *
6*22159Sdist  *	@(#)vars.h	5.1 (Berkeley) 06/05/85
7*22159Sdist  */
82084Smckusick 
92084Smckusick #include <stdio.h>
102084Smckusick 
112084Smckusick /*
122084Smckusick  * px - Berkeley Pascal interpreter
132084Smckusick  *
142084Smckusick  * Version 4.0, January 1981
152084Smckusick  *
162084Smckusick  * Original version by Ken Thompson
172084Smckusick  *
182084Smckusick  * Substantial revisions by Bill Joy and Chuck Haley
192084Smckusick  * November-December 1976
202084Smckusick  *
212084Smckusick  * Rewritten for VAX 11/780 by Kirk McKusick
222084Smckusick  * Fall 1978
232084Smckusick  *
242084Smckusick  * Rewritten in ``C'' using libpc by Kirk McKusick
252084Smckusick  * Winter 1981
262084Smckusick  *
272084Smckusick  * Px is described in detail in the "PX 4.0 Implementation Notes"
282084Smckusick  * The source code for px is in several major pieces:
292084Smckusick  *
302084Smckusick  *	int.c		C main program which reads in interpreter code
312084Smckusick  *	interp.c	Driver including main interpreter loop and
322084Smckusick  *			the interpreter instructions grouped by their
332084Smckusick  *			positions in the interpreter table.
342084Smckusick  *	utilities.c	Interpreter exit, backtrace, and runtime statistics.
352084Smckusick  *
362084Smckusick  * In addition there are several headers defining mappings for panic
372084Smckusick  * names into codes, and a definition of the interpreter transfer
382084Smckusick  * table. These are made by the script make.ed1 in this directory and
392084Smckusick  * the routine opc.c from ${PASCALDIR}. (see the makefile for details)
402084Smckusick  */
412084Smckusick #define PXPFILE		"pmon.out"
422084Smckusick #define	BITSPERBYTE	8
432084Smckusick #define	BITSPERLONG	(BITSPERBYTE * sizeof(long))
4410237Smckusick #define HZ		100
452084Smckusick #define NAMSIZ		76
462084Smckusick #define MAXFILES	32
472084Smckusick #define PREDEF		2
4810236Smckusick #ifdef ADDR32
492084Smckusick #define STDLVL		((struct iorec *)(0x7ffffff1))
502084Smckusick #define GLVL		((struct iorec *)(0x7ffffff0))
5110236Smckusick #endif ADDR32
5210236Smckusick #ifdef ADDR16
532953Smckusic #define STDLVL		((struct iorec *)(0xfff1))
542953Smckusic #define GLVL		((struct iorec *)(0xfff0))
5510236Smckusick #endif ADDR16
562084Smckusick #define FILNIL		((struct iorec *)(0))
572084Smckusick #define INPUT		((struct iorec *)(&input))
582084Smckusick #define OUTPUT		((struct iorec *)(&output))
592084Smckusick #define ERR		((struct iorec *)(&_err))
602084Smckusick #define	PX	0	/* normal run of px */
612084Smckusick #define	PIX	1	/* load and go */
622084Smckusick #define	PIPE	2	/* bootstrap via a pipe */
635660Slinton #define	PDX	3	/* invoked by the debugger "pdx" */
642084Smckusick #define releq 0
652110Smckusic #define relne 2
662110Smckusic #define rellt 4
672110Smckusic #define relgt 6
682110Smckusic #define relle 8
692110Smckusic #define relge 10
702953Smckusic typedef enum {FALSE, TRUE} bool;
712084Smckusick 
722084Smckusick /*
732084Smckusick  * interrupt and allocation routines
742084Smckusick  */
752084Smckusick extern long createtime;
762084Smckusick extern char *PALLOC();
772084Smckusick extern char *malloc();
782953Smckusic extern long time();
792084Smckusick extern intr();
802084Smckusick extern memsize();
812084Smckusick extern syserr();
822084Smckusick extern liberr();
832084Smckusick 
842084Smckusick /*
852234Smckusic  * stack routines and structures
862084Smckusick  */
872234Smckusic struct sze8 {
882234Smckusic 	char element[8];
892234Smckusic };
902084Smckusick extern short pop2();
912084Smckusick extern long pop4();
922084Smckusick extern double pop8();
932234Smckusic extern struct sze8 popsze8();
942084Smckusick extern char *pushsp();
952084Smckusick 
962084Smckusick /*
972084Smckusick  * emulated pc types
982084Smckusick  */
992084Smckusick union progcntr {
1002084Smckusick 	char *cp;
1012084Smckusick 	unsigned char *ucp;
1022084Smckusick 	short *sp;
1032084Smckusick 	unsigned short *usp;
1042084Smckusick 	long *lp;
1052953Smckusic 	double *dbp;
1062084Smckusick 	struct hdr *hdrp;
1072084Smckusick };
1082084Smckusick 
1092084Smckusick /*
1102084Smckusick  * THE RUNTIME DISPLAY
1112084Smckusick  *
1122084Smckusick  * The entries in the display point to the active static block marks.
1132084Smckusick  * The first entry in the display is for the global variables,
1142084Smckusick  * then the procedure or function at level one, etc.
1152084Smckusick  * Each display entry points to a stack frame as shown:
1162084Smckusick  *
1172084Smckusick  *		base of stack frame
1182084Smckusick  *		  ---------------
1192084Smckusick  *		  |		|
1202084Smckusick  *		  | block mark  |
1212084Smckusick  *		  |		|
1222110Smckusic  *		  ---------------  <-- display entry "stp" points here
1232110Smckusic  *		  |             |  <-- display entry "locvars" points here
1242084Smckusick  *		  |   local	|
1252084Smckusick  *		  |  variables  |
1262084Smckusick  *		  |		|
1272084Smckusick  *		  ---------------
1282084Smckusick  *		  |		|
1292084Smckusick  *		  |  expression |
1302084Smckusick  *		  |  temporary  |
1312084Smckusick  *		  |  storage	|
1322084Smckusick  *		  |		|
1332084Smckusick  *		  - - - - - - - -
1342084Smckusick  *
1352084Smckusick  * The information in the block mark is thus at positive offsets from
1362110Smckusic  * the display.stp pointer entries while the local variables are at negative
1372110Smckusic  * offsets from display.locvars. The block mark actually consists of
1382110Smckusic  * two parts. The first part is created at CALL and the second at entry,
1392110Smckusic  * i.e. BEGIN. Thus:
1402084Smckusick  *
1412084Smckusick  *		-------------------------
1422084Smckusick  *		|			|
1432084Smckusick  *		|  Saved lino		|
1442084Smckusick  *		|  Saved lc		|
1452084Smckusick  *		|  Saved dp		|
1462084Smckusick  *		|			|
1472084Smckusick  *		-------------------------
1482084Smckusick  *		|			|
1492084Smckusick  *		|  Saved (dp)		|
1502084Smckusick  *		|			|
1512110Smckusic  *		|  Pointer to current 	|
1522110Smckusic  *		|   routine header info	|
1532084Smckusick  *		|			|
1542110Smckusic  *		|  Saved value of	|
1552110Smckusic  *		|   "curfile"		|
1562084Smckusick  *		|			|
1572084Smckusick  *		|  Empty tos value	|
1582084Smckusick  *		|			|
1592084Smckusick  *		-------------------------
1602084Smckusick  */
1612084Smckusick 
1622084Smckusick /*
1632084Smckusick  * program variables
1642084Smckusick  */
16510574Smckusick extern union display	_display;	/* runtime display */
16610574Smckusick extern struct dispsave	*_dp;		/* ptr to active frame */
1672110Smckusic extern long		_lino;		/* current line number */
1682110Smckusic extern int		_argc;		/* number of passed args */
1692110Smckusic extern char		**_argv;	/* values of passed args */
1702953Smckusic extern bool		_nodump;	/* TRUE => no post mortum dump */
17110574Smckusick extern long		_runtst;	/* TRUE => runtime tests */
1722110Smckusic extern long		_mode;		/* execl by PX, PIPE, or PIX */
1732110Smckusic extern long		_stlim;		/* statement limit */
1742110Smckusic extern long		_stcnt;		/* statement count */
1752176Smckusic extern long		_seed;		/* random number seed */
1762110Smckusic extern char		*_maxptr;	/* maximum valid pointer */
1772110Smckusic extern char		*_minptr;	/* minimum valid pointer */
1782110Smckusic extern long		*_pcpcount;	/* pointer to pxp buffer */
1792110Smckusic extern long		_cntrs;		/* number of counters */
1802110Smckusic extern long		_rtns;		/* number of routine cntrs */
1812110Smckusic 
1822084Smckusick /*
1832084Smckusick  * The file i/o routines maintain a notion of a "current file".
1842084Smckusick  * A pointer to this file structure is kept in "curfile".
1852084Smckusick  *
1862084Smckusick  * file structures
1872084Smckusick  */
1882084Smckusick struct iorechd {
1892084Smckusick 	char		*fileptr;	/* ptr to file window */
1902084Smckusick 	long		lcount;		/* number of lines printed */
1912084Smckusick 	long		llimit;		/* maximum number of text lines */
1922084Smckusick 	FILE		*fbuf;		/* FILE ptr */
1932084Smckusick 	struct iorec	*fchain;	/* chain to next file */
1942084Smckusick 	struct iorec	*flev;		/* ptr to associated file variable */
1952084Smckusick 	char		*pfname;	/* ptr to name of file */
1962084Smckusick 	short		funit;		/* file status flags */
1972084Smckusick 	short		fblk;		/* index into active file table */
1982084Smckusick 	long		fsize;		/* size of elements in the file */
1992084Smckusick 	char		fname[NAMSIZ];	/* name of associated UNIX file */
2002084Smckusick };
2012084Smckusick 
2022084Smckusick struct iorec {
2032084Smckusick 	char		*fileptr;	/* ptr to file window */
2042084Smckusick 	long		lcount;		/* number of lines printed */
2052084Smckusick 	long		llimit;		/* maximum number of text lines */
2062084Smckusick 	FILE		*fbuf;		/* FILE ptr */
2072084Smckusick 	struct iorec	*fchain;	/* chain to next file */
2082084Smckusick 	struct iorec	*flev;		/* ptr to associated file variable */
2092084Smckusick 	char		*pfname;	/* ptr to name of file */
2102084Smckusick 	short		funit;		/* file status flags */
2112084Smckusick 	short		fblk;		/* index into active file table */
2122084Smckusick 	long		fsize;		/* size of elements in the file */
2132084Smckusick 	char		fname[NAMSIZ];	/* name of associated UNIX file */
2142084Smckusick 	char		buf[BUFSIZ];	/* I/O buffer */
2152084Smckusick 	char		window[1];	/* file window element */
2162084Smckusick };
2172110Smckusic 
2182084Smckusick /*
2192084Smckusick  * unit flags
2202084Smckusick  */
2212084Smckusick #define	FDEF	0x80	/* 1 => reserved file name */
2222084Smckusick #define	FTEXT	0x40	/* 1 => text file, process EOLN */
2232084Smckusick #define	FWRITE	0x20	/* 1 => open for writing */
2242084Smckusick #define	FREAD	0x10	/* 1 => open for reading */
2252084Smckusick #define	TEMP	0x08	/* 1 => temporary file */
2262084Smckusick #define	SYNC	0x04	/* 1 => window is out of sync */
2272084Smckusick #define	EOLN	0x02	/* 1 => at end of line */
2282084Smckusick #define	EOFF	0x01	/* 1 => at end of file */
2292084Smckusick 
2302084Smckusick /*
2312084Smckusick  * file routines
2322084Smckusick  */
2332084Smckusick extern struct iorec	*GETNAME();
2342084Smckusick extern char		*MKTEMP();
2352084Smckusick 
2362084Smckusick /*
2372084Smckusick  * file record variables
2382084Smckusick  */
2392084Smckusick extern struct iorechd	_fchain;	/* head of active file chain */
2402084Smckusick extern struct iorec	*_actfile[];	/* table of active files */
2412084Smckusick extern long		_filefre;	/* last used entry in _actfile */
2422084Smckusick 
2432084Smckusick /*
2442084Smckusick  * standard files
2452084Smckusick  */
2462084Smckusick extern struct iorechd	input;
2472084Smckusick extern struct iorechd	output;
2482084Smckusick extern struct iorechd	_err;
2492110Smckusic 
2502084Smckusick /*
2512110Smckusic  * Px execution profile array
2522084Smckusick  */
2532110Smckusic #ifdef PROFILE
2542110Smckusic #define	NUMOPS 256
2552110Smckusic extern long _profcnts[NUMOPS];
2562110Smckusic #endif PROFILE
257