@@ -11,7 +11,7 @@ argument. Its stack of exception handlers is stored in
1111Exception handlers are pushed into this stack
1212when entering a [try ... with ...] and popped on exit.
1313Handlers are stored in [caml_current_stack.h]
14- and the remaining fibers are stored in [caml_fiber_stack ].
14+ and the remaining fibers are stored in [caml_current_stack.e ].
1515To install an effect handler, we push a new fiber into the execution context.
1616
1717We have basically the following type for reified continuations (type
@@ -47,7 +47,12 @@ additional parameter which is the current low-level continuation.
4747
4848//Provides: caml_current_stack
4949//If: effects
50- var caml_current_stack = { } ;
50+ // This has the shape {k, x, h, e} where
51+ // - h is a triple of handlers (see effect.ml)
52+ // - k is the low level continuation
53+ // - x is the exception stack
54+ // - e is the fiber stack of the parent fiber.
55+ var caml_current_stack = { k :0 , x :0 , h :0 , e :0 } ;
5156
5257//Provides: caml_push_trap
5358//Requires: caml_current_stack
@@ -69,17 +74,8 @@ function caml_pop_trap() {
6974 return h ;
7075}
7176
72- //Provides: caml_fiber_stack
73- //If: effects
74- // This has the shape {k, x, h, e} where
75- // - h is a triple of handlers (see effect.ml)
76- // - k is the low level continuation
77- // - x is the exception stack
78- // - e is the fiber stack of the parent fiber.
79- var caml_fiber_stack = 0 ;
80-
8177//Provides:caml_resume_stack
82- //Requires: caml_named_value, caml_raise_constant, caml_fiber_stack
78+ //Requires: caml_named_value, caml_raise_constant
8379//Requires: caml_pop_fiber, caml_current_stack
8480//If: effects
8581//Version: >= 5.0
@@ -93,24 +89,21 @@ function caml_resume_stack(stack, last, k) {
9389 // Pre OCaml 5.2, last/cont[2] was not populated.
9490 while ( last . e !== 0 ) last = last . e ;
9591 }
96- var fiber = caml_current_stack ;
97- fiber . k = k ;
98- fiber . e = caml_fiber_stack ;
99- last . e = fiber ;
100- caml_fiber_stack = stack ;
101- return caml_pop_fiber ( ) ;
92+ caml_current_stack . k = k ;
93+ last . e = caml_current_stack ;
94+ caml_current_stack = stack ;
95+ return stack . k ;
10296}
10397
10498//Provides: caml_pop_fiber
105- //Requires: caml_current_stack, caml_fiber_stack
99+ //Requires: caml_current_stack
106100//If: effects
107101//Version: >= 5.0
108102function caml_pop_fiber ( ) {
109103 // Move to the parent fiber, returning the parent's low-level continuation
110- var c = caml_fiber_stack ;
111- caml_current_stack = c ;
112- caml_fiber_stack = c . e ;
104+ var c = caml_current_stack . e ;
113105 caml_current_stack . e = 0 ;
106+ caml_current_stack = c ;
114107 return c . k ;
115108}
116109
@@ -132,12 +125,12 @@ function caml_make_unhandled_effect_exn(eff) {
132125}
133126
134127//Provides: caml_perform_effect
135- //Requires: caml_pop_fiber, caml_stack_check_depth, caml_trampoline_return, caml_fiber_stack
128+ //Requires: caml_pop_fiber, caml_stack_check_depth, caml_trampoline_return
136129//Requires: caml_make_unhandled_effect_exn, caml_current_stack
137130//If: effects
138131//Version: >= 5.0
139132function caml_perform_effect ( eff , k0 ) {
140- if ( caml_fiber_stack === 0 ) {
133+ if ( caml_current_stack . e === 0 ) {
141134 var exn = caml_make_unhandled_effect_exn ( eff ) ;
142135 throw exn ;
143136 }
@@ -155,13 +148,13 @@ function caml_perform_effect(eff, k0) {
155148}
156149
157150//Provides: caml_reperform_effect
158- //Requires: caml_pop_fiber, caml_stack_check_depth, caml_trampoline_return, caml_fiber_stack
151+ //Requires: caml_pop_fiber, caml_stack_check_depth, caml_trampoline_return
159152//Requires: caml_make_unhandled_effect_exn, caml_current_stack
160153//Requires: caml_resume_stack, caml_continuation_use_noexc
161154//If: effects
162155//Version: >= 5.0
163156function caml_reperform_effect ( eff , cont , last , k0 ) {
164- if ( caml_fiber_stack === 0 ) {
157+ if ( caml_current_stack . e === 0 ) {
165158 var exn = caml_make_unhandled_effect_exn ( eff ) ;
166159 var stack = caml_continuation_use_noexc ( cont ) ;
167160 caml_resume_stack ( stack , last , k0 ) ;
0 commit comments