Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions jscomp/core/lam_convert.ml
Original file line number Diff line number Diff line change
Expand Up @@ -278,18 +278,18 @@ let lam_prim ~primitive:( p : Lambda.primitive) ~args loc : Lam.t =
begin match args with
| [Lvar _ | Lconst _ | Lfunction _ as result ] ->
let args =
[ Lam.const (Const_string "done") ;
[ Lam.const Const_js_true ;
result
] in
prim ~primitive:(Pmakeblock (tag,Blk_record [|"RE_LAZY";"value"|],Mutable)) ~args loc
prim ~primitive:(Pmakeblock (tag,Blk_record [|"RE_LAZY_DONE";"value"|],Mutable)) ~args loc
| [computation] ->
let args =
[ Lam.const (Const_string "todo") ;
[ Lam.const Const_js_false ;
(* FIXME: arity 0 does not get proper supported*)
prim ~primitive:(Pjs_fn_make 0) ~args:[Lam.function_ ~arity:1 ~params:[Ident.create "param"] ~body:computation]
loc
] in
prim ~primitive:(Pmakeblock (tag,Blk_record [|"RE_LAZY";"value"|],Mutable)) ~args loc
prim ~primitive:(Pmakeblock (tag,Blk_record [|"RE_LAZY_DONE";"value"|],Mutable)) ~args loc

| _ -> assert false
end
Expand Down
4 changes: 2 additions & 2 deletions jscomp/main/builtin_cmj_datasets.ml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(* 41e7f158a42bd8f0a232242d88578e11 *)
(* 22680a52333cb2d8603ed9cb8b316240 *)
let module_names : string array = Obj.magic (
"Gc" (* 220 *),
"Js" (* 23 *),
Expand Down Expand Up @@ -151,7 +151,7 @@ let module_data : string array = Obj.magic (
(* Sys *)"\132\149\166\190\000\000\000\139\000\000\000 \000\000\000n\000\000\000d\160\224\176&cygwin\144@\144\146C\176*getenv_opt\144\160\160A@@@\176*set_signal\144\160\160B@@@\176+catch_break\144\160\160A@@@\1767enable_runtime_warnings\144\160\160A@@@\1768runtime_warnings_enabled\144\160\160A@@@A",
(* Belt *)"\132\149\166\190\000\000\000\003\000\000\000\001\000\000\000\003\000\000\000\003\160\128A",
(* Char *)"\132\149\166\190\000\000\000\223\000\000\000<\000\000\000\197\000\000\000\186\160\b\000\000 \000\176#chr\144\160\160A@@@\176%equal\144\160\160B@@@\176'compare\144\160\160B@@\144\180B\160\176\001\004\001\"c1@\160\176\001\004\002\"c2@@\151\176I\160\144\004\t\160\144\004\b@\176\1922stdlib-406/char.ml\000K\001\n\001\001\n\021\192\004\002\000K\001\n\001\001\n&@\176'escaped\144\160\160A@@@\176)lowercase\144\160\160A@@@\176)uppercase\144\160\160A@@@\176/lowercase_ascii\144\160\160A@@@\176/uppercase_ascii\144\160\160A@@@A",
(* Lazy *)"\132\149\166\190\000\000\001$\000\000\000O\000\000\001\002\000\000\000\241\160\240\176&is_val\144\160\160A@@@\176(from_fun\144\160\160A@@\144\180A\160\176\001\003\239!f@@\151\176\176\001\000\246\146\160'RE_LAZY%valueA\160\146\146$todo\160\180@@\147\192\144\004\018\160\146A@\176\1922stdlib-406/lazy.ml|\001\t\175\001\t\197\192\004\002|\001\t\175\001\t\203@@@\004\004\176(from_val\144\160\160A@@\144\180A\160\176\001\003\241!v@@\151\176\176\001\000\246\146\160'RE_LAZY%valueA\160\146\146$done\160\144\004\015@\176\192\004\027~\001\t\205\001\t\227\192\004\028~\001\t\205\001\t\228@\176)force_val\144\160\160A@@@\176+lazy_is_val\144\004D@\176-lazy_from_fun\144\004B@\176-lazy_from_val\144\004%@A",
(* Lazy *)"\132\149\166\190\000\000\001$\000\000\000K\000\000\000\252\000\000\000\235\160\240\176&is_val\144\160\160A@@@\176(from_fun\144\160\160A@@\144\180A\160\176\001\003\239!f@@\151\176\176\001\000\246\146\160,RE_LAZY_DONE%valueA\160\146C\160\180@@\147\192\144\004\016\160\146A@\176\1922stdlib-406/lazy.ml|\001\t\175\001\t\197\192\004\002|\001\t\175\001\t\203@@@\004\004\176(from_val\144\160\160A@@\144\180A\160\176\001\003\241!v@@\151\176\176\001\000\246\146\160,RE_LAZY_DONE%valueA\160\146B\160\144\004\r@\176\192\004\025~\001\t\205\001\t\227\192\004\026~\001\t\205\001\t\228@\176)force_val\144\160\160A@@@\176+lazy_is_val\144\004@@\176-lazy_from_fun\144\004>@\176-lazy_from_val\144\004#@A",
(* List *)"\132\149\166\190\000\000\003\134\000\000\001\020\000\000\003\135\000\000\003T\160\b\000\000\208\000\176\"hd\144\160\160A@@@\176\"tl\144\160\160A@@@\176#map\144\160\160B@@@\176#mem\144\160\160B@@@\176#nth\144\160\160B@@@\176#rev\144\160\160A@@@\176$assq\144\160\160B@@@\176$cons\144\160\160B@@\144\180B\160\176\001\003\241!a@\160\176\001\003\242!l@@\151\176\176@\160\"::A@\160\144\004\012\160\144\004\011@\176\1922stdlib-406/list.mlX\001\004\193\001\004\208\192\004\002X\001\004\193\001\004\212@\176$find\144\160\160B@@@\176$init\144\160\160B@@@\176$iter\144\160\160B@@@\176$map2\144\160\160C@@@\176$mapi\144\160\160B@@@\176$memq\144\160\160B@@@\176$sort\144\160\160B@@@\176%assoc\144\160\160B@@@\176%iter2\144\160\160C@@@\176%iteri\144\160\160B@@@\176%merge\144\160\160C@@@\176%split\144\160\160A@@@\176&append\144\160\160B@@@\176&concat\144\160\160A@@@\176&exists\144\160\160B@@@\176&filter\144\160\160A\160A@@@\176&length\144\160\160A@@@\176'combine\144\160\160B@@@\176'exists2\144\160\160C@@@\176'flatten\144\004\031@\176'for_all\144\160\160B@@@\176'nth_opt\144\160\160B@@@\176'rev_map\144\160\160B@@@\176(assq_opt\144\160\160B@@@\176(find_all\144\004,@\176(find_opt\144\160\160B@@@\176(for_all2\144\160\160C@@@\176(mem_assq\144\160\160B@@@\176(rev_map2\144\160\160C@@@\176)assoc_opt\144\160\160B@@@\176)fast_sort\144\004u@\176)fold_left\144\160\160C@@@\176)mem_assoc\144\160\160B@@@\176)partition\144\160\160B@@@\176)sort_uniq\144\160\160B@@@\176*fold_left2\144\160\160D@@@\176*fold_right\144\160\160C@@@\176*rev_append\144\160\160B@@@\176+fold_right2\144\160\160D@@@\176+remove_assq\144\160\160B@@@\176+stable_sort\144\004\165@\176,remove_assoc\144\160\160B@@@\176/compare_lengths\144\160\160B@@@\1763compare_length_with\144\160\160B@@@A",
(* Node *)"\132\149\166\190\000\000\000\016\000\000\000\007\000\000\000\020\000\000\000\019\160\144\176$test\144\160\160A@@@A",
(* Sort *)"\132\149\166\190\000\000\000,\000\000\000\017\000\000\0004\000\000\0001\160\176\176$list\144\160\160B@@@\176%array\144\160\160B@@@\176%merge\144\160\160C@@@A",
Expand Down
6 changes: 3 additions & 3 deletions jscomp/runtime/release.ninja
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,17 @@ build runtime/caml_chrome_debugger.cmj : cc_cmi runtime/caml_chrome_debugger.ml
build runtime/caml_chrome_debugger.cmi : cc runtime/caml_chrome_debugger.mli | runtime/bs_stdlib_mini.cmi runtime/caml_obj_extern.cmj runtime/js.cmi runtime/js.cmj
build runtime/caml_float.cmj : cc_cmi runtime/caml_float.ml | runtime/caml_float.cmi runtime/caml_float_extern.cmj
build runtime/caml_float.cmi : cc runtime/caml_float.mli | runtime/bs_stdlib_mini.cmi runtime/js.cmi runtime/js.cmj
build runtime/caml_format.cmj : cc_cmi runtime/caml_format.ml | runtime/caml_char.cmj runtime/caml_float.cmj runtime/caml_float_extern.cmj runtime/caml_format.cmi runtime/caml_int32.cmj runtime/caml_int64.cmj runtime/caml_int64_extern.cmj runtime/caml_nativeint_extern.cmj runtime/caml_string_extern.cmj
build runtime/caml_format.cmj : cc_cmi runtime/caml_format.ml | runtime/caml_char.cmj runtime/caml_float.cmj runtime/caml_float_extern.cmj runtime/caml_format.cmi runtime/caml_int64.cmj runtime/caml_int64_extern.cmj runtime/caml_nativeint_extern.cmj runtime/caml_string_extern.cmj
build runtime/caml_format.cmi : cc runtime/caml_format.mli | runtime/bs_stdlib_mini.cmi runtime/js.cmi runtime/js.cmj
build runtime/caml_gc.cmj : cc_cmi runtime/caml_gc.ml | runtime/caml_gc.cmi
build runtime/caml_gc.cmi : cc runtime/caml_gc.mli | runtime/bs_stdlib_mini.cmi runtime/js.cmi runtime/js.cmj
build runtime/caml_hash.cmj : cc_cmi runtime/caml_hash.ml | runtime/caml_hash.cmi runtime/caml_hash_primitive.cmj runtime/caml_nativeint_extern.cmj runtime/caml_obj_extern.cmj runtime/js.cmj
build runtime/caml_hash.cmi : cc runtime/caml_hash.mli | runtime/bs_stdlib_mini.cmi runtime/caml_obj_extern.cmj runtime/js.cmi runtime/js.cmj
build runtime/caml_hash_primitive.cmj : cc_cmi runtime/caml_hash_primitive.ml | runtime/caml_char.cmj runtime/caml_hash_primitive.cmi runtime/caml_int32.cmj runtime/caml_nativeint_extern.cmj runtime/caml_string_extern.cmj
build runtime/caml_hash_primitive.cmj : cc_cmi runtime/caml_hash_primitive.ml | runtime/caml_char.cmj runtime/caml_hash_primitive.cmi runtime/caml_nativeint_extern.cmj runtime/caml_string_extern.cmj
build runtime/caml_hash_primitive.cmi : cc runtime/caml_hash_primitive.mli | runtime/bs_stdlib_mini.cmi runtime/js.cmi runtime/js.cmj
build runtime/caml_int32.cmj : cc_cmi runtime/caml_int32.ml | runtime/caml_int32.cmi runtime/caml_nativeint_extern.cmj
build runtime/caml_int32.cmi : cc runtime/caml_int32.mli | runtime/bs_stdlib_mini.cmi runtime/js.cmi runtime/js.cmj
build runtime/caml_int64.cmj : cc_cmi runtime/caml_int64.ml | runtime/caml_float.cmj runtime/caml_float_extern.cmj runtime/caml_int32.cmj runtime/caml_int64.cmi runtime/caml_nativeint_extern.cmj runtime/caml_primitive.cmj runtime/caml_string_extern.cmj runtime/js.cmj
build runtime/caml_int64.cmj : cc_cmi runtime/caml_int64.ml | runtime/caml_float.cmj runtime/caml_float_extern.cmj runtime/caml_int64.cmi runtime/caml_nativeint_extern.cmj runtime/caml_primitive.cmj runtime/caml_string_extern.cmj runtime/js.cmj
build runtime/caml_int64.cmi : cc runtime/caml_int64.mli | runtime/bs_stdlib_mini.cmi runtime/js.cmi runtime/js.cmj
build runtime/caml_io.cmj : cc_cmi runtime/caml_io.ml | runtime/caml_io.cmi runtime/caml_string_extern.cmj runtime/caml_undefined_extern.cmj runtime/curry.cmj runtime/js.cmj
build runtime/caml_io.cmi : cc runtime/caml_io.mli | runtime/bs_stdlib_mini.cmi runtime/caml_undefined_extern.cmj runtime/js.cmi runtime/js.cmj
Expand Down
15 changes: 8 additions & 7 deletions jscomp/stdlib-406/camlinternalLazy.ml
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,22 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *)


[@@@bs.config { flags = [|"-bs-no-cross-module-opt" |]}]

(* Internals of forcing lazy values. *)
type 'a t = {
mutable tag : string [@bs.as "RE_LAZY"] ;
mutable tag : bool [@bs.as "RE_LAZY_DONE"] ;
(* Invariant: name *)
mutable value : 'a (* its type is ['a] or [unit -> 'a ] *)
}

let%private status_done = "done" (* used to be forward_tag in native *)

external%private fnToVal : (unit -> 'a [@bs]) -> 'a = "%identity"
external%private valToFn : 'a -> (unit -> 'a [@bs]) = "%identity"
external%private castToConcrete : 'a lazy_t -> 'a t = "%identity"

let is_val (type a ) (l : a lazy_t) : bool =
((castToConcrete l ).tag = status_done)
(castToConcrete l ).tag



Expand All @@ -46,7 +47,7 @@ let%private forward_with_closure (type a ) (blk : a t) (closure : unit -> a [@bs
let result = closure () [@bs] in
(* do set_field BEFORE set_tag *)
blk.value <- result;
blk.tag<- status_done;
blk.tag<- true;
result


Expand All @@ -73,15 +74,15 @@ let%private force_val_lazy_block (type a ) (blk : a t) : a =

let force (type a ) (lzv : a lazy_t) : a =
let lzv = (castToConcrete lzv : _ t) in
if lzv.tag = status_done then lzv.value else
if lzv.tag then lzv.value else
force_lazy_block lzv




let force_val (type a) (lzv : a lazy_t) : a =
let lzv : _ t = castToConcrete lzv in
if lzv.tag = status_done then lzv.value else
if lzv.tag then lzv.value else
force_val_lazy_block lzv


1 change: 1 addition & 0 deletions jscomp/test/build.ninja
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,7 @@ build test/label_uncurry.cmi test/label_uncurry.cmj : cc test/label_uncurry.ml |
build test/large_obj_test.cmi test/large_obj_test.cmj : cc test/large_obj_test.ml | $stdlib
build test/large_record_duplication_test.cmi test/large_record_duplication_test.cmj : cc test/large_record_duplication_test.ml | test/mt.cmj $stdlib
build test/largest_int_flow.cmi test/largest_int_flow.cmj : cc test/largest_int_flow.ml | $stdlib
build test/lazy_demo.cmi test/lazy_demo.cmj : cc test/lazy_demo.re | $stdlib
build test/lazy_test.cmi test/lazy_test.cmj : cc test/lazy_test.ml | test/mt.cmj $stdlib
build test/lexer_test.cmi test/lexer_test.cmj : cc test/lexer_test.ml | test/arith_lexer.cmj test/arith_parser.cmj test/arith_syntax.cmj test/mt.cmj test/number_lexer.cmj $stdlib
build test/lib_js_test.cmi test/lib_js_test.cmj : cc test/lib_js_test.ml | test/mt.cmj $stdlib
Expand Down
4 changes: 2 additions & 2 deletions jscomp/test/ext_filename_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ var node_parent = "..";
var node_current = ".";

var cwd = {
RE_LAZY: "todo",
RE_LAZY_DONE: false,
value: (function () {
return Caml_sys.caml_sys_getcwd(undefined);
})
Expand Down Expand Up @@ -217,7 +217,7 @@ function find_package_json_dir(cwd) {
}

var package_dir = {
RE_LAZY: "todo",
RE_LAZY_DONE: false,
value: (function () {
var cwd$1 = CamlinternalLazy.force(cwd);
return find_root_filename(cwd$1, Test_literals.bsconfig_json);
Expand Down
2 changes: 1 addition & 1 deletion jscomp/test/gpr_3697_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ var CamlinternalLazy = require("../../lib/js/camlinternalLazy.js");

function fix(param) {
return /* Fix */[{
RE_LAZY: "todo",
RE_LAZY_DONE: false,
value: (function () {
return fix(undefined);
})
Expand Down
12 changes: 6 additions & 6 deletions jscomp/test/hamming_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ function pr(param) {

function map(f, l) {
return {
RE_LAZY: "todo",
RE_LAZY_DONE: false,
value: (function () {
var match = CamlinternalLazy.force(l);
return /* Cons */[
Expand All @@ -132,7 +132,7 @@ function map(f, l) {

function merge(cmp, l1, l2) {
return {
RE_LAZY: "todo",
RE_LAZY_DONE: false,
value: (function () {
var match = CamlinternalLazy.force(l1);
var match$1 = CamlinternalLazy.force(l2);
Expand Down Expand Up @@ -184,7 +184,7 @@ function iter_interval(f, _l, _param) {
}

var hamming = {
RE_LAZY: "todo",
RE_LAZY_DONE: false,
value: (function () {
return /* Cons */[
nn1,
Expand All @@ -194,21 +194,21 @@ var hamming = {
};

var ham2 = {
RE_LAZY: "todo",
RE_LAZY_DONE: false,
value: (function () {
return CamlinternalLazy.force(map(x2, hamming));
})
};

var ham3 = {
RE_LAZY: "todo",
RE_LAZY_DONE: false,
value: (function () {
return CamlinternalLazy.force(map(x3, hamming));
})
};

var ham5 = {
RE_LAZY: "todo",
RE_LAZY_DONE: false,
value: (function () {
return CamlinternalLazy.force(map(x5, hamming));
})
Expand Down
30 changes: 30 additions & 0 deletions jscomp/test/lazy_demo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
'use strict';

var CamlinternalLazy = require("../../lib/js/camlinternalLazy.js");

var lazy1 = {
RE_LAZY_DONE: false,
value: (function () {
console.log("Hello, lazy");
return 1;
})
};

var lazy2 = {
RE_LAZY_DONE: true,
value: 3
};

console.log(lazy1, lazy2);

var la = CamlinternalLazy.force(lazy1);

var lb = CamlinternalLazy.force(lazy2);

console.log(la, lb);

exports.lazy1 = lazy1;
exports.lazy2 = lazy2;
exports.la = la;
exports.lb = lb;
/* Not a pure module */
12 changes: 12 additions & 0 deletions jscomp/test/lazy_demo.re
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
let lazy1 = lazy {
"Hello, lazy" -> Js.log;
1
};

let lazy2 = lazy 3 ;

Js.log2 (lazy1, lazy2);

let (lazy la, lazy lb) = (lazy1, lazy2);

Js.log2 (la, lb);
Loading