Commit | Line | Data |
---|---|---|
484cb0ef CH |
1 | # |
2 | /* | |
3 | * px - Berkeley Pascal interpreter | |
4 | * | |
5 | * Version 2.0, January 1979 | |
6 | * | |
7 | * Original version by Ken Thompson | |
8 | * | |
9 | * Substantial revisions by Bill Joy and Chuck Haley | |
10 | * November-December 1976 | |
11 | * | |
12 | * Rewritten for VAX 11/780 by Kirk McKusick | |
13 | * Fall 1978 | |
14 | * | |
15 | * Px is described in detail in the "PX 1.0 Implementation Notes" | |
16 | * The source code for px is in several major pieces: | |
17 | * | |
18 | * int.c C main program which reads in interpreter code | |
19 | * 00case.s Driver including main interpreter loop | |
20 | * dd*.s Where dd are digits, interpreter instructions | |
21 | * grouped by their positions in the interpreter table. | |
22 | * p*.c Various C language routines supporting the system. | |
23 | * | |
24 | * In addition there are several headers defining mappings for error | |
25 | * messages names into codes, and a definition of the interpreter transfer | |
26 | * table. These are made by the script Emake in this directory and the scripts | |
27 | * in the directory '../opcodes'. | |
28 | */ | |
29 | ||
30 | long argc; | |
31 | char **argv; | |
32 | ||
33 | /* | |
34 | * Pascal runtime errors transfer to the routine | |
35 | * 'error' in the file perror.c to decode them. | |
36 | */ | |
37 | int perrno; /* number of error which occurred */ | |
38 | ||
39 | /* | |
40 | * Definitions for memory allocation | |
41 | * Memory allocation is done by palloc in utilities.c | |
42 | */ | |
43 | ||
44 | /* | |
45 | * The file i/o routines maintain a notion of a "current file". | |
46 | * The printing name of this file is kept in the variable | |
47 | * "file" for use in error messages. | |
48 | */ | |
49 | char *file; /* ptr to active file name */ | |
50 | long fchain; /* head of active file chain */ | |
51 | int bufopt; /* controls flushing of std output as follows: | |
52 | * 0 => flush on every write | |
53 | * 1 => flush before std read or at end of line | |
54 | * 2 => normal buffering | |
55 | */ | |
56 | /* | |
57 | * THE RUNTIME DISPLAY | |
58 | * | |
59 | * The entries in the display point to the active static block marks. | |
60 | * The first entry in the display is for the global variables, | |
61 | * then the procedure or function at level one, etc. | |
62 | * Each display entry points to a stack frame as shown: | |
63 | * | |
64 | * base of stack frame | |
65 | * --------------- | |
66 | * | | | |
67 | * | block mark | | |
68 | * | | | |
69 | * --------------- <-- display entry points here | |
70 | * | | | |
71 | * | local | | |
72 | * | variables | | |
73 | * | | | |
74 | * --------------- | |
75 | * | | | |
76 | * | expression | | |
77 | * | temporary | | |
78 | * | storage | | |
79 | * | | | |
80 | * - - - - - - - - | |
81 | * | |
82 | * The information in the block mark is thus at positive offsets from | |
83 | * the display pointer entries while the local variables are at negative | |
84 | * offsets. The block mark actually consists of two parts. The first | |
85 | * part is created at CALL and the second at entry, i.e. BEGIN. Thus: | |
86 | * | |
87 | * ------------------------- | |
88 | * | | | |
89 | * | Saved lino | | |
90 | * | Saved lc | | |
91 | * | Saved dp | | |
92 | * | | | |
93 | * ------------------------- | |
94 | * | | | |
95 | * | Saved (dp) | | |
96 | * | | | |
97 | * | Current section name | | |
98 | * | and entry line ptr | | |
99 | * | | | |
100 | * | Saved file name and | | |
101 | * | file buffer ptr | | |
102 | * | | | |
103 | * | Empty tos value | | |
104 | * | | | |
105 | * ------------------------- | |
106 | */ | |
107 | \f | |
108 | /* | |
109 | * Structure for accessing things in the block mark | |
110 | */ | |
111 | struct stack { | |
112 | long *tos; /* pointer to top of stack frame */ | |
113 | char *file; /* pointer to active file name */ | |
114 | long buf; /* pointer to active file record */ | |
115 | struct { | |
116 | char name[8];/* name of active procedure */ | |
117 | short offset; /* offset of procedure in source file */ | |
118 | } *entry; | |
119 | struct stack *disp; /* previous display value for this level */ | |
120 | struct stack **dp; /* pointer to active display entry */ | |
121 | long lc; /* previous location counter */ | |
122 | long lino; /* previous line number */ | |
123 | } *display[40]; | |
124 | ||
125 | long addrsze; /* size of display addresses */ | |
126 | ||
127 | ||
128 | /* | |
129 | * Program option variables | |
130 | */ | |
131 | long stcnt; /* number of statements executed */ | |
132 | long stlim; /* max number of statements to execute */ | |
133 | long llimit; /* max number of lines per text file */ | |
134 | short nodump; /* 1 => no post mortum dump */ | |
135 | short mode; /* mode of input to interpreter */ | |
136 | #define PX 0 /* normal run of px */ | |
137 | #define PIX 1 /* load and go */ | |
138 | #define PIPE 2 /* bootstrap via a pipe */ | |
139 | \f | |
140 | /* | |
141 | * Pxp variables | |
142 | */ | |
143 | char *pxpbuf; /* pointer to pxp buffer */ | |
144 | long pxpsize; /* size of pxp buffer */ | |
145 | ||
146 | #ifdef profile | |
147 | /* | |
148 | * Px execution profile data | |
149 | */ | |
150 | #define numops 256 | |
151 | struct cntrec { | |
152 | double counts[numops]; /* instruction counts */ | |
153 | long runs; /* number of interpreter runs */ | |
154 | long startdate; /* date profile started */ | |
155 | long usrtime; /* total user time consumed */ | |
156 | long systime; /* total system time consumed */ | |
157 | double stmts; /* number of pascal statements executed */ | |
158 | } profdata; | |
159 | long profcnts[numops]; | |
160 | #define proffile "/usr/ucb/pascal/px/pcnt.out" | |
161 | FILE *datafile; /* input datafiles */ | |
162 | #else | |
163 | int profcnts; /* dummy just to keep the linker happy */ | |
164 | #endif |