@shd101wyy/yo 0.1.12 → 0.1.13
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/README.md +10 -1
- package/out/cjs/index.cjs +578 -572
- package/out/cjs/yo-cli.cjs +1413 -592
- package/out/esm/index.mjs +434 -428
- package/out/types/src/build-runner.d.ts +1 -1
- package/out/types/src/doc/builder.d.ts +21 -0
- package/out/types/src/doc/builder.test.d.ts +1 -0
- package/out/types/src/doc/extractor.d.ts +27 -0
- package/out/types/src/doc/extractor.test.d.ts +1 -0
- package/out/types/src/doc/model.d.ts +87 -0
- package/out/types/src/doc/render-html.d.ts +23 -0
- package/out/types/src/doc/render-html.test.d.ts +1 -0
- package/out/types/src/doc/render-json.d.ts +7 -0
- package/out/types/src/doc/render-json.test.d.ts +1 -0
- package/out/types/src/doc/render-markdown.d.ts +13 -0
- package/out/types/src/doc/render-markdown.test.d.ts +1 -0
- package/out/types/src/doc/sections.d.ts +7 -0
- package/out/types/src/doc/sections.test.d.ts +1 -0
- package/out/types/src/doc-command.d.ts +10 -0
- package/out/types/src/env.d.ts +1 -0
- package/out/types/src/evaluator/builtins/build.d.ts +17 -0
- package/out/types/src/evaluator/context.d.ts +1 -0
- package/out/types/src/expr.d.ts +2 -1
- package/out/types/src/token.d.ts +4 -0
- package/out/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +2 -1
- package/scripts/build-site.ts +461 -0
- package/std/alg/hash.yo +12 -24
- package/std/allocator.yo +21 -29
- package/std/async.yo +4 -2
- package/std/build.yo +188 -42
- package/std/cli/arg_parser.yo +37 -1
- package/std/collections/array_list.yo +8 -20
- package/std/collections/btree_map.yo +15 -20
- package/std/collections/deque.yo +13 -15
- package/std/collections/hash_map.yo +15 -54
- package/std/collections/hash_set.yo +14 -50
- package/std/collections/linked_list.yo +6 -23
- package/std/collections/priority_queue.yo +15 -17
- package/std/crypto/md5.yo +10 -9
- package/std/crypto/random.yo +14 -12
- package/std/crypto/sha256.yo +9 -8
- package/std/encoding/base64.yo +13 -15
- package/std/encoding/hex.yo +14 -10
- package/std/encoding/html.yo +14 -11
- package/std/encoding/html_char_utils.yo +14 -11
- package/std/encoding/html_entities.yo +7 -8
- package/std/encoding/json.yo +36 -19
- package/std/encoding/punycode.yo +21 -18
- package/std/encoding/toml.yo +23 -9
- package/std/encoding/utf16.yo +16 -9
- package/std/error.yo +10 -23
- package/std/fmt/display.yo +15 -17
- package/std/fmt/index.yo +6 -27
- package/std/fmt/to_string.yo +4 -10
- package/std/fmt/writer.yo +33 -34
- package/std/fs/dir.yo +37 -30
- package/std/fs/file.yo +77 -75
- package/std/fs/metadata.yo +25 -25
- package/std/fs/temp.yo +21 -27
- package/std/fs/types.yo +20 -23
- package/std/fs/walker.yo +26 -31
- package/std/gc.yo +5 -0
- package/std/glob/index.yo +3 -0
- package/std/http/client.yo +25 -11
- package/std/http/http.yo +20 -0
- package/std/http/index.yo +1 -0
- package/std/io/reader.yo +4 -8
- package/std/io/writer.yo +4 -7
- package/std/libc/assert.yo +2 -2
- package/std/libc/ctype.yo +1 -2
- package/std/libc/dirent.yo +1 -2
- package/std/libc/errno.yo +1 -2
- package/std/libc/fcntl.yo +2 -2
- package/std/libc/float.yo +1 -2
- package/std/libc/limits.yo +1 -2
- package/std/libc/math.yo +2 -0
- package/std/libc/signal.yo +1 -2
- package/std/libc/stdatomic.yo +1 -2
- package/std/libc/stdint.yo +4 -3
- package/std/libc/stdio.yo +2 -0
- package/std/libc/stdlib.yo +2 -0
- package/std/libc/string.yo +2 -0
- package/std/libc/sys/stat.yo +1 -2
- package/std/libc/time.yo +2 -2
- package/std/libc/unistd.yo +2 -0
- package/std/libc/wctype.yo +1 -2
- package/std/libc/windows.yo +2 -2
- package/std/log/index.yo +11 -26
- package/std/net/addr.yo +18 -11
- package/std/net/dns.yo +3 -2
- package/std/net/errors.yo +16 -2
- package/std/net/tcp.yo +25 -22
- package/std/net/udp.yo +14 -12
- package/std/os/env.yo +23 -18
- package/std/os/signal.yo +31 -19
- package/std/path.yo +23 -74
- package/std/prelude.yo +284 -113
- package/std/process.yo +23 -37
- package/std/regex/compiler.yo +3 -5
- package/std/regex/flags.yo +11 -11
- package/std/regex/index.yo +2 -13
- package/std/regex/match.yo +3 -5
- package/std/regex/node.yo +6 -6
- package/std/regex/parser.yo +2 -4
- package/std/regex/unicode.yo +5 -5
- package/std/regex/vm.yo +5 -5
- package/std/string/index.yo +2 -1
- package/std/string/rune.yo +25 -1
- package/std/string/string.yo +31 -19
- package/std/string/unicode.yo +14 -15
- package/std/sync/channel.yo +18 -28
- package/std/sync/cond.yo +4 -0
- package/std/sync/mutex.yo +4 -1
- package/std/sync/once.yo +17 -19
- package/std/sync/rwlock.yo +19 -22
- package/std/sync/waitgroup.yo +21 -23
- package/std/sys/advise.yo +4 -4
- package/std/sys/bufio/buf_reader.yo +19 -16
- package/std/sys/bufio/buf_writer.yo +14 -11
- package/std/sys/clock.yo +4 -4
- package/std/sys/constants.yo +5 -5
- package/std/sys/copy.yo +9 -8
- package/std/sys/dir.yo +9 -8
- package/std/sys/dns.yo +8 -8
- package/std/sys/errors.yo +35 -6
- package/std/sys/events.yo +3 -3
- package/std/sys/externs.yo +3 -3
- package/std/sys/fallocate.yo +4 -4
- package/std/sys/fcntl.yo +8 -6
- package/std/sys/file.yo +7 -8
- package/std/sys/future.yo +1 -3
- package/std/sys/iov.yo +4 -4
- package/std/sys/lock.yo +7 -7
- package/std/sys/mmap.yo +7 -8
- package/std/sys/path.yo +4 -7
- package/std/sys/perm.yo +8 -8
- package/std/sys/pipe.yo +9 -8
- package/std/sys/process.yo +8 -8
- package/std/sys/seek.yo +4 -4
- package/std/sys/signal.yo +4 -4
- package/std/sys/signals.yo +4 -4
- package/std/sys/socket.yo +4 -4
- package/std/sys/socketpair.yo +4 -4
- package/std/sys/sockinfo.yo +4 -4
- package/std/sys/statfs.yo +8 -8
- package/std/sys/statx.yo +4 -4
- package/std/sys/sysinfo.yo +4 -4
- package/std/sys/tcp.yo +8 -8
- package/std/sys/temp.yo +9 -8
- package/std/sys/time.yo +8 -8
- package/std/sys/timer.yo +7 -8
- package/std/sys/tty.yo +13 -10
- package/std/sys/udp.yo +8 -8
- package/std/sys/umask.yo +4 -4
- package/std/sys/unix.yo +5 -5
- package/std/testing/bench.yo +21 -10
- package/std/thread.yo +18 -9
- package/std/time/datetime.yo +12 -14
- package/std/time/duration.yo +12 -14
- package/std/time/instant.yo +13 -16
- package/std/time/sleep.yo +9 -8
- package/std/url/index.yo +3 -19
- package/std/worker.yo +10 -18
package/std/sys/pipe.yo
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
//! Pipe and file descriptor duplication operations.
|
|
2
|
+
//!
|
|
3
|
+
//! Synchronous wrappers for `pipe`/`dup`/`dup2`.
|
|
4
|
+
//! These are inherently synchronous kernel operations on all platforms.
|
|
5
|
+
//!
|
|
6
|
+
//! ## Return values
|
|
7
|
+
//!
|
|
8
|
+
//! - `pipe`: 0 on success, -errno on failure
|
|
9
|
+
//! - `dup`/`dup2`: new fd on success, -errno on failure
|
|
9
10
|
|
|
10
11
|
{ __yo_sync_pipe, __yo_sync_dup, __yo_sync_dup2 } :: import "./externs.yo";
|
|
11
12
|
|
package/std/sys/process.yo
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
//! Child process management.
|
|
2
|
+
//!
|
|
3
|
+
//! Provides cross-platform child process spawning, waiting, and signal delivery.
|
|
4
|
+
//! All async operations return `IOFuture` which resolves to:
|
|
5
|
+
//! - Positive value: success (pid for spawn, status for waitpid)
|
|
6
|
+
//! - Negative value: -errno on failure
|
|
7
|
+
//!
|
|
8
|
+
//! `argv`/`envp` are NULL-terminated arrays of C strings.
|
|
9
9
|
// Use `?*(u8)` for entries so .None can be used as the terminator.
|
|
10
10
|
|
|
11
11
|
{ IOFuture } :: import "./future.yo";
|
package/std/sys/seek.yo
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
//! File position control.
|
|
2
|
+
//!
|
|
3
|
+
//! Synchronous wrapper for `lseek`.
|
|
4
|
+
//! Returns resulting absolute file offset on success, -errno on failure.
|
|
5
5
|
|
|
6
6
|
{ __yo_sync_lseek } :: import "./externs.yo";
|
|
7
7
|
|
package/std/sys/signal.yo
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
//! Signal handling functions.
|
|
2
|
+
//!
|
|
3
|
+
//! Provides low-level wrappers for signal registration and delivery.
|
|
4
4
|
|
|
5
5
|
{ __yo_signal_start, __yo_signal_stop, __yo_kill } :: import "./externs.yo";
|
|
6
6
|
|
|
@@ -9,7 +9,7 @@ SignalHandler :: (fn(data: *(u8)) -> unit);
|
|
|
9
9
|
// Register a signal handler.
|
|
10
10
|
// Returns 0 on success, -errno on failure.
|
|
11
11
|
on_signal :: (fn(signum: i32, handler: SignalHandler) -> i32)({
|
|
12
|
-
__yo_signal_start(signum,
|
|
12
|
+
__yo_signal_start(signum, unsafe.cast(handler, *(u8)))
|
|
13
13
|
});
|
|
14
14
|
|
|
15
15
|
// Remove a signal handler (reset to default).
|
package/std/sys/signals.yo
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
//! POSIX signal constants.
|
|
2
|
+
//!
|
|
3
|
+
//! Platform-aware signal numbers.
|
|
4
|
+
//! Uses `process.platform` for values that differ between Linux and macOS.
|
|
5
5
|
|
|
6
6
|
{ platform, Platform } :: import "../process";
|
|
7
7
|
|
package/std/sys/socket.yo
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
//! Socket constants.
|
|
2
|
+
//!
|
|
3
|
+
//! Platform-aware socket constants for TCP, UDP, and Unix domain sockets.
|
|
4
|
+
//! Uses `process.platform` for values that differ between Linux and macOS.
|
|
5
5
|
|
|
6
6
|
{ platform, Platform } :: import "../process";
|
|
7
7
|
{
|
package/std/sys/socketpair.yo
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
//! Connected socket pair.
|
|
2
|
+
//!
|
|
3
|
+
//! Synchronous wrapper for `socketpair`-like behavior.
|
|
4
|
+
//! Returns 0 on success, negative error on failure.
|
|
5
5
|
|
|
6
6
|
{ __yo_sync_socketpair } :: import "./externs.yo";
|
|
7
7
|
|
package/std/sys/sockinfo.yo
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
//! Socket address and option query helpers.
|
|
2
|
+
//!
|
|
3
|
+
//! Synchronous wrappers for socket metadata operations.
|
|
4
|
+
//! Returns 0 on success, -errno (or negative platform socket error) on failure.
|
|
5
5
|
|
|
6
6
|
{
|
|
7
7
|
__yo_sync_getsockname,
|
package/std/sys/statfs.yo
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
//! Filesystem statistics.
|
|
2
|
+
//!
|
|
3
|
+
//! Provides a synchronous wrapper around `statfs` and typed accessors
|
|
4
|
+
//! for the statfs buffer returned by the C runtime.
|
|
5
|
+
//!
|
|
6
|
+
//! All operations return `i32` directly (no `IOFuture` overhead):
|
|
7
|
+
//! - 0 on success
|
|
8
|
+
//! - Negative value: -errno on failure
|
|
9
9
|
//
|
|
10
10
|
// Example:
|
|
11
11
|
// statfs :: import "std/sys/statfs";
|
package/std/sys/statx.yo
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
//! Statx file status type.
|
|
2
|
+
//!
|
|
3
|
+
//! Object wrapper around the C statx buffer, providing
|
|
4
|
+
//! accessor methods for file metadata.
|
|
5
5
|
|
|
6
6
|
{
|
|
7
7
|
S_IFMT, S_IFREG, S_IFDIR, S_IFLNK
|
package/std/sys/sysinfo.yo
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
//! Runtime system identification.
|
|
2
|
+
//!
|
|
3
|
+
//! Synchronous wrappers for `uname`/`gethostname`.
|
|
4
|
+
//! Returns 0 on success, -errno / negative platform error on failure.
|
|
5
5
|
|
|
6
6
|
{ platform, Platform } :: import "../process";
|
|
7
7
|
{
|
package/std/sys/tcp.yo
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
//! Async TCP socket operations.
|
|
2
|
+
//!
|
|
3
|
+
//! Provides TCP socket wrappers around the low-level C runtime externs.
|
|
4
|
+
//! Uses the socket address helpers to construct `sockaddr_in`/`sockaddr_in6` buffers.
|
|
5
|
+
//!
|
|
6
|
+
//! All async operations return `IOFuture` which resolves to:
|
|
7
|
+
//! - Positive value: success (fd for socket/accept, bytes for send/recv, 0 for others)
|
|
8
|
+
//! - Negative value: -errno on failure
|
|
9
9
|
//
|
|
10
10
|
// Example:
|
|
11
11
|
// { GlobalAllocator } :: import "../allocator.yo";
|
package/std/sys/temp.yo
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
//! Temporary file/directory operations.
|
|
2
|
+
//!
|
|
3
|
+
//! Synchronous wrappers for `mkdtemp`/`mkstemp`.
|
|
4
|
+
//! These are inherently synchronous on all platforms.
|
|
5
|
+
//!
|
|
6
|
+
//! ## Return values
|
|
7
|
+
//!
|
|
8
|
+
//! - `mkdtemp`: 0 on success, -errno on failure
|
|
9
|
+
//! - `mkstemp`: fd on success, -errno on failure
|
|
9
10
|
|
|
10
11
|
{ __yo_sync_mkdtemp, __yo_sync_mkstemp } :: import "./externs.yo";
|
|
11
12
|
|
package/std/sys/time.yo
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
//! File timestamp operations.
|
|
2
|
+
//!
|
|
3
|
+
//! Provides synchronous wrappers for `utime`/`futime`/`lutime` to change file timestamps.
|
|
4
|
+
//! All operations return `i32` directly (no `IOFuture` overhead).
|
|
5
|
+
//!
|
|
6
|
+
//! Returns:
|
|
7
|
+
//! - 0: success
|
|
8
|
+
//! - Negative value: -errno on failure
|
|
9
9
|
//
|
|
10
10
|
// Timestamps use (seconds, nanoseconds) pairs for both atime and mtime.
|
|
11
11
|
// Use special value UTIME_NOW (0x3fffffff) to set current time,
|
package/std/sys/timer.yo
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
// Use with `await` in async contexts.
|
|
1
|
+
//! Async timer operations.
|
|
2
|
+
//!
|
|
3
|
+
//! Provides high-level async timer functions:
|
|
4
|
+
//! - `sleep(ms)` — async sleep for the given number of milliseconds
|
|
5
|
+
//!
|
|
6
|
+
//! Returns an `IOFuture` that resolves to a positive value on success
|
|
7
|
+
//! or a negative errno. Use with `await` in async contexts.
|
|
9
8
|
//
|
|
10
9
|
// Example:
|
|
11
10
|
// IO :: import "std/io";
|
package/std/sys/tty.yo
CHANGED
|
@@ -1,33 +1,36 @@
|
|
|
1
|
-
|
|
1
|
+
//! TTY operations.
|
|
2
2
|
|
|
3
3
|
{ __yo_tty_init, __yo_tty_set_mode, __yo_tty_reset_mode, __yo_tty_get_winsize, __yo_isatty } :: import "./externs.yo";
|
|
4
4
|
{ TTY_MODE_NORMAL, TTY_MODE_RAW, TTY_MODE_IO } :: import "./events.yo";
|
|
5
5
|
|
|
6
|
+
/// Terminal window size.
|
|
6
7
|
WinSize :: struct(
|
|
8
|
+
/// Width in columns.
|
|
7
9
|
width : i32,
|
|
10
|
+
/// Height in rows.
|
|
8
11
|
height : i32
|
|
9
12
|
);
|
|
10
13
|
|
|
11
|
-
|
|
12
|
-
|
|
14
|
+
/// Initialize TTY for a fd.
|
|
15
|
+
/// Returns 0 on success, -errno on failure.
|
|
13
16
|
tty_init :: (fn(fd: i32) -> i32)(
|
|
14
17
|
__yo_tty_init(fd)
|
|
15
18
|
);
|
|
16
19
|
|
|
17
|
-
|
|
18
|
-
|
|
20
|
+
/// Set TTY mode (normal, raw, IO).
|
|
21
|
+
/// Returns 0 on success, -errno on failure.
|
|
19
22
|
tty_set_mode :: (fn(fd: i32, mode: i32) -> i32)(
|
|
20
23
|
__yo_tty_set_mode(fd, mode)
|
|
21
24
|
);
|
|
22
25
|
|
|
23
|
-
|
|
24
|
-
|
|
26
|
+
/// Reset TTY to original mode.
|
|
27
|
+
/// Returns 0 on success, -errno on failure.
|
|
25
28
|
tty_reset :: (fn() -> i32)(
|
|
26
29
|
__yo_tty_reset_mode()
|
|
27
30
|
);
|
|
28
31
|
|
|
29
|
-
|
|
30
|
-
|
|
32
|
+
/// Get terminal window size.
|
|
33
|
+
/// Returns width and height (0,0 on error).
|
|
31
34
|
tty_winsize :: (fn(fd: i32) -> WinSize)({
|
|
32
35
|
buf_uninit := MaybeUninit(Array(i32, usize(2))).new();
|
|
33
36
|
buf := *(i32)(buf_uninit.as_ptr());
|
|
@@ -43,7 +46,7 @@ tty_winsize :: (fn(fd: i32) -> WinSize)({
|
|
|
43
46
|
WinSize(width, height)
|
|
44
47
|
});
|
|
45
48
|
|
|
46
|
-
|
|
49
|
+
/// Check if `fd` is a TTY.
|
|
47
50
|
isatty :: (fn(fd: i32) -> bool)({
|
|
48
51
|
res := __yo_isatty(fd);
|
|
49
52
|
(res > i32(0))
|
package/std/sys/udp.yo
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
//! Async UDP socket operations.
|
|
2
|
+
//!
|
|
3
|
+
//! Provides UDP socket wrappers around the low-level C runtime externs.
|
|
4
|
+
//! Reuses `SockAddr` and address helpers from `tcp.yo`.
|
|
5
|
+
//!
|
|
6
|
+
//! All async operations return `IOFuture` which resolves to:
|
|
7
|
+
//! - Positive value: success (fd for socket, bytes for sendto/recvfrom, 0 for others)
|
|
8
|
+
//! - Negative value: -errno on failure
|
|
9
9
|
//
|
|
10
10
|
// Example:
|
|
11
11
|
// { GlobalAllocator } :: import "../allocator.yo";
|
package/std/sys/umask.yo
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
//! Process file creation mask.
|
|
2
|
+
//!
|
|
3
|
+
//! Synchronous wrapper for setting process `umask`.
|
|
4
|
+
//! Returns previous mask value.
|
|
5
5
|
|
|
6
6
|
{ __yo_sync_umask } :: import "./externs.yo";
|
|
7
7
|
|
package/std/sys/unix.yo
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
//! Unix domain socket operations.
|
|
2
|
+
//!
|
|
3
|
+
//! Provides Unix domain socket wrappers around the low-level C runtime externs.
|
|
4
|
+
//! Reuses the socket ops (bind/listen/accept/connect/send/recv/close) from the
|
|
5
|
+
//! generic socket externs. Uses `sockaddr_un` helpers to build address buffers.
|
|
6
6
|
|
|
7
7
|
{ GlobalAllocator } :: import "../allocator.yo";
|
|
8
8
|
{ malloc, free } :: GlobalAllocator;
|
package/std/testing/bench.yo
CHANGED
|
@@ -1,12 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
1
|
+
//! Micro-benchmarking utilities.
|
|
2
|
+
//!
|
|
3
|
+
//! Runs a function N times, measures elapsed nanoseconds, and returns statistics
|
|
4
|
+
//! (average, min, max).
|
|
5
|
+
//!
|
|
6
|
+
//! # Example
|
|
7
|
+
//!
|
|
8
|
+
//! ```rust
|
|
9
|
+
//! { bench } :: import "std/testing/bench";
|
|
10
|
+
//!
|
|
11
|
+
//! result := bench(`sort`, u64(1000), () => { /* work */ });
|
|
12
|
+
//! println(result.to_string());
|
|
13
|
+
//! ```
|
|
10
14
|
|
|
11
15
|
open import "../string";
|
|
12
16
|
{ ToString } :: import "../fmt";
|
|
@@ -17,12 +21,19 @@ open import "../string";
|
|
|
17
21
|
// BenchResult
|
|
18
22
|
// ============================================================================
|
|
19
23
|
|
|
24
|
+
/// Timing statistics returned by `bench`.
|
|
20
25
|
BenchResult :: struct(
|
|
26
|
+
/// Benchmark name.
|
|
21
27
|
name : String,
|
|
28
|
+
/// Total number of iterations executed.
|
|
22
29
|
iterations : u64,
|
|
30
|
+
/// Total elapsed nanoseconds across all iterations.
|
|
23
31
|
total_ns : i64,
|
|
32
|
+
/// Average nanoseconds per iteration.
|
|
24
33
|
avg_ns : i64,
|
|
34
|
+
/// Minimum nanoseconds for a single iteration.
|
|
25
35
|
min_ns : i64,
|
|
36
|
+
/// Maximum nanoseconds for a single iteration.
|
|
26
37
|
max_ns : i64
|
|
27
38
|
);
|
|
28
39
|
|
|
@@ -61,7 +72,7 @@ export BenchResult;
|
|
|
61
72
|
// bench
|
|
62
73
|
// ============================================================================
|
|
63
74
|
|
|
64
|
-
|
|
75
|
+
/// Run `body` for `iterations` times and return timing statistics.
|
|
65
76
|
bench :: (fn(name: String, iterations: u64, body: Impl(Fn() -> unit)) -> BenchResult)({
|
|
66
77
|
total_ns := i64(0);
|
|
67
78
|
min_ns := i64(9223372036854775807); // i64::MAX
|
package/std/thread.yo
CHANGED
|
@@ -1,38 +1,47 @@
|
|
|
1
|
+
//! OS thread creation and management with per-thread IO event loops.
|
|
2
|
+
|
|
1
3
|
extern "Yo",
|
|
2
|
-
// Thread utilities
|
|
3
4
|
__yo_thread_get_hardware_threads : (fn() -> usize),
|
|
4
5
|
__yo_get_thread_id : (fn() -> usize),
|
|
5
6
|
__yo_get_cpu_id : (fn() -> i32)
|
|
6
7
|
;
|
|
7
8
|
|
|
8
|
-
// Low-level runtime types and functions for Thread
|
|
9
9
|
extern "Yo",
|
|
10
10
|
__yo_thread_t : Type,
|
|
11
11
|
__yo_thread_spawn : (fn(cb : Impl(Fn(using(io : IO)) -> unit, Send)) -> __yo_thread_t),
|
|
12
12
|
__yo_thread_join : (fn(t : __yo_thread_t) -> unit)
|
|
13
13
|
;
|
|
14
14
|
|
|
15
|
-
|
|
15
|
+
/// OS thread handle. Each spawned thread gets its own IO event loop.
|
|
16
16
|
Thread :: struct(
|
|
17
17
|
handle : __yo_thread_t
|
|
18
18
|
);
|
|
19
19
|
impl(Thread,
|
|
20
|
-
|
|
21
|
-
|
|
20
|
+
/// Spawn a new OS thread running the given closure.
|
|
21
|
+
/// The closure receives its own per-thread IO event loop.
|
|
22
22
|
spawn : (fn(cb : Impl(Fn(using(io : IO)) -> unit, Send)) -> Self)({
|
|
23
23
|
raw := __yo_thread_spawn(cb);
|
|
24
24
|
Self(raw)
|
|
25
25
|
}),
|
|
26
26
|
|
|
27
|
-
|
|
27
|
+
/// Block the current thread until this thread completes.
|
|
28
28
|
join : (fn(self : *(Self)) -> unit)(
|
|
29
29
|
__yo_thread_join(self.handle)
|
|
30
30
|
)
|
|
31
31
|
);
|
|
32
32
|
|
|
33
|
+
/// Get the number of hardware threads (CPU cores) available.
|
|
34
|
+
get_hardware_threads :: __yo_thread_get_hardware_threads;
|
|
35
|
+
|
|
36
|
+
/// Get the current OS thread ID.
|
|
37
|
+
get_thread_id :: __yo_get_thread_id;
|
|
38
|
+
|
|
39
|
+
/// Get the current CPU core ID.
|
|
40
|
+
get_cpu_id :: __yo_get_cpu_id;
|
|
41
|
+
|
|
33
42
|
export
|
|
34
|
-
get_hardware_threads
|
|
35
|
-
get_thread_id
|
|
36
|
-
get_cpu_id
|
|
43
|
+
get_hardware_threads,
|
|
44
|
+
get_thread_id,
|
|
45
|
+
get_cpu_id,
|
|
37
46
|
Thread
|
|
38
47
|
;
|
package/std/time/datetime.yo
CHANGED
|
@@ -1,23 +1,21 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
1
|
+
//! Wall-clock date and time in UTC.
|
|
2
|
+
//!
|
|
3
|
+
//! # Example
|
|
4
|
+
//!
|
|
5
|
+
//! ```rust
|
|
6
|
+
//! { DateTime } :: import "std/time/datetime";
|
|
7
|
+
//!
|
|
8
|
+
//! now := DateTime.now_utc();
|
|
9
|
+
//! println(now.to_string()); // "2026-02-26T17:41:24Z"
|
|
10
|
+
//! ```
|
|
11
11
|
|
|
12
12
|
{ String } :: import "../string";
|
|
13
13
|
{ ToString } :: import "../fmt";
|
|
14
14
|
{ CLOCK_REALTIME, clock_gettime } :: import "../sys/clock";
|
|
15
15
|
{ snprintf } :: import "../libc/stdio";
|
|
16
16
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
// ============================================================================
|
|
20
|
-
|
|
17
|
+
/// Calendar date and time with nanosecond precision.
|
|
18
|
+
/// Values are in UTC unless `utc_offset_secs` is non-zero.
|
|
21
19
|
DateTime :: struct(
|
|
22
20
|
year : i32,
|
|
23
21
|
month : u8,
|
package/std/time/duration.yo
CHANGED
|
@@ -1,22 +1,20 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
1
|
+
//! Duration type representing a span of time with nanosecond precision.
|
|
2
|
+
//!
|
|
3
|
+
//! # Example
|
|
4
|
+
//!
|
|
5
|
+
//! ```rust
|
|
6
|
+
//! { Duration } :: import "std/time/duration";
|
|
7
|
+
//!
|
|
8
|
+
//! d := Duration.from_millis(i64(500));
|
|
9
|
+
//! println(d.as_secs()); // 0
|
|
10
|
+
//! println(d.as_millis()); // 500
|
|
11
|
+
//! ```
|
|
11
12
|
|
|
12
13
|
{ String } :: import "../string";
|
|
13
14
|
{ ToString } :: import "../fmt";
|
|
14
15
|
{ snprintf } :: import "../libc/stdio";
|
|
15
16
|
|
|
16
|
-
|
|
17
|
-
// Duration
|
|
18
|
-
// ============================================================================
|
|
19
|
-
|
|
17
|
+
/// Span of time stored as seconds and nanoseconds.
|
|
20
18
|
Duration :: struct(
|
|
21
19
|
secs : i64,
|
|
22
20
|
nanos : i64
|
package/std/time/instant.yo
CHANGED
|
@@ -1,23 +1,20 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
//
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
1
|
+
//! Monotonic clock instant for measuring elapsed time.
|
|
2
|
+
//!
|
|
3
|
+
//! # Example
|
|
4
|
+
//!
|
|
5
|
+
//! ```rust
|
|
6
|
+
//! { Instant } :: import "std/time/instant";
|
|
7
|
+
//!
|
|
8
|
+
//! start := Instant.now();
|
|
9
|
+
//! // ... do work ...
|
|
10
|
+
//! elapsed := start.elapsed();
|
|
11
|
+
//! println(elapsed.as_millis());
|
|
12
|
+
//! ```
|
|
13
13
|
|
|
14
14
|
{ Duration } :: import "./duration";
|
|
15
15
|
{ CLOCK_MONOTONIC, clock_gettime } :: import "../sys/clock";
|
|
16
16
|
|
|
17
|
-
|
|
18
|
-
// Instant - monotonic clock snapshot
|
|
19
|
-
// ============================================================================
|
|
20
|
-
|
|
17
|
+
/// Snapshot from the monotonic clock. Use `elapsed` to measure durations.
|
|
21
18
|
Instant :: struct(
|
|
22
19
|
secs : i64,
|
|
23
20
|
nanos : i64
|
package/std/time/sleep.yo
CHANGED
|
@@ -1,16 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
//! Synchronous sleep — blocks the current thread.
|
|
2
|
+
//!
|
|
3
|
+
//! # Example
|
|
4
|
+
//!
|
|
5
|
+
//! ```rust
|
|
6
|
+
//! { sleep } :: import "std/time/sleep";
|
|
7
|
+
//! sleep(usize(100)); // sleep 100ms
|
|
8
|
+
//! ```
|
|
9
9
|
|
|
10
10
|
extern "Yo",
|
|
11
11
|
__yo_ms_sleep : (fn(ms: usize) -> unit)
|
|
12
12
|
;
|
|
13
13
|
|
|
14
|
+
/// Block the current thread for the given number of milliseconds.
|
|
14
15
|
sleep :: __yo_ms_sleep;
|
|
15
16
|
|
|
16
17
|
export
|