Skip to content

Commit 60af8f7

Browse files
vouillonhhugo
authored andcommitted
Update tests
1 parent 4c74025 commit 60af8f7

File tree

9 files changed

+2074
-2253
lines changed

9 files changed

+2074
-2253
lines changed

compiler/tests-compiler/direct_calls.ml

Lines changed: 25 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -56,46 +56,22 @@ let%expect_test "direct calls without --effects=cps" =
5656
print_fun_decl code (Some "test4");
5757
[%expect
5858
{|
59-
function test1(param){
60-
function f(g, x){
61-
try{caml_call1(g, x); return;}
62-
catch(e$0){
63-
var e = caml_wrap_exception(e$0);
64-
throw caml_maybe_attach_backtrace(e, 0);
65-
}
66-
}
67-
f(function(x){return x + 1 | 0;}, 7);
68-
f(function(x){return x * 2.;}, 4.);
69-
return 0;
70-
}
59+
function test1(param){return 0;}
7160
//end
7261
function test2(param){
73-
function f(g, x){
74-
try{caml_call1(g, x); return;}
75-
catch(e$0){
76-
var e = caml_wrap_exception(e$0);
77-
throw caml_maybe_attach_backtrace(e, 0);
78-
}
62+
try{caml_call2(Stdlib[28], x, cst_a);}
63+
catch(e$0){
64+
var e = caml_wrap_exception(e$0);
65+
throw caml_maybe_attach_backtrace(e, 0);
7966
}
80-
f(function(x){return x + 1 | 0;}, 7);
81-
f(function(x){return caml_call2(Stdlib[28], x, cst_a$0);}, cst_a);
8267
return 0;
8368
}
8469
//end
85-
function test3(x){
86-
function F(symbol){function f(x){return x + 1 | 0;} return [0, f];}
87-
var M1 = F([0]), M2 = F([0]), _b_ = M2[1].call(null, 2);
88-
return [0, M1[1].call(null, 1), _b_];
89-
}
70+
function test3(x){return [0, 2, 3];}
9071
//end
9172
function test4(x){
92-
function F(symbol){
93-
function f(x){return caml_call2(Stdlib_Printf[2], _a_, x);}
94-
return [0, f];
95-
}
96-
var M1 = F([0]), M2 = F([0]);
97-
M1[1].call(null, 1);
98-
return M2[1].call(null, 2);
73+
caml_call2(Stdlib_Printf[2], _a_, 1);
74+
return caml_call2(Stdlib_Printf[2], _a_, 2);
9975
}
10076
//end |}]
10177

@@ -138,64 +114,30 @@ let%expect_test "direct calls with --effects=cps" =
138114
print_fun_decl code (Some "test4");
139115
[%expect
140116
{|
141-
function test1(param, cont){
142-
function f(g, x){
143-
try{g(); return;}
144-
catch(e$0){
145-
var e = caml_wrap_exception(e$0);
146-
throw caml_maybe_attach_backtrace(e, 0);
147-
}
148-
}
149-
f(function(x){});
150-
f(function(x){});
151-
return cont(0);
152-
}
117+
function test1(param, cont){return cont(0);}
153118
//end
154119
function test2(param, cont){
155-
function f(g, x, cont){
156-
runtime.caml_push_trap
157-
(function(e){
158-
var raise = caml_pop_trap(), e$0 = caml_maybe_attach_backtrace(e, 0);
159-
return raise(e$0);
160-
});
161-
return caml_exact_trampoline_cps_call
162-
(g, x, function(_t_){caml_pop_trap(); return cont();});
163-
}
164-
return caml_exact_trampoline_cps_call$0
165-
(f,
166-
function(x, cont){return cont();},
167-
7,
168-
function(_r_){
169-
return caml_exact_trampoline_cps_call$0
170-
(f,
171-
function(x, cont){
172-
return caml_trampoline_cps_call3
173-
(Stdlib[28], x, cst_a$0, cont);
174-
},
175-
cst_a,
176-
function(_s_){return cont(0);});
177-
});
120+
runtime.caml_push_trap
121+
(function(e){
122+
var raise = caml_pop_trap(), e$0 = caml_maybe_attach_backtrace(e, 0);
123+
return raise(e$0);
124+
});
125+
return caml_trampoline_cps_call3
126+
(Stdlib[28],
127+
x,
128+
cst_a,
129+
function(_g_){caml_pop_trap(); return cont(0);});
178130
}
179131
//end
180-
function test3(x, cont){
181-
function F(symbol){function f(x){return x + 1 | 0;} return [0, f];}
182-
var M1 = F(), M2 = F(), _q_ = M2[1].call(null, 2);
183-
return cont([0, M1[1].call(null, 1), _q_]);
184-
}
132+
function test3(x, cont){return cont([0, 2, 3]);}
185133
//end
186134
function test4(x, cont){
187-
function F(symbol){
188-
function f(x, cont){
189-
return caml_trampoline_cps_call3(Stdlib_Printf[2], _o_, x, cont);
190-
}
191-
return [0, f];
192-
}
193-
var M1 = F(), M2 = F();
194-
return caml_exact_trampoline_cps_call
195-
(M1[1],
135+
return caml_trampoline_cps_call3
136+
(Stdlib_Printf[2],
137+
_e_,
196138
1,
197-
function(_p_){
198-
return caml_exact_trampoline_cps_call(M2[1], 2, cont);
139+
function(_f_){
140+
return caml_trampoline_cps_call3(Stdlib_Printf[2], _e_, 2, cont);
199141
});
200142
}
201143
//end

compiler/tests-compiler/double-translation/direct_calls.ml

Lines changed: 34 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -121,103 +121,47 @@ let%expect_test "direct calls with --effects=double-translation" =
121121
: runtime.caml_call_gen(f, [a0, a1]))
122122
: runtime.caml_trampoline_return(f, [a0, a1, a2], 0);
123123
}
124-
function caml_exact_trampoline_cps_call$0(f, a0, a1, a2){
125-
return runtime.caml_stack_check_depth()
126-
? f.cps ? f.cps.call(null, a0, a1, a2) : a2(f(a0, a1))
127-
: runtime.caml_trampoline_return(f, [a0, a1, a2], 0);
128-
}
129124
var
130-
dummy = 0,
131125
global_data = runtime.caml_get_global_data(),
132-
_z_ = [0, [4, 0, 0, 0, 0], caml_string_of_jsbytes("%d")],
133-
cst_a$0 = caml_string_of_jsbytes("a"),
126+
_k_ = [0, [4, 0, 0, 0, 0], caml_string_of_jsbytes("%d")],
134127
cst_a = caml_string_of_jsbytes("a"),
128+
x = caml_string_of_jsbytes("a"),
135129
Stdlib = global_data.Stdlib,
136130
Stdlib_Printf = global_data.Stdlib__Printf;
137-
function test1(param){
138-
function f(g, x){
139-
try{caml_call1(g, dummy); return;}
140-
catch(e$0){
141-
var e = caml_wrap_exception(e$0);
142-
throw caml_maybe_attach_backtrace(e, 0);
143-
}
144-
}
145-
f(function(x){});
146-
f(function(x){});
147-
return 0;
148-
}
149-
function f$0(){
150-
function f$0(g, x){
151-
try{caml_call1(g, x); return;}
152-
catch(e$0){
153-
var e = caml_wrap_exception(e$0);
154-
throw caml_maybe_attach_backtrace(e, 0);
155-
}
156-
}
157-
function f$1(g, x, cont){
158-
runtime.caml_push_trap
159-
(function(e$0){
160-
var raise = caml_pop_trap(), e = caml_maybe_attach_backtrace(e$0, 0);
161-
return raise(e);
162-
});
163-
return caml_exact_trampoline_cps_call
164-
(g, x, function(_K_){caml_pop_trap(); return cont();});
165-
}
166-
var f = caml_cps_closure(f$0, f$1);
167-
return f;
168-
}
169-
function _h_(){return function(x){};}
170-
function _j_(){
171-
return caml_cps_closure
172-
(function(x){return caml_call2(Stdlib[28], x, cst_a$0);},
173-
function(x, cont){
174-
return caml_trampoline_cps_call3(Stdlib[28], x, cst_a$0, cont);
175-
});
176-
}
131+
function test1(param){return 0;}
177132
function test2$0(param){
178-
var f = f$0();
179-
f(_h_(), 7);
180-
f(_j_(), cst_a);
133+
try{caml_call2(Stdlib[28], x, cst_a);}
134+
catch(e$0){
135+
var e = caml_wrap_exception(e$0);
136+
throw caml_maybe_attach_backtrace(e, 0);
137+
}
181138
return 0;
182139
}
183140
function test2$1(param, cont){
184-
var f = f$0();
185-
return caml_exact_trampoline_cps_call$0
186-
(f,
187-
_h_(),
188-
7,
189-
function(_I_){
190-
return caml_exact_trampoline_cps_call$0
191-
(f, _j_(), cst_a, function(_J_){return cont(0);});
192-
});
141+
runtime.caml_push_trap
142+
(function(e$0){
143+
var raise = caml_pop_trap(), e = caml_maybe_attach_backtrace(e$0, 0);
144+
return raise(e);
145+
});
146+
return caml_trampoline_cps_call3
147+
(Stdlib[28],
148+
x,
149+
cst_a,
150+
function(_s_){caml_pop_trap(); return cont(0);});
193151
}
194152
var test2 = caml_cps_closure(test2$0, test2$1);
195-
function test3(x){
196-
function F(symbol){function f(x){return x + 1 | 0;} return [0, f];}
197-
var M1 = F(), M2 = F(), _H_ = caml_call1(M2[1], 2);
198-
return [0, caml_call1(M1[1], 1), _H_];
199-
}
200-
function f(){
201-
function f$0(x){return caml_call2(Stdlib_Printf[2], _z_, x);}
202-
function f$1(x, cont){
203-
return caml_trampoline_cps_call3(Stdlib_Printf[2], _z_, x, cont);
204-
}
205-
var f = caml_cps_closure(f$0, f$1);
206-
return f;
207-
}
208-
function F(){function F(symbol){var f$0 = f(); return [0, f$0];} return F;}
153+
function test3(x){return [0, 2, 3];}
209154
function test4$0(x){
210-
var F$0 = F(), M1 = F$0(), M2 = F$0();
211-
caml_call1(M1[1], 1);
212-
return caml_call1(M2[1], 2);
155+
caml_call2(Stdlib_Printf[2], _k_, 1);
156+
return caml_call2(Stdlib_Printf[2], _k_, 2);
213157
}
214158
function test4$1(x, cont){
215-
var F$0 = F(), M1 = F$0(), M2 = F$0();
216-
return caml_exact_trampoline_cps_call
217-
(M1[1],
159+
return caml_trampoline_cps_call3
160+
(Stdlib_Printf[2],
161+
_k_,
218162
1,
219-
function(_G_){
220-
return caml_exact_trampoline_cps_call(M2[1], 2, cont);
163+
function(_r_){
164+
return caml_trampoline_cps_call3(Stdlib_Printf[2], _k_, 2, cont);
221165
});
222166
}
223167
var test4 = caml_cps_closure(test4$0, test4$1);
@@ -233,18 +177,18 @@ let%expect_test "direct calls with --effects=double-translation" =
233177
tuple = recfuncs(x),
234178
f = tuple[2],
235179
h = tuple[1],
236-
_E_ = h(100),
237-
_F_ = f(12) + _E_ | 0;
238-
return caml_call1(Stdlib[44], _F_);
180+
_p_ = h(100),
181+
_q_ = f(12) + _p_ | 0;
182+
return caml_call1(Stdlib[44], _q_);
239183
}
240184
function g$1(x, cont){
241185
var
242186
tuple = recfuncs(x),
243187
f = tuple[2],
244188
h = tuple[1],
245-
_C_ = h(100),
246-
_D_ = f(12) + _C_ | 0;
247-
return caml_trampoline_cps_call2(Stdlib[44], _D_, cont);
189+
_n_ = h(100),
190+
_o_ = f(12) + _n_ | 0;
191+
return caml_trampoline_cps_call2(Stdlib[44], _o_, cont);
248192
}
249193
var g = caml_cps_closure(g$0, g$1);
250194
return g;
@@ -255,9 +199,9 @@ let%expect_test "direct calls with --effects=double-translation" =
255199
return caml_exact_trampoline_cps_call
256200
(g$0,
257201
42,
258-
function(_A_){
202+
function(_l_){
259203
return caml_exact_trampoline_cps_call
260-
(g$0, - 5, function(_B_){return cont(0);});
204+
(g$0, - 5, function(_m_){return cont(0);});
261205
});
262206
}
263207
var

compiler/tests-compiler/double-translation/effects_toplevel.ml

Lines changed: 36 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,18 @@ let%expect_test "test-compiler/lib-effects/test1.ml" =
3838
"use strict";
3939
var
4040
runtime = globalThis.jsoo_runtime,
41+
caml_cps_closure = runtime.caml_cps_closure,
4142
caml_string_of_jsbytes = runtime.caml_string_of_jsbytes;
4243
function caml_call1(f, a0){
4344
return (f.l >= 0 ? f.l : f.l = f.length) === 1
4445
? f(a0)
4546
: runtime.caml_call_gen(f, [a0]);
4647
}
48+
function caml_exact_trampoline_call1(f, a0){
49+
return runtime.caml_stack_check_depth()
50+
? f(a0)
51+
: runtime.caml_trampoline_return(f, [a0], 1);
52+
}
4753
function caml_trampoline_cps_call2(f, a0, a1){
4854
return runtime.caml_stack_check_depth()
4955
? f.cps
@@ -60,32 +66,47 @@ let%expect_test "test-compiler/lib-effects/test1.ml" =
6066
: runtime.caml_call_gen(f, [a0]))
6167
: runtime.caml_trampoline_return(f, [a0, a1], 0);
6268
}
69+
function caml_exact_trampoline_cps_call(f, a0, a1){
70+
return runtime.caml_stack_check_depth()
71+
? f.cps ? f.cps.call(null, a0, a1) : a1(f(a0))
72+
: runtime.caml_trampoline_return(f, [a0, a1], 0);
73+
}
6374
var
6475
dummy = 0,
6576
global_data = runtime.caml_get_global_data(),
66-
_b_ =
77+
_c_ =
6778
[0,
6879
[11, caml_string_of_jsbytes("abc"), 0],
6980
caml_string_of_jsbytes("abc")],
7081
Stdlib_Printf = global_data.Stdlib__Printf;
71-
function g$0(param){return caml_call1(Stdlib_Printf[2], _b_);}
82+
function g$0(param){return caml_call1(Stdlib_Printf[2], _c_);}
7283
function g$1(param, cont){
73-
return caml_trampoline_cps_call2(Stdlib_Printf[2], _b_, cont);
84+
return caml_trampoline_cps_call2(Stdlib_Printf[2], _c_, cont);
7485
}
75-
var g = runtime.caml_cps_closure(g$0, g$1);
76-
g();
77-
var i = 1;
78-
for(;;){
79-
g();
80-
var _c_ = i + 1 | 0;
81-
if(5 === i){
82-
g();
83-
var Test = [0];
84-
runtime.caml_register_global(2, Test, "Test");
85-
return;
86+
var g = caml_cps_closure(g$0, g$1);
87+
function f$0(param){
88+
var i = 1;
89+
for(;;){g(); var _g_ = i + 1 | 0; if(5 === i) return; i = _g_;}
90+
}
91+
function f$1(param, cont){
92+
function _d_(i){
93+
return caml_exact_trampoline_cps_call
94+
(g,
95+
dummy,
96+
function(_f_){
97+
var _e_ = i + 1 | 0;
98+
return 5 !== i ? caml_exact_trampoline_call1(_d_, _e_) : cont();
99+
});
86100
}
87-
i = _c_;
101+
return _d_(1);
88102
}
103+
var f = caml_cps_closure(f$0, f$1);
104+
g();
105+
f();
106+
g();
107+
var Test = [0];
108+
runtime.caml_register_global(2, Test, "Test");
109+
return;
89110
}
90111
(globalThis));
91112
//end

0 commit comments

Comments
 (0)