16
16
17
17
(* Internals of forcing lazy values. *)
18
18
type 'a t = {
19
- mutable tag : int [@ bs.as "tag " ] ;
19
+ mutable tag : string [@ bs.as "RE_LAZY " ] ;
20
20
(* Invariant: name *)
21
- mutable value : 'a (* [@bs.as "val"] *)
22
- (* its type is ['a] or [unit -> 'a ] *)
21
+ mutable value : 'a (* its type is ['a] or [unit -> 'a ] *)
23
22
}
24
23
25
24
26
- let % private lazy_tag = 246
27
- let % private forward_tag = 250
25
+ let % private status_todo = " todo " (* used to be lazy tag in native *)
26
+ let % private status_done = " done " (* used to be forward_tag in native *)
28
27
external% private magic : 'a -> 'b = " %identity"
29
28
external% private fnToVal : (unit -> 'a [@ bs]) -> 'a = " %identity"
30
29
external% private valToFn : 'a -> (unit -> 'a [@ bs]) = " %identity"
@@ -37,18 +36,18 @@ let%private lazy_boxed (type a) (l : a ) : bool =
37
36
if Js. testAny l then false
38
37
else
39
38
let t = (magic l : _ t ).tag in
40
- t = forward_tag || t = lazy_tag
39
+ t = status_done || t = status_todo
41
40
42
41
let is_val (type a ) (l : a lazy_t ) : bool =
43
- Js. testAny l || ((castToConcrete l ).tag <> lazy_tag )
42
+ Js. testAny l || ((castToConcrete l ).tag <> status_todo )
44
43
45
44
let from_fun (type arg ) f : arg lazy_t =
46
- castToLazy {tag = lazy_tag ; value = fnToVal f}
45
+ castToLazy {tag = status_todo ; value = fnToVal f}
47
46
48
47
49
48
let from_val (type arg ) (v : arg ) : arg lazy_t =
50
49
if lazy_boxed v then begin
51
- castToLazy {tag = forward_tag ; value = v}
50
+ castToLazy {tag = status_done ; value = v}
52
51
end else begin
53
52
lazyBox v
54
53
end
@@ -59,7 +58,7 @@ let%private forward_with_closure (type a ) (blk : a t) (closure : unit -> a [@bs
59
58
let result = closure () [@ bs] in
60
59
(* do set_field BEFORE set_tag *)
61
60
blk.value < - result;
62
- blk.tag< - forward_tag ;
61
+ blk.tag< - status_done ;
63
62
result
64
63
65
64
0 commit comments