File: lazy.ml

package info (click to toggle)
js-of-ocaml 5.9.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 32,020 kB
  • sloc: ml: 91,250; javascript: 57,289; ansic: 315; makefile: 271; lisp: 23; sh: 6; perl: 4
file content (48 lines) | stat: -rw-r--r-- 1,574 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
(* Js_of_ocaml tests
 * http://www.ocsigen.org/js_of_ocaml/
 * Copyright (C) 2019 Hugo Heuzard
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 *)

open Util

let%expect_test "static eval of string get" =
  let program =
    compile_and_parse
      {|
      let lz = lazy ( List.map (fun x -> x * x) [8;9] )

      let rec do_the_lazy_rec n =
        if n = 0 then [] else (Lazy.force lz) :: do_the_lazy_rec (n-1)
      let _ = do_the_lazy_rec 8
  |}
  in
  print_fun_decl program (Some "do_the_lazy_rec");
  [%expect
    {|
    function do_the_lazy_rec(n){
     if(0 === n) return 0;
     var _b_ = do_the_lazy_rec(n - 1 | 0), _c_ = runtime.caml_obj_tag(lz);
     a:
     if(250 === _c_)
      var _d_ = lz[1];
     else{
      if(246 !== _c_ && 244 !== _c_){var _d_ = lz; break a;}
      var _d_ = caml_call1(CamlinternalLazy[2], lz);
     }
     return [0, _d_, _b_];
    }
    //end |}]