forked from rescript-lang/rescript
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcaml_module.js
115 lines (108 loc) · 2.54 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
114
115
'use strict';
var Caml_obj = require("./caml_obj.js");
function init_mod(loc, shape) {
var undef_module = function (param) {
throw {
RE_EXN_ID: "Undefined_recursive_module",
_1: loc,
Error: new Error()
};
};
var loop = function (shape, struct_, idx) {
if (typeof shape === "number") {
switch (shape) {
case /* Function */0 :
struct_[idx] = undef_module;
return ;
case /* Lazy */1 :
struct_[idx] = {
LAZY_DONE: true,
VAL: undef_module
};
return ;
case /* Class */2 :
struct_[idx] = [
undef_module,
undef_module,
undef_module,
0
];
return ;
}
} else {
if (shape.TAG) {
struct_[idx] = shape._0;
return ;
}
var comps = shape._0;
var v = {};
struct_[idx] = v;
var len = comps.length;
for(var i = 0; i < len; ++i){
var match = comps[i];
loop(match[0], v, match[1]);
}
return ;
}
};
var res = {};
var dummy_name = "dummy";
loop(shape, res, dummy_name);
return res[dummy_name];
}
function update_mod(shape, o, n) {
var aux = function (shape, o, n, parent, i) {
if (typeof shape === "number") {
switch (shape) {
case /* Function */0 :
parent[i] = n;
return ;
case /* Lazy */1 :
case /* Class */2 :
return Caml_obj.update_dummy(o, n);
}
} else {
if (shape.TAG) {
return ;
}
var comps = shape._0;
for(var i$1 = 0 ,i_finish = comps.length; i$1 < i_finish; ++i$1){
var match = comps[i$1];
var name = match[1];
aux(match[0], o[name], n[name], o, name);
}
return ;
}
};
if (typeof shape === "number") {
throw {
RE_EXN_ID: "Assert_failure",
_1: [
"caml_module.ml",
107,
10
],
Error: new Error()
};
}
if (shape.TAG) {
throw {
RE_EXN_ID: "Assert_failure",
_1: [
"caml_module.ml",
107,
10
],
Error: new Error()
};
}
var comps = shape._0;
for(var i = 0 ,i_finish = comps.length; i < i_finish; ++i){
var match = comps[i];
var name = match[1];
aux(match[0], o[name], n[name], o, name);
}
}
exports.init_mod = init_mod;
exports.update_mod = update_mod;
/* No side effect */