@grain/stdlib 0.4.4 → 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.
- package/CHANGELOG.md +87 -0
- package/LICENSE +1 -1
- package/array.gr +92 -73
- package/array.md +18 -18
- package/bigint.gr +497 -0
- package/bigint.md +811 -0
- package/buffer.gr +56 -217
- package/buffer.md +24 -17
- package/bytes.gr +103 -205
- package/bytes.md +19 -0
- package/char.gr +152 -166
- package/char.md +200 -0
- package/exception.md +6 -0
- package/float32.gr +159 -82
- package/float32.md +315 -0
- package/float64.gr +163 -82
- package/float64.md +315 -0
- package/hash.gr +53 -49
- package/int32.gr +479 -230
- package/int32.md +937 -0
- package/int64.gr +479 -230
- package/int64.md +937 -0
- package/list.gr +530 -116
- package/list.md +1141 -0
- package/map.gr +302 -121
- package/map.md +525 -0
- package/number.gr +51 -57
- package/number.md +37 -3
- package/option.gr +25 -25
- package/option.md +1 -1
- package/package.json +3 -3
- package/pervasives.gr +504 -52
- package/pervasives.md +1116 -0
- package/queue.gr +8 -1
- package/queue.md +10 -0
- package/random.gr +196 -0
- package/random.md +179 -0
- package/range.gr +26 -26
- package/regex.gr +1833 -842
- package/regex.md +11 -11
- package/result.md +1 -1
- package/runtime/bigint.gr +2045 -0
- package/runtime/bigint.md +326 -0
- package/runtime/dataStructures.gr +99 -279
- package/runtime/dataStructures.md +391 -0
- package/runtime/debug.gr +0 -1
- package/runtime/debug.md +6 -0
- package/runtime/equal.gr +40 -37
- package/runtime/equal.md +6 -0
- package/runtime/exception.gr +28 -15
- package/runtime/exception.md +30 -0
- package/runtime/gc.gr +50 -20
- package/runtime/gc.md +36 -0
- package/runtime/malloc.gr +32 -22
- package/runtime/malloc.md +55 -0
- package/runtime/numberUtils.gr +297 -142
- package/runtime/numberUtils.md +54 -0
- package/runtime/numbers.gr +1204 -453
- package/runtime/numbers.md +300 -0
- package/runtime/string.gr +193 -228
- package/runtime/string.md +24 -0
- package/runtime/stringUtils.gr +62 -38
- package/runtime/stringUtils.md +6 -0
- package/runtime/unsafe/constants.gr +17 -0
- package/runtime/unsafe/constants.md +72 -0
- package/runtime/unsafe/conv.gr +10 -10
- package/runtime/unsafe/conv.md +71 -0
- package/runtime/unsafe/errors.md +204 -0
- package/runtime/unsafe/memory.gr +14 -3
- package/runtime/unsafe/memory.md +54 -0
- package/runtime/unsafe/printWasm.gr +4 -4
- package/runtime/unsafe/printWasm.md +24 -0
- package/runtime/unsafe/tags.gr +11 -10
- package/runtime/unsafe/tags.md +120 -0
- package/runtime/unsafe/wasmf32.gr +9 -2
- package/runtime/unsafe/wasmf32.md +168 -0
- package/runtime/unsafe/wasmf64.gr +9 -2
- package/runtime/unsafe/wasmf64.md +168 -0
- package/runtime/unsafe/wasmi32.gr +65 -47
- package/runtime/unsafe/wasmi32.md +282 -0
- package/runtime/unsafe/wasmi64.gr +78 -50
- package/runtime/unsafe/wasmi64.md +300 -0
- package/runtime/utils/printing.gr +62 -0
- package/runtime/utils/printing.md +18 -0
- package/runtime/wasi.gr +200 -46
- package/runtime/wasi.md +839 -0
- package/set.gr +125 -121
- package/set.md +24 -21
- package/stack.gr +29 -29
- package/stack.md +4 -6
- package/string.gr +434 -415
- package/string.md +3 -3
- package/sys/file.gr +477 -482
- package/sys/process.gr +33 -47
- package/sys/random.gr +48 -20
- package/sys/random.md +38 -0
- package/sys/time.gr +12 -28
|
@@ -0,0 +1,300 @@
|
|
|
1
|
+
### Wasmi64.**load**
|
|
2
|
+
|
|
3
|
+
```grain
|
|
4
|
+
load : (WasmI32, WasmI32) -> WasmI64
|
|
5
|
+
```
|
|
6
|
+
|
|
7
|
+
### Wasmi64.**load8S**
|
|
8
|
+
|
|
9
|
+
```grain
|
|
10
|
+
load8S : (WasmI32, WasmI32) -> WasmI64
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
### Wasmi64.**load8U**
|
|
14
|
+
|
|
15
|
+
```grain
|
|
16
|
+
load8U : (WasmI32, WasmI32) -> WasmI64
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
### Wasmi64.**load16S**
|
|
20
|
+
|
|
21
|
+
```grain
|
|
22
|
+
load16S : (WasmI32, WasmI32) -> WasmI64
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
### Wasmi64.**load16U**
|
|
26
|
+
|
|
27
|
+
```grain
|
|
28
|
+
load16U : (WasmI32, WasmI32) -> WasmI64
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
### Wasmi64.**load32S**
|
|
32
|
+
|
|
33
|
+
```grain
|
|
34
|
+
load32S : (WasmI32, WasmI32) -> WasmI64
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
### Wasmi64.**load32U**
|
|
38
|
+
|
|
39
|
+
```grain
|
|
40
|
+
load32U : (WasmI32, WasmI32) -> WasmI64
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
### Wasmi64.**store**
|
|
44
|
+
|
|
45
|
+
```grain
|
|
46
|
+
store : (WasmI32, WasmI64, WasmI32) -> Void
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
### Wasmi64.**store8**
|
|
50
|
+
|
|
51
|
+
```grain
|
|
52
|
+
store8 : (WasmI32, WasmI64, WasmI32) -> Void
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
### Wasmi64.**store16**
|
|
56
|
+
|
|
57
|
+
```grain
|
|
58
|
+
store16 : (WasmI32, WasmI64, WasmI32) -> Void
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
### Wasmi64.**store32**
|
|
62
|
+
|
|
63
|
+
```grain
|
|
64
|
+
store32 : (WasmI32, WasmI64, WasmI32) -> Void
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
### Wasmi64.**clz**
|
|
68
|
+
|
|
69
|
+
```grain
|
|
70
|
+
clz : WasmI64 -> WasmI64
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
### Wasmi64.**ctz**
|
|
74
|
+
|
|
75
|
+
```grain
|
|
76
|
+
ctz : WasmI64 -> WasmI64
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
### Wasmi64.**popcnt**
|
|
80
|
+
|
|
81
|
+
```grain
|
|
82
|
+
popcnt : WasmI64 -> WasmI64
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
### Wasmi64.**eqz**
|
|
86
|
+
|
|
87
|
+
```grain
|
|
88
|
+
eqz : WasmI64 -> Bool
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
### Wasmi64.**add**
|
|
92
|
+
|
|
93
|
+
```grain
|
|
94
|
+
add : (WasmI64, WasmI64) -> WasmI64
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
### Wasmi64.**sub**
|
|
98
|
+
|
|
99
|
+
```grain
|
|
100
|
+
sub : (WasmI64, WasmI64) -> WasmI64
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
### Wasmi64.**mul**
|
|
104
|
+
|
|
105
|
+
```grain
|
|
106
|
+
mul : (WasmI64, WasmI64) -> WasmI64
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
### Wasmi64.**divS**
|
|
110
|
+
|
|
111
|
+
```grain
|
|
112
|
+
divS : (WasmI64, WasmI64) -> WasmI64
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
### Wasmi64.**divU**
|
|
116
|
+
|
|
117
|
+
```grain
|
|
118
|
+
divU : (WasmI64, WasmI64) -> WasmI64
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
### Wasmi64.**remS**
|
|
122
|
+
|
|
123
|
+
```grain
|
|
124
|
+
remS : (WasmI64, WasmI64) -> WasmI64
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
### Wasmi64.**remU**
|
|
128
|
+
|
|
129
|
+
```grain
|
|
130
|
+
remU : (WasmI64, WasmI64) -> WasmI64
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
### Wasmi64.**and**
|
|
134
|
+
|
|
135
|
+
```grain
|
|
136
|
+
and : (WasmI64, WasmI64) -> WasmI64
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
### Wasmi64.**or**
|
|
140
|
+
|
|
141
|
+
```grain
|
|
142
|
+
or : (WasmI64, WasmI64) -> WasmI64
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
### Wasmi64.**xor**
|
|
146
|
+
|
|
147
|
+
```grain
|
|
148
|
+
xor : (WasmI64, WasmI64) -> WasmI64
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
### Wasmi64.**shl**
|
|
152
|
+
|
|
153
|
+
```grain
|
|
154
|
+
shl : (WasmI64, WasmI64) -> WasmI64
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
### Wasmi64.**shrU**
|
|
158
|
+
|
|
159
|
+
```grain
|
|
160
|
+
shrU : (WasmI64, WasmI64) -> WasmI64
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
### Wasmi64.**shrS**
|
|
164
|
+
|
|
165
|
+
```grain
|
|
166
|
+
shrS : (WasmI64, WasmI64) -> WasmI64
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
### Wasmi64.**rotl**
|
|
170
|
+
|
|
171
|
+
```grain
|
|
172
|
+
rotl : (WasmI64, WasmI64) -> WasmI64
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
### Wasmi64.**rotr**
|
|
176
|
+
|
|
177
|
+
```grain
|
|
178
|
+
rotr : (WasmI64, WasmI64) -> WasmI64
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
### Wasmi64.**eq**
|
|
182
|
+
|
|
183
|
+
```grain
|
|
184
|
+
eq : (WasmI64, WasmI64) -> Bool
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
### Wasmi64.**ne**
|
|
188
|
+
|
|
189
|
+
```grain
|
|
190
|
+
ne : (WasmI64, WasmI64) -> Bool
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
### Wasmi64.**ltS**
|
|
194
|
+
|
|
195
|
+
```grain
|
|
196
|
+
ltS : (WasmI64, WasmI64) -> Bool
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
### Wasmi64.**ltU**
|
|
200
|
+
|
|
201
|
+
```grain
|
|
202
|
+
ltU : (WasmI64, WasmI64) -> Bool
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
### Wasmi64.**leS**
|
|
206
|
+
|
|
207
|
+
```grain
|
|
208
|
+
leS : (WasmI64, WasmI64) -> Bool
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
### Wasmi64.**leU**
|
|
212
|
+
|
|
213
|
+
```grain
|
|
214
|
+
leU : (WasmI64, WasmI64) -> Bool
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
### Wasmi64.**gtS**
|
|
218
|
+
|
|
219
|
+
```grain
|
|
220
|
+
gtS : (WasmI64, WasmI64) -> Bool
|
|
221
|
+
```
|
|
222
|
+
|
|
223
|
+
### Wasmi64.**gtU**
|
|
224
|
+
|
|
225
|
+
```grain
|
|
226
|
+
gtU : (WasmI64, WasmI64) -> Bool
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
### Wasmi64.**geS**
|
|
230
|
+
|
|
231
|
+
```grain
|
|
232
|
+
geS : (WasmI64, WasmI64) -> Bool
|
|
233
|
+
```
|
|
234
|
+
|
|
235
|
+
### Wasmi64.**geU**
|
|
236
|
+
|
|
237
|
+
```grain
|
|
238
|
+
geU : (WasmI64, WasmI64) -> Bool
|
|
239
|
+
```
|
|
240
|
+
|
|
241
|
+
### Wasmi64.**extendI32S**
|
|
242
|
+
|
|
243
|
+
```grain
|
|
244
|
+
extendI32S : WasmI32 -> WasmI64
|
|
245
|
+
```
|
|
246
|
+
|
|
247
|
+
### Wasmi64.**extendI32U**
|
|
248
|
+
|
|
249
|
+
```grain
|
|
250
|
+
extendI32U : WasmI32 -> WasmI64
|
|
251
|
+
```
|
|
252
|
+
|
|
253
|
+
### Wasmi64.**truncF32S**
|
|
254
|
+
|
|
255
|
+
```grain
|
|
256
|
+
truncF32S : WasmF32 -> WasmI64
|
|
257
|
+
```
|
|
258
|
+
|
|
259
|
+
### Wasmi64.**truncF32U**
|
|
260
|
+
|
|
261
|
+
```grain
|
|
262
|
+
truncF32U : WasmF32 -> WasmI64
|
|
263
|
+
```
|
|
264
|
+
|
|
265
|
+
### Wasmi64.**truncF64S**
|
|
266
|
+
|
|
267
|
+
```grain
|
|
268
|
+
truncF64S : WasmF64 -> WasmI64
|
|
269
|
+
```
|
|
270
|
+
|
|
271
|
+
### Wasmi64.**truncF64U**
|
|
272
|
+
|
|
273
|
+
```grain
|
|
274
|
+
truncF64U : WasmF64 -> WasmI64
|
|
275
|
+
```
|
|
276
|
+
|
|
277
|
+
### Wasmi64.**reinterpretF64**
|
|
278
|
+
|
|
279
|
+
```grain
|
|
280
|
+
reinterpretF64 : WasmF64 -> WasmI64
|
|
281
|
+
```
|
|
282
|
+
|
|
283
|
+
### Wasmi64.**extendS8**
|
|
284
|
+
|
|
285
|
+
```grain
|
|
286
|
+
extendS8 : WasmI64 -> WasmI64
|
|
287
|
+
```
|
|
288
|
+
|
|
289
|
+
### Wasmi64.**extendS16**
|
|
290
|
+
|
|
291
|
+
```grain
|
|
292
|
+
extendS16 : WasmI64 -> WasmI64
|
|
293
|
+
```
|
|
294
|
+
|
|
295
|
+
### Wasmi64.**extendS32**
|
|
296
|
+
|
|
297
|
+
```grain
|
|
298
|
+
extendS32 : WasmI64 -> WasmI64
|
|
299
|
+
```
|
|
300
|
+
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/* grainc-flags --no-pervasives */
|
|
2
|
+
// Printing utilities for runtime code (primarily for debugging)
|
|
3
|
+
import WasmI32 from "runtime/unsafe/wasmi32"
|
|
4
|
+
import Memory from "runtime/unsafe/memory"
|
|
5
|
+
import NumberUtils from "runtime/numberUtils"
|
|
6
|
+
|
|
7
|
+
import foreign wasm fd_write: (
|
|
8
|
+
WasmI32,
|
|
9
|
+
WasmI32,
|
|
10
|
+
WasmI32,
|
|
11
|
+
WasmI32,
|
|
12
|
+
) -> WasmI32 from "wasi_snapshot_preview1"
|
|
13
|
+
|
|
14
|
+
@unsafe
|
|
15
|
+
export let rec numberToString = (n: WasmI64) => {
|
|
16
|
+
NumberUtils.itoa64(n, 10n)
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
@unsafe
|
|
20
|
+
export let rec printNumber = (n: WasmI64) => {
|
|
21
|
+
// like print(), but `s` should be a Grain string
|
|
22
|
+
let (+) = WasmI32.add
|
|
23
|
+
let s = numberToString(n)
|
|
24
|
+
let ptr = WasmI32.fromGrain(s)
|
|
25
|
+
// iov: [<ptr to string> <nbytes of string> <ptr to newline> <nbytes of newline>] (32 bytes)
|
|
26
|
+
// buf: <iov> <written> <newline char>
|
|
27
|
+
// fd_write(STDOUT (1), iov, len(iov), written)
|
|
28
|
+
let buf = Memory.malloc(37n)
|
|
29
|
+
let iov = buf
|
|
30
|
+
let written = buf + 32n
|
|
31
|
+
let lf = buf + 36n
|
|
32
|
+
WasmI32.store(iov, ptr + 8n, 0n)
|
|
33
|
+
WasmI32.store(iov, WasmI32.load(ptr, 4n), 4n)
|
|
34
|
+
WasmI32.store8(lf, 10n, 0n)
|
|
35
|
+
WasmI32.store(iov, lf, 8n)
|
|
36
|
+
WasmI32.store(iov, 1n, 12n)
|
|
37
|
+
fd_write(1n, iov, 2n, written)
|
|
38
|
+
Memory.free(buf)
|
|
39
|
+
void
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
@unsafe
|
|
43
|
+
export let rec printString = (s: String) => {
|
|
44
|
+
// like print(), but `s` should be a Grain string
|
|
45
|
+
let (+) = WasmI32.add
|
|
46
|
+
let ptr = WasmI32.fromGrain(s)
|
|
47
|
+
// iov: [<ptr to string> <nbytes of string> <ptr to newline> <nbytes of newline>] (32 bytes)
|
|
48
|
+
// buf: <iov> <written> <newline char>
|
|
49
|
+
// fd_write(STDOUT (1), iov, len(iov), written)
|
|
50
|
+
let buf = Memory.malloc(37n)
|
|
51
|
+
let iov = buf
|
|
52
|
+
let written = buf + 32n
|
|
53
|
+
let lf = buf + 36n
|
|
54
|
+
WasmI32.store(iov, ptr + 8n, 0n)
|
|
55
|
+
WasmI32.store(iov, WasmI32.load(ptr, 4n), 4n)
|
|
56
|
+
WasmI32.store8(lf, 10n, 0n)
|
|
57
|
+
WasmI32.store(iov, lf, 8n)
|
|
58
|
+
WasmI32.store(iov, 1n, 12n)
|
|
59
|
+
fd_write(1n, iov, 2n, written)
|
|
60
|
+
Memory.free(buf)
|
|
61
|
+
void
|
|
62
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
### Printing.**numberToString**
|
|
2
|
+
|
|
3
|
+
```grain
|
|
4
|
+
numberToString : WasmI64 -> String
|
|
5
|
+
```
|
|
6
|
+
|
|
7
|
+
### Printing.**printNumber**
|
|
8
|
+
|
|
9
|
+
```grain
|
|
10
|
+
printNumber : WasmI64 -> Void
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
### Printing.**printString**
|
|
14
|
+
|
|
15
|
+
```grain
|
|
16
|
+
printString : String -> Void
|
|
17
|
+
```
|
|
18
|
+
|
package/runtime/wasi.gr
CHANGED
|
@@ -6,26 +6,66 @@ import WasmI32 from "runtime/unsafe/wasmi32"
|
|
|
6
6
|
import Exception from "exception"
|
|
7
7
|
|
|
8
8
|
// env
|
|
9
|
-
import foreign wasm args_get: (
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
9
|
+
import foreign wasm args_get: (
|
|
10
|
+
WasmI32,
|
|
11
|
+
WasmI32,
|
|
12
|
+
) -> WasmI32 from "wasi_snapshot_preview1"
|
|
13
|
+
import foreign wasm args_sizes_get: (
|
|
14
|
+
WasmI32,
|
|
15
|
+
WasmI32,
|
|
16
|
+
) -> WasmI32 from "wasi_snapshot_preview1"
|
|
17
|
+
import foreign wasm environ_get: (
|
|
18
|
+
WasmI32,
|
|
19
|
+
WasmI32,
|
|
20
|
+
) -> WasmI32 from "wasi_snapshot_preview1"
|
|
21
|
+
import foreign wasm environ_sizes_get: (
|
|
22
|
+
WasmI32,
|
|
23
|
+
WasmI32,
|
|
24
|
+
) -> WasmI32 from "wasi_snapshot_preview1"
|
|
13
25
|
|
|
14
26
|
// proc
|
|
15
|
-
import foreign wasm proc_exit:
|
|
16
|
-
import foreign wasm proc_raise:
|
|
27
|
+
import foreign wasm proc_exit: WasmI32 -> Void from "wasi_snapshot_preview1"
|
|
28
|
+
import foreign wasm proc_raise: WasmI32 -> WasmI32 from "wasi_snapshot_preview1"
|
|
17
29
|
import foreign wasm sched_yield: () -> WasmI32 from "wasi_snapshot_preview1"
|
|
18
30
|
|
|
19
31
|
// random
|
|
20
|
-
import foreign wasm random_get
|
|
32
|
+
import foreign wasm random_get: (
|
|
33
|
+
WasmI32,
|
|
34
|
+
WasmI32,
|
|
35
|
+
) -> WasmI32 from "wasi_snapshot_preview1"
|
|
21
36
|
|
|
22
37
|
// time
|
|
23
|
-
import foreign wasm clock_time_get: (
|
|
38
|
+
import foreign wasm clock_time_get: (
|
|
39
|
+
WasmI32,
|
|
40
|
+
WasmI64,
|
|
41
|
+
WasmI32,
|
|
42
|
+
) -> WasmI32 from "wasi_snapshot_preview1"
|
|
24
43
|
|
|
25
44
|
// file
|
|
26
|
-
import foreign wasm path_open
|
|
27
|
-
|
|
28
|
-
|
|
45
|
+
import foreign wasm path_open: (
|
|
46
|
+
WasmI32,
|
|
47
|
+
WasmI32,
|
|
48
|
+
WasmI32,
|
|
49
|
+
WasmI32,
|
|
50
|
+
WasmI32,
|
|
51
|
+
WasmI64,
|
|
52
|
+
WasmI64,
|
|
53
|
+
WasmI32,
|
|
54
|
+
WasmI32,
|
|
55
|
+
) -> WasmI32 from "wasi_snapshot_preview1"
|
|
56
|
+
import foreign wasm fd_read: (
|
|
57
|
+
WasmI32,
|
|
58
|
+
WasmI32,
|
|
59
|
+
WasmI32,
|
|
60
|
+
WasmI32,
|
|
61
|
+
) -> WasmI32 from "wasi_snapshot_preview1"
|
|
62
|
+
import foreign wasm fd_pread: (
|
|
63
|
+
WasmI32,
|
|
64
|
+
WasmI32,
|
|
65
|
+
WasmI32,
|
|
66
|
+
WasmI64,
|
|
67
|
+
WasmI32,
|
|
68
|
+
) -> WasmI32 from "wasi_snapshot_preview1"
|
|
29
69
|
/**
|
|
30
70
|
* Invokes the `fd_write` system call.
|
|
31
71
|
*
|
|
@@ -33,33 +73,140 @@ import foreign wasm fd_pread : (WasmI32, WasmI32, WasmI32, WasmI64, WasmI32) ->
|
|
|
33
73
|
* @param iovs: The pointer to the array of iovs to write
|
|
34
74
|
* @param iovs_len: The length of the array of iovs
|
|
35
75
|
* @param nwritten: Where to store the number of bytes written
|
|
36
|
-
* @
|
|
76
|
+
* @returns The number of bytes written
|
|
37
77
|
*/
|
|
38
|
-
import foreign wasm fd_write
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
import foreign wasm
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
import foreign wasm
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
import foreign wasm
|
|
57
|
-
import foreign wasm
|
|
58
|
-
import foreign wasm
|
|
59
|
-
import foreign wasm
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
78
|
+
import foreign wasm fd_write: (
|
|
79
|
+
WasmI32,
|
|
80
|
+
WasmI32,
|
|
81
|
+
WasmI32,
|
|
82
|
+
WasmI32,
|
|
83
|
+
) -> WasmI32 from "wasi_snapshot_preview1"
|
|
84
|
+
import foreign wasm fd_pwrite: (
|
|
85
|
+
WasmI32,
|
|
86
|
+
WasmI32,
|
|
87
|
+
WasmI32,
|
|
88
|
+
WasmI64,
|
|
89
|
+
WasmI32,
|
|
90
|
+
) -> WasmI32 from "wasi_snapshot_preview1"
|
|
91
|
+
import foreign wasm fd_allocate: (
|
|
92
|
+
WasmI32,
|
|
93
|
+
WasmI64,
|
|
94
|
+
WasmI64,
|
|
95
|
+
) -> WasmI32 from "wasi_snapshot_preview1"
|
|
96
|
+
import foreign wasm fd_close: WasmI32 -> WasmI32 from "wasi_snapshot_preview1"
|
|
97
|
+
import foreign wasm fd_datasync: WasmI32 -> WasmI32 from "wasi_snapshot_preview1"
|
|
98
|
+
import foreign wasm fd_sync: WasmI32 -> WasmI32 from "wasi_snapshot_preview1"
|
|
99
|
+
import foreign wasm fd_fdstat_get: (
|
|
100
|
+
WasmI32,
|
|
101
|
+
WasmI32,
|
|
102
|
+
) -> WasmI32 from "wasi_snapshot_preview1"
|
|
103
|
+
import foreign wasm fd_fdstat_set_flags: (
|
|
104
|
+
WasmI32,
|
|
105
|
+
WasmI32,
|
|
106
|
+
) -> WasmI32 from "wasi_snapshot_preview1"
|
|
107
|
+
import foreign wasm fd_fdstat_set_rights: (
|
|
108
|
+
WasmI32,
|
|
109
|
+
WasmI64,
|
|
110
|
+
WasmI64,
|
|
111
|
+
) -> WasmI32 from "wasi_snapshot_preview1"
|
|
112
|
+
import foreign wasm fd_filestat_get: (
|
|
113
|
+
WasmI32,
|
|
114
|
+
WasmI32,
|
|
115
|
+
) -> WasmI32 from "wasi_snapshot_preview1"
|
|
116
|
+
import foreign wasm fd_filestat_set_size: (
|
|
117
|
+
WasmI32,
|
|
118
|
+
WasmI64,
|
|
119
|
+
) -> WasmI32 from "wasi_snapshot_preview1"
|
|
120
|
+
import foreign wasm fd_filestat_set_times: (
|
|
121
|
+
WasmI32,
|
|
122
|
+
WasmI64,
|
|
123
|
+
WasmI64,
|
|
124
|
+
WasmI32,
|
|
125
|
+
) -> WasmI32 from "wasi_snapshot_preview1"
|
|
126
|
+
import foreign wasm fd_readdir: (
|
|
127
|
+
WasmI32,
|
|
128
|
+
WasmI32,
|
|
129
|
+
WasmI32,
|
|
130
|
+
WasmI64,
|
|
131
|
+
WasmI32,
|
|
132
|
+
) -> WasmI32 from "wasi_snapshot_preview1"
|
|
133
|
+
import foreign wasm fd_renumber: (
|
|
134
|
+
WasmI32,
|
|
135
|
+
WasmI32,
|
|
136
|
+
) -> WasmI32 from "wasi_snapshot_preview1"
|
|
137
|
+
import foreign wasm fd_seek: (
|
|
138
|
+
WasmI32,
|
|
139
|
+
WasmI64,
|
|
140
|
+
WasmI32,
|
|
141
|
+
WasmI32,
|
|
142
|
+
) -> WasmI32 from "wasi_snapshot_preview1"
|
|
143
|
+
import foreign wasm fd_tell: (
|
|
144
|
+
WasmI32,
|
|
145
|
+
WasmI32,
|
|
146
|
+
) -> WasmI32 from "wasi_snapshot_preview1"
|
|
147
|
+
import foreign wasm path_create_directory: (
|
|
148
|
+
WasmI32,
|
|
149
|
+
WasmI32,
|
|
150
|
+
WasmI32,
|
|
151
|
+
) -> WasmI32 from "wasi_snapshot_preview1"
|
|
152
|
+
import foreign wasm path_filestat_get: (
|
|
153
|
+
WasmI32,
|
|
154
|
+
WasmI32,
|
|
155
|
+
WasmI32,
|
|
156
|
+
WasmI32,
|
|
157
|
+
WasmI32,
|
|
158
|
+
) -> WasmI32 from "wasi_snapshot_preview1"
|
|
159
|
+
import foreign wasm path_filestat_set_times: (
|
|
160
|
+
WasmI32,
|
|
161
|
+
WasmI32,
|
|
162
|
+
WasmI32,
|
|
163
|
+
WasmI32,
|
|
164
|
+
WasmI64,
|
|
165
|
+
WasmI64,
|
|
166
|
+
WasmI32,
|
|
167
|
+
) -> WasmI32 from "wasi_snapshot_preview1"
|
|
168
|
+
import foreign wasm path_link: (
|
|
169
|
+
WasmI32,
|
|
170
|
+
WasmI32,
|
|
171
|
+
WasmI32,
|
|
172
|
+
WasmI32,
|
|
173
|
+
WasmI32,
|
|
174
|
+
WasmI32,
|
|
175
|
+
WasmI32,
|
|
176
|
+
) -> WasmI32 from "wasi_snapshot_preview1"
|
|
177
|
+
import foreign wasm path_symlink: (
|
|
178
|
+
WasmI32,
|
|
179
|
+
WasmI32,
|
|
180
|
+
WasmI32,
|
|
181
|
+
WasmI32,
|
|
182
|
+
WasmI32,
|
|
183
|
+
) -> WasmI32 from "wasi_snapshot_preview1"
|
|
184
|
+
import foreign wasm path_unlink_file: (
|
|
185
|
+
WasmI32,
|
|
186
|
+
WasmI32,
|
|
187
|
+
WasmI32,
|
|
188
|
+
) -> WasmI32 from "wasi_snapshot_preview1"
|
|
189
|
+
import foreign wasm path_readlink: (
|
|
190
|
+
WasmI32,
|
|
191
|
+
WasmI32,
|
|
192
|
+
WasmI32,
|
|
193
|
+
WasmI32,
|
|
194
|
+
WasmI32,
|
|
195
|
+
WasmI32,
|
|
196
|
+
) -> WasmI32 from "wasi_snapshot_preview1"
|
|
197
|
+
import foreign wasm path_remove_directory: (
|
|
198
|
+
WasmI32,
|
|
199
|
+
WasmI32,
|
|
200
|
+
WasmI32,
|
|
201
|
+
) -> WasmI32 from "wasi_snapshot_preview1"
|
|
202
|
+
import foreign wasm path_rename: (
|
|
203
|
+
WasmI32,
|
|
204
|
+
WasmI32,
|
|
205
|
+
WasmI32,
|
|
206
|
+
WasmI32,
|
|
207
|
+
WasmI32,
|
|
208
|
+
WasmI32,
|
|
209
|
+
) -> WasmI32 from "wasi_snapshot_preview1"
|
|
63
210
|
|
|
64
211
|
// clocks
|
|
65
212
|
let _CLOCK_REALTIME = 0n
|
|
@@ -176,17 +323,19 @@ let _ENOTCAPABLE = 76n
|
|
|
176
323
|
|
|
177
324
|
exception SystemError(Number)
|
|
178
325
|
|
|
179
|
-
let stringOfSystemError =
|
|
326
|
+
let stringOfSystemError = code => {
|
|
180
327
|
let n = WasmI32.shrS(WasmI32.fromGrain(code), 1n)
|
|
181
328
|
let (==) = WasmI32.eq
|
|
182
329
|
match (n) {
|
|
183
|
-
n when n == _ESUCCESS =>
|
|
330
|
+
n when n == _ESUCCESS =>
|
|
331
|
+
"SystemError: No error occurred. System call completed successfully.",
|
|
184
332
|
n when n == _ETOOBIG => "SystemError: Argument list too long.",
|
|
185
333
|
n when n == _EACCES => "SystemError: Permission denied.",
|
|
186
334
|
n when n == _EADDRINUSE => "SystemError: Address in use.",
|
|
187
335
|
n when n == _EADDRNOTAVAIL => "SystemError: Address not available.",
|
|
188
336
|
n when n == _EAFNOSUPPORT => "SystemError: Address family not supported.",
|
|
189
|
-
n when n == _EAGAIN =>
|
|
337
|
+
n when n == _EAGAIN =>
|
|
338
|
+
"SystemError: Resource unavailable, or operation would block.",
|
|
190
339
|
n when n == _EALREADY => "SystemError: Connection already in progress.",
|
|
191
340
|
n when n == _EBADF => "SystemError: Bad file descriptor.",
|
|
192
341
|
n when n == _EBADMSG => "SystemError: Bad message.",
|
|
@@ -198,7 +347,8 @@ let stringOfSystemError = (code) => {
|
|
|
198
347
|
n when n == _ECONNRESET => "SystemError: Connection reset.",
|
|
199
348
|
n when n == _EDEADLK => "SystemError: Resource deadlock would occur.",
|
|
200
349
|
n when n == _EDESTADDRREQ => "SystemError: Destination address required.",
|
|
201
|
-
n when n == _EDOM =>
|
|
350
|
+
n when n == _EDOM =>
|
|
351
|
+
"SystemError: Mathematics argument out of domain of function.",
|
|
202
352
|
n when n == _EDQUOT => "SystemError: Reserved.",
|
|
203
353
|
n when n == _EEXIST => "SystemError: File exists.",
|
|
204
354
|
n when n == _EFAULT => "SystemError: Bad address.",
|
|
@@ -234,14 +384,17 @@ let stringOfSystemError = (code) => {
|
|
|
234
384
|
n when n == _ENOSPC => "SystemError: No space left on device.",
|
|
235
385
|
n when n == _ENOSYS => "SystemError: Function not supported.",
|
|
236
386
|
n when n == _ENOTCONN => "SystemError: The socket is not connected.",
|
|
237
|
-
n when n == _ENOTDIR =>
|
|
387
|
+
n when n == _ENOTDIR =>
|
|
388
|
+
"SystemError: Not a directory or a symbolic link to a directory.",
|
|
238
389
|
n when n == _ENOTEMPTY => "SystemError: Directory not empty.",
|
|
239
390
|
n when n == _ENOTRECOVERABLE => "SystemError: State not recoverable.",
|
|
240
391
|
n when n == _ENOTSOCK => "SystemError: Not a socket.",
|
|
241
|
-
n when n == _ENOTSUP =>
|
|
392
|
+
n when n == _ENOTSUP =>
|
|
393
|
+
"SystemError: Not supported, or operation not supported on socket.",
|
|
242
394
|
n when n == _ENOTTY => "SystemError: Inappropriate I/O control operation.",
|
|
243
395
|
n when n == _ENXIO => "SystemError: No such device or address.",
|
|
244
|
-
n when n == _EOVERFLOW =>
|
|
396
|
+
n when n == _EOVERFLOW =>
|
|
397
|
+
"SystemError: Value too large to be stored in data type.",
|
|
245
398
|
n when n == _EOWNERDEAD => "SystemError: Previous owner died.",
|
|
246
399
|
n when n == _EPERM => "SystemError: Operation not permitted.",
|
|
247
400
|
n when n == _EPIPE => "SystemError: Broken pipe.",
|
|
@@ -256,7 +409,8 @@ let stringOfSystemError = (code) => {
|
|
|
256
409
|
n when n == _ETIMEDOUT => "SystemError: Connection timed out.",
|
|
257
410
|
n when n == _ETXTBSY => "SystemError: Text file busy.",
|
|
258
411
|
n when n == _EXDEV => "SystemError: Cross-device link.",
|
|
259
|
-
n when n == _ENOTCAPABLE =>
|
|
412
|
+
n when n == _ENOTCAPABLE =>
|
|
413
|
+
"SystemError: Extension: Capabilities insufficient.",
|
|
260
414
|
_ => "SystemError: Unknown system error: " ++ toString(code),
|
|
261
415
|
}
|
|
262
416
|
}
|
|
@@ -264,6 +418,6 @@ let stringOfSystemError = (code) => {
|
|
|
264
418
|
Exception.registerPrinter(e => {
|
|
265
419
|
match (e) {
|
|
266
420
|
SystemError(n) => Some(stringOfSystemError(n)),
|
|
267
|
-
_ => None
|
|
421
|
+
_ => None,
|
|
268
422
|
}
|
|
269
423
|
})
|