forked from rescript-lang/rescript
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcamlinternalLazy.js
84 lines (73 loc) · 1.63 KB
/
camlinternalLazy.js
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
'use strict';
var Block = require("./block.js");
var Curry = require("./curry.js");
var Caml_obj = require("./caml_obj.js");
var Caml_exceptions = require("./caml_exceptions.js");
function new_block_with_tag(tag, value) {
var x = /* obj_block */Block.__(tag, [0]);
x[0] = value;
return x;
}
function from_fun(f) {
return new_block_with_tag(246, f);
}
function from_val(v) {
var t = v.tag | 0;
if (t === 250 || t === 246 || false) {
return new_block_with_tag(250, v);
} else {
return v;
}
}
function forward_with_closure(blk, closure) {
var result = Curry._1(closure, undefined);
blk[0] = result;
Caml_obj.caml_obj_set_tag(blk, 250);
return result;
}
var Undefined = Caml_exceptions.create("CamlinternalLazy.Undefined");
function raise_undefined(param) {
throw Undefined;
}
function force(lzv) {
var t = lzv.tag | 0;
if (t === 250) {
return lzv[0];
} else if (t !== 246) {
return lzv;
} else {
var closure = lzv[0];
lzv[0] = raise_undefined;
try {
return forward_with_closure(lzv, closure);
}
catch (e){
lzv[0] = (function (param) {
throw e;
});
throw e;
}
}
}
function force_val(lzv) {
var t = lzv.tag | 0;
if (t === 250) {
return lzv[0];
} else if (t !== 246) {
return lzv;
} else {
var closure = lzv[0];
lzv[0] = raise_undefined;
return forward_with_closure(lzv, closure);
}
}
function is_val(l) {
return (l.tag | 0) !== 246;
}
exports.Undefined = Undefined;
exports.force = force;
exports.force_val = force_val;
exports.from_fun = from_fun;
exports.from_val = from_val;
exports.is_val = is_val;
/* No side effect */