forked from rescript-lang/rescript
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcaml_module.js
100 lines (94 loc) · 2.34 KB
/
caml_module.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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
'use strict';
var Caml_obj = require("./caml_obj");
var Caml_builtin_exceptions = require("./caml_builtin_exceptions");
function init_mod(loc, shape) {
var undef_module = function () {
throw [
Caml_builtin_exceptions.undefined_recursive_module,
loc
];
};
var loop = function (shape, struct_, idx) {
if (typeof shape === "number") {
switch (shape) {
case 0 :
case 1 :
struct_[idx] = undef_module;
return /* () */0;
case 2 :
struct_[idx] = /* tuple */[
undef_module,
undef_module,
undef_module,
0
];
return /* () */0;
}
} else if (shape.tag) {
struct_[idx] = shape[0];
return /* () */0;
} else {
var comps = shape[0];
var v = /* array */[];
struct_[idx] = v;
var len = comps.length;
for(var i = 0 ,i_finish = len - 1 | 0; i <= i_finish; ++i){
loop(comps[i], v, i);
}
return /* () */0;
}
};
var res = /* array */[];
loop(shape, res, 0);
return res[0];
}
function update_mod(shape, o, n) {
var aux = function (shape, o, n, parent, i) {
if (typeof shape === "number") {
switch (shape) {
case 0 :
parent[i] = n;
return /* () */0;
case 1 :
case 2 :
return Caml_obj.caml_update_dummy(o, n);
}
} else if (shape.tag) {
return /* () */0;
} else {
var comps = shape[0];
for(var i$1 = 0 ,i_finish = comps.length - 1 | 0; i$1 <= i_finish; ++i$1){
aux(comps[i$1], o[i$1], n[i$1], o, i$1);
}
return /* () */0;
}
};
if (typeof shape === "number") {
throw [
Caml_builtin_exceptions.assert_failure,
[
"caml_module.ml",
82,
10
]
];
} else if (shape.tag) {
throw [
Caml_builtin_exceptions.assert_failure,
[
"caml_module.ml",
82,
10
]
];
} else {
var comps = shape[0];
for(var i = 0 ,i_finish = comps.length - 1 | 0; i <= i_finish; ++i){
aux(comps[i], o[i], n[i], o, i);
}
return /* () */0;
}
}
exports.init_mod = init_mod;
exports.update_mod = update_mod;
/* No side effect */