@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.
Files changed (164) hide show
  1. package/README.md +10 -1
  2. package/out/cjs/index.cjs +578 -572
  3. package/out/cjs/yo-cli.cjs +1413 -592
  4. package/out/esm/index.mjs +434 -428
  5. package/out/types/src/build-runner.d.ts +1 -1
  6. package/out/types/src/doc/builder.d.ts +21 -0
  7. package/out/types/src/doc/builder.test.d.ts +1 -0
  8. package/out/types/src/doc/extractor.d.ts +27 -0
  9. package/out/types/src/doc/extractor.test.d.ts +1 -0
  10. package/out/types/src/doc/model.d.ts +87 -0
  11. package/out/types/src/doc/render-html.d.ts +23 -0
  12. package/out/types/src/doc/render-html.test.d.ts +1 -0
  13. package/out/types/src/doc/render-json.d.ts +7 -0
  14. package/out/types/src/doc/render-json.test.d.ts +1 -0
  15. package/out/types/src/doc/render-markdown.d.ts +13 -0
  16. package/out/types/src/doc/render-markdown.test.d.ts +1 -0
  17. package/out/types/src/doc/sections.d.ts +7 -0
  18. package/out/types/src/doc/sections.test.d.ts +1 -0
  19. package/out/types/src/doc-command.d.ts +10 -0
  20. package/out/types/src/env.d.ts +1 -0
  21. package/out/types/src/evaluator/builtins/build.d.ts +17 -0
  22. package/out/types/src/evaluator/context.d.ts +1 -0
  23. package/out/types/src/expr.d.ts +2 -1
  24. package/out/types/src/token.d.ts +4 -0
  25. package/out/types/tsconfig.tsbuildinfo +1 -1
  26. package/package.json +2 -1
  27. package/scripts/build-site.ts +461 -0
  28. package/std/alg/hash.yo +12 -24
  29. package/std/allocator.yo +21 -29
  30. package/std/async.yo +4 -2
  31. package/std/build.yo +188 -42
  32. package/std/cli/arg_parser.yo +37 -1
  33. package/std/collections/array_list.yo +8 -20
  34. package/std/collections/btree_map.yo +15 -20
  35. package/std/collections/deque.yo +13 -15
  36. package/std/collections/hash_map.yo +15 -54
  37. package/std/collections/hash_set.yo +14 -50
  38. package/std/collections/linked_list.yo +6 -23
  39. package/std/collections/priority_queue.yo +15 -17
  40. package/std/crypto/md5.yo +10 -9
  41. package/std/crypto/random.yo +14 -12
  42. package/std/crypto/sha256.yo +9 -8
  43. package/std/encoding/base64.yo +13 -15
  44. package/std/encoding/hex.yo +14 -10
  45. package/std/encoding/html.yo +14 -11
  46. package/std/encoding/html_char_utils.yo +14 -11
  47. package/std/encoding/html_entities.yo +7 -8
  48. package/std/encoding/json.yo +36 -19
  49. package/std/encoding/punycode.yo +21 -18
  50. package/std/encoding/toml.yo +23 -9
  51. package/std/encoding/utf16.yo +16 -9
  52. package/std/error.yo +10 -23
  53. package/std/fmt/display.yo +15 -17
  54. package/std/fmt/index.yo +6 -27
  55. package/std/fmt/to_string.yo +4 -10
  56. package/std/fmt/writer.yo +33 -34
  57. package/std/fs/dir.yo +37 -30
  58. package/std/fs/file.yo +77 -75
  59. package/std/fs/metadata.yo +25 -25
  60. package/std/fs/temp.yo +21 -27
  61. package/std/fs/types.yo +20 -23
  62. package/std/fs/walker.yo +26 -31
  63. package/std/gc.yo +5 -0
  64. package/std/glob/index.yo +3 -0
  65. package/std/http/client.yo +25 -11
  66. package/std/http/http.yo +20 -0
  67. package/std/http/index.yo +1 -0
  68. package/std/io/reader.yo +4 -8
  69. package/std/io/writer.yo +4 -7
  70. package/std/libc/assert.yo +2 -2
  71. package/std/libc/ctype.yo +1 -2
  72. package/std/libc/dirent.yo +1 -2
  73. package/std/libc/errno.yo +1 -2
  74. package/std/libc/fcntl.yo +2 -2
  75. package/std/libc/float.yo +1 -2
  76. package/std/libc/limits.yo +1 -2
  77. package/std/libc/math.yo +2 -0
  78. package/std/libc/signal.yo +1 -2
  79. package/std/libc/stdatomic.yo +1 -2
  80. package/std/libc/stdint.yo +4 -3
  81. package/std/libc/stdio.yo +2 -0
  82. package/std/libc/stdlib.yo +2 -0
  83. package/std/libc/string.yo +2 -0
  84. package/std/libc/sys/stat.yo +1 -2
  85. package/std/libc/time.yo +2 -2
  86. package/std/libc/unistd.yo +2 -0
  87. package/std/libc/wctype.yo +1 -2
  88. package/std/libc/windows.yo +2 -2
  89. package/std/log/index.yo +11 -26
  90. package/std/net/addr.yo +18 -11
  91. package/std/net/dns.yo +3 -2
  92. package/std/net/errors.yo +16 -2
  93. package/std/net/tcp.yo +25 -22
  94. package/std/net/udp.yo +14 -12
  95. package/std/os/env.yo +23 -18
  96. package/std/os/signal.yo +31 -19
  97. package/std/path.yo +23 -74
  98. package/std/prelude.yo +284 -113
  99. package/std/process.yo +23 -37
  100. package/std/regex/compiler.yo +3 -5
  101. package/std/regex/flags.yo +11 -11
  102. package/std/regex/index.yo +2 -13
  103. package/std/regex/match.yo +3 -5
  104. package/std/regex/node.yo +6 -6
  105. package/std/regex/parser.yo +2 -4
  106. package/std/regex/unicode.yo +5 -5
  107. package/std/regex/vm.yo +5 -5
  108. package/std/string/index.yo +2 -1
  109. package/std/string/rune.yo +25 -1
  110. package/std/string/string.yo +31 -19
  111. package/std/string/unicode.yo +14 -15
  112. package/std/sync/channel.yo +18 -28
  113. package/std/sync/cond.yo +4 -0
  114. package/std/sync/mutex.yo +4 -1
  115. package/std/sync/once.yo +17 -19
  116. package/std/sync/rwlock.yo +19 -22
  117. package/std/sync/waitgroup.yo +21 -23
  118. package/std/sys/advise.yo +4 -4
  119. package/std/sys/bufio/buf_reader.yo +19 -16
  120. package/std/sys/bufio/buf_writer.yo +14 -11
  121. package/std/sys/clock.yo +4 -4
  122. package/std/sys/constants.yo +5 -5
  123. package/std/sys/copy.yo +9 -8
  124. package/std/sys/dir.yo +9 -8
  125. package/std/sys/dns.yo +8 -8
  126. package/std/sys/errors.yo +35 -6
  127. package/std/sys/events.yo +3 -3
  128. package/std/sys/externs.yo +3 -3
  129. package/std/sys/fallocate.yo +4 -4
  130. package/std/sys/fcntl.yo +8 -6
  131. package/std/sys/file.yo +7 -8
  132. package/std/sys/future.yo +1 -3
  133. package/std/sys/iov.yo +4 -4
  134. package/std/sys/lock.yo +7 -7
  135. package/std/sys/mmap.yo +7 -8
  136. package/std/sys/path.yo +4 -7
  137. package/std/sys/perm.yo +8 -8
  138. package/std/sys/pipe.yo +9 -8
  139. package/std/sys/process.yo +8 -8
  140. package/std/sys/seek.yo +4 -4
  141. package/std/sys/signal.yo +4 -4
  142. package/std/sys/signals.yo +4 -4
  143. package/std/sys/socket.yo +4 -4
  144. package/std/sys/socketpair.yo +4 -4
  145. package/std/sys/sockinfo.yo +4 -4
  146. package/std/sys/statfs.yo +8 -8
  147. package/std/sys/statx.yo +4 -4
  148. package/std/sys/sysinfo.yo +4 -4
  149. package/std/sys/tcp.yo +8 -8
  150. package/std/sys/temp.yo +9 -8
  151. package/std/sys/time.yo +8 -8
  152. package/std/sys/timer.yo +7 -8
  153. package/std/sys/tty.yo +13 -10
  154. package/std/sys/udp.yo +8 -8
  155. package/std/sys/umask.yo +4 -4
  156. package/std/sys/unix.yo +5 -5
  157. package/std/testing/bench.yo +21 -10
  158. package/std/thread.yo +18 -9
  159. package/std/time/datetime.yo +12 -14
  160. package/std/time/duration.yo +12 -14
  161. package/std/time/instant.yo +13 -16
  162. package/std/time/sleep.yo +9 -8
  163. package/std/url/index.yo +3 -19
  164. package/std/worker.yo +10 -18
package/std/sys/pipe.yo CHANGED
@@ -1,11 +1,12 @@
1
- // std/sys/pipe.yo - 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
- // - pipe: 0 on success, -errno on failure
8
- // - dup/dup2: new fd on success, -errno on failure
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
 
@@ -1,11 +1,11 @@
1
- // std/sys/process.yo - 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.
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
- // std/sys/seek.yo - File position control
2
- //
3
- // Synchronous wrapper for lseek.
4
- // Returns resulting absolute file offset on success, -errno on failure.
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
- // std/sys/signal.yo - Signal handling functions
2
- //
3
- // Provides low-level wrappers for signal registration and delivery.
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, __yo_as(handler, *(u8)))
12
+ __yo_signal_start(signum, unsafe.cast(handler, *(u8)))
13
13
  });
14
14
 
15
15
  // Remove a signal handler (reset to default).
@@ -1,7 +1,7 @@
1
- // std/sys/signals.yo - POSIX signal constants
2
- //
3
- // Platform-aware signal numbers.
4
- // Uses process.platform for values that differ between Linux and macOS.
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
- // std/sys/socket.yo - 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.
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
  {
@@ -1,7 +1,7 @@
1
- // std/sys/socketpair.yo - Connected socket pair
2
- //
3
- // Synchronous wrapper for socketpair-like behavior.
4
- // Returns 0 on success, negative error on failure.
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
 
@@ -1,7 +1,7 @@
1
- // std/sys/sockinfo.yo - 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.
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
- // std/sys/statfs.yo - 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
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
- // std/sys/statx.yo - Statx file status type
2
- //
3
- // Object wrapper around the C statx buffer, providing
4
- // accessor methods for file metadata.
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
@@ -1,7 +1,7 @@
1
- // std/sys/sysinfo.yo - Runtime system identification
2
- //
3
- // Synchronous wrappers for uname/gethostname.
4
- // Returns 0 on success, -errno / negative platform error on failure.
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
- // std/sys/tcp.yo - 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
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
- // std/sys/temp.yo - Temporary file/directory operations
2
- //
3
- // Synchronous wrappers for mkdtemp/mkstemp.
4
- // These are inherently synchronous on all platforms.
5
- //
6
- // Return values:
7
- // - mkdtemp: 0 on success, -errno on failure
8
- // - mkstemp: fd on success, -errno on failure
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
- // std/sys/time.yo - 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
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
- // std/sys/timer.yo - 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
- // (timerfd read size on Linux) or a negative errno.
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
- // std/sys/tty.yo - TTY operations
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
- // Initialize TTY for a fd.
12
- // Returns 0 on success, -errno on failure.
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
- // Set TTY mode (normal, raw, IO).
18
- // Returns 0 on success, -errno on failure.
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
- // Reset TTY to original mode.
24
- // Returns 0 on success, -errno on failure.
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
- // Get terminal window size.
30
- // Returns width and height (0,0 on error).
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
- // Check if fd is a TTY.
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
- // std/sys/udp.yo - 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
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
- // std/sys/umask.yo - Process file creation mask
2
- //
3
- // Synchronous wrapper for setting process umask.
4
- // Returns previous mask value.
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
- // std/sys/unix.yo - 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.
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;
@@ -1,12 +1,16 @@
1
- // std/testing/bench.yo - Micro-benchmarking utilities
2
- //
3
- // Runs a function N times, measures elapsed nanoseconds, and returns statistics.
4
- //
5
- // Example:
6
- // { bench } :: import "std/testing/bench";
7
- //
8
- // result := bench(String.from("sort"), u64(1000), () => { /* ... */ });
9
- // println(result.to_string());
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
- // Run `body` `iterations` times and return timing statistics.
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
- // High-level Thread wrapper - a simple struct (stack allocated)
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
- // Spawn a new OS thread running the given closure.
21
- // The closure receives its own per-thread IO event loop.
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
- // Wait for the thread to complete (blocking)
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 : __yo_thread_get_hardware_threads,
35
- get_thread_id : __yo_get_thread_id,
36
- get_cpu_id : __yo_get_cpu_id,
43
+ get_hardware_threads,
44
+ get_thread_id,
45
+ get_cpu_id,
37
46
  Thread
38
47
  ;
@@ -1,23 +1,21 @@
1
- // std/time/datetime.yo - Wall-clock date/time
2
- //
3
- // DateTime represents a calendar date and time of day.
4
- // All values are in UTC unless utc_offset_secs is non-zero.
5
- //
6
- // Example:
7
- // { DateTime } :: import "std/time/datetime";
8
- //
9
- // now := DateTime.now_utc();
10
- // println(now.to_string()); // "2026-02-26T17:41:24Z"
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
- // DateTime
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,
@@ -1,22 +1,20 @@
1
- // std/time/duration.yo - Duration type
2
- //
3
- // Represents a span of time with nanosecond precision.
4
- //
5
- // Example:
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
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
@@ -1,23 +1,20 @@
1
- // std/time/instant.yo - Monotonic clock instant
2
- //
3
- // Instant captures a point in time from the monotonic clock.
4
- // Use it to measure elapsed time. Not suitable for wall-clock times.
5
- //
6
- // Example:
7
- // { Instant } :: import "std/time/instant";
8
- //
9
- // start := Instant.now();
10
- // // ... do work ...
11
- // elapsed := start.elapsed();
12
- // println(elapsed.as_millis());
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
- // std/time/sleep.yo - Synchronous sleep
2
- //
3
- // Blocks the current thread for the given number of milliseconds.
4
- // For async (non-blocking) sleep, use std/sys/timer.yo instead.
5
- //
6
- // Example:
7
- // { sleep } :: import "std/time/sleep";
8
- // sleep(usize(100)); // sleep 100ms
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