Skip to content

Commit e63b391

Browse files
committed
tweak a little bit change string based into bool based
1 parent 6ffb562 commit e63b391

33 files changed

+172
-132
lines changed

jscomp/core/lam_convert.ml

+4-4
Original file line numberDiff line numberDiff line change
@@ -278,18 +278,18 @@ let lam_prim ~primitive:( p : Lambda.primitive) ~args loc : Lam.t =
278278
begin match args with
279279
| [Lvar _ | Lconst _ | Lfunction _ as result ] ->
280280
let args =
281-
[ Lam.const (Const_string "done") ;
281+
[ Lam.const Const_js_true ;
282282
result
283283
] in
284-
prim ~primitive:(Pmakeblock (tag,Blk_record [|"RE_LAZY";"value"|],Mutable)) ~args loc
284+
prim ~primitive:(Pmakeblock (tag,Blk_record [|"RE_LAZY_DONE";"value"|],Mutable)) ~args loc
285285
| [computation] ->
286286
let args =
287-
[ Lam.const (Const_string "todo") ;
287+
[ Lam.const Const_js_false ;
288288
(* FIXME: arity 0 does not get proper supported*)
289289
prim ~primitive:(Pjs_fn_make 0) ~args:[Lam.function_ ~arity:1 ~params:[Ident.create "param"] ~body:computation]
290290
loc
291291
] in
292-
prim ~primitive:(Pmakeblock (tag,Blk_record [|"RE_LAZY";"value"|],Mutable)) ~args loc
292+
prim ~primitive:(Pmakeblock (tag,Blk_record [|"RE_LAZY_DONE";"value"|],Mutable)) ~args loc
293293

294294
| _ -> assert false
295295
end

jscomp/runtime/release.ninja

+3-3
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,17 @@ build runtime/caml_chrome_debugger.cmj : cc_cmi runtime/caml_chrome_debugger.ml
2323
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
2424
build runtime/caml_float.cmj : cc_cmi runtime/caml_float.ml | runtime/caml_float.cmi runtime/caml_float_extern.cmj
2525
build runtime/caml_float.cmi : cc runtime/caml_float.mli | runtime/bs_stdlib_mini.cmi runtime/js.cmi runtime/js.cmj
26-
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
26+
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
2727
build runtime/caml_format.cmi : cc runtime/caml_format.mli | runtime/bs_stdlib_mini.cmi runtime/js.cmi runtime/js.cmj
2828
build runtime/caml_gc.cmj : cc_cmi runtime/caml_gc.ml | runtime/caml_gc.cmi
2929
build runtime/caml_gc.cmi : cc runtime/caml_gc.mli | runtime/bs_stdlib_mini.cmi runtime/js.cmi runtime/js.cmj
3030
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
3131
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
32-
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
32+
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
3333
build runtime/caml_hash_primitive.cmi : cc runtime/caml_hash_primitive.mli | runtime/bs_stdlib_mini.cmi runtime/js.cmi runtime/js.cmj
3434
build runtime/caml_int32.cmj : cc_cmi runtime/caml_int32.ml | runtime/caml_int32.cmi runtime/caml_nativeint_extern.cmj
3535
build runtime/caml_int32.cmi : cc runtime/caml_int32.mli | runtime/bs_stdlib_mini.cmi runtime/js.cmi runtime/js.cmj
36-
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
36+
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
3737
build runtime/caml_int64.cmi : cc runtime/caml_int64.mli | runtime/bs_stdlib_mini.cmi runtime/js.cmi runtime/js.cmj
3838
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
3939
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

jscomp/stdlib-406/camlinternalLazy.ml

+8-7
Original file line numberDiff line numberDiff line change
@@ -22,21 +22,22 @@
2222
* along with this program; if not, write to the Free Software
2323
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *)
2424

25-
25+
[@@@bs.config { flags = [|"-bs-no-cross-module-opt" |]}]
26+
2627
(* Internals of forcing lazy values. *)
2728
type 'a t = {
28-
mutable tag : string [@bs.as "RE_LAZY"] ;
29+
mutable tag : bool [@bs.as "RE_LAZY_DONE"] ;
2930
(* Invariant: name *)
3031
mutable value : 'a (* its type is ['a] or [unit -> 'a ] *)
3132
}
3233

33-
let%private status_done = "done" (* used to be forward_tag in native *)
34+
3435
external%private fnToVal : (unit -> 'a [@bs]) -> 'a = "%identity"
3536
external%private valToFn : 'a -> (unit -> 'a [@bs]) = "%identity"
3637
external%private castToConcrete : 'a lazy_t -> 'a t = "%identity"
3738

3839
let is_val (type a ) (l : a lazy_t) : bool =
39-
((castToConcrete l ).tag = status_done)
40+
(castToConcrete l ).tag
4041

4142

4243

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

5253

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

7475
let force (type a ) (lzv : a lazy_t) : a =
7576
let lzv = (castToConcrete lzv : _ t) in
76-
if lzv.tag = status_done then lzv.value else
77+
if lzv.tag then lzv.value else
7778
force_lazy_block lzv
7879

7980

8081

8182

8283
let force_val (type a) (lzv : a lazy_t) : a =
8384
let lzv : _ t = castToConcrete lzv in
84-
if lzv.tag = status_done then lzv.value else
85+
if lzv.tag then lzv.value else
8586
force_val_lazy_block lzv
8687

8788

jscomp/test/build.ninja

+1
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,7 @@ build test/label_uncurry.cmi test/label_uncurry.cmj : cc test/label_uncurry.ml |
405405
build test/large_obj_test.cmi test/large_obj_test.cmj : cc test/large_obj_test.ml | $stdlib
406406
build test/large_record_duplication_test.cmi test/large_record_duplication_test.cmj : cc test/large_record_duplication_test.ml | test/mt.cmj $stdlib
407407
build test/largest_int_flow.cmi test/largest_int_flow.cmj : cc test/largest_int_flow.ml | $stdlib
408+
build test/lazy_demo.cmi test/lazy_demo.cmj : cc test/lazy_demo.re | $stdlib
408409
build test/lazy_test.cmi test/lazy_test.cmj : cc test/lazy_test.ml | test/mt.cmj $stdlib
409410
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
410411
build test/lib_js_test.cmi test/lib_js_test.cmj : cc test/lib_js_test.ml | test/mt.cmj $stdlib

jscomp/test/ext_filename_test.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ var node_parent = "..";
2525
var node_current = ".";
2626

2727
var cwd = {
28-
RE_LAZY: "todo",
28+
RE_LAZY_DONE: false,
2929
value: (function () {
3030
return Caml_sys.caml_sys_getcwd(undefined);
3131
})
@@ -217,7 +217,7 @@ function find_package_json_dir(cwd) {
217217
}
218218

219219
var package_dir = {
220-
RE_LAZY: "todo",
220+
RE_LAZY_DONE: false,
221221
value: (function () {
222222
var cwd$1 = CamlinternalLazy.force(cwd);
223223
return find_root_filename(cwd$1, Test_literals.bsconfig_json);

jscomp/test/gpr_3697_test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ var CamlinternalLazy = require("../../lib/js/camlinternalLazy.js");
44

55
function fix(param) {
66
return /* Fix */[{
7-
RE_LAZY: "todo",
7+
RE_LAZY_DONE: false,
88
value: (function () {
99
return fix(undefined);
1010
})

jscomp/test/hamming_test.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ function pr(param) {
119119

120120
function map(f, l) {
121121
return {
122-
RE_LAZY: "todo",
122+
RE_LAZY_DONE: false,
123123
value: (function () {
124124
var match = CamlinternalLazy.force(l);
125125
return /* Cons */[
@@ -132,7 +132,7 @@ function map(f, l) {
132132

133133
function merge(cmp, l1, l2) {
134134
return {
135-
RE_LAZY: "todo",
135+
RE_LAZY_DONE: false,
136136
value: (function () {
137137
var match = CamlinternalLazy.force(l1);
138138
var match$1 = CamlinternalLazy.force(l2);
@@ -184,7 +184,7 @@ function iter_interval(f, _l, _param) {
184184
}
185185

186186
var hamming = {
187-
RE_LAZY: "todo",
187+
RE_LAZY_DONE: false,
188188
value: (function () {
189189
return /* Cons */[
190190
nn1,
@@ -194,21 +194,21 @@ var hamming = {
194194
};
195195

196196
var ham2 = {
197-
RE_LAZY: "todo",
197+
RE_LAZY_DONE: false,
198198
value: (function () {
199199
return CamlinternalLazy.force(map(x2, hamming));
200200
})
201201
};
202202

203203
var ham3 = {
204-
RE_LAZY: "todo",
204+
RE_LAZY_DONE: false,
205205
value: (function () {
206206
return CamlinternalLazy.force(map(x3, hamming));
207207
})
208208
};
209209

210210
var ham5 = {
211-
RE_LAZY: "todo",
211+
RE_LAZY_DONE: false,
212212
value: (function () {
213213
return CamlinternalLazy.force(map(x5, hamming));
214214
})

jscomp/test/lazy_demo.js

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
'use strict';
2+
3+
var CamlinternalLazy = require("../../lib/js/camlinternalLazy.js");
4+
5+
var lazy1 = {
6+
RE_LAZY_DONE: false,
7+
value: (function () {
8+
console.log("Hello, lazy");
9+
return 1;
10+
})
11+
};
12+
13+
var lazy2 = {
14+
RE_LAZY_DONE: true,
15+
value: 3
16+
};
17+
18+
console.log(lazy1, lazy2);
19+
20+
var la = CamlinternalLazy.force(lazy1);
21+
22+
var lb = CamlinternalLazy.force(lazy2);
23+
24+
console.log(la, lb);
25+
26+
exports.lazy1 = lazy1;
27+
exports.lazy2 = lazy2;
28+
exports.la = la;
29+
exports.lb = lb;
30+
/* Not a pure module */

jscomp/test/lazy_demo.re

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
let lazy1 = lazy {
2+
"Hello, lazy" -> Js.log;
3+
1
4+
};
5+
6+
let lazy2 = lazy 3 ;
7+
8+
Js.log2 (lazy1, lazy2);
9+
10+
let (lazy la, lazy lb) = (lazy1, lazy2);
11+
12+
Js.log2 (la, lb);

jscomp/test/lazy_test.js

+21-21
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ var u = {
1111
};
1212

1313
var v = {
14-
RE_LAZY: "todo",
14+
RE_LAZY_DONE: false,
1515
value: (function () {
1616
u.contents = 32;
1717

@@ -55,15 +55,15 @@ var s = {
5555
};
5656

5757
var set_true = {
58-
RE_LAZY: "todo",
58+
RE_LAZY_DONE: false,
5959
value: (function () {
6060
s.contents = 1;
6161

6262
})
6363
};
6464

6565
var set_false = {
66-
RE_LAZY: "todo",
66+
RE_LAZY_DONE: false,
6767
value: (function () {
6868
s.contents = undefined;
6969

@@ -93,7 +93,7 @@ var u_v = {
9393
};
9494

9595
var u$1 = {
96-
RE_LAZY: "todo",
96+
RE_LAZY_DONE: false,
9797
value: (function () {
9898
u_v.contents = 2;
9999

@@ -105,14 +105,14 @@ CamlinternalLazy.force(u$1);
105105
var exotic = CamlinternalLazy.force;
106106

107107
var l_from_fun = {
108-
RE_LAZY: "todo",
108+
RE_LAZY_DONE: false,
109109
value: (function () {
110110
return 3;
111111
})
112112
};
113113

114114
var forward_test = {
115-
RE_LAZY: "todo",
115+
RE_LAZY_DONE: false,
116116
value: (function () {
117117
var u = 3;
118118
u = u + 1 | 0;
@@ -121,12 +121,12 @@ var forward_test = {
121121
};
122122

123123
var f005 = {
124-
RE_LAZY: "done",
124+
RE_LAZY_DONE: true,
125125
value: 6
126126
};
127127

128128
var f006 = {
129-
RE_LAZY: "todo",
129+
RE_LAZY_DONE: false,
130130
value: (function () {
131131
return function (param) {
132132
return 3;
@@ -135,7 +135,7 @@ var f006 = {
135135
};
136136

137137
var f007 = {
138-
RE_LAZY: "todo",
138+
RE_LAZY_DONE: false,
139139
value: (function () {
140140
throw {
141141
RE_EXN_ID: "Not_found",
@@ -145,7 +145,7 @@ var f007 = {
145145
};
146146

147147
var f008 = {
148-
RE_LAZY: "todo",
148+
RE_LAZY_DONE: false,
149149
value: (function () {
150150
console.log("hi");
151151
throw {
@@ -157,28 +157,28 @@ var f008 = {
157157

158158
function a2(x) {
159159
return {
160-
RE_LAZY: "done",
160+
RE_LAZY_DONE: true,
161161
value: x
162162
};
163163
}
164164

165165
var a3 = {
166-
RE_LAZY: "done",
166+
RE_LAZY_DONE: true,
167167
value: 3
168168
};
169169

170170
var a4 = {
171-
RE_LAZY: "done",
171+
RE_LAZY_DONE: true,
172172
value: 3
173173
};
174174

175175
var a5 = {
176-
RE_LAZY: "done",
176+
RE_LAZY_DONE: true,
177177
value: undefined
178178
};
179179

180180
var a6 = {
181-
RE_LAZY: "done",
181+
RE_LAZY_DONE: true,
182182
value: undefined
183183
};
184184

@@ -235,7 +235,7 @@ Mt.from_pair_suites("Lazy_test", /* :: */[
235235
(function (param) {
236236
return /* Eq */Block.__(0, [
237237
CamlinternalLazy.force({
238-
RE_LAZY: "done",
238+
RE_LAZY_DONE: true,
239239
value: 3
240240
}),
241241
3
@@ -248,9 +248,9 @@ Mt.from_pair_suites("Lazy_test", /* :: */[
248248
(function (param) {
249249
return /* Eq */Block.__(0, [
250250
CamlinternalLazy.force(CamlinternalLazy.force({
251-
RE_LAZY: "done",
251+
RE_LAZY_DONE: true,
252252
value: {
253-
RE_LAZY: "done",
253+
RE_LAZY_DONE: true,
254254
value: 3
255255
}
256256
})),
@@ -265,7 +265,7 @@ Mt.from_pair_suites("Lazy_test", /* :: */[
265265
debugger;
266266
return /* Eq */Block.__(0, [
267267
CamlinternalLazy.force(CamlinternalLazy.force({
268-
RE_LAZY: "done",
268+
RE_LAZY_DONE: true,
269269
value: forward_test
270270
})),
271271
4
@@ -307,7 +307,7 @@ Mt.from_pair_suites("Lazy_test", /* :: */[
307307
"File \"lazy_test.ml\", line 82, characters 0-7",
308308
(function (param) {
309309
return /* Ok */Block.__(4, [Lazy.is_val({
310-
RE_LAZY: "done",
310+
RE_LAZY_DONE: true,
311311
value: 3
312312
})]);
313313
})
@@ -317,7 +317,7 @@ Mt.from_pair_suites("Lazy_test", /* :: */[
317317
"File \"lazy_test.ml\", line 83, characters 0-7",
318318
(function (param) {
319319
return /* Ok */Block.__(4, [!Lazy.is_val({
320-
RE_LAZY: "todo",
320+
RE_LAZY_DONE: false,
321321
value: (function () {
322322
throw {
323323
RE_EXN_ID: "Not_found",

0 commit comments

Comments
 (0)