@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.
- package/CHANGELOG.md +52 -0
- package/LICENSE +1 -1
- package/array.gr +200 -89
- package/array.md +81 -5
- package/buffer.gr +93 -36
- package/bytes.gr +10 -10
- package/char.gr +112 -56
- package/char.md +200 -0
- package/float32.gr +120 -4
- package/float32.md +315 -0
- package/float64.gr +120 -4
- package/float64.md +315 -0
- package/hash.gr +42 -15
- package/hash.md +44 -0
- package/int32.gr +370 -75
- package/int32.md +833 -0
- package/int64.gr +370 -75
- package/int64.md +833 -0
- package/list.gr +121 -50
- package/map.gr +106 -110
- package/number.gr +37 -1
- package/number.md +66 -0
- package/option.gr +260 -53
- package/option.md +579 -0
- package/package.json +1 -1
- package/pervasives.gr +32 -20
- package/queue.gr +102 -30
- package/queue.md +191 -0
- package/range.gr +26 -26
- package/range.md +1 -1
- package/regex.md +9 -9
- package/result.gr +216 -70
- package/result.md +446 -0
- package/runtime/dataStructures.gr +28 -29
- package/runtime/debug.gr +0 -1
- package/runtime/equal.gr +37 -16
- package/runtime/exception.gr +28 -15
- package/runtime/gc.gr +33 -20
- package/runtime/malloc.gr +19 -11
- package/runtime/numberUtils.gr +208 -103
- package/runtime/numbers.gr +217 -118
- package/runtime/string.gr +98 -39
- package/runtime/stringUtils.gr +176 -0
- package/runtime/unsafe/conv.gr +10 -10
- package/runtime/unsafe/memory.gr +14 -3
- package/runtime/unsafe/printWasm.gr +4 -4
- package/runtime/unsafe/tags.gr +2 -2
- package/runtime/unsafe/wasmf32.gr +9 -2
- package/runtime/unsafe/wasmf64.gr +9 -2
- package/runtime/unsafe/wasmi32.gr +65 -47
- package/runtime/unsafe/wasmi64.gr +78 -50
- package/runtime/wasi.gr +199 -45
- package/set.gr +281 -119
- package/set.md +502 -0
- package/stack.gr +26 -26
- package/string.gr +657 -341
- package/string.md +815 -0
- package/sys/file.gr +356 -177
- package/sys/process.gr +10 -6
- package/sys/random.gr +3 -6
- package/sys/time.gr +3 -3
package/sys/file.gr
CHANGED
|
@@ -21,12 +21,19 @@ import WasmI32, {
|
|
|
21
21
|
gtS as (>),
|
|
22
22
|
geS as (>=),
|
|
23
23
|
and as (&),
|
|
24
|
-
or as (|)
|
|
24
|
+
or as (|),
|
|
25
25
|
} from "runtime/unsafe/wasmi32"
|
|
26
26
|
import WasmI64 from "runtime/unsafe/wasmi64"
|
|
27
27
|
import Wasi from "runtime/wasi"
|
|
28
28
|
import Memory from "runtime/unsafe/memory"
|
|
29
|
-
import {
|
|
29
|
+
import {
|
|
30
|
+
tagSimpleNumber,
|
|
31
|
+
allocateArray,
|
|
32
|
+
allocateString,
|
|
33
|
+
loadAdtVal,
|
|
34
|
+
newInt64,
|
|
35
|
+
allocateInt64,
|
|
36
|
+
} from "runtime/dataStructures"
|
|
30
37
|
|
|
31
38
|
import List from "list"
|
|
32
39
|
|
|
@@ -38,7 +45,7 @@ import List from "list"
|
|
|
38
45
|
* Represents a handle to an open file on the system.
|
|
39
46
|
*/
|
|
40
47
|
export enum FileDescriptor {
|
|
41
|
-
FileDescriptor(Number)
|
|
48
|
+
FileDescriptor(Number),
|
|
42
49
|
}
|
|
43
50
|
|
|
44
51
|
/**
|
|
@@ -46,7 +53,7 @@ export enum FileDescriptor {
|
|
|
46
53
|
*/
|
|
47
54
|
export enum LookupFlag {
|
|
48
55
|
// Follow symlinks
|
|
49
|
-
SymlinkFollow
|
|
56
|
+
SymlinkFollow,
|
|
50
57
|
}
|
|
51
58
|
|
|
52
59
|
// TODO(#775): This has specific ordering requirements because of ambiguous type inference
|
|
@@ -54,14 +61,14 @@ let rec combineLookupFlagsHelp = (acc, dirflags) => {
|
|
|
54
61
|
match (dirflags) {
|
|
55
62
|
[hd, ...tl] => {
|
|
56
63
|
let flag = match (hd) {
|
|
57
|
-
SymlinkFollow => Wasi._LOOKUP_FLAG_SYMLINK_FOLLOW
|
|
64
|
+
SymlinkFollow => Wasi._LOOKUP_FLAG_SYMLINK_FOLLOW,
|
|
58
65
|
}
|
|
59
66
|
combineLookupFlagsHelp(acc | flag, tl)
|
|
60
67
|
},
|
|
61
|
-
[] => acc
|
|
68
|
+
[] => acc,
|
|
62
69
|
}
|
|
63
70
|
}
|
|
64
|
-
let combineLookupFlags =
|
|
71
|
+
let combineLookupFlags = dirflags => {
|
|
65
72
|
combineLookupFlagsHelp(0n, dirflags)
|
|
66
73
|
}
|
|
67
74
|
|
|
@@ -91,10 +98,10 @@ let rec combineOpenFlagsHelp = (acc, dirflags) => {
|
|
|
91
98
|
}
|
|
92
99
|
combineOpenFlagsHelp(acc | flag, tl)
|
|
93
100
|
},
|
|
94
|
-
[] => acc
|
|
101
|
+
[] => acc,
|
|
95
102
|
}
|
|
96
103
|
}
|
|
97
|
-
let combineOpenFlags =
|
|
104
|
+
let combineOpenFlags = dirflags => {
|
|
98
105
|
combineOpenFlagsHelp(0n, dirflags)
|
|
99
106
|
}
|
|
100
107
|
|
|
@@ -242,13 +249,13 @@ let rec combineRightsHelp = (acc, dirflags) => {
|
|
|
242
249
|
PathUnlinkFile => _RIGHT_PATH_UNLINK_FILE,
|
|
243
250
|
PollFdReadwrite => _RIGHT_POLL_FD_READWRITE,
|
|
244
251
|
SockShutdown => _RIGHT_SOCK_SHUTDOWN,
|
|
245
|
-
_ => fail "Unknown file right"
|
|
252
|
+
_ => fail "Unknown file right",
|
|
246
253
|
}
|
|
247
254
|
combineRightsHelp(WasmI64.or(flag, acc), tl)
|
|
248
|
-
}
|
|
255
|
+
},
|
|
249
256
|
}
|
|
250
257
|
}
|
|
251
|
-
let combineRights =
|
|
258
|
+
let combineRights = dirflags => {
|
|
252
259
|
combineRightsHelp(0N, dirflags)
|
|
253
260
|
}
|
|
254
261
|
|
|
@@ -283,10 +290,10 @@ let rec combineFdFlagsHelp = (acc, dirflags) => {
|
|
|
283
290
|
}
|
|
284
291
|
combineFdFlagsHelp(acc | flag, tl)
|
|
285
292
|
},
|
|
286
|
-
[] => acc
|
|
293
|
+
[] => acc,
|
|
287
294
|
}
|
|
288
295
|
}
|
|
289
|
-
let combineFdFlags =
|
|
296
|
+
let combineFdFlags = dirflags => {
|
|
290
297
|
combineFdFlagsHelp(0n, dirflags)
|
|
291
298
|
}
|
|
292
299
|
|
|
@@ -313,7 +320,7 @@ export enum Filetype {
|
|
|
313
320
|
}
|
|
314
321
|
|
|
315
322
|
// TODO(#775): This has specific ordering requirements because of ambiguous type inference
|
|
316
|
-
let filetypeFromNumber =
|
|
323
|
+
let filetypeFromNumber = filetype => {
|
|
317
324
|
match (filetype) {
|
|
318
325
|
0n => Unknown,
|
|
319
326
|
1n => BlockDevice,
|
|
@@ -323,7 +330,7 @@ let filetypeFromNumber = (filetype) => {
|
|
|
323
330
|
5n => SocketDatagram,
|
|
324
331
|
6n => SocketStream,
|
|
325
332
|
7n => SymbolicLink,
|
|
326
|
-
_ => fail "Unknown filetype"
|
|
333
|
+
_ => fail "Unknown filetype",
|
|
327
334
|
}
|
|
328
335
|
}
|
|
329
336
|
|
|
@@ -346,7 +353,7 @@ export record Stats {
|
|
|
346
353
|
filetype: Filetype,
|
|
347
354
|
flags: List<FdFlag>,
|
|
348
355
|
rights: List<Rights>,
|
|
349
|
-
rightsInheriting: List<Rights
|
|
356
|
+
rightsInheriting: List<Rights>,
|
|
350
357
|
}
|
|
351
358
|
|
|
352
359
|
/**
|
|
@@ -360,7 +367,7 @@ export record Filestats {
|
|
|
360
367
|
size: Int64,
|
|
361
368
|
accessed: Int64,
|
|
362
369
|
modified: Int64,
|
|
363
|
-
changed: Int64
|
|
370
|
+
changed: Int64,
|
|
364
371
|
}
|
|
365
372
|
|
|
366
373
|
/**
|
|
@@ -369,7 +376,7 @@ export record Filestats {
|
|
|
369
376
|
export record DirectoryEntry {
|
|
370
377
|
inode: Int64,
|
|
371
378
|
filetype: Filetype,
|
|
372
|
-
path: String
|
|
379
|
+
path: String,
|
|
373
380
|
}
|
|
374
381
|
|
|
375
382
|
/**
|
|
@@ -393,13 +400,13 @@ export let stderr = FileDescriptor(2)
|
|
|
393
400
|
*/
|
|
394
401
|
export let pwdfd = FileDescriptor(3)
|
|
395
402
|
|
|
396
|
-
let wasmSafeOk =
|
|
403
|
+
let wasmSafeOk = val => {
|
|
397
404
|
Memory.incRef(WasmI32.fromGrain(Ok))
|
|
398
405
|
Memory.incRef(WasmI32.fromGrain(val))
|
|
399
406
|
Ok(val)
|
|
400
407
|
}
|
|
401
408
|
|
|
402
|
-
let wasmSafeErr =
|
|
409
|
+
let wasmSafeErr = err => {
|
|
403
410
|
Memory.incRef(WasmI32.fromGrain(Err))
|
|
404
411
|
Memory.incRef(WasmI32.fromGrain(err))
|
|
405
412
|
Err(err)
|
|
@@ -417,21 +424,20 @@ let wasmSafeErr = (err) => {
|
|
|
417
424
|
* @param flags: Flags which affect read/write operations on this file descriptor
|
|
418
425
|
* @returns `Ok(fd)` of the opened file or directory if successful or `Err(exception)` otherwise
|
|
419
426
|
*/
|
|
420
|
-
export let rec pathOpen =
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
427
|
+
export let rec pathOpen =
|
|
428
|
+
(
|
|
429
|
+
dirFd: FileDescriptor,
|
|
430
|
+
dirFlags: List<LookupFlag>,
|
|
431
|
+
path: String,
|
|
432
|
+
openFlags: List<OpenFlag>,
|
|
433
|
+
rights: List<Rights>,
|
|
434
|
+
rightsInheriting: List<Rights>,
|
|
435
|
+
flags: List<FdFlag>,
|
|
436
|
+
) => {
|
|
429
437
|
let dirFdArg = dirFd
|
|
430
438
|
let pathArg = path
|
|
431
439
|
let rightsInheritingArg = rightsInheriting
|
|
432
|
-
let dirFd = match (dirFd) {
|
|
433
|
-
FileDescriptor(n) => WasmI32.fromGrain(n) >> 1n
|
|
434
|
-
}
|
|
440
|
+
let dirFd = match (dirFd) { FileDescriptor(n) => WasmI32.fromGrain(n) >> 1n }
|
|
435
441
|
|
|
436
442
|
let combinedDirFlags = combineLookupFlags(dirFlags)
|
|
437
443
|
|
|
@@ -489,19 +495,17 @@ export let rec pathOpen = (
|
|
|
489
495
|
*/
|
|
490
496
|
export let rec fdRead = (fd: FileDescriptor, size: Number) => {
|
|
491
497
|
let fdArg = fd
|
|
492
|
-
let fd = match (fd) {
|
|
493
|
-
FileDescriptor(n) => WasmI32.fromGrain(n) >> 1n
|
|
494
|
-
}
|
|
498
|
+
let fd = match (fd) { FileDescriptor(n) => WasmI32.fromGrain(n) >> 1n }
|
|
495
499
|
|
|
496
500
|
let n = WasmI32.fromGrain(size) >> 1n
|
|
497
501
|
|
|
498
502
|
let iovs = Memory.malloc(3n * 4n)
|
|
499
503
|
let strPtr = allocateString(n)
|
|
500
504
|
|
|
501
|
-
WasmI32.store(iovs, strPtr +
|
|
505
|
+
WasmI32.store(iovs, strPtr + 2n * 4n, 0n)
|
|
502
506
|
WasmI32.store(iovs, n, 4n)
|
|
503
507
|
|
|
504
|
-
let mut nread = iovs +
|
|
508
|
+
let mut nread = iovs + 3n * 4n
|
|
505
509
|
|
|
506
510
|
let err = Wasi.fd_read(fd, iovs, 1n, nread)
|
|
507
511
|
let ret = if (err != Wasi._ESUCCESS) {
|
|
@@ -534,9 +538,7 @@ export let rec fdRead = (fd: FileDescriptor, size: Number) => {
|
|
|
534
538
|
export let rec fdPread = (fd: FileDescriptor, offset: Int64, size: Number) => {
|
|
535
539
|
let fdArg = fd
|
|
536
540
|
let offsetArg = offset
|
|
537
|
-
let fd = match (fd) {
|
|
538
|
-
FileDescriptor(n) => WasmI32.fromGrain(n) >> 1n
|
|
539
|
-
}
|
|
541
|
+
let fd = match (fd) { FileDescriptor(n) => WasmI32.fromGrain(n) >> 1n }
|
|
540
542
|
|
|
541
543
|
let offset = WasmI64.load(WasmI32.fromGrain(offset), 8n)
|
|
542
544
|
|
|
@@ -545,10 +547,10 @@ export let rec fdPread = (fd: FileDescriptor, offset: Int64, size: Number) => {
|
|
|
545
547
|
let iovs = Memory.malloc(3n * 4n)
|
|
546
548
|
let strPtr = allocateString(n)
|
|
547
549
|
|
|
548
|
-
WasmI32.store(iovs, strPtr +
|
|
550
|
+
WasmI32.store(iovs, strPtr + 2n * 4n, 0n)
|
|
549
551
|
WasmI32.store(iovs, n, 4n)
|
|
550
552
|
|
|
551
|
-
let mut nread = iovs +
|
|
553
|
+
let mut nread = iovs + 3n * 4n
|
|
552
554
|
|
|
553
555
|
let err = Wasi.fd_pread(fd, iovs, 1n, offset, nread)
|
|
554
556
|
let ret = if (err != Wasi._ESUCCESS) {
|
|
@@ -580,9 +582,7 @@ export let rec fdPread = (fd: FileDescriptor, offset: Int64, size: Number) => {
|
|
|
580
582
|
*/
|
|
581
583
|
export let rec fdWrite = (fd: FileDescriptor, data: String) => {
|
|
582
584
|
let fdArg = fd
|
|
583
|
-
let fd = match (fd) {
|
|
584
|
-
FileDescriptor(n) => WasmI32.fromGrain(n) >> 1n
|
|
585
|
-
}
|
|
585
|
+
let fd = match (fd) { FileDescriptor(n) => WasmI32.fromGrain(n) >> 1n }
|
|
586
586
|
|
|
587
587
|
let iovs = Memory.malloc(3n * 4n)
|
|
588
588
|
let strPtr = WasmI32.fromGrain(data)
|
|
@@ -590,7 +590,7 @@ export let rec fdWrite = (fd: FileDescriptor, data: String) => {
|
|
|
590
590
|
WasmI32.store(iovs, strPtr + 8n, 0n)
|
|
591
591
|
WasmI32.store(iovs, WasmI32.load(strPtr, 4n), 4n)
|
|
592
592
|
|
|
593
|
-
let mut nwritten = iovs +
|
|
593
|
+
let mut nwritten = iovs + 3n * 4n
|
|
594
594
|
|
|
595
595
|
let err = Wasi.fd_write(fd, iovs, 1n, nwritten)
|
|
596
596
|
let ret = if (err != Wasi._ESUCCESS) {
|
|
@@ -620,19 +620,17 @@ export let rec fdWrite = (fd: FileDescriptor, data: String) => {
|
|
|
620
620
|
export let rec fdPwrite = (fd: FileDescriptor, data: String, offset: Int64) => {
|
|
621
621
|
let fdArg = fd
|
|
622
622
|
let offsetArg = offset
|
|
623
|
-
let fd = match (fd) {
|
|
624
|
-
FileDescriptor(n) => WasmI32.fromGrain(n) >> 1n
|
|
625
|
-
}
|
|
623
|
+
let fd = match (fd) { FileDescriptor(n) => WasmI32.fromGrain(n) >> 1n }
|
|
626
624
|
|
|
627
625
|
let iovs = Memory.malloc(3n * 4n)
|
|
628
626
|
let strPtr = WasmI32.fromGrain(data)
|
|
629
627
|
|
|
630
|
-
WasmI32.store(iovs, strPtr +
|
|
628
|
+
WasmI32.store(iovs, strPtr + 2n * 4n, 0n)
|
|
631
629
|
WasmI32.store(iovs, WasmI32.load(strPtr, 4n), 4n)
|
|
632
630
|
|
|
633
631
|
let offset = WasmI64.load(WasmI32.fromGrain(offset), 8n)
|
|
634
632
|
|
|
635
|
-
let mut nwritten = iovs +
|
|
633
|
+
let mut nwritten = iovs + 3n * 4n
|
|
636
634
|
|
|
637
635
|
let err = Wasi.fd_pwrite(fd, iovs, 1n, offset, nwritten)
|
|
638
636
|
let ret = if (err != Wasi._ESUCCESS) {
|
|
@@ -660,13 +658,16 @@ export let rec fdPwrite = (fd: FileDescriptor, data: String, offset: Int64) => {
|
|
|
660
658
|
* @param size: The number of bytes to allocate
|
|
661
659
|
* @returns `Ok(void)` if successful or `Err(exception)` otherwise
|
|
662
660
|
*/
|
|
663
|
-
export let rec fdAllocate =
|
|
661
|
+
export let rec fdAllocate =
|
|
662
|
+
(
|
|
663
|
+
fd: FileDescriptor,
|
|
664
|
+
offset: Int64,
|
|
665
|
+
size: Int64,
|
|
666
|
+
) => {
|
|
664
667
|
let fdArg = fd
|
|
665
668
|
let offsetArg = offset
|
|
666
669
|
let sizeArg = size
|
|
667
|
-
let fd = match (fd) {
|
|
668
|
-
FileDescriptor(n) => WasmI32.fromGrain(n) >> 1n
|
|
669
|
-
}
|
|
670
|
+
let fd = match (fd) { FileDescriptor(n) => WasmI32.fromGrain(n) >> 1n }
|
|
670
671
|
|
|
671
672
|
let offset = WasmI64.load(WasmI32.fromGrain(offset), 8n)
|
|
672
673
|
|
|
@@ -693,9 +694,7 @@ export let rec fdAllocate = (fd: FileDescriptor, offset: Int64, size: Int64) =>
|
|
|
693
694
|
*/
|
|
694
695
|
export let rec fdClose = (fd: FileDescriptor) => {
|
|
695
696
|
let fdArg = fd
|
|
696
|
-
let fd = match (fd) {
|
|
697
|
-
FileDescriptor(n) => WasmI32.fromGrain(n) >> 1n
|
|
698
|
-
}
|
|
697
|
+
let fd = match (fd) { FileDescriptor(n) => WasmI32.fromGrain(n) >> 1n }
|
|
699
698
|
|
|
700
699
|
let err = Wasi.fd_close(fd)
|
|
701
700
|
let ret = if (err != Wasi._ESUCCESS) {
|
|
@@ -716,9 +715,7 @@ export let rec fdClose = (fd: FileDescriptor) => {
|
|
|
716
715
|
*/
|
|
717
716
|
export let rec fdDatasync = (fd: FileDescriptor) => {
|
|
718
717
|
let fdArg = fd
|
|
719
|
-
let fd = match (fd) {
|
|
720
|
-
FileDescriptor(n) => WasmI32.fromGrain(n) >> 1n
|
|
721
|
-
}
|
|
718
|
+
let fd = match (fd) { FileDescriptor(n) => WasmI32.fromGrain(n) >> 1n }
|
|
722
719
|
|
|
723
720
|
let err = Wasi.fd_datasync(fd)
|
|
724
721
|
let ret = if (err != Wasi._ESUCCESS) {
|
|
@@ -739,9 +736,7 @@ export let rec fdDatasync = (fd: FileDescriptor) => {
|
|
|
739
736
|
*/
|
|
740
737
|
export let rec fdSync = (fd: FileDescriptor) => {
|
|
741
738
|
let fdArg = fd
|
|
742
|
-
let fd = match (fd) {
|
|
743
|
-
FileDescriptor(n) => WasmI32.fromGrain(n) >> 1n
|
|
744
|
-
}
|
|
739
|
+
let fd = match (fd) { FileDescriptor(n) => WasmI32.fromGrain(n) >> 1n }
|
|
745
740
|
|
|
746
741
|
let err = Wasi.fd_sync(fd)
|
|
747
742
|
let ret = if (err != Wasi._ESUCCESS) {
|
|
@@ -754,7 +749,6 @@ export let rec fdSync = (fd: FileDescriptor) => {
|
|
|
754
749
|
ret
|
|
755
750
|
}
|
|
756
751
|
|
|
757
|
-
|
|
758
752
|
let wasmSafeCons = (a, b) => {
|
|
759
753
|
// [TODO] Once grain-lang/grain#802 is fixed:
|
|
760
754
|
// Memory.incRef(WasmI32.fromGrain([...]))
|
|
@@ -766,8 +760,101 @@ let wasmSafeCons = (a, b) => {
|
|
|
766
760
|
// [a, ...b]
|
|
767
761
|
}
|
|
768
762
|
|
|
769
|
-
let orderedFdflags = wasmSafeCons(
|
|
770
|
-
|
|
763
|
+
let orderedFdflags = wasmSafeCons(
|
|
764
|
+
Append,
|
|
765
|
+
wasmSafeCons(
|
|
766
|
+
Dsync,
|
|
767
|
+
wasmSafeCons(Nonblock, wasmSafeCons(Rsync, wasmSafeCons(Sync, [])))
|
|
768
|
+
)
|
|
769
|
+
)
|
|
770
|
+
let orderedRights = wasmSafeCons(
|
|
771
|
+
FdDatasync,
|
|
772
|
+
wasmSafeCons(
|
|
773
|
+
FdRead,
|
|
774
|
+
wasmSafeCons(
|
|
775
|
+
FdSeek,
|
|
776
|
+
wasmSafeCons(
|
|
777
|
+
FdSetFlags,
|
|
778
|
+
wasmSafeCons(
|
|
779
|
+
FdSync,
|
|
780
|
+
wasmSafeCons(
|
|
781
|
+
FdTell,
|
|
782
|
+
wasmSafeCons(
|
|
783
|
+
FdWrite,
|
|
784
|
+
wasmSafeCons(
|
|
785
|
+
FdAdvise,
|
|
786
|
+
wasmSafeCons(
|
|
787
|
+
FdAllocate,
|
|
788
|
+
wasmSafeCons(
|
|
789
|
+
PathCreateDirectory,
|
|
790
|
+
wasmSafeCons(
|
|
791
|
+
PathCreateFile,
|
|
792
|
+
wasmSafeCons(
|
|
793
|
+
PathLinkSource,
|
|
794
|
+
wasmSafeCons(
|
|
795
|
+
PathLinkTarget,
|
|
796
|
+
wasmSafeCons(
|
|
797
|
+
PathOpen,
|
|
798
|
+
wasmSafeCons(
|
|
799
|
+
FdReaddir,
|
|
800
|
+
wasmSafeCons(
|
|
801
|
+
PathReadlink,
|
|
802
|
+
wasmSafeCons(
|
|
803
|
+
PathRenameSource,
|
|
804
|
+
wasmSafeCons(
|
|
805
|
+
PathRenameTarget,
|
|
806
|
+
wasmSafeCons(
|
|
807
|
+
PathFilestats,
|
|
808
|
+
wasmSafeCons(
|
|
809
|
+
PathSetSize,
|
|
810
|
+
wasmSafeCons(
|
|
811
|
+
PathSetTimes,
|
|
812
|
+
wasmSafeCons(
|
|
813
|
+
FdFilestats,
|
|
814
|
+
wasmSafeCons(
|
|
815
|
+
FdSetSize,
|
|
816
|
+
wasmSafeCons(
|
|
817
|
+
FdSetTimes,
|
|
818
|
+
wasmSafeCons(
|
|
819
|
+
PathSymlink,
|
|
820
|
+
wasmSafeCons(
|
|
821
|
+
PathRemoveDirectory,
|
|
822
|
+
wasmSafeCons(
|
|
823
|
+
PathUnlinkFile,
|
|
824
|
+
wasmSafeCons(
|
|
825
|
+
PollFdReadwrite,
|
|
826
|
+
wasmSafeCons(
|
|
827
|
+
SockShutdown,
|
|
828
|
+
[]
|
|
829
|
+
)
|
|
830
|
+
)
|
|
831
|
+
)
|
|
832
|
+
)
|
|
833
|
+
)
|
|
834
|
+
)
|
|
835
|
+
)
|
|
836
|
+
)
|
|
837
|
+
)
|
|
838
|
+
)
|
|
839
|
+
)
|
|
840
|
+
)
|
|
841
|
+
)
|
|
842
|
+
)
|
|
843
|
+
)
|
|
844
|
+
)
|
|
845
|
+
)
|
|
846
|
+
)
|
|
847
|
+
)
|
|
848
|
+
)
|
|
849
|
+
)
|
|
850
|
+
)
|
|
851
|
+
)
|
|
852
|
+
)
|
|
853
|
+
)
|
|
854
|
+
)
|
|
855
|
+
)
|
|
856
|
+
)
|
|
857
|
+
)
|
|
771
858
|
|
|
772
859
|
/**
|
|
773
860
|
* Retrieve information about a file descriptor.
|
|
@@ -777,9 +864,7 @@ let orderedRights = wasmSafeCons(FdDatasync, wasmSafeCons(FdRead, wasmSafeCons(F
|
|
|
777
864
|
*/
|
|
778
865
|
export let rec fdStats = (fd: FileDescriptor) => {
|
|
779
866
|
let fdArg = fd
|
|
780
|
-
let fd = match (fd) {
|
|
781
|
-
FileDescriptor(n) => WasmI32.fromGrain(n) >> 1n
|
|
782
|
-
}
|
|
867
|
+
let fd = match (fd) { FileDescriptor(n) => WasmI32.fromGrain(n) >> 1n }
|
|
783
868
|
|
|
784
869
|
let structPtr = Memory.malloc(24n)
|
|
785
870
|
|
|
@@ -794,7 +879,7 @@ export let rec fdStats = (fd: FileDescriptor) => {
|
|
|
794
879
|
|
|
795
880
|
let flagsToWasmVal = (flag, i) => {
|
|
796
881
|
let fdflags = WasmI32.load16U(structPtr, 4n)
|
|
797
|
-
WasmI32.gtU(
|
|
882
|
+
WasmI32.gtU(fdflags & 1n << (WasmI32.fromGrain(i) >> 1n), 0n)
|
|
798
883
|
}
|
|
799
884
|
Memory.incRef(WasmI32.fromGrain(List.filteri))
|
|
800
885
|
Memory.incRef(WasmI32.fromGrain(flagsToWasmVal))
|
|
@@ -808,7 +893,7 @@ export let rec fdStats = (fd: FileDescriptor) => {
|
|
|
808
893
|
|
|
809
894
|
let flagsToWasmVal = (flag, i) => {
|
|
810
895
|
let rights = WasmI64.load(structPtr, 8n)
|
|
811
|
-
(rights &
|
|
896
|
+
(rights & 1N << WasmI64.extendI32U(WasmI32.fromGrain(i) >> 1n)) > 0N
|
|
812
897
|
}
|
|
813
898
|
Memory.incRef(WasmI32.fromGrain(List.filteri))
|
|
814
899
|
Memory.incRef(WasmI32.fromGrain(flagsToWasmVal))
|
|
@@ -818,7 +903,9 @@ export let rec fdStats = (fd: FileDescriptor) => {
|
|
|
818
903
|
|
|
819
904
|
let flagsToWasmVal = (flag, i) => {
|
|
820
905
|
let rightsInheriting = WasmI64.load(structPtr, 16n)
|
|
821
|
-
(rightsInheriting &
|
|
906
|
+
(rightsInheriting &
|
|
907
|
+
1N << WasmI64.extendI32U(WasmI32.fromGrain(i) >> 1n)) >
|
|
908
|
+
0N
|
|
822
909
|
}
|
|
823
910
|
Memory.incRef(WasmI32.fromGrain(List.filteri))
|
|
824
911
|
Memory.incRef(WasmI32.fromGrain(flagsToWasmVal))
|
|
@@ -828,7 +915,14 @@ export let rec fdStats = (fd: FileDescriptor) => {
|
|
|
828
915
|
|
|
829
916
|
Memory.free(structPtr)
|
|
830
917
|
|
|
831
|
-
wasmSafeOk(
|
|
918
|
+
wasmSafeOk(
|
|
919
|
+
{
|
|
920
|
+
filetype,
|
|
921
|
+
flags: fdflagsList,
|
|
922
|
+
rights: rightsList,
|
|
923
|
+
rightsInheriting: rightsInheritingList,
|
|
924
|
+
}
|
|
925
|
+
)
|
|
832
926
|
}
|
|
833
927
|
Memory.decRef(WasmI32.fromGrain(fdArg))
|
|
834
928
|
Memory.decRef(WasmI32.fromGrain(fdStats))
|
|
@@ -845,9 +939,7 @@ export let rec fdStats = (fd: FileDescriptor) => {
|
|
|
845
939
|
export let rec fdSetFlags = (fd: FileDescriptor, flags: List<FdFlag>) => {
|
|
846
940
|
let fdArg = fd
|
|
847
941
|
let flagsArg = flags
|
|
848
|
-
let fd = match (fd) {
|
|
849
|
-
FileDescriptor(n) => WasmI32.fromGrain(n) >> 1n
|
|
850
|
-
}
|
|
942
|
+
let fd = match (fd) { FileDescriptor(n) => WasmI32.fromGrain(n) >> 1n }
|
|
851
943
|
|
|
852
944
|
let flags = combineFdFlags(flags)
|
|
853
945
|
|
|
@@ -871,13 +963,16 @@ export let rec fdSetFlags = (fd: FileDescriptor, flags: List<FdFlag>) => {
|
|
|
871
963
|
* @param rightsInheriting: Inheriting rights to apply to the file descriptor
|
|
872
964
|
* @returns `Ok(void)` if successful or `Err(exception)` otherwise
|
|
873
965
|
*/
|
|
874
|
-
export let rec fdSetRights =
|
|
966
|
+
export let rec fdSetRights =
|
|
967
|
+
(
|
|
968
|
+
fd: FileDescriptor,
|
|
969
|
+
rights: List<Rights>,
|
|
970
|
+
rightsInheriting: List<Rights>,
|
|
971
|
+
) => {
|
|
875
972
|
let fdArg = fd
|
|
876
973
|
let rightsArg = rights
|
|
877
974
|
let rightsInheritingArg = rightsInheriting
|
|
878
|
-
let fd = match (fd) {
|
|
879
|
-
FileDescriptor(n) => WasmI32.fromGrain(n) >> 1n
|
|
880
|
-
}
|
|
975
|
+
let fd = match (fd) { FileDescriptor(n) => WasmI32.fromGrain(n) >> 1n }
|
|
881
976
|
|
|
882
977
|
let rights = combineRights(rights)
|
|
883
978
|
let rightsInheriting = combineRights(rightsInheriting)
|
|
@@ -903,9 +998,7 @@ export let rec fdSetRights = (fd: FileDescriptor, rights: List<Rights>, rightsIn
|
|
|
903
998
|
*/
|
|
904
999
|
export let rec fdFilestats = (fd: FileDescriptor) => {
|
|
905
1000
|
let fdArg = fd
|
|
906
|
-
let fd = match (fd) {
|
|
907
|
-
FileDescriptor(n) => WasmI32.fromGrain(n) >> 1n
|
|
908
|
-
}
|
|
1001
|
+
let fd = match (fd) { FileDescriptor(n) => WasmI32.fromGrain(n) >> 1n }
|
|
909
1002
|
|
|
910
1003
|
let filestats = Memory.malloc(64n)
|
|
911
1004
|
|
|
@@ -917,15 +1010,23 @@ export let rec fdFilestats = (fd: FileDescriptor) => {
|
|
|
917
1010
|
let device = WasmI32.toGrain(newInt64(WasmI64.load(filestats, 0n))): Int64
|
|
918
1011
|
let inode = WasmI32.toGrain(newInt64(WasmI64.load(filestats, 8n))): Int64
|
|
919
1012
|
let filetype = filetypeFromNumber(WasmI32.load8U(filestats, 16n))
|
|
920
|
-
let linkcount = WasmI32.toGrain(
|
|
1013
|
+
let linkcount = WasmI32.toGrain(
|
|
1014
|
+
newInt64(WasmI64.load(filestats, 24n))
|
|
1015
|
+
): Int64
|
|
921
1016
|
let size = WasmI32.toGrain(newInt64(WasmI64.load(filestats, 32n))): Int64
|
|
922
|
-
let accessed = WasmI32.toGrain(
|
|
923
|
-
|
|
1017
|
+
let accessed = WasmI32.toGrain(
|
|
1018
|
+
newInt64(WasmI64.load(filestats, 40n))
|
|
1019
|
+
): Int64
|
|
1020
|
+
let modified = WasmI32.toGrain(
|
|
1021
|
+
newInt64(WasmI64.load(filestats, 48n))
|
|
1022
|
+
): Int64
|
|
924
1023
|
let changed = WasmI32.toGrain(newInt64(WasmI64.load(filestats, 56n))): Int64
|
|
925
1024
|
|
|
926
1025
|
Memory.free(filestats)
|
|
927
1026
|
|
|
928
|
-
wasmSafeOk(
|
|
1027
|
+
wasmSafeOk(
|
|
1028
|
+
{ device, inode, filetype, linkcount, size, accessed, modified, changed }
|
|
1029
|
+
)
|
|
929
1030
|
}
|
|
930
1031
|
Memory.decRef(WasmI32.fromGrain(fdArg))
|
|
931
1032
|
Memory.decRef(WasmI32.fromGrain(fdFilestats))
|
|
@@ -942,9 +1043,7 @@ export let rec fdFilestats = (fd: FileDescriptor) => {
|
|
|
942
1043
|
export let rec fdSetSize = (fd: FileDescriptor, size: Int64) => {
|
|
943
1044
|
let fdArg = fd
|
|
944
1045
|
let sizeArg = size
|
|
945
|
-
let fd = match (fd) {
|
|
946
|
-
FileDescriptor(n) => WasmI32.fromGrain(n) >> 1n
|
|
947
|
-
}
|
|
1046
|
+
let fd = match (fd) { FileDescriptor(n) => WasmI32.fromGrain(n) >> 1n }
|
|
948
1047
|
|
|
949
1048
|
let size = WasmI64.load(WasmI32.fromGrain(size), 8n)
|
|
950
1049
|
|
|
@@ -969,9 +1068,7 @@ export let rec fdSetSize = (fd: FileDescriptor, size: Int64) => {
|
|
|
969
1068
|
*/
|
|
970
1069
|
export let rec fdSetAccessTime = (fd: FileDescriptor, timestamp: Int64) => {
|
|
971
1070
|
let fdArg = fd
|
|
972
|
-
let fd = match (fd) {
|
|
973
|
-
FileDescriptor(n) => WasmI32.fromGrain(n) >> 1n
|
|
974
|
-
}
|
|
1071
|
+
let fd = match (fd) { FileDescriptor(n) => WasmI32.fromGrain(n) >> 1n }
|
|
975
1072
|
|
|
976
1073
|
let time = WasmI64.load(WasmI32.fromGrain(timestamp), 8n)
|
|
977
1074
|
|
|
@@ -995,9 +1092,7 @@ export let rec fdSetAccessTime = (fd: FileDescriptor, timestamp: Int64) => {
|
|
|
995
1092
|
*/
|
|
996
1093
|
export let rec fdSetAccessTimeNow = (fd: FileDescriptor) => {
|
|
997
1094
|
let fdArg = fd
|
|
998
|
-
let fd = match (fd) {
|
|
999
|
-
FileDescriptor(n) => WasmI32.fromGrain(n) >> 1n
|
|
1000
|
-
}
|
|
1095
|
+
let fd = match (fd) { FileDescriptor(n) => WasmI32.fromGrain(n) >> 1n }
|
|
1001
1096
|
|
|
1002
1097
|
let err = Wasi.fd_filestat_set_times(fd, 0N, 0N, Wasi._TIME_SET_ATIM_NOW)
|
|
1003
1098
|
let ret = if (err != Wasi._ESUCCESS) {
|
|
@@ -1019,9 +1114,7 @@ export let rec fdSetAccessTimeNow = (fd: FileDescriptor) => {
|
|
|
1019
1114
|
*/
|
|
1020
1115
|
export let rec fdSetModifiedTime = (fd: FileDescriptor, timestamp: Int64) => {
|
|
1021
1116
|
let fdArg = fd
|
|
1022
|
-
let fd = match (fd) {
|
|
1023
|
-
FileDescriptor(n) => WasmI32.fromGrain(n) >> 1n
|
|
1024
|
-
}
|
|
1117
|
+
let fd = match (fd) { FileDescriptor(n) => WasmI32.fromGrain(n) >> 1n }
|
|
1025
1118
|
|
|
1026
1119
|
let time = WasmI64.load(WasmI32.fromGrain(timestamp), 8n)
|
|
1027
1120
|
|
|
@@ -1045,9 +1138,7 @@ export let rec fdSetModifiedTime = (fd: FileDescriptor, timestamp: Int64) => {
|
|
|
1045
1138
|
*/
|
|
1046
1139
|
export let rec fdSetModifiedTimeNow = (fd: FileDescriptor) => {
|
|
1047
1140
|
let fdArg = fd
|
|
1048
|
-
let fd = match (fd) {
|
|
1049
|
-
FileDescriptor(n) => WasmI32.fromGrain(n) >> 1n
|
|
1050
|
-
}
|
|
1141
|
+
let fd = match (fd) { FileDescriptor(n) => WasmI32.fromGrain(n) >> 1n }
|
|
1051
1142
|
|
|
1052
1143
|
let err = Wasi.fd_filestat_set_times(fd, 0N, 0N, Wasi._TIME_SET_MTIM_NOW)
|
|
1053
1144
|
let ret = if (err != Wasi._ESUCCESS) {
|
|
@@ -1068,9 +1159,7 @@ export let rec fdSetModifiedTimeNow = (fd: FileDescriptor) => {
|
|
|
1068
1159
|
*/
|
|
1069
1160
|
export let rec fdReaddir = (fd: FileDescriptor) => {
|
|
1070
1161
|
let fdArg = fd
|
|
1071
|
-
let fd = match (fd) {
|
|
1072
|
-
FileDescriptor(n) => WasmI32.fromGrain(n) >> 1n
|
|
1073
|
-
}
|
|
1162
|
+
let fd = match (fd) { FileDescriptor(n) => WasmI32.fromGrain(n) >> 1n }
|
|
1074
1163
|
|
|
1075
1164
|
let structWidth = 24n
|
|
1076
1165
|
|
|
@@ -1091,7 +1180,7 @@ export let rec fdReaddir = (fd: FileDescriptor) => {
|
|
|
1091
1180
|
if (used <= 0n) {
|
|
1092
1181
|
Memory.free(buf)
|
|
1093
1182
|
Memory.free(bufUsed)
|
|
1094
|
-
wasmSafeOk(WasmI32.toGrain(allocateArray(0n)): Array<DirectoryEntry>)
|
|
1183
|
+
wasmSafeOk(WasmI32.toGrain(allocateArray(0n)): (Array<DirectoryEntry>))
|
|
1095
1184
|
} else {
|
|
1096
1185
|
bufLen = WasmI32.load(buf, 16n) + structWidth * 2n
|
|
1097
1186
|
|
|
@@ -1167,8 +1256,8 @@ export let rec fdReaddir = (fd: FileDescriptor) => {
|
|
|
1167
1256
|
bufs = next
|
|
1168
1257
|
}
|
|
1169
1258
|
|
|
1170
|
-
wasmSafeOk(WasmI32.toGrain(arr): Array<DirectoryEntry>)
|
|
1171
|
-
}
|
|
1259
|
+
wasmSafeOk(WasmI32.toGrain(arr): (Array<DirectoryEntry>))
|
|
1260
|
+
},
|
|
1172
1261
|
}
|
|
1173
1262
|
}
|
|
1174
1263
|
}
|
|
@@ -1188,12 +1277,10 @@ export let rec fdRenumber = (fromFd: FileDescriptor, toFd: FileDescriptor) => {
|
|
|
1188
1277
|
let fromFdArg = fromFd
|
|
1189
1278
|
let toFdArg = toFd
|
|
1190
1279
|
let fromFd = match (fromFd) {
|
|
1191
|
-
FileDescriptor(n) => WasmI32.fromGrain(n) >> 1n
|
|
1280
|
+
FileDescriptor(n) => WasmI32.fromGrain(n) >> 1n,
|
|
1192
1281
|
}
|
|
1193
1282
|
|
|
1194
|
-
let toFd = match (toFd) {
|
|
1195
|
-
FileDescriptor(n) => WasmI32.fromGrain(n) >> 1n
|
|
1196
|
-
}
|
|
1283
|
+
let toFd = match (toFd) { FileDescriptor(n) => WasmI32.fromGrain(n) >> 1n }
|
|
1197
1284
|
|
|
1198
1285
|
let err = Wasi.fd_renumber(fromFd, toFd)
|
|
1199
1286
|
let ret = if (err != Wasi._ESUCCESS) {
|
|
@@ -1219,16 +1306,14 @@ export let rec fdSeek = (fd: FileDescriptor, offset: Int64, whence: Whence) => {
|
|
|
1219
1306
|
let fdArg = fd
|
|
1220
1307
|
let offsetArg = offset
|
|
1221
1308
|
let whenceArg = whence
|
|
1222
|
-
let fd = match (fd) {
|
|
1223
|
-
FileDescriptor(n) => WasmI32.fromGrain(n) >> 1n
|
|
1224
|
-
}
|
|
1309
|
+
let fd = match (fd) { FileDescriptor(n) => WasmI32.fromGrain(n) >> 1n }
|
|
1225
1310
|
|
|
1226
1311
|
let offset = WasmI64.load(WasmI32.fromGrain(offset), 8n)
|
|
1227
1312
|
|
|
1228
1313
|
let whence = match (whence) {
|
|
1229
1314
|
Set => Wasi._WHENCE_SET,
|
|
1230
1315
|
Current => Wasi._WHENCE_CUR,
|
|
1231
|
-
End => Wasi._WHENCE_END
|
|
1316
|
+
End => Wasi._WHENCE_END,
|
|
1232
1317
|
}
|
|
1233
1318
|
|
|
1234
1319
|
let newoffset = allocateInt64()
|
|
@@ -1256,9 +1341,7 @@ export let rec fdSeek = (fd: FileDescriptor, offset: Int64, whence: Whence) => {
|
|
|
1256
1341
|
*/
|
|
1257
1342
|
export let rec fdTell = (fd: FileDescriptor) => {
|
|
1258
1343
|
let fdArg = fd
|
|
1259
|
-
let fd = match (fd) {
|
|
1260
|
-
FileDescriptor(n) => WasmI32.fromGrain(n) >> 1n
|
|
1261
|
-
}
|
|
1344
|
+
let fd = match (fd) { FileDescriptor(n) => WasmI32.fromGrain(n) >> 1n }
|
|
1262
1345
|
|
|
1263
1346
|
let offset = allocateInt64()
|
|
1264
1347
|
let offsetPtr = offset + 8n
|
|
@@ -1284,9 +1367,7 @@ export let rec fdTell = (fd: FileDescriptor) => {
|
|
|
1284
1367
|
*/
|
|
1285
1368
|
export let rec pathCreateDirectory = (fd: FileDescriptor, path: String) => {
|
|
1286
1369
|
let fdArg = fd
|
|
1287
|
-
let fd = match (fd) {
|
|
1288
|
-
FileDescriptor(n) => WasmI32.fromGrain(n) >> 1n
|
|
1289
|
-
}
|
|
1370
|
+
let fd = match (fd) { FileDescriptor(n) => WasmI32.fromGrain(n) >> 1n }
|
|
1290
1371
|
|
|
1291
1372
|
let stringPtr = WasmI32.fromGrain(path)
|
|
1292
1373
|
|
|
@@ -1312,11 +1393,14 @@ export let rec pathCreateDirectory = (fd: FileDescriptor, path: String) => {
|
|
|
1312
1393
|
* @param path: The path to retrieve information about
|
|
1313
1394
|
* @returns `Ok(info)` of the `Filestats` associated with the file descriptor if successful or `Err(exception)` otherwise
|
|
1314
1395
|
*/
|
|
1315
|
-
export let rec pathFilestats =
|
|
1396
|
+
export let rec pathFilestats =
|
|
1397
|
+
(
|
|
1398
|
+
fd: FileDescriptor,
|
|
1399
|
+
dirFlags: List<LookupFlag>,
|
|
1400
|
+
path: String,
|
|
1401
|
+
) => {
|
|
1316
1402
|
let fdArg = fd
|
|
1317
|
-
let fd = match (fd) {
|
|
1318
|
-
FileDescriptor(n) => WasmI32.fromGrain(n) >> 1n
|
|
1319
|
-
}
|
|
1403
|
+
let fd = match (fd) { FileDescriptor(n) => WasmI32.fromGrain(n) >> 1n }
|
|
1320
1404
|
|
|
1321
1405
|
let combinedDirFlags = combineLookupFlags(dirFlags)
|
|
1322
1406
|
|
|
@@ -1326,7 +1410,13 @@ export let rec pathFilestats = (fd: FileDescriptor, dirFlags: List<LookupFlag>,
|
|
|
1326
1410
|
|
|
1327
1411
|
let filestats = Memory.malloc(64n)
|
|
1328
1412
|
|
|
1329
|
-
let err = Wasi.path_filestat_get(
|
|
1413
|
+
let err = Wasi.path_filestat_get(
|
|
1414
|
+
fd,
|
|
1415
|
+
combinedDirFlags,
|
|
1416
|
+
pathPtr,
|
|
1417
|
+
pathSize,
|
|
1418
|
+
filestats
|
|
1419
|
+
)
|
|
1330
1420
|
let ret = if (err != Wasi._ESUCCESS) {
|
|
1331
1421
|
Memory.free(filestats)
|
|
1332
1422
|
wasmSafeErr(Wasi.SystemError(tagSimpleNumber(err)))
|
|
@@ -1334,16 +1424,23 @@ export let rec pathFilestats = (fd: FileDescriptor, dirFlags: List<LookupFlag>,
|
|
|
1334
1424
|
let device = WasmI32.toGrain(newInt64(WasmI64.load(filestats, 0n))): Int64
|
|
1335
1425
|
let inode = WasmI32.toGrain(newInt64(WasmI64.load(filestats, 8n))): Int64
|
|
1336
1426
|
let filetype = filetypeFromNumber(WasmI32.load8U(filestats, 16n))
|
|
1337
|
-
let linkcount = WasmI32.toGrain(
|
|
1427
|
+
let linkcount = WasmI32.toGrain(
|
|
1428
|
+
newInt64(WasmI64.load(filestats, 24n))
|
|
1429
|
+
): Int64
|
|
1338
1430
|
let size = WasmI32.toGrain(newInt64(WasmI64.load(filestats, 32n))): Int64
|
|
1339
|
-
let accessed = WasmI32.toGrain(
|
|
1340
|
-
|
|
1431
|
+
let accessed = WasmI32.toGrain(
|
|
1432
|
+
newInt64(WasmI64.load(filestats, 40n))
|
|
1433
|
+
): Int64
|
|
1434
|
+
let modified = WasmI32.toGrain(
|
|
1435
|
+
newInt64(WasmI64.load(filestats, 48n))
|
|
1436
|
+
): Int64
|
|
1341
1437
|
let changed = WasmI32.toGrain(newInt64(WasmI64.load(filestats, 56n))): Int64
|
|
1342
1438
|
|
|
1343
|
-
|
|
1344
1439
|
Memory.free(filestats)
|
|
1345
1440
|
|
|
1346
|
-
wasmSafeOk(
|
|
1441
|
+
wasmSafeOk(
|
|
1442
|
+
{ device, inode, filetype, linkcount, size, accessed, modified, changed }
|
|
1443
|
+
)
|
|
1347
1444
|
}
|
|
1348
1445
|
Memory.decRef(WasmI32.fromGrain(fdArg))
|
|
1349
1446
|
Memory.decRef(WasmI32.fromGrain(dirFlags))
|
|
@@ -1361,11 +1458,15 @@ export let rec pathFilestats = (fd: FileDescriptor, dirFlags: List<LookupFlag>,
|
|
|
1361
1458
|
* @param timestamp: The time to set
|
|
1362
1459
|
* @returns `Ok(void)` if successful or `Err(exception)` otherwise
|
|
1363
1460
|
*/
|
|
1364
|
-
export let rec pathSetAccessTime =
|
|
1461
|
+
export let rec pathSetAccessTime =
|
|
1462
|
+
(
|
|
1463
|
+
fd: FileDescriptor,
|
|
1464
|
+
dirFlags: List<LookupFlag>,
|
|
1465
|
+
path: String,
|
|
1466
|
+
timestamp: Int64,
|
|
1467
|
+
) => {
|
|
1365
1468
|
let fdArg = fd
|
|
1366
|
-
let fd = match (fd) {
|
|
1367
|
-
FileDescriptor(n) => WasmI32.fromGrain(n) >> 1n
|
|
1368
|
-
}
|
|
1469
|
+
let fd = match (fd) { FileDescriptor(n) => WasmI32.fromGrain(n) >> 1n }
|
|
1369
1470
|
|
|
1370
1471
|
let combinedDirFlags = combineLookupFlags(dirFlags)
|
|
1371
1472
|
|
|
@@ -1375,7 +1476,15 @@ export let rec pathSetAccessTime = (fd: FileDescriptor, dirFlags: List<LookupFla
|
|
|
1375
1476
|
|
|
1376
1477
|
let time = WasmI64.load(WasmI32.fromGrain(timestamp), 8n)
|
|
1377
1478
|
|
|
1378
|
-
let err = Wasi.path_filestat_set_times(
|
|
1479
|
+
let err = Wasi.path_filestat_set_times(
|
|
1480
|
+
fd,
|
|
1481
|
+
combinedDirFlags,
|
|
1482
|
+
pathPtr,
|
|
1483
|
+
pathSize,
|
|
1484
|
+
time,
|
|
1485
|
+
0N,
|
|
1486
|
+
Wasi._TIME_SET_ATIM
|
|
1487
|
+
)
|
|
1379
1488
|
let ret = if (err != Wasi._ESUCCESS) {
|
|
1380
1489
|
wasmSafeErr(Wasi.SystemError(tagSimpleNumber(err)))
|
|
1381
1490
|
} else {
|
|
@@ -1397,11 +1506,14 @@ export let rec pathSetAccessTime = (fd: FileDescriptor, dirFlags: List<LookupFla
|
|
|
1397
1506
|
* @param path: The path to set the time
|
|
1398
1507
|
* @returns `Ok(void)` if successful or `Err(exception)` otherwise
|
|
1399
1508
|
*/
|
|
1400
|
-
export let pathSetAccessTimeNow =
|
|
1509
|
+
export let pathSetAccessTimeNow =
|
|
1510
|
+
(
|
|
1511
|
+
fd: FileDescriptor,
|
|
1512
|
+
dirFlags: List<LookupFlag>,
|
|
1513
|
+
path: String,
|
|
1514
|
+
) => {
|
|
1401
1515
|
let fdArg = fd
|
|
1402
|
-
let fd = match (fd) {
|
|
1403
|
-
FileDescriptor(n) => WasmI32.fromGrain(n) >> 1n
|
|
1404
|
-
}
|
|
1516
|
+
let fd = match (fd) { FileDescriptor(n) => WasmI32.fromGrain(n) >> 1n }
|
|
1405
1517
|
|
|
1406
1518
|
let combinedDirFlags = combineLookupFlags(dirFlags)
|
|
1407
1519
|
|
|
@@ -1409,7 +1521,15 @@ export let pathSetAccessTimeNow = (fd: FileDescriptor, dirFlags: List<LookupFlag
|
|
|
1409
1521
|
let pathSize = WasmI32.load(pathPtr, 4n)
|
|
1410
1522
|
pathPtr += 8n
|
|
1411
1523
|
|
|
1412
|
-
let err = Wasi.path_filestat_set_times(
|
|
1524
|
+
let err = Wasi.path_filestat_set_times(
|
|
1525
|
+
fd,
|
|
1526
|
+
combinedDirFlags,
|
|
1527
|
+
pathPtr,
|
|
1528
|
+
pathSize,
|
|
1529
|
+
0N,
|
|
1530
|
+
0N,
|
|
1531
|
+
Wasi._TIME_SET_ATIM_NOW
|
|
1532
|
+
)
|
|
1413
1533
|
let ret = if (err != Wasi._ESUCCESS) {
|
|
1414
1534
|
wasmSafeErr(Wasi.SystemError(tagSimpleNumber(err)))
|
|
1415
1535
|
} else {
|
|
@@ -1431,11 +1551,15 @@ export let pathSetAccessTimeNow = (fd: FileDescriptor, dirFlags: List<LookupFlag
|
|
|
1431
1551
|
* @param timestamp: The time to set
|
|
1432
1552
|
* @returns `Ok(void)` if successful or `Err(exception)` otherwise
|
|
1433
1553
|
*/
|
|
1434
|
-
export let rec pathSetModifiedTime =
|
|
1554
|
+
export let rec pathSetModifiedTime =
|
|
1555
|
+
(
|
|
1556
|
+
fd: FileDescriptor,
|
|
1557
|
+
dirFlags: List<LookupFlag>,
|
|
1558
|
+
path: String,
|
|
1559
|
+
timestamp: Int64,
|
|
1560
|
+
) => {
|
|
1435
1561
|
let fdArg = fd
|
|
1436
|
-
let fd = match (fd) {
|
|
1437
|
-
FileDescriptor(n) => WasmI32.fromGrain(n) >> 1n
|
|
1438
|
-
}
|
|
1562
|
+
let fd = match (fd) { FileDescriptor(n) => WasmI32.fromGrain(n) >> 1n }
|
|
1439
1563
|
|
|
1440
1564
|
let combinedDirFlags = combineLookupFlags(dirFlags)
|
|
1441
1565
|
|
|
@@ -1445,7 +1569,15 @@ export let rec pathSetModifiedTime = (fd: FileDescriptor, dirFlags: List<LookupF
|
|
|
1445
1569
|
|
|
1446
1570
|
let time = WasmI64.load(WasmI32.fromGrain(timestamp), 8n)
|
|
1447
1571
|
|
|
1448
|
-
let err = Wasi.path_filestat_set_times(
|
|
1572
|
+
let err = Wasi.path_filestat_set_times(
|
|
1573
|
+
fd,
|
|
1574
|
+
combinedDirFlags,
|
|
1575
|
+
pathPtr,
|
|
1576
|
+
pathSize,
|
|
1577
|
+
0N,
|
|
1578
|
+
time,
|
|
1579
|
+
Wasi._TIME_SET_MTIM
|
|
1580
|
+
)
|
|
1449
1581
|
let ret = if (err != Wasi._ESUCCESS) {
|
|
1450
1582
|
wasmSafeErr(Wasi.SystemError(tagSimpleNumber(err)))
|
|
1451
1583
|
} else {
|
|
@@ -1467,11 +1599,14 @@ export let rec pathSetModifiedTime = (fd: FileDescriptor, dirFlags: List<LookupF
|
|
|
1467
1599
|
* @param path: The path to set the time
|
|
1468
1600
|
* @returns `Ok(void)` if successful or `Err(exception)` otherwise
|
|
1469
1601
|
*/
|
|
1470
|
-
export let rec pathSetModifiedTimeNow =
|
|
1602
|
+
export let rec pathSetModifiedTimeNow =
|
|
1603
|
+
(
|
|
1604
|
+
fd: FileDescriptor,
|
|
1605
|
+
dirFlags: List<LookupFlag>,
|
|
1606
|
+
path: String,
|
|
1607
|
+
) => {
|
|
1471
1608
|
let fdArg = fd
|
|
1472
|
-
let fd = match (fd) {
|
|
1473
|
-
FileDescriptor(n) => WasmI32.fromGrain(n) >> 1n
|
|
1474
|
-
}
|
|
1609
|
+
let fd = match (fd) { FileDescriptor(n) => WasmI32.fromGrain(n) >> 1n }
|
|
1475
1610
|
|
|
1476
1611
|
let combinedDirFlags = combineLookupFlags(dirFlags)
|
|
1477
1612
|
|
|
@@ -1479,7 +1614,15 @@ export let rec pathSetModifiedTimeNow = (fd: FileDescriptor, dirFlags: List<Look
|
|
|
1479
1614
|
let pathSize = WasmI32.load(pathPtr, 4n)
|
|
1480
1615
|
pathPtr += 8n
|
|
1481
1616
|
|
|
1482
|
-
let err = Wasi.path_filestat_set_times(
|
|
1617
|
+
let err = Wasi.path_filestat_set_times(
|
|
1618
|
+
fd,
|
|
1619
|
+
combinedDirFlags,
|
|
1620
|
+
pathPtr,
|
|
1621
|
+
pathSize,
|
|
1622
|
+
0N,
|
|
1623
|
+
0N,
|
|
1624
|
+
Wasi._TIME_SET_MTIM_NOW
|
|
1625
|
+
)
|
|
1483
1626
|
let ret = if (err != Wasi._ESUCCESS) {
|
|
1484
1627
|
wasmSafeErr(Wasi.SystemError(tagSimpleNumber(err)))
|
|
1485
1628
|
} else {
|
|
@@ -1502,15 +1645,22 @@ export let rec pathSetModifiedTimeNow = (fd: FileDescriptor, dirFlags: List<Look
|
|
|
1502
1645
|
* @param targetPath: The path to the target of the link
|
|
1503
1646
|
* @returns `Ok(void)` if successful or `Err(exception)` otherwise
|
|
1504
1647
|
*/
|
|
1505
|
-
export let rec pathLink =
|
|
1648
|
+
export let rec pathLink =
|
|
1649
|
+
(
|
|
1650
|
+
sourceFd: FileDescriptor,
|
|
1651
|
+
dirFlags: List<LookupFlag>,
|
|
1652
|
+
sourcePath: String,
|
|
1653
|
+
targetFd: FileDescriptor,
|
|
1654
|
+
targetPath: String,
|
|
1655
|
+
) => {
|
|
1506
1656
|
let sourceFdArg = sourceFd
|
|
1507
1657
|
let targetFdArg = targetFd
|
|
1508
1658
|
let sourceFd = match (sourceFd) {
|
|
1509
|
-
FileDescriptor(n) => WasmI32.fromGrain(n) >> 1n
|
|
1659
|
+
FileDescriptor(n) => WasmI32.fromGrain(n) >> 1n,
|
|
1510
1660
|
}
|
|
1511
1661
|
|
|
1512
1662
|
let targetFd = match (targetFd) {
|
|
1513
|
-
FileDescriptor(n) => WasmI32.fromGrain(n) >> 1n
|
|
1663
|
+
FileDescriptor(n) => WasmI32.fromGrain(n) >> 1n,
|
|
1514
1664
|
}
|
|
1515
1665
|
|
|
1516
1666
|
let combinedDirFlags = combineLookupFlags(dirFlags)
|
|
@@ -1521,7 +1671,15 @@ export let rec pathLink = (sourceFd: FileDescriptor, dirFlags: List<LookupFlag>,
|
|
|
1521
1671
|
let sourceSize = WasmI32.load(sourcePtr, 4n)
|
|
1522
1672
|
let targetSize = WasmI32.load(targetPtr, 4n)
|
|
1523
1673
|
|
|
1524
|
-
let err = Wasi.path_link(
|
|
1674
|
+
let err = Wasi.path_link(
|
|
1675
|
+
sourceFd,
|
|
1676
|
+
combinedDirFlags,
|
|
1677
|
+
sourcePtr + 8n,
|
|
1678
|
+
sourceSize,
|
|
1679
|
+
targetFd,
|
|
1680
|
+
targetPtr + 8n,
|
|
1681
|
+
targetSize
|
|
1682
|
+
)
|
|
1525
1683
|
let ret = if (err != Wasi._ESUCCESS) {
|
|
1526
1684
|
wasmSafeErr(Wasi.SystemError(tagSimpleNumber(err)))
|
|
1527
1685
|
} else {
|
|
@@ -1544,11 +1702,14 @@ export let rec pathLink = (sourceFd: FileDescriptor, dirFlags: List<LookupFlag>,
|
|
|
1544
1702
|
* @param targetPath: The path to the target of the link
|
|
1545
1703
|
* @returns `Ok(void)` if successful or `Err(exception)` otherwise
|
|
1546
1704
|
*/
|
|
1547
|
-
export let rec pathSymlink =
|
|
1705
|
+
export let rec pathSymlink =
|
|
1706
|
+
(
|
|
1707
|
+
fd: FileDescriptor,
|
|
1708
|
+
sourcePath: String,
|
|
1709
|
+
targetPath: String,
|
|
1710
|
+
) => {
|
|
1548
1711
|
let fdArg = fd
|
|
1549
|
-
let fd = match (fd) {
|
|
1550
|
-
FileDescriptor(n) => WasmI32.fromGrain(n) >> 1n
|
|
1551
|
-
}
|
|
1712
|
+
let fd = match (fd) { FileDescriptor(n) => WasmI32.fromGrain(n) >> 1n }
|
|
1552
1713
|
|
|
1553
1714
|
let sourcePtr = WasmI32.fromGrain(sourcePath)
|
|
1554
1715
|
let targetPtr = WasmI32.fromGrain(targetPath)
|
|
@@ -1556,7 +1717,13 @@ export let rec pathSymlink = (fd: FileDescriptor, sourcePath: String, targetPath
|
|
|
1556
1717
|
let sourceSize = WasmI32.load(sourcePtr, 4n)
|
|
1557
1718
|
let targetSize = WasmI32.load(targetPtr, 4n)
|
|
1558
1719
|
|
|
1559
|
-
let err = Wasi.path_symlink(
|
|
1720
|
+
let err = Wasi.path_symlink(
|
|
1721
|
+
sourcePtr + 8n,
|
|
1722
|
+
sourceSize,
|
|
1723
|
+
fd,
|
|
1724
|
+
targetPtr + 8n,
|
|
1725
|
+
targetSize
|
|
1726
|
+
)
|
|
1560
1727
|
let ret = if (err != Wasi._ESUCCESS) {
|
|
1561
1728
|
wasmSafeErr(Wasi.SystemError(tagSimpleNumber(err)))
|
|
1562
1729
|
} else {
|
|
@@ -1578,9 +1745,7 @@ export let rec pathSymlink = (fd: FileDescriptor, sourcePath: String, targetPath
|
|
|
1578
1745
|
*/
|
|
1579
1746
|
export let rec pathUnlink = (fd: FileDescriptor, path: String) => {
|
|
1580
1747
|
let fdArg = fd
|
|
1581
|
-
let fd = match (fd) {
|
|
1582
|
-
FileDescriptor(n) => WasmI32.fromGrain(n) >> 1n
|
|
1583
|
-
}
|
|
1748
|
+
let fd = match (fd) { FileDescriptor(n) => WasmI32.fromGrain(n) >> 1n }
|
|
1584
1749
|
|
|
1585
1750
|
let pathPtr = WasmI32.fromGrain(path)
|
|
1586
1751
|
let pathSize = WasmI32.load(pathPtr, 4n)
|
|
@@ -1605,12 +1770,15 @@ export let rec pathUnlink = (fd: FileDescriptor, path: String) => {
|
|
|
1605
1770
|
* @param size: The number of bytes to read
|
|
1606
1771
|
* @returns `Ok((contents, numBytes))` of the bytes read and the number of bytes read if successful or `Err(exception)` otherwise
|
|
1607
1772
|
*/
|
|
1608
|
-
export let rec pathReadlink =
|
|
1773
|
+
export let rec pathReadlink =
|
|
1774
|
+
(
|
|
1775
|
+
fd: FileDescriptor,
|
|
1776
|
+
path: String,
|
|
1777
|
+
size: Number,
|
|
1778
|
+
) => {
|
|
1609
1779
|
let fdArg = fd
|
|
1610
1780
|
let sizeArg = size
|
|
1611
|
-
let fd = match (fd) {
|
|
1612
|
-
FileDescriptor(n) => WasmI32.fromGrain(n) >> 1n
|
|
1613
|
-
}
|
|
1781
|
+
let fd = match (fd) { FileDescriptor(n) => WasmI32.fromGrain(n) >> 1n }
|
|
1614
1782
|
|
|
1615
1783
|
let pathPtr = WasmI32.fromGrain(path)
|
|
1616
1784
|
let pathSize = WasmI32.load(pathPtr, 4n)
|
|
@@ -1649,9 +1817,7 @@ export let rec pathReadlink = (fd: FileDescriptor, path: String, size: Number) =
|
|
|
1649
1817
|
*/
|
|
1650
1818
|
export let rec pathRemoveDirectory = (fd: FileDescriptor, path: String) => {
|
|
1651
1819
|
let fdArg = fd
|
|
1652
|
-
let fd = match (fd) {
|
|
1653
|
-
FileDescriptor(n) => WasmI32.fromGrain(n) >> 1n
|
|
1654
|
-
}
|
|
1820
|
+
let fd = match (fd) { FileDescriptor(n) => WasmI32.fromGrain(n) >> 1n }
|
|
1655
1821
|
|
|
1656
1822
|
let pathPtr = WasmI32.fromGrain(path)
|
|
1657
1823
|
let pathSize = WasmI32.load(pathPtr, 4n)
|
|
@@ -1677,15 +1843,21 @@ export let rec pathRemoveDirectory = (fd: FileDescriptor, path: String) => {
|
|
|
1677
1843
|
* @param targetPath: The new path of the file
|
|
1678
1844
|
* @returns `Ok(void)` if successful or `Err(exception)` otherwise
|
|
1679
1845
|
*/
|
|
1680
|
-
export let rec pathRename =
|
|
1846
|
+
export let rec pathRename =
|
|
1847
|
+
(
|
|
1848
|
+
sourceFd: FileDescriptor,
|
|
1849
|
+
sourcePath: String,
|
|
1850
|
+
targetFd: FileDescriptor,
|
|
1851
|
+
targetPath: String,
|
|
1852
|
+
) => {
|
|
1681
1853
|
let sourceFdArg = sourceFd
|
|
1682
1854
|
let targetFdArg = targetFd
|
|
1683
1855
|
let sourceFd = match (sourceFd) {
|
|
1684
|
-
FileDescriptor(n) => WasmI32.fromGrain(n) >> 1n
|
|
1856
|
+
FileDescriptor(n) => WasmI32.fromGrain(n) >> 1n,
|
|
1685
1857
|
}
|
|
1686
1858
|
|
|
1687
1859
|
let targetFd = match (targetFd) {
|
|
1688
|
-
FileDescriptor(n) => WasmI32.fromGrain(n) >> 1n
|
|
1860
|
+
FileDescriptor(n) => WasmI32.fromGrain(n) >> 1n,
|
|
1689
1861
|
}
|
|
1690
1862
|
|
|
1691
1863
|
let sourcePtr = WasmI32.fromGrain(sourcePath)
|
|
@@ -1694,7 +1866,14 @@ export let rec pathRename = (sourceFd: FileDescriptor, sourcePath: String, targe
|
|
|
1694
1866
|
let sourceSize = WasmI32.load(sourcePtr, 4n)
|
|
1695
1867
|
let targetSize = WasmI32.load(targetPtr, 4n)
|
|
1696
1868
|
|
|
1697
|
-
let err = Wasi.path_rename(
|
|
1869
|
+
let err = Wasi.path_rename(
|
|
1870
|
+
sourceFd,
|
|
1871
|
+
sourcePtr + 8n,
|
|
1872
|
+
sourceSize,
|
|
1873
|
+
targetFd,
|
|
1874
|
+
targetPtr + 8n,
|
|
1875
|
+
targetSize
|
|
1876
|
+
)
|
|
1698
1877
|
let ret = if (err != Wasi._ESUCCESS) {
|
|
1699
1878
|
wasmSafeErr(Wasi.SystemError(tagSimpleNumber(err)))
|
|
1700
1879
|
} else {
|