@shd101wyy/yo 0.1.33 → 0.1.34
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-core-patterns/SKILL.md +1 -1
- package/.github/skills/yo-core-patterns/core-patterns-cheatsheet.md +51 -21
- package/.github/skills/yo-syntax/SKILL.md +1 -1
- package/.github/skills/yo-syntax/syntax-cheatsheet.md +56 -67
- package/out/cjs/index.cjs +664 -649
- package/out/cjs/yo-cli.cjs +736 -721
- package/out/cjs/yo-lsp.cjs +682 -667
- package/out/esm/index.mjs +498 -483
- package/out/types/src/codegen/exprs/comptime-value.d.ts +2 -1
- package/out/types/src/codegen/types/generation.d.ts +1 -1
- package/out/types/src/codegen/utils/index.d.ts +2 -4
- package/out/types/src/evaluator/exprs/_expr.d.ts +1 -0
- package/out/types/src/evaluator/types/flowability.d.ts +21 -0
- package/out/types/src/expr.d.ts +4 -13
- package/out/types/src/types/creators.d.ts +2 -3
- package/out/types/src/types/definitions.d.ts +2 -3
- package/out/types/src/types/guards.d.ts +2 -2
- package/out/types/src/types/tags.d.ts +2 -2
- package/out/types/src/value-tag.d.ts +0 -1
- package/out/types/src/value.d.ts +2 -11
- package/out/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/std/alg/hash.yo +5 -3
- package/std/build.yo +46 -46
- package/std/collections/array_list.yo +73 -66
- package/std/collections/hash_map.yo +2 -81
- package/std/collections/list_view.yo +77 -0
- package/std/crypto/random.yo +5 -5
- package/std/encoding/base64.yo +12 -13
- package/std/encoding/hex.yo +6 -6
- package/std/encoding/json.yo +6 -5
- package/std/encoding/utf16.yo +9 -9
- package/std/env.yo +8 -8
- package/std/fmt/to_string.yo +12 -12
- package/std/http/client.yo +1 -1
- package/std/imm/list.yo +4 -3
- package/std/imm/map.yo +3 -2
- package/std/imm/set.yo +4 -3
- package/std/imm/sorted_map.yo +3 -2
- package/std/imm/sorted_set.yo +4 -3
- package/std/imm/string.yo +12 -5
- package/std/imm/vec.yo +8 -3
- package/std/prelude.yo +174 -401
- package/std/string/string.yo +198 -71
- package/std/url/index.yo +26 -26
- package/out/types/src/evaluator/types/slice.d.ts +0 -8
package/std/prelude.yo
CHANGED
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
// `Comptime` and `Runtime` are defined first because every other
|
|
13
13
|
// type (including `Pragma` below) is type-checked against them.
|
|
14
14
|
/// Comptime trait — indicates a type that can be used at compile-time.
|
|
15
|
-
/// Examples: `i32`, `bool`, `Type`, `comptime_int`, `comptime_float`, `
|
|
15
|
+
/// Examples: `i32`, `bool`, `Type`, `comptime_int`, `comptime_float`, `comptime_str`.
|
|
16
16
|
/// Non-examples: `int`, `ushort` (runtime-only types).
|
|
17
17
|
Comptime :: trait(
|
|
18
18
|
id := "Comptime"
|
|
@@ -20,7 +20,7 @@ Comptime :: trait(
|
|
|
20
20
|
export(Comptime);
|
|
21
21
|
/// Runtime trait — indicates a type that can be used at runtime.
|
|
22
22
|
/// Examples: `i32`, `bool`, `*(i32)`, `void`.
|
|
23
|
-
/// Non-examples: `comptime_int`, `comptime_float`, `
|
|
23
|
+
/// Non-examples: `comptime_int`, `comptime_float`, `comptime_str`, `Type` (compile-time-only types).
|
|
24
24
|
Runtime :: trait(
|
|
25
25
|
id := "Runtime"
|
|
26
26
|
);
|
|
@@ -145,27 +145,27 @@ extern(
|
|
|
145
145
|
fn(forall(T : Type), ptr1 : T, ptr2 : T) -> bool,
|
|
146
146
|
__yo_ptr_gte :
|
|
147
147
|
fn(forall(T : Type), ptr1 : T, ptr2 : T) -> bool,
|
|
148
|
-
//
|
|
149
|
-
|
|
150
|
-
fn(
|
|
151
|
-
|
|
152
|
-
fn(
|
|
153
|
-
|
|
154
|
-
fn(
|
|
155
|
-
|
|
148
|
+
// str (builtin static string view) intrinsics
|
|
149
|
+
__yo_str_from_raw_parts :
|
|
150
|
+
fn(ptr : *(u8), length : usize) -> str,
|
|
151
|
+
__yo_str_len :
|
|
152
|
+
fn(s : str) -> usize,
|
|
153
|
+
__yo_str_ptr :
|
|
154
|
+
fn(s : str) -> *(u8),
|
|
155
|
+
__yo_str_byte :
|
|
156
|
+
fn(s : str, idx : usize) -> u8,
|
|
157
|
+
// array indexing builtin (used by Index trait impls)
|
|
156
158
|
__yo_array_index :
|
|
157
159
|
fn(forall(T : Type, N : usize), self : *(Array(T, N)), idx : usize) -> *(T),
|
|
158
|
-
__yo_slice_index :
|
|
159
|
-
fn(forall(T : Type), self : *(Slice(T)), idx : usize) -> *(T),
|
|
160
160
|
// C macro related
|
|
161
|
-
__yo_c_macro_defined : (fn(comptime(name) :
|
|
162
|
-
__yo_c_macro_value : (fn(comptime(name) :
|
|
161
|
+
__yo_c_macro_defined : (fn(comptime(name) : comptime_str) -> comptime(bool)),
|
|
162
|
+
__yo_c_macro_value : (fn(comptime(name) : comptime_str) -> comptime(comptime_str)),
|
|
163
163
|
// Process related functions
|
|
164
|
-
__yo_process_platform : (fn() -> comptime(
|
|
165
|
-
__yo_process_arch : (fn() -> comptime(
|
|
166
|
-
__yo_process_cwd : (fn() -> comptime(
|
|
167
|
-
__yo_process_env_get : (fn(comptime(key) :
|
|
168
|
-
__yo_process_node_version : (fn() -> comptime(
|
|
164
|
+
__yo_process_platform : (fn() -> comptime(comptime_str)),
|
|
165
|
+
__yo_process_arch : (fn() -> comptime(comptime_str)),
|
|
166
|
+
__yo_process_cwd : (fn() -> comptime(comptime_str)),
|
|
167
|
+
__yo_process_env_get : (fn(comptime(key) : comptime_str) -> comptime(comptime_str)),
|
|
168
|
+
__yo_process_node_version : (fn() -> comptime(comptime_str))
|
|
169
169
|
);
|
|
170
170
|
export(__yo_as);
|
|
171
171
|
/// The `unsafe` module — provides low-level unwind hatches.
|
|
@@ -181,7 +181,7 @@ export(unsafe);
|
|
|
181
181
|
// c_macro :: impl {
|
|
182
182
|
// /// Check if a C macro is defined
|
|
183
183
|
// /// Returns true if the macro exists, false otherwise
|
|
184
|
-
// defined :: (fn(comptime(name) :
|
|
184
|
+
// defined :: (fn(comptime(name) : comptime_str) -> comptime(bool))(
|
|
185
185
|
// __yo_c_macro_defined(name)
|
|
186
186
|
// );
|
|
187
187
|
// export defined;
|
|
@@ -189,13 +189,13 @@ export(unsafe);
|
|
|
189
189
|
// /// Get the value of a C macro as a compile-time string
|
|
190
190
|
// /// Returns the macro's value as a string, or empty string "" if not defined
|
|
191
191
|
// /// Note: For function-like macros, returns the definition without expansion
|
|
192
|
-
// value :: (fn(comptime(name) :
|
|
192
|
+
// value :: (fn(comptime(name) : comptime_str) -> comptime(comptime_str))(
|
|
193
193
|
// __yo_c_macro_value(name)
|
|
194
194
|
// );
|
|
195
195
|
// export value;
|
|
196
196
|
//
|
|
197
197
|
// /// Get a macro value with a default fallback
|
|
198
|
-
// value_or :: (fn(comptime(name) :
|
|
198
|
+
// value_or :: (fn(comptime(name) : comptime_str, comptime(default_val) : comptime_str) -> comptime(comptime_str))(
|
|
199
199
|
// cond(
|
|
200
200
|
// defined(name) => value(name),
|
|
201
201
|
// true => default_val
|
|
@@ -239,21 +239,6 @@ Index :: (fn(comptime(Idx) : Type) -> comptime(Trait))(
|
|
|
239
239
|
)
|
|
240
240
|
);
|
|
241
241
|
export(Index);
|
|
242
|
-
/// Indexable trait — projection-style indexing yielding a borrow.
|
|
243
|
-
/// Companion to `Index`, but instead of returning a raw `*(T)` the
|
|
244
|
-
/// `project` method returns a `ref(Element)` — a second-class
|
|
245
|
-
/// reference that flows through Yo's flowability rule (R1–R4) and
|
|
246
|
-
/// can be received by a `ref(name) := coll.project(pos);` local
|
|
247
|
-
/// binding. The for-loop macro lowers iteration through this trait
|
|
248
|
-
/// so user code never sees a raw pointer. See
|
|
249
|
-
/// plans/ITERATOR_REDESIGN.md.
|
|
250
|
-
Indexable :: (fn(comptime(Idx) : Type) -> comptime(Trait))(
|
|
251
|
-
trait(
|
|
252
|
-
Element : Type,
|
|
253
|
-
project : (fn(ref(self) : Self, pos : Idx) -> ref(Self.Element))
|
|
254
|
-
)
|
|
255
|
-
);
|
|
256
|
-
export(Indexable);
|
|
257
242
|
/// ComptimeIndex — compile-time indexing trait for constant expressions.
|
|
258
243
|
ComptimeIndex :: (fn(comptime(Idx) : Type, where(Idx <: Comptime)) -> comptime(Trait))(
|
|
259
244
|
trait(
|
|
@@ -283,39 +268,17 @@ RangeInclusiveOp :: trait(
|
|
|
283
268
|
(..=) : (fn(start : Self, end : Self) -> RangeInclusive(Self))
|
|
284
269
|
);
|
|
285
270
|
export(RangeInclusiveOp);
|
|
286
|
-
// array/slice range indexing builtins (declared after Range/RangeInclusive types)
|
|
287
|
-
extern(
|
|
288
|
-
"Yo",
|
|
289
|
-
__yo_array_index_range :
|
|
290
|
-
fn(forall(T : Type, N : usize), self : *(Array(T, N)), idx : Range(usize)) -> *(Slice(T)),
|
|
291
|
-
__yo_array_index_range_inclusive :
|
|
292
|
-
fn(forall(T : Type, N : usize), self : *(Array(T, N)), idx : RangeInclusive(usize)) -> *(Slice(T)),
|
|
293
|
-
__yo_slice_index_range :
|
|
294
|
-
fn(forall(T : Type), self : *(Slice(T)), idx : Range(usize)) -> *(Slice(T)),
|
|
295
|
-
__yo_slice_index_range_inclusive :
|
|
296
|
-
fn(forall(T : Type), self : *(Slice(T)), idx : RangeInclusive(usize)) -> *(Slice(T))
|
|
297
|
-
);
|
|
298
271
|
// comptime array/slice/string indexing builtins (used by ComptimeIndex trait impls)
|
|
299
272
|
extern(
|
|
300
273
|
"Yo",
|
|
301
274
|
__yo_comptime_array_index :
|
|
302
275
|
(fn(forall(T : Type, N : usize), comptime(self) : *(Array(T, N)), comptime(idx) : usize, where(T <: Comptime)) -> comptime(*(T))),
|
|
303
|
-
__yo_comptime_slice_index :
|
|
304
|
-
(fn(forall(T : Type), comptime(self) : *(Slice(T)), comptime(idx) : usize, where(T <: Comptime)) -> comptime(*(T))),
|
|
305
|
-
__yo_comptime_array_index_range :
|
|
306
|
-
(fn(forall(T : Type, N : usize), comptime(self) : *(Array(T, N)), comptime(idx) : Range(usize), where(T <: Comptime)) -> comptime(*(Slice(T)))),
|
|
307
|
-
__yo_comptime_array_index_range_inclusive :
|
|
308
|
-
(fn(forall(T : Type, N : usize), comptime(self) : *(Array(T, N)), comptime(idx) : RangeInclusive(usize), where(T <: Comptime)) -> comptime(*(Slice(T)))),
|
|
309
|
-
__yo_comptime_slice_index_range :
|
|
310
|
-
(fn(forall(T : Type), comptime(self) : *(Slice(T)), comptime(idx) : Range(usize), where(T <: Comptime)) -> comptime(*(Slice(T)))),
|
|
311
|
-
__yo_comptime_slice_index_range_inclusive :
|
|
312
|
-
(fn(forall(T : Type), comptime(self) : *(Slice(T)), comptime(idx) : RangeInclusive(usize), where(T <: Comptime)) -> comptime(*(Slice(T)))),
|
|
313
276
|
__yo_comptime_string_index :
|
|
314
|
-
(fn(comptime(self) :
|
|
277
|
+
(fn(comptime(self) : comptime_str, comptime(idx) : comptime_int) -> comptime(comptime_str)),
|
|
315
278
|
__yo_comptime_string_index_range :
|
|
316
|
-
(fn(comptime(self) :
|
|
279
|
+
(fn(comptime(self) : comptime_str, comptime(idx) : Range(comptime_int)) -> comptime(comptime_str)),
|
|
317
280
|
__yo_comptime_string_index_range_inclusive :
|
|
318
|
-
(fn(comptime(self) :
|
|
281
|
+
(fn(comptime(self) : comptime_str, comptime(idx) : RangeInclusive(comptime_int)) -> comptime(comptime_str)),
|
|
319
282
|
__yo_comptime_list_index :
|
|
320
283
|
(fn(forall(T : Type), comptime(self) : *(ComptimeList(T)), comptime(idx) : usize, where(T <: Comptime)) -> comptime(*(T))),
|
|
321
284
|
__yo_comptime_list_index_range :
|
|
@@ -739,11 +702,11 @@ Isolation :: trait(
|
|
|
739
702
|
export(Isolation);
|
|
740
703
|
/// ComptimeToString trait — compile-time string conversion.
|
|
741
704
|
ComptimeToString :: trait(
|
|
742
|
-
to_comptime_string : (fn(comptime(self) : Self) -> comptime(
|
|
705
|
+
to_comptime_string : (fn(comptime(self) : Self) -> comptime(comptime_str)),
|
|
743
706
|
where(Self <: Comptime)
|
|
744
707
|
);
|
|
745
708
|
// SAFETY: All builtin primitive types (unit, void, comptime_int,
|
|
746
|
-
// comptime_float,
|
|
709
|
+
// comptime_float, comptime_str, bool, i8/i16/i32/i64, u8/u16/u32/u64,
|
|
747
710
|
// f32/f64, isize/usize, char/int/uint/short/ushort/long/ulong/longlong/
|
|
748
711
|
// ulonglong/longdouble) are plain value types with no heap allocations
|
|
749
712
|
// or thread-local state. They are trivially safe to send across threads
|
|
@@ -974,13 +937,13 @@ impl(
|
|
|
974
937
|
);
|
|
975
938
|
_comptime_float :: comptime_float;
|
|
976
939
|
export(comptime_float : _comptime_float);
|
|
977
|
-
///
|
|
978
|
-
impl(
|
|
979
|
-
impl(
|
|
940
|
+
/// comptime_str
|
|
941
|
+
impl(comptime_str, Acyclic());
|
|
942
|
+
impl(comptime_str, Comptime());
|
|
980
943
|
impl(
|
|
981
|
-
|
|
982
|
-
ComptimeAdd(
|
|
983
|
-
Output :
|
|
944
|
+
comptime_str,
|
|
945
|
+
ComptimeAdd(comptime_str)(
|
|
946
|
+
Output : comptime_str,
|
|
984
947
|
(+) : (
|
|
985
948
|
(lhs, rhs) ->
|
|
986
949
|
__yo_comptime_string_concat(lhs, rhs)
|
|
@@ -988,8 +951,8 @@ impl(
|
|
|
988
951
|
)
|
|
989
952
|
);
|
|
990
953
|
impl(
|
|
991
|
-
|
|
992
|
-
ComptimeEq(
|
|
954
|
+
comptime_str,
|
|
955
|
+
ComptimeEq(comptime_str)(
|
|
993
956
|
(==) : (
|
|
994
957
|
(lhs, rhs) ->
|
|
995
958
|
__yo_comptime_string_eq(lhs, rhs)
|
|
@@ -1001,8 +964,8 @@ impl(
|
|
|
1001
964
|
)
|
|
1002
965
|
);
|
|
1003
966
|
impl(
|
|
1004
|
-
|
|
1005
|
-
ComptimeOrd(
|
|
967
|
+
comptime_str,
|
|
968
|
+
ComptimeOrd(comptime_str)(
|
|
1006
969
|
(<) : (
|
|
1007
970
|
(lhs, rhs) ->
|
|
1008
971
|
__yo_comptime_string_lt(lhs, rhs)
|
|
@@ -1022,25 +985,25 @@ impl(
|
|
|
1022
985
|
)
|
|
1023
986
|
);
|
|
1024
987
|
impl(
|
|
1025
|
-
|
|
1026
|
-
len : (fn(comptime(self) :
|
|
988
|
+
comptime_str,
|
|
989
|
+
len : (fn(comptime(self) : comptime_str) -> comptime(comptime_int))(
|
|
1027
990
|
__yo_comptime_string_length(self)
|
|
1028
991
|
),
|
|
1029
|
-
(to_upper) : (fn(comptime(self) :
|
|
992
|
+
(to_upper) : (fn(comptime(self) : comptime_str) -> comptime(comptime_str))(
|
|
1030
993
|
__yo_comptime_string_to_upper(self)
|
|
1031
994
|
),
|
|
1032
|
-
(to_lower) : (fn(comptime(self) :
|
|
995
|
+
(to_lower) : (fn(comptime(self) : comptime_str) -> comptime(comptime_str))(
|
|
1033
996
|
__yo_comptime_string_to_lower(self)
|
|
1034
997
|
),
|
|
1035
|
-
slice : (fn(comptime(self) :
|
|
998
|
+
slice : (fn(comptime(self) : comptime_str, comptime(start) : comptime_int, comptime(end) : comptime_int) -> comptime(comptime_str))(
|
|
1036
999
|
__yo_comptime_string_slice(self, start, end)
|
|
1037
1000
|
),
|
|
1038
|
-
to_expr : (fn(comptime(self) :
|
|
1001
|
+
to_expr : (fn(comptime(self) : comptime_str) -> comptime(Expr))(
|
|
1039
1002
|
__yo_comptime_string_to_expr(self)
|
|
1040
1003
|
)
|
|
1041
1004
|
);
|
|
1042
|
-
_comptime_string ::
|
|
1043
|
-
export(
|
|
1005
|
+
_comptime_string :: comptime_str;
|
|
1006
|
+
export(comptime_str : _comptime_string);
|
|
1044
1007
|
/// bool
|
|
1045
1008
|
impl(bool, Send());
|
|
1046
1009
|
impl(bool, Acyclic());
|
|
@@ -5605,119 +5568,19 @@ impl(
|
|
|
5605
5568
|
)
|
|
5606
5569
|
)
|
|
5607
5570
|
);
|
|
5608
|
-
|
|
5609
|
-
|
|
5610
|
-
|
|
5611
|
-
|
|
5612
|
-
|
|
5613
|
-
|
|
5614
|
-
|
|
5615
|
-
)
|
|
5616
|
-
)
|
|
5617
|
-
);
|
|
5618
|
-
impl(
|
|
5619
|
-
forall(T : Type, N : usize),
|
|
5620
|
-
Array(T, N),
|
|
5621
|
-
Index(RangeInclusive(usize))(
|
|
5622
|
-
Output : Slice(T),
|
|
5623
|
-
index : (fn(ref(self) : Self, idx : RangeInclusive(usize)) -> *(Self.Output))(
|
|
5624
|
-
__yo_array_index_range_inclusive(&(self), idx)
|
|
5625
|
-
)
|
|
5626
|
-
)
|
|
5571
|
+
/// RawSlice — a plain ptr+len pair for PRIVILEGED (pragma'd) code: C
|
|
5572
|
+
/// interop and std internals. Carries a raw pointer, so the existing
|
|
5573
|
+
/// raw-pointer gates apply: safe code cannot name or construct it.
|
|
5574
|
+
/// Replaces the builtin Slice(T) for internal plumbing
|
|
5575
|
+
/// (plans/SLICE_REWORK.md step 4).
|
|
5576
|
+
RawSlice :: (fn(comptime(T) : Type) -> comptime(Type))(
|
|
5577
|
+
struct(ptr : *(T), len : usize)
|
|
5627
5578
|
);
|
|
5628
|
-
|
|
5629
|
-
/// Body takes `&(self)` so `__yo_array_index`'s `self : *(Array(T, N))`
|
|
5630
|
-
/// parameter is satisfied — the `ref(self) : Self` binding gives the
|
|
5631
|
-
/// body a value-typed view of `self` even though the C ABI passes a
|
|
5632
|
-
/// pointer. The `unsafe` wrap is the trusted escape from the
|
|
5633
|
-
/// flowability rule (privileged code only). See plans/ITERATOR_REDESIGN.md.
|
|
5634
|
-
impl(
|
|
5635
|
-
forall(T : Type, N : usize),
|
|
5636
|
-
Array(T, N),
|
|
5637
|
-
Indexable(usize)(
|
|
5638
|
-
Element : T,
|
|
5639
|
-
project : (fn(ref(self) : Self, pos : usize) -> ref(T))(
|
|
5640
|
-
cond(
|
|
5641
|
-
(pos >= N) => panic("Array: project out of bounds"),
|
|
5642
|
-
true => unsafe(__yo_array_index(&(self), pos))
|
|
5643
|
-
)
|
|
5644
|
-
)
|
|
5645
|
-
)
|
|
5646
|
-
);
|
|
5647
|
-
/// Slice
|
|
5648
|
-
// SAFETY: Slice(T) is a value-typed view (pointer + length) over a backing
|
|
5579
|
+
export(RawSlice);
|
|
5649
5580
|
// array. Sending a slice across threads copies the header; both threads
|
|
5650
5581
|
// can independently read the backing array. The backing array's lifetime
|
|
5651
5582
|
// is managed by its owning collection (which must itself be Send to cross
|
|
5652
5583
|
// threads). Slice is always Acyclic — it is a value type with no ARC.
|
|
5653
|
-
impl(forall(T : Type), where(T <: Send), Slice(T), Send());
|
|
5654
|
-
impl(forall(T : Type), Slice(T), Acyclic());
|
|
5655
|
-
impl(forall(T : Type), where(T <: Comptime), Slice(T), Comptime());
|
|
5656
|
-
impl(forall(T : Type), where(T <: Runtime), Slice(T), Runtime());
|
|
5657
|
-
impl(forall(T : Type), Range(T), Acyclic());
|
|
5658
|
-
impl(forall(T : Type), where(T <: Comptime), Range(T), Comptime());
|
|
5659
|
-
impl(forall(T : Type), where(T <: Runtime), Range(T), Runtime());
|
|
5660
|
-
impl(forall(T : Type), RangeInclusive(T), Acyclic());
|
|
5661
|
-
impl(forall(T : Type), where(T <: Comptime), RangeInclusive(T), Comptime());
|
|
5662
|
-
impl(forall(T : Type), where(T <: Runtime), RangeInclusive(T), Runtime());
|
|
5663
|
-
impl(
|
|
5664
|
-
forall(T : Type),
|
|
5665
|
-
Slice(T),
|
|
5666
|
-
from_raw_parts : (fn(ptr : *(T), length : usize) -> Self)(
|
|
5667
|
-
__yo_slice_new(ptr, length)
|
|
5668
|
-
),
|
|
5669
|
-
len : (fn(self : Self) -> usize)(
|
|
5670
|
-
__yo_slice_len(self)
|
|
5671
|
-
),
|
|
5672
|
-
ptr : (fn(self : Self) -> *(T))(
|
|
5673
|
-
__yo_slice_ptr(self)
|
|
5674
|
-
)
|
|
5675
|
-
);
|
|
5676
|
-
/// Slice Index impls (same `&(self)` rationale as Array above).
|
|
5677
|
-
impl(
|
|
5678
|
-
forall(T : Type),
|
|
5679
|
-
Slice(T),
|
|
5680
|
-
Index(usize)(
|
|
5681
|
-
Output : T,
|
|
5682
|
-
index : (fn(ref(self) : Self, idx : usize) -> *(Self.Output))(
|
|
5683
|
-
__yo_slice_index(&(self), idx)
|
|
5684
|
-
)
|
|
5685
|
-
)
|
|
5686
|
-
);
|
|
5687
|
-
impl(
|
|
5688
|
-
forall(T : Type),
|
|
5689
|
-
Slice(T),
|
|
5690
|
-
Index(Range(usize))(
|
|
5691
|
-
Output : Slice(T),
|
|
5692
|
-
index : (fn(ref(self) : Self, idx : Range(usize)) -> *(Self.Output))(
|
|
5693
|
-
__yo_slice_index_range(&(self), idx)
|
|
5694
|
-
)
|
|
5695
|
-
)
|
|
5696
|
-
);
|
|
5697
|
-
impl(
|
|
5698
|
-
forall(T : Type),
|
|
5699
|
-
Slice(T),
|
|
5700
|
-
Index(RangeInclusive(usize))(
|
|
5701
|
-
Output : Slice(T),
|
|
5702
|
-
index : (fn(ref(self) : Self, idx : RangeInclusive(usize)) -> *(Self.Output))(
|
|
5703
|
-
__yo_slice_index_range_inclusive(&(self), idx)
|
|
5704
|
-
)
|
|
5705
|
-
)
|
|
5706
|
-
);
|
|
5707
|
-
/// Slice Indexable impl — see Array Indexable above.
|
|
5708
|
-
impl(
|
|
5709
|
-
forall(T : Type),
|
|
5710
|
-
Slice(T),
|
|
5711
|
-
Indexable(usize)(
|
|
5712
|
-
Element : T,
|
|
5713
|
-
project : (fn(ref(self) : Self, pos : usize) -> ref(T))(
|
|
5714
|
-
cond(
|
|
5715
|
-
(pos >= self.len()) => panic("Slice: project out of bounds"),
|
|
5716
|
-
true => unsafe(__yo_slice_index(&(self), pos))
|
|
5717
|
-
)
|
|
5718
|
-
)
|
|
5719
|
-
)
|
|
5720
|
-
);
|
|
5721
5584
|
/// Array ComptimeIndex impls
|
|
5722
5585
|
impl(
|
|
5723
5586
|
forall(T : Type, N : usize),
|
|
@@ -5730,67 +5593,11 @@ impl(
|
|
|
5730
5593
|
)
|
|
5731
5594
|
)
|
|
5732
5595
|
);
|
|
5596
|
+
/// comptime_str ComptimeIndex impls
|
|
5733
5597
|
impl(
|
|
5734
|
-
|
|
5735
|
-
where(T <: Comptime),
|
|
5736
|
-
Array(T, N),
|
|
5737
|
-
ComptimeIndex(Range(usize))(
|
|
5738
|
-
Output : Slice(T),
|
|
5739
|
-
index : (fn(comptime(ref(self)) : Self, comptime(idx) : Range(usize)) -> comptime(*(Self.Output)))(
|
|
5740
|
-
__yo_comptime_array_index_range(self, idx)
|
|
5741
|
-
)
|
|
5742
|
-
)
|
|
5743
|
-
);
|
|
5744
|
-
impl(
|
|
5745
|
-
forall(T : Type, N : usize),
|
|
5746
|
-
where(T <: Comptime),
|
|
5747
|
-
Array(T, N),
|
|
5748
|
-
ComptimeIndex(RangeInclusive(usize))(
|
|
5749
|
-
Output : Slice(T),
|
|
5750
|
-
index : (fn(comptime(ref(self)) : Self, comptime(idx) : RangeInclusive(usize)) -> comptime(*(Self.Output)))(
|
|
5751
|
-
__yo_comptime_array_index_range_inclusive(self, idx)
|
|
5752
|
-
)
|
|
5753
|
-
)
|
|
5754
|
-
);
|
|
5755
|
-
/// Slice ComptimeIndex impls
|
|
5756
|
-
impl(
|
|
5757
|
-
forall(T : Type),
|
|
5758
|
-
where(T <: Comptime),
|
|
5759
|
-
Slice(T),
|
|
5760
|
-
ComptimeIndex(usize)(
|
|
5761
|
-
Output : T,
|
|
5762
|
-
index : (fn(comptime(ref(self)) : Self, comptime(idx) : usize) -> comptime(*(Self.Output)))(
|
|
5763
|
-
__yo_comptime_slice_index(self, idx)
|
|
5764
|
-
)
|
|
5765
|
-
)
|
|
5766
|
-
);
|
|
5767
|
-
impl(
|
|
5768
|
-
forall(T : Type),
|
|
5769
|
-
where(T <: Comptime),
|
|
5770
|
-
Slice(T),
|
|
5771
|
-
ComptimeIndex(Range(usize))(
|
|
5772
|
-
Output : Slice(T),
|
|
5773
|
-
index : (fn(comptime(ref(self)) : Self, comptime(idx) : Range(usize)) -> comptime(*(Self.Output)))(
|
|
5774
|
-
__yo_comptime_slice_index_range(self, idx)
|
|
5775
|
-
)
|
|
5776
|
-
)
|
|
5777
|
-
);
|
|
5778
|
-
impl(
|
|
5779
|
-
forall(T : Type),
|
|
5780
|
-
where(T <: Comptime),
|
|
5781
|
-
Slice(T),
|
|
5782
|
-
ComptimeIndex(RangeInclusive(usize))(
|
|
5783
|
-
Output : Slice(T),
|
|
5784
|
-
index : (fn(comptime(ref(self)) : Self, comptime(idx) : RangeInclusive(usize)) -> comptime(*(Self.Output)))(
|
|
5785
|
-
__yo_comptime_slice_index_range_inclusive(self, idx)
|
|
5786
|
-
)
|
|
5787
|
-
)
|
|
5788
|
-
);
|
|
5789
|
-
/// comptime_string ComptimeIndex impls
|
|
5790
|
-
impl(
|
|
5791
|
-
comptime_string,
|
|
5598
|
+
comptime_str,
|
|
5792
5599
|
ComptimeIndex(comptime_int)(
|
|
5793
|
-
Output :
|
|
5600
|
+
Output : comptime_str,
|
|
5794
5601
|
index : (
|
|
5795
5602
|
(self, idx) ->
|
|
5796
5603
|
__yo_comptime_string_index(self, idx)
|
|
@@ -5798,9 +5605,9 @@ impl(
|
|
|
5798
5605
|
)
|
|
5799
5606
|
);
|
|
5800
5607
|
impl(
|
|
5801
|
-
|
|
5608
|
+
comptime_str,
|
|
5802
5609
|
ComptimeIndex(Range(comptime_int))(
|
|
5803
|
-
Output :
|
|
5610
|
+
Output : comptime_str,
|
|
5804
5611
|
index : (
|
|
5805
5612
|
(self, idx) ->
|
|
5806
5613
|
__yo_comptime_string_index_range(self, idx)
|
|
@@ -5808,37 +5615,58 @@ impl(
|
|
|
5808
5615
|
)
|
|
5809
5616
|
);
|
|
5810
5617
|
impl(
|
|
5811
|
-
|
|
5618
|
+
comptime_str,
|
|
5812
5619
|
ComptimeIndex(RangeInclusive(comptime_int))(
|
|
5813
|
-
Output :
|
|
5620
|
+
Output : comptime_str,
|
|
5814
5621
|
index : (
|
|
5815
5622
|
(self, idx) ->
|
|
5816
5623
|
__yo_comptime_string_index_range_inclusive(self, idx)
|
|
5817
5624
|
)
|
|
5818
5625
|
)
|
|
5819
5626
|
);
|
|
5820
|
-
/// `str` —
|
|
5627
|
+
/// `str` — the BUILTIN immutable view of STATIC string bytes (TypeTag.Str,
|
|
5628
|
+
/// a fat pointer `{ const uint8_t* ptr; size_t len; }` in C).
|
|
5821
5629
|
///
|
|
5822
|
-
/// String literals `"hello"` produce `str`
|
|
5630
|
+
/// String literals `"hello"` and template-literal segments produce `str`
|
|
5631
|
+
/// at runtime; the backing bytes live in static storage (immortal), so a
|
|
5632
|
+
/// `str` is freely copyable and storable with no lifetime constraints.
|
|
5823
5633
|
/// For heap-allocated growable strings, see `String`.
|
|
5824
|
-
str :: newtype(
|
|
5825
|
-
/// The underlying byte slice.
|
|
5826
|
-
bytes : Slice(u8)
|
|
5827
|
-
);
|
|
5828
5634
|
impl(
|
|
5829
5635
|
str,
|
|
5830
5636
|
/// Construct a `str` from a raw pointer and length.
|
|
5637
|
+
/// SAFETY: callers must guarantee the bytes outlive every use of the
|
|
5638
|
+
/// view — the safe surface only ever does this with static storage.
|
|
5831
5639
|
from_raw_parts : (fn(ptr : *(u8), length : usize) -> Self)(
|
|
5832
|
-
|
|
5640
|
+
__yo_str_from_raw_parts(ptr, length)
|
|
5833
5641
|
),
|
|
5834
5642
|
/// Return the length in bytes.
|
|
5835
5643
|
len : (fn(self : Self) -> usize)(
|
|
5836
|
-
|
|
5644
|
+
__yo_str_len(self)
|
|
5837
5645
|
),
|
|
5838
5646
|
ptr : (fn(self : Self) -> *(u8))(
|
|
5839
|
-
|
|
5647
|
+
__yo_str_ptr(self)
|
|
5648
|
+
),
|
|
5649
|
+
/// Return the byte at `idx` (bounds are the caller's responsibility,
|
|
5650
|
+
/// mirroring slice indexing).
|
|
5651
|
+
bytes : (fn(self : Self, idx : usize) -> u8)(
|
|
5652
|
+
__yo_str_byte(self, idx)
|
|
5840
5653
|
)
|
|
5841
5654
|
);
|
|
5655
|
+
/// Range slicing on `str` stays a ZERO-COPY `str` — a window of static
|
|
5656
|
+
/// bytes is still static (byte indices). `s(a..b)` lowers to this.
|
|
5657
|
+
impl(
|
|
5658
|
+
str,
|
|
5659
|
+
slice_copy : (fn(self : Self, r : Range(usize)) -> Self)({
|
|
5660
|
+
e := cond((r.end > __yo_str_len(self)) => __yo_str_len(self), true => r.end);
|
|
5661
|
+
st := cond((r.start > e) => e, true => r.start);
|
|
5662
|
+
__yo_str_from_raw_parts(__yo_str_ptr(self) &+ st, e - st)
|
|
5663
|
+
}),
|
|
5664
|
+
slice_copy_inclusive : (fn(self : Self, r : RangeInclusive(usize)) -> Self)({
|
|
5665
|
+
e := cond(((r.end + usize(1)) > __yo_str_len(self)) => __yo_str_len(self), true => (r.end + usize(1)));
|
|
5666
|
+
st := cond((r.start > e) => e, true => r.start);
|
|
5667
|
+
__yo_str_from_raw_parts(__yo_str_ptr(self) &+ st, e - st)
|
|
5668
|
+
})
|
|
5669
|
+
);
|
|
5842
5670
|
impl(
|
|
5843
5671
|
str,
|
|
5844
5672
|
Eq(str)(
|
|
@@ -5898,7 +5726,8 @@ impl(
|
|
|
5898
5726
|
})
|
|
5899
5727
|
)
|
|
5900
5728
|
);
|
|
5901
|
-
|
|
5729
|
+
// (str is a builtin type — no export needed; the identifier resolves
|
|
5730
|
+
// everywhere like bool/i32.)
|
|
5902
5731
|
assert :: (fn(flag : bool, (msg : str) ?= "Assertion failed.") -> unit)(
|
|
5903
5732
|
cond(
|
|
5904
5733
|
flag => (),
|
|
@@ -6026,7 +5855,7 @@ impl(
|
|
|
6026
5855
|
neq : (fn(comptime(a) : Type, comptime(b) : Type) -> comptime(bool))({
|
|
6027
5856
|
return(!(__yo_are_types_equal(a, b)));
|
|
6028
5857
|
}),
|
|
6029
|
-
to_comptime_string : (fn(comptime(self) : Type) -> comptime(
|
|
5858
|
+
to_comptime_string : (fn(comptime(self) : Type) -> comptime(comptime_str))({
|
|
6030
5859
|
return(__yo_type_to_comptime_string(self));
|
|
6031
5860
|
})
|
|
6032
5861
|
);
|
|
@@ -6055,7 +5884,7 @@ export(StructKind);
|
|
|
6055
5884
|
/// TypeFieldInfo — metadata for a single struct/object field.
|
|
6056
5885
|
TypeFieldInfo :: struct(
|
|
6057
5886
|
/// Field name.
|
|
6058
|
-
name :
|
|
5887
|
+
name : comptime_str,
|
|
6059
5888
|
/// Field type.
|
|
6060
5889
|
field_type : Type
|
|
6061
5890
|
);
|
|
@@ -6078,7 +5907,7 @@ export(TraitInfo);
|
|
|
6078
5907
|
/// TraitFieldInfo — metadata for a single trait field.
|
|
6079
5908
|
TraitFieldInfo :: struct(
|
|
6080
5909
|
/// Field name.
|
|
6081
|
-
name :
|
|
5910
|
+
name : comptime_str,
|
|
6082
5911
|
/// Field type.
|
|
6083
5912
|
field_type : Type,
|
|
6084
5913
|
/// `true` if this field is an associated type (not a method).
|
|
@@ -6089,7 +5918,7 @@ export(TraitFieldInfo);
|
|
|
6089
5918
|
/// ParamInfo — metadata for a function parameter.
|
|
6090
5919
|
ParamInfo :: struct(
|
|
6091
5920
|
/// Parameter name.
|
|
6092
|
-
name :
|
|
5921
|
+
name : comptime_str,
|
|
6093
5922
|
/// Parameter type.
|
|
6094
5923
|
param_type : Type,
|
|
6095
5924
|
/// `true` if the parameter is compile-time (`comptime`).
|
|
@@ -6103,14 +5932,14 @@ impl(ParamInfo, Comptime());
|
|
|
6103
5932
|
export(ParamInfo);
|
|
6104
5933
|
/// ForallParamInfo — metadata for a forall type parameter.
|
|
6105
5934
|
ForallParamInfo :: struct(
|
|
6106
|
-
name :
|
|
5935
|
+
name : comptime_str,
|
|
6107
5936
|
param_type : Type
|
|
6108
5937
|
);
|
|
6109
5938
|
impl(ForallParamInfo, Comptime());
|
|
6110
5939
|
export(ForallParamInfo);
|
|
6111
5940
|
/// ImplicitParamInfo — metadata for a `using`/effect parameter.
|
|
6112
5941
|
ImplicitParamInfo :: struct(
|
|
6113
|
-
name :
|
|
5942
|
+
name : comptime_str,
|
|
6114
5943
|
param_type : Type
|
|
6115
5944
|
);
|
|
6116
5945
|
impl(ImplicitParamInfo, Comptime());
|
|
@@ -6144,7 +5973,7 @@ export(TraitKind);
|
|
|
6144
5973
|
/// VariantInfo — metadata for an enum variant.
|
|
6145
5974
|
VariantInfo :: struct(
|
|
6146
5975
|
/// Variant name.
|
|
6147
|
-
name :
|
|
5976
|
+
name : comptime_str,
|
|
6148
5977
|
/// Variant fields (may be empty for unit variants).
|
|
6149
5978
|
fields : ComptimeList(TypeFieldInfo),
|
|
6150
5979
|
_enum_type : Type,
|
|
@@ -6182,9 +6011,10 @@ TypeInfo :: enum(
|
|
|
6182
6011
|
ULongLong,
|
|
6183
6012
|
LongDouble,
|
|
6184
6013
|
Void,
|
|
6014
|
+
/// `str` — static string view (fieldless)
|
|
6015
|
+
Str,
|
|
6185
6016
|
// Compound types (with metadata)
|
|
6186
6017
|
Array(element : Type, length : comptime_int),
|
|
6187
|
-
Slice(element : Type),
|
|
6188
6018
|
Tuple(fields : ComptimeList(TypeFieldInfo)),
|
|
6189
6019
|
Struct(
|
|
6190
6020
|
fields : ComptimeList(TypeFieldInfo),
|
|
@@ -6210,7 +6040,7 @@ TypeInfo :: enum(
|
|
|
6210
6040
|
),
|
|
6211
6041
|
Type(level : comptime_int),
|
|
6212
6042
|
Some(
|
|
6213
|
-
name :
|
|
6043
|
+
name : comptime_str,
|
|
6214
6044
|
required_traits : ComptimeList(TraitInfo),
|
|
6215
6045
|
negative_traits : ComptimeList(TraitInfo),
|
|
6216
6046
|
resolved_type : Type
|
|
@@ -6218,7 +6048,7 @@ TypeInfo :: enum(
|
|
|
6218
6048
|
// Comptime only
|
|
6219
6049
|
ComptimeInt,
|
|
6220
6050
|
ComptimeFloat,
|
|
6221
|
-
|
|
6051
|
+
ComptimeStr,
|
|
6222
6052
|
ComptimeList(element : Type),
|
|
6223
6053
|
// Metaprogramming (fieldless)
|
|
6224
6054
|
Expr,
|
|
@@ -6243,8 +6073,8 @@ impl(
|
|
|
6243
6073
|
is_array : (fn(comptime(self) : TypeInfo) -> comptime(bool))(
|
|
6244
6074
|
match(self,.Array(_, _) => true, _ => false)
|
|
6245
6075
|
),
|
|
6246
|
-
|
|
6247
|
-
match(self,.
|
|
6076
|
+
is_str : (fn(comptime(self) : TypeInfo) -> comptime(bool))(
|
|
6077
|
+
match(self,.Str => true, _ => false)
|
|
6248
6078
|
),
|
|
6249
6079
|
is_function : (fn(comptime(self) : TypeInfo) -> comptime(bool))(
|
|
6250
6080
|
match(self,.Function(_) => true, _ => false)
|
|
@@ -6284,6 +6114,7 @@ impl(
|
|
|
6284
6114
|
.LongLong => true,
|
|
6285
6115
|
.ULongLong => true,
|
|
6286
6116
|
.LongDouble => true,
|
|
6117
|
+
.Str => true,
|
|
6287
6118
|
_ => false
|
|
6288
6119
|
)
|
|
6289
6120
|
),
|
|
@@ -6326,7 +6157,7 @@ impl(
|
|
|
6326
6157
|
self,
|
|
6327
6158
|
.ComptimeInt => true,
|
|
6328
6159
|
.ComptimeFloat => true,
|
|
6329
|
-
.
|
|
6160
|
+
.ComptimeStr => true,
|
|
6330
6161
|
.ComptimeList(_) => true,
|
|
6331
6162
|
.Expr => true,
|
|
6332
6163
|
_ => false
|
|
@@ -6388,7 +6219,7 @@ impl(
|
|
|
6388
6219
|
})
|
|
6389
6220
|
);
|
|
6390
6221
|
/// `FieldInfo` — compile-time struct field metadata for derive rules (legacy alias).
|
|
6391
|
-
FieldInfo :: struct(name :
|
|
6222
|
+
FieldInfo :: struct(name : comptime_str, field_type : Type);
|
|
6392
6223
|
impl(FieldInfo, Comptime());
|
|
6393
6224
|
impl(
|
|
6394
6225
|
FieldInfo,
|
|
@@ -6685,9 +6516,9 @@ export(DeriveContext);
|
|
|
6685
6516
|
__yo_comptime_fold_range :: (
|
|
6686
6517
|
fn(
|
|
6687
6518
|
comptime(n) : usize,
|
|
6688
|
-
comptime(init) :
|
|
6689
|
-
comptime(f) : (fn(comptime(acc) :
|
|
6690
|
-
) -> comptime(
|
|
6519
|
+
comptime(init) : comptime_str,
|
|
6520
|
+
comptime(f) : (fn(comptime(acc) : comptime_str, comptime(i) : usize) -> comptime(comptime_str))
|
|
6521
|
+
) -> comptime(comptime_str)
|
|
6691
6522
|
)(
|
|
6692
6523
|
cond(
|
|
6693
6524
|
(n == usize(0)) => init,
|
|
@@ -6696,17 +6527,17 @@ __yo_comptime_fold_range :: (
|
|
|
6696
6527
|
)
|
|
6697
6528
|
);
|
|
6698
6529
|
// Helper: concat 2 strings
|
|
6699
|
-
__s2 :: (fn(comptime(a) :
|
|
6530
|
+
__s2 :: (fn(comptime(a) : comptime_str, comptime(b) : comptime_str) -> comptime(comptime_str))(a + b);
|
|
6700
6531
|
// Helper: concat 3 strings
|
|
6701
|
-
__s3 :: (fn(comptime(a) :
|
|
6532
|
+
__s3 :: (fn(comptime(a) : comptime_str, comptime(b) : comptime_str, comptime(c) : comptime_str) -> comptime(comptime_str))(
|
|
6702
6533
|
(a + b) + c
|
|
6703
6534
|
);
|
|
6704
6535
|
// Helper: concat 4 strings
|
|
6705
|
-
__s4 :: (fn(comptime(a) :
|
|
6536
|
+
__s4 :: (fn(comptime(a) : comptime_str, comptime(b) : comptime_str, comptime(c) : comptime_str, comptime(d) : comptime_str) -> comptime(comptime_str))(
|
|
6706
6537
|
((a + b) + c) + d
|
|
6707
6538
|
);
|
|
6708
6539
|
// Helper: concat 5 strings
|
|
6709
|
-
__s5 :: (fn(comptime(a) :
|
|
6540
|
+
__s5 :: (fn(comptime(a) : comptime_str, comptime(b) : comptime_str, comptime(c) : comptime_str, comptime(d) : comptime_str, comptime(e) : comptime_str) -> comptime(comptime_str))(
|
|
6710
6541
|
(((a + b) + c) + d) + e
|
|
6711
6542
|
);
|
|
6712
6543
|
// --- derive_rule for Eq ---
|
|
@@ -6738,7 +6569,7 @@ __derive_eq :: (fn(comptime(T) : Type, comptime(ctx) : DeriveContext, comptime(t
|
|
|
6738
6569
|
eq_branches :: __yo_comptime_fold_range(
|
|
6739
6570
|
vc,
|
|
6740
6571
|
"",
|
|
6741
|
-
(fn(comptime(acc) :
|
|
6572
|
+
(fn(comptime(acc) : comptime_str, comptime(vi) : usize) -> comptime(comptime_str))({
|
|
6742
6573
|
v :: variants.get(vi);
|
|
6743
6574
|
branch :: cond(
|
|
6744
6575
|
(v.fields.len() == 0) =>
|
|
@@ -6747,7 +6578,7 @@ __derive_eq :: (fn(comptime(T) : Type, comptime(ctx) : DeriveContext, comptime(t
|
|
|
6747
6578
|
lhs_bindings :: __yo_comptime_fold_range(
|
|
6748
6579
|
v.fields.len(),
|
|
6749
6580
|
"",
|
|
6750
|
-
(fn(comptime(a) :
|
|
6581
|
+
(fn(comptime(a) : comptime_str, comptime(fi) : usize) -> comptime(comptime_str))({
|
|
6751
6582
|
fname :: v.fields.get(fi).name;
|
|
6752
6583
|
cond(
|
|
6753
6584
|
(a == "") => __s2("__lhs_", fname),
|
|
@@ -6758,7 +6589,7 @@ __derive_eq :: (fn(comptime(T) : Type, comptime(ctx) : DeriveContext, comptime(t
|
|
|
6758
6589
|
rhs_bindings :: __yo_comptime_fold_range(
|
|
6759
6590
|
v.fields.len(),
|
|
6760
6591
|
"",
|
|
6761
|
-
(fn(comptime(a) :
|
|
6592
|
+
(fn(comptime(a) : comptime_str, comptime(fi) : usize) -> comptime(comptime_str))({
|
|
6762
6593
|
fname :: v.fields.get(fi).name;
|
|
6763
6594
|
cond(
|
|
6764
6595
|
(a == "") => __s2("__rhs_", fname),
|
|
@@ -6769,7 +6600,7 @@ __derive_eq :: (fn(comptime(T) : Type, comptime(ctx) : DeriveContext, comptime(t
|
|
|
6769
6600
|
eq_cmp :: __yo_comptime_fold_range(
|
|
6770
6601
|
v.fields.len(),
|
|
6771
6602
|
"",
|
|
6772
|
-
(fn(comptime(a) :
|
|
6603
|
+
(fn(comptime(a) : comptime_str, comptime(fi) : usize) -> comptime(comptime_str))({
|
|
6773
6604
|
fname :: v.fields.get(fi).name;
|
|
6774
6605
|
part :: __s4("(__lhs_", fname, " == __rhs_", fname);
|
|
6775
6606
|
cond(
|
|
@@ -6828,7 +6659,7 @@ __derive_clone :: (fn(comptime(T) : Type, comptime(ctx) : DeriveContext, comptim
|
|
|
6828
6659
|
cloned_fields :: __yo_comptime_fold_range(
|
|
6829
6660
|
fc,
|
|
6830
6661
|
"",
|
|
6831
|
-
(fn(comptime(a) :
|
|
6662
|
+
(fn(comptime(a) : comptime_str, comptime(fi) : usize) -> comptime(comptime_str))({
|
|
6832
6663
|
fname :: fields.get(fi).name;
|
|
6833
6664
|
part :: __s3("self.", fname, ".clone()");
|
|
6834
6665
|
cond(
|
|
@@ -6852,7 +6683,7 @@ __derive_clone :: (fn(comptime(T) : Type, comptime(ctx) : DeriveContext, comptim
|
|
|
6852
6683
|
clone_branches :: __yo_comptime_fold_range(
|
|
6853
6684
|
vc,
|
|
6854
6685
|
"",
|
|
6855
|
-
(fn(comptime(acc) :
|
|
6686
|
+
(fn(comptime(acc) : comptime_str, comptime(vi) : usize) -> comptime(comptime_str))({
|
|
6856
6687
|
v :: variants.get(vi);
|
|
6857
6688
|
branch :: cond(
|
|
6858
6689
|
(v.fields.len() == 0) => __s4(".", v.name, " => .", v.name),
|
|
@@ -6860,7 +6691,7 @@ __derive_clone :: (fn(comptime(T) : Type, comptime(ctx) : DeriveContext, comptim
|
|
|
6860
6691
|
bindings :: __yo_comptime_fold_range(
|
|
6861
6692
|
v.fields.len(),
|
|
6862
6693
|
"",
|
|
6863
|
-
(fn(comptime(a) :
|
|
6694
|
+
(fn(comptime(a) : comptime_str, comptime(fi) : usize) -> comptime(comptime_str))({
|
|
6864
6695
|
fname :: v.fields.get(fi).name;
|
|
6865
6696
|
cond(
|
|
6866
6697
|
(a == "") => __s2("__v_", fname),
|
|
@@ -6871,7 +6702,7 @@ __derive_clone :: (fn(comptime(T) : Type, comptime(ctx) : DeriveContext, comptim
|
|
|
6871
6702
|
cloned :: __yo_comptime_fold_range(
|
|
6872
6703
|
v.fields.len(),
|
|
6873
6704
|
"",
|
|
6874
|
-
(fn(comptime(a) :
|
|
6705
|
+
(fn(comptime(a) : comptime_str, comptime(fi) : usize) -> comptime(comptime_str))({
|
|
6875
6706
|
fname :: v.fields.get(fi).name;
|
|
6876
6707
|
cond(
|
|
6877
6708
|
(a == "") => __s3("__v_", fname, ".clone()"),
|
|
@@ -6934,7 +6765,7 @@ __derive_hash :: (fn(comptime(T) : Type, comptime(ctx) : DeriveContext, comptime
|
|
|
6934
6765
|
hash_stmts :: __yo_comptime_fold_range(
|
|
6935
6766
|
fc,
|
|
6936
6767
|
"",
|
|
6937
|
-
(fn(comptime(a) :
|
|
6768
|
+
(fn(comptime(a) : comptime_str, comptime(fi) : usize) -> comptime(comptime_str))({
|
|
6938
6769
|
fname :: fields.get(fi).name;
|
|
6939
6770
|
cond(
|
|
6940
6771
|
(fi == 0) => __s3("(h : u64) = self.", fname, ".hash()"),
|
|
@@ -6959,7 +6790,7 @@ __derive_hash :: (fn(comptime(T) : Type, comptime(ctx) : DeriveContext, comptime
|
|
|
6959
6790
|
hash_branches :: __yo_comptime_fold_range(
|
|
6960
6791
|
vc,
|
|
6961
6792
|
"",
|
|
6962
|
-
(fn(comptime(acc) :
|
|
6793
|
+
(fn(comptime(acc) : comptime_str, comptime(vi) : usize) -> comptime(comptime_str))({
|
|
6963
6794
|
v :: variants.get(vi);
|
|
6964
6795
|
vi_str :: __yo_comptime_usize_to_comptime_string(vi);
|
|
6965
6796
|
branch :: cond(
|
|
@@ -6968,7 +6799,7 @@ __derive_hash :: (fn(comptime(T) : Type, comptime(ctx) : DeriveContext, comptime
|
|
|
6968
6799
|
bindings :: __yo_comptime_fold_range(
|
|
6969
6800
|
v.fields.len(),
|
|
6970
6801
|
"",
|
|
6971
|
-
(fn(comptime(a) :
|
|
6802
|
+
(fn(comptime(a) : comptime_str, comptime(fi) : usize) -> comptime(comptime_str))({
|
|
6972
6803
|
fname :: v.fields.get(fi).name;
|
|
6973
6804
|
cond(
|
|
6974
6805
|
(a == "") => __s2("__v_", fname),
|
|
@@ -6979,7 +6810,7 @@ __derive_hash :: (fn(comptime(T) : Type, comptime(ctx) : DeriveContext, comptime
|
|
|
6979
6810
|
hash_stmts :: __yo_comptime_fold_range(
|
|
6980
6811
|
v.fields.len(),
|
|
6981
6812
|
__s3("(h : u64) = u64(", vi_str, ")"),
|
|
6982
|
-
(fn(comptime(a) :
|
|
6813
|
+
(fn(comptime(a) : comptime_str, comptime(fi) : usize) -> comptime(comptime_str))({
|
|
6983
6814
|
fname :: v.fields.get(fi).name;
|
|
6984
6815
|
__s4(a, "; h = ((h * u64(31)) + __v_", fname, ".hash())")
|
|
6985
6816
|
})
|
|
@@ -7021,7 +6852,7 @@ __derive_hash :: (fn(comptime(T) : Type, comptime(ctx) : DeriveContext, comptime
|
|
|
7021
6852
|
derive_rule(Hash, __derive_hash);
|
|
7022
6853
|
// --- derive_rule for Ord ---
|
|
7023
6854
|
// Helper: generate lexicographic comparison for struct fields
|
|
7024
|
-
__derive_ord_struct_body :: (fn(comptime(T) : Type, comptime(op) :
|
|
6855
|
+
__derive_ord_struct_body :: (fn(comptime(T) : Type, comptime(op) : comptime_str) -> comptime(comptime_str))({
|
|
7025
6856
|
fields :: Type.get_struct_fields(T);
|
|
7026
6857
|
fc :: fields.len();
|
|
7027
6858
|
cond(
|
|
@@ -7033,7 +6864,7 @@ __derive_ord_struct_body :: (fn(comptime(T) : Type, comptime(op) : comptime_stri
|
|
|
7033
6864
|
branches :: __yo_comptime_fold_range(
|
|
7034
6865
|
fc,
|
|
7035
6866
|
"",
|
|
7036
|
-
(fn(comptime(a) :
|
|
6867
|
+
(fn(comptime(a) : comptime_str, comptime(fi) : usize) -> comptime(comptime_str))({
|
|
7037
6868
|
fname :: fields.get(fi).name;
|
|
7038
6869
|
branch :: cond(
|
|
7039
6870
|
(fi == (fc - 1)) =>
|
|
@@ -7052,7 +6883,7 @@ __derive_ord_struct_body :: (fn(comptime(T) : Type, comptime(op) : comptime_stri
|
|
|
7052
6883
|
)
|
|
7053
6884
|
});
|
|
7054
6885
|
// Helper: generate lexicographic comparison for enum variant bindings
|
|
7055
|
-
__derive_ord_variant_body :: (fn(comptime(v) : VariantInfo, comptime(op) :
|
|
6886
|
+
__derive_ord_variant_body :: (fn(comptime(v) : VariantInfo, comptime(op) : comptime_str) -> comptime(comptime_str))(
|
|
7056
6887
|
cond(
|
|
7057
6888
|
(v.fields.len() == 1) => {
|
|
7058
6889
|
fname :: v.fields.get(0).name;
|
|
@@ -7062,7 +6893,7 @@ __derive_ord_variant_body :: (fn(comptime(v) : VariantInfo, comptime(op) : compt
|
|
|
7062
6893
|
branches :: __yo_comptime_fold_range(
|
|
7063
6894
|
v.fields.len(),
|
|
7064
6895
|
"",
|
|
7065
|
-
(fn(comptime(a) :
|
|
6896
|
+
(fn(comptime(a) : comptime_str, comptime(fi) : usize) -> comptime(comptime_str))({
|
|
7066
6897
|
fname :: v.fields.get(fi).name;
|
|
7067
6898
|
branch :: cond(
|
|
7068
6899
|
(fi == (v.fields.len() - 1)) =>
|
|
@@ -7120,11 +6951,11 @@ __derive_ord :: (fn(comptime(T) : Type, comptime(ctx) : DeriveContext, comptime(
|
|
|
7120
6951
|
variants :: Type.get_enum_variants(T);
|
|
7121
6952
|
vc :: variants.len();
|
|
7122
6953
|
// Generate one operator's match branches
|
|
7123
|
-
__gen_op_branches :: (fn(comptime(op) :
|
|
6954
|
+
__gen_op_branches :: (fn(comptime(op) : comptime_str, comptime(eq_val) : comptime_str) -> comptime(comptime_str))({
|
|
7124
6955
|
branches :: __yo_comptime_fold_range(
|
|
7125
6956
|
vc,
|
|
7126
6957
|
"",
|
|
7127
|
-
(fn(comptime(acc) :
|
|
6958
|
+
(fn(comptime(acc) : comptime_str, comptime(vi) : usize) -> comptime(comptime_str))({
|
|
7128
6959
|
v :: variants.get(vi);
|
|
7129
6960
|
branch :: cond(
|
|
7130
6961
|
(v.fields.len() == 0) =>
|
|
@@ -7133,7 +6964,7 @@ __derive_ord :: (fn(comptime(T) : Type, comptime(ctx) : DeriveContext, comptime(
|
|
|
7133
6964
|
lhs_bindings :: __yo_comptime_fold_range(
|
|
7134
6965
|
v.fields.len(),
|
|
7135
6966
|
"",
|
|
7136
|
-
(fn(comptime(a) :
|
|
6967
|
+
(fn(comptime(a) : comptime_str, comptime(fi) : usize) -> comptime(comptime_str))({
|
|
7137
6968
|
fname :: v.fields.get(fi).name;
|
|
7138
6969
|
cond(
|
|
7139
6970
|
(a == "") => __s2("__lhs_", fname),
|
|
@@ -7144,7 +6975,7 @@ __derive_ord :: (fn(comptime(T) : Type, comptime(ctx) : DeriveContext, comptime(
|
|
|
7144
6975
|
rhs_bindings :: __yo_comptime_fold_range(
|
|
7145
6976
|
v.fields.len(),
|
|
7146
6977
|
"",
|
|
7147
|
-
(fn(comptime(a) :
|
|
6978
|
+
(fn(comptime(a) : comptime_str, comptime(fi) : usize) -> comptime(comptime_str))({
|
|
7148
6979
|
fname :: v.fields.get(fi).name;
|
|
7149
6980
|
cond(
|
|
7150
6981
|
(a == "") => __s2("__rhs_", fname),
|
|
@@ -7696,55 +7527,24 @@ IntoIterator :: trait(
|
|
|
7696
7527
|
);
|
|
7697
7528
|
export(IntoIterator);
|
|
7698
7529
|
/// === Array Iterator ===
|
|
7699
|
-
///
|
|
7700
|
-
///
|
|
7701
|
-
|
|
7702
|
-
|
|
7703
|
-
|
|
7704
|
-
|
|
7705
|
-
_len : usize
|
|
7706
|
-
);
|
|
7707
|
-
impl(
|
|
7708
|
-
_ArrayPosIter,
|
|
7709
|
-
Iterator(
|
|
7710
|
-
Item : usize,
|
|
7711
|
-
next : (fn(ref(self) : Self) -> Option(usize))(
|
|
7712
|
-
cond(
|
|
7713
|
-
(self._index >= self._len) =>.None,
|
|
7714
|
-
true => {
|
|
7715
|
-
out := self._index;
|
|
7716
|
-
self._index = (self._index + usize(1));
|
|
7717
|
-
.Some(out)
|
|
7718
|
-
}
|
|
7719
|
-
)
|
|
7720
|
-
)
|
|
7530
|
+
/// Value iterator for Array(T, N) — yields elements by value. Backs
|
|
7531
|
+
/// the for-macro value form `for(arr, (x) => body)` via `into_iter`.
|
|
7532
|
+
_ArrayIter :: (fn(comptime(T) : Type, comptime(N) : usize) -> comptime(Type))(
|
|
7533
|
+
struct(
|
|
7534
|
+
_arr : Array(T, N),
|
|
7535
|
+
_index : usize
|
|
7721
7536
|
)
|
|
7722
7537
|
);
|
|
7723
7538
|
impl(
|
|
7724
7539
|
forall(T : Type, N : usize),
|
|
7725
|
-
|
|
7726
|
-
iter : (fn(ref(self) : Self) -> _ArrayPosIter)(
|
|
7727
|
-
_ArrayPosIter(_index : usize(0), _len : N)
|
|
7728
|
-
)
|
|
7729
|
-
);
|
|
7730
|
-
/// === Slice Iterator ===
|
|
7731
|
-
/// Position iterator for Slice(T) — yields `usize` indices into the
|
|
7732
|
-
/// slice. Used by `Slice.iter()`; the for-macro pairs each yielded
|
|
7733
|
-
/// position with `Slice.project(pos)` (Indexable) to bind the body's
|
|
7734
|
-
/// `ref`-name. See plans/ITERATOR_REDESIGN.md.
|
|
7735
|
-
_SlicePosIter :: struct(
|
|
7736
|
-
_index : usize,
|
|
7737
|
-
_len : usize
|
|
7738
|
-
);
|
|
7739
|
-
impl(
|
|
7740
|
-
_SlicePosIter,
|
|
7540
|
+
_ArrayIter(T, N),
|
|
7741
7541
|
Iterator(
|
|
7742
|
-
Item :
|
|
7743
|
-
next : (fn(ref(self) : Self) -> Option(
|
|
7542
|
+
Item : T,
|
|
7543
|
+
next : (fn(ref(self) : Self) -> Option(T))(
|
|
7744
7544
|
cond(
|
|
7745
|
-
(self._index >=
|
|
7545
|
+
(self._index >= N) =>.None,
|
|
7746
7546
|
true => {
|
|
7747
|
-
out := self._index;
|
|
7547
|
+
out := self._arr(self._index);
|
|
7748
7548
|
self._index = (self._index + usize(1));
|
|
7749
7549
|
.Some(out)
|
|
7750
7550
|
}
|
|
@@ -7753,10 +7553,10 @@ impl(
|
|
|
7753
7553
|
)
|
|
7754
7554
|
);
|
|
7755
7555
|
impl(
|
|
7756
|
-
forall(T : Type),
|
|
7757
|
-
|
|
7758
|
-
|
|
7759
|
-
|
|
7556
|
+
forall(T : Type, N : usize),
|
|
7557
|
+
Array(T, N),
|
|
7558
|
+
into_iter : (fn(self : Self) -> _ArrayIter(T, N))(
|
|
7559
|
+
_ArrayIter(T, N)(_arr : self, _index : usize(0))
|
|
7760
7560
|
)
|
|
7761
7561
|
);
|
|
7762
7562
|
/// TryFrom trait — fallible conversion from one type to another.
|
|
@@ -7822,33 +7622,30 @@ try :: (fn(quote(expr_to_try) : Expr) -> unquote(Expr))({
|
|
|
7822
7622
|
})
|
|
7823
7623
|
});
|
|
7824
7624
|
export(try);
|
|
7825
|
-
/// `for` macro — iterate over a collection.
|
|
7826
|
-
/// dictates whether the iteration borrows or consumes:
|
|
7827
|
-
///
|
|
7828
|
-
/// `for(coll, ref(x) => body)` — borrow form. Calls `coll.iter()`
|
|
7829
|
-
/// (must yield positions) + `coll.project(pos)` for each. `x` is
|
|
7830
|
-
/// `ref`-bound to the element; reads auto-deref, writes propagate
|
|
7831
|
-
/// back to the collection; `coll` survives the loop.
|
|
7625
|
+
/// `for` macro — iterate over a collection.
|
|
7832
7626
|
///
|
|
7833
|
-
/// `for(coll, (x) => body)` —
|
|
7834
|
-
///
|
|
7835
|
-
///
|
|
7627
|
+
/// `for(coll, (x) => body)` — calls `coll.into_iter()` and binds `x`
|
|
7628
|
+
/// to each yielded value. The collection is moved into the
|
|
7629
|
+
/// iterator; object elements are handles, so mutating `x` in the
|
|
7630
|
+
/// body mutates the element in place.
|
|
7836
7631
|
///
|
|
7837
|
-
///
|
|
7838
|
-
///
|
|
7839
|
-
///
|
|
7840
|
-
///
|
|
7632
|
+
/// The old borrow form `for(coll, ref(x) => body)` was REMOVED: it
|
|
7633
|
+
/// required `ref`s into reallocatable storage, which is no longer
|
|
7634
|
+
/// expressible. Object elements mutate in place through the value
|
|
7635
|
+
/// handle; struct elements use an index loop with `get`/`set`.
|
|
7841
7636
|
///
|
|
7842
|
-
///
|
|
7637
|
+
/// Combinator chains (`coll.into_iter().map(f)`, etc.) work
|
|
7638
|
+
/// transparently: a blanket `into_iter` impl on `Iterator` (below)
|
|
7639
|
+
/// makes every iterator its own `IntoIterator`.
|
|
7843
7640
|
///
|
|
7844
7641
|
/// # Examples
|
|
7845
7642
|
/// ```rust
|
|
7846
|
-
/// //
|
|
7847
|
-
/// for(
|
|
7848
|
-
///
|
|
7643
|
+
/// // Object elements — mutate in place through the handle.
|
|
7644
|
+
/// for(names, (s) => {
|
|
7645
|
+
/// s.push_str("!");
|
|
7849
7646
|
/// });
|
|
7850
7647
|
///
|
|
7851
|
-
/// //
|
|
7648
|
+
/// // Consume an iterator chain.
|
|
7852
7649
|
/// for(list.into_iter(), (x) => print(x));
|
|
7853
7650
|
/// ```
|
|
7854
7651
|
for :: (
|
|
@@ -7879,38 +7676,14 @@ for :: (
|
|
|
7879
7676
|
);
|
|
7880
7677
|
cond(
|
|
7881
7678
|
is_ref_form => {
|
|
7882
|
-
|
|
7883
|
-
|
|
7884
|
-
|
|
7885
|
-
|
|
7886
|
-
|
|
7887
|
-
|
|
7888
|
-
|
|
7889
|
-
|
|
7890
|
-
// storage; a value-typed local copy would receive the
|
|
7891
|
-
// writes silently. The for-macro consumes `coll` as an
|
|
7892
|
-
// expression directly so the `&coll` pointer it
|
|
7893
|
-
// implicitly forms reaches the caller's collection.
|
|
7894
|
-
// (This is correct for `coll : Array(T, N)` /
|
|
7895
|
-
// `Slice(T)` / `String` value-typed collections and
|
|
7896
|
-
// for `ref(coll)`-bound parameter inputs; for owning
|
|
7897
|
-
// collections like `ArrayList` whose internal storage
|
|
7898
|
-
// is heap, the receiver-by-ref semantics already work.)
|
|
7899
|
-
quote({
|
|
7900
|
-
unquote(iter_var) := unquote(coll).iter();
|
|
7901
|
-
while(runtime(true), {
|
|
7902
|
-
match(
|
|
7903
|
-
unquote(iter_var).next(),
|
|
7904
|
-
.Some(unquote(pos_var)) => {
|
|
7905
|
-
ref(unquote(name)) := unquote(coll).project(unquote(pos_var));
|
|
7906
|
-
unquote(body);
|
|
7907
|
-
},
|
|
7908
|
-
.None => {
|
|
7909
|
-
break;
|
|
7910
|
-
}
|
|
7911
|
-
);
|
|
7912
|
-
});
|
|
7913
|
-
})
|
|
7679
|
+
// The borrow form is gone: it handed out refs into
|
|
7680
|
+
// reallocatable storage. Teach the migration instead
|
|
7681
|
+
// of failing with a resolution error.
|
|
7682
|
+
comptime_assert(
|
|
7683
|
+
false,
|
|
7684
|
+
"'for(coll, ref(x) => ...)' was removed - use the value form 'for(coll, (x) => ...)'. Object elements are handles and mutate in place; for struct elements use an index loop with get/set."
|
|
7685
|
+
);
|
|
7686
|
+
quote(())
|
|
7914
7687
|
},
|
|
7915
7688
|
true => {
|
|
7916
7689
|
iter_var :: gensym("for_iter_var");
|