@shd101wyy/yo 0.1.12 → 0.1.14

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 +1447 -529
  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 +27 -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 +498 -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 +192 -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 +16 -15
  44. package/std/encoding/hex.yo +17 -10
  45. package/std/encoding/html.yo +17 -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 +39 -19
  49. package/std/encoding/punycode.yo +24 -18
  50. package/std/encoding/toml.yo +26 -9
  51. package/std/encoding/utf16.yo +19 -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 +40 -30
  58. package/std/fs/file.yo +80 -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 +31 -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/build.yo CHANGED
@@ -1,45 +1,65 @@
1
- // Build System Module
2
- //
3
- // Provides the declarative build API for Yo projects.
4
- // All functions are compile-time only they register build artifacts
5
- // and steps that the build runner uses to orchestrate compilation.
6
- //
7
- // Usage in build.yo:
8
- // build :: import "std/build";
9
- // mod :: build.module({ name: "my-app", root: "./src/lib.yo" });
10
- // exe :: build.executable({ name: "my-app", root: "./src/main.yo" });
11
- // install :: build.step("install", "Build all artifacts");
12
- // install.depend_on(exe);
1
+ //! Declarative build API for Yo projects.
2
+ //!
3
+ //! All functions are compile-time only they register build artifacts
4
+ //! and steps that the build runner uses to orchestrate compilation.
5
+ //!
6
+ //! # Example
7
+ //!
8
+ //! ```rust
9
+ //! build :: import "std/build";
10
+ //!
11
+ //! mod :: build.module({ name: "my-lib", root: "./src/lib.yo" });
12
+ //! exe :: build.executable({ name: "my-app", root: "./src/main.yo" });
13
+ //! install :: build.step("install", "Build all artifacts");
14
+ //! install.depend_on(exe);
15
+ //! ```
13
16
 
14
17
  // ── Optimization levels ──────────────────────────────────────────────
15
18
 
19
+ /// Optimization level for compiled artifacts.
16
20
  Optimize :: enum(
21
+ /// No optimizations, full debug info.
22
+ /// Compiler Flags: `-O0 -g`
17
23
  Debug,
24
+ /// Optimized with safety checks.
25
+ /// Compiler Flags: `-O2 -g`
18
26
  ReleaseSafe,
27
+ /// Maximum speed optimizations.
28
+ /// Compiler Flags: `-O3`
19
29
  ReleaseFast,
30
+ /// Optimize for binary size.
31
+ /// Compiler Flags `-O2`
20
32
  ReleaseSmall
21
33
  );
22
34
  export Optimize;
23
35
 
24
36
  // ── Memory allocators ────────────────────────────────────────────────
25
37
 
38
+ /// Memory allocator to use in the compiled artifact.
26
39
  Allocator :: enum(
40
+ /// High-performance allocator (mimalloc).
27
41
  Mimalloc,
42
+ /// Standard C library malloc.
28
43
  Libc
29
44
  );
30
45
  export Allocator;
31
46
 
32
47
  // ── Sanitizers ───────────────────────────────────────────────────────
33
48
 
49
+ /// Runtime sanitizer to enable.
34
50
  Sanitize :: enum(
51
+ /// No sanitizer.
35
52
  None,
53
+ /// AddressSanitizer — detects memory errors and leaks.
36
54
  Address,
55
+ /// LeakSanitizer — detects memory leaks only.
37
56
  Leak
38
57
  );
39
58
  export Sanitize;
40
59
 
41
60
  // ── Step kinds ───────────────────────────────────────────────────────
42
61
 
62
+ /// Kind of build step.
43
63
  StepKind :: enum(
44
64
  Executable,
45
65
  StaticLibrary,
@@ -47,7 +67,8 @@ StepKind :: enum(
47
67
  SystemLibrary,
48
68
  TestSuite,
49
69
  Run,
50
- Custom
70
+ Custom,
71
+ Documentation
51
72
  );
52
73
  export StepKind;
53
74
 
@@ -68,89 +89,118 @@ export CompilationTarget;
68
89
 
69
90
  // ── Target utilities ─────────────────────────────────────────────────
70
91
 
92
+ /// Host compilation target string.
71
93
  target_host :: __yo_build_target_host();
72
94
  export target_host;
73
95
 
74
96
  // ── Config struct types ──────────────────────────────────────────────
75
- // Struct types with defaults, like Zig's options structs.
76
- // Usage: build.executable({ name: "app", root: "./src/main.yo" })
77
- // Unspecified fields get their default values.
78
97
 
98
+ /// Configuration for building an executable.
79
99
  Executable :: struct(
100
+ /// Artifact name.
80
101
  name : comptime_string,
102
+ /// Root source file.
81
103
  root : comptime_string,
104
+ /// Compilation target triple (defaults to host).
82
105
  (target : comptime_string) ?= __yo_build_target_host(),
106
+ /// Optimization level.
83
107
  (optimize : Optimize) ?= Optimize.Debug,
108
+ /// Memory allocator.
84
109
  (allocator : Allocator) ?= Allocator.Libc,
110
+ /// Runtime sanitizer.
85
111
  (sanitize : Sanitize) ?= Sanitize.None
86
112
  );
87
113
  export Executable;
88
114
 
115
+ /// Configuration for building a static library.
89
116
  StaticLibrary :: struct(
117
+ /// Artifact name.
90
118
  name : comptime_string,
119
+ /// Root source file.
91
120
  root : comptime_string,
121
+ /// Compilation target triple (defaults to host).
92
122
  (target : comptime_string) ?= __yo_build_target_host(),
123
+ /// Optimization level.
93
124
  (optimize : Optimize) ?= Optimize.Debug
94
125
  );
95
126
  export StaticLibrary;
96
127
 
128
+ /// Configuration for building a shared/dynamic library.
97
129
  SharedLibrary :: struct(
130
+ /// Artifact name.
98
131
  name : comptime_string,
132
+ /// Root source file.
99
133
  root : comptime_string,
134
+ /// Compilation target triple (defaults to host).
100
135
  (target : comptime_string) ?= __yo_build_target_host(),
136
+ /// Optimization level.
101
137
  (optimize : Optimize) ?= Optimize.Debug
102
138
  );
103
139
  export SharedLibrary;
104
140
 
141
+ /// Configuration for a test suite.
105
142
  TestSuite :: struct(
143
+ /// Suite name.
106
144
  name : comptime_string,
145
+ /// Root test file.
107
146
  root : comptime_string,
147
+ /// Compilation target triple (defaults to host).
108
148
  (target : comptime_string) ?= __yo_build_target_host()
109
149
  );
110
150
  export TestSuite;
111
151
 
112
152
  // ── Build module type ────────────────────────────────────────────────
113
- // Represents a named source module that declares system library requirements.
114
- // Modules are the unit of reuse across Yo dependencies.
115
153
 
154
+ /// Represents a named source module that declares system library requirements.
155
+ /// Modules are the unit of reuse across Yo dependencies.
116
156
  BuildModule :: struct(
157
+ /// Module name.
117
158
  name : comptime_string,
159
+ /// Root source file.
118
160
  root : comptime_string,
119
- _dep : comptime_string // dependency name, empty for local modules
161
+ _dep : comptime_string
120
162
  );
121
163
  export BuildModule;
122
164
 
123
165
  // ── Import entry type ────────────────────────────────────────────────
124
- // Pairs an import name with a module for use with add_import/add_import_list.
125
166
 
167
+ /// Pairs an import name with a module for use with `add_import`/`add_import_list`.
126
168
  ImportEntry :: struct(
169
+ /// Import alias used in source code.
127
170
  name : comptime_string,
171
+ /// The module to import.
128
172
  module : BuildModule
129
173
  );
130
174
  export ImportEntry;
131
175
 
132
176
  // ── Step type ────────────────────────────────────────────────────────
133
- // Returned by all build functions. Used to wire dependencies between steps.
134
177
 
178
+ /// A build step returned by all registration functions.
179
+ /// Use `step.depend_on(dep)` to wire dependencies between steps.
135
180
  Step :: struct(
181
+ /// Step name.
136
182
  name : comptime_string,
183
+ /// Kind of step.
137
184
  kind : StepKind
138
185
  );
139
186
  export Step;
140
187
 
141
188
  // ── Step methods ─────────────────────────────────────────────────────
142
- // Methods on Step for Zig-like API: step.depend_on(other), exe.link(lib).
143
189
 
144
190
  impl(Step,
191
+ /// Add a dependency — `dep` must complete before this step runs.
145
192
  depend_on : (fn(comptime(self) : Self, comptime(dep) : Step) -> comptime(unit))({
146
193
  __yo_build_step_depend_on(self.name, dep.name, dep.kind);
147
194
  }),
195
+ /// Link a library step into this step.
148
196
  link : (fn(comptime(self) : Self, comptime(library) : Step) -> comptime(unit))({
149
197
  __yo_build_link(self.name, library.name);
150
198
  }),
199
+ /// Add a single module import to this step.
151
200
  add_import : (fn(comptime(self) : Self, comptime(entry) : ImportEntry) -> comptime(unit))({
152
201
  __yo_build_add_import(self.name, entry.name, entry.module.name, entry.module._dep);
153
202
  }),
203
+ /// Add a list of module imports to this step.
154
204
  add_import_list : (fn(comptime(self) : Self, comptime(entries) : ComptimeList(ImportEntry)) -> comptime(unit))({
155
205
  cond(
156
206
  (entries.len() == usize(0)) => (),
@@ -160,6 +210,7 @@ impl(Step,
160
210
  }
161
211
  )
162
212
  }),
213
+ /// Add extra C compiler flags to this step.
163
214
  add_c_flags : (fn(comptime(self) : Self, comptime(flags) : comptime_string) -> comptime(unit))({
164
215
  __yo_build_add_cflags(self.name, flags);
165
216
  })
@@ -168,6 +219,7 @@ impl(Step,
168
219
  // ── Build module methods ─────────────────────────────────────────────
169
220
 
170
221
  impl(BuildModule,
222
+ /// Link a system library into this module.
171
223
  link : (fn(comptime(self) : Self, comptime(library) : Step) -> comptime(unit))({
172
224
  __yo_build_module_link(self.name, library.name);
173
225
  })
@@ -177,34 +229,52 @@ impl(BuildModule,
177
229
  // Like Zig's b.option(), declare user-configurable options.
178
230
  // CLI usage: yo build -Dname=value
179
231
 
232
+ /// User-configurable build option (declared in `build.yo`, set via `yo build -Dname=value`).
180
233
  BuildOption :: struct(
234
+ /// Option name (used with `-D`).
181
235
  name : comptime_string,
236
+ /// Human-readable description.
182
237
  description : comptime_string,
238
+ /// Default value if not provided.
183
239
  (default : comptime_string) ?= ""
184
240
  );
185
241
  export BuildOption;
186
242
 
187
243
  // ── Dependency config types ──────────────────────────────────────────
188
244
 
245
+ /// Git-hosted dependency configuration.
189
246
  GitDependency :: struct(
247
+ /// Dependency name.
190
248
  name : comptime_string,
249
+ /// Git repository URL.
191
250
  url : comptime_string,
251
+ /// Git ref (tag, branch, or commit SHA). Defaults to `"HEAD"`.
192
252
  (ref : comptime_string) ?= "HEAD",
253
+ /// Subdirectory within the repository.
193
254
  (path : comptime_string) ?= ""
194
255
  );
195
256
  export GitDependency;
196
257
 
258
+ /// Local path dependency configuration.
197
259
  PathDependency :: struct(
260
+ /// Dependency name.
198
261
  name : comptime_string,
262
+ /// Filesystem path to the dependency root.
199
263
  path : comptime_string
200
264
  );
201
265
  export PathDependency;
202
266
 
267
+ /// System C library discovered via `pkg-config`.
203
268
  SystemLibrary :: struct(
269
+ /// Library name (passed to `pkg-config`).
204
270
  name : comptime_string,
271
+ /// Fallback include path if pkg-config fails.
205
272
  (fallback_include : comptime_string) ?= "",
273
+ /// Fallback library path.
206
274
  (fallback_lib : comptime_string) ?= "",
275
+ /// Fallback link flags.
207
276
  (fallback_link : comptime_string) ?= "",
277
+ /// Extra C preprocessor defines.
208
278
  (defines : comptime_string) ?= ""
209
279
  );
210
280
  export SystemLibrary;
@@ -213,20 +283,21 @@ export SystemLibrary;
213
283
  // Returned by build.dependency() and build.path_dependency().
214
284
  // Provides access to artifacts defined in the dependency's build.yo.
215
285
 
286
+ /// Handle to a registered dependency. Use `.artifact()` or `.module()` to access its exports.
216
287
  Dependency :: struct(
217
288
  name : comptime_string
218
289
  );
219
290
  export Dependency;
220
291
 
221
292
  impl(Dependency,
222
- // Access a named artifact from the dependency's build.yo.
223
- // Returns a Step that can be linked to the consumer's artifacts.
293
+ /// Access a named artifact from the dependency's `build.yo`.
294
+ /// Returns a `Step` that can be linked to the consumer's artifacts.
224
295
  artifact : (fn(comptime(self) : Self, comptime(artifact_name) : comptime_string) -> comptime(Step))({
225
296
  __yo_build_dep_artifact(self.name, artifact_name);
226
297
  Step(name: artifact_name, kind: StepKind.StaticLibrary)
227
298
  }),
228
- // Get a module from the dependency's build.yo.
229
- // Empty module_name defaults to the sole module if exactly one exists.
299
+ /// Get a module from the dependency's `build.yo`.
300
+ /// Empty `module_name` defaults to the sole module if exactly one exists.
230
301
  module : (fn(comptime(self) : Self, (comptime(module_name) : comptime_string) ?= "") -> comptime(BuildModule))({
231
302
  _encoded :: __yo_build_dep_module(self.name, module_name);
232
303
  BuildModule(name: module_name, root: "", _dep: self.name)
@@ -237,7 +308,7 @@ impl(Dependency,
237
308
  // All registration functions return a Step value, allowing steps to be
238
309
  // wired together as dependencies via step.depend_on(dep).
239
310
 
240
- // Register an executable artifact. Returns a Step for dependency wiring.
311
+ /// Register an executable artifact. Returns a `Step` for dependency wiring.
241
312
  executable :: (fn(comptime(config) : Executable) -> comptime(Step)) {
242
313
  opt_str :: match(config.optimize,
243
314
  .Debug => "debug",
@@ -259,7 +330,7 @@ executable :: (fn(comptime(config) : Executable) -> comptime(Step)) {
259
330
  };
260
331
  export executable;
261
332
 
262
- // Register a static library artifact. Returns a Step for dependency wiring.
333
+ /// Register a static library artifact. Returns a `Step` for dependency wiring.
263
334
  static_library :: (fn(comptime(config) : StaticLibrary) -> comptime(Step)) {
264
335
  opt_str :: match(config.optimize,
265
336
  .Debug => "debug",
@@ -272,7 +343,7 @@ static_library :: (fn(comptime(config) : StaticLibrary) -> comptime(Step)) {
272
343
  };
273
344
  export static_library;
274
345
 
275
- // Register a shared/dynamic library artifact. Returns a Step for dependency wiring.
346
+ /// Register a shared/dynamic library artifact. Returns a `Step` for dependency wiring.
276
347
  shared_library :: (fn(comptime(config) : SharedLibrary) -> comptime(Step)) {
277
348
  opt_str :: match(config.optimize,
278
349
  .Debug => "debug",
@@ -285,21 +356,21 @@ shared_library :: (fn(comptime(config) : SharedLibrary) -> comptime(Step)) {
285
356
  };
286
357
  export shared_library;
287
358
 
288
- // Register a test suite. Returns a Step for dependency wiring.
359
+ /// Register a test-suite artifact. Returns a `Step` for dependency wiring.
289
360
  test :: (fn(comptime(config) : TestSuite) -> comptime(Step)) {
290
361
  __yo_build_test(config.name, config.root, config.target);
291
362
  Step(name: config.name, kind: StepKind.TestSuite)
292
363
  };
293
364
  export test;
294
365
 
295
- // Create a run step (compile + execute an artifact). Returns a Step.
366
+ /// Create a run step (compile + execute an artifact). Returns a `Step`.
296
367
  run :: (fn(comptime(artifact) : Step) -> comptime(Step)) {
297
368
  __yo_build_run(artifact.name);
298
369
  Step(name: artifact.name, kind: StepKind.Run)
299
370
  };
300
371
  export run;
301
372
 
302
- // Register a named build step. Use step.depend_on(dep) to add dependencies.
373
+ /// Register a named build step. Use `step.depend_on(dep)` to add dependencies.
303
374
  step :: (fn(
304
375
  comptime(name) : comptime_string,
305
376
  comptime(description) : comptime_string
@@ -309,47 +380,126 @@ step :: (fn(
309
380
  };
310
381
  export step;
311
382
 
312
- // Register a git-hosted dependency. Returns a Dependency handle for accessing artifacts.
383
+ /// Register a git-hosted dependency. Returns a `Dependency` handle for accessing artifacts.
313
384
  dependency :: (fn(comptime(config) : GitDependency) -> comptime(Dependency)) {
314
385
  __yo_build_dependency(config.name, config.url, config.ref, config.path);
315
386
  Dependency(name: config.name)
316
387
  };
317
388
  export dependency;
318
389
 
319
- // Register a local path dependency. Returns a Dependency handle for accessing artifacts.
390
+ /// Register a local path dependency. Returns a `Dependency` handle for accessing artifacts.
320
391
  path_dependency :: (fn(comptime(config) : PathDependency) -> comptime(Dependency)) {
321
392
  __yo_build_path_dependency(config.name, config.path);
322
393
  Dependency(name: config.name)
323
394
  };
324
395
  export path_dependency;
325
396
 
326
- // Register a system C library discovered via pkg-config. Returns a Step for linking.
397
+ /// Register a system C library discovered via `pkg-config`. Returns a `Step` for linking.
327
398
  system_library :: (fn(comptime(config) : SystemLibrary) -> comptime(Step)) {
328
399
  __yo_build_system_library(config.name, config.fallback_include, config.fallback_lib, config.fallback_link, config.defines);
329
400
  Step(name: config.name, kind: StepKind.SystemLibrary)
330
401
  };
331
402
  export system_library;
332
403
 
333
- // ── Module config type ───────────────────────────────────────────────
334
-
404
+ /// Module configuration for shared compilation units.
335
405
  ModuleConfig :: struct(
406
+ /// Module name.
336
407
  name : comptime_string,
408
+ /// Root source file for the module.
337
409
  root : comptime_string
338
410
  );
339
411
  export ModuleConfig;
340
412
 
341
- // Register a named module. Returns a BuildModule for linking system libraries
342
- // and importing into executables/libraries.
413
+ /// Register a named module. Returns a `BuildModule` for linking system libraries
414
+ /// and importing into executables/libraries.
343
415
  _module :: (fn(comptime(config) : ModuleConfig) -> comptime(BuildModule)) {
344
416
  __yo_build_module(config.name, config.root);
345
417
  BuildModule(name: config.name, root: config.root, _dep: "")
346
418
  };
347
419
  export module : _module;
348
420
 
349
- // Declare a user-configurable build option.
350
- // Returns the option value (from CLI -Dname=value, or the default).
351
- // Usage: strip :: build.option({ name: "strip", description: "Strip debug symbols", default: "false" });
421
+ /// Declare a user-configurable build option.
422
+ /// Returns the option value (from CLI `-Dname=value`, or the default).
423
+ ///
424
+ /// # Example
425
+ /// ```rust
426
+ /// strip :: build.option({
427
+ /// name: "strip",
428
+ /// description: "Strip debug symbols",
429
+ /// default: "false"
430
+ /// });
431
+ /// ```
352
432
  option :: (fn(comptime(config) : BuildOption) -> comptime(str))(
353
433
  __yo_build_option(config.name, config.description, config.default)
354
434
  );
355
435
  export option;
436
+
437
+ // ── Documentation generation ─────────────────────────────────────────
438
+
439
+ /// Output format for documentation generation.
440
+ DocFormat :: enum(
441
+ Html,
442
+ Markdown,
443
+ Json
444
+ );
445
+ export DocFormat;
446
+
447
+ /// Configuration for documentation generation.
448
+ DocConfig :: struct(
449
+ /// Step name (e.g., "doc").
450
+ name : comptime_string,
451
+ /// Root source file or directory to document.
452
+ root : comptime_string,
453
+ /// Output directory (default: "yo-out/doc").
454
+ (output : comptime_string) ?= "yo-out/doc",
455
+ /// Output format (default: Html).
456
+ (format : DocFormat) ?= DocFormat.Html,
457
+ /// Document non-exported (private) items.
458
+ (include_private : bool) ?= false,
459
+ /// Document dependencies too.
460
+ (include_deps : bool) ?= false,
461
+ /// Custom site title (default: project name).
462
+ (title : comptime_string) ?= "",
463
+ /// Path to logo image.
464
+ (logo : comptime_string) ?= "",
465
+ /// Path to favicon.
466
+ (favicon : comptime_string) ?= ""
467
+ );
468
+ export DocConfig;
469
+
470
+ /// Register a documentation generation step. Returns a Step for dependency wiring.
471
+ ///
472
+ /// # Examples
473
+ ///
474
+ /// ```rust
475
+ /// build :: import "std/build";
476
+ ///
477
+ /// // Minimal — just works with defaults
478
+ /// doc_step :: build.doc({ name: "doc", root: "./src/lib.yo" });
479
+ ///
480
+ /// // Full customization
481
+ /// doc_step :: build.doc({
482
+ /// name: "doc",
483
+ /// root: "./src",
484
+ /// output: "docs/api",
485
+ /// format: DocFormat.Markdown,
486
+ /// title: "My Library API"
487
+ /// });
488
+ ///
489
+ /// install :: build.step("install", "Build all artifacts");
490
+ /// install.depend_on(doc_step);
491
+ /// ```
492
+ doc :: (fn(comptime(config) : DocConfig) -> comptime(Step)) {
493
+ fmt_str :: match(config.format,
494
+ .Html => "html",
495
+ .Markdown => "markdown",
496
+ .Json => "json"
497
+ );
498
+ __yo_build_doc(
499
+ config.name, config.root, config.output, fmt_str,
500
+ config.include_private, config.include_deps,
501
+ config.title, config.logo, config.favicon
502
+ );
503
+ Step(name: config.name, kind: StepKind.Documentation)
504
+ };
505
+ export doc;
@@ -1,17 +1,49 @@
1
+ //! Command-line argument parsing.
2
+ //!
3
+ //! Supports flags (`--verbose`), options (`--output file`), short aliases (`-v`),
4
+ //! and positional arguments. Automatically generates help text.
5
+ //!
6
+ //! # Example
7
+ //!
8
+ //! ```rust
9
+ //! { ArgParser } :: import "std/cli/arg_parser";
10
+ //!
11
+ //! parser := ArgParser.new(`myapp`, `A sample CLI tool`);
12
+ //! parser.flag(`verbose`, `v`, `Enable verbose output`);
13
+ //! parser.option(`output`, `o`, `Output file`, `out.txt`);
14
+ //! args := parser.parse();
15
+ //! ```
16
+
1
17
  open import "../collections/array_list";
2
18
  open import "../string";
3
19
 
4
- ArgKind :: enum(Flag, Opt, Positional);
20
+ /// Kind of command-line argument.
21
+ ArgKind :: enum(
22
+ /// Boolean flag (e.g. `--verbose`).
23
+ Flag,
24
+ /// Key-value option (e.g. `--output file`).
25
+ Opt,
26
+ /// Positional argument.
27
+ Positional
28
+ );
5
29
 
30
+ /// Definition of a single command-line argument.
6
31
  ArgDef :: object(
32
+ /// Long name (e.g. `"verbose"` for `--verbose`).
7
33
  _long_name : String,
34
+ /// Short name (e.g. `"v"` for `-v`).
8
35
  _short_name : String,
36
+ /// Human-readable description for help text.
9
37
  _description : String,
38
+ /// Kind of argument (flag, option, or positional).
10
39
  _kind : ArgKind,
40
+ /// Default value for options.
11
41
  _default_value : String,
42
+ /// Whether this argument is required.
12
43
  _required : bool
13
44
  );
14
45
 
46
+ /// Result of parsing command-line arguments.
15
47
  ParsedArgs :: object(
16
48
  _set_flags : ArrayList(String),
17
49
  _option_names : ArrayList(String),
@@ -20,9 +52,13 @@ ParsedArgs :: object(
20
52
  _positional_names : ArrayList(String)
21
53
  );
22
54
 
55
+ /// Command-line argument parser.
23
56
  ArgParser :: object(
57
+ /// Application name shown in help text.
24
58
  _name : String,
59
+ /// Application description shown in help text.
25
60
  _description : String,
61
+ /// Registered argument definitions.
26
62
  _args : ArrayList(ArgDef)
27
63
  );
28
64
 
@@ -1,33 +1,21 @@
1
- /**
2
- * ArrayList - A dynamic array implementation for Yo language
3
- *
4
- * Similar to Rust's Vec<T> and Zig's ArrayList, this ArrayList provides:
5
- * - Dynamic resizing
6
- * - ~~Memory management via custom allocator~~
7
- * - Type safety
8
- * - RAII for automatic cleanup
9
- */
1
+ //! Dynamic array (vector) with amortized O(1) push and O(1) indexed access.
2
+
10
3
  { GlobalAllocator, AllocError } :: import "../allocator.yo";
11
4
  { memmove, memcpy, memset } :: import "../libc/string.yo";
12
5
  { malloc, calloc, realloc, free, aligned_alloc } :: GlobalAllocator;
13
6
 
14
- /**
15
- * ArrayList error types
16
- */
7
+ /// Error variants for ArrayList operations.
17
8
  ArrayListError :: enum(
9
+ /// Memory allocation failed.
18
10
  AllocError(error : AllocError),
11
+ /// Index is out of bounds for the current length.
19
12
  IndexOutOfBounds(index: usize, length: usize),
13
+ /// Attempted to access an element from an empty list.
20
14
  EmptyList
21
15
  );
22
16
 
23
- /**
24
- * ArrayList type - a growable array
25
- *
26
- * Memory layout:
27
- * - ptr: pointer to the heap-allocated buffer
28
- * - _length: current number of elements
29
- * - _capacity: total capacity of the buffer
30
- */
17
+ /// Generic growable array similar to Rust's `Vec<T>`.
18
+ /// Heap-allocated with automatic resizing and reference-counted cleanup.
31
19
  ArrayList :: (fn(comptime(T): Type) -> comptime(Type))(
32
20
  object(
33
21
  _ptr : ?*(T),
@@ -1,23 +1,20 @@
1
- // std/collections/btree_map.yo - Sorted map backed by a sorted ArrayList
2
- //
3
- // BTreeMap maintains entries sorted by key, enabling ordered iteration and
4
- // O(log n) lookups via binary search. Insert is O(n) (shift-based).
5
- //
6
- // Example:
7
- // { BTreeMap } :: import "std/collections/btree_map";
8
- //
9
- // m := BTreeMap(String, i32).new();
10
- // m.set(String.from("b"), 2);
11
- // m.set(String.from("a"), 1);
12
- // // Iteration order: a, b
1
+ //! Sorted map backed by a sorted array with O(log n) lookup via binary search.
2
+ //!
3
+ //! # Example
4
+ //!
5
+ //! ```rust
6
+ //! { BTreeMap } :: import "std/collections/btree_map";
7
+ //!
8
+ //! m := BTreeMap(String, i32).new();
9
+ //! m.set(String.from("b"), 2);
10
+ //! m.set(String.from("a"), 1);
11
+ //! // Iteration order: a, b
12
+ //! ```
13
13
 
14
14
  { ArrayList } :: import "./array_list";
15
15
  open import "../string";
16
16
 
17
- // ============================================================================
18
- // BTreeEntry - key/value pair
19
- // ============================================================================
20
-
17
+ /// Key-value pair entry stored in a BTreeMap.
21
18
  BTreeEntry :: (fn(comptime(K) : Type, comptime(V) : Type) -> comptime(Type))(
22
19
  struct(key: K, value: V)
23
20
  );
@@ -27,10 +24,8 @@ export BTreeEntry;
27
24
  // Internal result from binary search.
28
25
  _FindResult :: struct(idx: usize, found: bool);
29
26
 
30
- // ============================================================================
31
- // BTreeMap
32
- // ============================================================================
33
-
27
+ /// Sorted map maintaining entries in key order.
28
+ /// Provides ordered iteration and O(log n) lookup via binary search. Insert is O(n).
34
29
  BTreeMap :: (fn(comptime(K) : Type, comptime(V) : Type) -> comptime(Type))(
35
30
  object(
36
31
  _entries : ArrayList(BTreeEntry(K, V))