@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,516 @@
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
+ //Provides: caml_int64_offset
21
+ var caml_int64_offset = Math.pow(2, -24);
22
+
23
+ //Provides: MlInt64
24
+ //Requires: caml_int64_offset, caml_raise_zero_divide
25
+ class MlInt64 {
26
+ constructor(lo, mi, hi) {
27
+ this.lo = lo & 0xffffff;
28
+ this.mi = mi & 0xffffff;
29
+ this.hi = hi & 0xffff;
30
+ this.caml_custom = "_j";
31
+ }
32
+
33
+ static UNSIGNED_MAX = new MlInt64(0xffffff, 0xffffff, 0xffff);
34
+ static SIGNED_MAX = new MlInt64(0xffffff, 0xffffff, 0x7fff);
35
+ static SIGNED_MIN = new MlInt64(0x000000, 0x000000, 0x8000);
36
+
37
+ slice() {
38
+ return new MlInt64(this.lo, this.mi, this.hi);
39
+ }
40
+
41
+ ucompare(x) {
42
+ if (this.hi > x.hi) return 1;
43
+ if (this.hi < x.hi) return -1;
44
+ if (this.mi > x.mi) return 1;
45
+ if (this.mi < x.mi) return -1;
46
+ if (this.lo > x.lo) return 1;
47
+ if (this.lo < x.lo) return -1;
48
+ return 0;
49
+ }
50
+
51
+ compare(x) {
52
+ var hi = this.hi << 16;
53
+ var xhi = x.hi << 16;
54
+ if (hi > xhi) return 1;
55
+ if (hi < xhi) return -1;
56
+ if (this.mi > x.mi) return 1;
57
+ if (this.mi < x.mi) return -1;
58
+ if (this.lo > x.lo) return 1;
59
+ if (this.lo < x.lo) return -1;
60
+ return 0;
61
+ }
62
+
63
+ neg() {
64
+ var lo = -this.lo;
65
+ var mi = -this.mi + (lo >> 24);
66
+ var hi = -this.hi + (mi >> 24);
67
+ return new MlInt64(lo, mi, hi);
68
+ }
69
+
70
+ add(x) {
71
+ var lo = this.lo + x.lo;
72
+ var mi = this.mi + x.mi + (lo >> 24);
73
+ var hi = this.hi + x.hi + (mi >> 24);
74
+ return new MlInt64(lo, mi, hi);
75
+ }
76
+
77
+ sub(x) {
78
+ var lo = this.lo - x.lo;
79
+ var mi = this.mi - x.mi + (lo >> 24);
80
+ var hi = this.hi - x.hi + (mi >> 24);
81
+ return new MlInt64(lo, mi, hi);
82
+ }
83
+
84
+ mul(x) {
85
+ var lo = this.lo * x.lo;
86
+ var mi = ((lo * caml_int64_offset) | 0) + this.mi * x.lo + this.lo * x.mi;
87
+ var hi =
88
+ ((mi * caml_int64_offset) | 0) +
89
+ this.hi * x.lo +
90
+ this.mi * x.mi +
91
+ this.lo * x.hi;
92
+ return new MlInt64(lo, mi, hi);
93
+ }
94
+
95
+ isZero() {
96
+ return (this.lo | this.mi | this.hi) === 0;
97
+ }
98
+
99
+ isNeg() {
100
+ return this.hi << 16 < 0;
101
+ }
102
+
103
+ and(x) {
104
+ return new MlInt64(this.lo & x.lo, this.mi & x.mi, this.hi & x.hi);
105
+ }
106
+
107
+ or(x) {
108
+ return new MlInt64(this.lo | x.lo, this.mi | x.mi, this.hi | x.hi);
109
+ }
110
+
111
+ xor(x) {
112
+ return new MlInt64(this.lo ^ x.lo, this.mi ^ x.mi, this.hi ^ x.hi);
113
+ }
114
+
115
+ shift_left(s) {
116
+ s = s & 63;
117
+ if (s === 0) return this;
118
+ if (s < 24) {
119
+ return new MlInt64(
120
+ this.lo << s,
121
+ (this.mi << s) | (this.lo >> (24 - s)),
122
+ (this.hi << s) | (this.mi >> (24 - s)),
123
+ );
124
+ }
125
+ if (s < 48)
126
+ return new MlInt64(
127
+ 0,
128
+ this.lo << (s - 24),
129
+ (this.mi << (s - 24)) | (this.lo >> (48 - s)),
130
+ );
131
+ return new MlInt64(0, 0, this.lo << (s - 48));
132
+ }
133
+
134
+ shift_right_unsigned(s) {
135
+ s = s & 63;
136
+ if (s === 0) return this;
137
+ if (s < 24)
138
+ return new MlInt64(
139
+ (this.lo >> s) | (this.mi << (24 - s)),
140
+ (this.mi >> s) | (this.hi << (24 - s)),
141
+ this.hi >> s,
142
+ );
143
+ if (s < 48)
144
+ return new MlInt64(
145
+ (this.mi >> (s - 24)) | (this.hi << (48 - s)),
146
+ this.hi >> (s - 24),
147
+ 0,
148
+ );
149
+ return new MlInt64(this.hi >> (s - 48), 0, 0);
150
+ }
151
+
152
+ shift_right(s) {
153
+ s = s & 63;
154
+ if (s === 0) return this;
155
+ var h = (this.hi << 16) >> 16;
156
+ if (s < 24)
157
+ return new MlInt64(
158
+ (this.lo >> s) | (this.mi << (24 - s)),
159
+ (this.mi >> s) | (h << (24 - s)),
160
+ ((this.hi << 16) >> s) >>> 16,
161
+ );
162
+ var sign = (this.hi << 16) >> 31;
163
+ if (s < 48)
164
+ return new MlInt64(
165
+ // [h] is sign-extended: for s > 40 the sign bits reach
166
+ // into the low limb
167
+ (this.mi >> (s - 24)) | (h << (48 - s)),
168
+ ((this.hi << 16) >> (s - 24)) >> 16,
169
+ sign & 0xffff,
170
+ );
171
+ return new MlInt64((this.hi << 16) >> (s - 32), sign, sign);
172
+ }
173
+
174
+ lsl1() {
175
+ this.hi = (this.hi << 1) | (this.mi >> 23);
176
+ this.mi = ((this.mi << 1) | (this.lo >> 23)) & 0xffffff;
177
+ this.lo = (this.lo << 1) & 0xffffff;
178
+ }
179
+
180
+ lsr1() {
181
+ this.lo = ((this.lo >>> 1) | (this.mi << 23)) & 0xffffff;
182
+ this.mi = ((this.mi >>> 1) | (this.hi << 23)) & 0xffffff;
183
+ this.hi = this.hi >>> 1;
184
+ }
185
+
186
+ udivmod(x) {
187
+ var offset = 0;
188
+ var modulus = this.slice();
189
+ var divisor = x.slice();
190
+ var quotient = new MlInt64(0, 0, 0);
191
+ while (modulus.ucompare(divisor) > 0) {
192
+ offset++;
193
+ divisor.lsl1();
194
+ }
195
+ while (offset >= 0) {
196
+ offset--;
197
+ quotient.lsl1();
198
+ if (modulus.ucompare(divisor) >= 0) {
199
+ quotient.lo++;
200
+ modulus = modulus.sub(divisor);
201
+ }
202
+ divisor.lsr1();
203
+ }
204
+ return { quotient: quotient, modulus: modulus };
205
+ }
206
+
207
+ div(y) {
208
+ var x = this;
209
+ if (y.isZero()) caml_raise_zero_divide();
210
+ var sign = x.hi ^ y.hi;
211
+ if (x.hi & 0x8000) x = x.neg();
212
+ if (y.hi & 0x8000) y = y.neg();
213
+ var q = x.udivmod(y).quotient;
214
+ if (sign & 0x8000) q = q.neg();
215
+ return q;
216
+ }
217
+
218
+ mod(y) {
219
+ var x = this;
220
+ if (y.isZero()) caml_raise_zero_divide();
221
+ var sign = x.hi;
222
+ if (x.hi & 0x8000) x = x.neg();
223
+ if (y.hi & 0x8000) y = y.neg();
224
+ var r = x.udivmod(y).modulus;
225
+ if (sign & 0x8000) r = r.neg();
226
+ return r;
227
+ }
228
+
229
+ toInt() {
230
+ return this.lo | (this.mi << 24);
231
+ }
232
+
233
+ toFloat() {
234
+ return (
235
+ (this.hi << 16) * Math.pow(2, 32) + this.mi * Math.pow(2, 24) + this.lo
236
+ );
237
+ }
238
+
239
+ toArray() {
240
+ return [
241
+ this.hi >> 8,
242
+ this.hi & 0xff,
243
+ this.mi >> 16,
244
+ (this.mi >> 8) & 0xff,
245
+ this.mi & 0xff,
246
+ this.lo >> 16,
247
+ (this.lo >> 8) & 0xff,
248
+ this.lo & 0xff,
249
+ ];
250
+ }
251
+
252
+ lo32() {
253
+ return this.lo | ((this.mi & 0xff) << 24);
254
+ }
255
+
256
+ hi32() {
257
+ return ((this.mi >>> 8) & 0xffff) | (this.hi << 16);
258
+ }
259
+ }
260
+
261
+ //Provides: caml_int64_ult const
262
+ function caml_int64_ult(x, y) {
263
+ return x.ucompare(y) < 0;
264
+ }
265
+
266
+ //Provides: caml_int64_compare const
267
+ function caml_int64_compare(x, y, _total) {
268
+ return x.compare(y);
269
+ }
270
+
271
+ //Provides: caml_int64_neg const
272
+ function caml_int64_neg(x) {
273
+ return x.neg();
274
+ }
275
+
276
+ //Provides: caml_int64_add const
277
+ function caml_int64_add(x, y) {
278
+ return x.add(y);
279
+ }
280
+
281
+ //Provides: caml_int64_sub const
282
+ function caml_int64_sub(x, y) {
283
+ return x.sub(y);
284
+ }
285
+
286
+ //Provides: caml_int64_mul const
287
+ //Requires: caml_int64_offset
288
+ function caml_int64_mul(x, y) {
289
+ return x.mul(y);
290
+ }
291
+
292
+ //Provides: caml_int64_is_zero const
293
+ function caml_int64_is_zero(x) {
294
+ return +x.isZero();
295
+ }
296
+
297
+ //Provides: caml_int64_is_negative const
298
+ function caml_int64_is_negative(x) {
299
+ return +x.isNeg();
300
+ }
301
+
302
+ //Provides: caml_int64_and const
303
+ function caml_int64_and(x, y) {
304
+ return x.and(y);
305
+ }
306
+
307
+ //Provides: caml_int64_or const
308
+ function caml_int64_or(x, y) {
309
+ return x.or(y);
310
+ }
311
+
312
+ //Provides: caml_int64_xor const
313
+ function caml_int64_xor(x, y) {
314
+ return x.xor(y);
315
+ }
316
+
317
+ //Provides: caml_int64_shift_left const
318
+ function caml_int64_shift_left(x, s) {
319
+ return x.shift_left(s);
320
+ }
321
+
322
+ //Provides: caml_int64_shift_right_unsigned const
323
+ function caml_int64_shift_right_unsigned(x, s) {
324
+ return x.shift_right_unsigned(s);
325
+ }
326
+
327
+ //Provides: caml_int64_shift_right const
328
+ function caml_int64_shift_right(x, s) {
329
+ return x.shift_right(s);
330
+ }
331
+
332
+ //Provides: caml_int64_div
333
+ function caml_int64_div(x, y) {
334
+ return x.div(y);
335
+ }
336
+
337
+ //Provides: caml_int64_mod
338
+ function caml_int64_mod(x, y) {
339
+ return x.mod(y);
340
+ }
341
+
342
+ //Provides: caml_int64_of_int32 const
343
+ //Requires: MlInt64
344
+ //Alias: caml_int64_of_int
345
+ //Alias: caml_int64_of_nativeint
346
+ function caml_int64_of_int32(x) {
347
+ return new MlInt64(x & 0xffffff, (x >> 24) & 0xffffff, (x >> 31) & 0xffff);
348
+ }
349
+
350
+ //Provides: caml_int64_to_int32 const
351
+ //Alias: caml_int64_to_int
352
+ //Alias: caml_int64_to_nativeint
353
+ function caml_int64_to_int32(x) {
354
+ return x.toInt();
355
+ }
356
+
357
+ //Provides: caml_checked_int64_to_int
358
+ //Requires: caml_int64_of_int32, caml_array_bound_error
359
+ //Version: >= 5.2, < 5.3
360
+ //OxCaml
361
+ function caml_checked_int64_to_int(x) {
362
+ var y = x.toInt();
363
+ if (x.compare(caml_int64_of_int32(y)) !== 0) caml_array_bound_error();
364
+ return y;
365
+ }
366
+
367
+ //Provides: caml_array_unsafe_get_indexed_by_int64 mutable (mutable, const)
368
+ //Version: >= 5.2, < 5.3
369
+ //OxCaml
370
+ function caml_array_unsafe_get_indexed_by_int64(array, index) {
371
+ return array[index.toInt() + 1];
372
+ }
373
+
374
+ //Provides: caml_array_unsafe_set_indexed_by_int64 (mutable, const, mutable)
375
+ //Version: >= 5.2, < 5.3
376
+ //OxCaml
377
+ function caml_array_unsafe_set_indexed_by_int64(array, index, newval) {
378
+ array[index.toInt() + 1] = newval;
379
+ return 0;
380
+ }
381
+
382
+ //Provides: caml_int64_to_float const
383
+ function caml_int64_to_float(x) {
384
+ return x.toFloat();
385
+ }
386
+
387
+ //Provides: caml_int64_of_float const
388
+ //Requires: caml_int64_offset, MlInt64
389
+ function caml_int64_of_float(x) {
390
+ if (x < 0) x = Math.ceil(x);
391
+ return new MlInt64(
392
+ x & 0xffffff,
393
+ Math.floor(x * caml_int64_offset) & 0xffffff,
394
+ Math.floor(x * caml_int64_offset * caml_int64_offset) & 0xffff,
395
+ );
396
+ }
397
+
398
+ //Provides: caml_int64_format const
399
+ //Requires: caml_parse_format, caml_finish_formatting
400
+ //Requires: caml_int64_is_negative, caml_int64_neg
401
+ //Requires: caml_int64_of_int32, caml_int64_to_int32
402
+ //Requires: caml_int64_is_zero, caml_str_repeat
403
+ function caml_int64_format(fmt, x) {
404
+ var f = caml_parse_format(fmt);
405
+ if (f.signedconv && caml_int64_is_negative(x)) {
406
+ f.sign = -1;
407
+ x = caml_int64_neg(x);
408
+ }
409
+ var buffer = "";
410
+ var wbase = caml_int64_of_int32(f.base);
411
+ var cvtbl = "0123456789abcdef";
412
+ do {
413
+ var p = x.udivmod(wbase);
414
+ x = p.quotient;
415
+ buffer = cvtbl.charAt(caml_int64_to_int32(p.modulus)) + buffer;
416
+ } while (!caml_int64_is_zero(x));
417
+ if (f.prec >= 0) {
418
+ f.filler = " ";
419
+ var n = f.prec - buffer.length;
420
+ if (n > 0) buffer = caml_str_repeat(n, "0") + buffer;
421
+ }
422
+ return caml_finish_formatting(f, buffer);
423
+ }
424
+
425
+ //Provides: caml_int64_of_string
426
+ //Requires: caml_parse_sign_and_base, caml_failwith, caml_parse_digit
427
+ //Requires: caml_int64_of_int32, caml_int64_ult
428
+ //Requires: caml_int64_add, caml_int64_mul, caml_int64_neg
429
+ //Requires: caml_ml_string_length,caml_string_unsafe_get, MlInt64
430
+ function caml_int64_of_string(s) {
431
+ var r = caml_parse_sign_and_base(s);
432
+ var i = r[0],
433
+ sign = r[1],
434
+ base = r[2],
435
+ signedness = r[3];
436
+ var base64 = caml_int64_of_int32(base);
437
+ var threshold = MlInt64.UNSIGNED_MAX.udivmod(base64).quotient;
438
+ var c = caml_string_unsafe_get(s, i);
439
+ var d = caml_parse_digit(c);
440
+ if (d < 0 || d >= base) caml_failwith("Int64.of_string");
441
+ var res = caml_int64_of_int32(d);
442
+ for (;;) {
443
+ i++;
444
+ c = caml_string_unsafe_get(s, i);
445
+ if (c === 95) continue;
446
+ d = caml_parse_digit(c);
447
+ if (d < 0 || d >= base) break;
448
+ /* Detect overflow in multiplication base * res */
449
+ if (caml_int64_ult(threshold, res)) caml_failwith("Int64.of_string");
450
+ d = caml_int64_of_int32(d);
451
+ res = caml_int64_add(caml_int64_mul(base64, res), d);
452
+ /* Detect overflow in addition (base * res) + d */
453
+ if (caml_int64_ult(res, d)) caml_failwith("Int64.of_string");
454
+ }
455
+ if (i !== caml_ml_string_length(s)) caml_failwith("Int64.of_string");
456
+ if (
457
+ signedness &&
458
+ caml_int64_ult(sign < 0 ? MlInt64.SIGNED_MIN : MlInt64.SIGNED_MAX, res)
459
+ )
460
+ caml_failwith("Int64.of_string");
461
+ if (sign < 0) res = caml_int64_neg(res);
462
+ return res;
463
+ }
464
+
465
+ //Provides: caml_int64_create_lo_mi_hi const
466
+ //Requires: MlInt64
467
+ function caml_int64_create_lo_mi_hi(lo, mi, hi) {
468
+ return new MlInt64(lo, mi, hi);
469
+ }
470
+ //Provides: caml_int64_create_lo_hi const
471
+ //Requires: MlInt64
472
+ function caml_int64_create_lo_hi(lo, hi) {
473
+ return new MlInt64(
474
+ lo & 0xffffff,
475
+ ((lo >>> 24) & 0xff) | ((hi & 0xffff) << 8),
476
+ (hi >>> 16) & 0xffff,
477
+ );
478
+ }
479
+ //Provides: caml_int64_lo32 const
480
+ function caml_int64_lo32(v) {
481
+ return v.lo32();
482
+ }
483
+
484
+ //Provides: caml_int64_hi32 const
485
+ function caml_int64_hi32(v) {
486
+ return v.hi32();
487
+ }
488
+
489
+ //Provides: caml_int64_of_bytes const
490
+ //Requires: MlInt64
491
+ function caml_int64_of_bytes(a) {
492
+ return new MlInt64(
493
+ (a[7] << 0) | (a[6] << 8) | (a[5] << 16),
494
+ (a[4] << 0) | (a[3] << 8) | (a[2] << 16),
495
+ (a[1] << 0) | (a[0] << 8),
496
+ );
497
+ }
498
+ //Provides: caml_int64_to_bytes const
499
+ function caml_int64_to_bytes(x) {
500
+ return x.toArray();
501
+ }
502
+
503
+ //Provides: caml_int64_hash const
504
+ function caml_int64_hash(v) {
505
+ return v.lo32() ^ v.hi32();
506
+ }
507
+
508
+ //Provides: caml_reinterpret_unboxed_int64_as_tagged_int63
509
+ //Requires: caml_failwith
510
+ //Version: >= 5.2, < 5.3
511
+ //OxCaml
512
+ function caml_reinterpret_unboxed_int64_as_tagged_int63(_v) {
513
+ caml_failwith(
514
+ "caml_reinterpret_unboxed_int64_as_tagged_int63 is not supported in javascript.",
515
+ );
516
+ }