@grain/stdlib 0.5.13 → 0.6.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 (155) hide show
  1. package/CHANGELOG.md +193 -0
  2. package/LICENSE +1 -1
  3. package/README.md +25 -2
  4. package/array.gr +1512 -199
  5. package/array.md +2032 -94
  6. package/bigint.gr +239 -140
  7. package/bigint.md +450 -106
  8. package/buffer.gr +595 -102
  9. package/buffer.md +903 -145
  10. package/bytes.gr +401 -110
  11. package/bytes.md +551 -63
  12. package/char.gr +228 -49
  13. package/char.md +373 -7
  14. package/exception.gr +26 -12
  15. package/exception.md +29 -5
  16. package/float32.gr +130 -109
  17. package/float32.md +185 -57
  18. package/float64.gr +112 -99
  19. package/float64.md +185 -57
  20. package/hash.gr +47 -37
  21. package/hash.md +21 -3
  22. package/int16.gr +430 -0
  23. package/int16.md +618 -0
  24. package/int32.gr +200 -269
  25. package/int32.md +254 -289
  26. package/int64.gr +142 -225
  27. package/int64.md +254 -289
  28. package/int8.gr +511 -0
  29. package/int8.md +786 -0
  30. package/json.gr +2084 -0
  31. package/json.md +608 -0
  32. package/list.gr +120 -68
  33. package/list.md +125 -80
  34. package/map.gr +560 -57
  35. package/map.md +672 -56
  36. package/marshal.gr +239 -227
  37. package/marshal.md +36 -4
  38. package/number.gr +626 -676
  39. package/number.md +738 -153
  40. package/option.gr +33 -35
  41. package/option.md +58 -42
  42. package/package.json +2 -2
  43. package/path.gr +148 -187
  44. package/path.md +47 -96
  45. package/pervasives.gr +75 -416
  46. package/pervasives.md +85 -180
  47. package/priorityqueue.gr +433 -74
  48. package/priorityqueue.md +422 -54
  49. package/queue.gr +362 -80
  50. package/queue.md +433 -38
  51. package/random.gr +67 -75
  52. package/random.md +68 -40
  53. package/range.gr +135 -63
  54. package/range.md +198 -43
  55. package/rational.gr +284 -0
  56. package/rational.md +545 -0
  57. package/regex.gr +933 -1066
  58. package/regex.md +59 -60
  59. package/result.gr +23 -25
  60. package/result.md +54 -39
  61. package/runtime/atof/common.gr +78 -82
  62. package/runtime/atof/common.md +22 -10
  63. package/runtime/atof/decimal.gr +102 -127
  64. package/runtime/atof/decimal.md +28 -7
  65. package/runtime/atof/lemire.gr +56 -71
  66. package/runtime/atof/lemire.md +9 -1
  67. package/runtime/atof/parse.gr +83 -110
  68. package/runtime/atof/parse.md +12 -2
  69. package/runtime/atof/slow.gr +28 -35
  70. package/runtime/atof/slow.md +9 -1
  71. package/runtime/atof/table.gr +19 -18
  72. package/runtime/atof/table.md +10 -2
  73. package/runtime/atoi/parse.gr +153 -136
  74. package/runtime/atoi/parse.md +50 -1
  75. package/runtime/bigint.gr +410 -517
  76. package/runtime/bigint.md +71 -57
  77. package/runtime/compare.gr +176 -85
  78. package/runtime/compare.md +31 -1
  79. package/runtime/dataStructures.gr +144 -32
  80. package/runtime/dataStructures.md +267 -31
  81. package/runtime/debugPrint.gr +34 -15
  82. package/runtime/debugPrint.md +37 -5
  83. package/runtime/equal.gr +53 -52
  84. package/runtime/equal.md +30 -1
  85. package/runtime/exception.gr +38 -47
  86. package/runtime/exception.md +10 -8
  87. package/runtime/gc.gr +23 -152
  88. package/runtime/gc.md +13 -17
  89. package/runtime/malloc.gr +31 -31
  90. package/runtime/malloc.md +11 -3
  91. package/runtime/numberUtils.gr +191 -172
  92. package/runtime/numberUtils.md +17 -9
  93. package/runtime/numbers.gr +1695 -1021
  94. package/runtime/numbers.md +1098 -134
  95. package/runtime/string.gr +540 -242
  96. package/runtime/string.md +76 -6
  97. package/runtime/unsafe/constants.gr +30 -13
  98. package/runtime/unsafe/constants.md +80 -0
  99. package/runtime/unsafe/conv.gr +55 -28
  100. package/runtime/unsafe/conv.md +41 -9
  101. package/runtime/unsafe/memory.gr +10 -30
  102. package/runtime/unsafe/memory.md +15 -19
  103. package/runtime/unsafe/tags.gr +37 -21
  104. package/runtime/unsafe/tags.md +88 -8
  105. package/runtime/unsafe/wasmf32.gr +30 -36
  106. package/runtime/unsafe/wasmf32.md +64 -56
  107. package/runtime/unsafe/wasmf64.gr +30 -36
  108. package/runtime/unsafe/wasmf64.md +64 -56
  109. package/runtime/unsafe/wasmi32.gr +49 -66
  110. package/runtime/unsafe/wasmi32.md +102 -94
  111. package/runtime/unsafe/wasmi64.gr +52 -79
  112. package/runtime/unsafe/wasmi64.md +108 -100
  113. package/runtime/utils/printing.gr +13 -15
  114. package/runtime/utils/printing.md +11 -3
  115. package/runtime/wasi.gr +294 -295
  116. package/runtime/wasi.md +62 -42
  117. package/set.gr +574 -64
  118. package/set.md +634 -54
  119. package/stack.gr +181 -64
  120. package/stack.md +271 -42
  121. package/string.gr +453 -533
  122. package/string.md +241 -151
  123. package/uint16.gr +369 -0
  124. package/uint16.md +585 -0
  125. package/uint32.gr +470 -0
  126. package/uint32.md +737 -0
  127. package/uint64.gr +471 -0
  128. package/uint64.md +737 -0
  129. package/uint8.gr +369 -0
  130. package/uint8.md +585 -0
  131. package/uri.gr +1093 -0
  132. package/uri.md +477 -0
  133. package/{sys → wasi}/file.gr +914 -500
  134. package/{sys → wasi}/file.md +454 -50
  135. package/wasi/process.gr +292 -0
  136. package/{sys → wasi}/process.md +164 -6
  137. package/wasi/random.gr +77 -0
  138. package/wasi/random.md +80 -0
  139. package/{sys → wasi}/time.gr +15 -22
  140. package/{sys → wasi}/time.md +5 -5
  141. package/immutablearray.gr +0 -929
  142. package/immutablearray.md +0 -1038
  143. package/immutablemap.gr +0 -493
  144. package/immutablemap.md +0 -479
  145. package/immutablepriorityqueue.gr +0 -360
  146. package/immutablepriorityqueue.md +0 -291
  147. package/immutableset.gr +0 -498
  148. package/immutableset.md +0 -449
  149. package/runtime/debug.gr +0 -2
  150. package/runtime/debug.md +0 -6
  151. package/runtime/unsafe/errors.gr +0 -36
  152. package/runtime/unsafe/errors.md +0 -204
  153. package/sys/process.gr +0 -254
  154. package/sys/random.gr +0 -79
  155. package/sys/random.md +0 -66
@@ -1,22 +1,16 @@
1
1
  /**
2
- * @module Time: Access to system clocks.
2
+ * Access to system clocks.
3
3
  *
4
- * @example import Time from "sys/time"
4
+ * @example from "wasi/time" include Time
5
5
  */
6
+ module Time
6
7
 
7
- import WasmI32, {
8
- add as (+),
9
- eq as (==),
10
- ne as (!=),
11
- } from "runtime/unsafe/wasmi32"
12
- import Memory from "runtime/unsafe/memory"
13
- import Wasi from "runtime/wasi"
14
- import Errors from "runtime/unsafe/errors"
15
- import { allocateInt64, tagSimpleNumber } from "runtime/dataStructures"
16
-
17
- /**
18
- * @section Values: Functions and constants included in the Time module.
19
- */
8
+ from "runtime/unsafe/wasmi32" include WasmI32
9
+ use WasmI32.{ (+), (==), (!=) }
10
+ from "runtime/unsafe/memory" include Memory
11
+ from "runtime/wasi" include Wasi
12
+ from "runtime/dataStructures" include DataStructures
13
+ use DataStructures.{ allocateInt64, tagSimpleNumber }
20
14
 
21
15
  @unsafe
22
16
  let getClockTime = (clockid, precision) => {
@@ -25,10 +19,9 @@ let getClockTime = (clockid, precision) => {
25
19
  let err = Wasi.clock_time_get(clockid, precision, timePtr)
26
20
  if (err != Wasi._ESUCCESS) {
27
21
  Memory.free(int64Ptr)
28
- Err(Wasi.SystemError(tagSimpleNumber(err)))
29
- } else {
30
- Ok(WasmI32.toGrain(int64Ptr): Int64)
22
+ return Err(Wasi.SystemError(tagSimpleNumber(err)))
31
23
  }
24
+ return Ok(WasmI32.toGrain(int64Ptr): Int64)
32
25
  }
33
26
 
34
27
  /**
@@ -38,7 +31,7 @@ let getClockTime = (clockid, precision) => {
38
31
  * @returns `Ok(time)` of the current time if successful or `Err(exception)` otherwise
39
32
  */
40
33
  @unsafe
41
- export let realTime = () => {
34
+ provide let realTime = () => {
42
35
  getClockTime(Wasi._CLOCK_REALTIME, 1000N)
43
36
  }
44
37
 
@@ -51,7 +44,7 @@ export let realTime = () => {
51
44
  * @returns `Ok(time)` of the current time if successful or `Err(exception)` otherwise
52
45
  */
53
46
  @unsafe
54
- export let monotonicTime = () => {
47
+ provide let monotonicTime = () => {
55
48
  getClockTime(Wasi._CLOCK_MONOTONIC, 1N)
56
49
  }
57
50
 
@@ -61,7 +54,7 @@ export let monotonicTime = () => {
61
54
  * @returns `Ok(elapsed)` of the elapsed nanoseconds if successful or `Err(exception)` otherwise
62
55
  */
63
56
  @unsafe
64
- export let processCpuTime = () => {
57
+ provide let processCpuTime = () => {
65
58
  getClockTime(Wasi._CLOCK_PROCESS_CPUTIME, 1N)
66
59
  }
67
60
 
@@ -71,6 +64,6 @@ export let processCpuTime = () => {
71
64
  * @returns `Ok(elapsed)` of the elapsed nanoseconds if successful or `Err(exception)` otherwise
72
65
  */
73
66
  @unsafe
74
- export let threadCpuTime = () => {
67
+ provide let threadCpuTime = () => {
75
68
  getClockTime(Wasi._CLOCK_THREAD_CPUTIME, 1N)
76
69
  }
@@ -5,7 +5,7 @@ title: Time
5
5
  Access to system clocks.
6
6
 
7
7
  ```grain
8
- import Time from "sys/time"
8
+ from "wasi/time" include Time
9
9
  ```
10
10
 
11
11
  ## Values
@@ -15,7 +15,7 @@ Functions and constants included in the Time module.
15
15
  ### Time.**realTime**
16
16
 
17
17
  ```grain
18
- realTime : () -> Result<Int64, Exception>
18
+ realTime : () => Result<Int64, Exception>
19
19
  ```
20
20
 
21
21
  Get the current time, in nanoseconds.
@@ -30,7 +30,7 @@ Returns:
30
30
  ### Time.**monotonicTime**
31
31
 
32
32
  ```grain
33
- monotonicTime : () -> Result<Int64, Exception>
33
+ monotonicTime : () => Result<Int64, Exception>
34
34
  ```
35
35
 
36
36
  Get the time of the system's high-resolution clock, in nanoseconds.
@@ -47,7 +47,7 @@ Returns:
47
47
  ### Time.**processCpuTime**
48
48
 
49
49
  ```grain
50
- processCpuTime : () -> Result<Int64, Exception>
50
+ processCpuTime : () => Result<Int64, Exception>
51
51
  ```
52
52
 
53
53
  Get the number of nanoseconds elapsed since the process began.
@@ -61,7 +61,7 @@ Returns:
61
61
  ### Time.**threadCpuTime**
62
62
 
63
63
  ```grain
64
- threadCpuTime : () -> Result<Int64, Exception>
64
+ threadCpuTime : () => Result<Int64, Exception>
65
65
  ```
66
66
 
67
67
  Get the number of nanoseconds elapsed since the thread began.