@grain/stdlib 0.4.6 → 0.5.2

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