13
13
14
14
#define AREA "ECEVAL"
15
15
16
- enum reg { ARGL , CONT , ENV , EXPR , PROC , STACK , UNEV , VAL };
17
-
18
16
static obj argl ; // 1
19
17
static obj cont ; // 2
20
18
static obj env ; // 3
@@ -26,7 +24,8 @@ static obj val; // 8
26
24
// Plus... the_global_environment // 9
27
25
obj anenv ; // 10
28
26
obj ambenv ; // 11
29
- const int rootlen = 11 ;
27
+ obj savetmp ; // 12
28
+ const int rootlen = 12 ;
30
29
static obj rootlst ;
31
30
32
31
// ln 182
@@ -58,50 +57,11 @@ static void timed_eval(obj start)
58
57
displaydat (of_string ("s ] " ));
59
58
}
60
59
61
- static void save (enum reg reg )
60
+ static void save (obj val )
62
61
{
63
- // Why use an enum? Why not just pass the obj to save as an argument?
64
- //
65
- // Because the call to newpair (below) allows garbage collection.
66
- //
67
- // So? The argument obj wouldn't be reachable from the GC 'root' list.
68
- //
69
- // So? If the arg(ument) is a pointer to a pair (i.e., is_pair), and a
70
- // collection occurs, then the arg's pointer will not be updated
71
- // because the garbage collector doesn't know about it.
72
- //
73
- // So? The arg would still point to the pair's original location (now a
74
- // 'broken heart') and not to the pair's new location.
75
- //
76
- // Oh! That's right, you just avoided putting corrupt data on the stack!
77
- //
78
-
79
- switch (reg ) {
80
- case ARGL :
81
- stack = consgc (& argl , & stack );
82
- break ;
83
- case CONT :
84
- stack = consgc (& cont , & stack );
85
- break ;
86
- case ENV :
87
- stack = consgc (& env , & stack );
88
- break ;
89
- case EXPR :
90
- stack = consgc (& expr , & stack );
91
- break ;
92
- case PROC :
93
- stack = consgc (& proc , & stack );
94
- break ;
95
- case STACK :
96
- stack = consgc (& stack , & stack );
97
- break ;
98
- case UNEV :
99
- stack = consgc (& unev , & stack );
100
- break ;
101
- case VAL :
102
- stack = consgc (& val , & stack );
103
- break ;
104
- }
62
+ savetmp = val ;
63
+ stack = consgc (& savetmp , & stack );
64
+
105
65
if (is_err (stack )) {
106
66
eprintf (AREA , "Halting - Reached Memory Limit" );
107
67
exit (1 );
@@ -129,7 +89,7 @@ obj getroot(void)
129
89
130
90
// intentionally not using rootlen here, change number manually after
131
91
// modifying body below.
132
- if ((actlen = length_u (rootlst )) != 11 ) {
92
+ if ((actlen = length_u (rootlst )) != 12 ) {
133
93
error_internal (
134
94
AREA ,
135
95
"Bug! getroot() got list of unexpected length: %d " ,
@@ -158,6 +118,8 @@ obj getroot(void)
158
118
set_car (lst , anenv );
159
119
lst = cdr (lst );
160
120
set_car (lst , ambenv );
121
+ lst = cdr (lst );
122
+ set_car (lst , savetmp );
161
123
162
124
return rootlst ;
163
125
}
@@ -170,7 +132,7 @@ obj setroot(obj rlst)
170
132
171
133
// intentionally not using rootlen here, change number manually after
172
134
// modifying body below.
173
- if ((actlen = length_u (rootlst )) != 11 ) {
135
+ if ((actlen = length_u (rootlst )) != 12 ) {
174
136
return error_internal (
175
137
AREA ,
176
138
"Bug! setroot() got list of unexpected length: %d" ,
@@ -198,6 +160,8 @@ obj setroot(obj rlst)
198
160
anenv = car (lst );
199
161
lst = cdr (lst );
200
162
ambenv = car (lst );
163
+ lst = cdr (lst );
164
+ savetmp = car (lst );
201
165
202
166
return unspecified ;
203
167
}
@@ -219,7 +183,7 @@ static obj init(void)
219
183
220
184
stack = emptylst ;
221
185
// preallocate storage for gc root
222
- rootlst = listn (11 , // <----- actual length
186
+ rootlst = listn (12 , // <----- actual length
223
187
unspecified , // 1
224
188
unspecified , // 2
225
189
unspecified , // 3
@@ -230,7 +194,8 @@ static obj init(void)
230
194
unspecified , // 8
231
195
unspecified , // 9
232
196
unspecified , // 10
233
- unspecified // 11
197
+ unspecified , // 11
198
+ unspecified // 12
234
199
);
235
200
if ((actlen = length_u (rootlst )) != rootlen ) {
236
201
error_internal (
@@ -331,10 +296,10 @@ obj eceval(obj expression, obj _environment)
331
296
332
297
// ln 277
333
298
ev_application :
334
- save (CONT );
335
- save (ENV );
299
+ save (cont );
300
+ save (env );
336
301
unev = operands (expr );
337
- save (UNEV );
302
+ save (unev );
338
303
expr = operator (expr );
339
304
set_proc_name ();
340
305
cont = ev_appl_did_operator ;
@@ -350,16 +315,16 @@ obj eceval(obj expression, obj _environment)
350
315
return proc ;
351
316
if (no_operands (unev ))
352
317
goto apply_dispatch ;
353
- save (PROC );
318
+ save (proc );
354
319
355
320
// ln 295
356
321
ev_appl_operand_loop :
357
- save (ARGL );
322
+ save (argl );
358
323
expr = first_operand (unev );
359
324
if (is_last_operand (unev ))
360
325
goto ev_appl_last_arg ;
361
- save (ENV );
362
- save (UNEV );
326
+ save (env );
327
+ save (unev );
363
328
cont = ev_appl_accumulate_arg ;
364
329
goto eval_dispatch ;
365
330
@@ -403,7 +368,7 @@ obj eceval(obj expression, obj _environment)
403
368
// ln 348
404
369
ev_begin :
405
370
unev = begin_actions (expr );
406
- save (CONT );
371
+ save (cont );
407
372
goto ev_sequence ;
408
373
409
374
// ln 338
@@ -423,8 +388,8 @@ obj eceval(obj expression, obj _environment)
423
388
expr = first_exp (unev );
424
389
if (is_last_exp (unev ))
425
390
goto ev_sequence_last_exp ;
426
- save (UNEV );
427
- save (ENV );
391
+ save (unev );
392
+ save (env );
428
393
cont = ev_sequence_continue ;
429
394
goto eval_dispatch ;
430
395
ev_sequence_continue :
@@ -440,9 +405,9 @@ obj eceval(obj expression, obj _environment)
440
405
441
406
// ln 374
442
407
ev_if :
443
- save (EXPR ); // save expression for later
444
- save (ENV );
445
- save (CONT );
408
+ save (expr ); // save expression for later
409
+ save (env );
410
+ save (cont );
446
411
cont = ev_if_decide ;
447
412
expr = if_predicate (expr );
448
413
goto eval_dispatch ; // evaluate the predicate
@@ -466,10 +431,10 @@ obj eceval(obj expression, obj _environment)
466
431
// ln 399
467
432
ev_assignment :
468
433
unev = assignment_variable (expr );
469
- save (UNEV ); // save variable for later
434
+ save (unev ); // save variable for later
470
435
expr = assignment_value (expr );
471
- save (ENV );
472
- save (CONT );
436
+ save (env );
437
+ save (cont );
473
438
cont = ev_assignment_1 ;
474
439
goto eval_dispatch ; // evaluate the assignment value
475
440
@@ -484,10 +449,10 @@ obj eceval(obj expression, obj _environment)
484
449
// ln 416
485
450
ev_definition :
486
451
unev = definition_variable (expr );
487
- save (UNEV ); // save variable for later
452
+ save (unev ); // save variable for later
488
453
expr = definition_value (expr );
489
- save (ENV );
490
- save (CONT );
454
+ save (env );
455
+ save (cont );
491
456
cont = ev_definition_1 ;
492
457
goto eval_dispatch ; // evaluate the definition value
493
458
ev_definition_1 :
@@ -538,10 +503,10 @@ obj eceval(obj expression, obj _environment)
538
503
539
504
// new
540
505
ev_timed :
541
- save (UNEV );
506
+ save (unev );
542
507
unev = runtime (emptylst );
543
- save (UNEV );
544
- save (CONT );
508
+ save (unev );
509
+ save (cont );
545
510
cont = ev_timed_done ;
546
511
expr = cons (begin , cdr (expr ));
547
512
goto eval_dispatch ;
@@ -555,10 +520,10 @@ obj eceval(obj expression, obj _environment)
555
520
556
521
// new
557
522
ev_apply :
558
- save (CONT );
559
- save (ENV );
523
+ save (cont );
524
+ save (env );
560
525
unev = apply_operands (expr );
561
- save (UNEV );
526
+ save (unev );
562
527
expr = apply_operator (expr );
563
528
cont = ev_apply_2 ;
564
529
goto eval_dispatch ;
@@ -567,8 +532,8 @@ obj eceval(obj expression, obj _environment)
567
532
unev = restore ();
568
533
env = restore ();
569
534
proc = val ;
570
- save (PROC );
571
- save (ENV );
535
+ save (proc );
536
+ save (env );
572
537
expr = unev ;
573
538
cont = ev_apply_3 ;
574
539
goto eval_dispatch ;
0 commit comments