16
16
17
17
#define AREA "ECEVAL"
18
18
19
+ static obj parallel_eval (obj actions , obj env );
19
20
static obj parallel_execute (obj actions , obj env );
20
21
21
22
// ln 182
@@ -136,8 +137,10 @@ static obj ecevalgoto(struct core *cr, bool yield)
136
137
goto ev_cons_stream ;
137
138
if (is_time (cr -> expr ))
138
139
goto ev_timed ;
140
+ if (is_parallel_eval (cr -> expr ))
141
+ goto ev_parallel_eval ;
139
142
if (is_parallel_execute (cr -> expr ))
140
- goto ev_concurrent_execute ;
143
+ goto ev_parallel_execute ;
141
144
if (is_ecapply (cr -> expr ))
142
145
goto ev_apply ;
143
146
if (is_application (cr -> expr ))
@@ -394,8 +397,16 @@ static obj ecevalgoto(struct core *cr, bool yield)
394
397
goto go_cont ;
395
398
396
399
// new
397
- ev_concurrent_execute :
398
- return parallel_execute (cdr (cr -> expr ), cr -> env );
400
+ ev_parallel_eval :
401
+ cr -> val = parallel_eval (cdr (cr -> expr ), cr -> env );
402
+ go_obj = cr -> cont ;
403
+ goto go_obj ;
404
+
405
+ ev_parallel_execute :
406
+ cr -> val = parallel_execute (cdr (cr -> expr ), cr -> env );
407
+ go_obj = cr -> cont ;
408
+ goto go_obj ;
409
+
399
410
// new
400
411
ev_apply :
401
412
save (cr -> cont , cr );
@@ -437,6 +448,7 @@ static obj ecevalgoto(struct core *cr, bool yield)
437
448
}
438
449
go_obj = cr -> cont ;
439
450
go_obj :
451
+ // printf("obj: %s\n", to_string(go_obj));
440
452
if (is_eq (go_obj , ev_return_caller ))
441
453
return cr -> val ;
442
454
if (is_eq (go_obj , ev_appl_accum_last_arg ))
@@ -477,15 +489,26 @@ obj eceval(obj expression, obj _environment)
477
489
return ecevalgoto (cr , false);
478
490
}
479
491
480
- static int rand_below (int n )
492
+ static obj parallel_execute (obj procs , obj env )
493
+ {
494
+ obj actions = emptylst ;
495
+
496
+ for (; is_pair (procs ); procs = cdr (procs )) {
497
+ actions = cons (list1 (car (procs )), actions );
498
+ }
499
+ return parallel_eval (actions , env );
500
+ }
501
+
502
+ static int rand_clicks (int n )
481
503
{
482
- return plat_rand () % n ;
504
+ Integer r = plat_rand ();
505
+ return ((r % 16 ) > 11 ) ? (r % n ) + 1 : 0 ;
483
506
}
484
507
485
- static obj parallel_execute (obj actions , obj env )
508
+ static obj parallel_eval (obj actions , obj env )
486
509
{
487
- static bool running [NCORE ];
488
- static int free = 0 ;
510
+ bool running [NCORE ];
511
+ int free = 0 ;
489
512
int i , j , runcount ;
490
513
491
514
while (is_pair (actions )) {
@@ -512,9 +535,10 @@ static obj parallel_execute(obj actions, obj env)
512
535
if (!running [i ]) {
513
536
continue ;
514
537
}
515
- int clicks = rand_below ( 32 );
538
+ int clicks = rand_clicks ( 2 );
516
539
for (j = 0 ; j < clicks ; j ++ ) {
517
- if (!is_yielded (ecevalgoto (getcore (i ), true))) {
540
+ obj r = ecevalgoto (getcore (i ), true);
541
+ if (!is_yielded (r )) {
518
542
running [i ] = false;
519
543
runcount -- ;
520
544
break ;
0 commit comments