@live-codes/ocaml 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +220 -0
- package/README.md +165 -2
- package/THIRD-PARTY-NOTICES.md +52 -0
- package/assets/compiler/compile_stdout.browser.js +27856 -0
- package/assets/compiler/jsoo.js +12631 -0
- package/assets/compiler/package.json +3 -0
- package/assets/compiler/runtime/bigarray.js +1072 -0
- package/assets/compiler/runtime/bigstring.js +137 -0
- package/assets/compiler/runtime/domain.js +393 -0
- package/assets/compiler/runtime/dynlink.js +91 -0
- package/assets/compiler/runtime/float32.js +486 -0
- package/assets/compiler/runtime/fs.js +416 -0
- package/assets/compiler/runtime/fs_fake.js +600 -0
- package/assets/compiler/runtime/fs_node.js +609 -0
- package/assets/compiler/runtime/fs_quickjs.js +532 -0
- package/assets/compiler/runtime/gc.js +201 -0
- package/assets/compiler/runtime/graphics.js +1053 -0
- package/assets/compiler/runtime/ieee_754.js +621 -0
- package/assets/compiler/runtime/int64.js +516 -0
- package/assets/compiler/runtime/io.js +739 -0
- package/assets/compiler/runtime/jslib.js +553 -0
- package/assets/compiler/runtime/jslib_js_of_ocaml.js +81 -0
- package/assets/compiler/runtime/lexing.js +240 -0
- package/assets/compiler/runtime/manifest.txt +31 -0
- package/assets/compiler/runtime/marshal.js +863 -0
- package/assets/compiler/runtime/md5.js +236 -0
- package/assets/compiler/runtime/mlBytes.js +1007 -0
- package/assets/compiler/runtime/nat.js +469 -0
- package/assets/compiler/runtime/parsing.js +317 -0
- package/assets/compiler/runtime/prng.js +84 -0
- package/assets/compiler/runtime/promise.js +45 -0
- package/assets/compiler/runtime/runtime.js +16688 -0
- package/assets/compiler/runtime/runtime_events.js +90 -0
- package/assets/compiler/runtime/stdlib.js +363 -0
- package/assets/compiler/runtime/sync.js +35 -0
- package/assets/compiler/runtime/toplevel.js +150 -0
- package/assets/compiler/runtime/unix.js +914 -0
- package/assets/compiler/runtime/weak.js +247 -0
- package/assets/compiler/stdlib.js +254 -0
- package/assets/compiler/worker.js +46 -0
- package/assets/interpreter/libs/greet.cma +0 -0
- package/assets/interpreter/libs/greet.cmi +0 -0
- package/assets/interpreter/libs/manifest.txt +1 -0
- package/assets/interpreter/package.json +3 -0
- package/assets/interpreter/stdlib/camlinternalFormat.cmi +0 -0
- package/assets/interpreter/stdlib/camlinternalFormatBasics.cmi +0 -0
- package/assets/interpreter/stdlib/camlinternalLazy.cmi +0 -0
- package/assets/interpreter/stdlib/camlinternalMod.cmi +0 -0
- package/assets/interpreter/stdlib/camlinternalOO.cmi +0 -0
- package/assets/interpreter/stdlib/std_exit.cmi +0 -0
- package/assets/interpreter/stdlib/stdlib.cmi +0 -0
- package/assets/interpreter/stdlib/stdlib__Arg.cmi +0 -0
- package/assets/interpreter/stdlib/stdlib__Array.cmi +0 -0
- package/assets/interpreter/stdlib/stdlib__ArrayLabels.cmi +0 -0
- package/assets/interpreter/stdlib/stdlib__Atomic.cmi +0 -0
- package/assets/interpreter/stdlib/stdlib__Bigarray.cmi +0 -0
- package/assets/interpreter/stdlib/stdlib__Bool.cmi +0 -0
- package/assets/interpreter/stdlib/stdlib__Buffer.cmi +0 -0
- package/assets/interpreter/stdlib/stdlib__Bytes.cmi +0 -0
- package/assets/interpreter/stdlib/stdlib__BytesLabels.cmi +0 -0
- package/assets/interpreter/stdlib/stdlib__Callback.cmi +0 -0
- package/assets/interpreter/stdlib/stdlib__Char.cmi +0 -0
- package/assets/interpreter/stdlib/stdlib__Complex.cmi +0 -0
- package/assets/interpreter/stdlib/stdlib__Condition.cmi +0 -0
- package/assets/interpreter/stdlib/stdlib__Digest.cmi +0 -0
- package/assets/interpreter/stdlib/stdlib__Domain.cmi +0 -0
- package/assets/interpreter/stdlib/stdlib__Dynarray.cmi +0 -0
- package/assets/interpreter/stdlib/stdlib__Effect.cmi +0 -0
- package/assets/interpreter/stdlib/stdlib__Either.cmi +0 -0
- package/assets/interpreter/stdlib/stdlib__Ephemeron.cmi +0 -0
- package/assets/interpreter/stdlib/stdlib__Filename.cmi +0 -0
- package/assets/interpreter/stdlib/stdlib__Float.cmi +0 -0
- package/assets/interpreter/stdlib/stdlib__Format.cmi +0 -0
- package/assets/interpreter/stdlib/stdlib__Fun.cmi +0 -0
- package/assets/interpreter/stdlib/stdlib__Gc.cmi +0 -0
- package/assets/interpreter/stdlib/stdlib__Hashtbl.cmi +0 -0
- package/assets/interpreter/stdlib/stdlib__Iarray.cmi +0 -0
- package/assets/interpreter/stdlib/stdlib__In_channel.cmi +0 -0
- package/assets/interpreter/stdlib/stdlib__Int.cmi +0 -0
- package/assets/interpreter/stdlib/stdlib__Int32.cmi +0 -0
- package/assets/interpreter/stdlib/stdlib__Int64.cmi +0 -0
- package/assets/interpreter/stdlib/stdlib__Lazy.cmi +0 -0
- package/assets/interpreter/stdlib/stdlib__Lexing.cmi +0 -0
- package/assets/interpreter/stdlib/stdlib__List.cmi +0 -0
- package/assets/interpreter/stdlib/stdlib__ListLabels.cmi +0 -0
- package/assets/interpreter/stdlib/stdlib__Map.cmi +0 -0
- package/assets/interpreter/stdlib/stdlib__Marshal.cmi +0 -0
- package/assets/interpreter/stdlib/stdlib__MoreLabels.cmi +0 -0
- package/assets/interpreter/stdlib/stdlib__Mutex.cmi +0 -0
- package/assets/interpreter/stdlib/stdlib__Nativeint.cmi +0 -0
- package/assets/interpreter/stdlib/stdlib__Obj.cmi +0 -0
- package/assets/interpreter/stdlib/stdlib__Oo.cmi +0 -0
- package/assets/interpreter/stdlib/stdlib__Option.cmi +0 -0
- package/assets/interpreter/stdlib/stdlib__Out_channel.cmi +0 -0
- package/assets/interpreter/stdlib/stdlib__Pair.cmi +0 -0
- package/assets/interpreter/stdlib/stdlib__Parsing.cmi +0 -0
- package/assets/interpreter/stdlib/stdlib__Pqueue.cmi +0 -0
- package/assets/interpreter/stdlib/stdlib__Printexc.cmi +0 -0
- package/assets/interpreter/stdlib/stdlib__Printf.cmi +0 -0
- package/assets/interpreter/stdlib/stdlib__Queue.cmi +0 -0
- package/assets/interpreter/stdlib/stdlib__Random.cmi +0 -0
- package/assets/interpreter/stdlib/stdlib__Repr.cmi +0 -0
- package/assets/interpreter/stdlib/stdlib__Result.cmi +0 -0
- package/assets/interpreter/stdlib/stdlib__Scanf.cmi +0 -0
- package/assets/interpreter/stdlib/stdlib__Semaphore.cmi +0 -0
- package/assets/interpreter/stdlib/stdlib__Seq.cmi +0 -0
- package/assets/interpreter/stdlib/stdlib__Set.cmi +0 -0
- package/assets/interpreter/stdlib/stdlib__Stack.cmi +0 -0
- package/assets/interpreter/stdlib/stdlib__StdLabels.cmi +0 -0
- package/assets/interpreter/stdlib/stdlib__String.cmi +0 -0
- package/assets/interpreter/stdlib/stdlib__StringLabels.cmi +0 -0
- package/assets/interpreter/stdlib/stdlib__Sys.cmi +0 -0
- package/assets/interpreter/stdlib/stdlib__Type.cmi +0 -0
- package/assets/interpreter/stdlib/stdlib__Uchar.cmi +0 -0
- package/assets/interpreter/stdlib/stdlib__Unit.cmi +0 -0
- package/assets/interpreter/stdlib/stdlib__Weak.cmi +0 -0
- package/assets/interpreter/stdlib/topdirs.cmi +0 -0
- package/assets/interpreter/stdlib/units.txt +75 -0
- package/assets/interpreter/stdlib/unix.cmi +0 -0
- package/assets/interpreter/stdlib/unixLabels.cmi +0 -0
- package/assets/interpreter/worker-entry.js +39 -0
- package/assets/interpreter/worker.js +42356 -0
- package/bin/copy-assets.mjs +75 -0
- package/package.json +41 -4
- package/src/compiler/compile.js +170 -0
- package/src/compiler/index.js +46 -0
- package/src/compiler/worker.js +46 -0
- package/src/index.js +12 -0
- package/src/interpreter/api.js +182 -0
- package/src/interpreter/index.js +5 -0
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
// Js_of_ocaml runtime support
|
|
2
|
+
// http://www.ocsigen.org/js_of_ocaml/
|
|
3
|
+
// Copyright (C) 2010 Jérôme Vouillon
|
|
4
|
+
// Laboratoire PPS - CNRS Université Paris Diderot
|
|
5
|
+
//
|
|
6
|
+
// This program is free software; you can redistribute it and/or modify
|
|
7
|
+
// it under the terms of the GNU Lesser General Public License as published by
|
|
8
|
+
// the Free Software Foundation, with linking exception;
|
|
9
|
+
// either version 2.1 of the License, or (at your option) any later version.
|
|
10
|
+
//
|
|
11
|
+
// This program is distributed in the hope that it will be useful,
|
|
12
|
+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
13
|
+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
14
|
+
// GNU Lesser General Public License for more details.
|
|
15
|
+
//
|
|
16
|
+
// You should have received a copy of the GNU Lesser General Public License
|
|
17
|
+
// along with this program; if not, write to the Free Software
|
|
18
|
+
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
19
|
+
|
|
20
|
+
// Weak API
|
|
21
|
+
|
|
22
|
+
//Provides: caml_ephe_key_offset
|
|
23
|
+
var caml_ephe_key_offset = 3;
|
|
24
|
+
|
|
25
|
+
//Provides: caml_ephe_data_offset
|
|
26
|
+
var caml_ephe_data_offset = 2;
|
|
27
|
+
|
|
28
|
+
//Provides: caml_ephe_none
|
|
29
|
+
var caml_ephe_none = { caml_ephe_none: 0 };
|
|
30
|
+
|
|
31
|
+
//Provides: caml_ephe_set_key
|
|
32
|
+
//Requires: caml_ephe_key_offset
|
|
33
|
+
//Requires: caml_ephe_get_data
|
|
34
|
+
//Requires: caml_ephe_set_data_opt
|
|
35
|
+
function caml_ephe_set_key(x, i, v) {
|
|
36
|
+
var old = caml_ephe_get_data(x);
|
|
37
|
+
if (globalThis.WeakRef && v instanceof Object) v = new globalThis.WeakRef(v);
|
|
38
|
+
x[caml_ephe_key_offset + i] = v;
|
|
39
|
+
caml_ephe_set_data_opt(x, old);
|
|
40
|
+
return 0;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
//Provides: caml_ephe_unset_key
|
|
44
|
+
//Requires: caml_ephe_key_offset
|
|
45
|
+
//Requires: caml_ephe_get_data
|
|
46
|
+
//Requires: caml_ephe_set_data_opt
|
|
47
|
+
//Requires: caml_ephe_none
|
|
48
|
+
function caml_ephe_unset_key(x, i) {
|
|
49
|
+
var old = caml_ephe_get_data(x);
|
|
50
|
+
x[caml_ephe_key_offset + i] = caml_ephe_none;
|
|
51
|
+
caml_ephe_set_data_opt(x, old);
|
|
52
|
+
return 0;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
//Provides: caml_ephe_create
|
|
56
|
+
//Requires: caml_weak_create
|
|
57
|
+
function caml_ephe_create(n) {
|
|
58
|
+
return caml_weak_create(n);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
//Provides: caml_weak_create
|
|
62
|
+
//Requires: caml_ephe_key_offset
|
|
63
|
+
//Requires: caml_ephe_none
|
|
64
|
+
function caml_weak_create(n) {
|
|
65
|
+
var alen = caml_ephe_key_offset + n;
|
|
66
|
+
var x = new Array(alen);
|
|
67
|
+
x[0] = 251;
|
|
68
|
+
x[1] = "caml_ephe_list_head";
|
|
69
|
+
for (var i = 2; i < alen; i++) {
|
|
70
|
+
x[i] = caml_ephe_none;
|
|
71
|
+
}
|
|
72
|
+
return x;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
//Provides: caml_weak_set
|
|
76
|
+
//Requires: caml_ephe_set_key, caml_ephe_unset_key
|
|
77
|
+
function caml_weak_set(x, i, v) {
|
|
78
|
+
if (v === 0) caml_ephe_unset_key(x, i);
|
|
79
|
+
else caml_ephe_set_key(x, i, v[1]);
|
|
80
|
+
return 0;
|
|
81
|
+
}
|
|
82
|
+
//Provides: caml_ephe_get_key
|
|
83
|
+
//Requires: caml_ephe_key_offset, caml_ephe_data_offset
|
|
84
|
+
//Requires: caml_ephe_none
|
|
85
|
+
//Alias: caml_weak_get
|
|
86
|
+
|
|
87
|
+
function caml_ephe_get_key(x, i) {
|
|
88
|
+
var weak = x[caml_ephe_key_offset + i];
|
|
89
|
+
if (weak === caml_ephe_none) return 0;
|
|
90
|
+
if (globalThis.WeakRef && weak instanceof globalThis.WeakRef) {
|
|
91
|
+
weak = weak.deref();
|
|
92
|
+
if (weak === undefined) {
|
|
93
|
+
x[caml_ephe_key_offset + i] = caml_ephe_none;
|
|
94
|
+
x[caml_ephe_data_offset] = caml_ephe_none;
|
|
95
|
+
return 0;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
return [0, weak];
|
|
99
|
+
}
|
|
100
|
+
//Provides: caml_ephe_get_key_copy
|
|
101
|
+
//Requires: caml_ephe_get_key,caml_ephe_key_offset
|
|
102
|
+
//Requires: caml_obj_dup, caml_is_ml_bytes
|
|
103
|
+
//Alias: caml_weak_get_copy
|
|
104
|
+
function caml_ephe_get_key_copy(x, i) {
|
|
105
|
+
var y = caml_ephe_get_key(x, i);
|
|
106
|
+
if (y === 0) return y;
|
|
107
|
+
var z = y[1];
|
|
108
|
+
if (Array.isArray(z) || caml_is_ml_bytes(z)) return [0, caml_obj_dup(z)];
|
|
109
|
+
return y;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
//Provides: caml_ephe_check_key mutable
|
|
113
|
+
//Requires: caml_ephe_key_offset, caml_ephe_data_offset
|
|
114
|
+
//Requires: caml_ephe_none
|
|
115
|
+
//Alias: caml_weak_check
|
|
116
|
+
function caml_ephe_check_key(x, i) {
|
|
117
|
+
var weak = x[caml_ephe_key_offset + i];
|
|
118
|
+
if (weak === caml_ephe_none) return 0;
|
|
119
|
+
if (globalThis.WeakRef && weak instanceof globalThis.WeakRef) {
|
|
120
|
+
weak = weak.deref();
|
|
121
|
+
if (weak === undefined) {
|
|
122
|
+
x[caml_ephe_key_offset + i] = caml_ephe_none;
|
|
123
|
+
x[caml_ephe_data_offset] = caml_ephe_none;
|
|
124
|
+
return 0;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
return 1;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
//Provides: caml_ephe_blit_key
|
|
131
|
+
//Requires: caml_array_blit
|
|
132
|
+
//Requires: caml_ephe_key_offset
|
|
133
|
+
//Requires: caml_ephe_get_data
|
|
134
|
+
//Requires: caml_ephe_set_data_opt
|
|
135
|
+
//Alias: caml_weak_blit
|
|
136
|
+
function caml_ephe_blit_key(a1, i1, a2, i2, len) {
|
|
137
|
+
// The data is stored wrapped in WeakMaps keyed on the (live) keys, so
|
|
138
|
+
// fetch the destination's data before changing its keys and store it
|
|
139
|
+
// back afterwards.
|
|
140
|
+
var old = caml_ephe_get_data(a2);
|
|
141
|
+
// minus one because caml_array_blit works on ocaml array
|
|
142
|
+
caml_array_blit(
|
|
143
|
+
a1,
|
|
144
|
+
caml_ephe_key_offset + i1 - 1,
|
|
145
|
+
a2,
|
|
146
|
+
caml_ephe_key_offset + i2 - 1,
|
|
147
|
+
len,
|
|
148
|
+
);
|
|
149
|
+
caml_ephe_set_data_opt(a2, old);
|
|
150
|
+
return 0;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
//Provides: caml_ephe_blit_data
|
|
154
|
+
//Requires: caml_ephe_get_data, caml_ephe_set_data_opt
|
|
155
|
+
function caml_ephe_blit_data(src, dst) {
|
|
156
|
+
var old = caml_ephe_get_data(src);
|
|
157
|
+
caml_ephe_set_data_opt(dst, old);
|
|
158
|
+
return 0;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
//Provides: caml_ephe_get_data
|
|
162
|
+
//Requires: caml_ephe_data_offset, caml_ephe_key_offset
|
|
163
|
+
//Requires: caml_ephe_none
|
|
164
|
+
function caml_ephe_get_data(x) {
|
|
165
|
+
var data = x[caml_ephe_data_offset];
|
|
166
|
+
if (data === caml_ephe_none) return 0;
|
|
167
|
+
for (var i = caml_ephe_key_offset; i < x.length; i++) {
|
|
168
|
+
var k = x[i];
|
|
169
|
+
if (globalThis.WeakRef && k instanceof globalThis.WeakRef) {
|
|
170
|
+
var d = k.deref();
|
|
171
|
+
if (d === undefined) {
|
|
172
|
+
x[i] = caml_ephe_none;
|
|
173
|
+
x[caml_ephe_data_offset] = caml_ephe_none;
|
|
174
|
+
return 0;
|
|
175
|
+
}
|
|
176
|
+
if (globalThis.WeakMap) {
|
|
177
|
+
data = data.get(d);
|
|
178
|
+
if (data === undefined) {
|
|
179
|
+
x[caml_ephe_data_offset] = caml_ephe_none;
|
|
180
|
+
return 0;
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
return [0, data];
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
//Provides: caml_ephe_get_data_copy
|
|
189
|
+
//Requires: caml_ephe_get_data
|
|
190
|
+
//Requires: caml_obj_dup, caml_is_ml_bytes
|
|
191
|
+
function caml_ephe_get_data_copy(x) {
|
|
192
|
+
var r = caml_ephe_get_data(x);
|
|
193
|
+
if (r === 0) return 0;
|
|
194
|
+
var z = r[1];
|
|
195
|
+
if (Array.isArray(z) || caml_is_ml_bytes(z)) return [0, caml_obj_dup(z)];
|
|
196
|
+
return r;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
//Provides: caml_ephe_set_data
|
|
200
|
+
//Requires: caml_ephe_data_offset, caml_ephe_key_offset
|
|
201
|
+
//Requires: caml_ephe_none
|
|
202
|
+
function caml_ephe_set_data(x, data) {
|
|
203
|
+
for (var i = x.length - 1; i >= caml_ephe_key_offset; i--) {
|
|
204
|
+
var k = x[i];
|
|
205
|
+
if (globalThis.WeakRef && k instanceof globalThis.WeakRef) {
|
|
206
|
+
var d = k.deref();
|
|
207
|
+
if (d === undefined) {
|
|
208
|
+
x[i] = caml_ephe_none;
|
|
209
|
+
continue;
|
|
210
|
+
}
|
|
211
|
+
if (globalThis.WeakMap) {
|
|
212
|
+
// Key the map on the key object itself (not the WeakRef
|
|
213
|
+
// wrapper, which the ephemeron strongly holds): the data must
|
|
214
|
+
// be reachable only while the key is, so that key <-> data
|
|
215
|
+
// cycles can be collected.
|
|
216
|
+
data = new globalThis.WeakMap().set(d, data);
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
x[caml_ephe_data_offset] = data;
|
|
221
|
+
return 0;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
//Provides: caml_ephe_set_data_opt
|
|
225
|
+
//Requires: caml_ephe_set_data
|
|
226
|
+
//Requires: caml_ephe_unset_data
|
|
227
|
+
function caml_ephe_set_data_opt(x, data_opt) {
|
|
228
|
+
if (data_opt === 0) caml_ephe_unset_data(x);
|
|
229
|
+
else caml_ephe_set_data(x, data_opt[1]);
|
|
230
|
+
return 0;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
//Provides: caml_ephe_unset_data
|
|
234
|
+
//Requires: caml_ephe_data_offset
|
|
235
|
+
//Requires: caml_ephe_none
|
|
236
|
+
function caml_ephe_unset_data(x) {
|
|
237
|
+
x[caml_ephe_data_offset] = caml_ephe_none;
|
|
238
|
+
return 0;
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
//Provides: caml_ephe_check_data
|
|
242
|
+
//Requires: caml_ephe_get_data
|
|
243
|
+
function caml_ephe_check_data(x) {
|
|
244
|
+
var data = caml_ephe_get_data(x);
|
|
245
|
+
if (data === 0) return 0;
|
|
246
|
+
else return 1;
|
|
247
|
+
}
|