@@ -134,18 +134,12 @@ function caml_make_unhandled_effect_exn(eff) {
134134//Provides: caml_perform_effect
135135//Requires: caml_pop_fiber, caml_stack_check_depth, caml_trampoline_return, caml_fiber_stack
136136//Requires: caml_make_unhandled_effect_exn, caml_current_stack
137- //Requires: caml_resume_stack, caml_continuation_use_noexc
138137//If: effects
139138//Version: >= 5.0
140- function caml_perform_effect ( eff , cont , last , k0 ) {
139+ function caml_perform_effect ( eff , k0 ) {
141140 if ( caml_fiber_stack === 0 ) {
142141 var exn = caml_make_unhandled_effect_exn ( eff ) ;
143- if ( ! cont ) throw exn ;
144- else {
145- var stack = caml_continuation_use_noexc ( cont ) ;
146- caml_resume_stack ( stack , last , k0 ) ;
147- throw exn ;
148- }
142+ throw exn ;
149143 }
150144 // Get current effect handler
151145 var handler = caml_current_stack . h [ 3 ] ;
@@ -155,13 +149,34 @@ function caml_perform_effect(eff, cont, last, k0) {
155149 // Move to parent fiber and execute the effect handler there
156150 // The handler is defined in Stdlib.Effect, so we know that the arity matches
157151 var k1 = caml_pop_fiber ( ) ;
158- if ( ! cont ) {
159- //Perform
160- cont = [ 245 /*continuation*/ , last_fiber , 0 ] ;
161- } else {
162- //Reperform
163- last . e = last_fiber ;
152+ var cont = [ 245 /*continuation*/ , last_fiber , 0 ] ;
153+ return caml_stack_check_depth ( )
154+ ? handler ( eff , cont , last_fiber , k1 )
155+ : caml_trampoline_return ( handler , [ eff , cont , last_fiber , k1 ] ) ;
156+ }
157+
158+ //Provides: caml_reperform_effect
159+ //Requires: caml_pop_fiber, caml_stack_check_depth, caml_trampoline_return, caml_fiber_stack
160+ //Requires: caml_make_unhandled_effect_exn, caml_current_stack
161+ //Requires: caml_resume_stack, caml_continuation_use_noexc
162+ //If: effects
163+ //Version: >= 5.0
164+ function caml_reperform_effect ( eff , cont , last , k0 ) {
165+ if ( caml_fiber_stack === 0 ) {
166+ var exn = caml_make_unhandled_effect_exn ( eff ) ;
167+ var stack = caml_continuation_use_noexc ( cont ) ;
168+ caml_resume_stack ( stack , last , k0 ) ;
169+ throw exn ;
164170 }
171+ // Get current effect handler
172+ var handler = caml_current_stack . h [ 3 ] ;
173+ var last_fiber = caml_current_stack ;
174+ last_fiber . k = k0 ;
175+ last_fiber . e = 0 ;
176+ // Move to parent fiber and execute the effect handler there
177+ // The handler is defined in Stdlib.Effect, so we know that the arity matches
178+ var k1 = caml_pop_fiber ( ) ;
179+ last . e = last_fiber ;
165180 return caml_stack_check_depth ( )
166181 ? handler ( eff , cont , last_fiber , k1 )
167182 : caml_trampoline_return ( handler , [ eff , cont , last_fiber , k1 ] ) ;
0 commit comments