forked from rescript-lang/rescript
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcaml_module.js
113 lines (108 loc) · 2.38 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
101
102
103
104
105
106
107
108
109
110
111
112
113
import * as Caml_obj from "./caml_obj.js";
function init_mod(loc, shape) {
let undef_module = param => {
throw new Error("Undefined_recursive_module", {
cause: {
RE_EXN_ID: "Undefined_recursive_module",
_1: loc
}
});
};
let loop = (shape, struct_, idx) => {
if (typeof shape !== "object") {
switch (shape) {
case "Function" :
case "Lazy" :
struct_[idx] = undef_module;
return;
case "Class" :
struct_[idx] = [
undef_module,
undef_module,
undef_module,
0
];
return;
}
} else {
if (shape.TAG === "Module") {
let comps = shape._0;
let v = {};
struct_[idx] = v;
let len = comps.length;
for (let i = 0; i < len; ++i) {
let match = comps[i];
loop(match[0], v, match[1]);
}
return;
}
struct_[idx] = shape._0;
return;
}
};
let res = {};
let dummy_name = "dummy";
loop(shape, res, dummy_name);
return res[dummy_name];
}
function update_mod(shape, o, n) {
let aux = (shape, o, n, parent, i) => {
if (typeof shape !== "object") {
switch (shape) {
case "Function" :
parent[i] = n;
return;
case "Lazy" :
case "Class" :
return Caml_obj.update_dummy(o, n);
}
} else {
if (shape.TAG !== "Module") {
return;
}
let comps = shape._0;
for (let i$1 = 0, i_finish = comps.length; i$1 < i_finish; ++i$1) {
let match = comps[i$1];
let name = match[1];
aux(match[0], o[name], n[name], o, name);
}
return;
}
};
if (typeof shape !== "object") {
throw new Error("Assert_failure", {
cause: {
RE_EXN_ID: "Assert_failure",
_1: [
"caml_module.res",
109,
9
]
}
});
}
if (shape.TAG === "Module") {
let comps = shape._0;
for (let i = 0, i_finish = comps.length; i < i_finish; ++i) {
let match = comps[i];
let name = match[1];
aux(match[0], o[name], n[name], o, name);
}
return;
}
throw new Error("Assert_failure", {
cause: {
RE_EXN_ID: "Assert_failure",
_1: [
"caml_module.res",
109,
9
]
}
});
}
export {
init_mod,
update_mod,
}
/* No side effect */