@shd101wyy/yo 0.1.11 → 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 +579 -573
- package/out/cjs/yo-cli.cjs +1413 -592
- package/out/esm/index.mjs +437 -431
- 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/evaluator/exprs/import.d.ts +2 -0
- package/out/types/src/expr.d.ts +2 -1
- package/out/types/src/tests/import-path.test.d.ts +1 -0
- 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/prelude.yo
CHANGED
|
@@ -1,19 +1,26 @@
|
|
|
1
1
|
// @skip_prelude
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
2
|
+
//! Prelude — automatically imported into every Yo source file.
|
|
3
|
+
//!
|
|
4
|
+
//! Provides core language primitives: traits (`Comptime`, `Runtime`, `Clone`,
|
|
5
|
+
//! `Eq`, `Ord`, `Hash`, …), fundamental types (`Option`, `Result`, `Box`,
|
|
6
|
+
//! `Slice`, `Range`, `String`, …), operator traits (`Add`, `Sub`, …), type
|
|
7
|
+
//! reflection (`TypeInfo`), conversion (`Into`, `From`), the async runtime
|
|
8
|
+
//! (`IO`, `Future`, `JoinHandle`), and derive rules.
|
|
9
|
+
//!
|
|
10
|
+
//! **Do NOT import `std/prelude`** — it is loaded automatically and an
|
|
11
|
+
//! explicit import will produce a compile error.
|
|
12
|
+
|
|
13
|
+
/// Comptime trait — indicates a type that can be used at compile-time.
|
|
14
|
+
/// Examples: `i32`, `bool`, `Type`, `comptime_int`, `comptime_float`, `comptime_string`.
|
|
15
|
+
/// Non-examples: `int`, `ushort` (runtime-only types).
|
|
9
16
|
Comptime :: trait(
|
|
10
17
|
id := "Comptime"
|
|
11
18
|
);
|
|
12
19
|
export Comptime;
|
|
13
20
|
|
|
14
|
-
/// Runtime trait
|
|
15
|
-
/// Examples: i32
|
|
16
|
-
/// Non-examples: comptime_int
|
|
21
|
+
/// Runtime trait — indicates a type that can be used at runtime.
|
|
22
|
+
/// Examples: `i32`, `bool`, `*(i32)`, `void`.
|
|
23
|
+
/// Non-examples: `comptime_int`, `comptime_float`, `comptime_string`, `Type` (compile-time-only types).
|
|
17
24
|
Runtime :: trait(
|
|
18
25
|
id := "Runtime"
|
|
19
26
|
);
|
|
@@ -118,13 +125,15 @@ extern "Yo",
|
|
|
118
125
|
;
|
|
119
126
|
export __yo_as;
|
|
120
127
|
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
// unsafe module
|
|
128
|
+
/// The `unsafe` module — provides low-level escape hatches.
|
|
124
129
|
unsafe :: impl {
|
|
130
|
+
/// Manually drop `value`, running its destructor immediately.
|
|
125
131
|
drop :: (fn(quote(value) : Expr) -> unquote(Expr))
|
|
126
132
|
quote(___drop(unquote(value)));
|
|
127
133
|
export drop;
|
|
134
|
+
|
|
135
|
+
cast :: __yo_as;
|
|
136
|
+
export cast;
|
|
128
137
|
};
|
|
129
138
|
export unsafe;
|
|
130
139
|
|
|
@@ -156,7 +165,7 @@ export unsafe;
|
|
|
156
165
|
// };
|
|
157
166
|
// export c_macro;
|
|
158
167
|
|
|
159
|
-
///
|
|
168
|
+
/// Send trait — indicates a type that can be safely transferred between threads.
|
|
160
169
|
Send :: trait(
|
|
161
170
|
id := "Send"
|
|
162
171
|
);
|
|
@@ -185,7 +194,9 @@ Dispose :: trait(
|
|
|
185
194
|
);
|
|
186
195
|
export Dispose;
|
|
187
196
|
|
|
188
|
-
///
|
|
197
|
+
/// Index trait — enables `container(idx)` subscript syntax at runtime.
|
|
198
|
+
/// The `Idx` parameter is the index type (e.g., `usize`, `Range(usize)`).
|
|
199
|
+
/// Implementations must define an `Output` associated type and an `index` method.
|
|
189
200
|
Index :: (fn(comptime(Idx) : Type) -> comptime(Trait))(
|
|
190
201
|
trait(
|
|
191
202
|
Output : Type,
|
|
@@ -194,6 +205,7 @@ Index :: (fn(comptime(Idx) : Type) -> comptime(Trait))(
|
|
|
194
205
|
);
|
|
195
206
|
export Index;
|
|
196
207
|
|
|
208
|
+
/// ComptimeIndex — compile-time indexing trait for constant expressions.
|
|
197
209
|
ComptimeIndex :: (fn(comptime(Idx) : Type, where(Idx <: Comptime)) -> comptime(Trait))(
|
|
198
210
|
trait(
|
|
199
211
|
Output : Type,
|
|
@@ -203,23 +215,25 @@ ComptimeIndex :: (fn(comptime(Idx) : Type, where(Idx <: Comptime)) -> comptime(T
|
|
|
203
215
|
);
|
|
204
216
|
export ComptimeIndex;
|
|
205
217
|
|
|
206
|
-
///
|
|
218
|
+
/// Half-open range `start..end` (excludes `end`).
|
|
207
219
|
Range :: (fn(comptime(T) : Type) -> comptime(Type))(
|
|
208
220
|
struct(start : T, end : T)
|
|
209
221
|
);
|
|
210
222
|
export Range;
|
|
211
223
|
|
|
224
|
+
/// Inclusive range `start..=end` (includes `end`).
|
|
212
225
|
RangeInclusive :: (fn(comptime(T) : Type) -> comptime(Type))(
|
|
213
226
|
struct(start : T, end : T)
|
|
214
227
|
);
|
|
215
228
|
export RangeInclusive;
|
|
216
229
|
|
|
217
|
-
///
|
|
230
|
+
/// RangeOp trait — enables `start..end` operator syntax.
|
|
218
231
|
RangeOp :: trait(
|
|
219
232
|
(..) : (fn(start: Self, end: Self) -> Range(Self))
|
|
220
233
|
);
|
|
221
234
|
export RangeOp;
|
|
222
235
|
|
|
236
|
+
/// RangeInclusiveOp trait — enables `start..=end` operator syntax.
|
|
223
237
|
RangeInclusiveOp :: trait(
|
|
224
238
|
(..=) : (fn(start: Self, end: Self) -> RangeInclusive(Self))
|
|
225
239
|
);
|
|
@@ -277,15 +291,17 @@ ComptimeRangeInclusiveOp :: trait(
|
|
|
277
291
|
);
|
|
278
292
|
export ComptimeRangeInclusiveOp;
|
|
279
293
|
|
|
280
|
-
///
|
|
294
|
+
/// Add trait — enables `lhs + rhs` operator. Parameterized by `Rhs` type.
|
|
281
295
|
Add :: (fn(comptime(Rhs) : Type)-> comptime(Trait))(
|
|
282
296
|
trait(
|
|
297
|
+
/// The output type of the addition.
|
|
283
298
|
Output : Type,
|
|
284
299
|
(+) : (fn(lhs: Self, rhs: Rhs) -> Self.Output)
|
|
285
300
|
)
|
|
286
301
|
);
|
|
287
302
|
export Add;
|
|
288
303
|
|
|
304
|
+
/// Compile-time variant of `Add`.
|
|
289
305
|
ComptimeAdd :: (fn(comptime(Rhs) : Type, where(Rhs <: Comptime))-> comptime(Trait))(
|
|
290
306
|
trait(
|
|
291
307
|
Output : Type,
|
|
@@ -295,6 +311,7 @@ ComptimeAdd :: (fn(comptime(Rhs) : Type, where(Rhs <: Comptime))-> comptime(Trai
|
|
|
295
311
|
);
|
|
296
312
|
export ComptimeAdd;
|
|
297
313
|
|
|
314
|
+
/// Sub trait — enables `lhs - rhs` operator.
|
|
298
315
|
Sub :: (fn(comptime(Rhs) : Type)-> comptime(Trait))(
|
|
299
316
|
trait(
|
|
300
317
|
Output : Type,
|
|
@@ -312,6 +329,7 @@ ComptimeSub :: (fn(comptime(Rhs) : Type, where(Rhs <: Comptime))-> comptime(Trai
|
|
|
312
329
|
);
|
|
313
330
|
export ComptimeSub;
|
|
314
331
|
|
|
332
|
+
/// Mul trait — enables `lhs * rhs` operator.
|
|
315
333
|
Mul :: (fn(comptime(Rhs) : Type)-> comptime(Trait))(
|
|
316
334
|
trait(
|
|
317
335
|
Output : Type,
|
|
@@ -329,6 +347,7 @@ ComptimeMul :: (fn(comptime(Rhs) : Type, where(Rhs <: Comptime))-> comptime(Trai
|
|
|
329
347
|
);
|
|
330
348
|
export ComptimeMul;
|
|
331
349
|
|
|
350
|
+
/// Div trait — enables `lhs / rhs` operator.
|
|
332
351
|
Div :: (fn(comptime(Rhs) : Type)-> comptime(Trait))(
|
|
333
352
|
trait(
|
|
334
353
|
Output : Type,
|
|
@@ -346,6 +365,7 @@ ComptimeDiv :: (fn(comptime(Rhs) : Type, where(Rhs <: Comptime))-> comptime(Trai
|
|
|
346
365
|
);
|
|
347
366
|
export ComptimeDiv;
|
|
348
367
|
|
|
368
|
+
/// Mod trait — enables `lhs % rhs` operator.
|
|
349
369
|
Mod :: (fn(comptime(Rhs) : Type)-> comptime(Trait))(
|
|
350
370
|
trait(
|
|
351
371
|
Output : Type,
|
|
@@ -363,6 +383,7 @@ ComptimeMod :: (fn(comptime(Rhs) : Type, where(Rhs <: Comptime))-> comptime(Trai
|
|
|
363
383
|
);
|
|
364
384
|
export ComptimeMod;
|
|
365
385
|
|
|
386
|
+
/// BitLeftShift trait — enables `lhs << rhs` operator.
|
|
366
387
|
BitLeftShift :: (fn(comptime(Rhs) : Type)-> comptime(Trait))(
|
|
367
388
|
trait(
|
|
368
389
|
Output : Type,
|
|
@@ -380,6 +401,7 @@ ComptimeBitLeftShift :: (fn(comptime(Rhs) : Type, where(Rhs <: Comptime))-> comp
|
|
|
380
401
|
);
|
|
381
402
|
export ComptimeBitLeftShift;
|
|
382
403
|
|
|
404
|
+
/// BitRightShift trait — enables `lhs >> rhs` operator.
|
|
383
405
|
BitRightShift :: (fn(comptime(Rhs) : Type)-> comptime(Trait))(
|
|
384
406
|
trait(
|
|
385
407
|
Output : Type,
|
|
@@ -397,6 +419,7 @@ ComptimeBitRightShift :: (fn(comptime(Rhs) : Type, where(Rhs <: Comptime))-> com
|
|
|
397
419
|
);
|
|
398
420
|
export ComptimeBitRightShift;
|
|
399
421
|
|
|
422
|
+
/// Exponentiation trait — enables `lhs ** rhs` operator.
|
|
400
423
|
Exponentiation :: (fn(comptime(Rhs) : Type)-> comptime(Trait))(
|
|
401
424
|
trait(
|
|
402
425
|
Output : Type,
|
|
@@ -414,6 +437,7 @@ ComptimeExponentiation :: (fn(comptime(Rhs) : Type, where(Rhs <: Comptime))-> co
|
|
|
414
437
|
);
|
|
415
438
|
export ComptimeExponentiation;
|
|
416
439
|
|
|
440
|
+
/// Negate trait — enables unary `-value` operator.
|
|
417
441
|
Negate :: trait(
|
|
418
442
|
Output : Type,
|
|
419
443
|
(neg): (fn(self: Self) -> Self.Output)
|
|
@@ -427,7 +451,7 @@ ComptimeNegate :: trait(
|
|
|
427
451
|
);
|
|
428
452
|
export ComptimeNegate;
|
|
429
453
|
|
|
430
|
-
///
|
|
454
|
+
/// LogicalNot trait — enables `!value` boolean negation.
|
|
431
455
|
LogicalNot :: trait
|
|
432
456
|
(!) : (fn(self: Self)-> bool)
|
|
433
457
|
;
|
|
@@ -439,6 +463,7 @@ ComptimeLogicalNot :: trait
|
|
|
439
463
|
;
|
|
440
464
|
export ComptimeLogicalNot;
|
|
441
465
|
|
|
466
|
+
/// BitNot trait — enables `~value` bitwise complement.
|
|
442
467
|
BitNot :: trait(
|
|
443
468
|
Output : Type,
|
|
444
469
|
(~) : (fn(self: Self) -> Self.Output)
|
|
@@ -452,6 +477,7 @@ ComptimeBitNot :: trait(
|
|
|
452
477
|
);
|
|
453
478
|
export ComptimeBitNot;
|
|
454
479
|
|
|
480
|
+
/// BitAnd trait — enables `lhs & rhs` bitwise AND.
|
|
455
481
|
BitAnd :: (fn(comptime(Rhs) : Type) -> comptime(Trait))(
|
|
456
482
|
trait(
|
|
457
483
|
Output : Type,
|
|
@@ -469,6 +495,7 @@ ComptimeBitAnd :: (fn(comptime(Rhs) : Type, where(Rhs <: Comptime))-> comptime(T
|
|
|
469
495
|
);
|
|
470
496
|
export ComptimeBitAnd;
|
|
471
497
|
|
|
498
|
+
/// BitOr trait — enables `lhs | rhs` bitwise OR.
|
|
472
499
|
BitOr :: (fn(comptime(Rhs) : Type) -> comptime(Trait))(
|
|
473
500
|
trait(
|
|
474
501
|
Output : Type,
|
|
@@ -486,6 +513,7 @@ ComptimeBitOr :: (fn(comptime(Rhs) : Type, where(Rhs <: Comptime))-> comptime(Tr
|
|
|
486
513
|
);
|
|
487
514
|
export ComptimeBitOr;
|
|
488
515
|
|
|
516
|
+
/// BitXor trait — enables `lhs ^ rhs` bitwise XOR.
|
|
489
517
|
BitXor :: (fn(comptime(Rhs) : Type) -> comptime(Trait))(
|
|
490
518
|
trait(
|
|
491
519
|
Output : Type,
|
|
@@ -590,7 +618,8 @@ impl(bool, ComptimeLogicalNot(
|
|
|
590
618
|
)
|
|
591
619
|
));
|
|
592
620
|
|
|
593
|
-
///
|
|
621
|
+
/// Eq trait — enables `==` and `!=` comparison operators.
|
|
622
|
+
/// The `!=` method has a default implementation that negates `==`.
|
|
594
623
|
Eq ::
|
|
595
624
|
(fn(comptime(Rhs) : Type) -> comptime(Trait))
|
|
596
625
|
trait(
|
|
@@ -618,14 +647,19 @@ ComptimeEq ::
|
|
|
618
647
|
;
|
|
619
648
|
export ComptimeEq;
|
|
620
649
|
|
|
621
|
-
///
|
|
650
|
+
/// Ordering — result of a comparison.
|
|
622
651
|
Ordering :: enum(
|
|
652
|
+
/// Left-hand side is less than right-hand side.
|
|
623
653
|
Less,
|
|
654
|
+
/// Both sides are equal.
|
|
624
655
|
Equal,
|
|
656
|
+
/// Left-hand side is greater than right-hand side.
|
|
625
657
|
Greater
|
|
626
658
|
);
|
|
627
659
|
export Ordering;
|
|
628
660
|
|
|
661
|
+
/// Ord trait — enables `<`, `<=`, `>`, `>=` comparison operators.
|
|
662
|
+
/// Requires the type to also implement `Eq`.
|
|
629
663
|
Ord :: (
|
|
630
664
|
fn(
|
|
631
665
|
comptime(Rhs) : Type
|
|
@@ -686,20 +720,21 @@ export
|
|
|
686
720
|
Hash
|
|
687
721
|
;
|
|
688
722
|
|
|
689
|
-
|
|
723
|
+
/// Clone trait — deep-copy a value.
|
|
690
724
|
Clone :: trait(
|
|
725
|
+
/// Create an independent clone of `self`.
|
|
691
726
|
clone :
|
|
692
727
|
fn(self: *(Self)) -> Self
|
|
693
728
|
);
|
|
694
729
|
export Clone;
|
|
695
730
|
|
|
696
|
-
|
|
731
|
+
/// Isolation trait — runtime check whether a value can be safely transferred.
|
|
697
732
|
Isolation :: trait(
|
|
698
733
|
can_isolate : (fn(self : Self) -> bool)
|
|
699
734
|
);
|
|
700
735
|
export Isolation;
|
|
701
736
|
|
|
702
|
-
|
|
737
|
+
/// ComptimeToString trait — compile-time string conversion.
|
|
703
738
|
ComptimeToString :: trait(
|
|
704
739
|
to_comptime_string : (fn(comptime(self) : Self) -> comptime(comptime_string)),
|
|
705
740
|
where(Self <: Comptime)
|
|
@@ -3828,14 +3863,20 @@ impl(comptime_string, ComptimeIndex(RangeInclusive(comptime_int))(
|
|
|
3828
3863
|
)
|
|
3829
3864
|
));
|
|
3830
3865
|
|
|
3831
|
-
/// str
|
|
3866
|
+
/// `str` — an immutable UTF-8 byte string view (newtype over `Slice(u8)`).
|
|
3867
|
+
///
|
|
3868
|
+
/// String literals `"hello"` produce `str` at runtime.
|
|
3869
|
+
/// For heap-allocated growable strings, see `String`.
|
|
3832
3870
|
str :: newtype(
|
|
3871
|
+
/// The underlying byte slice.
|
|
3833
3872
|
bytes : Slice(u8)
|
|
3834
3873
|
);
|
|
3835
3874
|
impl(str,
|
|
3875
|
+
/// Construct a `str` from a raw pointer and length.
|
|
3836
3876
|
from_raw_parts : (fn(ptr : *(u8), length : usize) -> Self)(
|
|
3837
3877
|
Self(bytes: __yo_slice_new(ptr, length))
|
|
3838
3878
|
),
|
|
3879
|
+
/// Return the length in bytes.
|
|
3839
3880
|
len : (fn(self : Self) -> usize)(
|
|
3840
3881
|
__yo_slice_len(self.bytes)
|
|
3841
3882
|
),
|
|
@@ -4028,54 +4069,73 @@ impl(Type,
|
|
|
4028
4069
|
_Type :: Type;
|
|
4029
4070
|
export Type : _Type;
|
|
4030
4071
|
|
|
4031
|
-
|
|
4072
|
+
/// Type reflection metadata structs — used by `Type.get_info()`.
|
|
4032
4073
|
|
|
4033
|
-
|
|
4034
|
-
StructKind :: enum(
|
|
4074
|
+
/// StructKind — discriminant for struct flavors.
|
|
4075
|
+
StructKind :: enum(
|
|
4076
|
+
/// Regular value struct.
|
|
4077
|
+
Struct,
|
|
4078
|
+
/// Reference-counted object.
|
|
4079
|
+
Object,
|
|
4080
|
+
/// Single-field newtype wrapper.
|
|
4081
|
+
NewType
|
|
4082
|
+
);
|
|
4035
4083
|
impl(StructKind, Comptime());
|
|
4036
4084
|
export StructKind;
|
|
4037
4085
|
|
|
4038
|
-
|
|
4086
|
+
/// TypeFieldInfo — metadata for a single struct/object field.
|
|
4039
4087
|
TypeFieldInfo :: struct(
|
|
4088
|
+
/// Field name.
|
|
4040
4089
|
name : comptime_string,
|
|
4090
|
+
/// Field type.
|
|
4041
4091
|
field_type : Type
|
|
4042
4092
|
);
|
|
4043
4093
|
impl(TypeFieldInfo, Comptime());
|
|
4044
4094
|
impl(TypeFieldInfo,
|
|
4095
|
+
/// Convert the field name to an AST expression (for metaprogramming).
|
|
4045
4096
|
to_expr : (fn(comptime(self): TypeFieldInfo) -> comptime(Expr))(
|
|
4046
4097
|
__yo_comptime_string_to_expr(self.name)
|
|
4047
4098
|
)
|
|
4048
4099
|
);
|
|
4049
4100
|
export TypeFieldInfo;
|
|
4050
4101
|
|
|
4051
|
-
|
|
4102
|
+
/// TraitInfo — lightweight reference to a trait type.
|
|
4052
4103
|
TraitInfo :: struct(
|
|
4104
|
+
/// The trait's `Type` value.
|
|
4053
4105
|
trait_type : Type
|
|
4054
4106
|
);
|
|
4055
4107
|
impl(TraitInfo, Comptime());
|
|
4056
4108
|
export TraitInfo;
|
|
4057
4109
|
|
|
4058
|
-
|
|
4110
|
+
/// TraitFieldInfo — metadata for a single trait field.
|
|
4059
4111
|
TraitFieldInfo :: struct(
|
|
4112
|
+
/// Field name.
|
|
4060
4113
|
name : comptime_string,
|
|
4114
|
+
/// Field type.
|
|
4061
4115
|
field_type : Type,
|
|
4116
|
+
/// `true` if this field is an associated type (not a method).
|
|
4062
4117
|
is_associated_type : bool
|
|
4063
4118
|
);
|
|
4064
4119
|
impl(TraitFieldInfo, Comptime());
|
|
4065
4120
|
export TraitFieldInfo;
|
|
4066
4121
|
|
|
4067
|
-
|
|
4122
|
+
/// ParamInfo — metadata for a function parameter.
|
|
4068
4123
|
ParamInfo :: struct(
|
|
4124
|
+
/// Parameter name.
|
|
4069
4125
|
name : comptime_string,
|
|
4126
|
+
/// Parameter type.
|
|
4070
4127
|
param_type : Type,
|
|
4128
|
+
/// `true` if the parameter is compile-time (`comptime`).
|
|
4071
4129
|
is_comptime : bool,
|
|
4130
|
+
/// `true` if the parameter uses `quote`.
|
|
4072
4131
|
is_quote : bool,
|
|
4132
|
+
/// `true` if the parameter is variadic.
|
|
4073
4133
|
is_variadic : bool
|
|
4074
4134
|
);
|
|
4075
4135
|
impl(ParamInfo, Comptime());
|
|
4076
4136
|
export ParamInfo;
|
|
4077
4137
|
|
|
4078
|
-
|
|
4138
|
+
/// ForallParamInfo — metadata for a forall type parameter.
|
|
4079
4139
|
ForallParamInfo :: struct(
|
|
4080
4140
|
name : comptime_string,
|
|
4081
4141
|
param_type : Type
|
|
@@ -4083,7 +4143,7 @@ ForallParamInfo :: struct(
|
|
|
4083
4143
|
impl(ForallParamInfo, Comptime());
|
|
4084
4144
|
export ForallParamInfo;
|
|
4085
4145
|
|
|
4086
|
-
|
|
4146
|
+
/// ImplicitParamInfo — metadata for a `using`/effect parameter.
|
|
4087
4147
|
ImplicitParamInfo :: struct(
|
|
4088
4148
|
name : comptime_string,
|
|
4089
4149
|
param_type : Type
|
|
@@ -4091,29 +4151,39 @@ ImplicitParamInfo :: struct(
|
|
|
4091
4151
|
impl(ImplicitParamInfo, Comptime());
|
|
4092
4152
|
export ImplicitParamInfo;
|
|
4093
4153
|
|
|
4094
|
-
|
|
4154
|
+
/// FunctionInfo — metadata for a function type.
|
|
4095
4155
|
FunctionInfo :: struct(
|
|
4156
|
+
/// Regular parameters.
|
|
4096
4157
|
params : ComptimeList(ParamInfo),
|
|
4158
|
+
/// Return type.
|
|
4097
4159
|
return_type : Type,
|
|
4160
|
+
/// Forall type parameters.
|
|
4098
4161
|
forall_params : ComptimeList(ForallParamInfo),
|
|
4162
|
+
/// Implicit `using` parameters.
|
|
4099
4163
|
implicit_params : ComptimeList(ImplicitParamInfo),
|
|
4164
|
+
/// `true` if this is a closure type.
|
|
4100
4165
|
is_closure : bool
|
|
4101
4166
|
);
|
|
4102
4167
|
impl(FunctionInfo, Comptime());
|
|
4103
4168
|
export FunctionInfo;
|
|
4104
4169
|
|
|
4105
|
-
|
|
4170
|
+
/// TraitKind — discriminant for different trait flavors.
|
|
4106
4171
|
TraitKind :: enum(
|
|
4172
|
+
/// A Future trait with child type and effects.
|
|
4107
4173
|
Future(child : Type, effects : ComptimeList(TraitInfo)),
|
|
4174
|
+
/// A callable `Fn` trait with function info.
|
|
4108
4175
|
Fn(call : FunctionInfo),
|
|
4176
|
+
/// A normal user-defined trait.
|
|
4109
4177
|
Normal
|
|
4110
4178
|
);
|
|
4111
4179
|
impl(TraitKind, Comptime());
|
|
4112
4180
|
export TraitKind;
|
|
4113
4181
|
|
|
4114
|
-
|
|
4182
|
+
/// VariantInfo — metadata for an enum variant.
|
|
4115
4183
|
VariantInfo :: struct(
|
|
4184
|
+
/// Variant name.
|
|
4116
4185
|
name : comptime_string,
|
|
4186
|
+
/// Variant fields (may be empty for unit variants).
|
|
4117
4187
|
fields : ComptimeList(TypeFieldInfo),
|
|
4118
4188
|
_enum_type : Type,
|
|
4119
4189
|
_variant_index : usize
|
|
@@ -4121,7 +4191,8 @@ VariantInfo :: struct(
|
|
|
4121
4191
|
impl(VariantInfo, Comptime());
|
|
4122
4192
|
export VariantInfo;
|
|
4123
4193
|
|
|
4124
|
-
|
|
4194
|
+
/// TypeInfo — compile-time enum representing rich type metadata.
|
|
4195
|
+
/// Returned by `Type.get_info()` for compile-time type reflection.
|
|
4125
4196
|
TypeInfo :: enum(
|
|
4126
4197
|
// Primitives (fieldless)
|
|
4127
4198
|
Unit, Bool,
|
|
@@ -4285,19 +4356,24 @@ impl(TypeInfo,
|
|
|
4285
4356
|
);
|
|
4286
4357
|
export TypeInfo;
|
|
4287
4358
|
|
|
4288
|
-
|
|
4289
|
-
|
|
4359
|
+
/// `Type.get_info()` — returns compile-time type metadata.
|
|
4360
|
+
/// Defined after `TypeInfo` so the return type is available.
|
|
4290
4361
|
impl(Type,
|
|
4362
|
+
/// Return rich metadata about this type at compile-time.
|
|
4291
4363
|
get_info : (fn(comptime(self): Type) -> comptime(TypeInfo))({
|
|
4292
4364
|
return __yo_type_get_info(self);
|
|
4293
4365
|
}),
|
|
4294
4366
|
|
|
4367
|
+
/// Return the list of struct fields for this type at compile-time.
|
|
4368
|
+
/// Asserts that the type is a struct.
|
|
4295
4369
|
get_struct_fields : (fn(comptime(self): Type) -> comptime(ComptimeList(TypeFieldInfo)))({
|
|
4296
4370
|
info :: __yo_type_get_info(self);
|
|
4297
4371
|
comptime_assert(info.is_struct(), "Type.get_struct_fields: expected a struct type");
|
|
4298
4372
|
match(info, .Struct(f, _) => f, _ => comptime_list(TypeFieldInfo("_", unit)))
|
|
4299
4373
|
}),
|
|
4300
4374
|
|
|
4375
|
+
/// Return the list of enum variants for this type at compile-time.
|
|
4376
|
+
/// Asserts that the type is an enum.
|
|
4301
4377
|
get_enum_variants : (fn(comptime(self): Type) -> comptime(ComptimeList(VariantInfo)))({
|
|
4302
4378
|
info :: __yo_type_get_info(self);
|
|
4303
4379
|
comptime_assert(info.is_enum(), "Type.get_enum_variants: expected an enum type");
|
|
@@ -4305,32 +4381,42 @@ impl(Type,
|
|
|
4305
4381
|
})
|
|
4306
4382
|
);
|
|
4307
4383
|
|
|
4308
|
-
|
|
4384
|
+
/// `FieldInfo` — compile-time struct field metadata for derive rules (legacy alias).
|
|
4309
4385
|
FieldInfo :: struct(name : comptime_string, field_type : Type);
|
|
4310
4386
|
impl(FieldInfo, Comptime());
|
|
4311
4387
|
impl(FieldInfo,
|
|
4388
|
+
/// Convert the field name to a quoted expression.
|
|
4312
4389
|
to_expr : (fn(comptime(self): FieldInfo) -> comptime(Expr))(
|
|
4313
4390
|
__yo_comptime_string_to_expr(self.name)
|
|
4314
4391
|
)
|
|
4315
4392
|
);
|
|
4316
4393
|
export FieldInfo;
|
|
4317
4394
|
|
|
4318
|
-
|
|
4395
|
+
/// Function type for mapping over struct fields during derive.
|
|
4319
4396
|
MapFieldsFn :: (fn(comptime(_) : FieldInfo) -> comptime(Expr));
|
|
4397
|
+
/// Function type for mapping over enum variants during derive.
|
|
4320
4398
|
MapVariantsFn :: (fn(comptime(_) : VariantInfo) -> comptime(Expr));
|
|
4321
4399
|
|
|
4322
4400
|
impl(Type,
|
|
4401
|
+
/// Join struct fields by applying a mapper to each field and combining with
|
|
4402
|
+
/// a combiner expression. Used by derive macros.
|
|
4323
4403
|
join_fields : (fn(comptime(self): Type, comptime(mapper): MapFieldsFn, comptime(combiner): Expr) -> comptime(Expr))({
|
|
4324
4404
|
return __yo_type_join_fields(self, mapper, combiner);
|
|
4325
4405
|
}),
|
|
4326
4406
|
|
|
4407
|
+
/// Map over enum variants, applying a mapper function to each variant.
|
|
4408
|
+
/// Returns a compile-time list of expressions. Used by derive macros.
|
|
4327
4409
|
map_variants : (fn(comptime(self): Type, comptime(mapper): MapVariantsFn) -> comptime(ComptimeList(Expr)))({
|
|
4328
4410
|
return __yo_type_map_variants(self, mapper);
|
|
4329
4411
|
})
|
|
4330
4412
|
);
|
|
4331
4413
|
|
|
4332
|
-
|
|
4414
|
+
/// `Var` — compile-time variable introspection utilities.
|
|
4415
|
+
///
|
|
4416
|
+
/// Provides macros for querying metadata about a variable at compile-time,
|
|
4417
|
+
/// such as ownership status and alias information.
|
|
4333
4418
|
Var :: impl({
|
|
4419
|
+
/// Print debug information about a variable at compile-time.
|
|
4334
4420
|
print_info :: (fn(quote(variable) : Expr) -> unquote(Expr)) {
|
|
4335
4421
|
return quote {
|
|
4336
4422
|
__yo_var_print_info(unquote(variable));
|
|
@@ -4338,11 +4424,13 @@ Var :: impl({
|
|
|
4338
4424
|
};
|
|
4339
4425
|
export print_info;
|
|
4340
4426
|
|
|
4427
|
+
/// Returns whether the variable is the owner of a reference-counted value.
|
|
4341
4428
|
is_owning_the_rc_value :: (fn(quote(variable) : Expr) -> unquote(Expr)) {
|
|
4342
4429
|
return quote __yo_var_is_owning_the_rc_value(unquote(variable));
|
|
4343
4430
|
};
|
|
4344
4431
|
export is_owning_the_rc_value;
|
|
4345
4432
|
|
|
4433
|
+
/// Returns whether the variable has other aliases pointing to the same value.
|
|
4346
4434
|
has_other_aliases :: (fn(quote(variable) : Expr) -> unquote(Expr)) {
|
|
4347
4435
|
return quote __yo_var_has_other_aliases(unquote(variable));
|
|
4348
4436
|
};
|
|
@@ -4350,8 +4438,18 @@ Var :: impl({
|
|
|
4350
4438
|
});
|
|
4351
4439
|
export Var;
|
|
4352
4440
|
|
|
4353
|
-
|
|
4354
|
-
///
|
|
4441
|
+
/// Option — a value that may or may not be present.
|
|
4442
|
+
///
|
|
4443
|
+
/// `Option(T)` has two variants:
|
|
4444
|
+
/// - `.Some(value)` — contains a value of type `T`
|
|
4445
|
+
/// - `.None` — contains no value
|
|
4446
|
+
///
|
|
4447
|
+
/// # Example
|
|
4448
|
+
/// ```rust
|
|
4449
|
+
/// (x : Option(i32)) = .Some(i32(42));
|
|
4450
|
+
/// assert(x.is_some(), "expected Some");
|
|
4451
|
+
/// assert((x.unwrap() == i32(42)), "expected 42");
|
|
4452
|
+
/// ```
|
|
4355
4453
|
Option :: (fn(comptime(T) : Type) -> comptime(Type))(
|
|
4356
4454
|
enum(
|
|
4357
4455
|
None,
|
|
@@ -4359,6 +4457,7 @@ Option :: (fn(comptime(T) : Type) -> comptime(Type))(
|
|
|
4359
4457
|
)
|
|
4360
4458
|
);
|
|
4361
4459
|
impl(forall(T : Type), Option(T),
|
|
4460
|
+
/// Extract the contained value, panicking with a message if `None`.
|
|
4362
4461
|
unwrap : (fn(self : Self) -> T)(
|
|
4363
4462
|
match(self,
|
|
4364
4463
|
.Some(value) => value,
|
|
@@ -4366,6 +4465,7 @@ impl(forall(T : Type), Option(T),
|
|
|
4366
4465
|
)
|
|
4367
4466
|
),
|
|
4368
4467
|
|
|
4468
|
+
/// Extract the contained value, or return `or_value` if `None`.
|
|
4369
4469
|
unwrap_or : (fn(self : Self, or_value : T) -> T)(
|
|
4370
4470
|
match(self,
|
|
4371
4471
|
.Some(value) => value,
|
|
@@ -4373,6 +4473,7 @@ impl(forall(T : Type), Option(T),
|
|
|
4373
4473
|
)
|
|
4374
4474
|
),
|
|
4375
4475
|
|
|
4476
|
+
/// Return `true` if the option contains a value.
|
|
4376
4477
|
is_some : (fn(self : Self) -> bool)(
|
|
4377
4478
|
match(self,
|
|
4378
4479
|
.Some(_) => true,
|
|
@@ -4380,6 +4481,7 @@ impl(forall(T : Type), Option(T),
|
|
|
4380
4481
|
)
|
|
4381
4482
|
),
|
|
4382
4483
|
|
|
4484
|
+
/// Return `true` if the option is `None`.
|
|
4383
4485
|
is_none : (fn(self : Self) -> bool)(
|
|
4384
4486
|
match(self,
|
|
4385
4487
|
.None => true,
|
|
@@ -4388,8 +4490,9 @@ impl(forall(T : Type), Option(T),
|
|
|
4388
4490
|
)
|
|
4389
4491
|
);
|
|
4390
4492
|
|
|
4391
|
-
|
|
4493
|
+
/// Functional combinators for `Option(T)`.
|
|
4392
4494
|
impl(forall(T : Type), Option(T),
|
|
4495
|
+
/// Apply `f` to the contained value (if `Some`), or return `None`.
|
|
4393
4496
|
map : (fn(forall(B : Type), self : Self, f : Impl(Fn(a : T) -> B)) -> Option(B))(
|
|
4394
4497
|
match(self,
|
|
4395
4498
|
.Some(value) => Option(B).Some(f(value)),
|
|
@@ -4397,6 +4500,7 @@ impl(forall(T : Type), Option(T),
|
|
|
4397
4500
|
)
|
|
4398
4501
|
),
|
|
4399
4502
|
|
|
4503
|
+
/// Apply `f` to the contained value (if `Some`) and flatten the result.
|
|
4400
4504
|
and_then : (fn(forall(B : Type), self : Self, f : Impl(Fn(a : T) -> Option(B))) -> Option(B))(
|
|
4401
4505
|
match(self,
|
|
4402
4506
|
.Some(value) => f(value),
|
|
@@ -4404,6 +4508,7 @@ impl(forall(T : Type), Option(T),
|
|
|
4404
4508
|
)
|
|
4405
4509
|
),
|
|
4406
4510
|
|
|
4511
|
+
/// Return `Some(value)` if the predicate returns `true`, otherwise `None`.
|
|
4407
4512
|
filter : (fn(self : Self, predicate : Impl(Fn(a : T) -> bool)) -> Option(T))(
|
|
4408
4513
|
match(self,
|
|
4409
4514
|
.Some(value) => cond(
|
|
@@ -4414,6 +4519,7 @@ impl(forall(T : Type), Option(T),
|
|
|
4414
4519
|
)
|
|
4415
4520
|
),
|
|
4416
4521
|
|
|
4522
|
+
/// Return this option if `Some`, otherwise call `f` and return its result.
|
|
4417
4523
|
or_else : (fn(self : Self, f : Impl(Fn() -> Option(T))) -> Option(T))(
|
|
4418
4524
|
match(self,
|
|
4419
4525
|
.Some(value) => Option(T).Some(value),
|
|
@@ -4421,6 +4527,7 @@ impl(forall(T : Type), Option(T),
|
|
|
4421
4527
|
)
|
|
4422
4528
|
),
|
|
4423
4529
|
|
|
4530
|
+
/// Apply `f` if `Some`, otherwise return `default_val`.
|
|
4424
4531
|
map_or : (fn(forall(B : Type), self : Self, default_val : B, f : Impl(Fn(a : T) -> B)) -> B)(
|
|
4425
4532
|
match(self,
|
|
4426
4533
|
.Some(value) => f(value),
|
|
@@ -4428,6 +4535,7 @@ impl(forall(T : Type), Option(T),
|
|
|
4428
4535
|
)
|
|
4429
4536
|
),
|
|
4430
4537
|
|
|
4538
|
+
/// Apply `f` if `Some`, otherwise call `default_fn`.
|
|
4431
4539
|
map_or_else : (fn(forall(B : Type), self : Self, default_fn : Impl(Fn() -> B), f : Impl(Fn(a : T) -> B)) -> B)(
|
|
4432
4540
|
match(self,
|
|
4433
4541
|
.Some(value) => f(value),
|
|
@@ -4435,6 +4543,7 @@ impl(forall(T : Type), Option(T),
|
|
|
4435
4543
|
)
|
|
4436
4544
|
),
|
|
4437
4545
|
|
|
4546
|
+
/// Return `optb` if `self` is `Some`, otherwise `None`.
|
|
4438
4547
|
and : (fn(forall(B : Type), self : Self, optb : Option(B)) -> Option(B))(
|
|
4439
4548
|
match(self,
|
|
4440
4549
|
.Some(_) => optb,
|
|
@@ -4442,6 +4551,7 @@ impl(forall(T : Type), Option(T),
|
|
|
4442
4551
|
)
|
|
4443
4552
|
),
|
|
4444
4553
|
|
|
4554
|
+
/// Return `self` if `Some`, otherwise return `optb`.
|
|
4445
4555
|
or : (fn(self : Self, optb : Option(T)) -> Option(T))(
|
|
4446
4556
|
match(self,
|
|
4447
4557
|
.Some(value) => Option(T).Some(value),
|
|
@@ -4449,6 +4559,7 @@ impl(forall(T : Type), Option(T),
|
|
|
4449
4559
|
)
|
|
4450
4560
|
),
|
|
4451
4561
|
|
|
4562
|
+
/// Extract the contained value, or call `f` to produce a default.
|
|
4452
4563
|
unwrap_or_else : (fn(self : Self, f : Impl(Fn() -> T)) -> T)(
|
|
4453
4564
|
match(self,
|
|
4454
4565
|
.Some(value) => value,
|
|
@@ -4457,8 +4568,9 @@ impl(forall(T : Type), Option(T),
|
|
|
4457
4568
|
)
|
|
4458
4569
|
);
|
|
4459
4570
|
|
|
4460
|
-
|
|
4571
|
+
/// Flatten a nested `Option(Option(T))` into `Option(T)`.
|
|
4461
4572
|
impl(forall(T : Type), Option(Option(T)),
|
|
4573
|
+
/// Collapse one level of nesting.
|
|
4462
4574
|
flatten : (fn(self : Self) -> Option(T))(
|
|
4463
4575
|
match(self,
|
|
4464
4576
|
.Some(inner) => inner,
|
|
@@ -4467,11 +4579,12 @@ impl(forall(T : Type), Option(Option(T)),
|
|
|
4467
4579
|
)
|
|
4468
4580
|
);
|
|
4469
4581
|
|
|
4470
|
-
|
|
4582
|
+
/// `Option(T)` implements `Comptime` when `T` implements `Comptime`.
|
|
4471
4583
|
impl(forall(T : Type), where(T <: Comptime), Option(T), Comptime());
|
|
4472
4584
|
|
|
4473
|
-
|
|
4585
|
+
/// Compile-time methods for `Option(T)`.
|
|
4474
4586
|
impl(forall(T : Type), where(T <: Comptime), Option(T),
|
|
4587
|
+
/// Compile-time unwrap — panics at compile-time if `None`.
|
|
4475
4588
|
comptime_unwrap : (fn(comptime(self) : Self) -> comptime(T))(
|
|
4476
4589
|
match(self,
|
|
4477
4590
|
.Some(value) => value,
|
|
@@ -4501,9 +4614,9 @@ impl(forall(T : Type), where(T <: Comptime), Option(T),
|
|
|
4501
4614
|
)
|
|
4502
4615
|
);
|
|
4503
4616
|
|
|
4504
|
-
|
|
4617
|
+
/// `?` is a shorthand alias for `Option`.
|
|
4505
4618
|
? :: Option;
|
|
4506
|
-
|
|
4619
|
+
/// `?*(T)` is a nullable pointer — equivalent to `Option(*(T))`.
|
|
4507
4620
|
(?*) :: (fn(comptime(T): Type) -> comptime(Type))
|
|
4508
4621
|
Option(*(T))
|
|
4509
4622
|
;
|
|
@@ -4514,10 +4627,14 @@ export
|
|
|
4514
4627
|
;
|
|
4515
4628
|
|
|
4516
4629
|
|
|
4517
|
-
|
|
4630
|
+
/// DeriveContext — context passed to derive rule functions (needs Option).
|
|
4631
|
+
/// Used by the `derive` macro to generate trait implementations.
|
|
4518
4632
|
DeriveContext :: struct(
|
|
4633
|
+
/// The AST expression for the target type.
|
|
4519
4634
|
target : Expr,
|
|
4635
|
+
/// Optional forall parameters for generic types.
|
|
4520
4636
|
forall_params : Option(Expr),
|
|
4637
|
+
/// Optional where clause for constrained generics.
|
|
4521
4638
|
where_clause : Option(Expr)
|
|
4522
4639
|
);
|
|
4523
4640
|
impl(DeriveContext, Comptime());
|
|
@@ -5066,7 +5183,17 @@ __derive_ord :: (fn(comptime(T) : Type, comptime(ctx) : DeriveContext, comptime(
|
|
|
5066
5183
|
derive_rule(Ord, __derive_ord);
|
|
5067
5184
|
|
|
5068
5185
|
|
|
5069
|
-
///
|
|
5186
|
+
/// Result — a value that is either success (`Ok`) or failure (`Err`).
|
|
5187
|
+
///
|
|
5188
|
+
/// `Result(OkType, ErrorType)` has two variants:
|
|
5189
|
+
/// - `.Ok(value)` — contains a success value of type `OkType`
|
|
5190
|
+
/// - `.Err(error)` — contains an error value of type `ErrorType`
|
|
5191
|
+
///
|
|
5192
|
+
/// # Example
|
|
5193
|
+
/// ```rust
|
|
5194
|
+
/// (r : Result(i32, str)) = .Ok(i32(42));
|
|
5195
|
+
/// assert(r.is_ok(), "expected Ok");
|
|
5196
|
+
/// ```
|
|
5070
5197
|
Result :: (fn(comptime(OkType): Type, comptime(ErrorType): Type) -> comptime(Type))
|
|
5071
5198
|
enum(
|
|
5072
5199
|
Ok(value: OkType),
|
|
@@ -5074,6 +5201,7 @@ Result :: (fn(comptime(OkType): Type, comptime(ErrorType): Type) -> comptime(Typ
|
|
|
5074
5201
|
)
|
|
5075
5202
|
;
|
|
5076
5203
|
impl(forall(OkType : Type, ErrorType : Type), Result(OkType, ErrorType),
|
|
5204
|
+
/// Extract the `Ok` value, panicking if `Err`.
|
|
5077
5205
|
unwrap : (fn(self : Self) -> OkType)(
|
|
5078
5206
|
match(self,
|
|
5079
5207
|
.Ok(value) => value,
|
|
@@ -5081,6 +5209,7 @@ impl(forall(OkType : Type, ErrorType : Type), Result(OkType, ErrorType),
|
|
|
5081
5209
|
)
|
|
5082
5210
|
),
|
|
5083
5211
|
|
|
5212
|
+
/// Extract the `Err` value, panicking if `Ok`.
|
|
5084
5213
|
unwrap_err : (fn(self : Self) -> ErrorType)(
|
|
5085
5214
|
match(self,
|
|
5086
5215
|
.Err(error) => error,
|
|
@@ -5088,6 +5217,7 @@ impl(forall(OkType : Type, ErrorType : Type), Result(OkType, ErrorType),
|
|
|
5088
5217
|
)
|
|
5089
5218
|
),
|
|
5090
5219
|
|
|
5220
|
+
/// Return `true` if the result is `Ok`.
|
|
5091
5221
|
is_ok : (fn(self : Self) -> bool)(
|
|
5092
5222
|
match(self,
|
|
5093
5223
|
.Ok(_) => true,
|
|
@@ -5095,6 +5225,7 @@ impl(forall(OkType : Type, ErrorType : Type), Result(OkType, ErrorType),
|
|
|
5095
5225
|
)
|
|
5096
5226
|
),
|
|
5097
5227
|
|
|
5228
|
+
/// Return `true` if the result is `Err`.
|
|
5098
5229
|
is_err : (fn(self : Self) -> bool)(
|
|
5099
5230
|
match(self,
|
|
5100
5231
|
.Err(_) => true,
|
|
@@ -5103,8 +5234,9 @@ impl(forall(OkType : Type, ErrorType : Type), Result(OkType, ErrorType),
|
|
|
5103
5234
|
)
|
|
5104
5235
|
);
|
|
5105
5236
|
|
|
5106
|
-
|
|
5237
|
+
/// Functional combinators for `Result(OkType, ErrorType)`.
|
|
5107
5238
|
impl(forall(OkType : Type, ErrorType : Type), Result(OkType, ErrorType),
|
|
5239
|
+
/// Map the `Ok` value with `f`, leaving `Err` untouched.
|
|
5108
5240
|
map : (fn(forall(B : Type), self : Self, f : Impl(Fn(a : OkType) -> B)) -> Result(B, ErrorType))(
|
|
5109
5241
|
match(self,
|
|
5110
5242
|
.Ok(value) => Result(B, ErrorType).Ok(f(value)),
|
|
@@ -5112,6 +5244,7 @@ impl(forall(OkType : Type, ErrorType : Type), Result(OkType, ErrorType),
|
|
|
5112
5244
|
)
|
|
5113
5245
|
),
|
|
5114
5246
|
|
|
5247
|
+
/// Map the `Err` value with `f`, leaving `Ok` untouched.
|
|
5115
5248
|
map_err : (fn(forall(F : Type), self : Self, f : Impl(Fn(a : ErrorType) -> F)) -> Result(OkType, F))(
|
|
5116
5249
|
match(self,
|
|
5117
5250
|
.Ok(value) => Result(OkType, F).Ok(value),
|
|
@@ -5119,6 +5252,7 @@ impl(forall(OkType : Type, ErrorType : Type), Result(OkType, ErrorType),
|
|
|
5119
5252
|
)
|
|
5120
5253
|
),
|
|
5121
5254
|
|
|
5255
|
+
/// Chain a computation that may fail on the `Ok` value.
|
|
5122
5256
|
and_then : (fn(forall(B : Type), self : Self, f : Impl(Fn(a : OkType) -> Result(B, ErrorType))) -> Result(B, ErrorType))(
|
|
5123
5257
|
match(self,
|
|
5124
5258
|
.Ok(value) => f(value),
|
|
@@ -5126,6 +5260,7 @@ impl(forall(OkType : Type, ErrorType : Type), Result(OkType, ErrorType),
|
|
|
5126
5260
|
)
|
|
5127
5261
|
),
|
|
5128
5262
|
|
|
5263
|
+
/// Chain a recovery computation on the `Err` value.
|
|
5129
5264
|
or_else : (fn(forall(F : Type), self : Self, f : Impl(Fn(a : ErrorType) -> Result(OkType, F))) -> Result(OkType, F))(
|
|
5130
5265
|
match(self,
|
|
5131
5266
|
.Ok(value) => Result(OkType, F).Ok(value),
|
|
@@ -5133,6 +5268,7 @@ impl(forall(OkType : Type, ErrorType : Type), Result(OkType, ErrorType),
|
|
|
5133
5268
|
)
|
|
5134
5269
|
),
|
|
5135
5270
|
|
|
5271
|
+
/// Return `res` if `Ok`, otherwise propagate `Err`.
|
|
5136
5272
|
and : (fn(forall(B : Type), self : Self, res : Result(B, ErrorType)) -> Result(B, ErrorType))(
|
|
5137
5273
|
match(self,
|
|
5138
5274
|
.Ok(_) => res,
|
|
@@ -5140,6 +5276,7 @@ impl(forall(OkType : Type, ErrorType : Type), Result(OkType, ErrorType),
|
|
|
5140
5276
|
)
|
|
5141
5277
|
),
|
|
5142
5278
|
|
|
5279
|
+
/// Return `self` if `Ok`, otherwise return `res`.
|
|
5143
5280
|
or : (fn(forall(F : Type), self : Self, res : Result(OkType, F)) -> Result(OkType, F))(
|
|
5144
5281
|
match(self,
|
|
5145
5282
|
.Ok(value) => Result(OkType, F).Ok(value),
|
|
@@ -5147,6 +5284,7 @@ impl(forall(OkType : Type, ErrorType : Type), Result(OkType, ErrorType),
|
|
|
5147
5284
|
)
|
|
5148
5285
|
),
|
|
5149
5286
|
|
|
5287
|
+
/// Convert to `Option(OkType)`, discarding the error.
|
|
5150
5288
|
ok : (fn(self : Self) -> Option(OkType))(
|
|
5151
5289
|
match(self,
|
|
5152
5290
|
.Ok(value) => Option(OkType).Some(value),
|
|
@@ -5154,6 +5292,7 @@ impl(forall(OkType : Type, ErrorType : Type), Result(OkType, ErrorType),
|
|
|
5154
5292
|
)
|
|
5155
5293
|
),
|
|
5156
5294
|
|
|
5295
|
+
/// Convert to `Option(ErrorType)`, discarding the success value.
|
|
5157
5296
|
err : (fn(self : Self) -> Option(ErrorType))(
|
|
5158
5297
|
match(self,
|
|
5159
5298
|
.Ok(_) => Option(ErrorType).None,
|
|
@@ -5161,6 +5300,7 @@ impl(forall(OkType : Type, ErrorType : Type), Result(OkType, ErrorType),
|
|
|
5161
5300
|
)
|
|
5162
5301
|
),
|
|
5163
5302
|
|
|
5303
|
+
/// Apply `f` if `Ok`, otherwise return `default_val`.
|
|
5164
5304
|
map_or : (fn(forall(B : Type), self : Self, default_val : B, f : Impl(Fn(a : OkType) -> B)) -> B)(
|
|
5165
5305
|
match(self,
|
|
5166
5306
|
.Ok(value) => f(value),
|
|
@@ -5168,6 +5308,7 @@ impl(forall(OkType : Type, ErrorType : Type), Result(OkType, ErrorType),
|
|
|
5168
5308
|
)
|
|
5169
5309
|
),
|
|
5170
5310
|
|
|
5311
|
+
/// Apply `f` if `Ok`, otherwise call `default_fn` with the error.
|
|
5171
5312
|
map_or_else : (fn(forall(B : Type), self : Self, default_fn : Impl(Fn(a : ErrorType) -> B), f : Impl(Fn(a : OkType) -> B)) -> B)(
|
|
5172
5313
|
match(self,
|
|
5173
5314
|
.Ok(value) => f(value),
|
|
@@ -5175,6 +5316,7 @@ impl(forall(OkType : Type, ErrorType : Type), Result(OkType, ErrorType),
|
|
|
5175
5316
|
)
|
|
5176
5317
|
),
|
|
5177
5318
|
|
|
5319
|
+
/// Extract the `Ok` value, or call `f` with the error to produce a fallback.
|
|
5178
5320
|
unwrap_or_else : (fn(self : Self, f : Impl(Fn(a : ErrorType) -> OkType)) -> OkType)(
|
|
5179
5321
|
match(self,
|
|
5180
5322
|
.Ok(value) => value,
|
|
@@ -5183,8 +5325,9 @@ impl(forall(OkType : Type, ErrorType : Type), Result(OkType, ErrorType),
|
|
|
5183
5325
|
)
|
|
5184
5326
|
);
|
|
5185
5327
|
|
|
5186
|
-
|
|
5328
|
+
/// `Option` to `Result` conversion methods (defined after `Result`).
|
|
5187
5329
|
impl(forall(T : Type), Option(T),
|
|
5330
|
+
/// Convert `Some(value)` to `Ok(value)`, or return `Err(err)` if `None`.
|
|
5188
5331
|
ok_or : (fn(forall(E : Type), self : Self, err : E) -> Result(T, E))(
|
|
5189
5332
|
match(self,
|
|
5190
5333
|
.Some(value) => Result(T, E).Ok(value),
|
|
@@ -5192,6 +5335,7 @@ impl(forall(T : Type), Option(T),
|
|
|
5192
5335
|
)
|
|
5193
5336
|
),
|
|
5194
5337
|
|
|
5338
|
+
/// Convert `Some(value)` to `Ok(value)`, or call `err_fn` to produce `Err` if `None`.
|
|
5195
5339
|
ok_or_else : (fn(forall(E : Type), self : Self, err_fn : Impl(Fn() -> E)) -> Result(T, E))(
|
|
5196
5340
|
match(self,
|
|
5197
5341
|
.Some(value) => Result(T, E).Ok(value),
|
|
@@ -5200,11 +5344,12 @@ impl(forall(T : Type), Option(T),
|
|
|
5200
5344
|
)
|
|
5201
5345
|
);
|
|
5202
5346
|
|
|
5203
|
-
|
|
5347
|
+
/// `Result(OkType, ErrorType)` implements `Comptime` when both types implement `Comptime`.
|
|
5204
5348
|
impl(forall(OkType : Type, ErrorType : Type), where(OkType <: Comptime, ErrorType <: Comptime), Result(OkType, ErrorType), Comptime());
|
|
5205
5349
|
|
|
5206
|
-
|
|
5350
|
+
/// Compile-time methods for `Result(OkType, ErrorType)`.
|
|
5207
5351
|
impl(forall(OkType : Type, ErrorType : Type), where(OkType <: Comptime, ErrorType <: Comptime), Result(OkType, ErrorType),
|
|
5352
|
+
/// Compile-time unwrap — panics at compile-time if `Err`.
|
|
5208
5353
|
comptime_unwrap : (fn(comptime(self) : Self) -> comptime(OkType))(
|
|
5209
5354
|
match(self,
|
|
5210
5355
|
.Ok(value) => value,
|
|
@@ -5238,12 +5383,21 @@ export
|
|
|
5238
5383
|
Result
|
|
5239
5384
|
;
|
|
5240
5385
|
|
|
5241
|
-
///
|
|
5386
|
+
/// Box — a heap-allocated, reference-counted container for a single value.
|
|
5387
|
+
///
|
|
5388
|
+
/// Use `box(value)` to allocate. Access the inner value with `b.*`.
|
|
5389
|
+
///
|
|
5390
|
+
/// # Example
|
|
5391
|
+
/// ```rust
|
|
5392
|
+
/// b := box(i32(42));
|
|
5393
|
+
/// assert((b.* == i32(42)), "inner value is 42");
|
|
5394
|
+
/// ```
|
|
5242
5395
|
Box :: (fn(comptime(V) : Type) -> comptime(Type))
|
|
5243
5396
|
object(
|
|
5244
5397
|
(*) : V
|
|
5245
5398
|
)
|
|
5246
5399
|
;
|
|
5400
|
+
/// Allocate a value on the heap, returning a `Box(V)`.
|
|
5247
5401
|
box :: (fn(forall(V : Type), own(value) : V) -> Box(V))
|
|
5248
5402
|
Box(V)(value)
|
|
5249
5403
|
;
|
|
@@ -5270,10 +5424,11 @@ export
|
|
|
5270
5424
|
box
|
|
5271
5425
|
;
|
|
5272
5426
|
|
|
5273
|
-
///
|
|
5427
|
+
/// Iso — an isolated reference-counted value that can be sent across threads.
|
|
5274
5428
|
impl(forall(T : Type), Iso(T), Send());
|
|
5275
5429
|
impl(forall(T : Type), where(T <: Acyclic), Iso(T), Acyclic());
|
|
5276
5430
|
impl(forall(T : Type), Iso(T),
|
|
5431
|
+
/// Attempt to extract the inner value if this `Iso` holds the only reference.
|
|
5277
5432
|
extract : (fn(self : Self) -> Option(T))(
|
|
5278
5433
|
__yo_iso_extract(self)
|
|
5279
5434
|
)
|
|
@@ -5345,51 +5500,58 @@ extern "Yo",
|
|
|
5345
5500
|
(fn(comptime(_Self) : Type, comptime(BaseType): Type, self: _Self) -> BaseType)
|
|
5346
5501
|
;
|
|
5347
5502
|
|
|
5503
|
+
/// MaybeUninit — a wrapper that allows holding an uninitialized value.
|
|
5504
|
+
///
|
|
5505
|
+
/// Useful for FFI or low-level patterns where a value must be
|
|
5506
|
+
/// allocated first and initialized later (e.g., by a C function).
|
|
5507
|
+
///
|
|
5508
|
+
/// # Example
|
|
5509
|
+
/// ```rust
|
|
5510
|
+
/// extern "C",
|
|
5511
|
+
/// time_t : Type,
|
|
5512
|
+
/// time : fn(timer: ?*(time_t)) -> time_t
|
|
5513
|
+
/// ;
|
|
5514
|
+
///
|
|
5515
|
+
/// uninitialized_timer := MaybeUninit(time_t).new();
|
|
5516
|
+
/// ptr := uninitialized_timer.as_ptr();
|
|
5517
|
+
/// time(.Some(ptr));
|
|
5518
|
+
/// timer := uninitialized_timer.assume_init();
|
|
5519
|
+
/// ```
|
|
5348
5520
|
MaybeUninit :: (fn(comptime(BaseType): Type) -> comptime(Type))
|
|
5349
5521
|
newtype(
|
|
5350
5522
|
value: BaseType
|
|
5351
5523
|
)
|
|
5352
5524
|
;
|
|
5353
5525
|
impl(forall(BaseType : Type), MaybeUninit(BaseType),
|
|
5526
|
+
/// Create a new uninitialized value.
|
|
5354
5527
|
new : (fn() -> Self)(__yo_maybe_uninit_new(Self)),
|
|
5355
5528
|
|
|
5529
|
+
/// Get a mutable pointer to the underlying value.
|
|
5356
5530
|
as_ptr : (fn(self: *(Self)) -> *(BaseType))(
|
|
5357
5531
|
__yo_maybe_uninit_as_ptr(Self, BaseType, self)
|
|
5358
5532
|
),
|
|
5359
5533
|
|
|
5534
|
+
/// Assume the value is initialized and extract it. **Undefined behavior if not initialized.**
|
|
5360
5535
|
assume_init : (fn(own(self) : Self) -> BaseType)(
|
|
5361
5536
|
__yo_maybe_uninit_assume_init(Self, BaseType, self)
|
|
5362
5537
|
)
|
|
5363
5538
|
);
|
|
5364
5539
|
|
|
5365
|
-
/* EXAMPLE:
|
|
5366
|
-
|
|
5367
|
-
extern "C",
|
|
5368
|
-
time_t : Type,
|
|
5369
|
-
time :
|
|
5370
|
-
fn(timer: ?*(time_t)) -> time_t
|
|
5371
|
-
;
|
|
5372
|
-
|
|
5373
|
-
uninitialized_timer := MaybeUninit(time_t).new(); // Create an uninitialized MaybeUninit(time_t)
|
|
5374
|
-
ptr := uninitialized_timer.as_ptr(); // ptr has type *(time_t)
|
|
5375
|
-
time(.Some(ptr)); // initialize the timer
|
|
5376
|
-
timer := uninitialized_timer.assume_init(); // now we can assume it's initialized
|
|
5377
|
-
|
|
5378
|
-
*/
|
|
5379
5540
|
export
|
|
5380
5541
|
MaybeUninit
|
|
5381
5542
|
;
|
|
5382
5543
|
|
|
5383
|
-
|
|
5384
|
-
/// === Iterator ===
|
|
5544
|
+
/// Iterator trait — lazy, pull-based sequence traversal.
|
|
5385
5545
|
Iterator :: trait(
|
|
5546
|
+
/// The type of elements yielded by this iterator.
|
|
5386
5547
|
Item : Type,
|
|
5548
|
+
/// Advance the iterator and return the next value, or `None` when exhausted.
|
|
5387
5549
|
next :
|
|
5388
5550
|
fn(self : *(Self)) -> Option(Self.Item)
|
|
5389
5551
|
);
|
|
5390
5552
|
export Iterator;
|
|
5391
5553
|
|
|
5392
|
-
///
|
|
5554
|
+
/// IntoIterator trait — convert a collection into an iterator.
|
|
5393
5555
|
IntoIterator :: trait(
|
|
5394
5556
|
Item : Type,
|
|
5395
5557
|
IntoIter : Type,
|
|
@@ -5468,27 +5630,36 @@ impl(forall(T : Type), Slice(T),
|
|
|
5468
5630
|
|
|
5469
5631
|
export SliceIterPtr;
|
|
5470
5632
|
|
|
5471
|
-
|
|
5633
|
+
/// TryFrom trait — fallible conversion from one type to another.
|
|
5472
5634
|
TryFrom :: (fn(comptime(From) : Type) -> comptime(Trait))(
|
|
5473
5635
|
trait(
|
|
5636
|
+
/// Error type returned on conversion failure.
|
|
5474
5637
|
Error : Type,
|
|
5638
|
+
/// Attempt to convert `value` into `Self`.
|
|
5475
5639
|
try_from :
|
|
5476
5640
|
(fn(value : From) -> Result(Self, Self.Error))
|
|
5477
5641
|
)
|
|
5478
5642
|
);
|
|
5479
5643
|
export TryFrom;
|
|
5480
5644
|
|
|
5645
|
+
/// TryInto trait — fallible conversion of `Self` into another type.
|
|
5481
5646
|
TryInto :: (fn(comptime(To) : Type) -> comptime(Trait))(
|
|
5482
5647
|
trait(
|
|
5648
|
+
/// Error type returned on conversion failure.
|
|
5483
5649
|
Error : Type,
|
|
5650
|
+
/// Attempt to convert `self` into the target type.
|
|
5484
5651
|
try_into :
|
|
5485
5652
|
(fn(self : Self, (comptime(_To) : Type) = To) -> Result(To, Self.Error))
|
|
5486
5653
|
)
|
|
5487
5654
|
);
|
|
5488
5655
|
export TryInto;
|
|
5489
5656
|
|
|
5490
|
-
|
|
5491
|
-
///
|
|
5657
|
+
/// `if` macro — expands to `cond(condition => then, true => else)`.
|
|
5658
|
+
///
|
|
5659
|
+
/// # Example
|
|
5660
|
+
/// ```rust
|
|
5661
|
+
/// if(x > 0, println("positive"), println("non-positive"));
|
|
5662
|
+
/// ```
|
|
5492
5663
|
if :: (fn(quote(condition) : Expr,
|
|
5493
5664
|
quote(then) : Expr,
|
|
5494
5665
|
(quote(else) : Expr) ?= quote(())
|
|
@@ -5502,9 +5673,12 @@ export
|
|
|
5502
5673
|
if
|
|
5503
5674
|
;
|
|
5504
5675
|
|
|
5505
|
-
|
|
5506
|
-
|
|
5507
|
-
|
|
5676
|
+
/// `try` macro — unwrap a `Result`, returning early on `Err`.
|
|
5677
|
+
///
|
|
5678
|
+
/// # Example
|
|
5679
|
+
/// ```rust
|
|
5680
|
+
/// value := try(might_fail());
|
|
5681
|
+
/// ```
|
|
5508
5682
|
try :: (fn(quote(expr_to_try): Expr) -> unquote(Expr)) {
|
|
5509
5683
|
temp :: gensym("try");
|
|
5510
5684
|
quote {
|
|
@@ -5519,26 +5693,14 @@ try :: (fn(quote(expr_to_try): Expr) -> unquote(Expr)) {
|
|
|
5519
5693
|
};
|
|
5520
5694
|
export try;
|
|
5521
5695
|
|
|
5522
|
-
|
|
5523
|
-
|
|
5524
|
-
|
|
5525
|
-
|
|
5526
|
-
|
|
5527
|
-
|
|
5528
|
-
|
|
5529
|
-
|
|
5530
|
-
* transforms to
|
|
5531
|
-
*
|
|
5532
|
-
* iter := box.into_iter();
|
|
5533
|
-
* while true, {
|
|
5534
|
-
* value := iter.next();
|
|
5535
|
-
* match(value,
|
|
5536
|
-
* .Some(value) => {
|
|
5537
|
-
* printf("value %d\n", value);
|
|
5538
|
-
* }),
|
|
5539
|
-
* .None => { break; }
|
|
5540
|
-
* }
|
|
5541
|
-
*/
|
|
5696
|
+
/// `for` macro — iterate over a collection using the `Iterator` trait.
|
|
5697
|
+
///
|
|
5698
|
+
/// # Example
|
|
5699
|
+
/// ```rust
|
|
5700
|
+
/// for arr.iter(), (value) => {
|
|
5701
|
+
/// printf("value %d\n", value.*);
|
|
5702
|
+
/// };
|
|
5703
|
+
/// ```
|
|
5542
5704
|
for :: (fn(
|
|
5543
5705
|
quote(iter) : Expr,
|
|
5544
5706
|
quote(handle) : Expr
|
|
@@ -5580,12 +5742,15 @@ for :: (fn(
|
|
|
5580
5742
|
};
|
|
5581
5743
|
export for;
|
|
5582
5744
|
|
|
5583
|
-
///
|
|
5584
|
-
/// === IO related ===
|
|
5745
|
+
/// FutureState — the state of an async `Future`.
|
|
5585
5746
|
FutureState :: enum(
|
|
5747
|
+
/// The future has been created but not yet started.
|
|
5586
5748
|
Pending = 0,
|
|
5749
|
+
/// The future is actively running.
|
|
5587
5750
|
Running = 1,
|
|
5751
|
+
/// The future completed successfully.
|
|
5588
5752
|
Completed = -(1),
|
|
5753
|
+
/// The future was aborted (e.g., via `escape`).
|
|
5589
5754
|
Aborted = -(2)
|
|
5590
5755
|
);
|
|
5591
5756
|
impl(FutureState, Acyclic());
|
|
@@ -5597,22 +5762,29 @@ impl(FutureState, Eq(FutureState)(
|
|
|
5597
5762
|
));
|
|
5598
5763
|
export FutureState;
|
|
5599
5764
|
|
|
5600
|
-
|
|
5601
|
-
|
|
5602
|
-
|
|
5603
|
-
// NOTE: __future uses *(T) (not *(void)) so that the type parameter T is visible
|
|
5604
|
-
// in the struct fields for generic impl matching to extract T from JoinHandle(T).
|
|
5765
|
+
/// JoinHandle — a handle to a spawned async task.
|
|
5766
|
+
/// Wraps a raw pointer to the spawned future's state machine.
|
|
5767
|
+
/// Generic over `T`, the return type of the spawned task.
|
|
5605
5768
|
JoinHandle :: (fn(comptime(T) : Type) -> comptime(Type))(
|
|
5606
5769
|
struct(
|
|
5770
|
+
/// Raw pointer to the spawned future (uses `*(T)` so the type parameter is visible).
|
|
5607
5771
|
__future : *(T)
|
|
5608
5772
|
)
|
|
5609
5773
|
);
|
|
5610
5774
|
export JoinHandle;
|
|
5611
5775
|
|
|
5776
|
+
/// IO module — the async runtime effect.
|
|
5777
|
+
///
|
|
5778
|
+
/// Provides `io.async`, `io.await`, `io.spawn`, and `io.state` operations.
|
|
5779
|
+
/// Automatically injected into `main` when declared with `using(io : IO)`.
|
|
5612
5780
|
IO :: module(
|
|
5781
|
+
/// Create a new `Future` from an async closure.
|
|
5613
5782
|
async : (fn(forall(T : Type, ...(E)), action : Impl(Fn(using(...(E))) -> T)) -> Impl(Future(T, ...(E)))),
|
|
5783
|
+
/// Await a `Future`, suspending until its result is ready.
|
|
5614
5784
|
await : (fn(forall(T : Type, ...(E)), fut : Impl(Future(T, ...(E))), using(...(E))) -> T),
|
|
5785
|
+
/// Inspect the current state of a `Future` without blocking.
|
|
5615
5786
|
state : (fn(forall(T : Type, ...(E)), fut : Impl(Future(T, ...(E)))) -> FutureState),
|
|
5787
|
+
/// Spawn a `Future` as an independent task, returning a `JoinHandle`.
|
|
5616
5788
|
spawn : (fn(forall(T : Type, ...(E)), fut : Impl(Future(T, ...(E))), using(...(E))) -> JoinHandle(T))
|
|
5617
5789
|
);
|
|
5618
5790
|
export IO;
|
|
@@ -5624,9 +5796,8 @@ extern "Yo",
|
|
|
5624
5796
|
__yo_io_spawn : (fn(forall(T : Type, ...(E)), fut : Impl(Future(T, ...(E))), using(...(E))) -> JoinHandle(T))
|
|
5625
5797
|
;
|
|
5626
5798
|
|
|
5627
|
-
|
|
5628
|
-
|
|
5629
|
-
// So it won't automatically inject to other functions.
|
|
5799
|
+
/// Built-in IO module instance. Automatically injected for `main` functions
|
|
5800
|
+
/// with `using(io : IO)`.
|
|
5630
5801
|
__yo_builtin_io :: IO(
|
|
5631
5802
|
async : __yo_io_async,
|
|
5632
5803
|
await : __yo_io_await,
|
|
@@ -5635,7 +5806,7 @@ __yo_builtin_io :: IO(
|
|
|
5635
5806
|
);
|
|
5636
5807
|
export __yo_builtin_io;
|
|
5637
5808
|
|
|
5638
|
-
|
|
5809
|
+
/// JoinHandle methods — defined after IO so `using(io : IO)` resolves.
|
|
5639
5810
|
extern "Yo",
|
|
5640
5811
|
__yo_join_handle_await : (fn(forall(T : Type), self : JoinHandle(T), using(io : IO)) -> Option(T))
|
|
5641
5812
|
;
|