new copyright; att/bsd/shared
[unix-history] / usr / src / usr.bin / pascal / px / vars.h
CommitLineData
505bf312
KB
1/*-
2 * Copyright (c) 1980 The Regents of the University of California.
3 * All rights reserved.
4 *
5 * %sccs.include.redist.c%
1259848a 6 *
505bf312 7 * @(#)vars.h 5.4 (Berkeley) %G%
1259848a 8 */
1e2b51bb
KM
9
10#include <stdio.h>
11
12/*
13 * px - Berkeley Pascal interpreter
14 *
15 * Version 4.0, January 1981
16 *
17 * Original version by Ken Thompson
18 *
19 * Substantial revisions by Bill Joy and Chuck Haley
20 * November-December 1976
21 *
22 * Rewritten for VAX 11/780 by Kirk McKusick
23 * Fall 1978
24 *
25 * Rewritten in ``C'' using libpc by Kirk McKusick
26 * Winter 1981
27 *
28 * Px is described in detail in the "PX 4.0 Implementation Notes"
29 * The source code for px is in several major pieces:
30 *
31 * int.c C main program which reads in interpreter code
32 * interp.c Driver including main interpreter loop and
33 * the interpreter instructions grouped by their
34 * positions in the interpreter table.
1e2b51bb
KM
35 * utilities.c Interpreter exit, backtrace, and runtime statistics.
36 *
37 * In addition there are several headers defining mappings for panic
38 * names into codes, and a definition of the interpreter transfer
39 * table. These are made by the script make.ed1 in this directory and
40 * the routine opc.c from ${PASCALDIR}. (see the makefile for details)
41 */
42#define PXPFILE "pmon.out"
43#define BITSPERBYTE 8
44#define BITSPERLONG (BITSPERBYTE * sizeof(long))
980cb17c 45#define HZ 100
1e2b51bb
KM
46#define NAMSIZ 76
47#define MAXFILES 32
48#define PREDEF 2
a7012926 49#ifdef ADDR32
f568a707 50#ifndef tahoe
1e2b51bb
KM
51#define STDLVL ((struct iorec *)(0x7ffffff1))
52#define GLVL ((struct iorec *)(0x7ffffff0))
f568a707
KM
53#else tahoe
54#define STDLVL ((struct iorec *)(0xbffffff1))
55#define GLVL ((struct iorec *)(0xbffffff0))
56#endif tahoe
a7012926
KM
57#endif ADDR32
58#ifdef ADDR16
9a92014d
KM
59#define STDLVL ((struct iorec *)(0xfff1))
60#define GLVL ((struct iorec *)(0xfff0))
a7012926 61#endif ADDR16
1e2b51bb
KM
62#define FILNIL ((struct iorec *)(0))
63#define INPUT ((struct iorec *)(&input))
64#define OUTPUT ((struct iorec *)(&output))
65#define ERR ((struct iorec *)(&_err))
66#define PX 0 /* normal run of px */
67#define PIX 1 /* load and go */
68#define PIPE 2 /* bootstrap via a pipe */
79029c32 69#define PDX 3 /* invoked by the debugger "pdx" */
1e2b51bb 70#define releq 0
15834a19
KM
71#define relne 2
72#define rellt 4
73#define relgt 6
74#define relle 8
75#define relge 10
9a92014d 76typedef enum {FALSE, TRUE} bool;
1e2b51bb
KM
77
78/*
79 * interrupt and allocation routines
80 */
81extern long createtime;
82extern char *PALLOC();
83extern char *malloc();
9a92014d 84extern long time();
1e2b51bb
KM
85extern intr();
86extern memsize();
1e2b51bb
KM
87extern syserr();
88extern liberr();
89
90/*
796c7f60 91 * stack routines and structures
1e2b51bb 92 */
796c7f60
KM
93struct sze8 {
94 char element[8];
95};
1e2b51bb
KM
96
97/*
98 * emulated pc types
99 */
100union progcntr {
101 char *cp;
102 unsigned char *ucp;
103 short *sp;
104 unsigned short *usp;
105 long *lp;
9a92014d 106 double *dbp;
1e2b51bb 107 struct hdr *hdrp;
24ba2374 108 struct sze8 *s8p;
1e2b51bb
KM
109};
110\f
111/*
112 * THE RUNTIME DISPLAY
113 *
114 * The entries in the display point to the active static block marks.
115 * The first entry in the display is for the global variables,
116 * then the procedure or function at level one, etc.
117 * Each display entry points to a stack frame as shown:
118 *
119 * base of stack frame
120 * ---------------
121 * | |
122 * | block mark |
123 * | |
15834a19
KM
124 * --------------- <-- display entry "stp" points here
125 * | | <-- display entry "locvars" points here
1e2b51bb
KM
126 * | local |
127 * | variables |
128 * | |
129 * ---------------
130 * | |
131 * | expression |
132 * | temporary |
133 * | storage |
134 * | |
135 * - - - - - - - -
136 *
137 * The information in the block mark is thus at positive offsets from
15834a19
KM
138 * the display.stp pointer entries while the local variables are at negative
139 * offsets from display.locvars. The block mark actually consists of
140 * two parts. The first part is created at CALL and the second at entry,
141 * i.e. BEGIN. Thus:
1e2b51bb
KM
142 *
143 * -------------------------
144 * | |
145 * | Saved lino |
146 * | Saved lc |
147 * | Saved dp |
148 * | |
149 * -------------------------
150 * | |
151 * | Saved (dp) |
152 * | |
15834a19
KM
153 * | Pointer to current |
154 * | routine header info |
1e2b51bb 155 * | |
15834a19
KM
156 * | Saved value of |
157 * | "curfile" |
1e2b51bb
KM
158 * | |
159 * | Empty tos value |
160 * | |
161 * -------------------------
162 */
163\f
1e2b51bb
KM
164/*
165 * program variables
166 */
831541c9
KM
167extern union display _display; /* runtime display */
168extern struct dispsave *_dp; /* ptr to active frame */
15834a19
KM
169extern long _lino; /* current line number */
170extern int _argc; /* number of passed args */
171extern char **_argv; /* values of passed args */
9a92014d 172extern bool _nodump; /* TRUE => no post mortum dump */
831541c9 173extern long _runtst; /* TRUE => runtime tests */
15834a19
KM
174extern long _mode; /* execl by PX, PIPE, or PIX */
175extern long _stlim; /* statement limit */
176extern long _stcnt; /* statement count */
50d6e33c 177extern long _seed; /* random number seed */
15834a19
KM
178extern char *_maxptr; /* maximum valid pointer */
179extern char *_minptr; /* minimum valid pointer */
180extern long *_pcpcount; /* pointer to pxp buffer */
181extern long _cntrs; /* number of counters */
182extern long _rtns; /* number of routine cntrs */
183\f
1e2b51bb
KM
184/*
185 * The file i/o routines maintain a notion of a "current file".
186 * A pointer to this file structure is kept in "curfile".
187 *
188 * file structures
189 */
190struct iorechd {
191 char *fileptr; /* ptr to file window */
192 long lcount; /* number of lines printed */
193 long llimit; /* maximum number of text lines */
194 FILE *fbuf; /* FILE ptr */
195 struct iorec *fchain; /* chain to next file */
196 struct iorec *flev; /* ptr to associated file variable */
197 char *pfname; /* ptr to name of file */
198 short funit; /* file status flags */
199 short fblk; /* index into active file table */
200 long fsize; /* size of elements in the file */
201 char fname[NAMSIZ]; /* name of associated UNIX file */
202};
203
204struct iorec {
205 char *fileptr; /* ptr to file window */
206 long lcount; /* number of lines printed */
207 long llimit; /* maximum number of text lines */
208 FILE *fbuf; /* FILE ptr */
209 struct iorec *fchain; /* chain to next file */
210 struct iorec *flev; /* ptr to associated file variable */
211 char *pfname; /* ptr to name of file */
212 short funit; /* file status flags */
213 short fblk; /* index into active file table */
214 long fsize; /* size of elements in the file */
215 char fname[NAMSIZ]; /* name of associated UNIX file */
216 char buf[BUFSIZ]; /* I/O buffer */
217 char window[1]; /* file window element */
218};
15834a19 219\f
1e2b51bb
KM
220/*
221 * unit flags
222 */
223#define FDEF 0x80 /* 1 => reserved file name */
224#define FTEXT 0x40 /* 1 => text file, process EOLN */
225#define FWRITE 0x20 /* 1 => open for writing */
226#define FREAD 0x10 /* 1 => open for reading */
227#define TEMP 0x08 /* 1 => temporary file */
228#define SYNC 0x04 /* 1 => window is out of sync */
229#define EOLN 0x02 /* 1 => at end of line */
230#define EOFF 0x01 /* 1 => at end of file */
231
232/*
233 * file routines
234 */
235extern struct iorec *GETNAME();
236extern char *MKTEMP();
237
238/*
239 * file record variables
240 */
241extern struct iorechd _fchain; /* head of active file chain */
242extern struct iorec *_actfile[]; /* table of active files */
243extern long _filefre; /* last used entry in _actfile */
244
245/*
246 * standard files
247 */
248extern struct iorechd input;
249extern struct iorechd output;
250extern struct iorechd _err;
15834a19 251
1e2b51bb 252/*
15834a19 253 * Px execution profile array
1e2b51bb 254 */
15834a19
KM
255#ifdef PROFILE
256#define NUMOPS 256
257extern long _profcnts[NUMOPS];
258#endif PROFILE