xref: /csrg-svn/usr.bin/pascal/src/0.h (revision 62203)
148117Sbostic /*-
2*62203Sbostic  * Copyright (c) 1980, 1993
3*62203Sbostic  *	The Regents of the University of California.  All rights reserved.
422218Sdist  *
548117Sbostic  * %sccs.include.redist.c%
648117Sbostic  *
7*62203Sbostic  *	@(#)0.h	8.1 (Berkeley) 06/06/93
822218Sdist  */
9733Speter 
10733Speter #define DEBUG
113071Smckusic #define CONSETS
12733Speter #define	CHAR
13733Speter #define	STATIC
14733Speter #define hp21mx 0
15733Speter 
16733Speter #include	<stdio.h>
1746292Storek #include	<stdlib.h>
18733Speter #include	<sys/types.h>
1923619Smckusick #undef roundup
20733Speter 
213071Smckusic typedef enum {FALSE, TRUE} bool;
22733Speter 
23733Speter /*
24733Speter  * Option flags
25733Speter  *
26733Speter  * The following options are recognized in the text of the program
27733Speter  * and also on the command line:
28733Speter  *
29733Speter  *	b	block buffer the file output
30733Speter  *
31733Speter  *	i	make a listing of the procedures and functions in
32733Speter  *		the following include files
33733Speter  *
34733Speter  *	l	make a listing of the program
35733Speter  *
36733Speter  *	n	place each include file on a new page with a header
37733Speter  *
38733Speter  *	p	disable post mortem and statement limit counting
39733Speter  *
40733Speter  *	t	disable run-time tests
41733Speter  *
42733Speter  *	u	card image mode; only first 72 chars of input count
43733Speter  *
44733Speter  *	w	suppress special diagnostic warnings
45733Speter  *
46733Speter  *	z	generate counters for an execution profile
47733Speter  */
48733Speter #ifdef DEBUG
49733Speter bool	fulltrace, errtrace, testtrace, yyunique;
50733Speter #endif DEBUG
51733Speter 
52733Speter /*
53733Speter  * Each option has a stack of 17 option values, with opts giving
54733Speter  * the current, top value, and optstk the value beneath it.
55733Speter  * One refers to option `l' as, e.g., opt('l') in the text for clarity.
56733Speter  */
57733Speter char	opts[ 'z' - 'A' + 1];
58733Speter short	optstk[ 'z' - 'A' + 1];
59733Speter 
60733Speter #define opt(c) opts[c-'A']
61733Speter 
62733Speter /*
63733Speter  * Monflg is set when we are generating
64733Speter  * a pxp profile.  this is set by the -z command line option.
65733Speter  */
66733Speter bool	monflg;
67733Speter 
68733Speter     /*
69733Speter      *	profflag is set when we are generating a prof profile.
70733Speter      *	this is set by the -p command line option.
71733Speter      */
7214750Sthien #ifdef PC
73733Speter bool	profflag;
7414750Sthien #endif
75733Speter 
76733Speter 
77733Speter /*
78733Speter  * NOTES ON THE DYNAMIC NATURE OF THE DATA STRUCTURES
79733Speter  *
80733Speter  * Pi uses expandable tables for
81733Speter  * its namelist (symbol table), string table
82733Speter  * hash table, and parse tree space.  The following
83733Speter  * definitions specify the size of the increments
84733Speter  * for these items in fundamental units so that
85733Speter  * each uses approximately 1024 bytes.
86733Speter  */
87733Speter 
88733Speter #define	STRINC	1024		/* string space increment */
8920193Smckusick #define	TRINC	1024		/* tree space increment */
90733Speter #define	HASHINC	509		/* hash table size in words, each increment */
91733Speter #define	NLINC	56		/* namelist increment size in nl structs */
92733Speter 
93733Speter /*
94733Speter  * The initial sizes of the structures.
95733Speter  * These should be large enough to compile
96733Speter  * an "average" sized program so as to minimize
97733Speter  * storage requests.
98733Speter  * On a small system or and 11/34 or 11/40
99733Speter  * these numbers can be trimmed to make the
100733Speter  * compiler smaller.
101733Speter  */
102733Speter #define	ITREE	2000
103733Speter #define	INL	200
104733Speter #define	IHASH	509
105733Speter 
106733Speter /*
107733Speter  * The following limits on hash and tree tables currently
108733Speter  * allow approximately 1200 symbols and 20k words of tree
109733Speter  * space.  The fundamental limit of 64k total data space
110733Speter  * should be exceeded well before these are full.
111733Speter  */
112733Speter /*
113733Speter  * TABLE_MULTIPLIER is for uniformly increasing the sizes of the tables
114733Speter  */
11510658Speter #ifdef ADDR32
116733Speter #define TABLE_MULTIPLIER	8
11710658Speter #endif ADDR32
11810658Speter #ifdef ADDR16
1193071Smckusic #define TABLE_MULTIPLIER	1
12010658Speter #endif ADDR16
121733Speter #define	MAXHASH	(4 * TABLE_MULTIPLIER)
122733Speter #define	MAXNL	(12 * TABLE_MULTIPLIER)
12320193Smckusick #define	MAXTREE	(40 * TABLE_MULTIPLIER)
124733Speter /*
125733Speter  * MAXDEPTH is the depth of the parse stack.
126733Speter  * STACK_MULTIPLIER is for increasing its size.
127733Speter  */
12810658Speter #ifdef ADDR32
129733Speter #define	STACK_MULTIPLIER	8
13010658Speter #endif ADDR32
13110658Speter #ifdef ADDR16
1323071Smckusic #define	STACK_MULTIPLIER	1
13310658Speter #endif ADDR16
134733Speter #define	MAXDEPTH ( 150 * STACK_MULTIPLIER )
135733Speter 
136733Speter /*
137733Speter  * ERROR RELATED DEFINITIONS
138733Speter  */
139733Speter 
140733Speter /*
141733Speter  * Exit statuses to pexit
142733Speter  *
143733Speter  * AOK
144733Speter  * ERRS		Compilation errors inhibit obj productin
145733Speter  * NOSTART	Errors before we ever got started
146733Speter  * DIED		We ran out of memory or some such
147733Speter  */
148733Speter #define	AOK	0
149733Speter #define	ERRS	1
150733Speter #define	NOSTART	2
151733Speter #define	DIED	3
152733Speter 
153733Speter bool	Recovery;
154733Speter 
15514750Sthien #define	eholdnl()	Eholdnl = TRUE
15614750Sthien #define	nocascade()	Enocascade = TRUE
157733Speter 
158733Speter bool	Eholdnl, Enocascade;
159733Speter 
160733Speter 
161733Speter /*
162733Speter  * The flag eflg is set whenever we have a hard error.
163733Speter  * The character in errpfx will precede the next error message.
164733Speter  * When cgenflg is set code generation is suppressed.
165733Speter  * This happens whenver we have an error (i.e. if eflg is set)
166733Speter  * and when we are walking the tree to determine types only.
167733Speter  */
168733Speter bool	eflg;
169733Speter char	errpfx;
170733Speter 
171733Speter #define	setpfx(x)	errpfx = x
172733Speter 
173733Speter #define	standard()	setpfx('s')
174733Speter #define	warning()	setpfx('w')
175733Speter #define	recovered()	setpfx('e')
1766358Speter #define	continuation()	setpfx(' ')
177733Speter 
1783071Smckusic int	cgenflg;
179733Speter 
180733Speter 
181733Speter /*
182733Speter  * The flag syneflg is used to suppress the diagnostics of the form
183733Speter  *	E 10 a, defined in someprocedure, is neither used nor set
184733Speter  * when there were syntax errors in "someprocedure".
185733Speter  * In this case, it is likely that these warinings would be spurious.
186733Speter  */
187733Speter bool	syneflg;
188733Speter 
189733Speter /*
190733Speter  * The compiler keeps its error messages in a file.
191733Speter  * The variable efil is the unit number on which
192733Speter  * this file is open for reading of error message text.
193733Speter  * Similarly, the file ofil is the unit of the file
194733Speter  * "obj" where we write the interpreter code.
195733Speter  */
196733Speter short	efil;
19714750Sthien 
19814750Sthien #ifdef OBJ
199733Speter short	ofil;
20014750Sthien 
201733Speter short	obuf[518];
20214750Sthien #endif
203733Speter 
2043071Smckusic bool	Enoline;
2053071Smckusic #define	elineoff()	Enoline = TRUE
2063071Smckusic #define	elineon()	Enoline = FALSE
207733Speter 
208733Speter 
209733Speter /*
210733Speter  * SYMBOL TABLE STRUCTURE DEFINITIONS
211733Speter  *
212733Speter  * The symbol table is henceforth referred to as the "namelist".
213733Speter  * It consists of a number of structures of the form "nl" below.
214733Speter  * These are contained in a number of segments of the symbol
215733Speter  * table which are dynamically allocated as needed.
216733Speter  * The major namelist manipulation routines are contained in the
217733Speter  * file "nl.c".
218733Speter  *
219733Speter  * The major components of a namelist entry are the "symbol", giving
220733Speter  * a pointer into the string table for the string associated with this
221733Speter  * entry and the "class" which tells which of the (currently 19)
222733Speter  * possible types of structure this is.
223733Speter  *
224733Speter  * Many of the classes use the "type" field for a pointer to the type
225733Speter  * which the entry has.
226733Speter  *
227733Speter  * Other pieces of information in more than one class include the block
228733Speter  * in which the symbol is defined, flags indicating whether the symbol
229733Speter  * has been used and whether it has been assigned to, etc.
230733Speter  *
231733Speter  * A more complete discussion of the features of the namelist is impossible
232733Speter  * here as it would be too voluminous.  Refer to the "PI 1.0 Implementation
233733Speter  * Notes" for more details.
234733Speter  */
235733Speter 
236733Speter /*
237733Speter  * The basic namelist structure.
2387915Smckusick  * There is a union of data types defining the stored information
2397915Smckusick  * as pointers, integers, longs, or a double.
240733Speter  *
241733Speter  * The array disptab defines the hash header for the symbol table.
242733Speter  * Symbols are hashed based on the low 6 bits of their pointer into
243733Speter  * the string table; see the routines in the file "lookup.c" and also "fdec.c"
244733Speter  * especially "funcend".
245733Speter  */
2463220Smckusic extern int	pnumcnt;
2473220Smckusic 
248733Speter struct	nl {
249733Speter 	char	*symbol;
2507915Smckusick 	char	info[4];
251733Speter 	struct	nl *type;
252733Speter 	struct	nl *chain, *nl_next;
2537915Smckusick 	union {
25414750Sthien 		struct nl *un_ptr[5];
25514750Sthien 		int	   un_value[5];
25614750Sthien 		long	   un_range[2];
25714750Sthien 		double	   un_real;
25815972Smckusick 		struct nl  *un_nptr[5];	/* Points to conformant array bounds */
2597915Smckusick 	} nl_un;
260733Speter #	ifdef PTREE
261733Speter 	    pPointer	inTree;
262733Speter #	endif PTREE
2637915Smckusick };
264733Speter 
2658680Speter #define class		info[0]
2668680Speter #define nl_flags	info[1]
2678680Speter #define nl_block	info[1]
2688680Speter #define extra_flags	info[2]
2698680Speter #define align_info	info[3]
270733Speter 
2718680Speter #define range	nl_un.un_range
2728680Speter #define value	nl_un.un_value
2738680Speter #define ptr	nl_un.un_ptr
2748680Speter #define real	nl_un.un_real
27515972Smckusick #define nptr	nl_un.un_nptr
276733Speter 
2777915Smckusick extern struct nl *nlp, *disptab[077+1], *Fp;
2787915Smckusick extern struct nl nl[INL];
279733Speter 
2803370Speter 
281733Speter /*
282733Speter  * NL FLAGS BITS
283733Speter  *
284733Speter  * Definitions of the usage of the bits in
285733Speter  * the nl_flags byte. Note that the low 5 bits of the
286733Speter  * byte are the "nl_block" and that some classes make use
287733Speter  * of this byte as a "width".
288733Speter  *
289733Speter  * The only non-obvious bit definition here is "NFILES"
290733Speter  * which records whether a structure contains any files.
291733Speter  * Such structures are not allowed to be dynamically allocated.
292733Speter  */
2933370Speter 
2943370Speter #define	BLOCKNO( flag )	( flag & 037 )
2953370Speter #define NLFLAGS( flag ) ( flag &~ 037 )
2963370Speter 
297733Speter #define	NUSED	0100
298733Speter #define	NMOD	0040
299733Speter #define	NFORWD	0200
300733Speter #define	NFILES	0200
301733Speter #ifdef PC
302733Speter #define NEXTERN 0001	/* flag used to mark external funcs and procs */
3033823Speter #define	NLOCAL	0002	/* variable is a local */
3043823Speter #define	NPARAM	0004	/* variable is a parameter */
3053823Speter #define	NGLOBAL	0010	/* variable is a global */
3063823Speter #define	NREGVAR	0020	/* or'ed in if variable is in a register */
3079126Smckusick #define NNLOCAL 0040	/* named local variable, not used in symbol table */
3083823Speter #endif PC
3093370Speter 
3103540Speter /*
3113540Speter  * used to mark value[ NL_FORV ] for loop variables
3123540Speter  */
3133540Speter #define	FORVAR		1
314733Speter 
315733Speter /*
316733Speter  * Definition of the commonly used "value" fields.
317733Speter  * The most important one is NL_OFFS which gives
318733Speter  * the offset of a variable in its stack mark.
319733Speter  */
320733Speter #define NL_OFFS	0
321733Speter 
322733Speter #define	NL_CNTR	1
3233296Smckusic #define NL_NLSTRT 2
3243296Smckusic #define	NL_LINENO 3
325733Speter #define	NL_FVAR	3
3267915Smckusick #define	NL_ENTLOC 4	/* FUNC, PROC - entry point */
3277915Smckusick #define	NL_FCHAIN 4	/* FFUNC, FPROC - ptr to formals */
328733Speter 
329733Speter #define NL_GOLEV 2
330733Speter #define NL_GOLINE 3
331733Speter #define NL_FORV 1
332733Speter 
3338680Speter     /*
3348680Speter      *	nlp -> nl_un.un_ptr[] subscripts for records
3358680Speter      *	NL_FIELDLIST	the chain of fixed fields of a record, in order.
3368680Speter      *			the fields are also chained through ptr[NL_FIELDLIST].
3378680Speter      *			this does not include the tag, or fields of variants.
3388680Speter      *	NL_VARNT	pointer to the variants of a record,
3398680Speter      *			these are then chained through the .chain field.
3408680Speter      *	NL_VTOREC	pointer from a VARNT to the RECORD that is the variant.
3418680Speter      *	NL_TAG		pointer from a RECORD to the tagfield
3428680Speter      *			if there are any variants.
3438680Speter      *	align_info	the alignment of a RECORD is in info[3].
3448680Speter      */
3458680Speter #define	NL_FIELDLIST	1
3468680Speter #define	NL_VARNT	2
3478680Speter #define	NL_VTOREC	2
3488680Speter #define	NL_TAG		3
3498680Speter /* and align_info is info[3].  #defined above */
350733Speter 
3517915Smckusick #define	NL_ELABEL 4	/* SCAL - ptr to definition of enums */
352733Speter 
353733Speter /*
354733Speter  * For BADUSE nl structures, NL_KINDS is a bit vector
355733Speter  * indicating the kinds of illegal usages complained about
356733Speter  * so far.  For kind of bad use "kind", "1 << kind" is set.
357733Speter  * The low bit is reserved as ISUNDEF to indicate whether
358733Speter  * this identifier is totally undefined.
359733Speter  */
360733Speter #define	NL_KINDS	0
361733Speter 
362733Speter #define	ISUNDEF		1
3633275Smckusic 
3643823Speter     /*
3653823Speter      *	variables come in three flavors: globals, parameters, locals;
3663823Speter      *	they can also hide in registers, but that's a different flag
3673823Speter      */
3683275Smckusic #define PARAMVAR	1
3693275Smckusic #define LOCALVAR	2
3703823Speter #define	GLOBALVAR	3
3719126Smckusick #define	NAMEDLOCALVAR	4
372733Speter 
373733Speter /*
374733Speter  * NAMELIST CLASSES
375733Speter  *
376733Speter  * The following are the namelist classes.
377733Speter  * Different classes make use of the value fields
378733Speter  * of the namelist in different ways.
379733Speter  *
380733Speter  * The namelist should be redesigned by providing
381733Speter  * a number of structure definitions with one corresponding
382733Speter  * to each namelist class, ala a variant record in Pascal.
383733Speter  */
384733Speter #define	BADUSE	0
385733Speter #define	CONST	1
386733Speter #define	TYPE	2
387733Speter #define	VAR	3
388733Speter #define	ARRAY	4
389733Speter #define	PTRFILE	5
390733Speter #define	RECORD	6
391733Speter #define	FIELD	7
392733Speter #define	PROC	8
393733Speter #define	FUNC	9
394733Speter #define	FVAR	10
395733Speter #define	REF	11
396733Speter #define	PTR	12
397733Speter #define	FILET	13
398733Speter #define	SET	14
399733Speter #define	RANGE	15
400733Speter #define	LABEL	16
401733Speter #define	WITHPTR 17
402733Speter #define	SCAL	18
403733Speter #define	STR	19
404733Speter #define	PROG	20
405733Speter #define	IMPROPER 21
406733Speter #define	VARNT	22
4071194Speter #define	FPROC	23
4081194Speter #define	FFUNC	24
40915972Smckusick #define CRANGE	25
410733Speter 
411733Speter /*
412733Speter  * Clnames points to an array of names for the
413733Speter  * namelist classes.
414733Speter  */
415733Speter char	**clnames;
416733Speter 
417733Speter /*
418733Speter  * PRE-DEFINED NAMELIST OFFSETS
419733Speter  *
420733Speter  * The following are the namelist offsets for the
421733Speter  * primitive types. The ones which are negative
422733Speter  * don't actually exist, but are generated and tested
423733Speter  * internally. These definitions are sensitive to the
424733Speter  * initializations in nl.c.
425733Speter  */
426733Speter #define	TFIRST -7
427733Speter #define	TFILE  -7
428733Speter #define	TREC   -6
429733Speter #define	TARY   -5
430733Speter #define	TSCAL  -4
431733Speter #define	TPTR   -3
432733Speter #define	TSET   -2
433733Speter #define	TSTR   -1
434733Speter #define	NIL	0
435733Speter #define	TBOOL	1
436733Speter #define	TCHAR	2
437733Speter #define	TINT	3
438733Speter #define	TDOUBLE	4
439733Speter #define	TNIL	5
440733Speter #define	T1INT	6
441733Speter #define	T2INT	7
442733Speter #define	T4INT	8
443733Speter #define	T1CHAR	9
444733Speter #define	T1BOOL	10
445733Speter #define	T8REAL	11
446733Speter #define TLAST	11
447733Speter 
448733Speter /*
449733Speter  * SEMANTIC DEFINITIONS
450733Speter  */
451733Speter 
452733Speter /*
453733Speter  * NOCON and SAWCON are flags in the tree telling whether
454733Speter  * a constant set is part of an expression.
4553314Speter  *	these are no longer used,
4563314Speter  *	since we now do constant sets at compile time.
457733Speter  */
458733Speter #define NOCON	0
459733Speter #define SAWCON	1
460733Speter 
461733Speter /*
462733Speter  * The variable cbn gives the current block number,
463733Speter  * the variable bn is set as a side effect of a call to
464733Speter  * lookup, and is the block number of the variable which
465733Speter  * was found.
466733Speter  */
467733Speter short	bn, cbn;
468733Speter 
469733Speter /*
470733Speter  * The variable line is the current semantic
471733Speter  * line and is set in stat.c from the numbers
472733Speter  * embedded in statement type tree nodes.
473733Speter  */
474733Speter short	line;
475733Speter 
476733Speter /*
477733Speter  * The size of the display
478733Speter  * which defines the maximum nesting
479733Speter  * of procedures and functions allowed.
480733Speter  * Because of the flags in the current namelist
481733Speter  * this must be no greater than 32.
482733Speter  */
483733Speter #define	DSPLYSZ 20
484733Speter 
485733Speter     /*
486733Speter      *	the following structure records whether a level declares
487733Speter      *	any variables which are (or contain) files.
488733Speter      *	this so that the runtime routines for file cleanup can be invoked.
489733Speter      */
490733Speter bool	dfiles[ DSPLYSZ ];
491733Speter 
492733Speter /*
493733Speter  * Structure recording information about a constant
494733Speter  * declaration.  It is actually the return value from
495733Speter  * the routine "gconst", but since C doesn't support
496733Speter  * record valued functions, this is more convenient.
497733Speter  */
498733Speter struct {
499733Speter 	struct nl	*ctype;
500733Speter 	short		cival;
501733Speter 	double		crval;
50214750Sthien 	char		*cpval;	/* note used to be int * */
503733Speter } con;
504733Speter 
505733Speter /*
506733Speter  * The set structure records the lower bound
507733Speter  * and upper bound with the lower bound normalized
508733Speter  * to zero when working with a set. It is set by
509733Speter  * the routine setran in var.c.
510733Speter  */
511733Speter struct {
512733Speter 	short	lwrb, uprbp;
513733Speter } set;
514733Speter 
515733Speter     /*
516733Speter      *	structures of this kind are filled in by precset and used by postcset
517733Speter      *	to indicate things about constant sets.
518733Speter      */
519733Speter struct csetstr {
520733Speter     struct nl	*csettype;
521733Speter     long	paircnt;
522733Speter     long	singcnt;
523733Speter     bool	comptime;
524733Speter };
525733Speter /*
526733Speter  * The following flags are passed on calls to lvalue
527733Speter  * to indicate how the reference is to affect the usage
528733Speter  * information for the variable being referenced.
529733Speter  * MOD is used to set the NMOD flag in the namelist
530733Speter  * entry for the variable, ASGN permits diagnostics
531733Speter  * to be formed when a for variable is assigned to in
532733Speter  * the range of the loop.
533733Speter  */
534733Speter #define	NOFLAGS	0
535733Speter #define	MOD	01
536733Speter #define	ASGN	02
537733Speter #define	NOUSE	04
538733Speter 
539733Speter     /*
540733Speter      *	the following flags are passed to lvalue and rvalue
541733Speter      *	to tell them whether an lvalue or rvalue is required.
542733Speter      *	the semantics checking is done according to the function called,
543733Speter      *	but for pc, lvalue may put out an rvalue by indirecting afterwards,
544733Speter      *	and rvalue may stop short of putting out the indirection.
545733Speter      */
546733Speter #define	LREQ	01
547733Speter #define	RREQ	02
548733Speter 
549733Speter double	MAXINT;
550733Speter double	MININT;
551733Speter 
552733Speter /*
553733Speter  * Variables for generation of profile information.
554733Speter  * Monflg is set when we want to generate a profile.
555733Speter  * Gocnt record the total number of goto's and
556733Speter  * cnts records the current counter for generating
557733Speter  * COUNT operators.
558733Speter  */
559733Speter short	gocnt;
560733Speter short	cnts;
561733Speter 
562733Speter /*
563733Speter  * Most routines call "incompat" rather than asking "!compat"
564733Speter  * for historical reasons.
565733Speter  */
566733Speter #define incompat 	!compat
567733Speter 
568733Speter /*
569733Speter  * Parts records which declaration parts have been seen.
570833Speter  * The grammar allows the "label" "const" "type" "var" and routine
571733Speter  * parts to be repeated and to be in any order, so that
572733Speter  * they can be detected semantically to give better
573733Speter  * error diagnostics.
5749126Smckusick  *
5759126Smckusick  * The flag NONLOCALVAR indicates that a non-local var has actually
5769126Smckusick  * been used hence the display must be saved; NONLOCALGOTO indicates
5779126Smckusick  * that a non-local goto has been done hence that a setjmp must be done.
578733Speter  */
579833Speter int	parts[ DSPLYSZ ];
580733Speter 
5819126Smckusick #define	LPRT		0x0001
5829126Smckusick #define	CPRT		0x0002
5839126Smckusick #define	TPRT		0x0004
5849126Smckusick #define	VPRT		0x0008
5859126Smckusick #define	RPRT		0x0010
586733Speter 
5879126Smckusick #define	NONLOCALVAR	0x0020
5889126Smckusick #define	NONLOCALGOTO	0x0040
5899126Smckusick 
590733Speter /*
591733Speter  * Flags for the "you used / instead of div" diagnostic
592733Speter  */
593733Speter bool	divchk;
594733Speter bool	divflg;
595733Speter 
5963071Smckusic bool	errcnt[DSPLYSZ];
597733Speter 
598733Speter /*
599733Speter  * Forechain links those types which are
600733Speter  *	^ sometype
601733Speter  * so that they can be evaluated later, permitting
602733Speter  * circular, recursive list structures to be defined.
603733Speter  */
604733Speter struct	nl *forechain;
605733Speter 
606733Speter /*
607733Speter  * Withlist links all the records which are currently
608733Speter  * opened scopes because of with statements.
609733Speter  */
610733Speter struct	nl *withlist;
611733Speter 
612733Speter struct	nl *intset;
613733Speter struct	nl *input, *output;
614733Speter struct	nl *program;
615733Speter 
616733Speter /* progseen flag used by PC to determine if
617733Speter  * a routine segment is being compiled (and
618733Speter  * therefore no program statement seen)
619733Speter  */
620733Speter bool	progseen;
621733Speter 
622733Speter 
623733Speter /*
624733Speter  * STRUCTURED STATEMENT GOTO CHECKING
625733Speter  *
626733Speter  * The variable level keeps track of the current
627733Speter  * "structured statement level" when processing the statement
628733Speter  * body of blocks.  This is used in the detection of goto's into
629733Speter  * structured statements in a block.
630733Speter  *
631733Speter  * Each label's namelist entry contains two pieces of information
632733Speter  * related to this check. The first `NL_GOLEV' either contains
633733Speter  * the level at which the label was declared, `NOTYET' if the label
634733Speter  * has not yet been declared, or `DEAD' if the label is dead, i.e.
635733Speter  * if we have exited the level in which the label was defined.
636733Speter  *
637733Speter  * When we discover a "goto" statement, if the label has not
638733Speter  * been defined yet, then we record the current level and the current line
639733Speter  * for a later error check.  If the label has been already become "DEAD"
640733Speter  * then a reference to it is an error.  Now the compiler maintains,
641733Speter  * for each block, a linked list of the labels headed by "gotos[bn]".
642733Speter  * When we exit a structured level, we perform the routine
643733Speter  * ungoto in stat.c. It notices labels whose definition levels have been
644733Speter  * exited and makes them be dead. For labels which have not yet been
645733Speter  * defined, ungoto will maintain NL_GOLEV as the minimum structured level
646733Speter  * since the first usage of the label. It is not hard to see that the label
647733Speter  * must eventually be declared at this level or an outer level to this
648733Speter  * one or a goto into a structured statement will exist.
649733Speter  */
650733Speter short	level;
651733Speter struct	nl *gotos[DSPLYSZ];
652733Speter 
653733Speter #define	NOTYET	10000
654733Speter #define	DEAD	10000
655733Speter 
656733Speter /*
657733Speter  * Noreach is true when the next statement will
658733Speter  * be unreachable unless something happens along
659733Speter  * (like exiting a looping construct) to save
660733Speter  * the day.
661733Speter  */
662733Speter bool	noreach;
663733Speter 
664733Speter /*
665733Speter  * UNDEFINED VARIABLE REFERENCE STRUCTURES
666733Speter  */
667733Speter struct	udinfo {
668733Speter 	int	ud_line;
669733Speter 	struct	udinfo *ud_next;
670733Speter 	char	nullch;
671733Speter };
672733Speter 
673733Speter /*
674733Speter  * CODE GENERATION DEFINITIONS
675733Speter  */
676733Speter 
677733Speter /*
678733Speter  * NSTAND is or'ed onto the abstract machine opcode
679733Speter  * for non-standard built-in procedures and functions.
680733Speter  */
681733Speter #define	NSTAND	0400
682733Speter 
683733Speter #define	codeon()	cgenflg++
684733Speter #define	codeoff()	--cgenflg
6853314Speter #define	CGENNING	( cgenflg >= 0 )
686733Speter 
687733Speter /*
688733Speter  * Codeline is the last lino output in the code generator.
689733Speter  * It used to be used to suppress LINO operators but no
690733Speter  * more since we now count statements.
691733Speter  * Lc is the intepreter code location counter.
692733Speter  *
693733Speter short	codeline;
694733Speter  */
69514750Sthien #ifdef OBJ
696733Speter char	*lc;
69714750Sthien #endif
698733Speter 
699733Speter 
700733Speter /*
701733Speter  * Routines which need types
702733Speter  * other than "integer" to be
703733Speter  * assumed by the compiler.
704733Speter  */
705733Speter long		lwidth();
7063071Smckusic long		leven();
707733Speter long		aryconst();
708733Speter long		a8tol();
7093071Smckusic long		roundup();
7103823Speter struct nl 	*tmpalloc();
711733Speter struct nl 	*lookup();
712733Speter int		*hash();
713733Speter char		*alloc();
71414750Sthien int		*pcalloc();
715733Speter char		*savestr();
71614750Sthien char 		*esavestr();
7173283Smckusic char		*parnam();
71814750Sthien char		*getlab();
71914750Sthien char		*getnext();
72014750Sthien char		*skipbl();
72114750Sthien char		*nameof();
72214750Sthien char 		*pstrcpy();
72314750Sthien char		*myctime();
72414750Sthien char		*putlab();
7253283Smckusic bool		fcompat();
72614750Sthien bool 		constval();
72714750Sthien bool		precset();
72814750Sthien bool		nilfnil();
72914750Sthien struct nl	*funccod();
73014750Sthien struct nl	*pcfunccod();
731733Speter struct nl	*lookup1();
732733Speter struct nl	*hdefnl();
733733Speter struct nl	*defnl();
73414750Sthien struct nl	*flvalue();
73514750Sthien struct nl	*plist();
736733Speter struct nl	*enter();
737733Speter struct nl	*nlcopy();
7388680Speter struct nl	*tyrec();
739733Speter struct nl	*tyary();
74014750Sthien struct nl	*tyrang();
74114750Sthien struct nl	*tyscal();
742733Speter struct nl	*deffld();
74314750Sthien struct nl	*stklval();
74414750Sthien struct nl	*scalar();
74514750Sthien struct nl	*gen();
74614750Sthien struct nl	*stkrval();
74714750Sthien struct nl	*funcext();
74814750Sthien struct nl	*funchdr();
74914750Sthien struct nl	*funcbody();
75014750Sthien struct nl 	*yybaduse();
75114750Sthien struct nl	*stackRV();
752733Speter struct nl	*defvnt();
753733Speter struct nl	*tyrec1();
754733Speter struct nl	*reclook();
755733Speter struct nl	*asgnop1();
75615983Saoki struct nl	*pcasgconf();
757733Speter struct nl	*gtype();
758733Speter struct nl	*call();
759733Speter struct nl	*lvalue();
76014750Sthien struct nl	*pclvalue();
761733Speter struct nl	*rvalue();
762733Speter struct nl	*cset();
76315983Saoki struct nl	*tycrang();
76414750Sthien struct tnode	*newlist();
76514750Sthien struct tnode	*addlist();
76614750Sthien struct tnode	*fixlist();
76714750Sthien struct tnode	*setupvar();
76814750Sthien struct tnode	*setuptyrec();
76914750Sthien struct tnode	*setupfield();
77014750Sthien struct tnode	*tree();
77114750Sthien struct tnode	*tree1();
77214750Sthien struct tnode	*tree2();
77314750Sthien struct tnode	*tree3();
77414750Sthien struct tnode	*tree4();
77514750Sthien struct tnode	*tree5();
776733Speter 
777733Speter /*
778733Speter  * type cast NIL to keep lint happy (which is not so bad)
779733Speter  */
780733Speter #define		NLNIL	( (struct nl *) NIL )
78114750Sthien #define		TR_NIL	( (struct tnode *) NIL)
782733Speter 
783733Speter /*
784733Speter  * Funny structures to use
785733Speter  * pointers in wild and wooly ways
786733Speter  */
78714750Sthien struct cstruct{
788733Speter 	char	pchar;
789733Speter };
790733Speter struct {
791733Speter 	short	pint;
792733Speter 	short	pint2;
793733Speter };
79414750Sthien struct lstruct {
795733Speter 	long	plong;
796733Speter };
797733Speter struct {
798733Speter 	double	pdouble;
799733Speter };
800733Speter 
801733Speter #define	OCT	1
802733Speter #define	HEX	2
803733Speter 
804733Speter /*
805733Speter  * MAIN PROGRAM VARIABLES, MISCELLANY
806733Speter  */
807733Speter 
808733Speter /*
809733Speter  * Variables forming a data base referencing
810733Speter  * the command line arguments with the "i" option, e.g.
811733Speter  * in "pi -i scanner.i compiler.p".
812733Speter  */
813733Speter char	**pflist;
814733Speter short	pflstc;
815733Speter short	pfcnt;
816733Speter 
817733Speter char	*filename;		/* current source file name */
818733Speter long	tvec;
819733Speter extern char	*snark;		/* SNARK */
820733Speter extern char	*classes[ ];	/* maps namelist classes to string names */
821733Speter 
822733Speter #define	derror error
823733Speter 
824733Speter #ifdef	PC
825733Speter 
826733Speter     /*
827733Speter      *	the current function number, for [ lines
828733Speter      */
829733Speter     int	ftnno;
830733Speter 
831733Speter     /*
832733Speter      *	the pc output stream
833733Speter      */
834733Speter     FILE *pcstream;
835733Speter 
836733Speter #endif PC
837