@grain/stdlib 0.5.2 → 0.5.4

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 (54) hide show
  1. package/CHANGELOG.md +59 -0
  2. package/array.gr +61 -1
  3. package/array.md +113 -0
  4. package/bigint.md +30 -30
  5. package/buffer.gr +24 -22
  6. package/char.gr +2 -2
  7. package/float32.md +3 -3
  8. package/float64.md +3 -3
  9. package/immutablemap.gr +493 -0
  10. package/immutablemap.md +479 -0
  11. package/immutablepriorityqueue.gr +360 -0
  12. package/immutablepriorityqueue.md +291 -0
  13. package/immutableset.gr +498 -0
  14. package/immutableset.md +449 -0
  15. package/list.gr +75 -2
  16. package/list.md +110 -0
  17. package/map.gr +1 -2
  18. package/marshal.gr +1058 -0
  19. package/marshal.md +76 -0
  20. package/number.gr +689 -23
  21. package/number.md +362 -27
  22. package/package.json +1 -1
  23. package/pervasives.gr +16 -5
  24. package/pervasives.md +28 -0
  25. package/priorityqueue.gr +261 -0
  26. package/priorityqueue.md +309 -0
  27. package/queue.gr +14 -1
  28. package/queue.md +16 -1
  29. package/regex.gr +90 -67
  30. package/runtime/bigint.gr +4 -4
  31. package/runtime/compare.gr +179 -0
  32. package/runtime/compare.md +6 -0
  33. package/runtime/equal.gr +3 -3
  34. package/runtime/exception.gr +9 -5
  35. package/runtime/exception.md +8 -2
  36. package/runtime/gc.gr +2 -1
  37. package/runtime/malloc.gr +1 -3
  38. package/runtime/numberUtils.gr +11 -11
  39. package/runtime/numbers.gr +423 -100
  40. package/runtime/numbers.md +50 -0
  41. package/runtime/string.gr +4 -2
  42. package/set.gr +26 -27
  43. package/stack.gr +12 -0
  44. package/stack.md +15 -0
  45. package/string.gr +409 -53
  46. package/string.md +164 -1
  47. package/sys/file.gr +4 -4
  48. package/sys/file.md +3 -3
  49. package/sys/process.gr +3 -3
  50. package/sys/process.md +3 -3
  51. package/sys/random.gr +2 -2
  52. package/sys/random.md +2 -2
  53. package/sys/time.gr +2 -2
  54. package/sys/time.md +2 -2
package/runtime/gc.gr CHANGED
@@ -213,7 +213,8 @@ let rec decRef = (userPtr: WasmI32, ignoreZeros: Bool) => {
213
213
  } else {
214
214
  userPtr
215
215
  }
216
- }, decRefChildren = (userPtr: WasmI32) => {
216
+ },
217
+ decRefChildren = (userPtr: WasmI32) => {
217
218
  match (WasmI32.load(userPtr, 0n)) {
218
219
  t when t == Tags._GRAIN_BOXED_NUM_HEAP_TAG => {
219
220
  let tag = WasmI32.load(userPtr, 4n)
package/runtime/malloc.gr CHANGED
@@ -28,8 +28,6 @@ primitive (!): Bool -> Bool = "@not"
28
28
  primitive (&&): (Bool, Bool) -> Bool = "@and"
29
29
  primitive (||): (Bool, Bool) -> Bool = "@or"
30
30
 
31
- primitive throw: Exception -> a = "@throw"
32
-
33
31
  primitive heapBase: WasmI32 = "@heap.base"
34
32
 
35
33
  /* UNDERSTANDING THE STRUCTURE OF THE FREE LIST
@@ -221,7 +219,7 @@ let morecore = (nbytes: WasmI32) => {
221
219
 
222
220
  // If there was an error, fail
223
221
  if (cp == -1n) {
224
- throw Exception.OutOfMemory
222
+ Exception.panic("OutOfMemory: Maximum memory size exceeded")
225
223
  } else {
226
224
  // Set the size of the new block to the amount the
227
225
  // heap was grown.
@@ -728,16 +728,16 @@ export let decimalCount32 = value => {
728
728
  1n + (if (WasmI32.geU(value, 10n)) 1n else 0n)
729
729
  } else {
730
730
  3n +
731
- (if (WasmI32.geU(value, 10000n)) 1n else 0n) +
732
- (if (WasmI32.geU(value, 1000n)) 1n else 0n)
731
+ (if (WasmI32.geU(value, 10000n)) 1n else 0n) +
732
+ (if (WasmI32.geU(value, 1000n)) 1n else 0n)
733
733
  }
734
734
  } else {
735
735
  if (WasmI32.ltU(value, 10000000n)) {
736
736
  6n + (if (WasmI32.geU(value, 1000000n)) 1n else 0n)
737
737
  } else {
738
738
  8n +
739
- (if (WasmI32.geU(value, 1000000000n)) 1n else 0n) +
740
- (if (WasmI32.geU(value, 100000000n)) 1n else 0n)
739
+ (if (WasmI32.geU(value, 1000000000n)) 1n else 0n) +
740
+ (if (WasmI32.geU(value, 100000000n)) 1n else 0n)
741
741
  }
742
742
  }
743
743
  }
@@ -749,20 +749,20 @@ let decimalCount64High = value => {
749
749
  if (WasmI64.ltU(value, 1000000000000000N)) {
750
750
  if (WasmI64.ltU(value, 1000000000000N)) {
751
751
  10n +
752
- (if (WasmI64.geU(value, 100000000000N)) 1n else 0n) +
753
- (if (WasmI64.geU(value, 10000000000N)) 1n else 0n)
752
+ (if (WasmI64.geU(value, 100000000000N)) 1n else 0n) +
753
+ (if (WasmI64.geU(value, 10000000000N)) 1n else 0n)
754
754
  } else {
755
755
  13n +
756
- (if (WasmI64.geU(value, 100000000000000N)) 1n else 0n) +
757
- (if (WasmI64.geU(value, 10000000000000N)) 1n else 0n)
756
+ (if (WasmI64.geU(value, 100000000000000N)) 1n else 0n) +
757
+ (if (WasmI64.geU(value, 10000000000000N)) 1n else 0n)
758
758
  }
759
759
  } else {
760
760
  if (WasmI64.ltU(value, 100000000000000000N)) {
761
761
  16n + (if (WasmI64.geU(value, 10000000000000000N)) 1n else 0n)
762
762
  } else {
763
763
  18n +
764
- (if (WasmI64.geU(value, 0x8AC7230489E80000N)) 1n else 0n) +
765
- (if (WasmI64.geU(value, 1000000000000000000N)) 1n else 0n)
764
+ (if (WasmI64.geU(value, 0x8AC7230489E80000N)) 1n else 0n) +
765
+ (if (WasmI64.geU(value, 1000000000000000000N)) 1n else 0n)
766
766
  }
767
767
  }
768
768
  }
@@ -774,7 +774,7 @@ let ulog_base = (num, base) => {
774
774
  63n - WasmI32.wrapI64(WasmI64.clz(num)),
775
775
  31n - WasmI32.clz(base)
776
776
  ) +
777
- 1n
777
+ 1n
778
778
  } else {
779
779
  let b64 = WasmI64.extendI32U(base)
780
780
  let mut b = b64