@shd101wyy/yo 0.1.28 → 0.1.30
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/skills/yo-async-effects/SKILL.md +15 -15
- package/.github/skills/yo-async-effects/async-effects-recipes.md +118 -121
- package/.github/skills/yo-core-patterns/core-patterns-cheatsheet.md +33 -13
- package/.github/skills/yo-project-workflow/workflow-cheatsheet.md +1 -1
- package/.github/skills/yo-syntax/SKILL.md +2 -2
- package/.github/skills/yo-syntax/syntax-cheatsheet.md +108 -96
- package/README.md +6 -3
- package/out/cjs/index.cjs +812 -706
- package/out/cjs/yo-cli.cjs +1023 -907
- package/out/cjs/yo-lsp.cjs +836 -730
- package/out/esm/index.mjs +757 -651
- package/out/types/src/codegen/exprs/async.d.ts +2 -0
- package/out/types/src/codegen/exprs/await.d.ts +1 -0
- package/out/types/src/codegen/exprs/closures.d.ts +4 -0
- package/out/types/src/codegen/functions/context.d.ts +6 -0
- package/out/types/src/codegen/functions/declarations.d.ts +1 -1
- package/out/types/src/doc/model.d.ts +0 -1
- package/out/types/src/env.d.ts +2 -2
- package/out/types/src/evaluator/builtins/pragma.d.ts +9 -0
- package/out/types/src/evaluator/builtins/unsafe.d.ts +8 -0
- package/out/types/src/evaluator/context.d.ts +3 -1
- package/out/types/src/evaluator/exprs/{escape.d.ts → unwind.d.ts} +1 -1
- package/out/types/src/evaluator/index.d.ts +1 -1
- package/out/types/src/evaluator/memory-safety.d.ts +14 -0
- package/out/types/src/evaluator/types/flowability.d.ts +6 -0
- package/out/types/src/evaluator/types/function.d.ts +1 -2
- package/out/types/src/evaluator/utils.d.ts +0 -1
- package/out/types/src/expr-traversal.d.ts +1 -0
- package/out/types/src/expr.d.ts +9 -7
- package/out/types/src/public-safe-report.d.ts +19 -0
- package/out/types/src/tests/comptime-ref-gate.test.d.ts +1 -0
- package/out/types/src/tests/pragma-validation.test.d.ts +1 -0
- package/out/types/src/tests/public-safe-report.test.d.ts +1 -0
- package/out/types/src/tests/type-representation-pointer.test.d.ts +1 -0
- package/out/types/src/tests/unsafe-gate.test.d.ts +1 -0
- package/out/types/src/tests/unsafe-report-classify.test.d.ts +1 -0
- package/out/types/src/types/creators.d.ts +4 -6
- package/out/types/src/types/definitions.d.ts +9 -16
- package/out/types/src/types/guards.d.ts +1 -2
- package/out/types/src/types/tags.d.ts +0 -1
- package/out/types/src/types/utils.d.ts +5 -0
- package/out/types/src/unsafe-report.d.ts +29 -0
- package/out/types/src/value.d.ts +1 -0
- package/out/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/scripts/add-pragma-for-pointer-decls.ts +134 -0
- package/scripts/add-pragma.ts +58 -0
- package/scripts/migrate-amp-method-calls.ts +186 -0
- package/scripts/migrate-clone-calls.ts +93 -0
- package/scripts/migrate-get-unwrap.ts +166 -0
- package/scripts/migrate-index-patterns.ts +210 -0
- package/scripts/migrate-index-trait.ts +142 -0
- package/scripts/migrate-iterator.ts +150 -0
- package/scripts/migrate-self-ptr.ts +220 -0
- package/scripts/migrate-skip-pragmas.ts +109 -0
- package/scripts/migrate-tostring.ts +134 -0
- package/scripts/trim-pragma.ts +130 -0
- package/scripts/wrap-extern-calls.ts +161 -0
- package/std/alg/hash.yo +3 -2
- package/std/allocator.yo +6 -5
- package/std/async.yo +2 -2
- package/std/collections/array_list.yo +59 -40
- package/std/collections/btree_map.yo +19 -18
- package/std/collections/deque.yo +9 -8
- package/std/collections/hash_map.yo +101 -13
- package/std/collections/hash_set.yo +5 -4
- package/std/collections/linked_list.yo +39 -4
- package/std/collections/ordered_map.yo +3 -3
- package/std/collections/priority_queue.yo +14 -13
- package/std/crypto/md5.yo +2 -1
- package/std/crypto/random.yo +21 -20
- package/std/crypto/sha256.yo +2 -1
- package/std/encoding/base64.yo +18 -18
- package/std/encoding/hex.yo +5 -5
- package/std/encoding/json.yo +62 -13
- package/std/encoding/punycode.yo +24 -23
- package/std/encoding/toml.yo +4 -3
- package/std/encoding/utf16.yo +3 -3
- package/std/env.yo +43 -28
- package/std/error.yo +15 -3
- package/std/fmt/display.yo +2 -2
- package/std/fmt/index.yo +6 -5
- package/std/fmt/to_string.yo +39 -38
- package/std/fmt/writer.yo +9 -8
- package/std/fs/dir.yo +61 -66
- package/std/fs/file.yo +121 -126
- package/std/fs/metadata.yo +13 -18
- package/std/fs/temp.yo +35 -30
- package/std/fs/walker.yo +14 -19
- package/std/gc.yo +1 -0
- package/std/glob.yo +7 -7
- package/std/http/client.yo +33 -36
- package/std/http/http.yo +6 -6
- package/std/http/index.yo +4 -4
- package/std/imm/list.yo +33 -0
- package/std/imm/map.yo +2 -1
- package/std/imm/set.yo +1 -0
- package/std/imm/sorted_map.yo +1 -0
- package/std/imm/sorted_set.yo +1 -0
- package/std/imm/string.yo +27 -23
- package/std/imm/vec.yo +18 -2
- package/std/io/reader.yo +2 -1
- package/std/io/writer.yo +3 -2
- package/std/libc/assert.yo +1 -0
- package/std/libc/ctype.yo +1 -0
- package/std/libc/dirent.yo +1 -0
- package/std/libc/errno.yo +1 -0
- package/std/libc/fcntl.yo +1 -0
- package/std/libc/float.yo +1 -0
- package/std/libc/limits.yo +1 -0
- package/std/libc/math.yo +1 -0
- package/std/libc/signal.yo +1 -0
- package/std/libc/stdatomic.yo +1 -0
- package/std/libc/stdint.yo +1 -0
- package/std/libc/stdio.yo +1 -0
- package/std/libc/stdlib.yo +1 -0
- package/std/libc/string.yo +1 -0
- package/std/libc/sys/stat.yo +1 -0
- package/std/libc/time.yo +1 -0
- package/std/libc/unistd.yo +1 -0
- package/std/libc/wctype.yo +1 -0
- package/std/libc/windows.yo +2 -0
- package/std/log.yo +7 -6
- package/std/net/addr.yo +6 -5
- package/std/net/dns.yo +13 -16
- package/std/net/errors.yo +9 -9
- package/std/net/tcp.yo +71 -74
- package/std/net/udp.yo +40 -43
- package/std/os/signal.yo +5 -5
- package/std/path.yo +1 -0
- package/std/prelude.yo +377 -200
- package/std/process/command.yo +57 -46
- package/std/process/index.yo +2 -1
- package/std/regex/compiler.yo +10 -9
- package/std/regex/index.yo +41 -41
- package/std/regex/match.yo +2 -2
- package/std/regex/parser.yo +31 -31
- package/std/regex/vm.yo +42 -41
- package/std/string/string.yo +95 -40
- package/std/string/string_builder.yo +9 -9
- package/std/string/unicode.yo +50 -49
- package/std/sync/channel.yo +2 -1
- package/std/sync/cond.yo +5 -4
- package/std/sync/mutex.yo +4 -3
- package/std/sys/advise.yo +1 -0
- package/std/sys/bufio/buf_reader.yo +27 -26
- package/std/sys/bufio/buf_writer.yo +22 -21
- package/std/sys/clock.yo +1 -0
- package/std/sys/copy.yo +1 -0
- package/std/sys/dir.yo +10 -9
- package/std/sys/dns.yo +6 -5
- package/std/sys/errors.yo +12 -12
- package/std/sys/events.yo +1 -0
- package/std/sys/externs.yo +38 -37
- package/std/sys/file.yo +17 -16
- package/std/sys/future.yo +4 -3
- package/std/sys/iov.yo +1 -0
- package/std/sys/mmap.yo +1 -0
- package/std/sys/path.yo +1 -0
- package/std/sys/perm.yo +2 -1
- package/std/sys/pipe.yo +1 -0
- package/std/sys/process.yo +5 -4
- package/std/sys/signal.yo +1 -0
- package/std/sys/socketpair.yo +1 -0
- package/std/sys/sockinfo.yo +1 -0
- package/std/sys/statfs.yo +2 -1
- package/std/sys/statx.yo +1 -0
- package/std/sys/sysinfo.yo +1 -0
- package/std/sys/tcp.yo +15 -14
- package/std/sys/temp.yo +1 -0
- package/std/sys/time.yo +2 -1
- package/std/sys/timer.yo +6 -6
- package/std/sys/tty.yo +2 -1
- package/std/sys/udp.yo +13 -12
- package/std/sys/unix.yo +12 -11
- package/std/testing/bench.yo +4 -3
- package/std/thread.yo +7 -6
- package/std/time/datetime.yo +18 -15
- package/std/time/duration.yo +11 -10
- package/std/time/instant.yo +4 -4
- package/std/time/sleep.yo +1 -0
- package/std/url/index.yo +5 -5
- package/std/worker.yo +4 -3
package/std/prelude.yo
CHANGED
|
@@ -1,14 +1,16 @@
|
|
|
1
|
-
// @skip_prelude
|
|
2
1
|
//! Prelude — automatically imported into every Yo source file.
|
|
3
2
|
//!
|
|
4
3
|
//! Provides core language primitives: traits (`Comptime`, `Runtime`, `Clone`,
|
|
5
4
|
//! `Eq`, `Ord`, `Hash`, …), fundamental types (`Option`, `Result`, `Box`,
|
|
6
5
|
//! `Slice`, `Range`, `String`, …), operator traits (`Add`, `Sub`, …), type
|
|
7
6
|
//! reflection (`TypeInfo`), conversion (`Into`, `From`), the async runtime
|
|
8
|
-
//! (`
|
|
7
|
+
//! (`Io`, `Future`, `JoinHandle`), and derive rules.
|
|
9
8
|
//!
|
|
10
9
|
//! **Do NOT import `std/prelude`** — it is loaded automatically and an
|
|
11
10
|
//! explicit import will produce a compile error.
|
|
11
|
+
// === Foundational traits ===
|
|
12
|
+
// `Comptime` and `Runtime` are defined first because every other
|
|
13
|
+
// type (including `Pragma` below) is type-checked against them.
|
|
12
14
|
/// Comptime trait — indicates a type that can be used at compile-time.
|
|
13
15
|
/// Examples: `i32`, `bool`, `Type`, `comptime_int`, `comptime_float`, `comptime_string`.
|
|
14
16
|
/// Non-examples: `int`, `ushort` (runtime-only types).
|
|
@@ -23,6 +25,49 @@ Runtime :: trait(
|
|
|
23
25
|
id := "Runtime"
|
|
24
26
|
);
|
|
25
27
|
export(Runtime);
|
|
28
|
+
|
|
29
|
+
// === Pragma — file-level privilege flags ===
|
|
30
|
+
//
|
|
31
|
+
// `Pragma` is defined here (right after the foundational traits and
|
|
32
|
+
// BEFORE any extern/asm/pointer-op site) so the prelude can declare
|
|
33
|
+
// its own `pragma(Pragma.AllowUnsafe);` via ordinary evaluation. The
|
|
34
|
+
// prelude is the foundation of Yo's unsafe-capable machinery
|
|
35
|
+
// (raw-pointer impls, FFI declarations, the async runtime, …); the
|
|
36
|
+
// pragma must be registered before the first extern/asm/pointer-op
|
|
37
|
+
// declaration fires the Phase C gates.
|
|
38
|
+
//
|
|
39
|
+
// `SkipPrelude` is recognized via a separate AST-level pre-scan that
|
|
40
|
+
// runs before the prelude loads (chicken-and-egg: a file with
|
|
41
|
+
// `pragma(Pragma.SkipPrelude);` doesn't have the prelude in scope).
|
|
42
|
+
// All other pragma variants are validated by ordinary evaluation
|
|
43
|
+
// against this enum. See plans/MEMORY_SAFETY.md.
|
|
44
|
+
/// File-level privilege flag for the `pragma(...)` builtin. Declared
|
|
45
|
+
/// at the top of a Yo file (e.g. `pragma(Pragma.AllowUnsafe);`) to
|
|
46
|
+
/// opt the file into compiler-recognized behaviors. See
|
|
47
|
+
/// plans/MEMORY_SAFETY.md.
|
|
48
|
+
Pragma :: enum(
|
|
49
|
+
/// File is permitted to use raw pointer ops, `unsafe(...)`,
|
|
50
|
+
/// `asm(...)`, and `extern(...)`. Without this, those constructs
|
|
51
|
+
/// produce compile errors.
|
|
52
|
+
AllowUnsafe,
|
|
53
|
+
/// Disable the auto-import of `std/prelude`. Used by the prelude
|
|
54
|
+
/// itself, and by any tool/test that wants to bootstrap manually.
|
|
55
|
+
/// Recognized at the AST level before the prelude loads.
|
|
56
|
+
SkipPrelude,
|
|
57
|
+
/// Test-runner directive: skip this test file on ALL WASM targets.
|
|
58
|
+
SkipWasm,
|
|
59
|
+
/// Test-runner directive: skip when target is wasm32-emscripten.
|
|
60
|
+
SkipWasm32Emscripten,
|
|
61
|
+
/// Test-runner directive: skip when target is wasm32-wasi.
|
|
62
|
+
SkipWasm32Wasi
|
|
63
|
+
);
|
|
64
|
+
export(Pragma);
|
|
65
|
+
|
|
66
|
+
// Prelude opts itself out of the implicit self-prelude import and
|
|
67
|
+
// into unsafe-capable mode. Both calls evaluate normally against the
|
|
68
|
+
// `Pragma` enum defined just above.
|
|
69
|
+
pragma(Pragma.SkipPrelude);
|
|
70
|
+
pragma(Pragma.AllowUnsafe);
|
|
26
71
|
// === Builtin Yo functions ===
|
|
27
72
|
extern(
|
|
28
73
|
"Yo",
|
|
@@ -113,7 +158,7 @@ extern(
|
|
|
113
158
|
__yo_process_node_version : (fn() -> comptime(comptime_string))
|
|
114
159
|
);
|
|
115
160
|
export(__yo_as);
|
|
116
|
-
/// The `unsafe` module — provides low-level
|
|
161
|
+
/// The `unsafe` module — provides low-level unwind hatches.
|
|
117
162
|
unsafe :: impl({
|
|
118
163
|
/// Manually drop `value`, running its destructor immediately.
|
|
119
164
|
drop :: (fn(quote(value) : Expr) -> unquote(Expr))(quote(___drop(unquote(value))));
|
|
@@ -180,15 +225,30 @@ export(Dispose);
|
|
|
180
225
|
Index :: (fn(comptime(Idx) : Type) -> comptime(Trait))(
|
|
181
226
|
trait(
|
|
182
227
|
Output : Type,
|
|
183
|
-
index : (fn(self :
|
|
228
|
+
index : (fn(ref(self) : Self, idx : Idx) -> *(Self.Output))
|
|
184
229
|
)
|
|
185
230
|
);
|
|
186
231
|
export(Index);
|
|
232
|
+
/// Indexable trait — projection-style indexing yielding a borrow.
|
|
233
|
+
/// Companion to `Index`, but instead of returning a raw `*(T)` the
|
|
234
|
+
/// `project` method returns a `ref(Element)` — a second-class
|
|
235
|
+
/// reference that flows through Yo's flowability rule (R1–R4) and
|
|
236
|
+
/// can be received by a `ref(name) := coll.project(pos);` local
|
|
237
|
+
/// binding. The for-loop macro lowers iteration through this trait
|
|
238
|
+
/// so user code never sees a raw pointer. See
|
|
239
|
+
/// plans/ITERATOR_REDESIGN.md.
|
|
240
|
+
Indexable :: (fn(comptime(Idx) : Type) -> comptime(Trait))(
|
|
241
|
+
trait(
|
|
242
|
+
Element : Type,
|
|
243
|
+
project : (fn(ref(self) : Self, pos : Idx) -> ref(Self.Element))
|
|
244
|
+
)
|
|
245
|
+
);
|
|
246
|
+
export(Indexable);
|
|
187
247
|
/// ComptimeIndex — compile-time indexing trait for constant expressions.
|
|
188
248
|
ComptimeIndex :: (fn(comptime(Idx) : Type, where(Idx <: Comptime)) -> comptime(Trait))(
|
|
189
249
|
trait(
|
|
190
250
|
Output : Type,
|
|
191
|
-
index : (fn(comptime(self) :
|
|
251
|
+
index : (fn(comptime(ref(self)) : Self, comptime(idx) : Idx) -> comptime(*(Self.Output))),
|
|
192
252
|
where(Self <: Comptime, Self.Output <: Comptime)
|
|
193
253
|
)
|
|
194
254
|
);
|
|
@@ -652,14 +712,14 @@ Hash :: trait(
|
|
|
652
712
|
* Compute the hash of a value
|
|
653
713
|
* Returns a u64 hash value
|
|
654
714
|
*/
|
|
655
|
-
(hash) : (fn(self :
|
|
715
|
+
(hash) : (fn(ref(self) : Self) -> u64)
|
|
656
716
|
);
|
|
657
717
|
export(Hash);
|
|
658
718
|
/// Clone trait — deep-copy a value.
|
|
659
719
|
Clone :: trait(
|
|
660
720
|
/// Create an independent clone of `self`.
|
|
661
721
|
clone :
|
|
662
|
-
fn(self :
|
|
722
|
+
fn(ref(self) : Self) -> Self
|
|
663
723
|
);
|
|
664
724
|
export(Clone);
|
|
665
725
|
/// Isolation trait — runtime check whether a value can be safely transferred.
|
|
@@ -985,7 +1045,7 @@ impl(
|
|
|
985
1045
|
Clone(
|
|
986
1046
|
clone : (
|
|
987
1047
|
(self) ->
|
|
988
|
-
__yo_return_self(self
|
|
1048
|
+
__yo_return_self(self)
|
|
989
1049
|
)
|
|
990
1050
|
)
|
|
991
1051
|
);
|
|
@@ -995,7 +1055,7 @@ impl(
|
|
|
995
1055
|
(hash) : (
|
|
996
1056
|
(self) ->
|
|
997
1057
|
cond(
|
|
998
|
-
self
|
|
1058
|
+
self => u64(1),
|
|
999
1059
|
true => u64(0)
|
|
1000
1060
|
)
|
|
1001
1061
|
)
|
|
@@ -1141,13 +1201,13 @@ impl(
|
|
|
1141
1201
|
impl(
|
|
1142
1202
|
i8,
|
|
1143
1203
|
Hash(
|
|
1144
|
-
(hash) : ((self) -> u64(self
|
|
1204
|
+
(hash) : ((self) -> u64(self))
|
|
1145
1205
|
)
|
|
1146
1206
|
);
|
|
1147
1207
|
impl(
|
|
1148
1208
|
i8,
|
|
1149
1209
|
Clone(
|
|
1150
|
-
clone : ((self) -> __yo_return_self(self
|
|
1210
|
+
clone : ((self) -> __yo_return_self(self))
|
|
1151
1211
|
)
|
|
1152
1212
|
);
|
|
1153
1213
|
impl(
|
|
@@ -1431,13 +1491,13 @@ impl(
|
|
|
1431
1491
|
impl(
|
|
1432
1492
|
i16,
|
|
1433
1493
|
Hash(
|
|
1434
|
-
(hash) : ((self) -> u64(self
|
|
1494
|
+
(hash) : ((self) -> u64(self))
|
|
1435
1495
|
)
|
|
1436
1496
|
);
|
|
1437
1497
|
impl(
|
|
1438
1498
|
i16,
|
|
1439
1499
|
Clone(
|
|
1440
|
-
clone : ((self) -> __yo_return_self(self
|
|
1500
|
+
clone : ((self) -> __yo_return_self(self))
|
|
1441
1501
|
)
|
|
1442
1502
|
);
|
|
1443
1503
|
impl(
|
|
@@ -1783,7 +1843,7 @@ impl(
|
|
|
1783
1843
|
Hash(
|
|
1784
1844
|
(hash) : (
|
|
1785
1845
|
(self) -> {
|
|
1786
|
-
u32_value := u32(self
|
|
1846
|
+
u32_value := u32(self);
|
|
1787
1847
|
u64(u32_value)
|
|
1788
1848
|
}
|
|
1789
1849
|
)
|
|
@@ -1794,7 +1854,7 @@ impl(
|
|
|
1794
1854
|
Clone(
|
|
1795
1855
|
clone : (
|
|
1796
1856
|
(self) ->
|
|
1797
|
-
__yo_return_self(self
|
|
1857
|
+
__yo_return_self(self)
|
|
1798
1858
|
)
|
|
1799
1859
|
)
|
|
1800
1860
|
);
|
|
@@ -2019,13 +2079,13 @@ impl(
|
|
|
2019
2079
|
impl(
|
|
2020
2080
|
i64,
|
|
2021
2081
|
Hash(
|
|
2022
|
-
(hash) : ((self) -> u64(self
|
|
2082
|
+
(hash) : ((self) -> u64(self))
|
|
2023
2083
|
)
|
|
2024
2084
|
);
|
|
2025
2085
|
impl(
|
|
2026
2086
|
i64,
|
|
2027
2087
|
Clone(
|
|
2028
|
-
clone : ((self) -> __yo_return_self(self
|
|
2088
|
+
clone : ((self) -> __yo_return_self(self))
|
|
2029
2089
|
)
|
|
2030
2090
|
);
|
|
2031
2091
|
impl(
|
|
@@ -2309,13 +2369,13 @@ impl(
|
|
|
2309
2369
|
impl(
|
|
2310
2370
|
u8,
|
|
2311
2371
|
Hash(
|
|
2312
|
-
(hash) : ((self) -> u64(self
|
|
2372
|
+
(hash) : ((self) -> u64(self))
|
|
2313
2373
|
)
|
|
2314
2374
|
);
|
|
2315
2375
|
impl(
|
|
2316
2376
|
u8,
|
|
2317
2377
|
Clone(
|
|
2318
|
-
clone : ((self) -> __yo_return_self(self
|
|
2378
|
+
clone : ((self) -> __yo_return_self(self))
|
|
2319
2379
|
)
|
|
2320
2380
|
);
|
|
2321
2381
|
impl(
|
|
@@ -2589,13 +2649,13 @@ impl(
|
|
|
2589
2649
|
impl(
|
|
2590
2650
|
u16,
|
|
2591
2651
|
Hash(
|
|
2592
|
-
(hash) : ((self) -> u64(self
|
|
2652
|
+
(hash) : ((self) -> u64(self))
|
|
2593
2653
|
)
|
|
2594
2654
|
);
|
|
2595
2655
|
impl(
|
|
2596
2656
|
u16,
|
|
2597
2657
|
Clone(
|
|
2598
|
-
clone : ((self) -> __yo_return_self(self
|
|
2658
|
+
clone : ((self) -> __yo_return_self(self))
|
|
2599
2659
|
)
|
|
2600
2660
|
);
|
|
2601
2661
|
impl(
|
|
@@ -2869,13 +2929,13 @@ impl(
|
|
|
2869
2929
|
impl(
|
|
2870
2930
|
u32,
|
|
2871
2931
|
Hash(
|
|
2872
|
-
(hash) : ((self) -> u64(self
|
|
2932
|
+
(hash) : ((self) -> u64(self))
|
|
2873
2933
|
)
|
|
2874
2934
|
);
|
|
2875
2935
|
impl(
|
|
2876
2936
|
u32,
|
|
2877
2937
|
Clone(
|
|
2878
|
-
clone : ((self) -> __yo_return_self(self
|
|
2938
|
+
clone : ((self) -> __yo_return_self(self))
|
|
2879
2939
|
)
|
|
2880
2940
|
);
|
|
2881
2941
|
impl(
|
|
@@ -3149,13 +3209,13 @@ impl(
|
|
|
3149
3209
|
impl(
|
|
3150
3210
|
u64,
|
|
3151
3211
|
Hash(
|
|
3152
|
-
(hash) : ((self) -> self
|
|
3212
|
+
(hash) : ((self) -> self)
|
|
3153
3213
|
)
|
|
3154
3214
|
);
|
|
3155
3215
|
impl(
|
|
3156
3216
|
u64,
|
|
3157
3217
|
Clone(
|
|
3158
|
-
clone : ((self) -> __yo_return_self(self
|
|
3218
|
+
clone : ((self) -> __yo_return_self(self))
|
|
3159
3219
|
)
|
|
3160
3220
|
);
|
|
3161
3221
|
impl(
|
|
@@ -3409,13 +3469,13 @@ impl(
|
|
|
3409
3469
|
impl(
|
|
3410
3470
|
f32,
|
|
3411
3471
|
Hash(
|
|
3412
|
-
(hash) : ((self) -> u64(i32(self
|
|
3472
|
+
(hash) : ((self) -> u64(i32(self)))
|
|
3413
3473
|
)
|
|
3414
3474
|
);
|
|
3415
3475
|
impl(
|
|
3416
3476
|
f32,
|
|
3417
3477
|
Clone(
|
|
3418
|
-
clone : ((self) -> __yo_return_self(self
|
|
3478
|
+
clone : ((self) -> __yo_return_self(self))
|
|
3419
3479
|
)
|
|
3420
3480
|
);
|
|
3421
3481
|
impl(
|
|
@@ -3610,13 +3670,13 @@ impl(
|
|
|
3610
3670
|
impl(
|
|
3611
3671
|
f64,
|
|
3612
3672
|
Hash(
|
|
3613
|
-
(hash) : ((self) -> u64(i64(self
|
|
3673
|
+
(hash) : ((self) -> u64(i64(self)))
|
|
3614
3674
|
)
|
|
3615
3675
|
);
|
|
3616
3676
|
impl(
|
|
3617
3677
|
f64,
|
|
3618
3678
|
Clone(
|
|
3619
|
-
clone : ((self) -> __yo_return_self(self
|
|
3679
|
+
clone : ((self) -> __yo_return_self(self))
|
|
3620
3680
|
)
|
|
3621
3681
|
);
|
|
3622
3682
|
impl(
|
|
@@ -3836,13 +3896,13 @@ impl(
|
|
|
3836
3896
|
impl(
|
|
3837
3897
|
isize,
|
|
3838
3898
|
Hash(
|
|
3839
|
-
(hash) : ((self) -> u64(self
|
|
3899
|
+
(hash) : ((self) -> u64(self))
|
|
3840
3900
|
)
|
|
3841
3901
|
);
|
|
3842
3902
|
impl(
|
|
3843
3903
|
isize,
|
|
3844
3904
|
Clone(
|
|
3845
|
-
clone : ((self) -> __yo_return_self(self
|
|
3905
|
+
clone : ((self) -> __yo_return_self(self))
|
|
3846
3906
|
)
|
|
3847
3907
|
);
|
|
3848
3908
|
impl(
|
|
@@ -4129,13 +4189,13 @@ impl(
|
|
|
4129
4189
|
impl(
|
|
4130
4190
|
usize,
|
|
4131
4191
|
Hash(
|
|
4132
|
-
(hash) : ((self) -> u64(self
|
|
4192
|
+
(hash) : ((self) -> u64(self))
|
|
4133
4193
|
)
|
|
4134
4194
|
);
|
|
4135
4195
|
impl(
|
|
4136
4196
|
usize,
|
|
4137
4197
|
Clone(
|
|
4138
|
-
clone : ((self) -> __yo_return_self(self
|
|
4198
|
+
clone : ((self) -> __yo_return_self(self))
|
|
4139
4199
|
)
|
|
4140
4200
|
);
|
|
4141
4201
|
impl(
|
|
@@ -4413,13 +4473,13 @@ impl(
|
|
|
4413
4473
|
impl(
|
|
4414
4474
|
char,
|
|
4415
4475
|
Hash(
|
|
4416
|
-
(hash) : ((self) -> u64(self
|
|
4476
|
+
(hash) : ((self) -> u64(self))
|
|
4417
4477
|
)
|
|
4418
4478
|
);
|
|
4419
4479
|
impl(
|
|
4420
4480
|
char,
|
|
4421
4481
|
Clone(
|
|
4422
|
-
clone : ((self) -> __yo_return_self(self
|
|
4482
|
+
clone : ((self) -> __yo_return_self(self))
|
|
4423
4483
|
)
|
|
4424
4484
|
);
|
|
4425
4485
|
_char :: char;
|
|
@@ -4523,13 +4583,13 @@ impl(
|
|
|
4523
4583
|
impl(
|
|
4524
4584
|
int,
|
|
4525
4585
|
Hash(
|
|
4526
|
-
(hash) : ((self) -> u64(self
|
|
4586
|
+
(hash) : ((self) -> u64(self))
|
|
4527
4587
|
)
|
|
4528
4588
|
);
|
|
4529
4589
|
impl(
|
|
4530
4590
|
int,
|
|
4531
4591
|
Clone(
|
|
4532
|
-
clone : ((self) -> __yo_return_self(self
|
|
4592
|
+
clone : ((self) -> __yo_return_self(self))
|
|
4533
4593
|
)
|
|
4534
4594
|
);
|
|
4535
4595
|
_int :: int;
|
|
@@ -4633,13 +4693,13 @@ impl(
|
|
|
4633
4693
|
impl(
|
|
4634
4694
|
uint,
|
|
4635
4695
|
Hash(
|
|
4636
|
-
(hash) : ((self) -> u64(self
|
|
4696
|
+
(hash) : ((self) -> u64(self))
|
|
4637
4697
|
)
|
|
4638
4698
|
);
|
|
4639
4699
|
impl(
|
|
4640
4700
|
uint,
|
|
4641
4701
|
Clone(
|
|
4642
|
-
clone : ((self) -> __yo_return_self(self
|
|
4702
|
+
clone : ((self) -> __yo_return_self(self))
|
|
4643
4703
|
)
|
|
4644
4704
|
);
|
|
4645
4705
|
_uint :: uint;
|
|
@@ -4743,13 +4803,13 @@ impl(
|
|
|
4743
4803
|
impl(
|
|
4744
4804
|
short,
|
|
4745
4805
|
Hash(
|
|
4746
|
-
(hash) : ((self) -> u64(self
|
|
4806
|
+
(hash) : ((self) -> u64(self))
|
|
4747
4807
|
)
|
|
4748
4808
|
);
|
|
4749
4809
|
impl(
|
|
4750
4810
|
short,
|
|
4751
4811
|
Clone(
|
|
4752
|
-
clone : ((self) -> __yo_return_self(self
|
|
4812
|
+
clone : ((self) -> __yo_return_self(self))
|
|
4753
4813
|
)
|
|
4754
4814
|
);
|
|
4755
4815
|
_short :: short;
|
|
@@ -4853,13 +4913,13 @@ impl(
|
|
|
4853
4913
|
impl(
|
|
4854
4914
|
ushort,
|
|
4855
4915
|
Hash(
|
|
4856
|
-
(hash) : ((self) -> u64(self
|
|
4916
|
+
(hash) : ((self) -> u64(self))
|
|
4857
4917
|
)
|
|
4858
4918
|
);
|
|
4859
4919
|
impl(
|
|
4860
4920
|
ushort,
|
|
4861
4921
|
Clone(
|
|
4862
|
-
clone : ((self) -> __yo_return_self(self
|
|
4922
|
+
clone : ((self) -> __yo_return_self(self))
|
|
4863
4923
|
)
|
|
4864
4924
|
);
|
|
4865
4925
|
_ushort :: ushort;
|
|
@@ -4963,13 +5023,13 @@ impl(
|
|
|
4963
5023
|
impl(
|
|
4964
5024
|
long,
|
|
4965
5025
|
Hash(
|
|
4966
|
-
(hash) : ((self) -> u64(self
|
|
5026
|
+
(hash) : ((self) -> u64(self))
|
|
4967
5027
|
)
|
|
4968
5028
|
);
|
|
4969
5029
|
impl(
|
|
4970
5030
|
long,
|
|
4971
5031
|
Clone(
|
|
4972
|
-
clone : ((self) -> __yo_return_self(self
|
|
5032
|
+
clone : ((self) -> __yo_return_self(self))
|
|
4973
5033
|
)
|
|
4974
5034
|
);
|
|
4975
5035
|
_long :: long;
|
|
@@ -5073,13 +5133,13 @@ impl(
|
|
|
5073
5133
|
impl(
|
|
5074
5134
|
ulong,
|
|
5075
5135
|
Hash(
|
|
5076
|
-
(hash) : ((self) -> u64(self
|
|
5136
|
+
(hash) : ((self) -> u64(self))
|
|
5077
5137
|
)
|
|
5078
5138
|
);
|
|
5079
5139
|
impl(
|
|
5080
5140
|
ulong,
|
|
5081
5141
|
Clone(
|
|
5082
|
-
clone : ((self) -> __yo_return_self(self
|
|
5142
|
+
clone : ((self) -> __yo_return_self(self))
|
|
5083
5143
|
)
|
|
5084
5144
|
);
|
|
5085
5145
|
_ulong :: ulong;
|
|
@@ -5183,13 +5243,13 @@ impl(
|
|
|
5183
5243
|
impl(
|
|
5184
5244
|
longlong,
|
|
5185
5245
|
Hash(
|
|
5186
|
-
(hash) : ((self) -> u64(self
|
|
5246
|
+
(hash) : ((self) -> u64(self))
|
|
5187
5247
|
)
|
|
5188
5248
|
);
|
|
5189
5249
|
impl(
|
|
5190
5250
|
longlong,
|
|
5191
5251
|
Clone(
|
|
5192
|
-
clone : ((self) -> __yo_return_self(self
|
|
5252
|
+
clone : ((self) -> __yo_return_self(self))
|
|
5193
5253
|
)
|
|
5194
5254
|
);
|
|
5195
5255
|
_longlong :: longlong;
|
|
@@ -5293,13 +5353,13 @@ impl(
|
|
|
5293
5353
|
impl(
|
|
5294
5354
|
ulonglong,
|
|
5295
5355
|
Hash(
|
|
5296
|
-
(hash) : ((self) -> u64(self
|
|
5356
|
+
(hash) : ((self) -> u64(self))
|
|
5297
5357
|
)
|
|
5298
5358
|
);
|
|
5299
5359
|
impl(
|
|
5300
5360
|
ulonglong,
|
|
5301
5361
|
Clone(
|
|
5302
|
-
clone : ((self) -> __yo_return_self(self
|
|
5362
|
+
clone : ((self) -> __yo_return_self(self))
|
|
5303
5363
|
)
|
|
5304
5364
|
);
|
|
5305
5365
|
_ulonglong :: ulonglong;
|
|
@@ -5403,13 +5463,13 @@ impl(
|
|
|
5403
5463
|
impl(
|
|
5404
5464
|
longdouble,
|
|
5405
5465
|
Hash(
|
|
5406
|
-
(hash) : ((self) -> u64(i64(self
|
|
5466
|
+
(hash) : ((self) -> u64(i64(self)))
|
|
5407
5467
|
)
|
|
5408
5468
|
);
|
|
5409
5469
|
impl(
|
|
5410
5470
|
longdouble,
|
|
5411
5471
|
Clone(
|
|
5412
|
-
clone : ((self) -> __yo_return_self(self
|
|
5472
|
+
clone : ((self) -> __yo_return_self(self))
|
|
5413
5473
|
)
|
|
5414
5474
|
);
|
|
5415
5475
|
_longdouble :: longdouble;
|
|
@@ -5483,7 +5543,7 @@ impl(forall(T : Type, U : usize), where(T <: Runtime), Array(T, U), Runtime());
|
|
|
5483
5543
|
impl(
|
|
5484
5544
|
forall(T : Type, U : usize),
|
|
5485
5545
|
Array(T, U),
|
|
5486
|
-
len : (fn(self :
|
|
5546
|
+
len : (fn(ref(self) : Self) -> usize)({
|
|
5487
5547
|
return(U);
|
|
5488
5548
|
})
|
|
5489
5549
|
/*
|
|
@@ -5505,13 +5565,17 @@ impl(
|
|
|
5505
5565
|
})
|
|
5506
5566
|
);
|
|
5507
5567
|
/// Array Index impls
|
|
5568
|
+
/// Bodies take `&(self)` so the `*(Array(T, N))`-expecting builtin
|
|
5569
|
+
/// receives the right C-ABI shape — `ref(self) : Self` gives the body
|
|
5570
|
+
/// a value-typed view of `self` even though the runtime passes a
|
|
5571
|
+
/// pointer. See plans/ITERATOR_REDESIGN.md.
|
|
5508
5572
|
impl(
|
|
5509
5573
|
forall(T : Type, N : usize),
|
|
5510
5574
|
Array(T, N),
|
|
5511
5575
|
Index(usize)(
|
|
5512
5576
|
Output : T,
|
|
5513
|
-
index : (fn(self :
|
|
5514
|
-
__yo_array_index(self, idx)
|
|
5577
|
+
index : (fn(ref(self) : Self, idx : usize) -> *(Self.Output))(
|
|
5578
|
+
__yo_array_index(&(self), idx)
|
|
5515
5579
|
)
|
|
5516
5580
|
)
|
|
5517
5581
|
);
|
|
@@ -5520,8 +5584,8 @@ impl(
|
|
|
5520
5584
|
Array(T, N),
|
|
5521
5585
|
Index(Range(usize))(
|
|
5522
5586
|
Output : Slice(T),
|
|
5523
|
-
index : (fn(self :
|
|
5524
|
-
__yo_array_index_range(self, idx)
|
|
5587
|
+
index : (fn(ref(self) : Self, idx : Range(usize)) -> *(Self.Output))(
|
|
5588
|
+
__yo_array_index_range(&(self), idx)
|
|
5525
5589
|
)
|
|
5526
5590
|
)
|
|
5527
5591
|
);
|
|
@@ -5530,8 +5594,27 @@ impl(
|
|
|
5530
5594
|
Array(T, N),
|
|
5531
5595
|
Index(RangeInclusive(usize))(
|
|
5532
5596
|
Output : Slice(T),
|
|
5533
|
-
index : (fn(self :
|
|
5534
|
-
__yo_array_index_range_inclusive(self, idx)
|
|
5597
|
+
index : (fn(ref(self) : Self, idx : RangeInclusive(usize)) -> *(Self.Output))(
|
|
5598
|
+
__yo_array_index_range_inclusive(&(self), idx)
|
|
5599
|
+
)
|
|
5600
|
+
)
|
|
5601
|
+
);
|
|
5602
|
+
/// Array Indexable impl — projection-style indexing yielding `ref(T)`.
|
|
5603
|
+
/// Body takes `&(self)` so `__yo_array_index`'s `self : *(Array(T, N))`
|
|
5604
|
+
/// parameter is satisfied — the `ref(self) : Self` binding gives the
|
|
5605
|
+
/// body a value-typed view of `self` even though the C ABI passes a
|
|
5606
|
+
/// pointer. The `unsafe` wrap is the trusted escape from the
|
|
5607
|
+
/// flowability rule (privileged code only). See plans/ITERATOR_REDESIGN.md.
|
|
5608
|
+
impl(
|
|
5609
|
+
forall(T : Type, N : usize),
|
|
5610
|
+
Array(T, N),
|
|
5611
|
+
Indexable(usize)(
|
|
5612
|
+
Element : T,
|
|
5613
|
+
project : (fn(ref(self) : Self, pos : usize) -> ref(T))(
|
|
5614
|
+
cond(
|
|
5615
|
+
(pos >= N) => panic("Array: project out of bounds"),
|
|
5616
|
+
true => unsafe(__yo_array_index(&(self), pos))
|
|
5617
|
+
)
|
|
5535
5618
|
)
|
|
5536
5619
|
)
|
|
5537
5620
|
);
|
|
@@ -5558,14 +5641,14 @@ impl(
|
|
|
5558
5641
|
__yo_slice_ptr(self)
|
|
5559
5642
|
)
|
|
5560
5643
|
);
|
|
5561
|
-
/// Slice Index impls
|
|
5644
|
+
/// Slice Index impls (same `&(self)` rationale as Array above).
|
|
5562
5645
|
impl(
|
|
5563
5646
|
forall(T : Type),
|
|
5564
5647
|
Slice(T),
|
|
5565
5648
|
Index(usize)(
|
|
5566
5649
|
Output : T,
|
|
5567
|
-
index : (fn(self :
|
|
5568
|
-
__yo_slice_index(self, idx)
|
|
5650
|
+
index : (fn(ref(self) : Self, idx : usize) -> *(Self.Output))(
|
|
5651
|
+
__yo_slice_index(&(self), idx)
|
|
5569
5652
|
)
|
|
5570
5653
|
)
|
|
5571
5654
|
);
|
|
@@ -5574,8 +5657,8 @@ impl(
|
|
|
5574
5657
|
Slice(T),
|
|
5575
5658
|
Index(Range(usize))(
|
|
5576
5659
|
Output : Slice(T),
|
|
5577
|
-
index : (fn(self :
|
|
5578
|
-
__yo_slice_index_range(self, idx)
|
|
5660
|
+
index : (fn(ref(self) : Self, idx : Range(usize)) -> *(Self.Output))(
|
|
5661
|
+
__yo_slice_index_range(&(self), idx)
|
|
5579
5662
|
)
|
|
5580
5663
|
)
|
|
5581
5664
|
);
|
|
@@ -5584,8 +5667,22 @@ impl(
|
|
|
5584
5667
|
Slice(T),
|
|
5585
5668
|
Index(RangeInclusive(usize))(
|
|
5586
5669
|
Output : Slice(T),
|
|
5587
|
-
index : (fn(self :
|
|
5588
|
-
__yo_slice_index_range_inclusive(self, idx)
|
|
5670
|
+
index : (fn(ref(self) : Self, idx : RangeInclusive(usize)) -> *(Self.Output))(
|
|
5671
|
+
__yo_slice_index_range_inclusive(&(self), idx)
|
|
5672
|
+
)
|
|
5673
|
+
)
|
|
5674
|
+
);
|
|
5675
|
+
/// Slice Indexable impl — see Array Indexable above.
|
|
5676
|
+
impl(
|
|
5677
|
+
forall(T : Type),
|
|
5678
|
+
Slice(T),
|
|
5679
|
+
Indexable(usize)(
|
|
5680
|
+
Element : T,
|
|
5681
|
+
project : (fn(ref(self) : Self, pos : usize) -> ref(T))(
|
|
5682
|
+
cond(
|
|
5683
|
+
(pos >= self.len()) => panic("Slice: project out of bounds"),
|
|
5684
|
+
true => unsafe(__yo_slice_index(&(self), pos))
|
|
5685
|
+
)
|
|
5589
5686
|
)
|
|
5590
5687
|
)
|
|
5591
5688
|
);
|
|
@@ -5596,7 +5693,7 @@ impl(
|
|
|
5596
5693
|
Array(T, N),
|
|
5597
5694
|
ComptimeIndex(usize)(
|
|
5598
5695
|
Output : T,
|
|
5599
|
-
index : (fn(comptime(self) :
|
|
5696
|
+
index : (fn(comptime(ref(self)) : Self, comptime(idx) : usize) -> comptime(*(Self.Output)))(
|
|
5600
5697
|
__yo_comptime_array_index(self, idx)
|
|
5601
5698
|
)
|
|
5602
5699
|
)
|
|
@@ -5607,7 +5704,7 @@ impl(
|
|
|
5607
5704
|
Array(T, N),
|
|
5608
5705
|
ComptimeIndex(Range(usize))(
|
|
5609
5706
|
Output : Slice(T),
|
|
5610
|
-
index : (fn(comptime(self) :
|
|
5707
|
+
index : (fn(comptime(ref(self)) : Self, comptime(idx) : Range(usize)) -> comptime(*(Self.Output)))(
|
|
5611
5708
|
__yo_comptime_array_index_range(self, idx)
|
|
5612
5709
|
)
|
|
5613
5710
|
)
|
|
@@ -5618,7 +5715,7 @@ impl(
|
|
|
5618
5715
|
Array(T, N),
|
|
5619
5716
|
ComptimeIndex(RangeInclusive(usize))(
|
|
5620
5717
|
Output : Slice(T),
|
|
5621
|
-
index : (fn(comptime(self) :
|
|
5718
|
+
index : (fn(comptime(ref(self)) : Self, comptime(idx) : RangeInclusive(usize)) -> comptime(*(Self.Output)))(
|
|
5622
5719
|
__yo_comptime_array_index_range_inclusive(self, idx)
|
|
5623
5720
|
)
|
|
5624
5721
|
)
|
|
@@ -5630,7 +5727,7 @@ impl(
|
|
|
5630
5727
|
Slice(T),
|
|
5631
5728
|
ComptimeIndex(usize)(
|
|
5632
5729
|
Output : T,
|
|
5633
|
-
index : (fn(comptime(self) :
|
|
5730
|
+
index : (fn(comptime(ref(self)) : Self, comptime(idx) : usize) -> comptime(*(Self.Output)))(
|
|
5634
5731
|
__yo_comptime_slice_index(self, idx)
|
|
5635
5732
|
)
|
|
5636
5733
|
)
|
|
@@ -5641,7 +5738,7 @@ impl(
|
|
|
5641
5738
|
Slice(T),
|
|
5642
5739
|
ComptimeIndex(Range(usize))(
|
|
5643
5740
|
Output : Slice(T),
|
|
5644
|
-
index : (fn(comptime(self) :
|
|
5741
|
+
index : (fn(comptime(ref(self)) : Self, comptime(idx) : Range(usize)) -> comptime(*(Self.Output)))(
|
|
5645
5742
|
__yo_comptime_slice_index_range(self, idx)
|
|
5646
5743
|
)
|
|
5647
5744
|
)
|
|
@@ -5652,7 +5749,7 @@ impl(
|
|
|
5652
5749
|
Slice(T),
|
|
5653
5750
|
ComptimeIndex(RangeInclusive(usize))(
|
|
5654
5751
|
Output : Slice(T),
|
|
5655
|
-
index : (fn(comptime(self) :
|
|
5752
|
+
index : (fn(comptime(ref(self)) : Self, comptime(idx) : RangeInclusive(usize)) -> comptime(*(Self.Output)))(
|
|
5656
5753
|
__yo_comptime_slice_index_range_inclusive(self, idx)
|
|
5657
5754
|
)
|
|
5658
5755
|
)
|
|
@@ -5808,7 +5905,7 @@ impl(
|
|
|
5808
5905
|
ComptimeList(T),
|
|
5809
5906
|
ComptimeIndex(usize)(
|
|
5810
5907
|
Output : T,
|
|
5811
|
-
index : (fn(comptime(self) :
|
|
5908
|
+
index : (fn(comptime(ref(self)) : Self, comptime(idx) : usize) -> comptime(*(Self.Output)))(
|
|
5812
5909
|
__yo_comptime_list_index(self, idx)
|
|
5813
5910
|
)
|
|
5814
5911
|
)
|
|
@@ -5819,7 +5916,7 @@ impl(
|
|
|
5819
5916
|
ComptimeList(T),
|
|
5820
5917
|
ComptimeIndex(Range(usize))(
|
|
5821
5918
|
Output : ComptimeList(T),
|
|
5822
|
-
index : (fn(comptime(self) :
|
|
5919
|
+
index : (fn(comptime(ref(self)) : Self, comptime(idx) : Range(usize)) -> comptime(*(Self.Output)))(
|
|
5823
5920
|
__yo_comptime_list_index_range(self, idx)
|
|
5824
5921
|
)
|
|
5825
5922
|
)
|
|
@@ -5830,7 +5927,7 @@ impl(
|
|
|
5830
5927
|
ComptimeList(T),
|
|
5831
5928
|
ComptimeIndex(RangeInclusive(usize))(
|
|
5832
5929
|
Output : ComptimeList(T),
|
|
5833
|
-
index : (fn(comptime(self) :
|
|
5930
|
+
index : (fn(comptime(ref(self)) : Self, comptime(idx) : RangeInclusive(usize)) -> comptime(*(Self.Output)))(
|
|
5834
5931
|
__yo_comptime_list_index_range_inclusive(self, idx)
|
|
5835
5932
|
)
|
|
5836
5933
|
)
|
|
@@ -5903,6 +6000,12 @@ impl(
|
|
|
5903
6000
|
);
|
|
5904
6001
|
_Type :: Type;
|
|
5905
6002
|
export(Type : _Type);
|
|
6003
|
+
// Kind-constraint syntax `Type.Struct`, `Type.Enum`, `Type.Union`,
|
|
6004
|
+
// `Type.Trait`, `Type.Function` is recognised by the evaluator (see
|
|
6005
|
+
// `src/evaluator/exprs/property-access.ts`). Use `T : Type.Struct` for
|
|
6006
|
+
// forall type-variable constraints that signal an effect record (or
|
|
6007
|
+
// other kind-restricted type). The legacy `Struct :: Type` alias was
|
|
6008
|
+
// removed in favour of this syntax.
|
|
5906
6009
|
/// Type reflection metadata structs — used by `Type.get_info()`.
|
|
5907
6010
|
/// StructKind — discriminant for struct flavors.
|
|
5908
6011
|
StructKind :: enum(
|
|
@@ -6591,7 +6694,7 @@ __derive_eq :: (fn(comptime(T) : Type, comptime(ctx) : DeriveContext, comptime(t
|
|
|
6591
6694
|
);
|
|
6592
6695
|
ctx.make_impl(
|
|
6593
6696
|
quote(
|
|
6594
|
-
Eq(
|
|
6697
|
+
Eq(...#(trait_params))(
|
|
6595
6698
|
(==) : ((lhs, rhs) -> #(eq_body))
|
|
6596
6699
|
)
|
|
6597
6700
|
)
|
|
@@ -6661,7 +6764,7 @@ __derive_eq :: (fn(comptime(T) : Type, comptime(ctx) : DeriveContext, comptime(t
|
|
|
6661
6764
|
match_body :: __s3("match(lhs,\n ", eq_branches, "\n )");
|
|
6662
6765
|
ctx.make_impl(
|
|
6663
6766
|
quote(
|
|
6664
|
-
Eq(
|
|
6767
|
+
Eq(...#(trait_params))(
|
|
6665
6768
|
(==) : ((lhs, rhs) -> #(match_body.to_expr()))
|
|
6666
6769
|
)
|
|
6667
6770
|
)
|
|
@@ -6670,7 +6773,7 @@ __derive_eq :: (fn(comptime(T) : Type, comptime(ctx) : DeriveContext, comptime(t
|
|
|
6670
6773
|
true =>
|
|
6671
6774
|
ctx.make_impl(
|
|
6672
6775
|
quote(
|
|
6673
|
-
Eq(
|
|
6776
|
+
Eq(...#(trait_params))(
|
|
6674
6777
|
(==) : ((lhs, rhs) -> true)
|
|
6675
6778
|
)
|
|
6676
6779
|
)
|
|
@@ -6691,7 +6794,7 @@ __derive_clone :: (fn(comptime(T) : Type, comptime(ctx) : DeriveContext, comptim
|
|
|
6691
6794
|
"",
|
|
6692
6795
|
(fn(comptime(a) : comptime_string, comptime(fi) : usize) -> comptime(comptime_string))({
|
|
6693
6796
|
fname :: fields.get(fi).name;
|
|
6694
|
-
part :: __s3("
|
|
6797
|
+
part :: __s3("self.", fname, ".clone()");
|
|
6695
6798
|
cond(
|
|
6696
6799
|
(a == "") => part,
|
|
6697
6800
|
true => __s3(a, ", ", part)
|
|
@@ -6735,8 +6838,8 @@ __derive_clone :: (fn(comptime(T) : Type, comptime(ctx) : DeriveContext, comptim
|
|
|
6735
6838
|
(fn(comptime(a) : comptime_string, comptime(fi) : usize) -> comptime(comptime_string))({
|
|
6736
6839
|
fname :: v.fields.get(fi).name;
|
|
6737
6840
|
cond(
|
|
6738
|
-
(a == "") => __s3("
|
|
6739
|
-
true => __s4(a, ",
|
|
6841
|
+
(a == "") => __s3("__v_", fname, ".clone()"),
|
|
6842
|
+
true => __s4(a, ", __v_", fname, ".clone()")
|
|
6740
6843
|
)
|
|
6741
6844
|
})
|
|
6742
6845
|
);
|
|
@@ -6755,7 +6858,7 @@ __derive_clone :: (fn(comptime(T) : Type, comptime(ctx) : DeriveContext, comptim
|
|
|
6755
6858
|
)
|
|
6756
6859
|
})
|
|
6757
6860
|
);
|
|
6758
|
-
match_body :: __s3("match(self
|
|
6861
|
+
match_body :: __s3("match(self,\n ", clone_branches, "\n )");
|
|
6759
6862
|
ctx.make_impl(
|
|
6760
6863
|
quote(
|
|
6761
6864
|
Clone(
|
|
@@ -6768,7 +6871,7 @@ __derive_clone :: (fn(comptime(T) : Type, comptime(ctx) : DeriveContext, comptim
|
|
|
6768
6871
|
ctx.make_impl(
|
|
6769
6872
|
quote(
|
|
6770
6873
|
Clone(
|
|
6771
|
-
clone : ((self) -> self
|
|
6874
|
+
clone : ((self) -> self)
|
|
6772
6875
|
)
|
|
6773
6876
|
)
|
|
6774
6877
|
)
|
|
@@ -6798,8 +6901,8 @@ __derive_hash :: (fn(comptime(T) : Type, comptime(ctx) : DeriveContext, comptime
|
|
|
6798
6901
|
(fn(comptime(a) : comptime_string, comptime(fi) : usize) -> comptime(comptime_string))({
|
|
6799
6902
|
fname :: fields.get(fi).name;
|
|
6800
6903
|
cond(
|
|
6801
|
-
(fi == 0) => __s3("(h : u64) =
|
|
6802
|
-
true => __s4(a, ";\n h = ((h * u64(31)) +
|
|
6904
|
+
(fi == 0) => __s3("(h : u64) = self.", fname, ".hash()"),
|
|
6905
|
+
true => __s4(a, ";\n h = ((h * u64(31)) + self.", fname, ".hash())")
|
|
6803
6906
|
)
|
|
6804
6907
|
})
|
|
6805
6908
|
);
|
|
@@ -6842,7 +6945,7 @@ __derive_hash :: (fn(comptime(T) : Type, comptime(ctx) : DeriveContext, comptime
|
|
|
6842
6945
|
__s3("(h : u64) = u64(", vi_str, ")"),
|
|
6843
6946
|
(fn(comptime(a) : comptime_string, comptime(fi) : usize) -> comptime(comptime_string))({
|
|
6844
6947
|
fname :: v.fields.get(fi).name;
|
|
6845
|
-
__s4(a, "; h = ((h * u64(31)) +
|
|
6948
|
+
__s4(a, "; h = ((h * u64(31)) + __v_", fname, ".hash())")
|
|
6846
6949
|
})
|
|
6847
6950
|
);
|
|
6848
6951
|
__s5(
|
|
@@ -6860,7 +6963,7 @@ __derive_hash :: (fn(comptime(T) : Type, comptime(ctx) : DeriveContext, comptime
|
|
|
6860
6963
|
)
|
|
6861
6964
|
})
|
|
6862
6965
|
);
|
|
6863
|
-
match_body :: __s3("match(self
|
|
6966
|
+
match_body :: __s3("match(self,\n ", hash_branches, "\n )");
|
|
6864
6967
|
ctx.make_impl(
|
|
6865
6968
|
quote(
|
|
6866
6969
|
Hash(
|
|
@@ -6951,7 +7054,7 @@ __derive_ord :: (fn(comptime(T) : Type, comptime(ctx) : DeriveContext, comptime(
|
|
|
6951
7054
|
(fc == 0) =>
|
|
6952
7055
|
ctx.make_impl(
|
|
6953
7056
|
quote(
|
|
6954
|
-
Ord(
|
|
7057
|
+
Ord(...#(trait_params))(
|
|
6955
7058
|
(<) : ((lhs, rhs) -> false),
|
|
6956
7059
|
(<=) : ((lhs, rhs) -> true),
|
|
6957
7060
|
(>) : ((lhs, rhs) -> false),
|
|
@@ -6966,7 +7069,7 @@ __derive_ord :: (fn(comptime(T) : Type, comptime(ctx) : DeriveContext, comptime(
|
|
|
6966
7069
|
ge_body :: __derive_ord_struct_body(T, ">=");
|
|
6967
7070
|
ctx.make_impl(
|
|
6968
7071
|
quote(
|
|
6969
|
-
Ord(
|
|
7072
|
+
Ord(...#(trait_params))(
|
|
6970
7073
|
(<) : ((lhs, rhs) -> #(lt_body.to_expr())),
|
|
6971
7074
|
(<=) : ((lhs, rhs) -> #(le_body.to_expr())),
|
|
6972
7075
|
(>) : ((lhs, rhs) -> #(gt_body.to_expr())),
|
|
@@ -7037,7 +7140,7 @@ __derive_ord :: (fn(comptime(T) : Type, comptime(ctx) : DeriveContext, comptime(
|
|
|
7037
7140
|
ge_match :: __gen_op_branches(">=", "true");
|
|
7038
7141
|
ctx.make_impl(
|
|
7039
7142
|
quote(
|
|
7040
|
-
Ord(
|
|
7143
|
+
Ord(...#(trait_params))(
|
|
7041
7144
|
(<) : ((lhs, rhs) -> #(lt_match.to_expr())),
|
|
7042
7145
|
(<=) : ((lhs, rhs) -> #(le_match.to_expr())),
|
|
7043
7146
|
(>) : ((lhs, rhs) -> #(gt_match.to_expr())),
|
|
@@ -7049,7 +7152,7 @@ __derive_ord :: (fn(comptime(T) : Type, comptime(ctx) : DeriveContext, comptime(
|
|
|
7049
7152
|
true =>
|
|
7050
7153
|
ctx.make_impl(
|
|
7051
7154
|
quote(
|
|
7052
|
-
Ord(
|
|
7155
|
+
Ord(...#(trait_params))(
|
|
7053
7156
|
(<) : ((lhs, rhs) -> false),
|
|
7054
7157
|
(<=) : ((lhs, rhs) -> true),
|
|
7055
7158
|
(>) : ((lhs, rhs) -> false),
|
|
@@ -7273,9 +7376,9 @@ impl(
|
|
|
7273
7376
|
clone : (
|
|
7274
7377
|
(self) ->
|
|
7275
7378
|
match(
|
|
7276
|
-
self
|
|
7379
|
+
self,
|
|
7277
7380
|
.None => Option(T).None,
|
|
7278
|
-
.Some(v) => Option(T).Some(
|
|
7381
|
+
.Some(v) => Option(T).Some(v.clone())
|
|
7279
7382
|
)
|
|
7280
7383
|
)
|
|
7281
7384
|
)
|
|
@@ -7309,9 +7412,9 @@ impl(
|
|
|
7309
7412
|
clone : (
|
|
7310
7413
|
(self) ->
|
|
7311
7414
|
match(
|
|
7312
|
-
self
|
|
7313
|
-
.Ok(v) => Result(T, E).Ok(
|
|
7314
|
-
.Err(e) => Result(T, E).Err(
|
|
7415
|
+
self,
|
|
7416
|
+
.Ok(v) => Result(T, E).Ok(v.clone()),
|
|
7417
|
+
.Err(e) => Result(T, E).Err(e.clone())
|
|
7315
7418
|
)
|
|
7316
7419
|
)
|
|
7317
7420
|
)
|
|
@@ -7369,7 +7472,7 @@ impl(
|
|
|
7369
7472
|
where(T <: Hash),
|
|
7370
7473
|
Box(T),
|
|
7371
7474
|
Hash(
|
|
7372
|
-
(hash) : ((self) ->
|
|
7475
|
+
(hash) : ((self) -> self.*.hash())
|
|
7373
7476
|
)
|
|
7374
7477
|
);
|
|
7375
7478
|
impl(
|
|
@@ -7377,7 +7480,10 @@ impl(
|
|
|
7377
7480
|
where(T <: Eq(T)),
|
|
7378
7481
|
Box(T),
|
|
7379
7482
|
Eq(Box(T))(
|
|
7380
|
-
|
|
7483
|
+
// SAFETY: Box always holds a non-null pointer to Rc-managed
|
|
7484
|
+
// storage; the deref is sound for as long as either operand
|
|
7485
|
+
// is alive, which covers the duration of this comparison.
|
|
7486
|
+
(==) : ((lhs, rhs) -> unsafe(lhs.* == rhs.*))
|
|
7381
7487
|
)
|
|
7382
7488
|
);
|
|
7383
7489
|
impl(
|
|
@@ -7385,7 +7491,7 @@ impl(
|
|
|
7385
7491
|
where(T <: Clone),
|
|
7386
7492
|
Box(T),
|
|
7387
7493
|
Clone(
|
|
7388
|
-
clone : ((self) -> box(
|
|
7494
|
+
clone : ((self) -> box(self.*.clone()))
|
|
7389
7495
|
)
|
|
7390
7496
|
);
|
|
7391
7497
|
export(
|
|
@@ -7515,8 +7621,8 @@ impl(
|
|
|
7515
7621
|
/// Create a new uninitialized value.
|
|
7516
7622
|
new : (fn() -> Self)(__yo_maybe_uninit_new(Self)),
|
|
7517
7623
|
/// Get a mutable pointer to the underlying value.
|
|
7518
|
-
as_ptr : (fn(self :
|
|
7519
|
-
__yo_maybe_uninit_as_ptr(Self, BaseType, self)
|
|
7624
|
+
as_ptr : (fn(ref(self) : Self) -> *(BaseType))(
|
|
7625
|
+
__yo_maybe_uninit_as_ptr(Self, BaseType, &(self))
|
|
7520
7626
|
),
|
|
7521
7627
|
/// Assume the value is initialized and extract it. **Undefined behavior if not initialized.**
|
|
7522
7628
|
assume_init : (fn(own(self) : Self) -> BaseType)(
|
|
@@ -7530,7 +7636,7 @@ Iterator :: trait(
|
|
|
7530
7636
|
Item : Type,
|
|
7531
7637
|
/// Advance the iterator and return the next value, or `None` when exhausted.
|
|
7532
7638
|
next :
|
|
7533
|
-
fn(self :
|
|
7639
|
+
fn(ref(self) : Self) -> Option(Self.Item)
|
|
7534
7640
|
);
|
|
7535
7641
|
export(Iterator);
|
|
7536
7642
|
/// IntoIterator trait — convert a collection into an iterator.
|
|
@@ -7543,29 +7649,25 @@ IntoIterator :: trait(
|
|
|
7543
7649
|
);
|
|
7544
7650
|
export(IntoIterator);
|
|
7545
7651
|
/// === Array Iterator ===
|
|
7546
|
-
|
|
7547
|
-
|
|
7548
|
-
|
|
7549
|
-
|
|
7550
|
-
|
|
7551
|
-
|
|
7552
|
-
|
|
7553
|
-
_index : usize,
|
|
7554
|
-
_len : usize
|
|
7555
|
-
)
|
|
7652
|
+
/// Position iterator for Array(T, N) — yields `usize` indices.
|
|
7653
|
+
/// Used by `Array.iter()`; the for-macro pairs each yielded position
|
|
7654
|
+
/// with `Array.project(pos)` (Indexable trait) to hand the body a
|
|
7655
|
+
/// `ref(T)`-binding into the element. See plans/ITERATOR_REDESIGN.md.
|
|
7656
|
+
_ArrayPosIter :: struct(
|
|
7657
|
+
_index : usize,
|
|
7658
|
+
_len : usize
|
|
7556
7659
|
);
|
|
7557
7660
|
impl(
|
|
7558
|
-
|
|
7559
|
-
ArrayIterPtr(T),
|
|
7661
|
+
_ArrayPosIter,
|
|
7560
7662
|
Iterator(
|
|
7561
|
-
Item :
|
|
7562
|
-
next : (fn(self :
|
|
7663
|
+
Item : usize,
|
|
7664
|
+
next : (fn(ref(self) : Self) -> Option(usize))(
|
|
7563
7665
|
cond(
|
|
7564
7666
|
(self._index >= self._len) =>.None,
|
|
7565
7667
|
true => {
|
|
7566
|
-
|
|
7668
|
+
out := self._index;
|
|
7567
7669
|
self._index = (self._index + usize(1));
|
|
7568
|
-
.Some(
|
|
7670
|
+
.Some(out)
|
|
7569
7671
|
}
|
|
7570
7672
|
)
|
|
7571
7673
|
)
|
|
@@ -7574,34 +7676,30 @@ impl(
|
|
|
7574
7676
|
impl(
|
|
7575
7677
|
forall(T : Type, N : usize),
|
|
7576
7678
|
Array(T, N),
|
|
7577
|
-
iter : (fn(self :
|
|
7578
|
-
|
|
7679
|
+
iter : (fn(ref(self) : Self) -> _ArrayPosIter)(
|
|
7680
|
+
_ArrayPosIter(_index : usize(0), _len : N)
|
|
7579
7681
|
)
|
|
7580
7682
|
);
|
|
7581
|
-
export(ArrayIterPtr);
|
|
7582
7683
|
/// === Slice Iterator ===
|
|
7583
|
-
|
|
7584
|
-
|
|
7585
|
-
|
|
7586
|
-
|
|
7587
|
-
|
|
7588
|
-
|
|
7589
|
-
|
|
7590
|
-
_index : usize
|
|
7591
|
-
)
|
|
7684
|
+
/// Position iterator for Slice(T) — yields `usize` indices into the
|
|
7685
|
+
/// slice. Used by `Slice.iter()`; the for-macro pairs each yielded
|
|
7686
|
+
/// position with `Slice.project(pos)` (Indexable) to bind the body's
|
|
7687
|
+
/// `ref`-name. See plans/ITERATOR_REDESIGN.md.
|
|
7688
|
+
_SlicePosIter :: struct(
|
|
7689
|
+
_index : usize,
|
|
7690
|
+
_len : usize
|
|
7592
7691
|
);
|
|
7593
7692
|
impl(
|
|
7594
|
-
|
|
7595
|
-
SliceIterPtr(T),
|
|
7693
|
+
_SlicePosIter,
|
|
7596
7694
|
Iterator(
|
|
7597
|
-
Item :
|
|
7598
|
-
next : (fn(self :
|
|
7695
|
+
Item : usize,
|
|
7696
|
+
next : (fn(ref(self) : Self) -> Option(usize))(
|
|
7599
7697
|
cond(
|
|
7600
|
-
(self._index >= self.
|
|
7698
|
+
(self._index >= self._len) =>.None,
|
|
7601
7699
|
true => {
|
|
7602
|
-
|
|
7700
|
+
out := self._index;
|
|
7603
7701
|
self._index = (self._index + usize(1));
|
|
7604
|
-
.Some(
|
|
7702
|
+
.Some(out)
|
|
7605
7703
|
}
|
|
7606
7704
|
)
|
|
7607
7705
|
)
|
|
@@ -7610,11 +7708,10 @@ impl(
|
|
|
7610
7708
|
impl(
|
|
7611
7709
|
forall(T : Type),
|
|
7612
7710
|
Slice(T),
|
|
7613
|
-
iter : (fn(self :
|
|
7614
|
-
|
|
7711
|
+
iter : (fn(ref(self) : Self) -> _SlicePosIter)(
|
|
7712
|
+
_SlicePosIter(_index : usize(0), _len : self.len())
|
|
7615
7713
|
)
|
|
7616
7714
|
);
|
|
7617
|
-
export(SliceIterPtr);
|
|
7618
7715
|
/// TryFrom trait — fallible conversion from one type to another.
|
|
7619
7716
|
TryFrom :: (fn(comptime(From) : Type) -> comptime(Trait))(
|
|
7620
7717
|
trait(
|
|
@@ -7678,17 +7775,38 @@ try :: (fn(quote(expr_to_try) : Expr) -> unquote(Expr))({
|
|
|
7678
7775
|
})
|
|
7679
7776
|
});
|
|
7680
7777
|
export(try);
|
|
7681
|
-
/// `for` macro — iterate over a collection
|
|
7778
|
+
/// `for` macro — iterate over a collection. The lambda's binding shape
|
|
7779
|
+
/// dictates whether the iteration borrows or consumes:
|
|
7682
7780
|
///
|
|
7683
|
-
///
|
|
7781
|
+
/// `for(coll, ref(x) => body)` — borrow form. Calls `coll.iter()`
|
|
7782
|
+
/// (must yield positions) + `coll.project(pos)` for each. `x` is
|
|
7783
|
+
/// `ref`-bound to the element; reads auto-deref, writes propagate
|
|
7784
|
+
/// back to the collection; `coll` survives the loop.
|
|
7785
|
+
///
|
|
7786
|
+
/// `for(coll, (x) => body)` — value form. Calls `coll.into_iter()`
|
|
7787
|
+
/// and binds `x` to each yielded value. The collection is moved
|
|
7788
|
+
/// into the iterator and consumed.
|
|
7789
|
+
///
|
|
7790
|
+
/// Combinator chains (`coll.iter().map(f)`, etc.) only support the
|
|
7791
|
+
/// value form — they yield computed values, not borrows. A blanket
|
|
7792
|
+
/// `into_iter` impl on `Iterator` (below) makes the value form work
|
|
7793
|
+
/// transparently on iterator chains.
|
|
7794
|
+
///
|
|
7795
|
+
/// See plans/ITERATOR_REDESIGN.md.
|
|
7796
|
+
///
|
|
7797
|
+
/// # Examples
|
|
7684
7798
|
/// ```rust
|
|
7685
|
-
///
|
|
7686
|
-
///
|
|
7687
|
-
///
|
|
7799
|
+
/// // Borrow form — mutate elements in place.
|
|
7800
|
+
/// for(arr, ref(x) => {
|
|
7801
|
+
/// x = (x + i32(1));
|
|
7802
|
+
/// });
|
|
7803
|
+
///
|
|
7804
|
+
/// // Value form — consume the collection.
|
|
7805
|
+
/// for(list.into_iter(), (x) => print(x));
|
|
7688
7806
|
/// ```
|
|
7689
7807
|
for :: (
|
|
7690
7808
|
fn(
|
|
7691
|
-
quote(
|
|
7809
|
+
quote(coll) : Expr,
|
|
7692
7810
|
quote(handle) : Expr
|
|
7693
7811
|
) -> unquote(Expr)
|
|
7694
7812
|
)({
|
|
@@ -7703,21 +7821,68 @@ for :: (
|
|
|
7703
7821
|
comptime_assert(args.len() == 2, "'for' macro requires 2 arguments in the function handle");
|
|
7704
7822
|
variable :: args.car();
|
|
7705
7823
|
body :: args.cdr().car();
|
|
7706
|
-
|
|
7707
|
-
|
|
7708
|
-
|
|
7709
|
-
|
|
7710
|
-
|
|
7711
|
-
|
|
7712
|
-
|
|
7713
|
-
|
|
7714
|
-
|
|
7715
|
-
|
|
7716
|
-
|
|
7717
|
-
|
|
7718
|
-
)
|
|
7719
|
-
|
|
7720
|
-
|
|
7824
|
+
// Detect `ref(name) => body` — borrow form. Otherwise
|
|
7825
|
+
// it's the value form `(name) => body`.
|
|
7826
|
+
is_ref_form :: cond(
|
|
7827
|
+
variable.is_fn_call() => {
|
|
7828
|
+
v_callee :: variable.get_callee();
|
|
7829
|
+
v_callee.is_atom() && (v_callee == quote(ref))
|
|
7830
|
+
},
|
|
7831
|
+
true => false
|
|
7832
|
+
);
|
|
7833
|
+
cond(
|
|
7834
|
+
is_ref_form => {
|
|
7835
|
+
v_args :: variable.get_args();
|
|
7836
|
+
comptime_assert(v_args.len() == 1, "'for' macro: ref(name) requires exactly one name");
|
|
7837
|
+
name :: v_args.car();
|
|
7838
|
+
iter_var :: gensym("for_iter_var");
|
|
7839
|
+
pos_var :: gensym("for_pos_var");
|
|
7840
|
+
// Note: the borrow form does NOT materialize a local
|
|
7841
|
+
// copy of `coll`. Writes through `ref(x) := …
|
|
7842
|
+
// coll.project(pos)` need to propagate to the caller's
|
|
7843
|
+
// storage; a value-typed local copy would receive the
|
|
7844
|
+
// writes silently. The for-macro consumes `coll` as an
|
|
7845
|
+
// expression directly so the `&coll` pointer it
|
|
7846
|
+
// implicitly forms reaches the caller's collection.
|
|
7847
|
+
// (This is correct for `coll : Array(T, N)` /
|
|
7848
|
+
// `Slice(T)` / `String` value-typed collections and
|
|
7849
|
+
// for `ref(coll)`-bound parameter inputs; for owning
|
|
7850
|
+
// collections like `ArrayList` whose internal storage
|
|
7851
|
+
// is heap, the receiver-by-ref semantics already work.)
|
|
7852
|
+
quote({
|
|
7853
|
+
unquote(iter_var) := unquote(coll).iter();
|
|
7854
|
+
while(runtime(true), {
|
|
7855
|
+
match(
|
|
7856
|
+
unquote(iter_var).next(),
|
|
7857
|
+
.Some(unquote(pos_var)) => {
|
|
7858
|
+
ref(unquote(name)) := unquote(coll).project(unquote(pos_var));
|
|
7859
|
+
unquote(body);
|
|
7860
|
+
},
|
|
7861
|
+
.None => {
|
|
7862
|
+
break;
|
|
7863
|
+
}
|
|
7864
|
+
);
|
|
7865
|
+
});
|
|
7866
|
+
})
|
|
7867
|
+
},
|
|
7868
|
+
true => {
|
|
7869
|
+
iter_var :: gensym("for_iter_var");
|
|
7870
|
+
temp_var :: gensym("for_temp_var");
|
|
7871
|
+
quote({
|
|
7872
|
+
unquote(iter_var) := unquote(coll).into_iter();
|
|
7873
|
+
while(runtime(true), {
|
|
7874
|
+
unquote(temp_var) := unquote(iter_var).next();
|
|
7875
|
+
match(
|
|
7876
|
+
unquote(temp_var),
|
|
7877
|
+
.Some(unquote(variable)) => unquote(body),
|
|
7878
|
+
.None => {
|
|
7879
|
+
break;
|
|
7880
|
+
}
|
|
7881
|
+
)
|
|
7882
|
+
});
|
|
7883
|
+
})
|
|
7884
|
+
}
|
|
7885
|
+
)
|
|
7721
7886
|
},
|
|
7722
7887
|
true => {
|
|
7723
7888
|
comptime_assert(false, "for macro requires a function handle with `=>`");
|
|
@@ -7758,9 +7923,9 @@ impl(
|
|
|
7758
7923
|
IterMap(I, B, F),
|
|
7759
7924
|
Iterator(
|
|
7760
7925
|
Item : B,
|
|
7761
|
-
next : (fn(self :
|
|
7926
|
+
next : (fn(ref(self) : Self) -> Option(B))(
|
|
7762
7927
|
match(
|
|
7763
|
-
|
|
7928
|
+
self._inner.next(),
|
|
7764
7929
|
.None =>.None,
|
|
7765
7930
|
.Some(item) =>.Some((self._f)(item))
|
|
7766
7931
|
)
|
|
@@ -7785,10 +7950,10 @@ impl(
|
|
|
7785
7950
|
IterFilter(I, F),
|
|
7786
7951
|
Iterator(
|
|
7787
7952
|
Item : A,
|
|
7788
|
-
next : (fn(self :
|
|
7953
|
+
next : (fn(ref(self) : Self) -> Option(A))({
|
|
7789
7954
|
(loop_result : Option(A)) =.None;
|
|
7790
7955
|
while(runtime(true), {
|
|
7791
|
-
candidate :=
|
|
7956
|
+
candidate := self._inner.next();
|
|
7792
7957
|
match(
|
|
7793
7958
|
candidate,
|
|
7794
7959
|
.None => {
|
|
@@ -7825,12 +7990,12 @@ impl(
|
|
|
7825
7990
|
IterTake(I),
|
|
7826
7991
|
Iterator(
|
|
7827
7992
|
Item : A,
|
|
7828
|
-
next : (fn(self :
|
|
7993
|
+
next : (fn(ref(self) : Self) -> Option(A))(
|
|
7829
7994
|
cond(
|
|
7830
7995
|
(self._remaining == usize(0)) =>.None,
|
|
7831
7996
|
true => {
|
|
7832
7997
|
self._remaining = (self._remaining - usize(1));
|
|
7833
|
-
|
|
7998
|
+
self._inner.next()
|
|
7834
7999
|
}
|
|
7835
8000
|
)
|
|
7836
8001
|
)
|
|
@@ -7853,9 +8018,9 @@ impl(
|
|
|
7853
8018
|
IterSkip(I),
|
|
7854
8019
|
Iterator(
|
|
7855
8020
|
Item : A,
|
|
7856
|
-
next : (fn(self :
|
|
8021
|
+
next : (fn(ref(self) : Self) -> Option(A))({
|
|
7857
8022
|
while(self._to_skip > usize(0), {
|
|
7858
|
-
result :=
|
|
8023
|
+
result := self._inner.next();
|
|
7859
8024
|
match(
|
|
7860
8025
|
result,
|
|
7861
8026
|
.None => {
|
|
@@ -7867,7 +8032,7 @@ impl(
|
|
|
7867
8032
|
}
|
|
7868
8033
|
);
|
|
7869
8034
|
});
|
|
7870
|
-
|
|
8035
|
+
self._inner.next()
|
|
7871
8036
|
})
|
|
7872
8037
|
)
|
|
7873
8038
|
);
|
|
@@ -7889,9 +8054,9 @@ impl(
|
|
|
7889
8054
|
IterEnumerate(I),
|
|
7890
8055
|
Iterator(
|
|
7891
8056
|
Item : IterPair(usize, A),
|
|
7892
|
-
next : (fn(self :
|
|
8057
|
+
next : (fn(ref(self) : Self) -> Option(IterPair(usize, A)))(
|
|
7893
8058
|
match(
|
|
7894
|
-
|
|
8059
|
+
self._inner.next(),
|
|
7895
8060
|
.None =>.None,
|
|
7896
8061
|
.Some(item) => {
|
|
7897
8062
|
idx := self._index;
|
|
@@ -7920,12 +8085,12 @@ impl(
|
|
|
7920
8085
|
IterZip(I, J),
|
|
7921
8086
|
Iterator(
|
|
7922
8087
|
Item : IterPair(A, B),
|
|
7923
|
-
next : (fn(self :
|
|
8088
|
+
next : (fn(ref(self) : Self) -> Option(IterPair(A, B)))(
|
|
7924
8089
|
match(
|
|
7925
|
-
|
|
8090
|
+
self._left.next(),
|
|
7926
8091
|
.None =>.None,
|
|
7927
8092
|
.Some(a) => match(
|
|
7928
|
-
|
|
8093
|
+
self._right.next(),
|
|
7929
8094
|
.None =>.None,
|
|
7930
8095
|
.Some(b) =>.Some(IterPair(A, B)(_0 : a, _1 : b))
|
|
7931
8096
|
)
|
|
@@ -7937,6 +8102,18 @@ export(IterZip);
|
|
|
7937
8102
|
// ---------------------------------------------------------------------------
|
|
7938
8103
|
// Blanket methods — added to all types implementing Iterator
|
|
7939
8104
|
// ---------------------------------------------------------------------------
|
|
8105
|
+
/// Blanket `into_iter` — every `Iterator` is its own `IntoIterator`,
|
|
8106
|
+
/// returning `self`. This lets `for(combinator_chain, (x) => body)`
|
|
8107
|
+
/// expand to `combinator_chain.into_iter().next()` uniformly with
|
|
8108
|
+
/// `for(coll, (x) => body)` — the macro always calls `.into_iter()`
|
|
8109
|
+
/// for the value-iteration form, and for an iterator we hand back
|
|
8110
|
+
/// self. See plans/ITERATOR_REDESIGN.md.
|
|
8111
|
+
impl(
|
|
8112
|
+
forall(I : Type),
|
|
8113
|
+
where(I <: Iterator),
|
|
8114
|
+
I,
|
|
8115
|
+
into_iter : (fn(self : Self) -> Self)(self)
|
|
8116
|
+
);
|
|
7940
8117
|
impl(
|
|
7941
8118
|
forall(I : Type),
|
|
7942
8119
|
where(I <: Iterator),
|
|
@@ -8020,7 +8197,7 @@ impl(
|
|
|
8020
8197
|
iter := self;
|
|
8021
8198
|
while(runtime(true), {
|
|
8022
8199
|
match(
|
|
8023
|
-
|
|
8200
|
+
iter.next(),
|
|
8024
8201
|
.None => {
|
|
8025
8202
|
break;
|
|
8026
8203
|
},
|
|
@@ -8043,7 +8220,7 @@ impl(
|
|
|
8043
8220
|
iter := self;
|
|
8044
8221
|
while(runtime(true), {
|
|
8045
8222
|
match(
|
|
8046
|
-
|
|
8223
|
+
iter.next(),
|
|
8047
8224
|
.None => {
|
|
8048
8225
|
break;
|
|
8049
8226
|
},
|
|
@@ -8065,7 +8242,7 @@ impl(
|
|
|
8065
8242
|
iter := self;
|
|
8066
8243
|
while(runtime(true), {
|
|
8067
8244
|
match(
|
|
8068
|
-
|
|
8245
|
+
iter.next(),
|
|
8069
8246
|
.None => {
|
|
8070
8247
|
break;
|
|
8071
8248
|
},
|
|
@@ -8089,7 +8266,7 @@ impl(
|
|
|
8089
8266
|
iter := self;
|
|
8090
8267
|
while(runtime(true), {
|
|
8091
8268
|
match(
|
|
8092
|
-
|
|
8269
|
+
iter.next(),
|
|
8093
8270
|
.None => {
|
|
8094
8271
|
break;
|
|
8095
8272
|
},
|
|
@@ -8119,7 +8296,7 @@ impl(
|
|
|
8119
8296
|
iter := self;
|
|
8120
8297
|
while(runtime(true), {
|
|
8121
8298
|
match(
|
|
8122
|
-
|
|
8299
|
+
iter.next(),
|
|
8123
8300
|
.None => {
|
|
8124
8301
|
break;
|
|
8125
8302
|
},
|
|
@@ -8145,7 +8322,7 @@ FutureState :: enum(
|
|
|
8145
8322
|
Running = 1,
|
|
8146
8323
|
/// The future completed successfully.
|
|
8147
8324
|
Completed = -(1),
|
|
8148
|
-
/// The future was aborted (e.g., via `
|
|
8325
|
+
/// The future was aborted (e.g., via `unwind`).
|
|
8149
8326
|
Aborted = -(2)
|
|
8150
8327
|
);
|
|
8151
8328
|
impl(FutureState, Acyclic());
|
|
@@ -8169,41 +8346,41 @@ JoinHandle :: (fn(comptime(T) : Type) -> comptime(Type))(
|
|
|
8169
8346
|
)
|
|
8170
8347
|
);
|
|
8171
8348
|
export(JoinHandle);
|
|
8172
|
-
///
|
|
8349
|
+
/// Io module — the async runtime effect.
|
|
8173
8350
|
///
|
|
8174
8351
|
/// Provides `io.async`, `io.await`, `io.spawn`, and `io.state` operations.
|
|
8175
|
-
/// Automatically injected into `main` when declared with `
|
|
8176
|
-
|
|
8352
|
+
/// Automatically injected into `main` when declared with `io : Io`.
|
|
8353
|
+
Io :: struct(
|
|
8177
8354
|
/// Create a new `Future` from an async closure.
|
|
8178
|
-
async : (fn(forall(T : Type,
|
|
8355
|
+
async : (fn(forall(T : Type, E : Type.Struct), action : Impl(Fn(e : E) -> T)) -> Impl(Future(T, E))),
|
|
8179
8356
|
/// Await a `Future`, suspending until its result is ready.
|
|
8180
|
-
await : (fn(forall(T : Type,
|
|
8357
|
+
await : (fn(forall(T : Type, E : Type.Struct), fut : Impl(Future(T, E)), e : E) -> T),
|
|
8181
8358
|
/// Inspect the current state of a `Future` without blocking.
|
|
8182
|
-
state : (fn(forall(T : Type,
|
|
8359
|
+
state : (fn(forall(T : Type, E : Type), fut : Impl(Future(T, E))) -> FutureState),
|
|
8183
8360
|
/// Spawn a `Future` as an independent task, returning a `JoinHandle`.
|
|
8184
|
-
spawn : (fn(forall(T : Type,
|
|
8361
|
+
spawn : (fn(forall(T : Type, E : Type.Struct), fut : Impl(Future(T, E)), e : E) -> JoinHandle(T))
|
|
8185
8362
|
);
|
|
8186
|
-
export(
|
|
8363
|
+
export(Io);
|
|
8187
8364
|
extern(
|
|
8188
8365
|
"Yo",
|
|
8189
|
-
__yo_io_async : (fn(forall(T : Type,
|
|
8190
|
-
__yo_io_await : (fn(forall(T : Type,
|
|
8191
|
-
__yo_io_state : (fn(forall(T : Type,
|
|
8192
|
-
__yo_io_spawn : (fn(forall(T : Type,
|
|
8193
|
-
);
|
|
8194
|
-
/// Built-in
|
|
8195
|
-
/// with `
|
|
8196
|
-
__yo_builtin_io ::
|
|
8366
|
+
__yo_io_async : (fn(forall(T : Type, E : Type.Struct), action : Impl(Fn(e : E) -> T)) -> Impl(Future(T, E))),
|
|
8367
|
+
__yo_io_await : (fn(forall(T : Type, E : Type.Struct), fut : Impl(Future(T, E)), e : E) -> T),
|
|
8368
|
+
__yo_io_state : (fn(forall(T : Type, E : Type), fut : Impl(Future(T, E))) -> FutureState),
|
|
8369
|
+
__yo_io_spawn : (fn(forall(T : Type, E : Type.Struct), fut : Impl(Future(T, E)), e : E) -> JoinHandle(T))
|
|
8370
|
+
);
|
|
8371
|
+
/// Built-in Io module instance. Automatically injected for `main` functions
|
|
8372
|
+
/// with `io : Io`.
|
|
8373
|
+
__yo_builtin_io :: Io(
|
|
8197
8374
|
async : __yo_io_async,
|
|
8198
8375
|
await : __yo_io_await,
|
|
8199
8376
|
state : __yo_io_state,
|
|
8200
8377
|
spawn : __yo_io_spawn
|
|
8201
8378
|
);
|
|
8202
8379
|
export(__yo_builtin_io);
|
|
8203
|
-
/// JoinHandle methods — defined after
|
|
8380
|
+
/// JoinHandle methods — defined after Io so `io : Io` resolves.
|
|
8204
8381
|
extern(
|
|
8205
8382
|
"Yo",
|
|
8206
|
-
__yo_join_handle_await : (fn(forall(T : Type), self : JoinHandle(T),
|
|
8383
|
+
__yo_join_handle_await : (fn(forall(T : Type), self : JoinHandle(T), io : Io) -> Option(T))
|
|
8207
8384
|
);
|
|
8208
8385
|
impl(
|
|
8209
8386
|
forall(T : Type),
|