9
9
#include "mceval.h"
10
10
#include "output.h"
11
11
#include "primproc.h"
12
+ #include "register.h"
12
13
#include "storage.h"
13
14
14
15
#define AREA "ECEVAL"
15
16
16
- struct core {
17
- obj argl ; // 1
18
- obj cont ; // 2
19
- obj env ; // 3
20
- obj expr ; // 4
21
- obj proc ; // 5
22
- obj stack ; // 6
23
- obj unev ; // 7
24
- obj val ; // 8
25
- } cre ;
26
- struct core * cr0 = & cre ;
27
-
28
- // the_global_environment // 9
29
- obj anenv ; // 10
30
- obj ambenv ; // 11
31
- obj savetmp ; // 12
32
-
33
- const int rootlen = 12 ;
34
- static obj rootlst ;
35
17
36
18
// ln 182
37
19
static obj empty_arglist (void )
@@ -87,89 +69,6 @@ static obj restore(struct core *cr)
87
69
}
88
70
89
71
// used for garbage collection
90
- obj getroot (void )
91
- {
92
- int actlen ;
93
- obj lst = rootlst ;
94
-
95
- // intentionally not using rootlen here, change number manually after
96
- // modifying body below.
97
- if ((actlen = length_u (rootlst )) != 12 ) {
98
- error_internal (
99
- AREA ,
100
- "Bug! getroot() got list of unexpected length: %d " ,
101
- actlen );
102
- exit (1 );
103
- }
104
- // order must match setroot
105
- set_car (lst , cr0 -> argl );
106
- lst = cdr (lst );
107
- set_car (lst , cr0 -> cont );
108
- lst = cdr (lst );
109
- set_car (lst , cr0 -> env );
110
- lst = cdr (lst );
111
- set_car (lst , cr0 -> expr );
112
- lst = cdr (lst );
113
- set_car (lst , cr0 -> proc );
114
- lst = cdr (lst );
115
- set_car (lst , cr0 -> stack );
116
- lst = cdr (lst );
117
- set_car (lst , cr0 -> unev );
118
- lst = cdr (lst );
119
- set_car (lst , cr0 -> val );
120
- lst = cdr (lst );
121
- set_car (lst , the_global_environment ());
122
- lst = cdr (lst );
123
- set_car (lst , anenv );
124
- lst = cdr (lst );
125
- set_car (lst , ambenv );
126
- lst = cdr (lst );
127
- set_car (lst , savetmp );
128
-
129
- return rootlst ;
130
- }
131
-
132
- // used for garbage collection
133
- obj setroot (obj rlst )
134
- {
135
- int actlen ;
136
- obj lst = rootlst = rlst ;
137
-
138
- // intentionally not using rootlen here, change number manually after
139
- // modifying body below.
140
- if ((actlen = length_u (rootlst )) != 12 ) {
141
- return error_internal (
142
- AREA ,
143
- "Bug! setroot() got list of unexpected length: %d" ,
144
- actlen );
145
- }
146
- // order must match getroot
147
- cr0 -> argl = car (lst );
148
- lst = cdr (lst );
149
- cr0 -> cont = car (lst );
150
- lst = cdr (lst );
151
- cr0 -> env = car (lst );
152
- lst = cdr (lst );
153
- cr0 -> expr = car (lst );
154
- lst = cdr (lst );
155
- cr0 -> proc = car (lst );
156
- lst = cdr (lst );
157
- cr0 -> stack = car (lst );
158
- lst = cdr (lst );
159
- cr0 -> unev = car (lst );
160
- lst = cdr (lst );
161
- cr0 -> val = car (lst );
162
- lst = cdr (lst );
163
- set_global_environment (car (lst ));
164
- lst = cdr (lst );
165
- anenv = car (lst );
166
- lst = cdr (lst );
167
- ambenv = car (lst );
168
- lst = cdr (lst );
169
- savetmp = car (lst );
170
-
171
- return unspecified ;
172
- }
173
72
174
73
static obj proc_name ;
175
74
static void set_proc_name (struct core * cr )
@@ -181,43 +80,8 @@ static void set_proc_name(struct core *cr)
181
80
of_string ("<unknown>" );
182
81
}
183
82
184
- static bool initdone = false;
185
- static obj init (void )
186
- {
187
- int actlen ;
188
-
189
- cr0 -> stack = emptylst ;
190
- // preallocate storage for gc root
191
- rootlst = listn (12 , // <----- actual length
192
- unspecified , // 1
193
- unspecified , // 2
194
- unspecified , // 3
195
- unspecified , // 4
196
- unspecified , // 5
197
- unspecified , // 6
198
- unspecified , // 7
199
- unspecified , // 8
200
- unspecified , // 9
201
- unspecified , // 10
202
- unspecified , // 11
203
- unspecified // 12
204
- );
205
- if ((actlen = length_u (rootlst )) != rootlen ) {
206
- error_internal (
207
- AREA ,
208
- "Bug! init, root wrong length. is: %d, expected %d" ,
209
- actlen , rootlen );
210
- exit (1 );
211
- }
212
- initdone = true;
213
- return unspecified ;
214
- }
215
-
216
83
static obj ecevalcr (obj expression , obj _environment , struct core * cr )
217
84
{
218
- if (!initdone ) {
219
- init ();
220
- }
221
85
cr -> expr = expression ;
222
86
cr -> env = _environment ;
223
87
cr -> cont = ev_return_caller ;
@@ -588,5 +452,5 @@ static obj ecevalcr(obj expression, obj _environment, struct core *cr)
588
452
589
453
obj eceval (obj expression , obj _environment )
590
454
{
591
- return ecevalcr (expression , _environment ,cr0 );
455
+ return ecevalcr (expression , _environment , dfltcore () );
592
456
}
0 commit comments