@@ -41,11 +41,6 @@ is resumed first.
41
41
42
42
The handlers are CPS-transformed functions: they actually take an
43
43
additional parameter which is the current low-level continuation.
44
-
45
- Effect and exception handlers are CPS, single-version functions, meaning that
46
- they are ordinary functions, unlike CPS-transformed functions which, if double
47
- translation is enabled, exist in both direct style and continuation-passing
48
- style. Low-level continuations are also ordinary functions.
49
44
*/
50
45
51
46
//Provides: caml_exn_stack
@@ -92,12 +87,30 @@ function caml_raise_unhandled(eff) {
92
87
//Provides: uncaught_effect_handler
93
88
//Requires: caml_resume_stack, caml_raise_unhandled
94
89
//If: effects
90
+ //If: !doubletranslate
95
91
function uncaught_effect_handler ( eff , k , ms ) {
96
92
// Resumes the continuation k by raising exception Unhandled.
97
93
caml_resume_stack ( k [ 1 ] , ms ) ;
98
94
caml_raise_unhandled ( eff ) ;
99
95
}
100
96
97
+ //Provides: uncaught_effect_handler_cps
98
+ //Requires: caml_resume_stack, caml_raise_unhandled
99
+ //If: effects
100
+ //If: doubletranslate
101
+ function uncaught_effect_handler_cps ( eff , k , ms , cont ) {
102
+ // Resumes the continuation k by raising exception Unhandled.
103
+ caml_resume_stack ( k [ 1 ] , ms ) ;
104
+ caml_raise_unhandled ( eff ) ;
105
+ }
106
+
107
+ //Provides: uncaught_effect_handler
108
+ //Requires: uncaught_effect_handler_cps
109
+ //If: effects
110
+ //If: doubletranslate
111
+ //Weakdef
112
+ var uncaught_effect_handler = { cps : uncaught_effect_handler_cps } ;
113
+
101
114
//Provides: caml_fiber_stack
102
115
//If: effects
103
116
// This has the shape {h, r:{k, x, e}} where h is a triple of handlers
@@ -149,22 +162,8 @@ function caml_pop_fiber() {
149
162
return rem . k ;
150
163
}
151
164
152
- //Provides: caml_prepare_tramp
153
- //If: effects
154
- //If: !doubletranslate
155
- function caml_prepare_tramp ( handler ) {
156
- return handler ;
157
- }
158
-
159
- //Provides: caml_prepare_tramp
160
- //If: effects
161
- //If: doubletranslate
162
- function caml_prepare_tramp ( handler ) {
163
- return { cps : handler } ;
164
- }
165
-
166
165
//Provides: caml_perform_effect
167
- //Requires: caml_pop_fiber, caml_stack_check_depth, caml_trampoline_return, caml_exn_stack, caml_fiber_stack, caml_prepare_tramp
166
+ //Requires: caml_pop_fiber, caml_stack_check_depth, caml_trampoline_return, caml_exn_stack, caml_fiber_stack, caml_get_cps_fun
168
167
//If: effects
169
168
function caml_perform_effect ( eff , cont , k0 ) {
170
169
// Allocate a continuation if we don't already have one
@@ -178,50 +177,34 @@ function caml_perform_effect(eff, cont, k0) {
178
177
// The handler is defined in Stdlib.Effect, so we know that the arity matches
179
178
var k1 = caml_pop_fiber ( ) ;
180
179
return caml_stack_check_depth ( )
181
- ? handler ( eff , cont , k1 , k1 )
182
- : caml_trampoline_return ( caml_prepare_tramp ( handler ) , [ eff , cont , k1 , k1 ] ) ;
183
- }
184
-
185
- //Provides: caml_call_fun
186
- //Requires: caml_call_gen
187
- //If: effects
188
- //If: !doubletranslate
189
- function caml_call_fun ( f , args ) {
190
- return caml_call_gen ( f , args ) ;
191
- }
192
-
193
- //Provides: caml_call_fun
194
- //Requires: caml_call_gen_cps
195
- //If: effects
196
- //If: doubletranslate
197
- function caml_call_fun ( f , args ) {
198
- return caml_call_gen_cps ( f , args ) ;
180
+ ? ( caml_get_cps_fun ( handler ) ) ( eff , cont , k1 , k1 )
181
+ : caml_trampoline_return ( handler , [ eff , cont , k1 , k1 ] ) ;
199
182
}
200
183
201
- //Provides: caml_get_fun
184
+ //Provides: caml_get_cps_fun
202
185
//If: effects
203
186
//If: !doubletranslate
204
- function caml_get_fun ( f ) {
187
+ function caml_get_cps_fun ( f ) {
205
188
return f ;
206
189
}
207
190
208
- //Provides: caml_get_fun
191
+ //Provides: caml_get_cps_fun
209
192
//If: effects
210
193
//If: doubletranslate
211
- function caml_get_fun ( f ) {
194
+ function caml_get_cps_fun ( f ) {
212
195
return f . cps ;
213
196
}
214
197
215
198
//Provides: caml_alloc_stack
216
- //Requires: caml_pop_fiber, caml_fiber_stack, caml_stack_check_depth, caml_trampoline_return, caml_call_fun, caml_get_fun
199
+ //Requires: caml_pop_fiber, caml_fiber_stack, caml_stack_check_depth, caml_trampoline_return, caml_call_gen_cps
217
200
//If: effects
218
201
//Version: >= 5.0
219
202
function caml_alloc_stack ( hv , hx , hf ) {
220
203
function call ( i , x ) {
221
204
var f = caml_fiber_stack . h [ i ] ;
222
205
var args = [ x , caml_pop_fiber ( ) ] ;
223
206
return caml_stack_check_depth ( )
224
- ? caml_call_fun ( f , args )
207
+ ? caml_call_gen_cps ( f , args )
225
208
: caml_trampoline_return ( f , args ) ;
226
209
}
227
210
function hval ( x ) {
@@ -232,7 +215,7 @@ function caml_alloc_stack(hv, hx, hf) {
232
215
// Call [hx] in the parent fiber
233
216
return call ( 2 , e ) ;
234
217
}
235
- return [ 0 , hval , [ 0 , hexn , 0 ] , [ 0 , hv , hx , caml_get_fun ( hf ) ] , 0 ] ;
218
+ return [ 0 , hval , [ 0 , hexn , 0 ] , [ 0 , hv , hx , hf ] , 0 ] ;
236
219
}
237
220
238
221
//Provides: caml_alloc_stack
0 commit comments