@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/tcp.yo
CHANGED
|
@@ -33,224 +33,194 @@
|
|
|
33
33
|
// client_fd := await tcp.accept(sockfd);
|
|
34
34
|
// // ...
|
|
35
35
|
// };
|
|
36
|
-
|
|
37
|
-
{ GlobalAllocator } :: import "../allocator.yo";
|
|
36
|
+
{ GlobalAllocator } :: import("../allocator.yo");
|
|
38
37
|
{ malloc, free } :: GlobalAllocator;
|
|
39
|
-
{ IOFuture } :: import
|
|
40
|
-
{
|
|
41
|
-
|
|
42
|
-
__yo_async_listen_start, __yo_async_accept_start,
|
|
43
|
-
__yo_async_connect_start, __yo_async_send_start,
|
|
44
|
-
__yo_async_recv_start, __yo_async_shutdown_start,
|
|
45
|
-
__yo_async_setsockopt_start, __yo_async_getsockopt_start,
|
|
46
|
-
__yo_async_close_start,
|
|
47
|
-
__yo_sockaddr_set_family, __yo_sockaddr_get_family,
|
|
48
|
-
__yo_sockaddr_in_set_port, __yo_sockaddr_in_get_port,
|
|
49
|
-
__yo_sockaddr_in_set_addr, __yo_sockaddr_in_get_addr,
|
|
50
|
-
__yo_sockaddr_in6_set_port, __yo_sockaddr_in6_get_port,
|
|
51
|
-
__yo_sockaddr_in6_set_addr, __yo_sockaddr_in6_get_addr,
|
|
52
|
-
__yo_inet_pton, __yo_inet_ntop,
|
|
53
|
-
__yo_htons, __yo_ntohs, __yo_htonl, __yo_ntohl
|
|
54
|
-
} :: import "./externs.yo";
|
|
55
|
-
{
|
|
56
|
-
AF_INET, AF_INET6, SOCK_STREAM,
|
|
57
|
-
sockaddr_in_size, sockaddr_in6_size
|
|
58
|
-
} :: import "./socket.yo";
|
|
59
|
-
|
|
38
|
+
{ IOFuture } :: import("./future.yo");
|
|
39
|
+
{ __yo_async_socket_start, __yo_async_bind_start, __yo_async_listen_start, __yo_async_accept_start, __yo_async_connect_start, __yo_async_send_start, __yo_async_recv_start, __yo_async_shutdown_start, __yo_async_setsockopt_start, __yo_async_getsockopt_start, __yo_async_close_start, __yo_sockaddr_set_family, __yo_sockaddr_get_family, __yo_sockaddr_in_set_port, __yo_sockaddr_in_get_port, __yo_sockaddr_in_set_addr, __yo_sockaddr_in_get_addr, __yo_sockaddr_in6_set_port, __yo_sockaddr_in6_get_port, __yo_sockaddr_in6_set_addr, __yo_sockaddr_in6_get_addr, __yo_inet_pton, __yo_inet_ntop, __yo_htons, __yo_ntohs, __yo_htonl, __yo_ntohl } :: import("./externs.yo");
|
|
40
|
+
{ AF_INET, AF_INET6, SOCK_STREAM, sockaddr_in_size, sockaddr_in6_size } :: import("./socket.yo");
|
|
60
41
|
// ============================================================================
|
|
61
42
|
// SockAddr - Socket address buffer with pointer and length
|
|
62
43
|
// ============================================================================
|
|
63
|
-
|
|
64
44
|
SockAddr :: struct(
|
|
65
45
|
buf : *(u8),
|
|
66
46
|
len : u32
|
|
67
47
|
);
|
|
68
|
-
export
|
|
69
|
-
|
|
48
|
+
export(SockAddr);
|
|
70
49
|
// ============================================================================
|
|
71
50
|
// Core TCP Operations (return IOFuture, use with await)
|
|
72
51
|
// ============================================================================
|
|
73
|
-
|
|
74
52
|
// Create a TCP socket.
|
|
75
53
|
// domain: AF_INET or AF_INET6
|
|
76
54
|
// Returns fd on success, -errno on failure.
|
|
77
|
-
socket :: (fn(domain: i32, sock_type: i32, protocol: i32) -> IOFuture)(
|
|
55
|
+
socket :: (fn(domain : i32, sock_type : i32, protocol : i32) -> IOFuture)(
|
|
78
56
|
__yo_async_socket_start(domain, sock_type, protocol)
|
|
79
57
|
);
|
|
80
|
-
|
|
81
58
|
// Bind a socket to a local address.
|
|
82
59
|
// Returns 0 on success, -errno on failure.
|
|
83
|
-
bind :: (fn(sockfd: i32, addr: *(u8), addrlen: u32) -> IOFuture)(
|
|
60
|
+
bind :: (fn(sockfd : i32, addr : *(u8), addrlen : u32) -> IOFuture)(
|
|
84
61
|
__yo_async_bind_start(sockfd, addr, addrlen)
|
|
85
62
|
);
|
|
86
|
-
|
|
87
63
|
// Listen for incoming connections on a socket.
|
|
88
64
|
// backlog: maximum length of the pending connections queue.
|
|
89
65
|
// Returns 0 on success, -errno on failure.
|
|
90
|
-
listen :: (fn(sockfd: i32, backlog: i32) -> IOFuture)(
|
|
66
|
+
listen :: (fn(sockfd : i32, backlog : i32) -> IOFuture)(
|
|
91
67
|
__yo_async_listen_start(sockfd, backlog)
|
|
92
68
|
);
|
|
93
|
-
|
|
94
69
|
// Accept an incoming connection on a listening socket.
|
|
95
70
|
// Returns the new connection fd on success, -errno on failure.
|
|
96
71
|
// addr/addrlen can be used to retrieve the peer address.
|
|
97
|
-
accept :: (fn(sockfd: i32, addr: *(u8), addrlen: *(u32)) -> IOFuture)(
|
|
72
|
+
accept :: (fn(sockfd : i32, addr : *(u8), addrlen : *(u32)) -> IOFuture)(
|
|
98
73
|
__yo_async_accept_start(sockfd, addr, addrlen)
|
|
99
74
|
);
|
|
100
|
-
|
|
101
75
|
// Connect to a remote address.
|
|
102
76
|
// Returns 0 on success, -errno on failure.
|
|
103
|
-
connect :: (fn(sockfd: i32, addr: *(u8), addrlen: u32) -> IOFuture)(
|
|
77
|
+
connect :: (fn(sockfd : i32, addr : *(u8), addrlen : u32) -> IOFuture)(
|
|
104
78
|
__yo_async_connect_start(sockfd, addr, addrlen)
|
|
105
79
|
);
|
|
106
|
-
|
|
107
80
|
// Send data on a connected socket.
|
|
108
81
|
// Returns number of bytes sent on success, -errno on failure.
|
|
109
|
-
send :: (fn(sockfd: i32, buf: *(u8), len: usize, flags: i32) -> IOFuture)(
|
|
82
|
+
send :: (fn(sockfd : i32, buf : *(u8), len : usize, flags : i32) -> IOFuture)(
|
|
110
83
|
__yo_async_send_start(sockfd, buf, len, flags)
|
|
111
84
|
);
|
|
112
|
-
|
|
113
85
|
// Receive data from a connected socket.
|
|
114
86
|
// Returns number of bytes received on success (0 = peer closed), -errno on failure.
|
|
115
|
-
recv :: (fn(sockfd: i32, buf: *(u8), len: usize, flags: i32) -> IOFuture)(
|
|
87
|
+
recv :: (fn(sockfd : i32, buf : *(u8), len : usize, flags : i32) -> IOFuture)(
|
|
116
88
|
__yo_async_recv_start(sockfd, buf, len, flags)
|
|
117
89
|
);
|
|
118
|
-
|
|
119
90
|
// Shut down part of a full-duplex connection.
|
|
120
91
|
// how: SHUT_RD (0), SHUT_WR (1), or SHUT_RDWR (2).
|
|
121
92
|
// Returns 0 on success, -errno on failure.
|
|
122
|
-
shutdown :: (fn(sockfd: i32, how: i32) -> IOFuture)(
|
|
93
|
+
shutdown :: (fn(sockfd : i32, how : i32) -> IOFuture)(
|
|
123
94
|
__yo_async_shutdown_start(sockfd, how)
|
|
124
95
|
);
|
|
125
|
-
|
|
126
96
|
// Close a socket file descriptor.
|
|
127
97
|
// Returns 0 on success, -errno on failure.
|
|
128
|
-
close :: (fn(fd: i32) -> IOFuture)(
|
|
98
|
+
close :: (fn(fd : i32) -> IOFuture)(
|
|
129
99
|
__yo_async_close_start(fd)
|
|
130
100
|
);
|
|
131
|
-
|
|
132
101
|
// ============================================================================
|
|
133
102
|
// Socket Options
|
|
134
103
|
// ============================================================================
|
|
135
|
-
|
|
136
104
|
// Set a socket option (raw).
|
|
137
105
|
// Returns 0 on success, -errno on failure.
|
|
138
|
-
setsockopt :: (fn(sockfd: i32, level: i32, optname: i32, optval: *(u8), optlen: u32) -> IOFuture)(
|
|
106
|
+
setsockopt :: (fn(sockfd : i32, level : i32, optname : i32, optval : *(u8), optlen : u32) -> IOFuture)(
|
|
139
107
|
__yo_async_setsockopt_start(sockfd, level, optname, optval, optlen)
|
|
140
108
|
);
|
|
141
|
-
|
|
142
109
|
// Get a socket option (raw).
|
|
143
110
|
// Returns 0 on success, -errno on failure.
|
|
144
|
-
getsockopt :: (fn(sockfd: i32, level: i32, optname: i32, optval: *(u8), optlen: *(u32)) -> IOFuture)(
|
|
111
|
+
getsockopt :: (fn(sockfd : i32, level : i32, optname : i32, optval : *(u8), optlen : *(u32)) -> IOFuture)(
|
|
145
112
|
__yo_async_getsockopt_start(sockfd, level, optname, optval, optlen)
|
|
146
113
|
);
|
|
147
|
-
|
|
148
114
|
// ============================================================================
|
|
149
115
|
// Socket Address Helpers
|
|
150
116
|
// ============================================================================
|
|
151
|
-
|
|
152
117
|
// Create an IPv4 socket address (sockaddr_in) from an IP string and port.
|
|
153
118
|
// The IP string must be a null-terminated C string (e.g. "127.0.0.1").
|
|
154
119
|
// Returns a SockAddr with an allocated buffer. Caller must free buf when done.
|
|
155
|
-
make_sockaddr_in :: (fn(ip: *(u8), port: u16) -> SockAddr)({
|
|
120
|
+
make_sockaddr_in :: (fn(ip : *(u8), port : u16) -> SockAddr)({
|
|
156
121
|
size := sockaddr_in_size();
|
|
157
122
|
buf := *(u8)(malloc(size).unwrap());
|
|
158
123
|
i := usize(0);
|
|
159
|
-
while
|
|
124
|
+
while(runtime(i < size), {
|
|
160
125
|
(buf &+ i).* = u8(0);
|
|
161
126
|
i = (i + usize(1));
|
|
162
|
-
};
|
|
127
|
+
});
|
|
163
128
|
__yo_sockaddr_set_family(buf, u16(AF_INET));
|
|
164
129
|
__yo_sockaddr_in_set_port(buf, port);
|
|
165
|
-
__yo_inet_pton(AF_INET, ip,
|
|
130
|
+
__yo_inet_pton(AF_INET, ip, buf &+ usize(4));
|
|
166
131
|
SockAddr(buf, u32(size))
|
|
167
132
|
});
|
|
168
|
-
|
|
169
133
|
// Create an IPv6 socket address (sockaddr_in6) from an IP string and port.
|
|
170
134
|
// The IP string must be a null-terminated C string (e.g. "::1").
|
|
171
135
|
// Returns a SockAddr with an allocated buffer. Caller must free buf when done.
|
|
172
|
-
make_sockaddr_in6 :: (fn(ip: *(u8), port: u16) -> SockAddr)({
|
|
136
|
+
make_sockaddr_in6 :: (fn(ip : *(u8), port : u16) -> SockAddr)({
|
|
173
137
|
size := sockaddr_in6_size();
|
|
174
138
|
buf := *(u8)(malloc(size).unwrap());
|
|
175
139
|
i := usize(0);
|
|
176
|
-
while
|
|
140
|
+
while(runtime(i < size), {
|
|
177
141
|
(buf &+ i).* = u8(0);
|
|
178
142
|
i = (i + usize(1));
|
|
179
|
-
};
|
|
143
|
+
});
|
|
180
144
|
__yo_sockaddr_set_family(buf, u16(AF_INET6));
|
|
181
145
|
__yo_sockaddr_in6_set_port(buf, port);
|
|
182
|
-
__yo_inet_pton(AF_INET6, ip,
|
|
146
|
+
__yo_inet_pton(AF_INET6, ip, buf &+ usize(8));
|
|
183
147
|
SockAddr(buf, u32(size))
|
|
184
148
|
});
|
|
185
|
-
|
|
186
149
|
// Create an IPv4 socket address for INADDR_ANY (0.0.0.0) with a given port.
|
|
187
150
|
// Returns a SockAddr with an allocated buffer. Caller must free buf when done.
|
|
188
|
-
make_sockaddr_in_any :: (fn(port: u16) -> SockAddr)({
|
|
151
|
+
make_sockaddr_in_any :: (fn(port : u16) -> SockAddr)({
|
|
189
152
|
size := sockaddr_in_size();
|
|
190
153
|
buf := *(u8)(malloc(size).unwrap());
|
|
191
154
|
i := usize(0);
|
|
192
|
-
while
|
|
155
|
+
while(runtime(i < size), {
|
|
193
156
|
(buf &+ i).* = u8(0);
|
|
194
157
|
i = (i + usize(1));
|
|
195
|
-
};
|
|
158
|
+
});
|
|
196
159
|
__yo_sockaddr_set_family(buf, u16(AF_INET));
|
|
197
160
|
__yo_sockaddr_in_set_port(buf, port);
|
|
198
161
|
__yo_sockaddr_in_set_addr(buf, u32(0));
|
|
199
162
|
SockAddr(buf, u32(size))
|
|
200
163
|
});
|
|
201
|
-
|
|
202
164
|
// Create an IPv4 socket address for loopback (127.0.0.1) with a given port.
|
|
203
165
|
// Returns a SockAddr with an allocated buffer. Caller must free buf when done.
|
|
204
|
-
make_sockaddr_in_loopback :: (fn(port: u16) -> SockAddr)({
|
|
166
|
+
make_sockaddr_in_loopback :: (fn(port : u16) -> SockAddr)({
|
|
205
167
|
size := sockaddr_in_size();
|
|
206
168
|
buf := *(u8)(malloc(size).unwrap());
|
|
207
169
|
i := usize(0);
|
|
208
|
-
while
|
|
170
|
+
while(runtime(i < size), {
|
|
209
171
|
(buf &+ i).* = u8(0);
|
|
210
172
|
i = (i + usize(1));
|
|
211
|
-
};
|
|
173
|
+
});
|
|
212
174
|
__yo_sockaddr_set_family(buf, u16(AF_INET));
|
|
213
175
|
__yo_sockaddr_in_set_port(buf, port);
|
|
214
176
|
__yo_sockaddr_in_set_addr(buf, __yo_htonl(u32(0x7F000001)));
|
|
215
177
|
SockAddr(buf, u32(size))
|
|
216
178
|
});
|
|
217
|
-
|
|
218
179
|
// Free a SockAddr buffer.
|
|
219
|
-
free_sockaddr :: (fn(addr: SockAddr) -> unit)(
|
|
180
|
+
free_sockaddr :: (fn(addr : SockAddr) -> unit)(
|
|
220
181
|
free(.Some(*(void)(addr.buf)))
|
|
221
182
|
);
|
|
222
|
-
|
|
223
183
|
// Get the port number from an IPv4 socket address buffer.
|
|
224
|
-
get_port_in :: (fn(addr: *(u8)) -> u16)(
|
|
184
|
+
get_port_in :: (fn(addr : *(u8)) -> u16)(
|
|
225
185
|
__yo_sockaddr_in_get_port(addr)
|
|
226
186
|
);
|
|
227
|
-
|
|
228
187
|
// Get the IPv4 address as a u32 from a socket address buffer.
|
|
229
|
-
get_addr_in :: (fn(addr: *(u8)) -> u32)(
|
|
188
|
+
get_addr_in :: (fn(addr : *(u8)) -> u32)(
|
|
230
189
|
__yo_sockaddr_in_get_addr(addr)
|
|
231
190
|
);
|
|
232
|
-
|
|
233
191
|
// Get the address family from a socket address buffer.
|
|
234
|
-
get_family :: (fn(addr: *(u8)) -> u16)(
|
|
192
|
+
get_family :: (fn(addr : *(u8)) -> u16)(
|
|
235
193
|
__yo_sockaddr_get_family(addr)
|
|
236
194
|
);
|
|
237
|
-
|
|
238
195
|
// ============================================================================
|
|
239
196
|
// Byte Order Helpers
|
|
240
197
|
// ============================================================================
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
198
|
+
htons :: (fn(hostshort : u16) -> u16)(__yo_htons(hostshort));
|
|
199
|
+
ntohs :: (fn(netshort : u16) -> u16)(__yo_ntohs(netshort));
|
|
200
|
+
htonl :: (fn(hostlong : u32) -> u32)(__yo_htonl(hostlong));
|
|
201
|
+
ntohl :: (fn(netlong : u32) -> u32)(__yo_ntohl(netlong));
|
|
202
|
+
export(
|
|
203
|
+
socket,
|
|
204
|
+
bind,
|
|
205
|
+
listen,
|
|
206
|
+
accept,
|
|
207
|
+
connect,
|
|
208
|
+
send,
|
|
209
|
+
recv,
|
|
210
|
+
shutdown,
|
|
211
|
+
close,
|
|
212
|
+
setsockopt,
|
|
213
|
+
getsockopt,
|
|
214
|
+
make_sockaddr_in,
|
|
215
|
+
make_sockaddr_in6,
|
|
216
|
+
make_sockaddr_in_any,
|
|
217
|
+
make_sockaddr_in_loopback,
|
|
253
218
|
free_sockaddr,
|
|
254
|
-
get_port_in,
|
|
255
|
-
|
|
256
|
-
|
|
219
|
+
get_port_in,
|
|
220
|
+
get_addr_in,
|
|
221
|
+
get_family,
|
|
222
|
+
htons,
|
|
223
|
+
ntohs,
|
|
224
|
+
htonl,
|
|
225
|
+
ntohl
|
|
226
|
+
);
|
package/std/sys/temp.yo
CHANGED
|
@@ -7,24 +7,20 @@
|
|
|
7
7
|
//!
|
|
8
8
|
//! - `mkdtemp`: 0 on success, -errno on failure
|
|
9
9
|
//! - `mkstemp`: fd on success, -errno on failure
|
|
10
|
-
|
|
11
|
-
{ __yo_sync_mkdtemp, __yo_sync_mkstemp } :: import "./externs.yo";
|
|
12
|
-
|
|
10
|
+
{ __yo_sync_mkdtemp, __yo_sync_mkstemp } :: import("./externs.yo");
|
|
13
11
|
// Create a temporary directory from template (e.g., "/tmp/myapp-XXXXXX").
|
|
14
12
|
// The template is modified in-place with the actual path.
|
|
15
13
|
// Returns 0 on success, -errno on failure.
|
|
16
|
-
mkdtemp :: (fn(template: *(u8)) -> i32)(
|
|
14
|
+
mkdtemp :: (fn(template : *(u8)) -> i32)(
|
|
17
15
|
__yo_sync_mkdtemp(template)
|
|
18
16
|
);
|
|
19
|
-
|
|
20
17
|
// Create a temporary file from template (e.g., "/tmp/myfile-XXXXXX").
|
|
21
18
|
// The template is modified in-place with the actual path.
|
|
22
19
|
// Returns fd on success, -errno on failure.
|
|
23
|
-
mkstemp :: (fn(template: *(u8)) -> i32)(
|
|
20
|
+
mkstemp :: (fn(template : *(u8)) -> i32)(
|
|
24
21
|
__yo_sync_mkstemp(template)
|
|
25
22
|
);
|
|
26
|
-
|
|
27
|
-
export
|
|
23
|
+
export(
|
|
28
24
|
mkdtemp,
|
|
29
25
|
mkstemp
|
|
30
|
-
;
|
|
26
|
+
);
|
package/std/sys/time.yo
CHANGED
|
@@ -21,49 +21,39 @@
|
|
|
21
21
|
// // Set timestamps on an open fd
|
|
22
22
|
// ret2 := time.futime(fd, i64(1000000), i64(0), i64(2000000), i64(0));
|
|
23
23
|
// assert(ret2 == i32(0));
|
|
24
|
-
|
|
25
|
-
{
|
|
26
|
-
__yo_sync_utime, __yo_sync_futime, __yo_sync_lutime
|
|
27
|
-
} :: import "./externs.yo";
|
|
28
|
-
|
|
24
|
+
{ __yo_sync_utime, __yo_sync_futime, __yo_sync_lutime } :: import("./externs.yo");
|
|
29
25
|
// ============================================================================
|
|
30
26
|
// utime — Change file timestamps by path
|
|
31
27
|
// ============================================================================
|
|
32
|
-
|
|
33
28
|
// Change file access and modification times by path.
|
|
34
29
|
// path: file path (null-terminated)
|
|
35
30
|
// atime_sec, atime_nsec: access time (seconds + nanoseconds)
|
|
36
31
|
// mtime_sec, mtime_nsec: modification time (seconds + nanoseconds)
|
|
37
32
|
// Returns 0 on success, -errno on failure.
|
|
38
|
-
utime :: (fn(path: *(u8), atime_sec: i64, atime_nsec: i64, mtime_sec: i64, mtime_nsec: i64) -> i32)(
|
|
33
|
+
utime :: (fn(path : *(u8), atime_sec : i64, atime_nsec : i64, mtime_sec : i64, mtime_nsec : i64) -> i32)(
|
|
39
34
|
__yo_sync_utime(path, atime_sec, atime_nsec, mtime_sec, mtime_nsec)
|
|
40
35
|
);
|
|
41
|
-
|
|
42
36
|
// ============================================================================
|
|
43
37
|
// futime — Change file timestamps by fd
|
|
44
38
|
// ============================================================================
|
|
45
|
-
|
|
46
39
|
// Change file access and modification times by file descriptor.
|
|
47
40
|
// fd: open file descriptor
|
|
48
41
|
// atime_sec, atime_nsec: access time (seconds + nanoseconds)
|
|
49
42
|
// mtime_sec, mtime_nsec: modification time (seconds + nanoseconds)
|
|
50
43
|
// Returns 0 on success, -errno on failure.
|
|
51
|
-
futime :: (fn(fd: i32, atime_sec: i64, atime_nsec: i64, mtime_sec: i64, mtime_nsec: i64) -> i32)(
|
|
44
|
+
futime :: (fn(fd : i32, atime_sec : i64, atime_nsec : i64, mtime_sec : i64, mtime_nsec : i64) -> i32)(
|
|
52
45
|
__yo_sync_futime(fd, atime_sec, atime_nsec, mtime_sec, mtime_nsec)
|
|
53
46
|
);
|
|
54
|
-
|
|
55
47
|
// ============================================================================
|
|
56
48
|
// lutime — Change symlink timestamps (does not follow symlinks)
|
|
57
49
|
// ============================================================================
|
|
58
|
-
|
|
59
50
|
// Change file access and modification times of a symlink itself.
|
|
60
51
|
// Does not follow the symlink (uses AT_SYMLINK_NOFOLLOW).
|
|
61
52
|
// path: symlink path (null-terminated)
|
|
62
53
|
// atime_sec, atime_nsec: access time (seconds + nanoseconds)
|
|
63
54
|
// mtime_sec, mtime_nsec: modification time (seconds + nanoseconds)
|
|
64
55
|
// Returns 0 on success, -errno on failure.
|
|
65
|
-
lutime :: (fn(path: *(u8), atime_sec: i64, atime_nsec: i64, mtime_sec: i64, mtime_nsec: i64) -> i32)(
|
|
56
|
+
lutime :: (fn(path : *(u8), atime_sec : i64, atime_nsec : i64, mtime_sec : i64, mtime_nsec : i64) -> i32)(
|
|
66
57
|
__yo_sync_lutime(path, atime_sec, atime_nsec, mtime_sec, mtime_nsec)
|
|
67
58
|
);
|
|
68
|
-
|
|
69
|
-
export utime, futime, lutime;
|
|
59
|
+
export(utime, futime, lutime);
|
package/std/sys/timer.yo
CHANGED
|
@@ -8,21 +8,16 @@
|
|
|
8
8
|
//
|
|
9
9
|
// Example:
|
|
10
10
|
// IO :: import "std/io";
|
|
11
|
-
//
|
|
11
|
+
//
|
|
12
12
|
// task := async {
|
|
13
13
|
// // Sleep for 100 milliseconds
|
|
14
14
|
// result := await IO.sleep(u64(100));
|
|
15
15
|
// printf("Woke up! result=%d\n", result);
|
|
16
16
|
// };
|
|
17
|
-
|
|
18
|
-
{
|
|
19
|
-
{
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
sleep :: (fn(milliseconds: u64) -> IOFuture)(
|
|
17
|
+
{ IOFuture } :: import("./future.yo");
|
|
18
|
+
{ IOError } :: import("./errors.yo");
|
|
19
|
+
{ __yo_async_sleep_start } :: import("./externs.yo");
|
|
20
|
+
sleep :: (fn(milliseconds : u64) -> IOFuture)(
|
|
23
21
|
__yo_async_sleep_start(milliseconds)
|
|
24
22
|
);
|
|
25
|
-
|
|
26
|
-
export
|
|
27
|
-
sleep
|
|
28
|
-
;
|
|
23
|
+
export(sleep);
|
package/std/sys/tty.yo
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
//! TTY operations.
|
|
2
|
-
|
|
3
|
-
{
|
|
4
|
-
{ TTY_MODE_NORMAL, TTY_MODE_RAW, TTY_MODE_IO } :: import "./events.yo";
|
|
5
|
-
|
|
2
|
+
{ __yo_tty_init, __yo_tty_set_mode, __yo_tty_reset_mode, __yo_tty_get_winsize, __yo_isatty } :: import("./externs.yo");
|
|
3
|
+
{ TTY_MODE_NORMAL, TTY_MODE_RAW, TTY_MODE_IO } :: import("./events.yo");
|
|
6
4
|
/// Terminal window size.
|
|
7
5
|
WinSize :: struct(
|
|
8
6
|
/// Width in columns.
|
|
@@ -10,31 +8,27 @@ WinSize :: struct(
|
|
|
10
8
|
/// Height in rows.
|
|
11
9
|
height : i32
|
|
12
10
|
);
|
|
13
|
-
|
|
14
11
|
/// Initialize TTY for a fd.
|
|
15
12
|
/// Returns 0 on success, -errno on failure.
|
|
16
|
-
tty_init :: (fn(fd: i32) -> i32)(
|
|
13
|
+
tty_init :: (fn(fd : i32) -> i32)(
|
|
17
14
|
__yo_tty_init(fd)
|
|
18
15
|
);
|
|
19
|
-
|
|
20
16
|
/// Set TTY mode (normal, raw, IO).
|
|
21
17
|
/// Returns 0 on success, -errno on failure.
|
|
22
|
-
tty_set_mode :: (fn(fd: i32, mode: i32) -> i32)(
|
|
18
|
+
tty_set_mode :: (fn(fd : i32, mode : i32) -> i32)(
|
|
23
19
|
__yo_tty_set_mode(fd, mode)
|
|
24
20
|
);
|
|
25
|
-
|
|
26
21
|
/// Reset TTY to original mode.
|
|
27
22
|
/// Returns 0 on success, -errno on failure.
|
|
28
23
|
tty_reset :: (fn() -> i32)(
|
|
29
24
|
__yo_tty_reset_mode()
|
|
30
25
|
);
|
|
31
|
-
|
|
32
26
|
/// Get terminal window size.
|
|
33
27
|
/// Returns width and height (0,0 on error).
|
|
34
|
-
tty_winsize :: (fn(fd: i32) -> WinSize)({
|
|
28
|
+
tty_winsize :: (fn(fd : i32) -> WinSize)({
|
|
35
29
|
buf_uninit := MaybeUninit(Array(i32, usize(2))).new();
|
|
36
30
|
buf := *(i32)(buf_uninit.as_ptr());
|
|
37
|
-
res := __yo_tty_get_winsize(fd,
|
|
31
|
+
res := __yo_tty_get_winsize(fd, buf &+ usize(0), buf &+ usize(1));
|
|
38
32
|
width := cond(
|
|
39
33
|
(res == i32(0)) => (buf &+ usize(0)).*,
|
|
40
34
|
true => i32(0)
|
|
@@ -45,14 +39,12 @@ tty_winsize :: (fn(fd: i32) -> WinSize)({
|
|
|
45
39
|
);
|
|
46
40
|
WinSize(width, height)
|
|
47
41
|
});
|
|
48
|
-
|
|
49
42
|
/// Check if `fd` is a TTY.
|
|
50
|
-
isatty :: (fn(fd: i32) -> bool)({
|
|
43
|
+
isatty :: (fn(fd : i32) -> bool)({
|
|
51
44
|
res := __yo_isatty(fd);
|
|
52
|
-
|
|
45
|
+
res > i32(0)
|
|
53
46
|
});
|
|
54
|
-
|
|
55
|
-
export
|
|
47
|
+
export(
|
|
56
48
|
WinSize,
|
|
57
49
|
tty_init,
|
|
58
50
|
tty_set_mode,
|
|
@@ -62,4 +54,4 @@ export
|
|
|
62
54
|
TTY_MODE_NORMAL,
|
|
63
55
|
TTY_MODE_RAW,
|
|
64
56
|
TTY_MODE_IO
|
|
65
|
-
;
|
|
57
|
+
);
|
package/std/sys/udp.yo
CHANGED
|
@@ -26,88 +26,71 @@
|
|
|
26
26
|
// await udp.close(sockfd);
|
|
27
27
|
// tcp.free_sockaddr(addr);
|
|
28
28
|
// };
|
|
29
|
-
|
|
30
|
-
{
|
|
31
|
-
{
|
|
32
|
-
__yo_async_socket_start, __yo_async_bind_start,
|
|
33
|
-
__yo_async_send_start, __yo_async_recv_start,
|
|
34
|
-
__yo_async_sendto_start, __yo_async_recvfrom_start,
|
|
35
|
-
__yo_async_close_start,
|
|
36
|
-
__yo_async_setsockopt_start, __yo_async_getsockopt_start
|
|
37
|
-
} :: import "./externs.yo";
|
|
38
|
-
{
|
|
39
|
-
SOCK_DGRAM
|
|
40
|
-
} :: import "./socket.yo";
|
|
41
|
-
|
|
29
|
+
{ IOFuture } :: import("./future.yo");
|
|
30
|
+
{ __yo_async_socket_start, __yo_async_bind_start, __yo_async_send_start, __yo_async_recv_start, __yo_async_sendto_start, __yo_async_recvfrom_start, __yo_async_close_start, __yo_async_setsockopt_start, __yo_async_getsockopt_start } :: import("./externs.yo");
|
|
31
|
+
{ SOCK_DGRAM } :: import("./socket.yo");
|
|
42
32
|
// ============================================================================
|
|
43
33
|
// Core UDP Operations (return IOFuture, use with await)
|
|
44
34
|
// ============================================================================
|
|
45
|
-
|
|
46
35
|
// Create a UDP socket.
|
|
47
36
|
// domain: AF_INET or AF_INET6
|
|
48
37
|
// protocol: typically 0
|
|
49
38
|
// Returns fd on success, -errno on failure.
|
|
50
|
-
socket :: (fn(domain: i32, protocol: i32) -> IOFuture)(
|
|
39
|
+
socket :: (fn(domain : i32, protocol : i32) -> IOFuture)(
|
|
51
40
|
__yo_async_socket_start(domain, SOCK_DGRAM, protocol)
|
|
52
41
|
);
|
|
53
|
-
|
|
54
42
|
// Bind a UDP socket to a local address.
|
|
55
43
|
// Returns 0 on success, -errno on failure.
|
|
56
|
-
bind :: (fn(sockfd: i32, addr: *(u8), addrlen: u32) -> IOFuture)(
|
|
44
|
+
bind :: (fn(sockfd : i32, addr : *(u8), addrlen : u32) -> IOFuture)(
|
|
57
45
|
__yo_async_bind_start(sockfd, addr, addrlen)
|
|
58
46
|
);
|
|
59
|
-
|
|
60
47
|
// Send a datagram to a specific destination address.
|
|
61
48
|
// Returns number of bytes sent on success, -errno on failure.
|
|
62
|
-
sendto :: (fn(sockfd: i32, buf: *(u8), len: usize, flags: i32, dest_addr: *(u8), addrlen: u32) -> IOFuture)(
|
|
49
|
+
sendto :: (fn(sockfd : i32, buf : *(u8), len : usize, flags : i32, dest_addr : *(u8), addrlen : u32) -> IOFuture)(
|
|
63
50
|
__yo_async_sendto_start(sockfd, buf, len, flags, dest_addr, addrlen)
|
|
64
51
|
);
|
|
65
|
-
|
|
66
52
|
// Receive a datagram and get the source address.
|
|
67
53
|
// src_addr/addrlen are filled with the sender's address.
|
|
68
54
|
// Returns number of bytes received on success, -errno on failure.
|
|
69
|
-
recvfrom :: (fn(sockfd: i32, buf: *(u8), len: usize, flags: i32, src_addr: *(u8), addrlen: *(u32)) -> IOFuture)(
|
|
55
|
+
recvfrom :: (fn(sockfd : i32, buf : *(u8), len : usize, flags : i32, src_addr : *(u8), addrlen : *(u32)) -> IOFuture)(
|
|
70
56
|
__yo_async_recvfrom_start(sockfd, buf, len, flags, src_addr, addrlen)
|
|
71
57
|
);
|
|
72
|
-
|
|
73
58
|
// Send data on a connected UDP socket (after connect()).
|
|
74
59
|
// Returns number of bytes sent on success, -errno on failure.
|
|
75
|
-
send :: (fn(sockfd: i32, buf: *(u8), len: usize, flags: i32) -> IOFuture)(
|
|
60
|
+
send :: (fn(sockfd : i32, buf : *(u8), len : usize, flags : i32) -> IOFuture)(
|
|
76
61
|
__yo_async_send_start(sockfd, buf, len, flags)
|
|
77
62
|
);
|
|
78
|
-
|
|
79
63
|
// Receive data on a connected UDP socket (after connect()).
|
|
80
64
|
// Returns number of bytes received on success, -errno on failure.
|
|
81
|
-
recv :: (fn(sockfd: i32, buf: *(u8), len: usize, flags: i32) -> IOFuture)(
|
|
65
|
+
recv :: (fn(sockfd : i32, buf : *(u8), len : usize, flags : i32) -> IOFuture)(
|
|
82
66
|
__yo_async_recv_start(sockfd, buf, len, flags)
|
|
83
67
|
);
|
|
84
|
-
|
|
85
68
|
// Close a UDP socket file descriptor.
|
|
86
69
|
// Returns 0 on success, -errno on failure.
|
|
87
|
-
close :: (fn(fd: i32) -> IOFuture)(
|
|
70
|
+
close :: (fn(fd : i32) -> IOFuture)(
|
|
88
71
|
__yo_async_close_start(fd)
|
|
89
72
|
);
|
|
90
|
-
|
|
91
73
|
// ============================================================================
|
|
92
74
|
// Socket Options
|
|
93
75
|
// ============================================================================
|
|
94
|
-
|
|
95
76
|
// Set a socket option (raw).
|
|
96
77
|
// Returns 0 on success, -errno on failure.
|
|
97
|
-
setsockopt :: (fn(sockfd: i32, level: i32, optname: i32, optval: *(u8), optlen: u32) -> IOFuture)(
|
|
78
|
+
setsockopt :: (fn(sockfd : i32, level : i32, optname : i32, optval : *(u8), optlen : u32) -> IOFuture)(
|
|
98
79
|
__yo_async_setsockopt_start(sockfd, level, optname, optval, optlen)
|
|
99
80
|
);
|
|
100
|
-
|
|
101
81
|
// Get a socket option (raw).
|
|
102
82
|
// Returns 0 on success, -errno on failure.
|
|
103
|
-
getsockopt :: (fn(sockfd: i32, level: i32, optname: i32, optval: *(u8), optlen: *(u32)) -> IOFuture)(
|
|
83
|
+
getsockopt :: (fn(sockfd : i32, level : i32, optname : i32, optval : *(u8), optlen : *(u32)) -> IOFuture)(
|
|
104
84
|
__yo_async_getsockopt_start(sockfd, level, optname, optval, optlen)
|
|
105
85
|
);
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
sendto,
|
|
110
|
-
|
|
86
|
+
export(
|
|
87
|
+
socket,
|
|
88
|
+
bind,
|
|
89
|
+
sendto,
|
|
90
|
+
recvfrom,
|
|
91
|
+
send,
|
|
92
|
+
recv,
|
|
111
93
|
close,
|
|
112
|
-
setsockopt,
|
|
113
|
-
|
|
94
|
+
setsockopt,
|
|
95
|
+
getsockopt
|
|
96
|
+
);
|
package/std/sys/umask.yo
CHANGED
|
@@ -2,11 +2,8 @@
|
|
|
2
2
|
//!
|
|
3
3
|
//! Synchronous wrapper for setting process `umask`.
|
|
4
4
|
//! Returns previous mask value.
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
umask :: (fn(mask: i32) -> i32)(
|
|
5
|
+
{ __yo_sync_umask } :: import("./externs.yo");
|
|
6
|
+
umask :: (fn(mask : i32) -> i32)(
|
|
9
7
|
__yo_sync_umask(mask)
|
|
10
8
|
);
|
|
11
|
-
|
|
12
|
-
export umask;
|
|
9
|
+
export(umask);
|