@grain/stdlib 0.6.6 → 0.7.1
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.
- package/CHANGELOG.md +67 -0
- package/LICENSE +1 -1
- package/README.md +2 -2
- package/array.gr +55 -7
- package/array.md +606 -560
- package/bigint.md +228 -228
- package/buffer.gr +85 -53
- package/buffer.md +442 -319
- package/bytes.gr +112 -35
- package/bytes.md +299 -219
- package/char.gr +201 -99
- package/char.md +447 -120
- package/exception.gr +11 -11
- package/exception.md +29 -4
- package/float32.gr +327 -3
- package/float32.md +698 -111
- package/float64.gr +320 -3
- package/float64.md +698 -111
- package/fs.gr +1082 -0
- package/fs.md +630 -0
- package/hash.gr +142 -88
- package/hash.md +105 -17
- package/int16.md +178 -178
- package/int32.gr +26 -5
- package/int32.md +266 -231
- package/int64.gr +27 -2
- package/int64.md +266 -231
- package/int8.md +178 -178
- package/json.gr +366 -51
- package/json.md +431 -15
- package/list.gr +328 -31
- package/list.md +759 -336
- package/map.gr +20 -12
- package/map.md +266 -260
- package/marshal.gr +41 -40
- package/marshal.md +14 -14
- package/number.gr +278 -35
- package/number.md +688 -269
- package/option.md +162 -162
- package/package.json +5 -3
- package/path.gr +48 -0
- package/path.md +180 -89
- package/pervasives.gr +2 -2
- package/pervasives.md +275 -275
- package/priorityqueue.gr +7 -7
- package/priorityqueue.md +131 -131
- package/queue.gr +183 -29
- package/queue.md +404 -148
- package/random.md +43 -43
- package/range.gr +4 -4
- package/range.md +42 -42
- package/rational.md +123 -123
- package/regex.gr +52 -51
- package/regex.md +102 -102
- package/result.md +118 -118
- package/runtime/atof/common.md +39 -39
- package/runtime/atof/decimal.gr +6 -6
- package/runtime/atof/decimal.md +14 -14
- package/runtime/atof/lemire.gr +5 -5
- package/runtime/atof/lemire.md +1 -1
- package/runtime/atof/parse.gr +16 -16
- package/runtime/atof/parse.md +2 -2
- package/runtime/atof/slow.md +1 -1
- package/runtime/atof/table.md +2 -2
- package/runtime/atoi/parse.gr +3 -3
- package/runtime/atoi/parse.md +1 -1
- package/runtime/bigint.gr +15 -47
- package/runtime/bigint.md +54 -60
- package/runtime/compare.gr +2 -2
- package/runtime/compare.md +8 -8
- package/runtime/dataStructures.md +211 -211
- package/runtime/debugPrint.gr +4 -1
- package/runtime/debugPrint.md +9 -9
- package/runtime/equal.gr +99 -77
- package/runtime/equal.md +8 -8
- package/runtime/exception.gr +62 -82
- package/runtime/exception.md +62 -11
- package/runtime/gc.gr +39 -45
- package/runtime/gc.md +4 -4
- package/runtime/malloc.gr +7 -7
- package/runtime/malloc.md +13 -13
- package/runtime/math/kernel/cos.gr +70 -0
- package/runtime/math/kernel/cos.md +14 -0
- package/runtime/math/kernel/sin.gr +65 -0
- package/runtime/math/kernel/sin.md +14 -0
- package/runtime/math/kernel/tan.gr +136 -0
- package/runtime/math/kernel/tan.md +14 -0
- package/runtime/math/rempio2.gr +244 -0
- package/runtime/math/rempio2.md +14 -0
- package/runtime/math/trig.gr +130 -0
- package/runtime/math/trig.md +28 -0
- package/runtime/math/umuldi.gr +26 -0
- package/runtime/math/umuldi.md +14 -0
- package/runtime/numberUtils.gr +29 -29
- package/runtime/numberUtils.md +12 -12
- package/runtime/numbers.gr +373 -381
- package/runtime/numbers.md +348 -342
- package/runtime/string.gr +37 -105
- package/runtime/string.md +20 -26
- package/runtime/unsafe/constants.md +24 -24
- package/runtime/unsafe/conv.md +19 -19
- package/runtime/unsafe/memory.gr +24 -20
- package/runtime/unsafe/memory.md +27 -7
- package/runtime/unsafe/offsets.gr +36 -0
- package/runtime/unsafe/offsets.md +88 -0
- package/runtime/unsafe/panic.gr +28 -0
- package/runtime/unsafe/panic.md +14 -0
- package/runtime/unsafe/tags.md +32 -32
- package/runtime/unsafe/wasmf32.md +28 -28
- package/runtime/unsafe/wasmf64.md +28 -28
- package/runtime/unsafe/wasmi32.md +47 -47
- package/runtime/unsafe/wasmi64.md +50 -50
- package/runtime/utf8.gr +189 -0
- package/runtime/utf8.md +117 -0
- package/runtime/wasi.gr +4 -2
- package/runtime/wasi.md +147 -147
- package/set.gr +18 -11
- package/set.md +253 -247
- package/stack.gr +171 -2
- package/stack.md +371 -89
- package/string.gr +352 -557
- package/string.md +298 -255
- package/uint16.md +170 -170
- package/uint32.gr +25 -4
- package/uint32.md +249 -214
- package/uint64.gr +25 -5
- package/uint64.md +249 -214
- package/uint8.md +170 -170
- package/uri.gr +57 -53
- package/uri.md +88 -89
- package/wasi/file.gr +67 -59
- package/wasi/file.md +308 -308
- package/wasi/process.md +26 -26
- package/wasi/random.md +12 -12
- package/wasi/time.md +16 -16
- package/runtime/utils/printing.gr +0 -60
- package/runtime/utils/printing.md +0 -26
package/wasi/process.md
CHANGED
|
@@ -218,82 +218,82 @@ Functions and constants included in the Process module.
|
|
|
218
218
|
### Process.**argv**
|
|
219
219
|
|
|
220
220
|
```grain
|
|
221
|
-
argv
|
|
221
|
+
argv: () => Result<Array<String>, Exception>
|
|
222
222
|
```
|
|
223
223
|
|
|
224
224
|
Access command line arguments.
|
|
225
225
|
|
|
226
226
|
Returns:
|
|
227
227
|
|
|
228
|
-
|type|description|
|
|
229
|
-
|
|
230
|
-
|
|
228
|
+
| type | description |
|
|
229
|
+
| ---------------------------------- | ------------------------------------------------------------------------------------------------------------------------ |
|
|
230
|
+
| `Result<Array<String>, Exception>` | `Ok(args)` of an array containing positional string arguments to the process if successful or `Err(exception)` otherwise |
|
|
231
231
|
|
|
232
232
|
### Process.**env**
|
|
233
233
|
|
|
234
234
|
```grain
|
|
235
|
-
env
|
|
235
|
+
env: () => Result<Array<String>, Exception>
|
|
236
236
|
```
|
|
237
237
|
|
|
238
238
|
Access environment variables.
|
|
239
239
|
|
|
240
240
|
Returns:
|
|
241
241
|
|
|
242
|
-
|type|description|
|
|
243
|
-
|
|
244
|
-
|
|
242
|
+
| type | description |
|
|
243
|
+
| ---------------------------------- | --------------------------------------------------------------------------------------------------------------------------- |
|
|
244
|
+
| `Result<Array<String>, Exception>` | `Ok(vars)` of an array containing environment variables supplied to the process if successful or `Err(exception)` otherwise |
|
|
245
245
|
|
|
246
246
|
### Process.**exit**
|
|
247
247
|
|
|
248
248
|
```grain
|
|
249
|
-
exit
|
|
249
|
+
exit: (code: Number) => Result<Void, Exception>
|
|
250
250
|
```
|
|
251
251
|
|
|
252
252
|
Terminate the process normally.
|
|
253
253
|
|
|
254
254
|
Parameters:
|
|
255
255
|
|
|
256
|
-
|param|type|description|
|
|
257
|
-
|
|
258
|
-
|
|
256
|
+
| param | type | description |
|
|
257
|
+
| ------ | -------- | -------------------------------------------------------------------------------------------------------------------------- |
|
|
258
|
+
| `code` | `Number` | The value to exit with. An exit code of 0 is considered normal, with other values having meaning depending on the platform |
|
|
259
259
|
|
|
260
260
|
Returns:
|
|
261
261
|
|
|
262
|
-
|type|description|
|
|
263
|
-
|
|
264
|
-
|
|
262
|
+
| type | description |
|
|
263
|
+
| ------------------------- | ---------------------------------------------------------------------------------------------------------- |
|
|
264
|
+
| `Result<Void, Exception>` | `Err(exception)` if unsuccessful. Will not actually return a value if successful, as the process has ended |
|
|
265
265
|
|
|
266
266
|
### Process.**sigRaise**
|
|
267
267
|
|
|
268
268
|
```grain
|
|
269
|
-
sigRaise
|
|
269
|
+
sigRaise: (signal: Signal) => Result<Void, Exception>
|
|
270
270
|
```
|
|
271
271
|
|
|
272
272
|
Send a signal to the process of the calling thread.
|
|
273
273
|
|
|
274
274
|
Parameters:
|
|
275
275
|
|
|
276
|
-
|param|type|description|
|
|
277
|
-
|
|
278
|
-
|
|
276
|
+
| param | type | description |
|
|
277
|
+
| -------- | -------- | ------------------ |
|
|
278
|
+
| `signal` | `Signal` | The signal to send |
|
|
279
279
|
|
|
280
280
|
Returns:
|
|
281
281
|
|
|
282
|
-
|type|description|
|
|
283
|
-
|
|
284
|
-
|
|
282
|
+
| type | description |
|
|
283
|
+
| ------------------------- | ------------------------------------------------------ |
|
|
284
|
+
| `Result<Void, Exception>` | `Ok(void)` if successful or `Err(exception)` otherwise |
|
|
285
285
|
|
|
286
286
|
### Process.**schedYield**
|
|
287
287
|
|
|
288
288
|
```grain
|
|
289
|
-
schedYield
|
|
289
|
+
schedYield: () => Result<Void, Exception>
|
|
290
290
|
```
|
|
291
291
|
|
|
292
292
|
Yield execution to the calling thread.
|
|
293
293
|
|
|
294
294
|
Returns:
|
|
295
295
|
|
|
296
|
-
|type|description|
|
|
297
|
-
|
|
298
|
-
|
|
296
|
+
| type | description |
|
|
297
|
+
| ------------------------- | ------------------------------------------------------ |
|
|
298
|
+
| `Result<Void, Exception>` | `Ok(void)` if successful or `Err(exception)` otherwise |
|
|
299
299
|
|
package/wasi/random.md
CHANGED
|
@@ -27,16 +27,16 @@ Functions and constants included in the Random module.
|
|
|
27
27
|
</details>
|
|
28
28
|
|
|
29
29
|
```grain
|
|
30
|
-
randomUint32
|
|
30
|
+
randomUint32: () => Result<Uint32, Exception>
|
|
31
31
|
```
|
|
32
32
|
|
|
33
33
|
Produce a random 32-bit integer. This function can be slow, so it's best to seed a generator if lots of random data is needed.
|
|
34
34
|
|
|
35
35
|
Returns:
|
|
36
36
|
|
|
37
|
-
|type|description|
|
|
38
|
-
|
|
39
|
-
|
|
37
|
+
| type | description |
|
|
38
|
+
| --------------------------- | ------------------------------------------------------------------------ |
|
|
39
|
+
| `Result<Uint32, Exception>` | `Ok(num)` of a random Uint32 if successful or `Err(exception)` otherwise |
|
|
40
40
|
|
|
41
41
|
### Random.**randomUint64**
|
|
42
42
|
|
|
@@ -53,28 +53,28 @@ Returns:
|
|
|
53
53
|
</details>
|
|
54
54
|
|
|
55
55
|
```grain
|
|
56
|
-
randomUint64
|
|
56
|
+
randomUint64: () => Result<Uint64, Exception>
|
|
57
57
|
```
|
|
58
58
|
|
|
59
59
|
Produce a random 64-bit integer. This function can be slow, so it's best to seed a generator if lots of random data is needed.
|
|
60
60
|
|
|
61
61
|
Returns:
|
|
62
62
|
|
|
63
|
-
|type|description|
|
|
64
|
-
|
|
65
|
-
|
|
63
|
+
| type | description |
|
|
64
|
+
| --------------------------- | ------------------------------------------------------------------------ |
|
|
65
|
+
| `Result<Uint64, Exception>` | `Ok(num)` of a random Uint64 if successful or `Err(exception)` otherwise |
|
|
66
66
|
|
|
67
67
|
### Random.**random**
|
|
68
68
|
|
|
69
69
|
```grain
|
|
70
|
-
random
|
|
70
|
+
random: () => Result<Number, Exception>
|
|
71
71
|
```
|
|
72
72
|
|
|
73
73
|
Produce a random number. This function can be slow, so it's best to seed a generator if lots of random data is needed.
|
|
74
74
|
|
|
75
75
|
Returns:
|
|
76
76
|
|
|
77
|
-
|type|description|
|
|
78
|
-
|
|
79
|
-
|
|
77
|
+
| type | description |
|
|
78
|
+
| --------------------------- | ------------------------------------------------------------------------ |
|
|
79
|
+
| `Result<Number, Exception>` | `Ok(num)` of a random number if successful or `Err(exception)` otherwise |
|
|
80
80
|
|
package/wasi/time.md
CHANGED
|
@@ -15,7 +15,7 @@ Functions and constants included in the Time module.
|
|
|
15
15
|
### Time.**realTime**
|
|
16
16
|
|
|
17
17
|
```grain
|
|
18
|
-
realTime
|
|
18
|
+
realTime: () => Result<Int64, Exception>
|
|
19
19
|
```
|
|
20
20
|
|
|
21
21
|
Get the current time, in nanoseconds.
|
|
@@ -23,14 +23,14 @@ Time value 0 corresponds with 1970-01-01T00:00:00Z.
|
|
|
23
23
|
|
|
24
24
|
Returns:
|
|
25
25
|
|
|
26
|
-
|type|description|
|
|
27
|
-
|
|
28
|
-
|
|
26
|
+
| type | description |
|
|
27
|
+
| -------------------------- | -------------------------------------------------------------------------- |
|
|
28
|
+
| `Result<Int64, Exception>` | `Ok(time)` of the current time if successful or `Err(exception)` otherwise |
|
|
29
29
|
|
|
30
30
|
### Time.**monotonicTime**
|
|
31
31
|
|
|
32
32
|
```grain
|
|
33
|
-
monotonicTime
|
|
33
|
+
monotonicTime: () => Result<Int64, Exception>
|
|
34
34
|
```
|
|
35
35
|
|
|
36
36
|
Get the time of the system's high-resolution clock, in nanoseconds.
|
|
@@ -40,35 +40,35 @@ Useful for calculation of precise time intervals.
|
|
|
40
40
|
|
|
41
41
|
Returns:
|
|
42
42
|
|
|
43
|
-
|type|description|
|
|
44
|
-
|
|
45
|
-
|
|
43
|
+
| type | description |
|
|
44
|
+
| -------------------------- | -------------------------------------------------------------------------- |
|
|
45
|
+
| `Result<Int64, Exception>` | `Ok(time)` of the current time if successful or `Err(exception)` otherwise |
|
|
46
46
|
|
|
47
47
|
### Time.**processCpuTime**
|
|
48
48
|
|
|
49
49
|
```grain
|
|
50
|
-
processCpuTime
|
|
50
|
+
processCpuTime: () => Result<Int64, Exception>
|
|
51
51
|
```
|
|
52
52
|
|
|
53
53
|
Get the number of nanoseconds elapsed since the process began.
|
|
54
54
|
|
|
55
55
|
Returns:
|
|
56
56
|
|
|
57
|
-
|type|description|
|
|
58
|
-
|
|
59
|
-
|
|
57
|
+
| type | description |
|
|
58
|
+
| -------------------------- | ------------------------------------------------------------------------------------ |
|
|
59
|
+
| `Result<Int64, Exception>` | `Ok(elapsed)` of the elapsed nanoseconds if successful or `Err(exception)` otherwise |
|
|
60
60
|
|
|
61
61
|
### Time.**threadCpuTime**
|
|
62
62
|
|
|
63
63
|
```grain
|
|
64
|
-
threadCpuTime
|
|
64
|
+
threadCpuTime: () => Result<Int64, Exception>
|
|
65
65
|
```
|
|
66
66
|
|
|
67
67
|
Get the number of nanoseconds elapsed since the thread began.
|
|
68
68
|
|
|
69
69
|
Returns:
|
|
70
70
|
|
|
71
|
-
|type|description|
|
|
72
|
-
|
|
73
|
-
|
|
71
|
+
| type | description |
|
|
72
|
+
| -------------------------- | ------------------------------------------------------------------------------------ |
|
|
73
|
+
| `Result<Int64, Exception>` | `Ok(elapsed)` of the elapsed nanoseconds if successful or `Err(exception)` otherwise |
|
|
74
74
|
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
@noPervasives
|
|
2
|
-
module Printing
|
|
3
|
-
|
|
4
|
-
// Printing utilities for runtime code (primarily for debugging)
|
|
5
|
-
from "runtime/unsafe/wasmi32" include WasmI32
|
|
6
|
-
from "runtime/unsafe/memory" include Memory
|
|
7
|
-
from "runtime/numberUtils" include NumberUtils
|
|
8
|
-
|
|
9
|
-
foreign wasm fd_write:
|
|
10
|
-
(WasmI32, WasmI32, WasmI32, WasmI32) => WasmI32 from "wasi_snapshot_preview1"
|
|
11
|
-
|
|
12
|
-
@unsafe
|
|
13
|
-
provide let numberToString = (n: WasmI64) => {
|
|
14
|
-
NumberUtils.itoa64(n, 10n)
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
@unsafe
|
|
18
|
-
provide let printNumber = (n: WasmI64) => {
|
|
19
|
-
// like print(), but `s` should be a Grain string
|
|
20
|
-
use WasmI32.{ (+) }
|
|
21
|
-
let s = numberToString(n)
|
|
22
|
-
let ptr = WasmI32.fromGrain(s)
|
|
23
|
-
// iov: [<ptr to string> <nbytes of string> <ptr to newline> <nbytes of newline>] (32 bytes)
|
|
24
|
-
// buf: <iov> <written> <newline char>
|
|
25
|
-
// fd_write(STDOUT (1), iov, len(iov), written)
|
|
26
|
-
let buf = Memory.malloc(37n)
|
|
27
|
-
let iov = buf
|
|
28
|
-
let written = buf + 32n
|
|
29
|
-
let lf = buf + 36n
|
|
30
|
-
WasmI32.store(iov, ptr + 8n, 0n)
|
|
31
|
-
WasmI32.store(iov, WasmI32.load(ptr, 4n), 4n)
|
|
32
|
-
WasmI32.store8(lf, 10n, 0n)
|
|
33
|
-
WasmI32.store(iov, lf, 8n)
|
|
34
|
-
WasmI32.store(iov, 1n, 12n)
|
|
35
|
-
fd_write(1n, iov, 2n, written)
|
|
36
|
-
Memory.free(buf)
|
|
37
|
-
void
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
@unsafe
|
|
41
|
-
provide let printString = (s: String) => {
|
|
42
|
-
// like print(), but `s` should be a Grain string
|
|
43
|
-
use WasmI32.{ (+) }
|
|
44
|
-
let ptr = WasmI32.fromGrain(s)
|
|
45
|
-
// iov: [<ptr to string> <nbytes of string> <ptr to newline> <nbytes of newline>] (32 bytes)
|
|
46
|
-
// buf: <iov> <written> <newline char>
|
|
47
|
-
// fd_write(STDOUT (1), iov, len(iov), written)
|
|
48
|
-
let buf = Memory.malloc(37n)
|
|
49
|
-
let iov = buf
|
|
50
|
-
let written = buf + 32n
|
|
51
|
-
let lf = buf + 36n
|
|
52
|
-
WasmI32.store(iov, ptr + 8n, 0n)
|
|
53
|
-
WasmI32.store(iov, WasmI32.load(ptr, 4n), 4n)
|
|
54
|
-
WasmI32.store8(lf, 10n, 0n)
|
|
55
|
-
WasmI32.store(iov, lf, 8n)
|
|
56
|
-
WasmI32.store(iov, 1n, 12n)
|
|
57
|
-
fd_write(1n, iov, 2n, written)
|
|
58
|
-
Memory.free(buf)
|
|
59
|
-
void
|
|
60
|
-
}
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
title: Printing
|
|
3
|
-
---
|
|
4
|
-
|
|
5
|
-
## Values
|
|
6
|
-
|
|
7
|
-
Functions and constants included in the Printing module.
|
|
8
|
-
|
|
9
|
-
### Printing.**numberToString**
|
|
10
|
-
|
|
11
|
-
```grain
|
|
12
|
-
numberToString : (n: WasmI64) => String
|
|
13
|
-
```
|
|
14
|
-
|
|
15
|
-
### Printing.**printNumber**
|
|
16
|
-
|
|
17
|
-
```grain
|
|
18
|
-
printNumber : (n: WasmI64) => Void
|
|
19
|
-
```
|
|
20
|
-
|
|
21
|
-
### Printing.**printString**
|
|
22
|
-
|
|
23
|
-
```grain
|
|
24
|
-
printString : (s: String) => Void
|
|
25
|
-
```
|
|
26
|
-
|