@live-codes/ocaml 0.0.0-stage → 0.1.1
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 +195 -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,137 @@
|
|
|
1
|
+
///////// BIGSTRING
|
|
2
|
+
|
|
3
|
+
//Provides: caml_hash_mix_bigstring
|
|
4
|
+
//Requires: caml_hash_mix_bytes_arr
|
|
5
|
+
function caml_hash_mix_bigstring(h, bs) {
|
|
6
|
+
return caml_hash_mix_bytes_arr(h, bs.data);
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
//Provides: bigstring_to_array_buffer mutable
|
|
10
|
+
function bigstring_to_array_buffer(bs) {
|
|
11
|
+
return bs.data.buffer;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
//Provides: bigstring_to_typed_array mutable
|
|
15
|
+
function bigstring_to_typed_array(bs) {
|
|
16
|
+
return bs.data;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
//Provides: bigstring_of_array_buffer mutable
|
|
20
|
+
//Requires: caml_ba_create_unsafe
|
|
21
|
+
function bigstring_of_array_buffer(ab) {
|
|
22
|
+
var ta = new Uint8Array(ab);
|
|
23
|
+
return caml_ba_create_unsafe(12, 0, [ta.length], ta);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
//Provides: bigstring_of_typed_array mutable
|
|
27
|
+
//Requires: caml_ba_create_unsafe
|
|
28
|
+
function bigstring_of_typed_array(ba) {
|
|
29
|
+
var ta = new Uint8Array(
|
|
30
|
+
ba.buffer,
|
|
31
|
+
ba.byteOffset,
|
|
32
|
+
ba.length * ba.BYTES_PER_ELEMENT,
|
|
33
|
+
);
|
|
34
|
+
return caml_ba_create_unsafe(12, 0, [ta.length], ta);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
//Provides: caml_bigstring_memcmp
|
|
38
|
+
//Requires: caml_ba_get_1
|
|
39
|
+
function caml_bigstring_memcmp(s1, pos1, s2, pos2, len) {
|
|
40
|
+
for (var i = 0; i < len; i++) {
|
|
41
|
+
var a = caml_ba_get_1(s1, pos1 + i);
|
|
42
|
+
var b = caml_ba_get_1(s2, pos2 + i);
|
|
43
|
+
if (a < b) return -1;
|
|
44
|
+
if (a > b) return 1;
|
|
45
|
+
}
|
|
46
|
+
return 0;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
//Provides: caml_bigstring_blit_ba_to_ba
|
|
50
|
+
//Requires: caml_invalid_argument, caml_array_bound_error
|
|
51
|
+
function caml_bigstring_blit_ba_to_ba(ba1, pos1, ba2, pos2, len) {
|
|
52
|
+
if (12 !== ba1.kind)
|
|
53
|
+
caml_invalid_argument("caml_bigstring_blit_ba_to_ba: kind mismatch");
|
|
54
|
+
if (12 !== ba2.kind)
|
|
55
|
+
caml_invalid_argument("caml_bigstring_blit_ba_to_ba: kind mismatch");
|
|
56
|
+
if (len === 0) return 0;
|
|
57
|
+
// Positions are raw offsets from the start of the data, ignoring the
|
|
58
|
+
// layout: these primitives back base_bigstring's bigstring_blit_*
|
|
59
|
+
// stubs, whose C code indexes from `data + pos` (and so does the Wasm
|
|
60
|
+
// runtime here)
|
|
61
|
+
if (pos1 < 0 || pos1 + len > ba1.data.length) {
|
|
62
|
+
caml_array_bound_error();
|
|
63
|
+
}
|
|
64
|
+
if (pos2 < 0 || pos2 + len > ba2.data.length) {
|
|
65
|
+
caml_array_bound_error();
|
|
66
|
+
}
|
|
67
|
+
var slice = ba1.data.subarray(pos1, pos1 + len);
|
|
68
|
+
ba2.data.set(slice, pos2);
|
|
69
|
+
return 0;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
//Provides: caml_bigstring_blit_string_to_ba
|
|
73
|
+
//Requires: caml_invalid_argument, caml_array_bound_error, caml_uint8_array_of_string
|
|
74
|
+
//Requires: caml_ml_string_length
|
|
75
|
+
function caml_bigstring_blit_string_to_ba(str1, pos1, ba2, pos2, len) {
|
|
76
|
+
if (12 !== ba2.kind)
|
|
77
|
+
caml_invalid_argument("caml_bigstring_blit_string_to_ba: kind mismatch");
|
|
78
|
+
if (len === 0) return 0;
|
|
79
|
+
// Positions are raw offsets from the start of the data, ignoring the
|
|
80
|
+
// layout: these primitives back base_bigstring's bigstring_blit_*
|
|
81
|
+
// stubs, whose C code indexes from `data + pos` (and so does the Wasm
|
|
82
|
+
// runtime here)
|
|
83
|
+
if (pos1 < 0 || pos1 + len > caml_ml_string_length(str1)) {
|
|
84
|
+
caml_array_bound_error();
|
|
85
|
+
}
|
|
86
|
+
if (pos2 < 0 || pos2 + len > ba2.data.length) {
|
|
87
|
+
caml_array_bound_error();
|
|
88
|
+
}
|
|
89
|
+
var slice = caml_uint8_array_of_string(str1).subarray(pos1, pos1 + len);
|
|
90
|
+
ba2.data.set(slice, pos2);
|
|
91
|
+
return 0;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
//Provides: caml_bigstring_blit_bytes_to_ba
|
|
95
|
+
//Requires: caml_invalid_argument, caml_array_bound_error, caml_uint8_array_of_bytes
|
|
96
|
+
//Requires: caml_ml_bytes_length
|
|
97
|
+
function caml_bigstring_blit_bytes_to_ba(str1, pos1, ba2, pos2, len) {
|
|
98
|
+
if (12 !== ba2.kind)
|
|
99
|
+
caml_invalid_argument("caml_bigstring_blit_bytes_to_ba: kind mismatch");
|
|
100
|
+
if (len === 0) return 0;
|
|
101
|
+
// Positions are raw offsets from the start of the data, ignoring the
|
|
102
|
+
// layout: these primitives back base_bigstring's bigstring_blit_*
|
|
103
|
+
// stubs, whose C code indexes from `data + pos` (and so does the Wasm
|
|
104
|
+
// runtime here)
|
|
105
|
+
if (pos1 < 0 || pos1 + len > caml_ml_bytes_length(str1)) {
|
|
106
|
+
caml_array_bound_error();
|
|
107
|
+
}
|
|
108
|
+
if (pos2 < 0 || pos2 + len > ba2.data.length) {
|
|
109
|
+
caml_array_bound_error();
|
|
110
|
+
}
|
|
111
|
+
var slice = caml_uint8_array_of_bytes(str1).subarray(pos1, pos1 + len);
|
|
112
|
+
ba2.data.set(slice, pos2);
|
|
113
|
+
return 0;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
//Provides: caml_bigstring_blit_ba_to_bytes
|
|
117
|
+
//Requires: caml_invalid_argument, caml_array_bound_error
|
|
118
|
+
//Requires: caml_blit_bytes, caml_bytes_of_uint8_array
|
|
119
|
+
//Requires: caml_ml_bytes_length
|
|
120
|
+
function caml_bigstring_blit_ba_to_bytes(ba1, pos1, bytes2, pos2, len) {
|
|
121
|
+
if (12 !== ba1.kind)
|
|
122
|
+
caml_invalid_argument("caml_bigstring_blit_ba_to_bytes: kind mismatch");
|
|
123
|
+
if (len === 0) return 0;
|
|
124
|
+
// Positions are raw offsets from the start of the data, ignoring the
|
|
125
|
+
// layout: these primitives back base_bigstring's bigstring_blit_*
|
|
126
|
+
// stubs, whose C code indexes from `data + pos` (and so does the Wasm
|
|
127
|
+
// runtime here)
|
|
128
|
+
if (pos1 < 0 || pos1 + len > ba1.data.length) {
|
|
129
|
+
caml_array_bound_error();
|
|
130
|
+
}
|
|
131
|
+
if (pos2 < 0 || pos2 + len > caml_ml_bytes_length(bytes2)) {
|
|
132
|
+
caml_array_bound_error();
|
|
133
|
+
}
|
|
134
|
+
var slice = ba1.data.subarray(pos1, pos1 + len);
|
|
135
|
+
caml_blit_bytes(caml_bytes_of_uint8_array(slice), 0, bytes2, pos2, len);
|
|
136
|
+
return 0;
|
|
137
|
+
}
|
|
@@ -0,0 +1,393 @@
|
|
|
1
|
+
//Provides: caml_domain_dls
|
|
2
|
+
//Version: >= 5
|
|
3
|
+
var caml_domain_dls = [0];
|
|
4
|
+
|
|
5
|
+
//Provides: caml_domain_dls_set
|
|
6
|
+
//Requires: caml_domain_dls
|
|
7
|
+
//Version: >= 5
|
|
8
|
+
function caml_domain_dls_set(a) {
|
|
9
|
+
caml_domain_dls = a;
|
|
10
|
+
return 0;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
//Provides: caml_domain_dls_compare_and_set
|
|
14
|
+
//Requires: caml_domain_dls
|
|
15
|
+
//Version: >= 5.2
|
|
16
|
+
function caml_domain_dls_compare_and_set(old, n) {
|
|
17
|
+
if (caml_domain_dls !== old) return 0;
|
|
18
|
+
caml_domain_dls = n;
|
|
19
|
+
return 1;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
//Provides: caml_domain_dls_get
|
|
23
|
+
//Requires: caml_domain_dls
|
|
24
|
+
//Version: >= 5
|
|
25
|
+
function caml_domain_dls_get(_unit) {
|
|
26
|
+
return caml_domain_dls;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
//Provides: caml_domain_tls
|
|
30
|
+
//Version: >= 5.2, < 5.3
|
|
31
|
+
//OxCaml
|
|
32
|
+
var caml_domain_tls = [0];
|
|
33
|
+
|
|
34
|
+
//Provides: caml_domain_tls_set
|
|
35
|
+
//Requires: caml_domain_tls
|
|
36
|
+
//Version: >= 5.2, < 5.3
|
|
37
|
+
//OxCaml
|
|
38
|
+
function caml_domain_tls_set(a) {
|
|
39
|
+
caml_domain_tls = a;
|
|
40
|
+
return 0;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
//Provides: caml_domain_tls_get
|
|
44
|
+
//Requires: caml_domain_tls
|
|
45
|
+
//Version: >= 5.2, < 5.3
|
|
46
|
+
//OxCaml
|
|
47
|
+
function caml_domain_tls_get(_unit) {
|
|
48
|
+
return caml_domain_tls;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
//Provides: caml_atomic_load
|
|
52
|
+
//Version: >= 5
|
|
53
|
+
function caml_atomic_load(ref) {
|
|
54
|
+
return ref[1];
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
//Provides: caml_atomic_load_field
|
|
58
|
+
//Version: >= 5.4
|
|
59
|
+
function caml_atomic_load_field(b, i) {
|
|
60
|
+
return b[i + 1];
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
//Provides: caml_atomic_cas
|
|
64
|
+
//Version: >= 5
|
|
65
|
+
function caml_atomic_cas(ref, o, n) {
|
|
66
|
+
if (ref[1] === o) {
|
|
67
|
+
ref[1] = n;
|
|
68
|
+
return 1;
|
|
69
|
+
}
|
|
70
|
+
return 0;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
//Provides: caml_atomic_cas_field
|
|
74
|
+
//Version: >= 5.4
|
|
75
|
+
function caml_atomic_cas_field(b, i, o, n) {
|
|
76
|
+
if (b[i + 1] === o) {
|
|
77
|
+
b[i + 1] = n;
|
|
78
|
+
return 1;
|
|
79
|
+
}
|
|
80
|
+
return 0;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
//Provides: caml_atomic_compare_exchange
|
|
84
|
+
//Version: >= 5.2, < 5.3
|
|
85
|
+
//OxCaml
|
|
86
|
+
function caml_atomic_compare_exchange(ref, o, n) {
|
|
87
|
+
var old = ref[1];
|
|
88
|
+
if (old === o) ref[1] = n;
|
|
89
|
+
return old;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
//Provides: caml_atomic_fetch_add
|
|
93
|
+
//Version: >= 5
|
|
94
|
+
function caml_atomic_fetch_add(ref, i) {
|
|
95
|
+
var old = ref[1];
|
|
96
|
+
ref[1] += i;
|
|
97
|
+
return old;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
//Provides: caml_atomic_fetch_add_field
|
|
101
|
+
//Version: >= 5.4
|
|
102
|
+
function caml_atomic_fetch_add_field(b, i, n) {
|
|
103
|
+
var old = b[i + 1];
|
|
104
|
+
b[i + 1] += n;
|
|
105
|
+
return old;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
//Provides: caml_atomic_add
|
|
109
|
+
//Version: >= 5.2, < 5.3
|
|
110
|
+
//OxCaml
|
|
111
|
+
function caml_atomic_add(ref, i) {
|
|
112
|
+
ref[1] += i;
|
|
113
|
+
return 0;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
//Provides: caml_atomic_sub
|
|
117
|
+
//Version: >= 5.2, < 5.3
|
|
118
|
+
//OxCaml
|
|
119
|
+
function caml_atomic_sub(ref, i) {
|
|
120
|
+
ref[1] -= i;
|
|
121
|
+
return 0;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
//Provides: caml_atomic_land
|
|
125
|
+
//Version: >= 5.2, < 5.3
|
|
126
|
+
//OxCaml
|
|
127
|
+
function caml_atomic_land(ref, i) {
|
|
128
|
+
ref[1] &= i;
|
|
129
|
+
return 0;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
//Provides: caml_atomic_lor
|
|
133
|
+
//Version: >= 5.2, < 5.3
|
|
134
|
+
//OxCaml
|
|
135
|
+
function caml_atomic_lor(ref, i) {
|
|
136
|
+
ref[1] |= i;
|
|
137
|
+
return 0;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
//Provides: caml_atomic_lxor
|
|
141
|
+
//Version: >= 5.2, < 5.3
|
|
142
|
+
//OxCaml
|
|
143
|
+
function caml_atomic_lxor(ref, i) {
|
|
144
|
+
ref[1] ^= i;
|
|
145
|
+
return 0;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
//Provides: caml_atomic_exchange
|
|
149
|
+
//Version: >= 5
|
|
150
|
+
function caml_atomic_exchange(ref, v) {
|
|
151
|
+
var r = ref[1];
|
|
152
|
+
ref[1] = v;
|
|
153
|
+
return r;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
//Provides: caml_atomic_exchange_field
|
|
157
|
+
//Version: >= 5.4
|
|
158
|
+
function caml_atomic_exchange_field(b, i, v) {
|
|
159
|
+
var r = b[i + 1];
|
|
160
|
+
b[i + 1] = v;
|
|
161
|
+
return r;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
//Provides: caml_atomic_set
|
|
165
|
+
//Version: >= 5.2, < 5.3
|
|
166
|
+
//OxCaml
|
|
167
|
+
function caml_atomic_set(ref, v) {
|
|
168
|
+
ref[1] = v;
|
|
169
|
+
return 0;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
//Provides: caml_atomic_make_contended
|
|
173
|
+
//Version: >= 5.2
|
|
174
|
+
function caml_atomic_make_contended(a) {
|
|
175
|
+
return [0, a];
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
//Provides: caml_ml_domain_unique_token
|
|
179
|
+
//Version: >= 5.0, < 5.2
|
|
180
|
+
var caml_ml_domain_unique_token_ = [0];
|
|
181
|
+
function caml_ml_domain_unique_token(_unit) {
|
|
182
|
+
return caml_ml_domain_unique_token_;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
//Provides: caml_recommended_domain_count
|
|
186
|
+
//Version: >= 5
|
|
187
|
+
function caml_recommended_domain_count(_unit) {
|
|
188
|
+
return 1;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
//Provides: caml_ml_domain_index
|
|
192
|
+
//Requires: caml_domain_id
|
|
193
|
+
//Version: >= 5.03
|
|
194
|
+
function caml_ml_domain_index(_unit) {
|
|
195
|
+
return caml_domain_id;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
//Provides: caml_ml_domain_index
|
|
199
|
+
//Requires: caml_domain_id
|
|
200
|
+
//Version: >= 5.2, < 5.3
|
|
201
|
+
//OxCaml
|
|
202
|
+
function caml_ml_domain_index(_unit) {
|
|
203
|
+
return caml_domain_id;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
//Provides: caml_domain_id
|
|
207
|
+
//Version: >= 5
|
|
208
|
+
var caml_domain_id = 0;
|
|
209
|
+
|
|
210
|
+
//Provides: caml_domain_spawn
|
|
211
|
+
//Requires: caml_ml_mutex_unlock
|
|
212
|
+
//Requires: caml_domain_id
|
|
213
|
+
//Requires: caml_callback
|
|
214
|
+
//Requires: caml_wrap_exception, caml_get_exception_raw_backtrace
|
|
215
|
+
//Version: >= 5.5
|
|
216
|
+
var caml_domain_latest_idx = 1;
|
|
217
|
+
function caml_domain_spawn(f, term_sync) {
|
|
218
|
+
var id = caml_domain_latest_idx++;
|
|
219
|
+
var old = caml_domain_id;
|
|
220
|
+
caml_domain_id = id;
|
|
221
|
+
var result;
|
|
222
|
+
try {
|
|
223
|
+
// term_sync.state = Finished (Ok res)
|
|
224
|
+
result = [0, [0, caml_callback(f, [0])]];
|
|
225
|
+
} catch (e) {
|
|
226
|
+
// term_sync.state = Finished (Error (exn, backtrace))
|
|
227
|
+
var exn = caml_wrap_exception(e);
|
|
228
|
+
result = [0, [1, [0, exn, caml_get_exception_raw_backtrace(0)]]];
|
|
229
|
+
}
|
|
230
|
+
caml_domain_id = old;
|
|
231
|
+
caml_ml_mutex_unlock(term_sync[2]);
|
|
232
|
+
term_sync[1] = result;
|
|
233
|
+
return id;
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
//Provides: caml_domain_spawn
|
|
237
|
+
//Requires: caml_ml_mutex_unlock
|
|
238
|
+
//Requires: caml_domain_id
|
|
239
|
+
//Requires: caml_callback
|
|
240
|
+
//Requires: caml_wrap_exception
|
|
241
|
+
//Version: >= 5.2, < 5.5
|
|
242
|
+
var caml_domain_latest_idx = 1;
|
|
243
|
+
function caml_domain_spawn(f, term_sync) {
|
|
244
|
+
var id = caml_domain_latest_idx++;
|
|
245
|
+
var old = caml_domain_id;
|
|
246
|
+
caml_domain_id = id;
|
|
247
|
+
var result;
|
|
248
|
+
try {
|
|
249
|
+
// term_sync.state = Finished (Ok res)
|
|
250
|
+
result = [0, [0, caml_callback(f, [0])]];
|
|
251
|
+
} catch (e) {
|
|
252
|
+
// term_sync.state = Finished (Error exn)
|
|
253
|
+
var exn = caml_wrap_exception(e);
|
|
254
|
+
result = [0, [1, exn]];
|
|
255
|
+
}
|
|
256
|
+
caml_domain_id = old;
|
|
257
|
+
caml_ml_mutex_unlock(term_sync[2]);
|
|
258
|
+
term_sync[1] = result;
|
|
259
|
+
return id;
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
//Provides: caml_domain_spawn
|
|
263
|
+
//Requires: caml_ml_mutex_unlock
|
|
264
|
+
//Requires: caml_domain_id
|
|
265
|
+
//Requires: caml_callback
|
|
266
|
+
//Version: >= 5.0, < 5.2
|
|
267
|
+
var caml_domain_latest_idx = 1;
|
|
268
|
+
function caml_domain_spawn(f, mutex) {
|
|
269
|
+
var id = caml_domain_latest_idx++;
|
|
270
|
+
var old = caml_domain_id;
|
|
271
|
+
caml_domain_id = id;
|
|
272
|
+
try {
|
|
273
|
+
caml_callback(f, [0]);
|
|
274
|
+
} finally {
|
|
275
|
+
caml_domain_id = old;
|
|
276
|
+
caml_ml_mutex_unlock(mutex);
|
|
277
|
+
}
|
|
278
|
+
return id;
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
//Provides: caml_ml_domain_id
|
|
282
|
+
//Requires: caml_domain_id
|
|
283
|
+
//Version: >= 5.0
|
|
284
|
+
function caml_ml_domain_id(_unit) {
|
|
285
|
+
return caml_domain_id;
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
//Provides: caml_ml_domain_cpu_relax
|
|
289
|
+
//Version: >= 5
|
|
290
|
+
function caml_ml_domain_cpu_relax(_unit) {
|
|
291
|
+
return 0;
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
//Provides: caml_domain_count const
|
|
295
|
+
//Version: >= 5.5
|
|
296
|
+
function caml_domain_count(_unit) {
|
|
297
|
+
return 1;
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
//Provides: caml_atomic_load_field
|
|
301
|
+
//Version: >= 5.2, < 5.3
|
|
302
|
+
//OxCaml
|
|
303
|
+
function caml_atomic_load_field(ref, field) {
|
|
304
|
+
return ref[field + 1];
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
//Provides: caml_atomic_add_field
|
|
308
|
+
//Version: >= 5.2, < 5.3
|
|
309
|
+
//OxCaml
|
|
310
|
+
function caml_atomic_add_field(ref, field, i) {
|
|
311
|
+
ref[field + 1] += i;
|
|
312
|
+
return 0;
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
//Provides: caml_atomic_fetch_add_field
|
|
316
|
+
//Version: >= 5.2, < 5.3
|
|
317
|
+
//OxCaml
|
|
318
|
+
function caml_atomic_fetch_add_field(ref, field, i) {
|
|
319
|
+
var old = ref[field + 1];
|
|
320
|
+
ref[field + 1] += i;
|
|
321
|
+
return old;
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
//Provides: caml_atomic_cas_field
|
|
325
|
+
//Version: >= 5.2, < 5.3
|
|
326
|
+
//OxCaml
|
|
327
|
+
function caml_atomic_cas_field(ref, field, o, n) {
|
|
328
|
+
if (ref[field + 1] === o) {
|
|
329
|
+
ref[field + 1] = n;
|
|
330
|
+
return 1;
|
|
331
|
+
}
|
|
332
|
+
return 0;
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
//Provides: caml_atomic_compare_exchange_field
|
|
336
|
+
//Version: >= 5.2, < 5.3
|
|
337
|
+
//OxCaml
|
|
338
|
+
function caml_atomic_compare_exchange_field(ref, field, o, n) {
|
|
339
|
+
var old = ref[field + 1];
|
|
340
|
+
if (old === o) {
|
|
341
|
+
ref[field + 1] = n;
|
|
342
|
+
}
|
|
343
|
+
return old;
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
//Provides: caml_atomic_set_field
|
|
347
|
+
//Version: >= 5.2, < 5.3
|
|
348
|
+
//OxCaml
|
|
349
|
+
function caml_atomic_set_field(ref, field, v) {
|
|
350
|
+
ref[field + 1] = v;
|
|
351
|
+
return 0;
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
//Provides: caml_atomic_exchange_field
|
|
355
|
+
//Version: >= 5.2, < 5.3
|
|
356
|
+
//OxCaml
|
|
357
|
+
function caml_atomic_exchange_field(ref, field, v) {
|
|
358
|
+
var old = ref[field + 1];
|
|
359
|
+
ref[field + 1] = v;
|
|
360
|
+
return old;
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
//Provides: caml_atomic_sub_field
|
|
364
|
+
//Version: >= 5.2, < 5.3
|
|
365
|
+
//OxCaml
|
|
366
|
+
function caml_atomic_sub_field(ref, field, i) {
|
|
367
|
+
ref[field + 1] -= i;
|
|
368
|
+
return 0;
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
//Provides: caml_atomic_land_field
|
|
372
|
+
//Version: >= 5.2, < 5.3
|
|
373
|
+
//OxCaml
|
|
374
|
+
function caml_atomic_land_field(ref, field, i) {
|
|
375
|
+
ref[field + 1] &= i;
|
|
376
|
+
return 0;
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
//Provides: caml_atomic_lor_field
|
|
380
|
+
//Version: >= 5.2, < 5.3
|
|
381
|
+
//OxCaml
|
|
382
|
+
function caml_atomic_lor_field(ref, field, i) {
|
|
383
|
+
ref[field + 1] |= i;
|
|
384
|
+
return 0;
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
//Provides: caml_atomic_lxor_field
|
|
388
|
+
//Version: >= 5.2, < 5.3
|
|
389
|
+
//OxCaml
|
|
390
|
+
function caml_atomic_lxor_field(ref, field, i) {
|
|
391
|
+
ref[field + 1] ^= i;
|
|
392
|
+
return 0;
|
|
393
|
+
}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
// Js_of_ocaml toplevel runtime support
|
|
2
|
+
// http://www.ocsigen.org/js_of_ocaml/
|
|
3
|
+
// Copyright (C) 2015 Hugo Heuzard
|
|
4
|
+
//
|
|
5
|
+
// This program is free software; you can redistribute it and/or modify
|
|
6
|
+
// it under the terms of the GNU Lesser General Public License as published by
|
|
7
|
+
// the Free Software Foundation, with linking exception;
|
|
8
|
+
// either version 2.1 of the License, or (at your option) any later version.
|
|
9
|
+
//
|
|
10
|
+
// This program is distributed in the hope that it will be useful,
|
|
11
|
+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12
|
+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
13
|
+
// GNU Lesser General Public License for more details.
|
|
14
|
+
//
|
|
15
|
+
// You should have received a copy of the GNU Lesser General Public License
|
|
16
|
+
// along with this program; if not, write to the Free Software
|
|
17
|
+
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
18
|
+
|
|
19
|
+
//Provides: get_current_libs
|
|
20
|
+
var current_libs;
|
|
21
|
+
function get_current_libs() {
|
|
22
|
+
if (!current_libs) current_libs = [0, globalThis, globalThis.jsoo_runtime];
|
|
23
|
+
return current_libs;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
//Provides: caml_dynlink_open_lib_impl
|
|
27
|
+
//Requires: get_current_libs
|
|
28
|
+
function caml_dynlink_open_lib_impl(_file) {
|
|
29
|
+
var current_libs = get_current_libs();
|
|
30
|
+
current_libs.push({});
|
|
31
|
+
// return the index of the slot just filled, used directly by
|
|
32
|
+
// lookup_symbol/close_lib
|
|
33
|
+
return current_libs.length - 1;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
//Provides: caml_dynlink_open_lib
|
|
37
|
+
//Requires: caml_dynlink_open_lib_impl
|
|
38
|
+
//Version: < 5.1
|
|
39
|
+
function caml_dynlink_open_lib(_mode, file) {
|
|
40
|
+
return caml_dynlink_open_lib_impl(file);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
//Provides: caml_dynlink_open_lib
|
|
44
|
+
//Requires: caml_dynlink_open_lib_impl
|
|
45
|
+
//Version: >= 5.1
|
|
46
|
+
function caml_dynlink_open_lib(file) {
|
|
47
|
+
return caml_dynlink_open_lib_impl(file);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
//Provides: caml_dynlink_close_lib
|
|
51
|
+
//Requires: get_current_libs
|
|
52
|
+
function caml_dynlink_close_lib(idx) {
|
|
53
|
+
var current_libs = get_current_libs();
|
|
54
|
+
current_libs[idx] = null;
|
|
55
|
+
return 0;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
//Provides: caml_dynlink_lookup_symbol
|
|
59
|
+
//Requires: get_current_libs
|
|
60
|
+
//Requires: caml_jsstring_of_string
|
|
61
|
+
function caml_dynlink_lookup_symbol(idx, fun_name) {
|
|
62
|
+
var name = caml_jsstring_of_string(fun_name);
|
|
63
|
+
console.log("Dynlink: looking for symbol", name);
|
|
64
|
+
var current_libs = get_current_libs();
|
|
65
|
+
if (current_libs[idx]?.[name])
|
|
66
|
+
return { name: name, symbol: current_libs[idx][name] };
|
|
67
|
+
return 0;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
//Provides: caml_dynlink_add_primitive
|
|
71
|
+
//Requires: caml_link_info
|
|
72
|
+
function caml_dynlink_add_primitive(dll_addr) {
|
|
73
|
+
globalThis.jsoo_runtime[dll_addr.name] = dll_addr.symbol;
|
|
74
|
+
return caml_link_info.prim_count++;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
//Provides: caml_dynlink_get_current_libs
|
|
78
|
+
//Requires: get_current_libs
|
|
79
|
+
function caml_dynlink_get_current_libs() {
|
|
80
|
+
var current_libs = get_current_libs();
|
|
81
|
+
var len = current_libs.length;
|
|
82
|
+
var a = new Array(len);
|
|
83
|
+
for (var i = 0; i < len; i++) a[i] = i;
|
|
84
|
+
return a;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
//Provides: caml_dynlink_parse_ld_conf
|
|
88
|
+
//Version: >= 5.5
|
|
89
|
+
function caml_dynlink_parse_ld_conf(_stdlib) {
|
|
90
|
+
return 0;
|
|
91
|
+
}
|