Skip to content

Commit

Permalink
Update testsuite for dynamic switching
Browse files Browse the repository at this point in the history
  • Loading branch information
OlivierNicole committed May 17, 2023
1 parent 6552d1e commit 91e352e
Show file tree
Hide file tree
Showing 13 changed files with 520 additions and 270 deletions.
104 changes: 71 additions & 33 deletions compiler/tests-compiler/direct_calls.ml
Original file line number Diff line number Diff line change
Expand Up @@ -123,53 +123,91 @@ let%expect_test "direct calls with --enable effects" =
M1.f 1; M2.f 2
|}
in
print_fun_decl code (Some "test1");
print_fun_decl code (Some "test2");
print_fun_decl code (Some "test3");
print_fun_decl code (Some "test4");
print_fun_decl code (Some "test1$0");
print_fun_decl code (Some "test1$1");
print_var_decl code "test1";
print_fun_decl code (Some "test2$0");
print_fun_decl code (Some "test2$1");
print_var_decl code "test2";
print_fun_decl code (Some "test3$0");
print_fun_decl code (Some "test3$1");
print_var_decl code "test3";
print_fun_decl code (Some "test4$0");
print_fun_decl code (Some "test4$1");
print_var_decl code "test4";
[%expect
{|
function test1(param, cont){
function f(g, x){return g(x);}
var _k_ = 7;
f(function(x){return x + 1 | 0;}, _k_);
var _l_ = 4.;
f(function(x){return x * 2.;}, _l_);
function test1$0(param){
function f(g, x){return caml_call1(g, x);}
var _H_ = 7;
f(function(x){return x + 1 | 0;}, _H_);
var _I_ = 4.;
f(function(x){return x * 2.;}, _I_);
return 0;
}
//end
function test1$1(param, cont){
function f(g, x){return caml_call1(g, x);}
var _F_ = 7;
f(function(x){return x + 1 | 0;}, _F_);
var _G_ = 4.;
f(function(x){return x * 2.;}, _G_);
return cont(0);
}
//end
function test2(param, cont){
function f(g, x, cont){return caml_cps_exact_call2(g, x, cont);}
var _f_ = 7;
function _g_(x, cont){return cont(x + 1 | 0);}
var test1 = caml_cps_closure(test1$0, test1$1);
//end
function test2$0(param){
var f = f$0();
f(_h_(), 7);
f(_j_(), cst_a);
return 0;
}
//end
function test2$1(param, cont){
var f = f$0(), _y_ = 7, _z_ = _h_();
return caml_cps_exact_call3
(f,
_g_,
_f_,
function(_h_){
function _i_(x, cont){
return caml_cps_call3(Stdlib[28], x, cst_a$0, cont);
}
_z_,
_y_,
function(_A_){
var _B_ = _j_();
return caml_cps_exact_call3
(f, _i_, cst_a, function(_j_){return cont(0);});
(f, _B_, cst_a, function(_C_){return cont(0);});
});
}
//end
function test3(x, cont){
var test2 = caml_cps_closure(test2$0, test2$1);
//end
function test3$0(x){
function F(symbol){function f(x){return x + 1 | 0;} return [0, f];}
var M1 = F([0]), M2 = F([0]), _e_ = M2[1].call(null, 2);
return cont([0, M1[1].call(null, 1), _e_]);
var M1 = F([0]), M2 = F([0]), _x_ = caml_call1(M2[1], 2);
return [0, caml_call1(M1[1], 1), _x_];
}
//end
function test4(x, cont){
function F(symbol){
function f(x, cont){return caml_cps_call3(Stdlib_Printf[2], _a_, x, cont);}
return [0, f];
}
var M1 = F([0]), M2 = F([0]), _b_ = 1, _c_ = M1[1];
function test3$1(x, cont){
function F(symbol){function f(x){return x + 1 | 0;} return [0, f];}
var M1 = F([0]), M2 = F([0]), _w_ = M2[1].call(null, 2);
return cont([0, M1[1].call(null, 1), _w_]);
}
//end
var test3 = caml_cps_closure(test3$0, test3$1);
//end
function test4$0(x){
function F(symbol){var f$0 = f(); return [0, f$0];}
var M1 = F([0]), M2 = F([0]);
caml_call1(M1[1], 1);
return caml_call1(M2[1], 2);
}
//end
function test4$1(x, cont){
function F(symbol){var f$0 = f(); return [0, f$0];}
var M1 = F([0]), M2 = F([0]), _t_ = 1, _u_ = M1[1];
return caml_cps_exact_call2
(_c_,
_b_,
function(_d_){return caml_cps_exact_call2(M2[1], 2, cont);});
(_u_,
_t_,
function(_v_){return caml_cps_exact_call2(M2[1], 2, cont);});
}
//end
var test4 = caml_cps_closure(test4$0, test4$1);
//end |}]
45 changes: 24 additions & 21 deletions compiler/tests-compiler/effects.ml
Original file line number Diff line number Diff line change
Expand Up @@ -39,32 +39,35 @@ let fff () =
| e -> None) }
|}
in
print_fun_decl program (Some "fff");
(*ignore @@ Js_of_ocaml_compiler.(Js_output.program (Pretty_print.to_out_channel stdout) program);*)
print_fun_decl program (Some "fff$0");
print_fun_decl program (Some "fff$1");
print_var_decl program "fff";
[%expect
{|
function fff(param, cont){
function fff$0(param){
var
_b_ =
[0,
function(e, cont){
return e === E
? cont([0, function(k, cont){return cont(11);}])
: cont(0);
}],
_c_ = 10;
function _d_(x, cont){return cont(x);}
var _e_ = Stdlib_Effect[3][5];
_p_ = [0, _d_()],
_q_ = _f_(),
_r_ = caml_call3(Stdlib_Effect[3][5], _q_, 10, _p_);
return caml_call1(caml_call1(Stdlib_Printf[2], _h_), _r_);
}
//end
function fff$1(param, cont){
var _i_ = [0, _d_()], _k_ = _f_(), _j_ = 10, _l_ = Stdlib_Effect[3][5];
return caml_cps_call4
(_e_,
_d_,
_c_,
_b_,
function(_f_){
var _g_ = Stdlib_Printf[2];
(_l_,
_k_,
_j_,
_i_,
function(_m_){
var _n_ = Stdlib_Printf[2];
return caml_cps_call2
(_g_,
_a_,
function(_h_){return caml_cps_call2(_h_, _f_, cont);});
(_n_,
_h_,
function(_o_){return caml_cps_call2(_o_, _m_, cont);});
});
}
//end
var fff = caml_cps_closure(fff$0, fff$1);
//end |}]
Loading

0 comments on commit 91e352e

Please sign in to comment.