@grain/stdlib 0.4.2 → 0.4.6

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 (61) hide show
  1. package/CHANGELOG.md +52 -0
  2. package/LICENSE +1 -1
  3. package/array.gr +200 -89
  4. package/array.md +81 -5
  5. package/buffer.gr +93 -36
  6. package/bytes.gr +10 -10
  7. package/char.gr +112 -56
  8. package/char.md +200 -0
  9. package/float32.gr +120 -4
  10. package/float32.md +315 -0
  11. package/float64.gr +120 -4
  12. package/float64.md +315 -0
  13. package/hash.gr +42 -15
  14. package/hash.md +44 -0
  15. package/int32.gr +370 -75
  16. package/int32.md +833 -0
  17. package/int64.gr +370 -75
  18. package/int64.md +833 -0
  19. package/list.gr +121 -50
  20. package/map.gr +106 -110
  21. package/number.gr +37 -1
  22. package/number.md +66 -0
  23. package/option.gr +260 -53
  24. package/option.md +579 -0
  25. package/package.json +1 -1
  26. package/pervasives.gr +32 -20
  27. package/queue.gr +102 -30
  28. package/queue.md +191 -0
  29. package/range.gr +26 -26
  30. package/range.md +1 -1
  31. package/regex.md +9 -9
  32. package/result.gr +216 -70
  33. package/result.md +446 -0
  34. package/runtime/dataStructures.gr +28 -29
  35. package/runtime/debug.gr +0 -1
  36. package/runtime/equal.gr +37 -16
  37. package/runtime/exception.gr +28 -15
  38. package/runtime/gc.gr +33 -20
  39. package/runtime/malloc.gr +19 -11
  40. package/runtime/numberUtils.gr +208 -103
  41. package/runtime/numbers.gr +217 -118
  42. package/runtime/string.gr +98 -39
  43. package/runtime/stringUtils.gr +176 -0
  44. package/runtime/unsafe/conv.gr +10 -10
  45. package/runtime/unsafe/memory.gr +14 -3
  46. package/runtime/unsafe/printWasm.gr +4 -4
  47. package/runtime/unsafe/tags.gr +2 -2
  48. package/runtime/unsafe/wasmf32.gr +9 -2
  49. package/runtime/unsafe/wasmf64.gr +9 -2
  50. package/runtime/unsafe/wasmi32.gr +65 -47
  51. package/runtime/unsafe/wasmi64.gr +78 -50
  52. package/runtime/wasi.gr +199 -45
  53. package/set.gr +281 -119
  54. package/set.md +502 -0
  55. package/stack.gr +26 -26
  56. package/string.gr +657 -341
  57. package/string.md +815 -0
  58. package/sys/file.gr +356 -177
  59. package/sys/process.gr +10 -6
  60. package/sys/random.gr +3 -6
  61. package/sys/time.gr +3 -3
package/float32.md ADDED
@@ -0,0 +1,315 @@
1
+ ---
2
+ title: Float32
3
+ ---
4
+
5
+ Utilities for working with the Float32 type.
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 Float32 from "float32"
14
+ ```
15
+
16
+ ## Conversions
17
+
18
+ Functions for converting between Numbers and the Float32 type.
19
+
20
+ ### Float32.**fromNumber**
21
+
22
+ <details disabled>
23
+ <summary tabindex="-1">Added in <code>0.2.0</code></summary>
24
+ No other changes yet.
25
+ </details>
26
+
27
+ ```grain
28
+ fromNumber : Number -> Float32
29
+ ```
30
+
31
+ Converts a Number to a Float32.
32
+
33
+ Parameters:
34
+
35
+ |param|type|description|
36
+ |-----|----|-----------|
37
+ |`number`|`Number`|The value to convert|
38
+
39
+ Returns:
40
+
41
+ |type|description|
42
+ |----|-----------|
43
+ |`Float32`|The Number represented as a Float32|
44
+
45
+ ### Float32.**toNumber**
46
+
47
+ <details disabled>
48
+ <summary tabindex="-1">Added in <code>0.2.0</code></summary>
49
+ No other changes yet.
50
+ </details>
51
+
52
+ ```grain
53
+ toNumber : Float32 -> Number
54
+ ```
55
+
56
+ Converts a Float32 to a Number.
57
+
58
+ Parameters:
59
+
60
+ |param|type|description|
61
+ |-----|----|-----------|
62
+ |`float`|`Float32`|The value to convert|
63
+
64
+ Returns:
65
+
66
+ |type|description|
67
+ |----|-----------|
68
+ |`Number`|The Float32 represented as a Number|
69
+
70
+ ## Operations
71
+
72
+ Mathematical operations for Float32 values.
73
+
74
+ ### Float32.**add**
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
+ add : (Float32, Float32) -> Float32
83
+ ```
84
+
85
+ Computes the sum of its operands.
86
+
87
+ Parameters:
88
+
89
+ |param|type|description|
90
+ |-----|----|-----------|
91
+ |`x`|`Float32`|The first operand|
92
+ |`y`|`Float32`|The second operand|
93
+
94
+ Returns:
95
+
96
+ |type|description|
97
+ |----|-----------|
98
+ |`Float32`|The sum of the two operands|
99
+
100
+ ### Float32.**sub**
101
+
102
+ <details disabled>
103
+ <summary tabindex="-1">Added in <code>0.2.0</code></summary>
104
+ No other changes yet.
105
+ </details>
106
+
107
+ ```grain
108
+ sub : (Float32, Float32) -> Float32
109
+ ```
110
+
111
+ Computes the difference of its operands.
112
+
113
+ Parameters:
114
+
115
+ |param|type|description|
116
+ |-----|----|-----------|
117
+ |`x`|`Float32`|The first operand|
118
+ |`y`|`Float32`|The second operand|
119
+
120
+ Returns:
121
+
122
+ |type|description|
123
+ |----|-----------|
124
+ |`Float32`|The difference of the two operands|
125
+
126
+ ### Float32.**mul**
127
+
128
+ <details disabled>
129
+ <summary tabindex="-1">Added in <code>0.2.0</code></summary>
130
+ No other changes yet.
131
+ </details>
132
+
133
+ ```grain
134
+ mul : (Float32, Float32) -> Float32
135
+ ```
136
+
137
+ Computes the product of its operands.
138
+
139
+ Parameters:
140
+
141
+ |param|type|description|
142
+ |-----|----|-----------|
143
+ |`x`|`Float32`|The first operand|
144
+ |`y`|`Float32`|The second operand|
145
+
146
+ Returns:
147
+
148
+ |type|description|
149
+ |----|-----------|
150
+ |`Float32`|The product of the two operands|
151
+
152
+ ### Float32.**div**
153
+
154
+ <details disabled>
155
+ <summary tabindex="-1">Added in <code>0.2.0</code></summary>
156
+ No other changes yet.
157
+ </details>
158
+
159
+ ```grain
160
+ div : (Float32, Float32) -> Float32
161
+ ```
162
+
163
+ Computes the quotient of its operands.
164
+
165
+ Parameters:
166
+
167
+ |param|type|description|
168
+ |-----|----|-----------|
169
+ |`x`|`Float32`|The first operand|
170
+ |`y`|`Float32`|The second operand|
171
+
172
+ Returns:
173
+
174
+ |type|description|
175
+ |----|-----------|
176
+ |`Float32`|The quotient of the two operands|
177
+
178
+ ## Comparisons
179
+
180
+ Functions for comparing Float32 values.
181
+
182
+ ### Float32.**lt**
183
+
184
+ <details disabled>
185
+ <summary tabindex="-1">Added in <code>0.2.0</code></summary>
186
+ No other changes yet.
187
+ </details>
188
+
189
+ ```grain
190
+ lt : (Float32, Float32) -> Bool
191
+ ```
192
+
193
+ Checks if the first value is less than the second value.
194
+
195
+ Parameters:
196
+
197
+ |param|type|description|
198
+ |-----|----|-----------|
199
+ |`x`|`Float32`|The first value|
200
+ |`y`|`Float32`|The second value|
201
+
202
+ Returns:
203
+
204
+ |type|description|
205
+ |----|-----------|
206
+ |`Bool`|`true` if the first value is less than the second value or `false` otherwise|
207
+
208
+ ### Float32.**gt**
209
+
210
+ <details disabled>
211
+ <summary tabindex="-1">Added in <code>0.2.0</code></summary>
212
+ No other changes yet.
213
+ </details>
214
+
215
+ ```grain
216
+ gt : (Float32, Float32) -> Bool
217
+ ```
218
+
219
+ Checks if the first value is greater than the second value.
220
+
221
+ Parameters:
222
+
223
+ |param|type|description|
224
+ |-----|----|-----------|
225
+ |`x`|`Float32`|The first value|
226
+ |`y`|`Float32`|The second value|
227
+
228
+ Returns:
229
+
230
+ |type|description|
231
+ |----|-----------|
232
+ |`Bool`|`true` if the first value is greater than the second value or `false` otherwise|
233
+
234
+ ### Float32.**lte**
235
+
236
+ <details disabled>
237
+ <summary tabindex="-1">Added in <code>0.2.0</code></summary>
238
+ No other changes yet.
239
+ </details>
240
+
241
+ ```grain
242
+ lte : (Float32, Float32) -> Bool
243
+ ```
244
+
245
+ Checks if the first value is less than or equal to the second value.
246
+
247
+ Parameters:
248
+
249
+ |param|type|description|
250
+ |-----|----|-----------|
251
+ |`x`|`Float32`|The first value|
252
+ |`y`|`Float32`|The second value|
253
+
254
+ Returns:
255
+
256
+ |type|description|
257
+ |----|-----------|
258
+ |`Bool`|`true` if the first value is less than or equal to the second value or `false` otherwise|
259
+
260
+ ### Float32.**gte**
261
+
262
+ <details disabled>
263
+ <summary tabindex="-1">Added in <code>0.2.0</code></summary>
264
+ No other changes yet.
265
+ </details>
266
+
267
+ ```grain
268
+ gte : (Float32, Float32) -> Bool
269
+ ```
270
+
271
+ Checks if the first value is greater than or equal to the second value.
272
+
273
+ Parameters:
274
+
275
+ |param|type|description|
276
+ |-----|----|-----------|
277
+ |`x`|`Float32`|The first value|
278
+ |`y`|`Float32`|The second value|
279
+
280
+ Returns:
281
+
282
+ |type|description|
283
+ |----|-----------|
284
+ |`Bool`|`true` if the first value is greater than or equal to the second value or `false` otherwise|
285
+
286
+ ## Constants
287
+
288
+ Float32 constant values.
289
+
290
+ ### Float32.**infinity**
291
+
292
+ <details disabled>
293
+ <summary tabindex="-1">Added in <code>0.4.0</code></summary>
294
+ No other changes yet.
295
+ </details>
296
+
297
+ ```grain
298
+ infinity : Float32
299
+ ```
300
+
301
+ Infinity represented as a Float32 value.
302
+
303
+ ### Float32.**nan**
304
+
305
+ <details disabled>
306
+ <summary tabindex="-1">Added in <code>0.4.0</code></summary>
307
+ No other changes yet.
308
+ </details>
309
+
310
+ ```grain
311
+ nan : Float32
312
+ ```
313
+
314
+ NaN (Not a Number) represented as a Float32 value.
315
+
package/float64.gr CHANGED
@@ -1,3 +1,9 @@
1
+ /**
2
+ * @module Float64: Utilities for working with the Float64 type.
3
+ * @example import Float64 from "float64"
4
+ *
5
+ * @since v0.2.0
6
+ */
1
7
  import WasmI32 from "runtime/unsafe/wasmi32"
2
8
  import WasmF64 from "runtime/unsafe/wasmf64"
3
9
  import Memory from "runtime/unsafe/memory"
@@ -10,10 +16,43 @@ import {
10
16
  coerceFloat64ToNumber as toNumber
11
17
  } from "runtime/numbers"
12
18
 
19
+ /**
20
+ * @section Conversions: Functions for converting between Numbers and the Float64 type.
21
+ */
22
+
23
+ /**
24
+ * Converts a Number to a Float64.
25
+ *
26
+ * @param number: The value to convert
27
+ * @returns The Number represented as a Float64
28
+ *
29
+ * @since v0.2.0
30
+ */
13
31
  export fromNumber
14
- export toNumber
15
32
 
33
+ /**
34
+ * Converts a Float64 to a Number.
35
+ *
36
+ * @param float: The value to convert
37
+ * @returns The Float64 represented as a Number
38
+ *
39
+ * @since v0.2.0
40
+ */
41
+ export toNumber
16
42
 
43
+ /**
44
+ * @section Operations: Mathematical operations for Float64 values.
45
+ */
46
+
47
+ /**
48
+ * Computes the sum of its operands.
49
+ *
50
+ * @param x: The first operand
51
+ * @param y: The second operand
52
+ * @returns The sum of the two operands
53
+ *
54
+ * @since v0.2.0
55
+ */
17
56
  @disableGC
18
57
  export let rec add = (x: Float64, y: Float64) => {
19
58
  let xv = WasmF64.load(WasmI32.fromGrain(x), 8n)
@@ -26,6 +65,15 @@ export let rec add = (x: Float64, y: Float64) => {
26
65
  ret
27
66
  }
28
67
 
68
+ /**
69
+ * Computes the difference of its operands.
70
+ *
71
+ * @param x: The first operand
72
+ * @param y: The second operand
73
+ * @returns The difference of the two operands
74
+ *
75
+ * @since v0.2.0
76
+ */
29
77
  @disableGC
30
78
  export let rec sub = (x: Float64, y: Float64) => {
31
79
  let xv = WasmF64.load(WasmI32.fromGrain(x), 8n)
@@ -38,6 +86,15 @@ export let rec sub = (x: Float64, y: Float64) => {
38
86
  ret
39
87
  }
40
88
 
89
+ /**
90
+ * Computes the product of its operands.
91
+ *
92
+ * @param x: The first operand
93
+ * @param y: The second operand
94
+ * @returns The product of the two operands
95
+ *
96
+ * @since v0.2.0
97
+ */
41
98
  @disableGC
42
99
  export let rec mul = (x: Float64, y: Float64) => {
43
100
  let xv = WasmF64.load(WasmI32.fromGrain(x), 8n)
@@ -50,6 +107,15 @@ export let rec mul = (x: Float64, y: Float64) => {
50
107
  ret
51
108
  }
52
109
 
110
+ /**
111
+ * Computes the quotient of its operands.
112
+ *
113
+ * @param x: The first operand
114
+ * @param y: The second operand
115
+ * @returns The quotient of the two operands
116
+ *
117
+ * @since v0.2.0
118
+ */
53
119
  @disableGC
54
120
  export let rec div = (x: Float64, y: Float64) => {
55
121
  let xv = WasmF64.load(WasmI32.fromGrain(x), 8n)
@@ -62,8 +128,19 @@ export let rec div = (x: Float64, y: Float64) => {
62
128
  ret
63
129
  }
64
130
 
65
-
66
- // Float64 comparisons
131
+ /**
132
+ * @section Comparisons: Functions for comparing Float64 values.
133
+ */
134
+
135
+ /**
136
+ * Checks if the first value is less than the second value.
137
+ *
138
+ * @param x: The first value
139
+ * @param y: The second value
140
+ * @returns `true` if the first value is less than the second value or `false` otherwise
141
+ *
142
+ * @since v0.2.0
143
+ */
67
144
  @disableGC
68
145
  export let rec lt = (x: Float64, y: Float64) => {
69
146
  let xv = WasmF64.load(WasmI32.fromGrain(x), 8n)
@@ -75,6 +152,15 @@ export let rec lt = (x: Float64, y: Float64) => {
75
152
  ret
76
153
  }
77
154
 
155
+ /**
156
+ * Checks if the first value is greater than the second value.
157
+ *
158
+ * @param x: The first value
159
+ * @param y: The second value
160
+ * @returns `true` if the first value is greater than the second value or `false` otherwise
161
+ *
162
+ * @since v0.2.0
163
+ */
78
164
  @disableGC
79
165
  export let rec gt = (x: Float64, y: Float64) => {
80
166
  let xv = WasmF64.load(WasmI32.fromGrain(x), 8n)
@@ -86,6 +172,15 @@ export let rec gt = (x: Float64, y: Float64) => {
86
172
  ret
87
173
  }
88
174
 
175
+ /**
176
+ * Checks if the first value is less than or equal to the second value.
177
+ *
178
+ * @param x: The first value
179
+ * @param y: The second value
180
+ * @returns `true` if the first value is less than or equal to the second value or `false` otherwise
181
+ *
182
+ * @since v0.2.0
183
+ */
89
184
  @disableGC
90
185
  export let rec lte = (x: Float64, y: Float64) => {
91
186
  let xv = WasmF64.load(WasmI32.fromGrain(x), 8n)
@@ -97,6 +192,15 @@ export let rec lte = (x: Float64, y: Float64) => {
97
192
  ret
98
193
  }
99
194
 
195
+ /**
196
+ * Checks if the first value is greater than or equal to the second value.
197
+ *
198
+ * @param x: The first value
199
+ * @param y: The second value
200
+ * @returns `true` if the first value is greater than or equal to the second value or `false` otherwise
201
+ *
202
+ * @since v0.2.0
203
+ */
100
204
  @disableGC
101
205
  export let rec gte = (x: Float64, y: Float64) => {
102
206
  let xv = WasmF64.load(WasmI32.fromGrain(x), 8n)
@@ -108,7 +212,9 @@ export let rec gte = (x: Float64, y: Float64) => {
108
212
  ret
109
213
  }
110
214
 
111
- // floating-point constants:
215
+ /**
216
+ * @section Constants: Float64 constant values.
217
+ */
112
218
 
113
219
  @disableGC
114
220
  let rec makeInfinity = () => {
@@ -118,6 +224,11 @@ let rec makeInfinity = () => {
118
224
  ret
119
225
  }
120
226
 
227
+ /**
228
+ * Infinity represented as a Float64 value.
229
+ *
230
+ * @since v0.4.0
231
+ */
121
232
  export let infinity = makeInfinity()
122
233
 
123
234
  @disableGC
@@ -128,4 +239,9 @@ let rec makeNaN = () => {
128
239
  ret
129
240
  }
130
241
 
242
+ /**
243
+ * NaN (Not a Number) represented as a Float64 value.
244
+ *
245
+ * @since v0.4.0
246
+ */
131
247
  export let nan = makeNaN()