Skip to content

Commit af6417d

Browse files
vouillonhhugo
authored andcommitted
Tuple unboxing: tests
1 parent 35ca610 commit af6417d

File tree

2 files changed

+109
-0
lines changed

2 files changed

+109
-0
lines changed

compiler/tests-compiler/dune.inc

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -854,6 +854,21 @@
854854
(preprocess
855855
(pps ppx_expect)))
856856

857+
(library
858+
;; compiler/tests-compiler/tuple_unboxing.ml
859+
(name tuple_unboxing_15)
860+
(enabled_if true)
861+
(modules tuple_unboxing)
862+
(libraries js_of_ocaml_compiler unix str jsoo_compiler_expect_tests_helper)
863+
(inline_tests
864+
(enabled_if true)
865+
(deps
866+
(file %{project_root}/compiler/bin-js_of_ocaml/js_of_ocaml.exe)
867+
(file %{project_root}/compiler/bin-jsoo_minify/jsoo_minify.exe)))
868+
(flags (:standard -open Jsoo_compiler_expect_tests_helper))
869+
(preprocess
870+
(pps ppx_expect)))
871+
857872
(library
858873
;; compiler/tests-compiler/unix_fs.ml
859874
(name unix_fs_15)
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
open Util
2+
3+
let%expect_test _ =
4+
let program =
5+
compile_and_parse
6+
~flags:[ "--no-inline" ]
7+
{|
8+
let f (x, y) = x + y
9+
let x = f(1, 2)
10+
|}
11+
in
12+
print_program program;
13+
[%expect
14+
{|
15+
(function(globalThis){
16+
"use strict";
17+
var runtime = globalThis.jsoo_runtime, _a_ = [0, 1, 2];
18+
function f(param){var y = param[2], x = param[1]; return x + y | 0;}
19+
var x = f(_a_), Test = [0, f, x];
20+
runtime.caml_register_global(1, Test, "Test");
21+
return;
22+
}
23+
(globalThis));
24+
//end |}]
25+
26+
let%expect_test _ =
27+
let program =
28+
compile_and_parse
29+
~flags:[ "--no-inline" ]
30+
{|
31+
type t = {x : int; y : int}
32+
let f b y t = let {x; _} = if b then {x=1; y} else t in x
33+
let g b t = let {x; _} = if b then {x=1; y=1} else t in x
34+
|}
35+
in
36+
print_program program;
37+
[%expect
38+
{|
39+
(function(globalThis){
40+
"use strict";
41+
var runtime = globalThis.jsoo_runtime, _a_ = [0, 1, 1];
42+
function f(b, y, t){var match = b ? [0, 1] : t, x = match[1]; return x;}
43+
function g(b, t){var match = b ? _a_ : t, x = match[1]; return x;}
44+
var Test = [0, f, g];
45+
runtime.caml_register_global(1, Test, "Test");
46+
return;
47+
}
48+
(globalThis));
49+
//end |}]
50+
51+
let%expect_test _ =
52+
let program =
53+
compile_and_parse
54+
~flags:[ "--no-inline" ]
55+
~debug:false
56+
{|
57+
type t = C | D | E
58+
type s = A of int | B of int
59+
let foo c a b =
60+
let m =
61+
match c with
62+
| C -> A a
63+
| D -> B b
64+
| E -> B (b + 1)
65+
in
66+
match m with
67+
| A x -> x
68+
| B y -> y
69+
|}
70+
in
71+
print_program program;
72+
[%expect
73+
{|
74+
(function(globalThis){
75+
"use strict";
76+
var
77+
runtime = globalThis.jsoo_runtime,
78+
Test =
79+
[0,
80+
function(_c_, _b_, _a_){
81+
switch(_c_){
82+
case 0:
83+
var _d_ = [0, _b_]; break;
84+
case 1:
85+
var _d_ = [1, _a_]; break;
86+
default: var _d_ = [1, _a_ + 1 | 0];
87+
}
88+
return _d_[1];
89+
}];
90+
runtime.caml_register_global(0, Test, "Test");
91+
return;
92+
}
93+
(globalThis));
94+
//end |}]

0 commit comments

Comments
 (0)