@@ -336,11 +336,11 @@ static obj eval_k(obj e) {
336336 // quote
337337 x = Mcadr (e );
338338 goto do_k ;
339- } else if (hd == Mcallwv_symbol ) {
340- // call-with-values
341- Mtc_cc (tc ) = Mcallwv_continuation (Mtc_cc (tc ), Mtc_env (tc ), Mcaddr (e ));
342- e = Mcadr (e );
343- goto loop ;
339+ // } else if (hd == Mcallwv_symbol) {
340+ // // call-with-values
341+ // Mtc_cc(tc) = Mcallwv_continuation(Mtc_cc(tc), Mtc_env(tc), Mcaddr(e));
342+ // e = Mcadr(e);
343+ // goto loop;
344344 } else {
345345 // application
346346 Mtc_cc (tc ) = Mapp_continuation (Mtc_cc (tc ), Mtc_env (tc ), e );
@@ -381,9 +381,14 @@ static obj eval_k(obj e) {
381381 Mtc_cc (tc ) = Mdynwind_continuation (Mtc_cc (tc ), Mtc_env (tc ), Mcar (args ), Mcadr (args ), Mcaddr (args ));
382382 x = Mvoid ;
383383 } else if (f == callcc_prim ) {
384+ check_callcc (Mcar (args ));
384385 continuation_set_immutable (Mtc_cc (tc )); // freeze the continuation chain
385386 Mtc_cc (tc ) = Mcallcc_continuation (Mtc_cc (tc ), Mtc_env (tc ), Mtc_wnd (tc ));
386387 x = Mcar (args );
388+ } else if (f == callwv_prim ) {
389+ assert_thunk ("call-with-values" , Mcar (args ));
390+ Mtc_cc (tc ) = Mcallwv_continuation (Mtc_cc (tc ), Mtc_env (tc ), Mcar (args ), Mcadr (args ));
391+ x = Mvoid ;
387392 } else {
388393 x = do_prim (f , args );
389394 }
@@ -462,9 +467,6 @@ static obj eval_k(obj e) {
462467 goto do_k ;
463468 } else {
464469 // capturing current continuation
465- assert_single_value (Mtc_cc (tc ), x );
466- check_callcc (x );
467-
468470 Mtc_cc (tc ) = continuation_mutable (Mtc_cc (tc ));
469471 Mcontinuation_capturedp (Mtc_cc (tc )) = 1 ;
470472
@@ -478,27 +480,13 @@ static obj eval_k(obj e) {
478480 // call-with-values expressions
479481 case CALLWV_CONT_TYPE :
480482 Mtc_cc (tc ) = continuation_mutable (Mtc_cc (tc ));
481- if (Mfalsep (Mcontinuation_callwv_producer (Mtc_cc (tc )))) {
482- // evaluated producer syntax
483- assert_single_value (Mtc_cc (tc ), x );
484- assert_thunk ("call-with-values" , x );
485-
486- Mcontinuation_callwv_producer (Mtc_cc (tc )) = x ;
487- e = Mcontinuation_callwv_consumer (Mtc_cc (tc ));
488- Mtc_env (tc ) = Mcontinuation_env (Mtc_cc (tc ));
489- goto loop ;
490- } else if (!Mprocp (Mcontinuation_callwv_consumer (Mtc_cc (tc )))) {
491- // evaluated consumer syntax
492- assert_single_value (Mtc_cc (tc ), x );
493- if (!Mprocp (x )) {
494- minim_error1 ("call-with-values" , "expected a procedure" , x );
495- }
496-
497- Mcontinuation_callwv_consumer (Mtc_cc (tc )) = x ;
483+ if (Mprocp (Mcontinuation_callwv_producer (Mtc_cc (tc )))) {
484+ // first time => evaluate producer
498485 f = Mcontinuation_callwv_producer (Mtc_cc (tc ));
499486 args = Mnull ;
500487
501488 Mtc_env (tc ) = Mcontinuation_env (Mtc_cc (tc ));
489+ Mcontinuation_callwv_producer (Mtc_cc (tc )) = Mfalse ;
502490 goto do_app ;
503491 } else {
504492 // evaluated producer procedure
0 commit comments