|
| 1 | +(* Js_of_ocaml compiler |
| 2 | + * http://www.ocsigen.org/js_of_ocaml/ |
| 3 | +u * Copyright (C) 2017 Hugo Heuzard |
| 4 | + * Copyright (C) 2019 Ty Overby |
| 5 | + * |
| 6 | + * This program is free software; you can redistribute it and/or modify |
| 7 | + * it under the terms of the GNU Lesser General Public License as published by |
| 8 | + * the Free Software Foundation, with linking exception; |
| 9 | + * either version 2.1 of the License, or (at your option) any later version. |
| 10 | + * |
| 11 | + * This program is distributed in the hope that it will be useful, |
| 12 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | + * GNU Lesser General Public License for more details. |
| 15 | + * |
| 16 | + * You should have received a copy of the GNU Lesser General Public License |
| 17 | + * along with this program; if not, write to the Free Software |
| 18 | + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 19 | + *) |
| 20 | + |
| 21 | +open Util |
| 22 | + |
| 23 | +let%expect_test "conditional" = |
| 24 | + let program = |
| 25 | + compile_and_parse |
| 26 | + {| |
| 27 | + let f a b c d e f = |
| 28 | + let x = match a,b,c,d,e,f with |
| 29 | + | true, false, false, false ,false, false -> 1 |
| 30 | + | false, false, false, true, false, false -> 4 |
| 31 | + | false, true, false, false, false ,false -> 2 |
| 32 | + | false, false, true, false, false, false -> 3 |
| 33 | + | false, false, false, false, true, false -> 5 |
| 34 | + | false, false, false, false, false, true -> 6 |
| 35 | + | false, false, false, false, false, false -> 100 |
| 36 | + | true, true, _, _, _, _ |
| 37 | + | _, true, _, true, _, _ |
| 38 | + | _ -> -1 |
| 39 | + in x + 2 |
| 40 | + |} |
| 41 | + in |
| 42 | + print_fun_decl program (Some "f"); |
| 43 | + [%expect |
| 44 | + {| |
| 45 | + function f(a,b,c,d,e,f) |
| 46 | + {var switch$0=0; |
| 47 | + if(a) |
| 48 | + {if(! b && ! c && ! d && ! e && ! f){var x=1;switch$0 = 1}} |
| 49 | + else |
| 50 | + if(b) |
| 51 | + {var switch$1=0; |
| 52 | + if(! c && ! d) |
| 53 | + if(e || f)switch$1 = 1;else{var x=2;switch$0 = 1;switch$1 = 1}} |
| 54 | + else |
| 55 | + if(c) |
| 56 | + {if(! d && ! e && ! f){var x=3;switch$0 = 1}} |
| 57 | + else |
| 58 | + if(d) |
| 59 | + {if(! e && ! f){var x=4;switch$0 = 1}} |
| 60 | + else |
| 61 | + if(e) |
| 62 | + {if(! f){var x=5;switch$0 = 1}} |
| 63 | + else |
| 64 | + if(f){var x=6;switch$0 = 1}else{var x=100;switch$0 = 1} |
| 65 | + if(! switch$0)var x=- 1; |
| 66 | + return x + 2 | 0} |}] |
0 commit comments