|
| 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