@shd101wyy/yo 0.1.25 → 0.1.27
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/.github/skills/yo-async-effects/SKILL.md +4 -4
- package/.github/skills/yo-async-effects/async-effects-recipes.md +40 -40
- package/.github/skills/yo-core-patterns/SKILL.md +1 -1
- package/.github/skills/yo-core-patterns/core-patterns-cheatsheet.md +30 -26
- package/.github/skills/yo-project-workflow/SKILL.md +6 -3
- package/.github/skills/yo-project-workflow/workflow-cheatsheet.md +34 -11
- package/.github/skills/yo-syntax/SKILL.md +7 -6
- package/.github/skills/yo-syntax/syntax-cheatsheet.md +78 -60
- package/.github/skills/yo-wasm-integration/wasm-integration-cheatsheet.md +3 -3
- package/README.md +10 -8
- package/out/cjs/index.cjs +583 -567
- package/out/cjs/yo-cli.cjs +664 -632
- package/out/cjs/yo-lsp.cjs +510 -485
- package/out/esm/index.mjs +538 -522
- package/out/types/src/codegen/codegen-c.d.ts +2 -2
- package/out/types/src/codegen/functions/collection.d.ts +2 -2
- package/out/types/src/codegen/functions/context.d.ts +3 -2
- package/out/types/src/codegen/types/collection.d.ts +2 -2
- package/out/types/src/codegen/utils/index.d.ts +3 -1
- package/out/types/src/doc/builder.d.ts +2 -2
- package/out/types/src/evaluator/calls/closure-type.d.ts +2 -2
- package/out/types/src/evaluator/calls/record-type.d.ts +11 -0
- package/out/types/src/evaluator/context.d.ts +8 -9
- package/out/types/src/evaluator/index.d.ts +3 -3
- package/out/types/src/evaluator/types/record.d.ts +14 -0
- package/out/types/src/evaluator/types/validation.d.ts +2 -2
- package/out/types/src/evaluator/values/anonymous-module.d.ts +5 -5
- package/out/types/src/evaluator/values/impl.d.ts +1 -1
- package/out/types/src/expr.d.ts +1 -4
- package/out/types/src/formatter.d.ts +11 -0
- package/out/types/src/function-value.d.ts +1 -1
- package/out/types/src/lsp/document-manager.d.ts +1 -1
- package/out/types/src/lsp/formatting.d.ts +2 -0
- package/out/types/src/module-manager.d.ts +3 -3
- package/out/types/src/tests/formatter.test.d.ts +1 -0
- package/out/types/src/types/creators.d.ts +3 -4
- package/out/types/src/types/definitions.d.ts +8 -19
- package/out/types/src/types/guards.d.ts +3 -3
- package/out/types/src/types/tags.d.ts +0 -1
- package/out/types/src/types/utils.d.ts +1 -1
- package/out/types/src/value-tag.d.ts +0 -1
- package/out/types/src/value.d.ts +6 -13
- package/out/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/std/alg/hash.yo +13 -21
- package/std/allocator.yo +25 -40
- package/std/async.yo +3 -7
- package/std/build.yo +105 -151
- package/std/cli/arg_parser.yo +184 -169
- package/std/collections/array_list.yo +350 -314
- package/std/collections/btree_map.yo +142 -131
- package/std/collections/deque.yo +132 -128
- package/std/collections/hash_map.yo +542 -566
- package/std/collections/hash_set.yo +623 -687
- package/std/collections/linked_list.yo +275 -293
- package/std/collections/ordered_map.yo +113 -85
- package/std/collections/priority_queue.yo +73 -73
- package/std/crypto/md5.yo +191 -95
- package/std/crypto/random.yo +56 -64
- package/std/crypto/sha256.yo +151 -107
- package/std/encoding/base64.yo +87 -81
- package/std/encoding/hex.yo +43 -50
- package/std/encoding/html.yo +56 -81
- package/std/encoding/html_char_utils.yo +7 -13
- package/std/encoding/html_entities.yo +2248 -2253
- package/std/encoding/json.yo +316 -224
- package/std/encoding/punycode.yo +86 -116
- package/std/encoding/toml.yo +67 -66
- package/std/encoding/utf16.yo +37 -44
- package/std/env.yo +62 -91
- package/std/error.yo +12 -20
- package/std/fmt/display.yo +5 -9
- package/std/fmt/index.yo +8 -14
- package/std/fmt/to_string.yo +330 -315
- package/std/fmt/writer.yo +58 -87
- package/std/fs/dir.yo +83 -102
- package/std/fs/file.yo +147 -180
- package/std/fs/metadata.yo +45 -78
- package/std/fs/temp.yo +55 -65
- package/std/fs/types.yo +27 -40
- package/std/fs/walker.yo +53 -68
- package/std/gc.yo +5 -8
- package/std/glob.yo +30 -43
- package/std/http/client.yo +107 -120
- package/std/http/http.yo +106 -96
- package/std/http/index.yo +4 -6
- package/std/imm/list.yo +88 -93
- package/std/imm/map.yo +528 -464
- package/std/imm/set.yo +52 -57
- package/std/imm/sorted_map.yo +340 -286
- package/std/imm/sorted_set.yo +57 -63
- package/std/imm/string.yo +404 -345
- package/std/imm/vec.yo +173 -181
- package/std/io/reader.yo +3 -6
- package/std/io/writer.yo +4 -8
- package/std/libc/assert.yo +5 -9
- package/std/libc/ctype.yo +32 -22
- package/std/libc/dirent.yo +26 -25
- package/std/libc/errno.yo +164 -90
- package/std/libc/fcntl.yo +52 -45
- package/std/libc/float.yo +66 -44
- package/std/libc/limits.yo +42 -33
- package/std/libc/math.yo +53 -82
- package/std/libc/signal.yo +72 -47
- package/std/libc/stdatomic.yo +217 -188
- package/std/libc/stdint.yo +5 -29
- package/std/libc/stdio.yo +5 -29
- package/std/libc/stdlib.yo +32 -39
- package/std/libc/string.yo +5 -23
- package/std/libc/sys/stat.yo +58 -56
- package/std/libc/time.yo +5 -19
- package/std/libc/unistd.yo +5 -20
- package/std/libc/wctype.yo +6 -9
- package/std/libc/windows.yo +26 -30
- package/std/log.yo +41 -55
- package/std/net/addr.yo +102 -97
- package/std/net/dns.yo +27 -28
- package/std/net/errors.yo +50 -49
- package/std/net/tcp.yo +113 -124
- package/std/net/udp.yo +55 -66
- package/std/os/env.yo +35 -33
- package/std/os/signal.yo +15 -25
- package/std/path.yo +276 -311
- package/std/prelude.yo +6316 -4333
- package/std/process/command.yo +87 -103
- package/std/process/index.yo +12 -31
- package/std/regex/compiler.yo +196 -95
- package/std/regex/flags.yo +58 -39
- package/std/regex/index.yo +157 -173
- package/std/regex/match.yo +20 -31
- package/std/regex/node.yo +134 -152
- package/std/regex/parser.yo +283 -259
- package/std/regex/unicode.yo +172 -202
- package/std/regex/vm.yo +155 -171
- package/std/string/index.yo +5 -7
- package/std/string/rune.yo +45 -55
- package/std/string/string.yo +937 -964
- package/std/string/string_builder.yo +94 -104
- package/std/string/unicode.yo +46 -64
- package/std/sync/channel.yo +72 -73
- package/std/sync/cond.yo +31 -36
- package/std/sync/mutex.yo +30 -32
- package/std/sync/once.yo +13 -16
- package/std/sync/rwlock.yo +26 -31
- package/std/sync/waitgroup.yo +20 -25
- package/std/sys/advise.yo +16 -24
- package/std/sys/bufio/buf_reader.yo +77 -93
- package/std/sys/bufio/buf_writer.yo +52 -65
- package/std/sys/clock.yo +4 -9
- package/std/sys/constants.yo +77 -61
- package/std/sys/copy.yo +4 -10
- package/std/sys/dir.yo +26 -43
- package/std/sys/dns.yo +41 -61
- package/std/sys/errors.yo +95 -103
- package/std/sys/events.yo +45 -57
- package/std/sys/externs.yo +319 -267
- package/std/sys/fallocate.yo +7 -11
- package/std/sys/fcntl.yo +14 -22
- package/std/sys/file.yo +26 -40
- package/std/sys/future.yo +5 -8
- package/std/sys/iov.yo +12 -25
- package/std/sys/lock.yo +12 -13
- package/std/sys/mmap.yo +38 -43
- package/std/sys/path.yo +3 -8
- package/std/sys/perm.yo +7 -21
- package/std/sys/pipe.yo +5 -12
- package/std/sys/process.yo +23 -29
- package/std/sys/seek.yo +10 -12
- package/std/sys/signal.yo +7 -13
- package/std/sys/signals.yo +52 -35
- package/std/sys/socket.yo +63 -58
- package/std/sys/socketpair.yo +3 -6
- package/std/sys/sockinfo.yo +11 -20
- package/std/sys/statfs.yo +11 -34
- package/std/sys/statx.yo +25 -52
- package/std/sys/sysinfo.yo +15 -20
- package/std/sys/tcp.yo +62 -92
- package/std/sys/temp.yo +5 -9
- package/std/sys/time.yo +5 -15
- package/std/sys/timer.yo +6 -11
- package/std/sys/tty.yo +10 -18
- package/std/sys/udp.yo +22 -39
- package/std/sys/umask.yo +3 -6
- package/std/sys/unix.yo +33 -52
- package/std/testing/bench.yo +49 -52
- package/std/thread.yo +10 -15
- package/std/time/datetime.yo +105 -89
- package/std/time/duration.yo +43 -56
- package/std/time/instant.yo +13 -18
- package/std/time/sleep.yo +5 -9
- package/std/url/index.yo +184 -209
- package/std/worker.yo +6 -10
- package/out/types/src/evaluator/calls/module-type.d.ts +0 -11
- package/out/types/src/evaluator/types/module.d.ts +0 -19
package/std/sys/constants.yo
CHANGED
|
@@ -3,22 +3,15 @@
|
|
|
3
3
|
//! File mode bits, permission bits, `AT_*` flags, open flags,
|
|
4
4
|
//! access mode constants, copyfile flags, directory entry types,
|
|
5
5
|
//! and default permission modes.
|
|
6
|
-
|
|
7
|
-
{ platform, Platform } :: import "../process";
|
|
8
|
-
|
|
6
|
+
{ platform, Platform } :: import("../process");
|
|
9
7
|
// Import platform-correct open flags from libc
|
|
10
|
-
{
|
|
11
|
-
O_RDONLY, O_WRONLY, O_RDWR, O_CREAT, O_EXCL, O_TRUNC, O_APPEND,
|
|
12
|
-
O_NONBLOCK, O_CLOEXEC, O_DIRECTORY
|
|
13
|
-
} :: import "../libc/fcntl";
|
|
14
|
-
|
|
8
|
+
{ O_RDONLY, O_WRONLY, O_RDWR, O_CREAT, O_EXCL, O_TRUNC, O_APPEND, O_NONBLOCK, O_CLOEXEC, O_DIRECTORY } :: import("../libc/fcntl");
|
|
15
9
|
// ============================================================================
|
|
16
10
|
// AT_* Flags
|
|
17
11
|
// ============================================================================
|
|
18
|
-
|
|
19
12
|
AT_FDCWD :: cond(
|
|
20
|
-
(platform == Platform.Macos) => i32(-2),
|
|
21
|
-
true => i32(-100)
|
|
13
|
+
(platform == Platform.Macos) => i32(-(2)),
|
|
14
|
+
true => i32(-(100))
|
|
22
15
|
);
|
|
23
16
|
AT_REMOVEDIR :: cond(
|
|
24
17
|
(platform == Platform.Macos) => i32(0x80),
|
|
@@ -30,27 +23,22 @@ AT_SYMLINK_NOFOLLOW :: cond(
|
|
|
30
23
|
true => i32(0x100)
|
|
31
24
|
);
|
|
32
25
|
AT_STATX_SYNC_AS_STAT :: i32(0x0000);
|
|
33
|
-
|
|
34
26
|
// STATX_BASIC_STATS - request basic stats (Linux-specific)
|
|
35
27
|
STATX_BASIC_STATS :: u32(0x000007ff);
|
|
36
|
-
|
|
37
28
|
// ============================================================================
|
|
38
29
|
// File Mode Bits (S_IF* and S_I* from sys/stat.h)
|
|
39
30
|
// ============================================================================
|
|
40
|
-
|
|
41
|
-
S_IFMT :: u32(0o170000);
|
|
31
|
+
S_IFMT :: u32(0o170000);
|
|
42
32
|
S_IFSOCK :: u32(0o140000);
|
|
43
|
-
S_IFLNK
|
|
44
|
-
S_IFREG
|
|
45
|
-
S_IFBLK
|
|
46
|
-
S_IFDIR
|
|
47
|
-
S_IFCHR
|
|
48
|
-
S_IFIFO
|
|
49
|
-
|
|
33
|
+
S_IFLNK :: u32(0o120000);
|
|
34
|
+
S_IFREG :: u32(0o100000);
|
|
35
|
+
S_IFBLK :: u32(0o060000);
|
|
36
|
+
S_IFDIR :: u32(0o040000);
|
|
37
|
+
S_IFCHR :: u32(0o020000);
|
|
38
|
+
S_IFIFO :: u32(0o010000);
|
|
50
39
|
// ============================================================================
|
|
51
40
|
// Permission Bits
|
|
52
41
|
// ============================================================================
|
|
53
|
-
|
|
54
42
|
S_IRWXU :: u32(0o0700);
|
|
55
43
|
S_IRUSR :: u32(0o0400);
|
|
56
44
|
S_IWUSR :: u32(0o0200);
|
|
@@ -63,66 +51,94 @@ S_IRWXO :: u32(0o0007);
|
|
|
63
51
|
S_IROTH :: u32(0o0004);
|
|
64
52
|
S_IWOTH :: u32(0o0002);
|
|
65
53
|
S_IXOTH :: u32(0o0001);
|
|
66
|
-
|
|
67
54
|
// Default permissions
|
|
68
55
|
DEFAULT_FILE_MODE :: u32(0o644);
|
|
69
|
-
DEFAULT_DIR_MODE
|
|
70
|
-
|
|
56
|
+
DEFAULT_DIR_MODE :: u32(0o755);
|
|
71
57
|
// ============================================================================
|
|
72
58
|
// Directory Entry Types (DT_*)
|
|
73
59
|
// ============================================================================
|
|
74
|
-
|
|
75
60
|
DT_UNKNOWN :: u8(0);
|
|
76
|
-
DT_FIFO
|
|
77
|
-
DT_CHR
|
|
78
|
-
DT_DIR
|
|
79
|
-
DT_BLK
|
|
80
|
-
DT_REG
|
|
81
|
-
DT_LNK
|
|
82
|
-
DT_SOCK
|
|
83
|
-
DT_WHT
|
|
84
|
-
|
|
61
|
+
DT_FIFO :: u8(1);
|
|
62
|
+
DT_CHR :: u8(2);
|
|
63
|
+
DT_DIR :: u8(4);
|
|
64
|
+
DT_BLK :: u8(6);
|
|
65
|
+
DT_REG :: u8(8);
|
|
66
|
+
DT_LNK :: u8(10);
|
|
67
|
+
DT_SOCK :: u8(12);
|
|
68
|
+
DT_WHT :: u8(14);
|
|
85
69
|
// ============================================================================
|
|
86
70
|
// Access Mode Constants (for access/faccessat)
|
|
87
71
|
// ============================================================================
|
|
88
|
-
|
|
89
72
|
F_OK :: i32(0);
|
|
90
73
|
R_OK :: i32(4);
|
|
91
74
|
W_OK :: i32(2);
|
|
92
75
|
X_OK :: i32(1);
|
|
93
|
-
|
|
94
76
|
// ============================================================================
|
|
95
77
|
// Copyfile Flags
|
|
96
78
|
// ============================================================================
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
COPYFILE_FICLONE :: i32(2);
|
|
79
|
+
COPYFILE_EXCL :: i32(1);
|
|
80
|
+
COPYFILE_FICLONE :: i32(2);
|
|
100
81
|
COPYFILE_FICLONE_FORCE :: i32(4);
|
|
101
|
-
|
|
102
|
-
export
|
|
82
|
+
export(
|
|
103
83
|
// Open flags (re-exported from libc)
|
|
104
|
-
O_RDONLY,
|
|
105
|
-
|
|
106
|
-
|
|
84
|
+
O_RDONLY,
|
|
85
|
+
O_WRONLY,
|
|
86
|
+
O_RDWR,
|
|
87
|
+
O_CREAT,
|
|
88
|
+
O_EXCL,
|
|
89
|
+
O_TRUNC,
|
|
90
|
+
O_APPEND,
|
|
91
|
+
O_NONBLOCK,
|
|
92
|
+
O_CLOEXEC,
|
|
93
|
+
O_DIRECTORY,
|
|
107
94
|
// AT_* flags
|
|
108
|
-
AT_FDCWD,
|
|
95
|
+
AT_FDCWD,
|
|
96
|
+
AT_REMOVEDIR,
|
|
97
|
+
AT_EMPTY_PATH,
|
|
98
|
+
AT_SYMLINK_NOFOLLOW,
|
|
99
|
+
AT_STATX_SYNC_AS_STAT,
|
|
109
100
|
STATX_BASIC_STATS,
|
|
110
|
-
|
|
111
101
|
// File type flags (S_IF*)
|
|
112
|
-
S_IFMT,
|
|
113
|
-
|
|
102
|
+
S_IFMT,
|
|
103
|
+
S_IFSOCK,
|
|
104
|
+
S_IFLNK,
|
|
105
|
+
S_IFREG,
|
|
106
|
+
S_IFBLK,
|
|
107
|
+
S_IFDIR,
|
|
108
|
+
S_IFCHR,
|
|
109
|
+
S_IFIFO,
|
|
114
110
|
// Permission flags (S_I*)
|
|
115
|
-
S_IRWXU,
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
111
|
+
S_IRWXU,
|
|
112
|
+
S_IRUSR,
|
|
113
|
+
S_IWUSR,
|
|
114
|
+
S_IXUSR,
|
|
115
|
+
S_IRWXG,
|
|
116
|
+
S_IRGRP,
|
|
117
|
+
S_IWGRP,
|
|
118
|
+
S_IXGRP,
|
|
119
|
+
S_IRWXO,
|
|
120
|
+
S_IROTH,
|
|
121
|
+
S_IWOTH,
|
|
122
|
+
S_IXOTH,
|
|
123
|
+
DEFAULT_FILE_MODE,
|
|
124
|
+
DEFAULT_DIR_MODE,
|
|
120
125
|
// Directory entry types (DT_*)
|
|
121
|
-
DT_UNKNOWN,
|
|
122
|
-
|
|
126
|
+
DT_UNKNOWN,
|
|
127
|
+
DT_FIFO,
|
|
128
|
+
DT_CHR,
|
|
129
|
+
DT_DIR,
|
|
130
|
+
DT_BLK,
|
|
131
|
+
DT_REG,
|
|
132
|
+
DT_LNK,
|
|
133
|
+
DT_SOCK,
|
|
134
|
+
DT_WHT,
|
|
123
135
|
// Access mode constants
|
|
124
|
-
F_OK,
|
|
125
|
-
|
|
136
|
+
F_OK,
|
|
137
|
+
R_OK,
|
|
138
|
+
W_OK,
|
|
139
|
+
X_OK,
|
|
126
140
|
// Copyfile flags
|
|
127
|
-
COPYFILE_EXCL,
|
|
128
|
-
|
|
141
|
+
COPYFILE_EXCL,
|
|
142
|
+
COPYFILE_FICLONE,
|
|
143
|
+
COPYFILE_FICLONE_FORCE
|
|
144
|
+
);
|
package/std/sys/copy.yo
CHANGED
|
@@ -7,22 +7,16 @@
|
|
|
7
7
|
//!
|
|
8
8
|
//! - `copyfile`: 0 on success, -errno on failure
|
|
9
9
|
//! - `sendfile`: bytes transferred on success, -errno on failure
|
|
10
|
-
|
|
11
|
-
{ __yo_sync_copyfile, __yo_sync_sendfile } :: import "./externs.yo";
|
|
12
|
-
|
|
10
|
+
{ __yo_sync_copyfile, __yo_sync_sendfile } :: import("./externs.yo");
|
|
13
11
|
// Copy a file using kernel-accelerated copy.
|
|
14
12
|
// flags: 0 = default, 1 = COPYFILE_EXCL (fail if dst exists)
|
|
15
13
|
// Returns 0 on success, -errno on failure.
|
|
16
|
-
copyfile :: (fn(src: *(u8), dst: *(u8), flags: i32) -> i32)(
|
|
14
|
+
copyfile :: (fn(src : *(u8), dst : *(u8), flags : i32) -> i32)(
|
|
17
15
|
__yo_sync_copyfile(src, dst, flags)
|
|
18
16
|
);
|
|
19
|
-
|
|
20
17
|
// Transfer data between file descriptors (zero-copy when possible).
|
|
21
18
|
// Returns bytes transferred on success, -errno on failure.
|
|
22
|
-
sendfile :: (fn(out_fd: i32, in_fd: i32, offset: i64, count: usize) -> i32)(
|
|
19
|
+
sendfile :: (fn(out_fd : i32, in_fd : i32, offset : i64, count : usize) -> i32)(
|
|
23
20
|
__yo_sync_sendfile(out_fd, in_fd, offset, count)
|
|
24
21
|
);
|
|
25
|
-
|
|
26
|
-
export
|
|
27
|
-
copyfile, sendfile
|
|
28
|
-
;
|
|
22
|
+
export(copyfile, sendfile);
|
package/std/sys/dir.yo
CHANGED
|
@@ -20,63 +20,45 @@
|
|
|
20
20
|
// result := await mkdir(AT_FDCWD, *(u8)("/tmp/yo_test_dir"), i32(0o755));
|
|
21
21
|
// assert(result == i32(0));
|
|
22
22
|
// };
|
|
23
|
-
|
|
24
|
-
{
|
|
25
|
-
{
|
|
26
|
-
__yo_async_mkdirat_start, __yo_async_unlinkat_start,
|
|
27
|
-
__yo_async_renameat_start, __yo_async_symlinkat_start,
|
|
28
|
-
__yo_async_linkat_start,
|
|
29
|
-
__yo_sync_readlinkat,
|
|
30
|
-
__yo_async_getdents_start,
|
|
31
|
-
__yo_dirent_size, __yo_dirent_reclen, __yo_dirent_type,
|
|
32
|
-
__yo_dirent_name, __yo_dirent_ino
|
|
33
|
-
} :: import "./externs.yo";
|
|
34
|
-
|
|
23
|
+
{ IOFuture } :: import("./future.yo");
|
|
24
|
+
{ __yo_async_mkdirat_start, __yo_async_unlinkat_start, __yo_async_renameat_start, __yo_async_symlinkat_start, __yo_async_linkat_start, __yo_sync_readlinkat, __yo_async_getdents_start, __yo_dirent_size, __yo_dirent_reclen, __yo_dirent_type, __yo_dirent_name, __yo_dirent_ino } :: import("./externs.yo");
|
|
35
25
|
// ============================================================================
|
|
36
26
|
// Async Directory Operations (return IOFuture, use with await)
|
|
37
27
|
// ============================================================================
|
|
38
|
-
|
|
39
28
|
// Create a directory relative to dirfd. Use AT_FDCWD for current directory.
|
|
40
29
|
// Returns 0 on success, -errno on failure.
|
|
41
|
-
mkdir :: (fn(dirfd: i32, path: *(u8), mode: i32) -> IOFuture)(
|
|
30
|
+
mkdir :: (fn(dirfd : i32, path : *(u8), mode : i32) -> IOFuture)(
|
|
42
31
|
__yo_async_mkdirat_start(dirfd, path, mode)
|
|
43
32
|
);
|
|
44
|
-
|
|
45
33
|
// Remove a file or directory relative to dirfd.
|
|
46
34
|
// Use flags=0 for files, flags=AT_REMOVEDIR (0x200) for directories.
|
|
47
35
|
// Returns 0 on success, -errno on failure.
|
|
48
|
-
unlink :: (fn(dirfd: i32, path: *(u8), flags: i32) -> IOFuture)(
|
|
36
|
+
unlink :: (fn(dirfd : i32, path : *(u8), flags : i32) -> IOFuture)(
|
|
49
37
|
__yo_async_unlinkat_start(dirfd, path, flags)
|
|
50
38
|
);
|
|
51
|
-
|
|
52
39
|
// Rename/move a file or directory.
|
|
53
40
|
// Returns 0 on success, -errno on failure.
|
|
54
|
-
rename :: (fn(olddirfd: i32, oldpath: *(u8), newdirfd: i32, newpath: *(u8)) -> IOFuture)(
|
|
41
|
+
rename :: (fn(olddirfd : i32, oldpath : *(u8), newdirfd : i32, newpath : *(u8)) -> IOFuture)(
|
|
55
42
|
__yo_async_renameat_start(olddirfd, oldpath, newdirfd, newpath)
|
|
56
43
|
);
|
|
57
|
-
|
|
58
44
|
// Create a symbolic link at linkpath pointing to target.
|
|
59
45
|
// Returns 0 on success, -errno on failure.
|
|
60
|
-
symlink :: (fn(target: *(u8), newdirfd: i32, linkpath: *(u8)) -> IOFuture)(
|
|
46
|
+
symlink :: (fn(target : *(u8), newdirfd : i32, linkpath : *(u8)) -> IOFuture)(
|
|
61
47
|
__yo_async_symlinkat_start(target, newdirfd, linkpath)
|
|
62
48
|
);
|
|
63
|
-
|
|
64
49
|
// Create a hard link from oldpath to newpath.
|
|
65
50
|
// Returns 0 on success, -errno on failure.
|
|
66
|
-
link :: (fn(olddirfd: i32, oldpath: *(u8), newdirfd: i32, newpath: *(u8), flags: i32) -> IOFuture)(
|
|
51
|
+
link :: (fn(olddirfd : i32, oldpath : *(u8), newdirfd : i32, newpath : *(u8), flags : i32) -> IOFuture)(
|
|
67
52
|
__yo_async_linkat_start(olddirfd, oldpath, newdirfd, newpath, flags)
|
|
68
53
|
);
|
|
69
|
-
|
|
70
54
|
// Read the target of a symbolic link into buf.
|
|
71
55
|
// Returns number of bytes read on success, -errno on failure.
|
|
72
|
-
readlink :: (fn(dirfd: i32, path: *(u8), buf: *(u8), bufsize: usize) -> i32)(
|
|
56
|
+
readlink :: (fn(dirfd : i32, path : *(u8), buf : *(u8), bufsize : usize) -> i32)(
|
|
73
57
|
__yo_sync_readlinkat(dirfd, path, buf, bufsize)
|
|
74
58
|
);
|
|
75
|
-
|
|
76
59
|
// ============================================================================
|
|
77
60
|
// Directory Listing
|
|
78
61
|
// ============================================================================
|
|
79
|
-
|
|
80
62
|
// Read directory entries from an open directory fd into buf.
|
|
81
63
|
// The fd should be opened with O_RDONLY | O_DIRECTORY.
|
|
82
64
|
// Returns the number of bytes read into buf on success (0 means end of directory).
|
|
@@ -111,43 +93,44 @@ readlink :: (fn(dirfd: i32, path: *(u8), buf: *(u8), bufsize: usize) -> i32)(
|
|
|
111
93
|
// free(.Some(*(void)(buf)));
|
|
112
94
|
// await close(fd);
|
|
113
95
|
// };
|
|
114
|
-
getdents :: (fn(fd: i32, buf: *(u8), buf_size: u32) -> IOFuture)(
|
|
96
|
+
getdents :: (fn(fd : i32, buf : *(u8), buf_size : u32) -> IOFuture)(
|
|
115
97
|
__yo_async_getdents_start(fd, buf, buf_size)
|
|
116
98
|
);
|
|
117
|
-
|
|
118
99
|
// ============================================================================
|
|
119
100
|
// Directory Entry Accessor Functions
|
|
120
101
|
// ============================================================================
|
|
121
|
-
|
|
122
102
|
// Get the size of a struct dirent (for buffer allocation).
|
|
123
103
|
dirent_size :: (fn() -> usize)(
|
|
124
104
|
__yo_dirent_size()
|
|
125
105
|
);
|
|
126
|
-
|
|
127
106
|
// Get the record length of a directory entry (used to advance to next entry).
|
|
128
|
-
dirent_reclen :: (fn(entry: *(u8)) -> u16)(
|
|
107
|
+
dirent_reclen :: (fn(entry : *(u8)) -> u16)(
|
|
129
108
|
__yo_dirent_reclen(entry)
|
|
130
109
|
);
|
|
131
|
-
|
|
132
110
|
// Get the file type of a directory entry (DT_REG, DT_DIR, etc).
|
|
133
111
|
// Returns DT_UNKNOWN (0) if not available on the platform.
|
|
134
|
-
dirent_type :: (fn(entry: *(u8)) -> u8)(
|
|
112
|
+
dirent_type :: (fn(entry : *(u8)) -> u8)(
|
|
135
113
|
__yo_dirent_type(entry)
|
|
136
114
|
);
|
|
137
|
-
|
|
138
115
|
// Get the name of a directory entry as a null-terminated C string.
|
|
139
|
-
dirent_name :: (fn(entry: *(u8)) -> *(u8))(
|
|
116
|
+
dirent_name :: (fn(entry : *(u8)) -> *(u8))(
|
|
140
117
|
__yo_dirent_name(entry)
|
|
141
118
|
);
|
|
142
|
-
|
|
143
119
|
// Get the inode number of a directory entry.
|
|
144
|
-
dirent_ino :: (fn(entry: *(u8)) -> u64)(
|
|
120
|
+
dirent_ino :: (fn(entry : *(u8)) -> u64)(
|
|
145
121
|
__yo_dirent_ino(entry)
|
|
146
122
|
);
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
123
|
+
export(
|
|
124
|
+
mkdir,
|
|
125
|
+
unlink,
|
|
126
|
+
rename,
|
|
127
|
+
symlink,
|
|
128
|
+
link,
|
|
129
|
+
readlink,
|
|
151
130
|
getdents,
|
|
152
|
-
dirent_size,
|
|
153
|
-
|
|
131
|
+
dirent_size,
|
|
132
|
+
dirent_reclen,
|
|
133
|
+
dirent_type,
|
|
134
|
+
dirent_name,
|
|
135
|
+
dirent_ino
|
|
136
|
+
);
|
package/std/sys/dns.yo
CHANGED
|
@@ -36,22 +36,13 @@
|
|
|
36
36
|
// );
|
|
37
37
|
// dns.free_result(result_ptr);
|
|
38
38
|
// };
|
|
39
|
-
|
|
40
|
-
{ GlobalAllocator } :: import "../allocator";
|
|
39
|
+
{ GlobalAllocator } :: import("../allocator");
|
|
41
40
|
{ malloc, free } :: GlobalAllocator;
|
|
42
|
-
{ IOFuture } :: import
|
|
43
|
-
{
|
|
44
|
-
__yo_async_getaddrinfo_start, __yo_async_getnameinfo_start,
|
|
45
|
-
__yo_freeaddrinfo,
|
|
46
|
-
__yo_addrinfo_size, __yo_addrinfo_flags, __yo_addrinfo_family,
|
|
47
|
-
__yo_addrinfo_socktype, __yo_addrinfo_protocol, __yo_addrinfo_addrlen,
|
|
48
|
-
__yo_addrinfo_addr, __yo_addrinfo_canonname, __yo_addrinfo_next
|
|
49
|
-
} :: import "./externs.yo";
|
|
50
|
-
|
|
41
|
+
{ IOFuture } :: import("./future.yo");
|
|
42
|
+
{ __yo_async_getaddrinfo_start, __yo_async_getnameinfo_start, __yo_freeaddrinfo, __yo_addrinfo_size, __yo_addrinfo_flags, __yo_addrinfo_family, __yo_addrinfo_socktype, __yo_addrinfo_protocol, __yo_addrinfo_addrlen, __yo_addrinfo_addr, __yo_addrinfo_canonname, __yo_addrinfo_next } :: import("./externs.yo");
|
|
51
43
|
// ============================================================================
|
|
52
44
|
// DNS Resolution (return IOFuture, use with await)
|
|
53
45
|
// ============================================================================
|
|
54
|
-
|
|
55
46
|
// Resolve hostname to a linked list of addrinfo results.
|
|
56
47
|
// node: hostname or IP string (e.g. "localhost", "example.com")
|
|
57
48
|
// service: service name or port string (e.g. "http", "80"), or .None
|
|
@@ -59,10 +50,9 @@
|
|
|
59
50
|
// result: pointer to a ?*(u8) that will receive the head of the result list
|
|
60
51
|
// Returns 0 on success, non-zero gai_error on failure.
|
|
61
52
|
// Caller must call freeaddrinfo() on the result when done.
|
|
62
|
-
getaddrinfo :: (fn(node: *(u8), service: ?*(u8), hints: ?*(u8), result: *(?*(u8))) -> IOFuture)(
|
|
53
|
+
getaddrinfo :: (fn(node : *(u8), service : ?*(u8), hints : ?*(u8), result : *(?*(u8))) -> IOFuture)(
|
|
63
54
|
__yo_async_getaddrinfo_start(node, service, hints, result)
|
|
64
55
|
);
|
|
65
|
-
|
|
66
56
|
// Reverse lookup: convert a socket address to hostname and service strings.
|
|
67
57
|
// addr: pointer to sockaddr buffer
|
|
68
58
|
// addrlen: size of the sockaddr
|
|
@@ -72,117 +62,107 @@ getaddrinfo :: (fn(node: *(u8), service: ?*(u8), hints: ?*(u8), result: *(?*(u8)
|
|
|
72
62
|
// servlen: size of service buffer
|
|
73
63
|
// flags: NI_NUMERICHOST, NI_NUMERICSERV, etc.
|
|
74
64
|
// Returns 0 on success, -gai_error on failure.
|
|
75
|
-
getnameinfo :: (fn(addr: *(u8), addrlen: u32, host: *(u8), hostlen: usize, service: *(u8), servlen: usize, flags: i32) -> IOFuture)(
|
|
65
|
+
getnameinfo :: (fn(addr : *(u8), addrlen : u32, host : *(u8), hostlen : usize, service : *(u8), servlen : usize, flags : i32) -> IOFuture)(
|
|
76
66
|
__yo_async_getnameinfo_start(addr, addrlen, host, hostlen, service, servlen, flags)
|
|
77
67
|
);
|
|
78
|
-
|
|
79
68
|
// Free an addrinfo result list returned by getaddrinfo.
|
|
80
|
-
freeaddrinfo :: (fn(res: *(u8)) -> unit)(
|
|
69
|
+
freeaddrinfo :: (fn(res : *(u8)) -> unit)(
|
|
81
70
|
__yo_freeaddrinfo(res)
|
|
82
71
|
);
|
|
83
|
-
|
|
84
72
|
// ============================================================================
|
|
85
73
|
// Result Pointer Helpers
|
|
86
74
|
// ============================================================================
|
|
87
|
-
|
|
88
75
|
// Allocate a *(?*(u8)) to hold the getaddrinfo result pointer.
|
|
89
76
|
// Initialized to .None. Caller must free with free_result() after use.
|
|
90
|
-
alloc_result :: (fn() -> *(?*(u8)))
|
|
77
|
+
alloc_result :: (fn() -> *(?*(u8)))({
|
|
91
78
|
ptr := *(?*(u8))(malloc(usize(8)).unwrap());
|
|
92
|
-
ptr.*
|
|
79
|
+
ptr.* =.None;
|
|
93
80
|
ptr
|
|
94
|
-
};
|
|
95
|
-
|
|
81
|
+
});
|
|
96
82
|
// Read the addrinfo head pointer from the result slot.
|
|
97
83
|
// Returns .Some(ai) if the result is non-null, .None otherwise.
|
|
98
|
-
get_result :: (fn(result: *(?*(u8))) -> ?*(u8))(
|
|
84
|
+
get_result :: (fn(result : *(?*(u8))) -> ?*(u8))(
|
|
99
85
|
result.*
|
|
100
86
|
);
|
|
101
|
-
|
|
102
87
|
// Free the result pointer slot (not the addrinfo list itself).
|
|
103
|
-
free_result :: (fn(result: *(?*(u8))) -> unit)(
|
|
88
|
+
free_result :: (fn(result : *(?*(u8))) -> unit)(
|
|
104
89
|
free(.Some(*(void)(result)))
|
|
105
90
|
);
|
|
106
|
-
|
|
107
91
|
// ============================================================================
|
|
108
92
|
// Addrinfo Accessors (for iterating the linked list)
|
|
109
93
|
// ============================================================================
|
|
110
|
-
|
|
111
94
|
// Get the size of a C struct addrinfo (useful for hints allocation).
|
|
112
95
|
addrinfo_size :: (fn() -> usize)(
|
|
113
96
|
__yo_addrinfo_size()
|
|
114
97
|
);
|
|
115
|
-
|
|
116
98
|
// Get the ai_flags field.
|
|
117
|
-
addrinfo_flags :: (fn(ai: *(u8)) -> i32)(
|
|
99
|
+
addrinfo_flags :: (fn(ai : *(u8)) -> i32)(
|
|
118
100
|
__yo_addrinfo_flags(ai)
|
|
119
101
|
);
|
|
120
|
-
|
|
121
102
|
// Get the ai_family field (AF_INET, AF_INET6, etc.).
|
|
122
|
-
addrinfo_family :: (fn(ai: *(u8)) -> i32)(
|
|
103
|
+
addrinfo_family :: (fn(ai : *(u8)) -> i32)(
|
|
123
104
|
__yo_addrinfo_family(ai)
|
|
124
105
|
);
|
|
125
|
-
|
|
126
106
|
// Get the ai_socktype field (SOCK_STREAM, SOCK_DGRAM, etc.).
|
|
127
|
-
addrinfo_socktype :: (fn(ai: *(u8)) -> i32)(
|
|
107
|
+
addrinfo_socktype :: (fn(ai : *(u8)) -> i32)(
|
|
128
108
|
__yo_addrinfo_socktype(ai)
|
|
129
109
|
);
|
|
130
|
-
|
|
131
110
|
// Get the ai_protocol field.
|
|
132
|
-
addrinfo_protocol :: (fn(ai: *(u8)) -> i32)(
|
|
111
|
+
addrinfo_protocol :: (fn(ai : *(u8)) -> i32)(
|
|
133
112
|
__yo_addrinfo_protocol(ai)
|
|
134
113
|
);
|
|
135
|
-
|
|
136
114
|
// Get the ai_addrlen field.
|
|
137
|
-
addrinfo_addrlen :: (fn(ai: *(u8)) -> u32)(
|
|
115
|
+
addrinfo_addrlen :: (fn(ai : *(u8)) -> u32)(
|
|
138
116
|
__yo_addrinfo_addrlen(ai)
|
|
139
117
|
);
|
|
140
|
-
|
|
141
118
|
// Get the ai_addr pointer (sockaddr buffer, always non-null in valid results).
|
|
142
|
-
addrinfo_addr :: (fn(ai: *(u8)) -> *(u8))(
|
|
119
|
+
addrinfo_addr :: (fn(ai : *(u8)) -> *(u8))(
|
|
143
120
|
__yo_addrinfo_addr(ai)
|
|
144
121
|
);
|
|
145
|
-
|
|
146
122
|
// Get the ai_canonname string (may be .None).
|
|
147
|
-
addrinfo_canonname :: (fn(ai: *(u8)) -> ?*(u8))(
|
|
123
|
+
addrinfo_canonname :: (fn(ai : *(u8)) -> ?*(u8))(
|
|
148
124
|
__yo_addrinfo_canonname(ai)
|
|
149
125
|
);
|
|
150
|
-
|
|
151
126
|
// Get the next addrinfo in the linked list (.None if end of list).
|
|
152
|
-
addrinfo_next :: (fn(ai: *(u8)) -> ?*(u8))(
|
|
127
|
+
addrinfo_next :: (fn(ai : *(u8)) -> ?*(u8))(
|
|
153
128
|
__yo_addrinfo_next(ai)
|
|
154
129
|
);
|
|
155
|
-
|
|
156
130
|
// ============================================================================
|
|
157
131
|
// Hints Helper
|
|
158
132
|
// ============================================================================
|
|
159
|
-
|
|
160
133
|
// Allocate and zero-initialize a hints struct for getaddrinfo.
|
|
161
134
|
// Set family, socktype, protocol, and flags as needed before passing to getaddrinfo.
|
|
162
135
|
// Caller must free with free_hints() after the getaddrinfo call.
|
|
163
|
-
alloc_hints :: (fn() -> *(u8))
|
|
136
|
+
alloc_hints :: (fn() -> *(u8))({
|
|
164
137
|
size := __yo_addrinfo_size();
|
|
165
138
|
ptr := *(u8)(malloc(size).unwrap());
|
|
166
139
|
i := usize(0);
|
|
167
|
-
while
|
|
140
|
+
while(i < size, {
|
|
168
141
|
(ptr &+ i).* = u8(0);
|
|
169
142
|
i = (i + usize(1));
|
|
170
|
-
};
|
|
143
|
+
});
|
|
171
144
|
ptr
|
|
172
|
-
};
|
|
173
|
-
|
|
145
|
+
});
|
|
174
146
|
// Free a hints buffer allocated with alloc_hints.
|
|
175
|
-
free_hints :: (fn(hints: *(u8)) -> unit)(
|
|
147
|
+
free_hints :: (fn(hints : *(u8)) -> unit)(
|
|
176
148
|
free(.Some(*(void)(hints)))
|
|
177
149
|
);
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
150
|
+
export(
|
|
151
|
+
getaddrinfo,
|
|
152
|
+
getnameinfo,
|
|
181
153
|
freeaddrinfo,
|
|
182
|
-
alloc_result,
|
|
154
|
+
alloc_result,
|
|
155
|
+
get_result,
|
|
156
|
+
free_result,
|
|
183
157
|
addrinfo_size,
|
|
184
|
-
addrinfo_flags,
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
158
|
+
addrinfo_flags,
|
|
159
|
+
addrinfo_family,
|
|
160
|
+
addrinfo_socktype,
|
|
161
|
+
addrinfo_protocol,
|
|
162
|
+
addrinfo_addrlen,
|
|
163
|
+
addrinfo_addr,
|
|
164
|
+
addrinfo_canonname,
|
|
165
|
+
addrinfo_next,
|
|
166
|
+
alloc_hints,
|
|
167
|
+
free_hints
|
|
168
|
+
);
|