@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/map.md ADDED
@@ -0,0 +1,525 @@
1
+ ---
2
+ title: Map
3
+ ---
4
+
5
+ A Map holds key-value pairs. Any value may be used as a key or value. Operations on a Map mutate the internal state, so it never needs to be re-assigned.
6
+
7
+ <details disabled>
8
+ <summary tabindex="-1">Added in <code>0.2.0</code></summary>
9
+ No other changes yet.
10
+ </details>
11
+
12
+ ```grain
13
+ import Map from "map"
14
+ ```
15
+
16
+ ## Types
17
+
18
+ Type declarations included in the Map module.
19
+
20
+ ### Map.**Map**
21
+
22
+ ```grain
23
+ type Map<k, v>
24
+ ```
25
+
26
+ ## Values
27
+
28
+ Functions for working with Maps.
29
+
30
+ ### Map.**makeSized**
31
+
32
+ <details disabled>
33
+ <summary tabindex="-1">Added in <code>0.2.0</code></summary>
34
+ No other changes yet.
35
+ </details>
36
+
37
+ ```grain
38
+ makeSized : Number -> Map<a, b>
39
+ ```
40
+
41
+ Creates a new empty map with an initial storage of the given size. As values are added or removed, the internal storage may grow or shrink. Generally, you won't need to care about the storage size of your map and can use `Map.make()` instead.
42
+
43
+ Parameters:
44
+
45
+ |param|type|description|
46
+ |-----|----|-----------|
47
+ |`size`|`Number`|The initial storage size of the map|
48
+
49
+ Returns:
50
+
51
+ |type|description|
52
+ |----|-----------|
53
+ |`Map<a, b>`|An empty map with the given initial storage size|
54
+
55
+ ### Map.**make**
56
+
57
+ <details disabled>
58
+ <summary tabindex="-1">Added in <code>0.2.0</code></summary>
59
+ No other changes yet.
60
+ </details>
61
+
62
+ ```grain
63
+ make : () -> Map<a, b>
64
+ ```
65
+
66
+ Creates a new, empty map.
67
+
68
+ Returns:
69
+
70
+ |type|description|
71
+ |----|-----------|
72
+ |`Map<a, b>`|An empty map|
73
+
74
+ ### Map.**set**
75
+
76
+ <details disabled>
77
+ <summary tabindex="-1">Added in <code>0.2.0</code></summary>
78
+ No other changes yet.
79
+ </details>
80
+
81
+ ```grain
82
+ set : (a, b, Map<a, b>) -> Void
83
+ ```
84
+
85
+ Adds a new key-value pair to the map. If the key already exists in the map, the value is replaced.
86
+
87
+ Parameters:
88
+
89
+ |param|type|description|
90
+ |-----|----|-----------|
91
+ |`key`|`a`|The unique key in the map|
92
+ |`value`|`b`|The value to store|
93
+ |`map`|`Map<a, b>`|The map to modify|
94
+
95
+ ### Map.**get**
96
+
97
+ <details disabled>
98
+ <summary tabindex="-1">Added in <code>0.2.0</code></summary>
99
+ No other changes yet.
100
+ </details>
101
+
102
+ ```grain
103
+ get : (a, Map<a, b>) -> Option<b>
104
+ ```
105
+
106
+ Retrieves the value for the given key.
107
+
108
+ Parameters:
109
+
110
+ |param|type|description|
111
+ |-----|----|-----------|
112
+ |`key`|`a`|The key to access|
113
+ |`map`|`Map<a, b>`|The map to access|
114
+
115
+ Returns:
116
+
117
+ |type|description|
118
+ |----|-----------|
119
+ |`Option<b>`|`Some(value)` if the key exists in the map or `None` otherwise|
120
+
121
+ ### Map.**contains**
122
+
123
+ <details disabled>
124
+ <summary tabindex="-1">Added in <code>0.2.0</code></summary>
125
+ No other changes yet.
126
+ </details>
127
+
128
+ ```grain
129
+ contains : (a, Map<a, b>) -> Bool
130
+ ```
131
+
132
+ Determines if the map contains the given key. In such a case, it will always contain a value for the given key.
133
+
134
+ Parameters:
135
+
136
+ |param|type|description|
137
+ |-----|----|-----------|
138
+ |`key`|`a`|The key to search for|
139
+ |`map`|`Map<a, b>`|The map to search|
140
+
141
+ Returns:
142
+
143
+ |type|description|
144
+ |----|-----------|
145
+ |`Bool`|`true` if the map contains the given key or `false` otherwise|
146
+
147
+ ### Map.**remove**
148
+
149
+ <details disabled>
150
+ <summary tabindex="-1">Added in <code>0.2.0</code></summary>
151
+ No other changes yet.
152
+ </details>
153
+
154
+ ```grain
155
+ remove : (a, Map<a, b>) -> Void
156
+ ```
157
+
158
+ Removes the given key from the map, which also removes the value. If the key pair doesn't exist, nothing happens.
159
+
160
+ Parameters:
161
+
162
+ |param|type|description|
163
+ |-----|----|-----------|
164
+ |`key`|`a`|The key to remove|
165
+ |`map`|`Map<a, b>`|The map to update|
166
+
167
+ ### Map.**update**
168
+
169
+ <details disabled>
170
+ <summary tabindex="-1">Added in <code>0.3.0</code></summary>
171
+ No other changes yet.
172
+ </details>
173
+
174
+ ```grain
175
+ update : (a, (Option<b> -> Option<b>), Map<a, b>) -> Void
176
+ ```
177
+
178
+ Updates a value in the map by calling an updater function that receives the previously stored value as an `Option` and returns the new value to be stored as an `Option`. If the key didn't exist previously, the value will be `None`. If `None` is returned from the updater function, the key-value pair is removed.
179
+
180
+ Parameters:
181
+
182
+ |param|type|description|
183
+ |-----|----|-----------|
184
+ |`key`|`a`|The unique key in the map|
185
+ |`fn`|`Option<b> -> Option<b>`|The updater function|
186
+ |`map`|`Map<a, b>`|The map to modify|
187
+
188
+ ### Map.**size**
189
+
190
+ <details disabled>
191
+ <summary tabindex="-1">Added in <code>0.2.0</code></summary>
192
+ No other changes yet.
193
+ </details>
194
+
195
+ ```grain
196
+ size : Map<a, b> -> Number
197
+ ```
198
+
199
+ Provides the count of key-value pairs stored within the map.
200
+
201
+ Parameters:
202
+
203
+ |param|type|description|
204
+ |-----|----|-----------|
205
+ |`map`|`Map<a, b>`|The map to inspect|
206
+
207
+ Returns:
208
+
209
+ |type|description|
210
+ |----|-----------|
211
+ |`Number`|The count of key-value pairs in the map|
212
+
213
+ ### Map.**isEmpty**
214
+
215
+ <details disabled>
216
+ <summary tabindex="-1">Added in <code>0.2.0</code></summary>
217
+ No other changes yet.
218
+ </details>
219
+
220
+ ```grain
221
+ isEmpty : Map<a, b> -> Bool
222
+ ```
223
+
224
+ Determines if the map contains no key-value pairs.
225
+
226
+ Parameters:
227
+
228
+ |param|type|description|
229
+ |-----|----|-----------|
230
+ |`map`|`Map<a, b>`|The map to inspect|
231
+
232
+ Returns:
233
+
234
+ |type|description|
235
+ |----|-----------|
236
+ |`Bool`|`true` if the given map is empty or `false` otherwise|
237
+
238
+ ### Map.**clear**
239
+
240
+ <details disabled>
241
+ <summary tabindex="-1">Added in <code>0.2.0</code></summary>
242
+ No other changes yet.
243
+ </details>
244
+
245
+ ```grain
246
+ clear : Map<a, b> -> Void
247
+ ```
248
+
249
+ Resets the map by removing all key-value pairs.
250
+
251
+ Parameters:
252
+
253
+ |param|type|description|
254
+ |-----|----|-----------|
255
+ |`map`|`Map<a, b>`|The map to reset|
256
+
257
+ ### Map.**forEach**
258
+
259
+ <details>
260
+ <summary>Added in <code>0.2.0</code></summary>
261
+ <table>
262
+ <thead>
263
+ <tr><th>version</th><th>changes</th></tr>
264
+ </thead>
265
+ <tbody>
266
+ <tr><td><code>next</code></td><td>Ensured the iterator function return type is always `Void`</td></tr>
267
+ </tbody>
268
+ </table>
269
+ </details>
270
+
271
+ ```grain
272
+ forEach : (((a, b) -> Void), Map<a, b>) -> Void
273
+ ```
274
+
275
+ Iterates the map, calling an iterator function with each key and value.
276
+
277
+ Parameters:
278
+
279
+ |param|type|description|
280
+ |-----|----|-----------|
281
+ |`fn`|`(a, b) -> Void`|The iterator function to call with each key and value|
282
+ |`map`|`Map<a, b>`|The map to iterate|
283
+
284
+ ### Map.**reduce**
285
+
286
+ <details disabled>
287
+ <summary tabindex="-1">Added in <code>0.2.0</code></summary>
288
+ No other changes yet.
289
+ </details>
290
+
291
+ ```grain
292
+ reduce : (((a, b, c) -> a), a, Map<b, c>) -> a
293
+ ```
294
+
295
+ Combines all key-value pairs of a map using a reducer function.
296
+
297
+ Parameters:
298
+
299
+ |param|type|description|
300
+ |-----|----|-----------|
301
+ |`fn`|`(a, b, c) -> a`|The reducer function to call on each key and value, where the value returned will be the next accumulator value|
302
+ |`init`|`a`|The initial value to use for the accumulator on the first iteration|
303
+ |`map`|`Map<b, c>`|The map to iterate|
304
+
305
+ Returns:
306
+
307
+ |type|description|
308
+ |----|-----------|
309
+ |`a`|The final accumulator returned from `fn`|
310
+
311
+ ### Map.**keys**
312
+
313
+ <details disabled>
314
+ <summary tabindex="-1">Added in <code>0.2.0</code></summary>
315
+ No other changes yet.
316
+ </details>
317
+
318
+ ```grain
319
+ keys : Map<a, b> -> List<a>
320
+ ```
321
+
322
+ Enumerates all keys in the given map.
323
+
324
+ Parameters:
325
+
326
+ |param|type|description|
327
+ |-----|----|-----------|
328
+ |`map`|`Map<a, b>`|The map to enumerate|
329
+
330
+ Returns:
331
+
332
+ |type|description|
333
+ |----|-----------|
334
+ |`List<a>`|A list containing all keys from the given map|
335
+
336
+ ### Map.**values**
337
+
338
+ <details disabled>
339
+ <summary tabindex="-1">Added in <code>0.2.0</code></summary>
340
+ No other changes yet.
341
+ </details>
342
+
343
+ ```grain
344
+ values : Map<a, b> -> List<b>
345
+ ```
346
+
347
+ Enumerates all values in the given map.
348
+
349
+ Parameters:
350
+
351
+ |param|type|description|
352
+ |-----|----|-----------|
353
+ |`map`|`Map<a, b>`|The map to enumerate|
354
+
355
+ Returns:
356
+
357
+ |type|description|
358
+ |----|-----------|
359
+ |`List<b>`|A list containing all values from the given map|
360
+
361
+ ### Map.**toList**
362
+
363
+ <details disabled>
364
+ <summary tabindex="-1">Added in <code>0.2.0</code></summary>
365
+ No other changes yet.
366
+ </details>
367
+
368
+ ```grain
369
+ toList : Map<a, b> -> List<(a, b)>
370
+ ```
371
+
372
+ Enumerates all key-value pairs in the given map.
373
+
374
+ Parameters:
375
+
376
+ |param|type|description|
377
+ |-----|----|-----------|
378
+ |`map`|`Map<a, b>`|The map to enumerate|
379
+
380
+ Returns:
381
+
382
+ |type|description|
383
+ |----|-----------|
384
+ |`List<(a, b)>`|A list containing all key-value pairs from the given map|
385
+
386
+ ### Map.**fromList**
387
+
388
+ <details disabled>
389
+ <summary tabindex="-1">Added in <code>0.2.0</code></summary>
390
+ No other changes yet.
391
+ </details>
392
+
393
+ ```grain
394
+ fromList : List<(a, b)> -> Map<a, b>
395
+ ```
396
+
397
+ Creates a map from a list.
398
+
399
+ Parameters:
400
+
401
+ |param|type|description|
402
+ |-----|----|-----------|
403
+ |`list`|`List<(a, b)>`|The list to convert|
404
+
405
+ Returns:
406
+
407
+ |type|description|
408
+ |----|-----------|
409
+ |`Map<a, b>`|A map containing all key-value pairs from the list|
410
+
411
+ ### Map.**toArray**
412
+
413
+ <details disabled>
414
+ <summary tabindex="-1">Added in <code>0.2.0</code></summary>
415
+ No other changes yet.
416
+ </details>
417
+
418
+ ```grain
419
+ toArray : Map<a, b> -> Array<(a, b)>
420
+ ```
421
+
422
+ Converts a map into an array of its key-value pairs.
423
+
424
+ Parameters:
425
+
426
+ |param|type|description|
427
+ |-----|----|-----------|
428
+ |`map`|`Map<a, b>`|The map to convert|
429
+
430
+ Returns:
431
+
432
+ |type|description|
433
+ |----|-----------|
434
+ |`Array<(a, b)>`|An array containing all key-value pairs from the given map|
435
+
436
+ ### Map.**fromArray**
437
+
438
+ <details disabled>
439
+ <summary tabindex="-1">Added in <code>0.2.0</code></summary>
440
+ No other changes yet.
441
+ </details>
442
+
443
+ ```grain
444
+ fromArray : Array<(a, b)> -> Map<a, b>
445
+ ```
446
+
447
+ Creates a map from an array.
448
+
449
+ Parameters:
450
+
451
+ |param|type|description|
452
+ |-----|----|-----------|
453
+ |`array`|`Array<(a, b)>`|The array to convert|
454
+
455
+ Returns:
456
+
457
+ |type|description|
458
+ |----|-----------|
459
+ |`Map<a, b>`|A map containing all key-value pairs from the array|
460
+
461
+ ### Map.**filter**
462
+
463
+ <details disabled>
464
+ <summary tabindex="-1">Added in <code>0.2.0</code></summary>
465
+ No other changes yet.
466
+ </details>
467
+
468
+ ```grain
469
+ filter : (((a, b) -> Bool), Map<a, b>) -> Void
470
+ ```
471
+
472
+ Removes key-value pairs from a map where a predicate function returns `false`.
473
+
474
+ Parameters:
475
+
476
+ |param|type|description|
477
+ |-----|----|-----------|
478
+ |`fn`|`(a, b) -> Bool`|The predicate function to indicate which key-value pairs to remove from the map, where returning `false` indicates the key-value pair should be removed|
479
+ |`map`|`Map<a, b>`|The map to iterate|
480
+
481
+ ### Map.**reject**
482
+
483
+ <details disabled>
484
+ <summary tabindex="-1">Added in <code>0.2.0</code></summary>
485
+ No other changes yet.
486
+ </details>
487
+
488
+ ```grain
489
+ reject : (((a, b) -> Bool), Map<a, b>) -> Void
490
+ ```
491
+
492
+ Removes key-value pairs from a map where a predicate function returns `true`.
493
+
494
+ Parameters:
495
+
496
+ |param|type|description|
497
+ |-----|----|-----------|
498
+ |`fn`|`(a, b) -> Bool`|The predicate function to indicate which key-value pairs to remove from the map, where returning `true` indicates the key-value pair should be removed|
499
+ |`map`|`Map<a, b>`|The map to iterate|
500
+
501
+ ### Map.**getInternalStats**
502
+
503
+ <details disabled>
504
+ <summary tabindex="-1">Added in <code>0.2.0</code></summary>
505
+ No other changes yet.
506
+ </details>
507
+
508
+ ```grain
509
+ getInternalStats : Map<a, b> -> (Number, Number)
510
+ ```
511
+
512
+ Provides data representing the internal state state of the map.
513
+
514
+ Parameters:
515
+
516
+ |param|type|description|
517
+ |-----|----|-----------|
518
+ |`map`|`Map<a, b>`|The map to inspect|
519
+
520
+ Returns:
521
+
522
+ |type|description|
523
+ |----|-----------|
524
+ |`(Number, Number)`|The internal state of the map|
525
+
package/number.gr CHANGED
@@ -71,19 +71,16 @@ export let div = (/)
71
71
  *
72
72
  * @since v0.4.0
73
73
  */
74
- @disableGC
75
- export let rec sqrt = (x: Number) => {
74
+ @unsafe
75
+ export let sqrt = (x: Number) => {
76
76
  let xval = coerceNumberToWasmF64(x)
77
77
  let x = WasmI32.fromGrain(x)
78
78
  let sqrtd = WasmF64.sqrt(xval)
79
- let ret = if (!isFloat(x) && WasmF64.eq(sqrtd, WasmF64.trunc(sqrtd))) {
79
+ if (!isFloat(x) && WasmF64.eq(sqrtd, WasmF64.trunc(sqrtd))) {
80
80
  WasmI32.toGrain(reducedInteger(WasmI64.truncF64S(sqrtd))): Number
81
81
  } else {
82
82
  WasmI32.toGrain(newFloat64(sqrtd)): Number
83
83
  }
84
- Memory.decRef(WasmI32.fromGrain(x))
85
- Memory.decRef(WasmI32.fromGrain(sqrt))
86
- ret
87
84
  }
88
85
 
89
86
  /**
@@ -134,14 +131,11 @@ export let max = (x: Number, y: Number) => if (x > y) x else y
134
131
  *
135
132
  * @since v0.4.0
136
133
  */
137
- @disableGC
138
- export let rec ceil = (x: Number) => {
134
+ @unsafe
135
+ export let ceil = (x: Number) => {
139
136
  let xval = coerceNumberToWasmF64(x)
140
137
  let ceiling = WasmI64.truncF64S(WasmF64.ceil(xval))
141
- let ret = WasmI32.toGrain(reducedInteger(ceiling)): Number
142
- Memory.decRef(WasmI32.fromGrain(x))
143
- Memory.decRef(WasmI32.fromGrain(ceil))
144
- ret
138
+ WasmI32.toGrain(reducedInteger(ceiling)): Number
145
139
  }
146
140
 
147
141
  /**
@@ -152,14 +146,11 @@ export let rec ceil = (x: Number) => {
152
146
  *
153
147
  * @since v0.4.0
154
148
  */
155
- @disableGC
156
- export let rec floor = (x: Number) => {
149
+ @unsafe
150
+ export let floor = (x: Number) => {
157
151
  let xval = coerceNumberToWasmF64(x)
158
152
  let floored = WasmI64.truncF64S(WasmF64.floor(xval))
159
- let ret = WasmI32.toGrain(reducedInteger(floored)): Number
160
- Memory.decRef(WasmI32.fromGrain(x))
161
- Memory.decRef(WasmI32.fromGrain(floor))
162
- ret
153
+ WasmI32.toGrain(reducedInteger(floored)): Number
163
154
  }
164
155
 
165
156
  /**
@@ -170,14 +161,11 @@ export let rec floor = (x: Number) => {
170
161
  *
171
162
  * @since v0.4.0
172
163
  */
173
- @disableGC
174
- export let rec trunc = (x: Number) => {
164
+ @unsafe
165
+ export let trunc = (x: Number) => {
175
166
  let xval = coerceNumberToWasmF64(x)
176
167
  let trunced = WasmI64.truncF64S(xval)
177
- let ret = WasmI32.toGrain(reducedInteger(trunced)): Number
178
- Memory.decRef(WasmI32.fromGrain(x))
179
- Memory.decRef(WasmI32.fromGrain(trunc))
180
- ret
168
+ WasmI32.toGrain(reducedInteger(trunced)): Number
181
169
  }
182
170
 
183
171
  /**
@@ -188,14 +176,11 @@ export let rec trunc = (x: Number) => {
188
176
  *
189
177
  * @since v0.4.0
190
178
  */
191
- @disableGC
192
- export let rec round = (x: Number) => {
179
+ @unsafe
180
+ export let round = (x: Number) => {
193
181
  let xval = coerceNumberToWasmF64(x)
194
182
  let rounded = WasmI64.truncF64S(WasmF64.nearest(xval))
195
- let ret = WasmI32.toGrain(reducedInteger(rounded)): Number
196
- Memory.decRef(WasmI32.fromGrain(x))
197
- Memory.decRef(WasmI32.fromGrain(round))
198
- ret
183
+ WasmI32.toGrain(reducedInteger(rounded)): Number
199
184
  }
200
185
 
201
186
  /**
@@ -216,21 +201,21 @@ export let abs = (x: Number) => if (0 > x) x * -1 else x
216
201
  *
217
202
  * @since v0.4.0
218
203
  */
219
- export let neg = (x: Number) => if (x > 0) x * -1 else x
204
+ export let neg = (x: Number) => x * -1
220
205
 
221
206
  /**
222
207
  * Checks if a number is finite.
223
208
  * All values are finite exept for floating point NaN, infinity or negative infinity.
224
209
  *
225
210
  * @param x: The number to check
226
- * @returns `true` if the value is finite, otherwise `false`
211
+ * @returns `true` if the value is finite or `false` otherwise
227
212
  *
228
213
  * @since v0.4.0
229
214
  */
230
- @disableGC
231
- export let rec isFinite = (x: Number) => {
215
+ @unsafe
216
+ export let isFinite = (x: Number) => {
232
217
  let asPtr = WasmI32.fromGrain(x)
233
- let ret = if (isBoxedNumber(asPtr)) {
218
+ if (isBoxedNumber(asPtr)) {
234
219
  // Boxed numbers can have multiple subtypes, of which float32 and float64 can be infinite.
235
220
  let tag = WasmI32.load(asPtr, 4n)
236
221
  if (WasmI32.eq(tag, Tags._GRAIN_FLOAT64_BOXED_NUM_TAG)) {
@@ -251,9 +236,6 @@ export let rec isFinite = (x: Number) => {
251
236
  // Simple numbers are integers and cannot be infinite.
252
237
  true
253
238
  }
254
- Memory.decRef(asPtr)
255
- Memory.decRef(WasmI32.fromGrain(isFinite))
256
- ret
257
239
  }
258
240
 
259
241
  /**
@@ -265,10 +247,10 @@ export let rec isFinite = (x: Number) => {
265
247
  *
266
248
  * @since v0.4.0
267
249
  */
268
- @disableGC
269
- export let rec isNaN = (x: Number) => {
250
+ @unsafe
251
+ export let isNaN = (x: Number) => {
270
252
  let asPtr = WasmI32.fromGrain(x)
271
- let ret = if (isBoxedNumber(asPtr)) {
253
+ if (isBoxedNumber(asPtr)) {
272
254
  // Boxed numbers can have multiple subtypes, of which float32 and float64 can be NaN.
273
255
  let tag = WasmI32.load(asPtr, 4n)
274
256
  if (WasmI32.eq(tag, Tags._GRAIN_FLOAT64_BOXED_NUM_TAG)) {
@@ -287,9 +269,6 @@ export let rec isNaN = (x: Number) => {
287
269
  // Simple numbers are integers and cannot be NaN.
288
270
  false
289
271
  }
290
- Memory.decRef(asPtr)
291
- Memory.decRef(WasmI32.fromGrain(isNaN))
292
- ret
293
272
  }
294
273
 
295
274
  /**
@@ -297,16 +276,16 @@ export let rec isNaN = (x: Number) => {
297
276
  * Note that this function is not the exact opposite of isFinite(Number) in that it doesn't return true for NaN.
298
277
  *
299
278
  * @param x: The number to check
300
- * @returns `true` if the value is infinite, otherwise `false`
279
+ * @returns `true` if the value is infinite or `false` otherwise
301
280
  *
302
281
  * @since v0.4.0
303
282
  */
304
- @disableGC
305
- export let rec isInfinite = (x: Number) => {
283
+ @unsafe
284
+ export let isInfinite = (x: Number) => {
306
285
  // The following code is equivalent to (!isFinite(x) && !isNaN(x)),
307
286
  // so see those functions to understand what's going on here.
308
287
  let asPtr = WasmI32.fromGrain(x)
309
- let ret = if (isBoxedNumber(asPtr)) {
288
+ if (isBoxedNumber(asPtr)) {
310
289
  let tag = WasmI32.load(asPtr, 4n)
311
290
  if (WasmI32.eq(tag, Tags._GRAIN_FLOAT64_BOXED_NUM_TAG)) {
312
291
  let wf64 = WasmF64.load(asPtr, 8n)
@@ -320,24 +299,21 @@ export let rec isInfinite = (x: Number) => {
320
299
  } else {
321
300
  false
322
301
  }
323
- Memory.decRef(asPtr)
324
- Memory.decRef(WasmI32.fromGrain(isInfinite))
325
- ret
326
302
  }
327
303
 
328
304
  /**
329
305
  * Parses a string representation of an integer into a `Number` using the
330
306
  * specified radix (also known as a number system "base").
331
- *
307
+ *
332
308
  * If the string has a radix prefix (i.e. "0x"/"0X", "0o"/"0O", or "0b"/"0B"
333
309
  * for radixes 16, 8, or 2 respectively), the supplied radix is ignored in
334
310
  * favor of the prefix. Underscores that appear in the numeric portion of the
335
311
  * input are ignored.
336
- *
312
+ *
337
313
  * @param input: The string to parse
338
314
  * @param radix: The number system base to use when parsing the input string
339
315
  * @returns `Ok(value)` containing the parsed number on a successful parse or `Err(msg)` containing an error message string otherwise
340
- *
316
+ *
341
317
  * @since v0.4.5
342
318
  */
343
319
  export parseInt