@grain/stdlib 0.4.6 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (82) hide show
  1. package/CHANGELOG.md +73 -0
  2. package/array.gr +18 -18
  3. package/array.md +18 -18
  4. package/bigint.gr +497 -0
  5. package/bigint.md +811 -0
  6. package/buffer.gr +49 -213
  7. package/buffer.md +24 -17
  8. package/bytes.gr +100 -202
  9. package/bytes.md +19 -0
  10. package/char.gr +63 -133
  11. package/exception.md +6 -0
  12. package/float32.gr +39 -78
  13. package/float64.gr +43 -78
  14. package/hash.gr +37 -37
  15. package/int32.gr +152 -198
  16. package/int32.md +104 -0
  17. package/int64.gr +151 -197
  18. package/int64.md +104 -0
  19. package/list.gr +467 -70
  20. package/list.md +1141 -0
  21. package/map.gr +192 -7
  22. package/map.md +525 -0
  23. package/number.gr +30 -54
  24. package/number.md +3 -3
  25. package/option.md +1 -1
  26. package/package.json +3 -3
  27. package/pervasives.gr +499 -59
  28. package/pervasives.md +1116 -0
  29. package/queue.gr +4 -0
  30. package/queue.md +10 -0
  31. package/random.gr +196 -0
  32. package/random.md +179 -0
  33. package/regex.gr +1833 -842
  34. package/regex.md +11 -11
  35. package/result.md +1 -1
  36. package/runtime/bigint.gr +2045 -0
  37. package/runtime/bigint.md +326 -0
  38. package/runtime/dataStructures.gr +99 -278
  39. package/runtime/dataStructures.md +391 -0
  40. package/runtime/debug.md +6 -0
  41. package/runtime/equal.gr +5 -23
  42. package/runtime/equal.md +6 -0
  43. package/runtime/exception.md +30 -0
  44. package/runtime/gc.gr +20 -3
  45. package/runtime/gc.md +36 -0
  46. package/runtime/malloc.gr +13 -11
  47. package/runtime/malloc.md +55 -0
  48. package/runtime/numberUtils.gr +91 -41
  49. package/runtime/numberUtils.md +54 -0
  50. package/runtime/numbers.gr +1043 -391
  51. package/runtime/numbers.md +300 -0
  52. package/runtime/string.gr +136 -230
  53. package/runtime/string.md +24 -0
  54. package/runtime/stringUtils.gr +58 -38
  55. package/runtime/stringUtils.md +6 -0
  56. package/runtime/unsafe/constants.gr +17 -0
  57. package/runtime/unsafe/constants.md +72 -0
  58. package/runtime/unsafe/conv.md +71 -0
  59. package/runtime/unsafe/errors.md +204 -0
  60. package/runtime/unsafe/memory.md +54 -0
  61. package/runtime/unsafe/printWasm.md +24 -0
  62. package/runtime/unsafe/tags.gr +9 -8
  63. package/runtime/unsafe/tags.md +120 -0
  64. package/runtime/unsafe/wasmf32.md +168 -0
  65. package/runtime/unsafe/wasmf64.md +168 -0
  66. package/runtime/unsafe/wasmi32.md +282 -0
  67. package/runtime/unsafe/wasmi64.md +300 -0
  68. package/runtime/utils/printing.gr +62 -0
  69. package/runtime/utils/printing.md +18 -0
  70. package/runtime/wasi.gr +1 -1
  71. package/runtime/wasi.md +839 -0
  72. package/set.gr +17 -8
  73. package/set.md +24 -21
  74. package/stack.gr +3 -3
  75. package/stack.md +4 -6
  76. package/string.gr +194 -329
  77. package/string.md +3 -3
  78. package/sys/file.gr +245 -429
  79. package/sys/process.gr +27 -45
  80. package/sys/random.gr +47 -16
  81. package/sys/random.md +38 -0
  82. package/sys/time.gr +11 -27
package/int64.gr CHANGED
@@ -7,7 +7,6 @@
7
7
  import WasmI32 from "runtime/unsafe/wasmi32"
8
8
  import WasmI64 from "runtime/unsafe/wasmi64"
9
9
  import Exception from "runtime/exception"
10
- import Memory from "runtime/unsafe/memory"
11
10
 
12
11
  import { newInt64 } from "runtime/dataStructures"
13
12
 
@@ -52,14 +51,11 @@ export toNumber
52
51
  *
53
52
  * @since v0.2.0
54
53
  */
55
- @disableGC
56
- export let rec incr = (value: Int64) => {
54
+ @unsafe
55
+ export let incr = (value: Int64) => {
57
56
  let value = WasmI32.fromGrain(value)
58
57
  let ptr = newInt64(WasmI64.add(WasmI64.load(value, 8n), 1N))
59
- let ret = WasmI32.toGrain(ptr): Int64
60
- Memory.decRef(value)
61
- Memory.decRef(WasmI32.fromGrain(incr))
62
- ret
58
+ WasmI32.toGrain(ptr): Int64
63
59
  }
64
60
 
65
61
  /**
@@ -70,14 +66,11 @@ export let rec incr = (value: Int64) => {
70
66
  *
71
67
  * @since v0.2.0
72
68
  */
73
- @disableGC
69
+ @unsafe
74
70
  export let decr = (value: Int64) => {
75
71
  let value = WasmI32.fromGrain(value)
76
72
  let ptr = newInt64(WasmI64.sub(WasmI64.load(value, 8n), 1N))
77
- let ret = WasmI32.toGrain(ptr): Int64
78
- Memory.decRef(value)
79
- Memory.decRef(WasmI32.fromGrain(decr))
80
- ret
73
+ WasmI32.toGrain(ptr): Int64
81
74
  }
82
75
 
83
76
  /**
@@ -89,16 +82,12 @@ export let decr = (value: Int64) => {
89
82
  *
90
83
  * @since v0.2.0
91
84
  */
92
- @disableGC
93
- export let rec add = (x: Int64, y: Int64) => {
85
+ @unsafe
86
+ export let add = (x: Int64, y: Int64) => {
94
87
  let xv = WasmI64.load(WasmI32.fromGrain(x), 8n)
95
88
  let yv = WasmI64.load(WasmI32.fromGrain(y), 8n)
96
89
  let ptr = newInt64(WasmI64.add(xv, yv))
97
- let ret = WasmI32.toGrain(ptr): Int64
98
- Memory.decRef(WasmI32.fromGrain(x))
99
- Memory.decRef(WasmI32.fromGrain(y))
100
- Memory.decRef(WasmI32.fromGrain(add))
101
- ret
90
+ WasmI32.toGrain(ptr): Int64
102
91
  }
103
92
 
104
93
  /**
@@ -110,16 +99,12 @@ export let rec add = (x: Int64, y: Int64) => {
110
99
  *
111
100
  * @since v0.2.0
112
101
  */
113
- @disableGC
114
- export let rec sub = (x: Int64, y: Int64) => {
102
+ @unsafe
103
+ export let sub = (x: Int64, y: Int64) => {
115
104
  let xv = WasmI64.load(WasmI32.fromGrain(x), 8n)
116
105
  let yv = WasmI64.load(WasmI32.fromGrain(y), 8n)
117
106
  let ptr = newInt64(WasmI64.sub(xv, yv))
118
- let ret = WasmI32.toGrain(ptr): Int64
119
- Memory.decRef(WasmI32.fromGrain(x))
120
- Memory.decRef(WasmI32.fromGrain(y))
121
- Memory.decRef(WasmI32.fromGrain(sub))
122
- ret
107
+ WasmI32.toGrain(ptr): Int64
123
108
  }
124
109
 
125
110
  /**
@@ -131,16 +116,12 @@ export let rec sub = (x: Int64, y: Int64) => {
131
116
  *
132
117
  * @since v0.2.0
133
118
  */
134
- @disableGC
135
- export let rec mul = (x: Int64, y: Int64) => {
119
+ @unsafe
120
+ export let mul = (x: Int64, y: Int64) => {
136
121
  let xv = WasmI64.load(WasmI32.fromGrain(x), 8n)
137
122
  let yv = WasmI64.load(WasmI32.fromGrain(y), 8n)
138
123
  let ptr = newInt64(WasmI64.mul(xv, yv))
139
- let ret = WasmI32.toGrain(ptr): Int64
140
- Memory.decRef(WasmI32.fromGrain(x))
141
- Memory.decRef(WasmI32.fromGrain(y))
142
- Memory.decRef(WasmI32.fromGrain(mul))
143
- ret
124
+ WasmI32.toGrain(ptr): Int64
144
125
  }
145
126
 
146
127
  /**
@@ -152,16 +133,12 @@ export let rec mul = (x: Int64, y: Int64) => {
152
133
  *
153
134
  * @since v0.2.0
154
135
  */
155
- @disableGC
156
- export let rec div = (x: Int64, y: Int64) => {
136
+ @unsafe
137
+ export let div = (x: Int64, y: Int64) => {
157
138
  let xv = WasmI64.load(WasmI32.fromGrain(x), 8n)
158
139
  let yv = WasmI64.load(WasmI32.fromGrain(y), 8n)
159
140
  let ptr = newInt64(WasmI64.divS(xv, yv))
160
- let ret = WasmI32.toGrain(ptr): Int64
161
- Memory.decRef(WasmI32.fromGrain(x))
162
- Memory.decRef(WasmI32.fromGrain(y))
163
- Memory.decRef(WasmI32.fromGrain(div))
164
- ret
141
+ WasmI32.toGrain(ptr): Int64
165
142
  }
166
143
 
167
144
  /**
@@ -173,16 +150,12 @@ export let rec div = (x: Int64, y: Int64) => {
173
150
  *
174
151
  * @since v0.2.0
175
152
  */
176
- @disableGC
177
- export let rec divU = (x: Int64, y: Int64) => {
153
+ @unsafe
154
+ export let divU = (x: Int64, y: Int64) => {
178
155
  let xv = WasmI64.load(WasmI32.fromGrain(x), 8n)
179
156
  let yv = WasmI64.load(WasmI32.fromGrain(y), 8n)
180
157
  let ptr = newInt64(WasmI64.divU(xv, yv))
181
- let ret = WasmI32.toGrain(ptr): Int64
182
- Memory.decRef(WasmI32.fromGrain(x))
183
- Memory.decRef(WasmI32.fromGrain(y))
184
- Memory.decRef(WasmI32.fromGrain(divU))
185
- ret
158
+ WasmI32.toGrain(ptr): Int64
186
159
  }
187
160
 
188
161
  /**
@@ -194,16 +167,12 @@ export let rec divU = (x: Int64, y: Int64) => {
194
167
  *
195
168
  * @since v0.2.0
196
169
  */
197
- @disableGC
198
- export let rec rem = (x: Int64, y: Int64) => {
170
+ @unsafe
171
+ export let rem = (x: Int64, y: Int64) => {
199
172
  let xv = WasmI64.load(WasmI32.fromGrain(x), 8n)
200
173
  let yv = WasmI64.load(WasmI32.fromGrain(y), 8n)
201
174
  let ptr = newInt64(WasmI64.remS(xv, yv))
202
- let ret = WasmI32.toGrain(ptr): Int64
203
- Memory.decRef(WasmI32.fromGrain(x))
204
- Memory.decRef(WasmI32.fromGrain(y))
205
- Memory.decRef(WasmI32.fromGrain(rem))
206
- ret
175
+ WasmI32.toGrain(ptr): Int64
207
176
  }
208
177
 
209
178
  /**
@@ -215,19 +184,15 @@ export let rec rem = (x: Int64, y: Int64) => {
215
184
  *
216
185
  * @since v0.2.0
217
186
  */
218
- @disableGC
219
- export let rec remU = (x: Int64, y: Int64) => {
187
+ @unsafe
188
+ export let remU = (x: Int64, y: Int64) => {
220
189
  let xv = WasmI64.load(WasmI32.fromGrain(x), 8n)
221
190
  let yv = WasmI64.load(WasmI32.fromGrain(y), 8n)
222
191
  let ptr = newInt64(WasmI64.remU(xv, yv))
223
- let ret = WasmI32.toGrain(ptr): Int64
224
- Memory.decRef(WasmI32.fromGrain(x))
225
- Memory.decRef(WasmI32.fromGrain(y))
226
- Memory.decRef(WasmI32.fromGrain(remU))
227
- ret
192
+ WasmI32.toGrain(ptr): Int64
228
193
  }
229
194
 
230
- @disableGC
195
+ @unsafe
231
196
  let abs = n => {
232
197
  let mask = WasmI64.shrS(n, 63N)
233
198
  WasmI64.sub(WasmI64.xor(n, mask), mask)
@@ -243,8 +208,8 @@ let abs = n => {
243
208
  *
244
209
  * @since v0.2.0
245
210
  */
246
- @disableGC
247
- export let rec mod = (x: Int64, y: Int64) => {
211
+ @unsafe
212
+ export let mod = (x: Int64, y: Int64) => {
248
213
  let xval = WasmI64.load(WasmI32.fromGrain(x), 8n)
249
214
  let yval = WasmI64.load(WasmI32.fromGrain(y), 8n)
250
215
 
@@ -265,11 +230,7 @@ export let rec mod = (x: Int64, y: Int64) => {
265
230
  } else {
266
231
  newInt64(WasmI64.remS(xval, yval))
267
232
  }
268
- let ret = WasmI32.toGrain(ptr): Int64
269
- Memory.decRef(WasmI32.fromGrain(x))
270
- Memory.decRef(WasmI32.fromGrain(y))
271
- Memory.decRef(WasmI32.fromGrain(mod))
272
- ret
233
+ WasmI32.toGrain(ptr): Int64
273
234
  }
274
235
 
275
236
  /**
@@ -285,16 +246,12 @@ export let rec mod = (x: Int64, y: Int64) => {
285
246
  *
286
247
  * @since v0.4.0
287
248
  */
288
- @disableGC
289
- export let rec rotl = (value: Int64, amount: Int64) => {
249
+ @unsafe
250
+ export let rotl = (value: Int64, amount: Int64) => {
290
251
  let xv = WasmI64.load(WasmI32.fromGrain(value), 8n)
291
252
  let yv = WasmI64.load(WasmI32.fromGrain(amount), 8n)
292
253
  let ptr = newInt64(WasmI64.rotl(xv, yv))
293
- let ret = WasmI32.toGrain(ptr): Int64
294
- Memory.decRef(WasmI32.fromGrain(value))
295
- Memory.decRef(WasmI32.fromGrain(amount))
296
- Memory.decRef(WasmI32.fromGrain(rotl))
297
- ret
254
+ WasmI32.toGrain(ptr): Int64
298
255
  }
299
256
 
300
257
  /**
@@ -306,16 +263,12 @@ export let rec rotl = (value: Int64, amount: Int64) => {
306
263
  *
307
264
  * @since v0.4.0
308
265
  */
309
- @disableGC
310
- export let rec rotr = (value: Int64, amount: Int64) => {
266
+ @unsafe
267
+ export let rotr = (value: Int64, amount: Int64) => {
311
268
  let xv = WasmI64.load(WasmI32.fromGrain(value), 8n)
312
269
  let yv = WasmI64.load(WasmI32.fromGrain(amount), 8n)
313
270
  let ptr = newInt64(WasmI64.rotr(xv, yv))
314
- let ret = WasmI32.toGrain(ptr): Int64
315
- Memory.decRef(WasmI32.fromGrain(value))
316
- Memory.decRef(WasmI32.fromGrain(amount))
317
- Memory.decRef(WasmI32.fromGrain(rotr))
318
- ret
271
+ WasmI32.toGrain(ptr): Int64
319
272
  }
320
273
 
321
274
  /**
@@ -327,16 +280,12 @@ export let rec rotr = (value: Int64, amount: Int64) => {
327
280
  *
328
281
  * @since v0.2.0
329
282
  */
330
- @disableGC
331
- export let rec shl = (value: Int64, amount: Int64) => {
283
+ @unsafe
284
+ export let shl = (value: Int64, amount: Int64) => {
332
285
  let xv = WasmI64.load(WasmI32.fromGrain(value), 8n)
333
286
  let yv = WasmI64.load(WasmI32.fromGrain(amount), 8n)
334
287
  let ptr = newInt64(WasmI64.shl(xv, yv))
335
- let ret = WasmI32.toGrain(ptr): Int64
336
- Memory.decRef(WasmI32.fromGrain(value))
337
- Memory.decRef(WasmI32.fromGrain(amount))
338
- Memory.decRef(WasmI32.fromGrain(shl))
339
- ret
288
+ WasmI32.toGrain(ptr): Int64
340
289
  }
341
290
 
342
291
  /**
@@ -348,16 +297,12 @@ export let rec shl = (value: Int64, amount: Int64) => {
348
297
  *
349
298
  * @since v0.2.0
350
299
  */
351
- @disableGC
352
- export let rec shr = (value: Int64, amount: Int64) => {
300
+ @unsafe
301
+ export let shr = (value: Int64, amount: Int64) => {
353
302
  let xv = WasmI64.load(WasmI32.fromGrain(value), 8n)
354
303
  let yv = WasmI64.load(WasmI32.fromGrain(amount), 8n)
355
304
  let ptr = newInt64(WasmI64.shrS(xv, yv))
356
- let ret = WasmI32.toGrain(ptr): Int64
357
- Memory.decRef(WasmI32.fromGrain(value))
358
- Memory.decRef(WasmI32.fromGrain(amount))
359
- Memory.decRef(WasmI32.fromGrain(shr))
360
- ret
305
+ WasmI32.toGrain(ptr): Int64
361
306
  }
362
307
 
363
308
  /**
@@ -369,16 +314,12 @@ export let rec shr = (value: Int64, amount: Int64) => {
369
314
  *
370
315
  * @since v0.2.0
371
316
  */
372
- @disableGC
373
- export let rec shrU = (value: Int64, amount: Int64) => {
317
+ @unsafe
318
+ export let shrU = (value: Int64, amount: Int64) => {
374
319
  let xv = WasmI64.load(WasmI32.fromGrain(value), 8n)
375
320
  let yv = WasmI64.load(WasmI32.fromGrain(amount), 8n)
376
321
  let ptr = newInt64(WasmI64.shrU(xv, yv))
377
- let ret = WasmI32.toGrain(ptr): Int64
378
- Memory.decRef(WasmI32.fromGrain(value))
379
- Memory.decRef(WasmI32.fromGrain(amount))
380
- Memory.decRef(WasmI32.fromGrain(shrU))
381
- ret
322
+ WasmI32.toGrain(ptr): Int64
382
323
  }
383
324
 
384
325
  /**
@@ -394,15 +335,11 @@ export let rec shrU = (value: Int64, amount: Int64) => {
394
335
  *
395
336
  * @since v0.4.0
396
337
  */
397
- @disableGC
398
- export let rec eq = (x: Int64, y: Int64) => {
338
+ @unsafe
339
+ export let eq = (x: Int64, y: Int64) => {
399
340
  let xv = WasmI64.load(WasmI32.fromGrain(x), 8n)
400
341
  let yv = WasmI64.load(WasmI32.fromGrain(y), 8n)
401
- let ret = WasmI64.eq(xv, yv)
402
- Memory.decRef(WasmI32.fromGrain(x))
403
- Memory.decRef(WasmI32.fromGrain(y))
404
- Memory.decRef(WasmI32.fromGrain(eq))
405
- ret
342
+ WasmI64.eq(xv, yv)
406
343
  }
407
344
 
408
345
  /**
@@ -414,15 +351,11 @@ export let rec eq = (x: Int64, y: Int64) => {
414
351
  *
415
352
  * @since v0.4.0
416
353
  */
417
- @disableGC
418
- export let rec ne = (x: Int64, y: Int64) => {
354
+ @unsafe
355
+ export let ne = (x: Int64, y: Int64) => {
419
356
  let xv = WasmI64.load(WasmI32.fromGrain(x), 8n)
420
357
  let yv = WasmI64.load(WasmI32.fromGrain(y), 8n)
421
- let ret = WasmI64.ne(xv, yv)
422
- Memory.decRef(WasmI32.fromGrain(x))
423
- Memory.decRef(WasmI32.fromGrain(y))
424
- Memory.decRef(WasmI32.fromGrain(ne))
425
- ret
358
+ WasmI64.ne(xv, yv)
426
359
  }
427
360
 
428
361
  /**
@@ -433,13 +366,10 @@ export let rec ne = (x: Int64, y: Int64) => {
433
366
  *
434
367
  * @since v0.4.0
435
368
  */
436
- @disableGC
437
- export let rec eqz = (value: Int64) => {
369
+ @unsafe
370
+ export let eqz = (value: Int64) => {
438
371
  let xv = WasmI64.load(WasmI32.fromGrain(value), 8n)
439
- let ret = WasmI64.eqz(xv)
440
- Memory.decRef(WasmI32.fromGrain(value))
441
- Memory.decRef(WasmI32.fromGrain(eqz))
442
- ret
372
+ WasmI64.eqz(xv)
443
373
  }
444
374
 
445
375
  /**
@@ -451,15 +381,27 @@ export let rec eqz = (value: Int64) => {
451
381
  *
452
382
  * @since v0.2.0
453
383
  */
454
- @disableGC
455
- export let rec lt = (x: Int64, y: Int64) => {
384
+ @unsafe
385
+ export let lt = (x: Int64, y: Int64) => {
456
386
  let xv = WasmI64.load(WasmI32.fromGrain(x), 8n)
457
387
  let yv = WasmI64.load(WasmI32.fromGrain(y), 8n)
458
- let ret = WasmI64.ltS(xv, yv)
459
- Memory.decRef(WasmI32.fromGrain(x))
460
- Memory.decRef(WasmI32.fromGrain(y))
461
- Memory.decRef(WasmI32.fromGrain(lt))
462
- ret
388
+ WasmI64.ltS(xv, yv)
389
+ }
390
+
391
+ /**
392
+ * Checks if the first unsigned value is less than the second unsigned value.
393
+ *
394
+ * @param x: The first value
395
+ * @param y: The second value
396
+ * @returns `true` if the first value is less than the second value or `false` otherwise
397
+ *
398
+ * @since v0.5.0
399
+ */
400
+ @unsafe
401
+ export let rec ltU = (x: Int64, y: Int64) => {
402
+ let xv = WasmI64.load(WasmI32.fromGrain(x), 8n)
403
+ let yv = WasmI64.load(WasmI32.fromGrain(y), 8n)
404
+ WasmI64.ltU(xv, yv)
463
405
  }
464
406
 
465
407
  /**
@@ -471,15 +413,27 @@ export let rec lt = (x: Int64, y: Int64) => {
471
413
  *
472
414
  * @since v0.2.0
473
415
  */
474
- @disableGC
475
- export let rec gt = (x: Int64, y: Int64) => {
416
+ @unsafe
417
+ export let gt = (x: Int64, y: Int64) => {
418
+ let xv = WasmI64.load(WasmI32.fromGrain(x), 8n)
419
+ let yv = WasmI64.load(WasmI32.fromGrain(y), 8n)
420
+ WasmI64.gtS(xv, yv)
421
+ }
422
+
423
+ /**
424
+ * Checks if the first unsigned value is greater than the second unsigned value.
425
+ *
426
+ * @param x: The first value
427
+ * @param y: The second value
428
+ * @returns `true` if the first value is greater than the second value or `false` otherwise
429
+ *
430
+ * @since v0.5.0
431
+ */
432
+ @unsafe
433
+ export let rec gtU = (x: Int64, y: Int64) => {
476
434
  let xv = WasmI64.load(WasmI32.fromGrain(x), 8n)
477
435
  let yv = WasmI64.load(WasmI32.fromGrain(y), 8n)
478
- let ret = WasmI64.gtS(xv, yv)
479
- Memory.decRef(WasmI32.fromGrain(x))
480
- Memory.decRef(WasmI32.fromGrain(y))
481
- Memory.decRef(WasmI32.fromGrain(gt))
482
- ret
436
+ WasmI64.gtU(xv, yv)
483
437
  }
484
438
 
485
439
  /**
@@ -491,15 +445,27 @@ export let rec gt = (x: Int64, y: Int64) => {
491
445
  *
492
446
  * @since v0.2.0
493
447
  */
494
- @disableGC
495
- export let rec lte = (x: Int64, y: Int64) => {
448
+ @unsafe
449
+ export let lte = (x: Int64, y: Int64) => {
496
450
  let xv = WasmI64.load(WasmI32.fromGrain(x), 8n)
497
451
  let yv = WasmI64.load(WasmI32.fromGrain(y), 8n)
498
- let ret = WasmI64.leS(xv, yv)
499
- Memory.decRef(WasmI32.fromGrain(x))
500
- Memory.decRef(WasmI32.fromGrain(y))
501
- Memory.decRef(WasmI32.fromGrain(lte))
502
- ret
452
+ WasmI64.leS(xv, yv)
453
+ }
454
+
455
+ /**
456
+ * Checks if the first unsigned value is less than or equal to the second unsigned value.
457
+ *
458
+ * @param x: The first value
459
+ * @param y: The second value
460
+ * @returns `true` if the first value is less than or equal to the second value or `false` otherwise
461
+ *
462
+ * @since v0.5.0
463
+ */
464
+ @unsafe
465
+ export let rec lteU = (x: Int64, y: Int64) => {
466
+ let xv = WasmI64.load(WasmI32.fromGrain(x), 8n)
467
+ let yv = WasmI64.load(WasmI32.fromGrain(y), 8n)
468
+ WasmI64.leU(xv, yv)
503
469
  }
504
470
 
505
471
  /**
@@ -511,15 +477,27 @@ export let rec lte = (x: Int64, y: Int64) => {
511
477
  *
512
478
  * @since v0.2.0
513
479
  */
514
- @disableGC
515
- export let rec gte = (x: Int64, y: Int64) => {
480
+ @unsafe
481
+ export let gte = (x: Int64, y: Int64) => {
482
+ let xv = WasmI64.load(WasmI32.fromGrain(x), 8n)
483
+ let yv = WasmI64.load(WasmI32.fromGrain(y), 8n)
484
+ WasmI64.geS(xv, yv)
485
+ }
486
+
487
+ /**
488
+ * Checks if the first unsigned value is greater than or equal to the second unsigned value.
489
+ *
490
+ * @param x: The first value
491
+ * @param y: The second value
492
+ * @returns `true` if the first value is greater than or equal to the second value or `false` otherwise
493
+ *
494
+ * @since v0.5.0
495
+ */
496
+ @unsafe
497
+ export let rec gteU = (x: Int64, y: Int64) => {
516
498
  let xv = WasmI64.load(WasmI32.fromGrain(x), 8n)
517
499
  let yv = WasmI64.load(WasmI32.fromGrain(y), 8n)
518
- let ret = WasmI64.geS(xv, yv)
519
- Memory.decRef(WasmI32.fromGrain(x))
520
- Memory.decRef(WasmI32.fromGrain(y))
521
- Memory.decRef(WasmI32.fromGrain(gte))
522
- ret
500
+ WasmI64.geU(xv, yv)
523
501
  }
524
502
 
525
503
  /**
@@ -534,14 +512,11 @@ export let rec gte = (x: Int64, y: Int64) => {
534
512
  *
535
513
  * @since v0.2.0
536
514
  */
537
- @disableGC
538
- export let rec lnot = (value: Int64) => {
515
+ @unsafe
516
+ export let lnot = (value: Int64) => {
539
517
  let xv = WasmI64.load(WasmI32.fromGrain(value), 8n)
540
518
  let ptr = newInt64(WasmI64.xor(xv, 0xffffffffffffffffN))
541
- let ret = WasmI32.toGrain(ptr): Int64
542
- Memory.decRef(WasmI32.fromGrain(value))
543
- Memory.decRef(WasmI32.fromGrain(lnot))
544
- ret
519
+ WasmI32.toGrain(ptr): Int64
545
520
  }
546
521
 
547
522
  /**
@@ -553,16 +528,12 @@ export let rec lnot = (value: Int64) => {
553
528
  *
554
529
  * @since v0.2.0
555
530
  */
556
- @disableGC
557
- export let rec land = (x: Int64, y: Int64) => {
531
+ @unsafe
532
+ export let land = (x: Int64, y: Int64) => {
558
533
  let xv = WasmI64.load(WasmI32.fromGrain(x), 8n)
559
534
  let yv = WasmI64.load(WasmI32.fromGrain(y), 8n)
560
535
  let ptr = newInt64(WasmI64.and(xv, yv))
561
- let ret = WasmI32.toGrain(ptr): Int64
562
- Memory.decRef(WasmI32.fromGrain(x))
563
- Memory.decRef(WasmI32.fromGrain(y))
564
- Memory.decRef(WasmI32.fromGrain(land))
565
- ret
536
+ WasmI32.toGrain(ptr): Int64
566
537
  }
567
538
 
568
539
  /**
@@ -574,16 +545,12 @@ export let rec land = (x: Int64, y: Int64) => {
574
545
  *
575
546
  * @since v0.2.0
576
547
  */
577
- @disableGC
578
- export let rec lor = (x: Int64, y: Int64) => {
548
+ @unsafe
549
+ export let lor = (x: Int64, y: Int64) => {
579
550
  let xv = WasmI64.load(WasmI32.fromGrain(x), 8n)
580
551
  let yv = WasmI64.load(WasmI32.fromGrain(y), 8n)
581
552
  let ptr = newInt64(WasmI64.or(xv, yv))
582
- let ret = WasmI32.toGrain(ptr): Int64
583
- Memory.decRef(WasmI32.fromGrain(x))
584
- Memory.decRef(WasmI32.fromGrain(y))
585
- Memory.decRef(WasmI32.fromGrain(lor))
586
- ret
553
+ WasmI32.toGrain(ptr): Int64
587
554
  }
588
555
 
589
556
  /**
@@ -595,16 +562,12 @@ export let rec lor = (x: Int64, y: Int64) => {
595
562
  *
596
563
  * @since v0.2.0
597
564
  */
598
- @disableGC
599
- export let rec lxor = (x: Int64, y: Int64) => {
565
+ @unsafe
566
+ export let lxor = (x: Int64, y: Int64) => {
600
567
  let xv = WasmI64.load(WasmI32.fromGrain(x), 8n)
601
568
  let yv = WasmI64.load(WasmI32.fromGrain(y), 8n)
602
569
  let ptr = newInt64(WasmI64.xor(xv, yv))
603
- let ret = WasmI32.toGrain(ptr): Int64
604
- Memory.decRef(WasmI32.fromGrain(x))
605
- Memory.decRef(WasmI32.fromGrain(y))
606
- Memory.decRef(WasmI32.fromGrain(lxor))
607
- ret
570
+ WasmI32.toGrain(ptr): Int64
608
571
  }
609
572
 
610
573
  /**
@@ -615,14 +578,11 @@ export let rec lxor = (x: Int64, y: Int64) => {
615
578
  *
616
579
  * @since v0.4.0
617
580
  */
618
- @disableGC
619
- export let rec clz = (value: Int64) => {
581
+ @unsafe
582
+ export let clz = (value: Int64) => {
620
583
  let nv = WasmI64.load(WasmI32.fromGrain(value), 8n)
621
584
  let ptr = newInt64(WasmI64.clz(nv))
622
- let ret = WasmI32.toGrain(ptr): Int64
623
- Memory.decRef(WasmI32.fromGrain(value))
624
- Memory.decRef(WasmI32.fromGrain(clz))
625
- ret
585
+ WasmI32.toGrain(ptr): Int64
626
586
  }
627
587
 
628
588
  /**
@@ -633,14 +593,11 @@ export let rec clz = (value: Int64) => {
633
593
  *
634
594
  * @since v0.4.0
635
595
  */
636
- @disableGC
637
- export let rec ctz = (value: Int64) => {
596
+ @unsafe
597
+ export let ctz = (value: Int64) => {
638
598
  let nv = WasmI64.load(WasmI32.fromGrain(value), 8n)
639
599
  let ptr = newInt64(WasmI64.ctz(nv))
640
- let ret = WasmI32.toGrain(ptr): Int64
641
- Memory.decRef(WasmI32.fromGrain(value))
642
- Memory.decRef(WasmI32.fromGrain(ctz))
643
- ret
600
+ WasmI32.toGrain(ptr): Int64
644
601
  }
645
602
 
646
603
  /**
@@ -651,12 +608,9 @@ export let rec ctz = (value: Int64) => {
651
608
  *
652
609
  * @since v0.4.0
653
610
  */
654
- @disableGC
655
- export let rec popcnt = (value: Int64) => {
611
+ @unsafe
612
+ export let popcnt = (value: Int64) => {
656
613
  let nv = WasmI64.load(WasmI32.fromGrain(value), 8n)
657
614
  let ptr = newInt64(WasmI64.popcnt(nv))
658
- let ret = WasmI32.toGrain(ptr): Int64
659
- Memory.decRef(WasmI32.fromGrain(value))
660
- Memory.decRef(WasmI32.fromGrain(popcnt))
661
- ret
615
+ WasmI32.toGrain(ptr): Int64
662
616
  }