@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.
Files changed (130) hide show
  1. package/LICENSE +220 -0
  2. package/README.md +165 -2
  3. package/THIRD-PARTY-NOTICES.md +52 -0
  4. package/assets/compiler/compile_stdout.browser.js +27856 -0
  5. package/assets/compiler/jsoo.js +12631 -0
  6. package/assets/compiler/package.json +3 -0
  7. package/assets/compiler/runtime/bigarray.js +1072 -0
  8. package/assets/compiler/runtime/bigstring.js +137 -0
  9. package/assets/compiler/runtime/domain.js +393 -0
  10. package/assets/compiler/runtime/dynlink.js +91 -0
  11. package/assets/compiler/runtime/float32.js +486 -0
  12. package/assets/compiler/runtime/fs.js +416 -0
  13. package/assets/compiler/runtime/fs_fake.js +600 -0
  14. package/assets/compiler/runtime/fs_node.js +609 -0
  15. package/assets/compiler/runtime/fs_quickjs.js +532 -0
  16. package/assets/compiler/runtime/gc.js +201 -0
  17. package/assets/compiler/runtime/graphics.js +1053 -0
  18. package/assets/compiler/runtime/ieee_754.js +621 -0
  19. package/assets/compiler/runtime/int64.js +516 -0
  20. package/assets/compiler/runtime/io.js +739 -0
  21. package/assets/compiler/runtime/jslib.js +553 -0
  22. package/assets/compiler/runtime/jslib_js_of_ocaml.js +81 -0
  23. package/assets/compiler/runtime/lexing.js +240 -0
  24. package/assets/compiler/runtime/manifest.txt +31 -0
  25. package/assets/compiler/runtime/marshal.js +863 -0
  26. package/assets/compiler/runtime/md5.js +236 -0
  27. package/assets/compiler/runtime/mlBytes.js +1007 -0
  28. package/assets/compiler/runtime/nat.js +469 -0
  29. package/assets/compiler/runtime/parsing.js +317 -0
  30. package/assets/compiler/runtime/prng.js +84 -0
  31. package/assets/compiler/runtime/promise.js +45 -0
  32. package/assets/compiler/runtime/runtime.js +16688 -0
  33. package/assets/compiler/runtime/runtime_events.js +90 -0
  34. package/assets/compiler/runtime/stdlib.js +363 -0
  35. package/assets/compiler/runtime/sync.js +35 -0
  36. package/assets/compiler/runtime/toplevel.js +150 -0
  37. package/assets/compiler/runtime/unix.js +914 -0
  38. package/assets/compiler/runtime/weak.js +247 -0
  39. package/assets/compiler/stdlib.js +254 -0
  40. package/assets/compiler/worker.js +46 -0
  41. package/assets/interpreter/libs/greet.cma +0 -0
  42. package/assets/interpreter/libs/greet.cmi +0 -0
  43. package/assets/interpreter/libs/manifest.txt +1 -0
  44. package/assets/interpreter/package.json +3 -0
  45. package/assets/interpreter/stdlib/camlinternalFormat.cmi +0 -0
  46. package/assets/interpreter/stdlib/camlinternalFormatBasics.cmi +0 -0
  47. package/assets/interpreter/stdlib/camlinternalLazy.cmi +0 -0
  48. package/assets/interpreter/stdlib/camlinternalMod.cmi +0 -0
  49. package/assets/interpreter/stdlib/camlinternalOO.cmi +0 -0
  50. package/assets/interpreter/stdlib/std_exit.cmi +0 -0
  51. package/assets/interpreter/stdlib/stdlib.cmi +0 -0
  52. package/assets/interpreter/stdlib/stdlib__Arg.cmi +0 -0
  53. package/assets/interpreter/stdlib/stdlib__Array.cmi +0 -0
  54. package/assets/interpreter/stdlib/stdlib__ArrayLabels.cmi +0 -0
  55. package/assets/interpreter/stdlib/stdlib__Atomic.cmi +0 -0
  56. package/assets/interpreter/stdlib/stdlib__Bigarray.cmi +0 -0
  57. package/assets/interpreter/stdlib/stdlib__Bool.cmi +0 -0
  58. package/assets/interpreter/stdlib/stdlib__Buffer.cmi +0 -0
  59. package/assets/interpreter/stdlib/stdlib__Bytes.cmi +0 -0
  60. package/assets/interpreter/stdlib/stdlib__BytesLabels.cmi +0 -0
  61. package/assets/interpreter/stdlib/stdlib__Callback.cmi +0 -0
  62. package/assets/interpreter/stdlib/stdlib__Char.cmi +0 -0
  63. package/assets/interpreter/stdlib/stdlib__Complex.cmi +0 -0
  64. package/assets/interpreter/stdlib/stdlib__Condition.cmi +0 -0
  65. package/assets/interpreter/stdlib/stdlib__Digest.cmi +0 -0
  66. package/assets/interpreter/stdlib/stdlib__Domain.cmi +0 -0
  67. package/assets/interpreter/stdlib/stdlib__Dynarray.cmi +0 -0
  68. package/assets/interpreter/stdlib/stdlib__Effect.cmi +0 -0
  69. package/assets/interpreter/stdlib/stdlib__Either.cmi +0 -0
  70. package/assets/interpreter/stdlib/stdlib__Ephemeron.cmi +0 -0
  71. package/assets/interpreter/stdlib/stdlib__Filename.cmi +0 -0
  72. package/assets/interpreter/stdlib/stdlib__Float.cmi +0 -0
  73. package/assets/interpreter/stdlib/stdlib__Format.cmi +0 -0
  74. package/assets/interpreter/stdlib/stdlib__Fun.cmi +0 -0
  75. package/assets/interpreter/stdlib/stdlib__Gc.cmi +0 -0
  76. package/assets/interpreter/stdlib/stdlib__Hashtbl.cmi +0 -0
  77. package/assets/interpreter/stdlib/stdlib__Iarray.cmi +0 -0
  78. package/assets/interpreter/stdlib/stdlib__In_channel.cmi +0 -0
  79. package/assets/interpreter/stdlib/stdlib__Int.cmi +0 -0
  80. package/assets/interpreter/stdlib/stdlib__Int32.cmi +0 -0
  81. package/assets/interpreter/stdlib/stdlib__Int64.cmi +0 -0
  82. package/assets/interpreter/stdlib/stdlib__Lazy.cmi +0 -0
  83. package/assets/interpreter/stdlib/stdlib__Lexing.cmi +0 -0
  84. package/assets/interpreter/stdlib/stdlib__List.cmi +0 -0
  85. package/assets/interpreter/stdlib/stdlib__ListLabels.cmi +0 -0
  86. package/assets/interpreter/stdlib/stdlib__Map.cmi +0 -0
  87. package/assets/interpreter/stdlib/stdlib__Marshal.cmi +0 -0
  88. package/assets/interpreter/stdlib/stdlib__MoreLabels.cmi +0 -0
  89. package/assets/interpreter/stdlib/stdlib__Mutex.cmi +0 -0
  90. package/assets/interpreter/stdlib/stdlib__Nativeint.cmi +0 -0
  91. package/assets/interpreter/stdlib/stdlib__Obj.cmi +0 -0
  92. package/assets/interpreter/stdlib/stdlib__Oo.cmi +0 -0
  93. package/assets/interpreter/stdlib/stdlib__Option.cmi +0 -0
  94. package/assets/interpreter/stdlib/stdlib__Out_channel.cmi +0 -0
  95. package/assets/interpreter/stdlib/stdlib__Pair.cmi +0 -0
  96. package/assets/interpreter/stdlib/stdlib__Parsing.cmi +0 -0
  97. package/assets/interpreter/stdlib/stdlib__Pqueue.cmi +0 -0
  98. package/assets/interpreter/stdlib/stdlib__Printexc.cmi +0 -0
  99. package/assets/interpreter/stdlib/stdlib__Printf.cmi +0 -0
  100. package/assets/interpreter/stdlib/stdlib__Queue.cmi +0 -0
  101. package/assets/interpreter/stdlib/stdlib__Random.cmi +0 -0
  102. package/assets/interpreter/stdlib/stdlib__Repr.cmi +0 -0
  103. package/assets/interpreter/stdlib/stdlib__Result.cmi +0 -0
  104. package/assets/interpreter/stdlib/stdlib__Scanf.cmi +0 -0
  105. package/assets/interpreter/stdlib/stdlib__Semaphore.cmi +0 -0
  106. package/assets/interpreter/stdlib/stdlib__Seq.cmi +0 -0
  107. package/assets/interpreter/stdlib/stdlib__Set.cmi +0 -0
  108. package/assets/interpreter/stdlib/stdlib__Stack.cmi +0 -0
  109. package/assets/interpreter/stdlib/stdlib__StdLabels.cmi +0 -0
  110. package/assets/interpreter/stdlib/stdlib__String.cmi +0 -0
  111. package/assets/interpreter/stdlib/stdlib__StringLabels.cmi +0 -0
  112. package/assets/interpreter/stdlib/stdlib__Sys.cmi +0 -0
  113. package/assets/interpreter/stdlib/stdlib__Type.cmi +0 -0
  114. package/assets/interpreter/stdlib/stdlib__Uchar.cmi +0 -0
  115. package/assets/interpreter/stdlib/stdlib__Unit.cmi +0 -0
  116. package/assets/interpreter/stdlib/stdlib__Weak.cmi +0 -0
  117. package/assets/interpreter/stdlib/topdirs.cmi +0 -0
  118. package/assets/interpreter/stdlib/units.txt +75 -0
  119. package/assets/interpreter/stdlib/unix.cmi +0 -0
  120. package/assets/interpreter/stdlib/unixLabels.cmi +0 -0
  121. package/assets/interpreter/worker-entry.js +39 -0
  122. package/assets/interpreter/worker.js +42356 -0
  123. package/bin/copy-assets.mjs +75 -0
  124. package/package.json +41 -4
  125. package/src/compiler/compile.js +195 -0
  126. package/src/compiler/index.js +46 -0
  127. package/src/compiler/worker.js +46 -0
  128. package/src/index.js +12 -0
  129. package/src/interpreter/api.js +182 -0
  130. package/src/interpreter/index.js +5 -0
@@ -0,0 +1,1007 @@
1
+ // Js_of_ocaml runtime support
2
+ // http://www.ocsigen.org/js_of_ocaml/
3
+ // Copyright (C) 2010-2014 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
+ // An OCaml string is an object with three fields:
21
+ // - tag 't'
22
+ // - length 'l'
23
+ // - contents 'c'
24
+ //
25
+ // The contents of the string can be either a JavaScript array or
26
+ // a JavaScript string. The length of this string can be less than the
27
+ // length of the OCaml string. In this case, remaining bytes are
28
+ // assumed to be zeroes. Arrays are mutable but consumes more memory
29
+ // than strings. A common pattern is to start from an empty string and
30
+ // progressively fill it from the start. Partial strings makes it
31
+ // possible to implement this efficiently.
32
+ //
33
+ // When converting to and from UTF-16, we keep track of whether the
34
+ // string is composed only of ASCII characters (in which case, no
35
+ // conversion needs to be performed) or not.
36
+ //
37
+ // The string tag can thus take the following values:
38
+ // full string BYTE | UNKNOWN: 0
39
+ // BYTE | ASCII: 9
40
+ // BYTE | NOT_ASCII: 8
41
+ // string prefix PARTIAL: 2
42
+ // array ARRAY: 4
43
+ //
44
+ // One can use bit masking to discriminate these different cases:
45
+ // known_encoding(x) = x&8
46
+ // is_ascii(x) = x&1
47
+ // kind(x) = x&6
48
+
49
+ //Provides: caml_str_repeat
50
+ function caml_str_repeat(n, s) {
51
+ return s.repeat(n);
52
+ }
53
+
54
+ //Provides: caml_subarray_to_jsbytes
55
+ //Weakdef
56
+ // Pre ECMAScript 5, [apply] would not support array-like object.
57
+ // In such setup, Typed_array would be implemented as polyfill, and [f.apply] would
58
+ // fail here. Mark the primitive as Weakdef, so that people can override it easily.
59
+ function caml_subarray_to_jsbytes(a, i, len) {
60
+ var f = String.fromCharCode;
61
+ if (i === 0 && len <= 4096 && len === a.length) return f.apply(null, a);
62
+ var s = "";
63
+ for (; 0 < len; i += 1024, len -= 1024)
64
+ s += f.apply(null, a.slice(i, i + Math.min(len, 1024)));
65
+ return s;
66
+ }
67
+
68
+ //Provides: caml_sub_uint8_array_to_jsbytes
69
+ //Weakdef
70
+ // Pre ECMAScript 5, [apply] would not support array-like object.
71
+ // In such setup, Typed_array would be implemented as polyfill, and [f.apply] would
72
+ // fail here. Mark the primitive as Weakdef, so that people can override it easily.
73
+ function caml_sub_uint8_array_to_jsbytes(a, i, len) {
74
+ var f = String.fromCharCode;
75
+ if (i === 0 && len <= 4096 && len === a.length) return f.apply(null, a);
76
+ var s = "";
77
+ for (; 0 < len; i += 1024, len -= 1024)
78
+ s += f.apply(null, a.subarray(i, i + Math.min(len, 1024)));
79
+ return s;
80
+ }
81
+
82
+ //Provides: jsoo_is_ascii
83
+ function jsoo_is_ascii(s) {
84
+ // The regular expression gets better at around this point for all browsers
85
+ if (s.length < 24) {
86
+ // Spidermonkey gets much slower when s.length >= 24 (on 64 bit archs)
87
+ for (var i = 0; i < s.length; i++) if (s.charCodeAt(i) > 127) return false;
88
+ return true;
89
+ }
90
+ // biome-ignore lint/suspicious/noControlCharactersInRegex: expected
91
+ else return !/[^\x00-\x7f]/.test(s);
92
+ }
93
+
94
+ //Provides: caml_bytes_unsafe_get mutable
95
+ function caml_bytes_unsafe_get(s, i) {
96
+ switch (s.t & 6) {
97
+ case 0 /* BYTES */:
98
+ return s.c.charCodeAt(i);
99
+ case 2 /* PARTIAL */:
100
+ if (i >= s.c.length) return 0;
101
+ return s.c.charCodeAt(i);
102
+ case 4 /* ARRAY */:
103
+ return s.c[i];
104
+ }
105
+ }
106
+
107
+ //Provides: caml_bytes_unsafe_set
108
+ //Requires: caml_convert_bytes_to_array
109
+ function caml_bytes_unsafe_set(s, i, c) {
110
+ // The OCaml compiler uses Char.unsafe_chr on integers larger than 255!
111
+ c &= 0xff;
112
+ if (s.t !== 4 /* ARRAY */) {
113
+ if (i === s.c.length) {
114
+ s.c += String.fromCharCode(c);
115
+ if (i + 1 === s.l) s.t = 0; /*BYTES | UNKNOWN*/
116
+ return 0;
117
+ }
118
+ caml_convert_bytes_to_array(s);
119
+ }
120
+ s.c[i] = c;
121
+ return 0;
122
+ }
123
+
124
+ //Provides: caml_string_bound_error
125
+ //Requires: caml_invalid_argument
126
+ function caml_string_bound_error() {
127
+ caml_invalid_argument("index out of bounds");
128
+ }
129
+
130
+ //Provides: caml_bytes_bound_error
131
+ //Requires: caml_invalid_argument
132
+ function caml_bytes_bound_error() {
133
+ caml_invalid_argument("index out of bounds");
134
+ }
135
+
136
+ //Provides: caml_string_get
137
+ //Requires: caml_string_bound_error, caml_string_unsafe_get
138
+ //Requires: caml_ml_string_length
139
+ function caml_string_get(s, i) {
140
+ if (i >>> 0 >= caml_ml_string_length(s)) caml_string_bound_error();
141
+ return caml_string_unsafe_get(s, i);
142
+ }
143
+
144
+ //Provides: caml_string_get16
145
+ //Requires: caml_string_unsafe_get, caml_string_bound_error
146
+ //Requires: caml_ml_string_length
147
+ function caml_string_get16(s, i) {
148
+ if (i >>> 0 >= caml_ml_string_length(s) - 1) caml_string_bound_error();
149
+ var b1 = caml_string_unsafe_get(s, i),
150
+ b2 = caml_string_unsafe_get(s, i + 1);
151
+ return (b2 << 8) | b1;
152
+ }
153
+
154
+ //Provides: caml_bytes_get16
155
+ //Requires: caml_bytes_unsafe_get, caml_bytes_bound_error
156
+ function caml_bytes_get16(s, i) {
157
+ if (i >>> 0 >= s.l - 1) caml_bytes_bound_error();
158
+ var b1 = caml_bytes_unsafe_get(s, i),
159
+ b2 = caml_bytes_unsafe_get(s, i + 1);
160
+ return (b2 << 8) | b1;
161
+ }
162
+
163
+ //Provides: caml_string_get32
164
+ //Requires: caml_string_unsafe_get, caml_string_bound_error
165
+ //Requires: caml_ml_string_length
166
+ function caml_string_get32(s, i) {
167
+ if (i >>> 0 >= caml_ml_string_length(s) - 3) caml_string_bound_error();
168
+ var b1 = caml_string_unsafe_get(s, i),
169
+ b2 = caml_string_unsafe_get(s, i + 1),
170
+ b3 = caml_string_unsafe_get(s, i + 2),
171
+ b4 = caml_string_unsafe_get(s, i + 3);
172
+ return (b4 << 24) | (b3 << 16) | (b2 << 8) | b1;
173
+ }
174
+
175
+ //Provides: caml_bytes_get32
176
+ //Requires: caml_bytes_unsafe_get, caml_bytes_bound_error
177
+ function caml_bytes_get32(s, i) {
178
+ if (i >>> 0 >= s.l - 3) caml_bytes_bound_error();
179
+ var b1 = caml_bytes_unsafe_get(s, i),
180
+ b2 = caml_bytes_unsafe_get(s, i + 1),
181
+ b3 = caml_bytes_unsafe_get(s, i + 2),
182
+ b4 = caml_bytes_unsafe_get(s, i + 3);
183
+ return (b4 << 24) | (b3 << 16) | (b2 << 8) | b1;
184
+ }
185
+
186
+ //Provides: caml_string_get64
187
+ //Requires: caml_string_unsafe_get, caml_string_bound_error
188
+ //Requires: caml_int64_of_bytes
189
+ //Requires: caml_ml_string_length
190
+ function caml_string_get64(s, i) {
191
+ if (i >>> 0 >= caml_ml_string_length(s) - 7) caml_string_bound_error();
192
+ var a = new Array(8);
193
+ for (var j = 0; j < 8; j++) {
194
+ a[7 - j] = caml_string_unsafe_get(s, i + j);
195
+ }
196
+ return caml_int64_of_bytes(a);
197
+ }
198
+
199
+ //Provides: caml_bytes_get64
200
+ //Requires: caml_bytes_unsafe_get, caml_bytes_bound_error
201
+ //Requires: caml_int64_of_bytes
202
+ function caml_bytes_get64(s, i) {
203
+ if (i >>> 0 >= s.l - 7) caml_bytes_bound_error();
204
+ var a = new Array(8);
205
+ for (var j = 0; j < 8; j++) {
206
+ a[7 - j] = caml_bytes_unsafe_get(s, i + j);
207
+ }
208
+ return caml_int64_of_bytes(a);
209
+ }
210
+
211
+ //Provides: caml_bytes_get
212
+ //Requires: caml_bytes_bound_error, caml_bytes_unsafe_get
213
+ function caml_bytes_get(s, i) {
214
+ if (i >>> 0 >= s.l) caml_bytes_bound_error();
215
+ return caml_bytes_unsafe_get(s, i);
216
+ }
217
+
218
+ //Provides: caml_string_set
219
+ //Requires: caml_failwith
220
+ //If: js-string
221
+ function caml_string_set(_s, _i, _c) {
222
+ caml_failwith("caml_string_set");
223
+ }
224
+
225
+ //Provides: caml_string_set
226
+ //Requires: caml_string_unsafe_set, caml_string_bound_error
227
+ //If: !js-string
228
+ function caml_string_set(s, i, c) {
229
+ if (i >>> 0 >= s.l) caml_string_bound_error();
230
+ return caml_string_unsafe_set(s, i, c);
231
+ }
232
+
233
+ //Provides: caml_bytes_set16
234
+ //Requires: caml_bytes_bound_error, caml_bytes_unsafe_set
235
+ function caml_bytes_set16(s, i, i16) {
236
+ if (i >>> 0 >= s.l - 1) caml_bytes_bound_error();
237
+ var b2 = 0xff & (i16 >> 8),
238
+ b1 = 0xff & i16;
239
+ caml_bytes_unsafe_set(s, i + 0, b1);
240
+ caml_bytes_unsafe_set(s, i + 1, b2);
241
+ return 0;
242
+ }
243
+
244
+ //Provides: caml_bytes_set32
245
+ //Requires: caml_bytes_bound_error, caml_bytes_unsafe_set
246
+ function caml_bytes_set32(s, i, i32) {
247
+ if (i >>> 0 >= s.l - 3) caml_bytes_bound_error();
248
+ var b4 = 0xff & (i32 >> 24),
249
+ b3 = 0xff & (i32 >> 16),
250
+ b2 = 0xff & (i32 >> 8),
251
+ b1 = 0xff & i32;
252
+ caml_bytes_unsafe_set(s, i + 0, b1);
253
+ caml_bytes_unsafe_set(s, i + 1, b2);
254
+ caml_bytes_unsafe_set(s, i + 2, b3);
255
+ caml_bytes_unsafe_set(s, i + 3, b4);
256
+ return 0;
257
+ }
258
+
259
+ //Provides: caml_bytes_set64
260
+ //Requires: caml_bytes_bound_error, caml_bytes_unsafe_set
261
+ //Requires: caml_int64_to_bytes
262
+ function caml_bytes_set64(s, i, i64) {
263
+ if (i >>> 0 >= s.l - 7) caml_bytes_bound_error();
264
+ var a = caml_int64_to_bytes(i64);
265
+ for (var j = 0; j < 8; j++) {
266
+ caml_bytes_unsafe_set(s, i + 7 - j, a[j]);
267
+ }
268
+ return 0;
269
+ }
270
+
271
+ //Provides: caml_bytes_set
272
+ //Requires: caml_bytes_bound_error, caml_bytes_unsafe_set
273
+ function caml_bytes_set(s, i, c) {
274
+ if (i >>> 0 >= s.l) caml_bytes_bound_error();
275
+ return caml_bytes_unsafe_set(s, i, c);
276
+ }
277
+
278
+ //Provides: jsoo_text_encoder_fallback
279
+ // Small UTF-8 encoder used when the host doesn't provide TextEncoder
280
+ // (e.g. QuickJS). WHATWG-compatible: lone UTF-16 surrogates become the
281
+ // UTF-8 encoding of U+FFFD.
282
+ var jsoo_text_encoder_fallback = {
283
+ encode: (s) => {
284
+ var len = s.length;
285
+ var n = 0;
286
+ for (var i = 0; i < len; i++) {
287
+ var c = s.charCodeAt(i);
288
+ if (c < 0x80) n += 1;
289
+ else if (c < 0x800) n += 2;
290
+ else if (c < 0xd800 || c >= 0xe000) n += 3;
291
+ else if (c < 0xdc00 && i + 1 < len) {
292
+ var c2 = s.charCodeAt(i + 1);
293
+ if (c2 >= 0xdc00 && c2 < 0xe000) {
294
+ n += 4;
295
+ i++;
296
+ } else n += 3; /* lone high surrogate -> U+FFFD */
297
+ } else n += 3; /* lone low surrogate or trailing high -> U+FFFD */
298
+ }
299
+ var bytes = new Uint8Array(n);
300
+ var j = 0;
301
+ for (var i = 0; i < len; i++) {
302
+ var c = s.charCodeAt(i);
303
+ if (c < 0x80) {
304
+ bytes[j++] = c;
305
+ } else if (c < 0x800) {
306
+ bytes[j++] = 0xc0 | (c >> 6);
307
+ bytes[j++] = 0x80 | (c & 0x3f);
308
+ } else if (c < 0xd800 || c >= 0xe000) {
309
+ bytes[j++] = 0xe0 | (c >> 12);
310
+ bytes[j++] = 0x80 | ((c >> 6) & 0x3f);
311
+ bytes[j++] = 0x80 | (c & 0x3f);
312
+ } else if (c < 0xdc00 && i + 1 < len) {
313
+ var c2 = s.charCodeAt(i + 1);
314
+ if (c2 >= 0xdc00 && c2 < 0xe000) {
315
+ var cp = 0x10000 + ((c & 0x3ff) << 10) + (c2 & 0x3ff);
316
+ bytes[j++] = 0xf0 | (cp >> 18);
317
+ bytes[j++] = 0x80 | ((cp >> 12) & 0x3f);
318
+ bytes[j++] = 0x80 | ((cp >> 6) & 0x3f);
319
+ bytes[j++] = 0x80 | (cp & 0x3f);
320
+ i++;
321
+ } else {
322
+ /* lone high surrogate */
323
+ bytes[j++] = 0xef;
324
+ bytes[j++] = 0xbf;
325
+ bytes[j++] = 0xbd;
326
+ }
327
+ } else {
328
+ /* lone low surrogate or trailing high surrogate */
329
+ bytes[j++] = 0xef;
330
+ bytes[j++] = 0xbf;
331
+ bytes[j++] = 0xbd;
332
+ }
333
+ }
334
+ return bytes;
335
+ },
336
+ };
337
+
338
+ //Provides: jsoo_text_encoder
339
+ //Requires: jsoo_text_encoder_fallback
340
+ var jsoo_text_encoder =
341
+ typeof TextEncoder !== "undefined"
342
+ ? new TextEncoder()
343
+ : jsoo_text_encoder_fallback;
344
+
345
+ //Provides: jsoo_text_decoder_fallback
346
+ // Small UTF-8 decoder used when the host doesn't provide TextDecoder
347
+ // (e.g. QuickJS). Default-only (utf-8, fatal=false) and implements the
348
+ // WHATWG substitution-of-maximal-subpart rule: an invalid sequence is
349
+ // replaced by a single U+FFFD that consumes the longest prefix that
350
+ // could have started a valid sequence (1 byte if no valid prefix).
351
+ var jsoo_text_decoder_fallback = {
352
+ decode: (a) => {
353
+ var len = a.length;
354
+ var s = "";
355
+ var i = 0;
356
+ var REPL = 0xfffd;
357
+ var cont = (b) => (b & 0xc0) === 0x80;
358
+ while (i < len) {
359
+ var b1 = a[i++];
360
+ var cp;
361
+ if (b1 < 0x80) {
362
+ cp = b1;
363
+ } else if (b1 < 0xc2 || b1 > 0xf4) {
364
+ // 0x80..0xbf: stray continuation; 0xc0/0xc1: overlong;
365
+ // 0xf5..0xff: out of Unicode range. None start a sequence.
366
+ cp = REPL;
367
+ } else if (b1 < 0xe0) {
368
+ if (i < len && cont(a[i])) cp = ((b1 & 0x1f) << 6) | (a[i++] & 0x3f);
369
+ else cp = REPL;
370
+ } else if (b1 < 0xf0) {
371
+ // Reject UTF-16 surrogates and non-shortest encodings.
372
+ var lo = b1 === 0xe0 ? 0xa0 : 0x80;
373
+ var hi = b1 === 0xed ? 0x9f : 0xbf;
374
+ var b2 = i < len ? a[i] : -1;
375
+ if (b2 < lo || b2 > hi) cp = REPL;
376
+ else if (i + 1 < len && cont(a[i + 1])) {
377
+ cp = ((b1 & 0x0f) << 12) | ((b2 & 0x3f) << 6) | (a[i + 1] & 0x3f);
378
+ i += 2;
379
+ } else {
380
+ /* valid 2-byte prefix, but third byte missing or invalid */
381
+ cp = REPL;
382
+ i += 1;
383
+ }
384
+ } else {
385
+ var lo = b1 === 0xf0 ? 0x90 : 0x80;
386
+ var hi = b1 === 0xf4 ? 0x8f : 0xbf;
387
+ var b2 = i < len ? a[i] : -1;
388
+ if (b2 < lo || b2 > hi) cp = REPL;
389
+ else if (i + 1 < len && cont(a[i + 1])) {
390
+ if (i + 2 < len && cont(a[i + 2])) {
391
+ cp =
392
+ ((b1 & 0x07) << 18) |
393
+ ((b2 & 0x3f) << 12) |
394
+ ((a[i + 1] & 0x3f) << 6) |
395
+ (a[i + 2] & 0x3f);
396
+ i += 3;
397
+ } else {
398
+ /* valid 3-byte prefix, fourth byte missing or invalid */
399
+ cp = REPL;
400
+ i += 2;
401
+ }
402
+ } else {
403
+ /* valid 2-byte prefix, third byte missing or invalid */
404
+ cp = REPL;
405
+ i += 1;
406
+ }
407
+ }
408
+ if (cp <= 0xffff) s += String.fromCharCode(cp);
409
+ else {
410
+ cp -= 0x10000;
411
+ s += String.fromCharCode(0xd800 | (cp >> 10), 0xdc00 | (cp & 0x3ff));
412
+ }
413
+ }
414
+ return s;
415
+ },
416
+ };
417
+
418
+ //Provides: jsoo_text_decoder
419
+ //Requires: jsoo_text_decoder_fallback
420
+ var jsoo_text_decoder =
421
+ typeof TextDecoder !== "undefined"
422
+ ? new TextDecoder()
423
+ : jsoo_text_decoder_fallback;
424
+
425
+ //Provides: caml_bytes_of_utf16_jsstring
426
+ //Requires: MlBytes, jsoo_text_encoder
427
+ //Requires: jsoo_is_ascii
428
+ function caml_bytes_of_utf16_jsstring(s) {
429
+ if (jsoo_is_ascii(s)) {
430
+ return new MlBytes(9, s, s.length);
431
+ } else {
432
+ var a = jsoo_text_encoder.encode(s);
433
+ return new MlBytes(4, a, a.length);
434
+ }
435
+ }
436
+
437
+ //Provides: MlBytes
438
+ //Requires: caml_convert_string_to_bytes, jsoo_is_ascii
439
+ //Requires: caml_uint8_array_of_bytes
440
+ //Requires: jsoo_text_decoder
441
+ class MlBytes {
442
+ constructor(tag, contents, length) {
443
+ this.t = tag;
444
+ this.c = contents;
445
+ this.l = length;
446
+ }
447
+
448
+ toString() {
449
+ switch (this.t) {
450
+ case 9: /*BYTES | ASCII*/
451
+ case 8 /*BYTES | NOT_ASCII*/:
452
+ return this.c;
453
+ case 4: /* ARRAY */
454
+ // biome-ignore lint/suspicious/noFallthroughSwitchClause: falls through
455
+ case 2 /* PARTIAL */:
456
+ caml_convert_string_to_bytes(this);
457
+ // falls through
458
+ case 0 /*BYTES | UNKNOWN*/:
459
+ if (jsoo_is_ascii(this.c)) this.t = 9; /*BYTES | ASCII*/
460
+ else this.t = 8; /*BYTES | NOT_ASCII*/
461
+ return this.c;
462
+ }
463
+ }
464
+
465
+ toUtf16() {
466
+ if (this.t === 9) return this.c;
467
+ var a = caml_uint8_array_of_bytes(this);
468
+ return jsoo_text_decoder.decode(a);
469
+ }
470
+
471
+ slice() {
472
+ var content = this.t === 4 ? this.c.slice() : this.c;
473
+ return new MlBytes(this.t, content, this.l);
474
+ }
475
+ }
476
+
477
+ //Provides: caml_convert_string_to_bytes
478
+ //Requires: caml_str_repeat, caml_sub_uint8_array_to_jsbytes
479
+ function caml_convert_string_to_bytes(s) {
480
+ /* Assumes not BYTES */
481
+ if (s.t === 2 /* PARTIAL */) s.c += caml_str_repeat(s.l - s.c.length, "\0");
482
+ else s.c = caml_sub_uint8_array_to_jsbytes(s.c, 0, s.c.length);
483
+ s.t = 0; /*BYTES | UNKNOWN*/
484
+ }
485
+
486
+ //Provides: caml_convert_bytes_to_array
487
+ function caml_convert_bytes_to_array(s) {
488
+ /* Assumes not ARRAY */
489
+ var a = new Uint8Array(s.l);
490
+ var b = s.c,
491
+ l = b.length,
492
+ i = 0;
493
+ for (; i < l; i++) a[i] = b.charCodeAt(i);
494
+ for (l = s.l; i < l; i++) a[i] = 0;
495
+ s.c = a;
496
+ s.t = 4; /* ARRAY */
497
+ return a;
498
+ }
499
+
500
+ //Provides: caml_uint8_array_of_bytes mutable
501
+ //Requires: caml_convert_bytes_to_array
502
+ function caml_uint8_array_of_bytes(s) {
503
+ if (s.t !== 4 /* ARRAY */) caml_convert_bytes_to_array(s);
504
+ return s.c;
505
+ }
506
+
507
+ //Provides: caml_uint8_array_of_string mutable
508
+ //Requires: caml_ml_string_length, caml_string_unsafe_get
509
+ function caml_uint8_array_of_string(s) {
510
+ var l = caml_ml_string_length(s);
511
+ var a = new Uint8Array(l);
512
+ var i = 0;
513
+ for (; i < l; i++) a[i] = caml_string_unsafe_get(s, i);
514
+ return a;
515
+ }
516
+
517
+ //Provides: caml_create_string const
518
+ //Requires: MlBytes, caml_invalid_argument
519
+ //If: !js-string
520
+ function caml_create_string(len) {
521
+ if (len < 0) caml_invalid_argument("String.create");
522
+ return new MlBytes(len ? 2 : 9, "", len);
523
+ }
524
+
525
+ //Provides: caml_create_string const
526
+ //Requires: caml_invalid_argument
527
+ //If: js-string
528
+ function caml_create_string(_len) {
529
+ caml_invalid_argument("String.create");
530
+ }
531
+
532
+ //Provides: caml_create_bytes const
533
+ //Requires: MlBytes,caml_invalid_argument
534
+ //Alias: caml_create_local_bytes
535
+ function caml_create_bytes(len) {
536
+ if (len < 0) caml_invalid_argument("Bytes.create");
537
+ return new MlBytes(len ? 2 : 9, "", len);
538
+ }
539
+
540
+ //Provides: caml_string_of_array
541
+ //Requires: caml_subarray_to_jsbytes, caml_string_of_jsbytes
542
+ function caml_string_of_array(a) {
543
+ return caml_string_of_jsbytes(caml_subarray_to_jsbytes(a, 0, a.length));
544
+ }
545
+
546
+ //Provides: caml_string_of_uint8_array
547
+ //Requires: caml_sub_uint8_array_to_jsbytes
548
+ //If: js-string
549
+ function caml_string_of_uint8_array(a) {
550
+ return caml_sub_uint8_array_to_jsbytes(a, 0, a.length);
551
+ }
552
+
553
+ //Provides: caml_string_of_uint8_array
554
+ //Requires: caml_bytes_of_uint8_array
555
+ //If: !js-string
556
+ function caml_string_of_uint8_array(a) {
557
+ return caml_bytes_of_uint8_array(a.slice());
558
+ }
559
+
560
+ //Provides: caml_bytes_of_array
561
+ //Requires: MlBytes
562
+ function caml_bytes_of_array(a) {
563
+ if (!(a instanceof Uint8Array)) {
564
+ a = new Uint8Array(a);
565
+ }
566
+ return new MlBytes(4, a, a.length);
567
+ }
568
+
569
+ //Provides: caml_bytes_of_uint8_array
570
+ //Requires: MlBytes
571
+ function caml_bytes_of_uint8_array(a) {
572
+ return new MlBytes(4, a, a.length);
573
+ }
574
+
575
+ //Provides: caml_bytes_compare mutable
576
+ //Requires: caml_convert_string_to_bytes
577
+ function caml_bytes_compare(s1, s2) {
578
+ s1.t & 6 && caml_convert_string_to_bytes(s1);
579
+ s2.t & 6 && caml_convert_string_to_bytes(s2);
580
+ return s1.c < s2.c ? -1 : s1.c > s2.c ? 1 : 0;
581
+ }
582
+
583
+ //Provides: caml_bytes_equal mutable (const, const)
584
+ //Requires: caml_convert_string_to_bytes
585
+ function caml_bytes_equal(s1, s2) {
586
+ if (s1 === s2) return 1;
587
+ s1.t & 6 && caml_convert_string_to_bytes(s1);
588
+ s2.t & 6 && caml_convert_string_to_bytes(s2);
589
+ return s1.c === s2.c ? 1 : 0;
590
+ }
591
+
592
+ //Provides: caml_string_notequal mutable (const, const)
593
+ //Requires: caml_string_equal
594
+ function caml_string_notequal(s1, s2) {
595
+ return 1 - caml_string_equal(s1, s2);
596
+ }
597
+
598
+ //Provides: caml_bytes_notequal mutable (const, const)
599
+ //Requires: caml_bytes_equal
600
+ function caml_bytes_notequal(s1, s2) {
601
+ return 1 - caml_bytes_equal(s1, s2);
602
+ }
603
+
604
+ //Provides: caml_bytes_lessequal mutable
605
+ //Requires: caml_convert_string_to_bytes
606
+ function caml_bytes_lessequal(s1, s2) {
607
+ s1.t & 6 && caml_convert_string_to_bytes(s1);
608
+ s2.t & 6 && caml_convert_string_to_bytes(s2);
609
+ return s1.c <= s2.c ? 1 : 0;
610
+ }
611
+
612
+ //Provides: caml_bytes_lessthan mutable
613
+ //Requires: caml_convert_string_to_bytes
614
+ function caml_bytes_lessthan(s1, s2) {
615
+ s1.t & 6 && caml_convert_string_to_bytes(s1);
616
+ s2.t & 6 && caml_convert_string_to_bytes(s2);
617
+ return s1.c < s2.c ? 1 : 0;
618
+ }
619
+
620
+ //Provides: caml_string_greaterequal
621
+ //Requires: caml_string_lessequal
622
+ function caml_string_greaterequal(s1, s2) {
623
+ return caml_string_lessequal(s2, s1);
624
+ }
625
+ //Provides: caml_bytes_greaterequal
626
+ //Requires: caml_bytes_lessequal
627
+ function caml_bytes_greaterequal(s1, s2) {
628
+ return caml_bytes_lessequal(s2, s1);
629
+ }
630
+
631
+ //Provides: caml_string_greaterthan
632
+ //Requires: caml_string_lessthan
633
+ function caml_string_greaterthan(s1, s2) {
634
+ return caml_string_lessthan(s2, s1);
635
+ }
636
+
637
+ //Provides: caml_bytes_greaterthan
638
+ //Requires: caml_bytes_lessthan
639
+ function caml_bytes_greaterthan(s1, s2) {
640
+ return caml_bytes_lessthan(s2, s1);
641
+ }
642
+
643
+ //Provides: caml_fill_bytes
644
+ //Requires: caml_str_repeat, caml_convert_bytes_to_array
645
+ //Alias: caml_fill_string
646
+ function caml_fill_bytes(s, i, l, c) {
647
+ if (l > 0) {
648
+ if (i === 0 && (l >= s.l || (s.t === 2 /* PARTIAL */ && l >= s.c.length))) {
649
+ if (c === 0) {
650
+ s.c = "";
651
+ s.t = 2; /* PARTIAL */
652
+ } else {
653
+ s.c = caml_str_repeat(l, String.fromCharCode(c));
654
+ s.t = l === s.l ? 0 /* BYTES | UNKNOWN */ : 2; /* PARTIAL */
655
+ }
656
+ } else {
657
+ if (s.t !== 4 /* ARRAY */) caml_convert_bytes_to_array(s);
658
+ for (l += i; i < l; i++) s.c[i] = c;
659
+ }
660
+ }
661
+ return 0;
662
+ }
663
+
664
+ //Provides: caml_blit_bytes
665
+ //Requires: caml_sub_uint8_array_to_jsbytes, caml_convert_bytes_to_array
666
+ function caml_blit_bytes(s1, i1, s2, i2, len) {
667
+ if (len === 0) return 0;
668
+ if (
669
+ i2 === 0 &&
670
+ (len >= s2.l || (s2.t === 2 /* PARTIAL */ && len >= s2.c.length))
671
+ ) {
672
+ s2.c =
673
+ s1.t === 4 /* ARRAY */
674
+ ? caml_sub_uint8_array_to_jsbytes(s1.c, i1, len)
675
+ : i1 === 0 && s1.c.length === len
676
+ ? s1.c
677
+ : s1.c.slice(i1, i1 + len);
678
+ s2.t = s2.c.length === s2.l ? 0 /* BYTES | UNKNOWN */ : 2; /* PARTIAL */
679
+ } else if (s2.t === 2 /* PARTIAL */ && i2 === s2.c.length) {
680
+ s2.c +=
681
+ s1.t === 4 /* ARRAY */
682
+ ? caml_sub_uint8_array_to_jsbytes(s1.c, i1, len)
683
+ : i1 === 0 && s1.c.length === len
684
+ ? s1.c
685
+ : s1.c.slice(i1, i1 + len);
686
+ s2.t = s2.c.length === s2.l ? 0 /* BYTES | UNKNOWN */ : 2; /* PARTIAL */
687
+ } else {
688
+ if (s2.t !== 4 /* ARRAY */) caml_convert_bytes_to_array(s2);
689
+ var c1 = s1.c,
690
+ c2 = s2.c;
691
+ if (s1.t === 4 /* ARRAY */) {
692
+ if (i2 <= i1) {
693
+ for (var i = 0; i < len; i++) c2[i2 + i] = c1[i1 + i];
694
+ } else {
695
+ for (var i = len - 1; i >= 0; i--) c2[i2 + i] = c1[i1 + i];
696
+ }
697
+ } else {
698
+ var l = Math.min(len, c1.length - i1);
699
+ for (var i = 0; i < l; i++) c2[i2 + i] = c1.charCodeAt(i1 + i);
700
+ for (; i < len; i++) c2[i2 + i] = 0;
701
+ }
702
+ }
703
+ return 0;
704
+ }
705
+
706
+ //Provides: caml_blit_string
707
+ //Requires: caml_blit_bytes, caml_bytes_of_string
708
+ function caml_blit_string(a, b, c, d, e) {
709
+ caml_blit_bytes(caml_bytes_of_string(a), b, c, d, e);
710
+ return 0;
711
+ }
712
+
713
+ //Provides: caml_ml_bytes_length const
714
+ function caml_ml_bytes_length(s) {
715
+ return s.l;
716
+ }
717
+
718
+ //Provides: caml_string_concat const
719
+ //If: js-string
720
+ function caml_string_concat(a, b) {
721
+ return a + b;
722
+ }
723
+
724
+ //Provides: caml_string_concat const
725
+ //Requires: caml_convert_string_to_bytes, MlBytes
726
+ //If: !js-string
727
+ function caml_string_concat(s1, s2) {
728
+ s1.t & 6 && caml_convert_string_to_bytes(s1);
729
+ s2.t & 6 && caml_convert_string_to_bytes(s2);
730
+ return new MlBytes(0, s1.c + s2.c, s1.l + s2.l);
731
+ }
732
+
733
+ //Provides: caml_string_unsafe_get const
734
+ //If: js-string
735
+ function caml_string_unsafe_get(s, i) {
736
+ return s.charCodeAt(i);
737
+ }
738
+
739
+ //Provides: caml_ml_string_length const
740
+ //If: js-string
741
+ function caml_ml_string_length(s) {
742
+ return s.length;
743
+ }
744
+
745
+ //Provides: caml_string_compare const
746
+ //If: js-string
747
+ function caml_string_compare(s1, s2) {
748
+ return s1 < s2 ? -1 : s1 > s2 ? 1 : 0;
749
+ }
750
+
751
+ //Provides: caml_string_equal const
752
+ //If: js-string
753
+ function caml_string_equal(s1, s2) {
754
+ if (s1 === s2) return 1;
755
+ return 0;
756
+ }
757
+
758
+ //Provides: caml_string_lessequal const
759
+ //If: js-string
760
+ function caml_string_lessequal(s1, s2) {
761
+ return s1 <= s2 ? 1 : 0;
762
+ }
763
+
764
+ //Provides: caml_string_lessthan const
765
+ //If: js-string
766
+ function caml_string_lessthan(s1, s2) {
767
+ return s1 < s2 ? 1 : 0;
768
+ }
769
+
770
+ //Provides: caml_string_of_bytes
771
+ //Requires: caml_convert_string_to_bytes, caml_string_of_jsbytes
772
+ //If: js-string
773
+ function caml_string_of_bytes(s) {
774
+ s.t & 6 && caml_convert_string_to_bytes(s);
775
+ return caml_string_of_jsbytes(s.c);
776
+ }
777
+
778
+ //Provides: caml_bytes_of_string const
779
+ //Requires: caml_bytes_of_jsbytes, caml_jsbytes_of_string
780
+ //If: js-string
781
+ function caml_bytes_of_string(s) {
782
+ return caml_bytes_of_jsbytes(caml_jsbytes_of_string(s));
783
+ }
784
+
785
+ //Provides: caml_string_of_jsbytes const
786
+ //If: js-string
787
+ function caml_string_of_jsbytes(x) {
788
+ return x;
789
+ }
790
+
791
+ //Provides: caml_jsbytes_of_string const
792
+ //If: js-string
793
+ function caml_jsbytes_of_string(x) {
794
+ return x;
795
+ }
796
+
797
+ //Provides: jsoo_text_decoder_buff
798
+ var jsoo_text_decoder_buff = new ArrayBuffer(1024);
799
+
800
+ //Provides: caml_jsstring_of_string const
801
+ //Requires: jsoo_is_ascii
802
+ //Requires: jsoo_text_decoder
803
+ //Requires: jsoo_text_decoder_buff
804
+ //If: js-string
805
+ function caml_jsstring_of_string(s) {
806
+ if (jsoo_is_ascii(s)) return s;
807
+ var a =
808
+ s.length <= jsoo_text_decoder_buff.byteLength
809
+ ? new Uint8Array(jsoo_text_decoder_buff, 0, s.length)
810
+ : new Uint8Array(s.length);
811
+ for (var i = 0; i < s.length; i++) {
812
+ a[i] = s.charCodeAt(i);
813
+ }
814
+ return jsoo_text_decoder.decode(a);
815
+ }
816
+
817
+ //Provides: caml_string_of_jsstring const
818
+ //Requires: caml_string_of_array
819
+ //Requires: jsoo_text_encoder
820
+ //Requires: jsoo_is_ascii, caml_string_of_jsbytes
821
+ //If: js-string
822
+ function caml_string_of_jsstring(s) {
823
+ if (jsoo_is_ascii(s)) return caml_string_of_jsbytes(s);
824
+ var a = jsoo_text_encoder.encode(s);
825
+ return caml_string_of_array(a);
826
+ }
827
+
828
+ //Provides: caml_bytes_of_jsbytes const
829
+ //Requires: MlBytes
830
+ function caml_bytes_of_jsbytes(s) {
831
+ return new MlBytes(0, s, s.length);
832
+ }
833
+
834
+ // The section below should be used when use-js-string=false
835
+
836
+ //Provides: caml_string_unsafe_get const
837
+ //Requires: caml_bytes_unsafe_get
838
+ //If: !js-string
839
+ function caml_string_unsafe_get(s, i) {
840
+ return caml_bytes_unsafe_get(s, i);
841
+ }
842
+
843
+ //Provides: caml_string_unsafe_set
844
+ //Requires: caml_bytes_unsafe_set
845
+ //If: !js-string
846
+ function caml_string_unsafe_set(s, i, c) {
847
+ return caml_bytes_unsafe_set(s, i, c);
848
+ }
849
+
850
+ //Provides: caml_ml_string_length const
851
+ //Requires: caml_ml_bytes_length
852
+ //If: !js-string
853
+ function caml_ml_string_length(s) {
854
+ return caml_ml_bytes_length(s);
855
+ }
856
+
857
+ //Provides: caml_string_compare
858
+ //Requires: caml_bytes_compare
859
+ //If: !js-string
860
+ function caml_string_compare(s1, s2) {
861
+ return caml_bytes_compare(s1, s2);
862
+ }
863
+
864
+ //Provides: caml_string_equal
865
+ //Requires: caml_bytes_equal
866
+ //If: !js-string
867
+ function caml_string_equal(s1, s2) {
868
+ return caml_bytes_equal(s1, s2);
869
+ }
870
+
871
+ //Provides: caml_string_lessequal
872
+ //Requires: caml_bytes_lessequal
873
+ //If: !js-string
874
+ function caml_string_lessequal(s1, s2) {
875
+ return caml_bytes_lessequal(s1, s2);
876
+ }
877
+
878
+ //Provides: caml_string_lessthan
879
+ //Requires: caml_bytes_lessthan
880
+ //If: !js-string
881
+ function caml_string_lessthan(s1, s2) {
882
+ return caml_bytes_lessthan(s1, s2);
883
+ }
884
+
885
+ //Provides: caml_string_of_bytes
886
+ //If: !js-string
887
+ function caml_string_of_bytes(s) {
888
+ return s;
889
+ }
890
+
891
+ //Provides: caml_bytes_of_string const
892
+ //If: !js-string
893
+ function caml_bytes_of_string(s) {
894
+ return s;
895
+ }
896
+
897
+ //Provides: caml_string_of_jsbytes const
898
+ //Requires: caml_bytes_of_jsbytes
899
+ //If: !js-string
900
+ function caml_string_of_jsbytes(s) {
901
+ return caml_bytes_of_jsbytes(s);
902
+ }
903
+
904
+ //Provides: caml_jsbytes_of_string const
905
+ //Requires: caml_convert_string_to_bytes
906
+ //If: !js-string
907
+ function caml_jsbytes_of_string(s) {
908
+ s.t & 6 && caml_convert_string_to_bytes(s);
909
+ return s.c;
910
+ }
911
+
912
+ //Provides: caml_jsstring_of_string mutable (const)
913
+ //If: !js-string
914
+ function caml_jsstring_of_string(s) {
915
+ return s.toUtf16();
916
+ }
917
+
918
+ //Provides: caml_string_of_jsstring
919
+ //Requires: caml_bytes_of_utf16_jsstring
920
+ //If: !js-string
921
+ function caml_string_of_jsstring(s) {
922
+ return caml_bytes_of_utf16_jsstring(s);
923
+ }
924
+
925
+ //Provides: caml_is_ml_bytes
926
+ //Requires: MlBytes
927
+ function caml_is_ml_bytes(s) {
928
+ return s instanceof MlBytes;
929
+ }
930
+
931
+ //Provides: caml_ml_bytes_content
932
+ //Requires: MlBytes, caml_convert_string_to_bytes
933
+ //Returns a (full) string of bytes or an array
934
+ function caml_ml_bytes_content(s) {
935
+ switch (s.t & 6) {
936
+ case 2 /* PARTIAL */:
937
+ caml_convert_string_to_bytes(s);
938
+ return s.c;
939
+ default: /* BYTES or ARRAY */
940
+ return s.c;
941
+ }
942
+ }
943
+
944
+ //Provides: caml_is_ml_string
945
+ //If: js-string
946
+ function caml_is_ml_string(s) {
947
+ // biome-ignore lint/suspicious/noControlCharactersInRegex: expected
948
+ return typeof s === "string" && !/[^\x00-\xff]/.test(s);
949
+ }
950
+
951
+ //Provides: caml_is_ml_string
952
+ //Requires: caml_is_ml_bytes
953
+ //If: !js-string
954
+ function caml_is_ml_string(s) {
955
+ return caml_is_ml_bytes(s);
956
+ }
957
+
958
+ // The functions below are deprecated
959
+
960
+ //Provides: caml_js_to_byte_string const
961
+ //Requires: caml_string_of_jsbytes
962
+ //Deprecated: Use [caml_string_of_jsbytes] instead
963
+ function caml_js_to_byte_string(s) {
964
+ return caml_string_of_jsbytes(s);
965
+ }
966
+
967
+ //Provides: caml_js_from_string mutable (const)
968
+ //Requires: caml_jsstring_of_string
969
+ //Deprecated: Use [caml_jsstring_of_string] instead
970
+ function caml_js_from_string(s) {
971
+ return caml_jsstring_of_string(s);
972
+ }
973
+
974
+ //Provides: caml_to_js_string mutable (const)
975
+ //Requires: caml_jsstring_of_string
976
+ //Deprecated: Use [caml_jsstring_of_string] instead
977
+ function caml_to_js_string(s) {
978
+ return caml_jsstring_of_string(s);
979
+ }
980
+
981
+ //Provides: caml_js_to_string const
982
+ //Requires: caml_string_of_jsstring
983
+ //Deprecated: Use [caml_string_of_jsstring] instead
984
+ function caml_js_to_string(s) {
985
+ return caml_string_of_jsstring(s);
986
+ }
987
+
988
+ //Provides: caml_array_of_string
989
+ //Requires: caml_uint8_array_of_string
990
+ //Deprecated: Use [caml_uint8_array_of_string] instead
991
+ function caml_array_of_string(x) {
992
+ return caml_uint8_array_of_string(x);
993
+ }
994
+
995
+ //Provides: caml_array_of_bytes
996
+ //Requires: caml_uint8_array_of_bytes
997
+ //Deprecated: Use [caml_uint8_array_of_bytes] instead
998
+ function caml_array_of_bytes(x) {
999
+ return caml_uint8_array_of_bytes(x);
1000
+ }
1001
+
1002
+ //Provides: caml_new_string
1003
+ //Requires: caml_string_of_jsbytes
1004
+ //Deprecated: Use [caml_string_of_jsbytes] instead
1005
+ function caml_new_string(s) {
1006
+ return caml_string_of_jsbytes(s);
1007
+ }