@shd101wyy/yo 0.1.22 → 0.1.24
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/async-effects-recipes.md +74 -1
- package/.github/skills/yo-core-patterns/core-patterns-cheatsheet.md +85 -0
- package/.github/skills/yo-syntax/syntax-cheatsheet.md +193 -6
- package/out/cjs/index.cjs +528 -519
- package/out/cjs/yo-cli.cjs +656 -647
- package/out/cjs/yo-lsp.cjs +554 -545
- package/out/esm/index.mjs +467 -458
- package/out/types/src/evaluator/context.d.ts +6 -0
- package/out/types/src/parser.d.ts +1 -0
- package/out/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/std/build.yo +2 -2
- package/std/collections/array_list.yo +26 -0
- package/std/{env/index.yo → env.yo} +11 -11
- package/std/{glob/index.yo → glob.yo} +2 -2
- package/std/imm/map.yo +15 -15
- package/std/imm/sorted_map.yo +14 -14
- package/std/imm/string.yo +4 -4
- package/std/{log/index.yo → log.yo} +3 -3
- package/std/prelude.yo +18 -23
- package/std/process/command.yo +8 -8
- package/std/string/string.yo +76 -55
- package/std/string/string_builder.yo +35 -0
- package/std/string/unicode.yo +6 -6
- package/std/sys/signal.yo +6 -6
package/package.json
CHANGED
package/std/build.yo
CHANGED
|
@@ -201,7 +201,7 @@ impl(Step,
|
|
|
201
201
|
__yo_build_add_import(self.name, entry.name, entry.module.name, entry.module._dep);
|
|
202
202
|
}),
|
|
203
203
|
/// Add a list of module imports to this step.
|
|
204
|
-
add_import_list : (fn(comptime(self) : Self, comptime(entries) : ComptimeList(ImportEntry)) -> comptime(unit))(
|
|
204
|
+
add_import_list : (fn(comptime(self) : Self, comptime(entries) : ComptimeList(ImportEntry)) -> comptime(unit))(
|
|
205
205
|
cond(
|
|
206
206
|
(entries.len() == usize(0)) => (),
|
|
207
207
|
true => {
|
|
@@ -209,7 +209,7 @@ impl(Step,
|
|
|
209
209
|
recur(self, entries.cdr())
|
|
210
210
|
}
|
|
211
211
|
)
|
|
212
|
-
|
|
212
|
+
),
|
|
213
213
|
/// Add extra C compiler flags to this step.
|
|
214
214
|
add_c_flags : (fn(comptime(self) : Self, comptime(flags) : comptime_string) -> comptime(unit))({
|
|
215
215
|
__yo_build_add_cflags(self.name, flags);
|
|
@@ -696,6 +696,32 @@ impl(forall(T : Type), where(T <: Ord(T)), ArrayList(T),
|
|
|
696
696
|
})
|
|
697
697
|
);
|
|
698
698
|
|
|
699
|
+
/// Equality for ArrayList — two lists are equal if they have the same length
|
|
700
|
+
/// and every pair of elements at corresponding indices is equal.
|
|
701
|
+
impl(forall(T : Type), where(T <: Eq(T)), ArrayList(T), Eq(ArrayList(T))(
|
|
702
|
+
(==) : (fn(lhs: Self, rhs: Self) -> bool)({
|
|
703
|
+
n := lhs.len();
|
|
704
|
+
cond(
|
|
705
|
+
((!(n == rhs.len()))) => false,
|
|
706
|
+
true => {
|
|
707
|
+
(i : usize) = usize(0);
|
|
708
|
+
(equal : bool) = true;
|
|
709
|
+
while runtime(((i < n) && equal)), {
|
|
710
|
+
match(lhs.get(i),
|
|
711
|
+
.Some(a) => match(rhs.get(i),
|
|
712
|
+
.Some(b) => { equal = (a == b); },
|
|
713
|
+
.None => { equal = false; }
|
|
714
|
+
),
|
|
715
|
+
.None => { equal = false; }
|
|
716
|
+
);
|
|
717
|
+
i = (i + usize(1));
|
|
718
|
+
};
|
|
719
|
+
equal
|
|
720
|
+
}
|
|
721
|
+
)
|
|
722
|
+
})
|
|
723
|
+
));
|
|
724
|
+
|
|
699
725
|
/// Clone implementation for ArrayList — deep-clones each element.
|
|
700
726
|
impl(forall(T : Type), where(T <: Clone), ArrayList(T), Clone(
|
|
701
727
|
clone : (fn(self: *(Self)) -> Self)(
|
|
@@ -4,11 +4,11 @@
|
|
|
4
4
|
//! Mirrors the layout of Rust's `std::env`. Platform/architecture detection
|
|
5
5
|
//! and child-process spawning live in `std/process`.
|
|
6
6
|
|
|
7
|
-
open import "
|
|
8
|
-
open import "
|
|
9
|
-
open import "
|
|
10
|
-
{ platform, Platform } :: import "
|
|
11
|
-
{ GlobalAllocator } :: import "
|
|
7
|
+
open import "./collections/array_list";
|
|
8
|
+
open import "./string";
|
|
9
|
+
open import "./path";
|
|
10
|
+
{ platform, Platform } :: import "./process";
|
|
11
|
+
{ GlobalAllocator } :: import "./allocator";
|
|
12
12
|
{ malloc, free } :: GlobalAllocator;
|
|
13
13
|
|
|
14
14
|
// === Low-level C interface ===
|
|
@@ -63,7 +63,7 @@ export args;
|
|
|
63
63
|
|
|
64
64
|
/// Environment variable access and manipulation.
|
|
65
65
|
env :: impl {
|
|
66
|
-
{ getenv, setenv } :: import "
|
|
66
|
+
{ getenv, setenv } :: import "./libc/stdlib";
|
|
67
67
|
|
|
68
68
|
/// Get the value of an environment variable by name.
|
|
69
69
|
/// Returns `.None` if the variable is not set.
|
|
@@ -85,7 +85,7 @@ env :: impl {
|
|
|
85
85
|
|
|
86
86
|
result := cond(
|
|
87
87
|
(platform == Platform.Windows) => {
|
|
88
|
-
{ _putenv_s } :: import "
|
|
88
|
+
{ _putenv_s } :: import "./libc/windows";
|
|
89
89
|
|
|
90
90
|
cond(
|
|
91
91
|
overwrite =>
|
|
@@ -119,7 +119,7 @@ export env;
|
|
|
119
119
|
cwd :: (fn() -> Result(Path, String))(
|
|
120
120
|
cond(
|
|
121
121
|
(platform == Platform.Windows) => {
|
|
122
|
-
{ GetCurrentDirectoryW, WideCharToMultiByte, CP_UTF8, WCHAR, DWORD } :: import "
|
|
122
|
+
{ GetCurrentDirectoryW, WideCharToMultiByte, CP_UTF8, WCHAR, DWORD } :: import "./libc/windows";
|
|
123
123
|
|
|
124
124
|
required_size := GetCurrentDirectoryW(ulong(0), .None);
|
|
125
125
|
cond(
|
|
@@ -187,7 +187,7 @@ cwd :: (fn() -> Result(Path, String))(
|
|
|
187
187
|
)
|
|
188
188
|
},
|
|
189
189
|
true => {
|
|
190
|
-
{ getcwd } :: import "
|
|
190
|
+
{ getcwd } :: import "./libc/unistd";
|
|
191
191
|
|
|
192
192
|
buf_size := usize(4096);
|
|
193
193
|
buf := *(char)(malloc(buf_size).unwrap());
|
|
@@ -215,7 +215,7 @@ export cwd;
|
|
|
215
215
|
chdir :: (fn(path: Path) -> Result(unit, String))(
|
|
216
216
|
cond(
|
|
217
217
|
(platform == Platform.Windows) => {
|
|
218
|
-
{ SetCurrentDirectoryA, BOOL } :: import "
|
|
218
|
+
{ SetCurrentDirectoryA, BOOL } :: import "./libc/windows";
|
|
219
219
|
|
|
220
220
|
path_str := path.to_string();
|
|
221
221
|
path_cstr := path_str.to_cstr().ptr().unwrap();
|
|
@@ -227,7 +227,7 @@ chdir :: (fn(path: Path) -> Result(unit, String))(
|
|
|
227
227
|
)
|
|
228
228
|
},
|
|
229
229
|
true => {
|
|
230
|
-
{ chdir : unix_chdir } :: import "
|
|
230
|
+
{ chdir : unix_chdir } :: import "./libc/unistd";
|
|
231
231
|
|
|
232
232
|
path_str := path.to_string();
|
|
233
233
|
path_cstr := path_str.to_cstr().ptr().unwrap();
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
//! Glob pattern matching for file paths.
|
|
2
2
|
|
|
3
|
-
open import "
|
|
4
|
-
{ ArrayList } :: import "
|
|
3
|
+
open import "./string";
|
|
4
|
+
{ ArrayList } :: import "./collections/array_list";
|
|
5
5
|
|
|
6
6
|
// Recursive byte-level glob pattern matching
|
|
7
7
|
_glob_match_impl :: (fn(pb: ArrayList(u8), pi: usize, tb: ArrayList(u8), ti: usize) -> bool)({
|
package/std/imm/map.yo
CHANGED
|
@@ -249,7 +249,7 @@ _copy_pairs :: (fn(
|
|
|
249
249
|
};
|
|
250
250
|
});
|
|
251
251
|
|
|
252
|
-
_coll_with_pair :: (fn(comptime(K) : Type, comptime(V) : Type, coll: MapCollision(K, V), k: K, v: V, where(K <: (Eq(K), Hash, Send), V <: Send)) -> MapCollision(K, V))(
|
|
252
|
+
_coll_with_pair :: (fn(comptime(K) : Type, comptime(V) : Type, coll: MapCollision(K, V), k: K, v: V, where(K <: (Eq(K), Hash, Send), V <: Send)) -> MapCollision(K, V))(
|
|
253
253
|
match(_coll_find_key(K, V, coll, k),
|
|
254
254
|
.Some(idx) => {
|
|
255
255
|
new_ptr := _alloc_pairs(K, V, coll._pairs_len);
|
|
@@ -265,9 +265,9 @@ _coll_with_pair :: (fn(comptime(K) : Type, comptime(V) : Type, coll: MapCollisio
|
|
|
265
265
|
return MapCollision(K, V)(hash: coll.hash, _pairs_ptr: new_ptr, _pairs_len: new_len);
|
|
266
266
|
}
|
|
267
267
|
)
|
|
268
|
-
|
|
268
|
+
);
|
|
269
269
|
|
|
270
|
-
_coll_without_key :: (fn(comptime(K) : Type, comptime(V) : Type, coll: MapCollision(K, V), k: K, where(K <: (Eq(K), Hash, Send), V <: Send)) -> Option(MapCollision(K, V)))(
|
|
270
|
+
_coll_without_key :: (fn(comptime(K) : Type, comptime(V) : Type, coll: MapCollision(K, V), k: K, where(K <: (Eq(K), Hash, Send), V <: Send)) -> Option(MapCollision(K, V)))(
|
|
271
271
|
match(_coll_find_key(K, V, coll, k),
|
|
272
272
|
.Some(idx) => {
|
|
273
273
|
if((coll._pairs_len <= usize(2)), {
|
|
@@ -286,7 +286,7 @@ _coll_without_key :: (fn(comptime(K) : Type, comptime(V) : Type, coll: MapCollis
|
|
|
286
286
|
},
|
|
287
287
|
.None => .Some(coll)
|
|
288
288
|
)
|
|
289
|
-
|
|
289
|
+
);
|
|
290
290
|
|
|
291
291
|
// -- Core HAMT algorithms --
|
|
292
292
|
|
|
@@ -311,7 +311,7 @@ _make_branch :: (fn(
|
|
|
311
311
|
frag1 := _fragment(hash1, shift);
|
|
312
312
|
frag2 := _fragment(hash2, shift);
|
|
313
313
|
if((frag1 == frag2), {
|
|
314
|
-
child :=
|
|
314
|
+
child := recur(K, V, (shift + BITS), node1, hash1, node2, hash2);
|
|
315
315
|
ptr := _alloc_map_children(K, V, u8(1));
|
|
316
316
|
consume((*(MapNode(K, V))(ptr)).* = child);
|
|
317
317
|
return .Branch(MapBranch(K, V)(
|
|
@@ -382,7 +382,7 @@ _node_insert :: (fn(
|
|
|
382
382
|
if(_branch_has_child(K, V, branch, bit), {
|
|
383
383
|
idx := _branch_index_for(K, V, branch, bit);
|
|
384
384
|
child := _branch_child_at(K, V, branch, idx);
|
|
385
|
-
result :=
|
|
385
|
+
result := recur(K, V, child, (shift + BITS), hash, k, v);
|
|
386
386
|
return InsertResult(K, V)(
|
|
387
387
|
node: .Branch(_branch_replace_child(K, V, branch, bit, result.node)),
|
|
388
388
|
added: result.added
|
|
@@ -433,7 +433,7 @@ _node_get :: (fn(
|
|
|
433
433
|
return .None;
|
|
434
434
|
});
|
|
435
435
|
idx := _branch_index_for(K, V, branch, bit);
|
|
436
|
-
return
|
|
436
|
+
return recur(K, V, _branch_child_at(K, V, branch, idx), (shift + BITS), hash, k);
|
|
437
437
|
},
|
|
438
438
|
.Collision(coll) => {
|
|
439
439
|
if((coll.hash != hash), {
|
|
@@ -479,7 +479,7 @@ _node_remove :: (fn(
|
|
|
479
479
|
});
|
|
480
480
|
idx := _branch_index_for(K, V, branch, bit);
|
|
481
481
|
child := _branch_child_at(K, V, branch, idx);
|
|
482
|
-
sub :=
|
|
482
|
+
sub := recur(K, V, child, (shift + BITS), hash, k);
|
|
483
483
|
if(!(sub.removed), {
|
|
484
484
|
return RemoveResult(K, V)(node: .Some(node), removed: false);
|
|
485
485
|
});
|
|
@@ -560,7 +560,7 @@ _merge_from_node :: (fn(
|
|
|
560
560
|
(result : Map(K, V)) = acc;
|
|
561
561
|
i := u8(0);
|
|
562
562
|
while (i < branch._children_len), (i = (i + u8(1))), {
|
|
563
|
-
result =
|
|
563
|
+
result = recur(K, V, result, _branch_child_at(K, V, branch, i));
|
|
564
564
|
};
|
|
565
565
|
result
|
|
566
566
|
},
|
|
@@ -589,7 +589,7 @@ _collect_keys :: (fn(
|
|
|
589
589
|
(result : List(K)) = acc;
|
|
590
590
|
i := u8(0);
|
|
591
591
|
while (i < branch._children_len), (i = (i + u8(1))), {
|
|
592
|
-
result =
|
|
592
|
+
result = recur(K, V, _branch_child_at(K, V, branch, i), result);
|
|
593
593
|
};
|
|
594
594
|
result
|
|
595
595
|
},
|
|
@@ -617,7 +617,7 @@ _collect_values :: (fn(
|
|
|
617
617
|
(result : List(V)) = acc;
|
|
618
618
|
i := u8(0);
|
|
619
619
|
while (i < branch._children_len), (i = (i + u8(1))), {
|
|
620
|
-
result =
|
|
620
|
+
result = recur(K, V, _branch_child_at(K, V, branch, i), result);
|
|
621
621
|
};
|
|
622
622
|
result
|
|
623
623
|
},
|
|
@@ -645,7 +645,7 @@ _collect_entries :: (fn(
|
|
|
645
645
|
(result : List(Pair(K, V))) = acc;
|
|
646
646
|
i := u8(0);
|
|
647
647
|
while (i < branch._children_len), (i = (i + u8(1))), {
|
|
648
|
-
result =
|
|
648
|
+
result = recur(K, V, _branch_child_at(K, V, branch, i), result);
|
|
649
649
|
};
|
|
650
650
|
result
|
|
651
651
|
},
|
|
@@ -675,7 +675,7 @@ _map_values_node :: (fn(
|
|
|
675
675
|
new_children := *(MapNode(K, U))(new_ptr);
|
|
676
676
|
i := u8(0);
|
|
677
677
|
while (i < branch._children_len), (i = (i + u8(1))), {
|
|
678
|
-
consume((new_children &+ usize(i)).* =
|
|
678
|
+
consume((new_children &+ usize(i)).* = recur(K, V, U, _branch_child_at(K, V, branch, i), f));
|
|
679
679
|
};
|
|
680
680
|
.Branch(MapBranch(K, U)(
|
|
681
681
|
bitmap: branch.bitmap,
|
|
@@ -716,7 +716,7 @@ _filter_from_node :: (fn(
|
|
|
716
716
|
(result : Map(K, V)) = acc;
|
|
717
717
|
i := u8(0);
|
|
718
718
|
while (i < branch._children_len), (i = (i + u8(1))), {
|
|
719
|
-
result =
|
|
719
|
+
result = recur(K, V, result, _branch_child_at(K, V, branch, i), f);
|
|
720
720
|
};
|
|
721
721
|
result
|
|
722
722
|
},
|
|
@@ -750,7 +750,7 @@ _all_entries_match :: (fn(
|
|
|
750
750
|
i := u8(0);
|
|
751
751
|
(ok : bool) = true;
|
|
752
752
|
while ((i < branch._children_len) && ok), (i = (i + u8(1))), {
|
|
753
|
-
if(!(
|
|
753
|
+
if(!(recur(K, V, _branch_child_at(K, V, branch, i), target)), {
|
|
754
754
|
ok = false;
|
|
755
755
|
});
|
|
756
756
|
};
|
package/std/imm/sorted_map.yo
CHANGED
|
@@ -202,12 +202,12 @@ _node_insert :: (fn(
|
|
|
202
202
|
(n : RBNode(K, V)) = cond(
|
|
203
203
|
(key < h._key) =>
|
|
204
204
|
_new_node(K, V, h._key, h._value, h._color,
|
|
205
|
-
.Some(
|
|
205
|
+
.Some(recur(K, V, h._left, key, value)), h._right),
|
|
206
206
|
(key == h._key) =>
|
|
207
207
|
_new_node(K, V, h._key, value, h._color, h._left, h._right),
|
|
208
208
|
true =>
|
|
209
209
|
_new_node(K, V, h._key, h._value, h._color,
|
|
210
|
-
h._left, .Some(
|
|
210
|
+
h._left, .Some(recur(K, V, h._right, key, value)))
|
|
211
211
|
);
|
|
212
212
|
_fixup(K, V, n)
|
|
213
213
|
}
|
|
@@ -225,9 +225,9 @@ _node_get :: (fn(
|
|
|
225
225
|
match(node,
|
|
226
226
|
.None => .None,
|
|
227
227
|
.Some(h) => cond(
|
|
228
|
-
(key < h._key) =>
|
|
228
|
+
(key < h._key) => recur(K, V, h._left, key),
|
|
229
229
|
(key == h._key) => .Some(h._value),
|
|
230
|
-
true =>
|
|
230
|
+
true => recur(K, V, h._right, key)
|
|
231
231
|
)
|
|
232
232
|
)
|
|
233
233
|
);
|
|
@@ -243,9 +243,9 @@ _node_contains :: (fn(
|
|
|
243
243
|
match(node,
|
|
244
244
|
.None => false,
|
|
245
245
|
.Some(h) => cond(
|
|
246
|
-
(key < h._key) =>
|
|
246
|
+
(key < h._key) => recur(K, V, h._left, key),
|
|
247
247
|
(key == h._key) => true,
|
|
248
|
-
true =>
|
|
248
|
+
true => recur(K, V, h._right, key)
|
|
249
249
|
)
|
|
250
250
|
)
|
|
251
251
|
);
|
|
@@ -305,7 +305,7 @@ _node_min :: (fn(
|
|
|
305
305
|
where(K <: (Eq(K), Ord(K), Send), V <: Send)
|
|
306
306
|
) -> RBNode(K, V))(
|
|
307
307
|
match(h._left,
|
|
308
|
-
.Some(l) =>
|
|
308
|
+
.Some(l) => recur(K, V, l),
|
|
309
309
|
.None => h
|
|
310
310
|
)
|
|
311
311
|
);
|
|
@@ -325,7 +325,7 @@ _delete_min :: (fn(
|
|
|
325
325
|
node = _move_red_left(K, V, node);
|
|
326
326
|
});
|
|
327
327
|
new_left := match(node._left,
|
|
328
|
-
.Some(nl) =>
|
|
328
|
+
.Some(nl) => recur(K, V, nl),
|
|
329
329
|
.None => (Option(RBNode(K, V)).None)
|
|
330
330
|
);
|
|
331
331
|
.Some(_fixup(K, V,
|
|
@@ -361,7 +361,7 @@ _node_remove :: (fn(
|
|
|
361
361
|
node = _move_red_left(K, V, node);
|
|
362
362
|
});
|
|
363
363
|
new_left := match(node._left,
|
|
364
|
-
.Some(nl) =>
|
|
364
|
+
.Some(nl) => recur(K, V, nl, key),
|
|
365
365
|
.None => (Option(RBNode(K, V)).None)
|
|
366
366
|
);
|
|
367
367
|
node = _new_node(K, V, node._key, node._value, node._color, new_left, node._right);
|
|
@@ -410,7 +410,7 @@ _node_remove :: (fn(
|
|
|
410
410
|
}, {
|
|
411
411
|
// Go right
|
|
412
412
|
new_right := match(node._right,
|
|
413
|
-
.Some(r) =>
|
|
413
|
+
.Some(r) => recur(K, V, r, key),
|
|
414
414
|
.None => (Option(RBNode(K, V)).None)
|
|
415
415
|
);
|
|
416
416
|
node = _new_node(K, V, node._key, node._value, node._color, node._left, new_right);
|
|
@@ -435,9 +435,9 @@ _collect_keys :: (fn(
|
|
|
435
435
|
match(node,
|
|
436
436
|
.None => acc,
|
|
437
437
|
.Some(h) => {
|
|
438
|
-
right_acc :=
|
|
438
|
+
right_acc := recur(K, V, h._right, acc);
|
|
439
439
|
with_key := right_acc.prepend(h._key);
|
|
440
|
-
|
|
440
|
+
recur(K, V, h._left, with_key)
|
|
441
441
|
}
|
|
442
442
|
)
|
|
443
443
|
);
|
|
@@ -453,9 +453,9 @@ _collect_values :: (fn(
|
|
|
453
453
|
match(node,
|
|
454
454
|
.None => acc,
|
|
455
455
|
.Some(h) => {
|
|
456
|
-
right_acc :=
|
|
456
|
+
right_acc := recur(K, V, h._right, acc);
|
|
457
457
|
with_val := right_acc.prepend(h._value);
|
|
458
|
-
|
|
458
|
+
recur(K, V, h._left, with_val)
|
|
459
459
|
}
|
|
460
460
|
)
|
|
461
461
|
);
|
package/std/imm/string.yo
CHANGED
|
@@ -15,12 +15,12 @@ _min :: (fn(a: usize, b: usize) -> usize)(
|
|
|
15
15
|
cond((a < b) => a, true => b)
|
|
16
16
|
);
|
|
17
17
|
|
|
18
|
-
_alloc_bytes :: (fn(n: usize) -> *(u8))(
|
|
18
|
+
_alloc_bytes :: (fn(n: usize) -> *(u8))(
|
|
19
19
|
match(malloc(n),
|
|
20
20
|
.Some(p) => *(u8)(p),
|
|
21
21
|
.None => panic("imm.String: allocation failed")
|
|
22
22
|
)
|
|
23
|
-
|
|
23
|
+
);
|
|
24
24
|
|
|
25
25
|
/// Immutable, thread-safe UTF-8 string.
|
|
26
26
|
///
|
|
@@ -424,7 +424,7 @@ impl(String,
|
|
|
424
424
|
}),
|
|
425
425
|
|
|
426
426
|
/// Replace the first occurrence of `search` with `replacement`.
|
|
427
|
-
replace : (fn(self: Self, search: Self, replacement: Self) -> Self)(
|
|
427
|
+
replace : (fn(self: Self, search: Self, replacement: Self) -> Self)(
|
|
428
428
|
match(self.index_of(search, usize(0)),
|
|
429
429
|
.None => { return self; },
|
|
430
430
|
.Some(idx) => {
|
|
@@ -434,7 +434,7 @@ impl(String,
|
|
|
434
434
|
return tmp.concat(after);
|
|
435
435
|
}
|
|
436
436
|
)
|
|
437
|
-
|
|
437
|
+
),
|
|
438
438
|
|
|
439
439
|
/// Replace all occurrences of `search` with `replacement`.
|
|
440
440
|
replace_all : (fn(self: Self, search: Self, replacement: Self) -> Self)({
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
//! Structured logging with configurable level and output destination.
|
|
2
2
|
|
|
3
|
-
open import "
|
|
4
|
-
{ ToString } :: import "
|
|
5
|
-
{ fwrite, stdout, stderr, FILE } :: import "
|
|
3
|
+
open import "./string";
|
|
4
|
+
{ ToString } :: import "./fmt";
|
|
5
|
+
{ fwrite, stdout, stderr, FILE } :: import "./libc/stdio";
|
|
6
6
|
|
|
7
7
|
/// Log severity level.
|
|
8
8
|
Level :: enum(Trace, Debug, Info, Warn, Error);
|
package/std/prelude.yo
CHANGED
|
@@ -31,7 +31,7 @@ extern "Yo",
|
|
|
31
31
|
__yo_return_self : (fn(forall(T: Type), self: T) -> T),
|
|
32
32
|
__yo_noop : (fn(forall(T : Type))-> T),
|
|
33
33
|
__yo_as : (fn(forall(_Self: Type), self: _Self, comptime(Target): Type) -> Target),
|
|
34
|
-
|
|
34
|
+
|
|
35
35
|
// Arithmetic Operators
|
|
36
36
|
/// +
|
|
37
37
|
__yo_op_add : (fn(forall(T : Type), x : T, y : T) -> T),
|
|
@@ -45,7 +45,7 @@ extern "Yo",
|
|
|
45
45
|
__yo_op_mod : (fn(forall(T : Type), x : T, y : T) -> T),
|
|
46
46
|
/// -
|
|
47
47
|
__yo_op_neg : (fn(forall(T : Type), x : T) -> T),
|
|
48
|
-
|
|
48
|
+
|
|
49
49
|
// Relational Operators
|
|
50
50
|
/// ==
|
|
51
51
|
__yo_op_eq : (fn(forall(T : Type), x : T, y : T) -> bool),
|
|
@@ -641,7 +641,7 @@ ComptimeEq ::
|
|
|
641
641
|
((lhs, rhs) ->
|
|
642
642
|
not(Self.(==)(lhs, rhs))
|
|
643
643
|
),
|
|
644
|
-
|
|
644
|
+
|
|
645
645
|
where(Self <: Comptime)
|
|
646
646
|
)
|
|
647
647
|
;
|
|
@@ -3377,7 +3377,6 @@ impl(long, Clone(
|
|
|
3377
3377
|
_long :: long;
|
|
3378
3378
|
export long : _long;
|
|
3379
3379
|
|
|
3380
|
-
|
|
3381
3380
|
/// ulong
|
|
3382
3381
|
impl(ulong, Send());
|
|
3383
3382
|
impl(ulong, Acyclic());
|
|
@@ -3946,7 +3945,6 @@ assert :: (fn(flag : bool, (msg : str) ?= "Assertion failed.") -> unit)
|
|
|
3946
3945
|
;
|
|
3947
3946
|
export assert;
|
|
3948
3947
|
|
|
3949
|
-
|
|
3950
3948
|
/// ComptimeList
|
|
3951
3949
|
impl(forall(T : Type), ComptimeList(T), Comptime());
|
|
3952
3950
|
impl(forall(T : Type), ComptimeList(T), Acyclic());
|
|
@@ -3961,7 +3959,7 @@ impl(forall(T : Type), where(T <: Comptime), ComptimeList(T),
|
|
|
3961
3959
|
|
|
3962
3960
|
first : car,
|
|
3963
3961
|
rest : cdr,
|
|
3964
|
-
|
|
3962
|
+
|
|
3965
3963
|
append : (fn(comptime(self): Self, comptime(another): Self) -> comptime(Self))(
|
|
3966
3964
|
__yo_comptime_list_append(self, another)
|
|
3967
3965
|
),
|
|
@@ -4627,7 +4625,6 @@ export
|
|
|
4627
4625
|
(?*)
|
|
4628
4626
|
;
|
|
4629
4627
|
|
|
4630
|
-
|
|
4631
4628
|
/// DeriveContext — context passed to derive rule functions (needs Option).
|
|
4632
4629
|
/// Used by the `derive` macro to generate trait implementations.
|
|
4633
4630
|
DeriveContext :: struct(
|
|
@@ -4789,13 +4786,13 @@ __derive_eq :: (fn(comptime(T) : Type, comptime(ctx) : DeriveContext, comptime(t
|
|
|
4789
4786
|
)
|
|
4790
4787
|
))
|
|
4791
4788
|
},
|
|
4792
|
-
true =>
|
|
4789
|
+
true =>
|
|
4793
4790
|
ctx.make_impl(quote(
|
|
4794
4791
|
Eq(...#(trait_params))(
|
|
4795
4792
|
(==) : ((lhs, rhs) -> true)
|
|
4796
4793
|
)
|
|
4797
4794
|
))
|
|
4798
|
-
|
|
4795
|
+
|
|
4799
4796
|
)
|
|
4800
4797
|
}
|
|
4801
4798
|
);
|
|
@@ -4884,13 +4881,13 @@ __derive_clone :: (fn(comptime(T) : Type, comptime(ctx) : DeriveContext, comptim
|
|
|
4884
4881
|
)
|
|
4885
4882
|
))
|
|
4886
4883
|
},
|
|
4887
|
-
true =>
|
|
4884
|
+
true =>
|
|
4888
4885
|
ctx.make_impl(quote(
|
|
4889
4886
|
Clone(
|
|
4890
4887
|
clone : ((self) -> self.*)
|
|
4891
4888
|
)
|
|
4892
4889
|
))
|
|
4893
|
-
|
|
4890
|
+
|
|
4894
4891
|
)
|
|
4895
4892
|
}
|
|
4896
4893
|
);
|
|
@@ -4905,13 +4902,13 @@ __derive_hash :: (fn(comptime(T) : Type, comptime(ctx) : DeriveContext, comptime
|
|
|
4905
4902
|
fields :: Type.get_struct_fields(T);
|
|
4906
4903
|
fc :: fields.len();
|
|
4907
4904
|
cond(
|
|
4908
|
-
(fc == 0) =>
|
|
4905
|
+
(fc == 0) =>
|
|
4909
4906
|
ctx.make_impl(quote(
|
|
4910
4907
|
Hash(
|
|
4911
4908
|
(hash) : ((self) -> u64(0))
|
|
4912
4909
|
)
|
|
4913
4910
|
))
|
|
4914
|
-
|
|
4911
|
+
,
|
|
4915
4912
|
true => {
|
|
4916
4913
|
hash_stmts :: __yo_comptime_fold_range(fc, "",
|
|
4917
4914
|
(fn(comptime(a) : comptime_string, comptime(fi) : usize) -> comptime(comptime_string))(
|
|
@@ -4986,13 +4983,13 @@ __derive_hash :: (fn(comptime(T) : Type, comptime(ctx) : DeriveContext, comptime
|
|
|
4986
4983
|
)
|
|
4987
4984
|
))
|
|
4988
4985
|
},
|
|
4989
|
-
true =>
|
|
4986
|
+
true =>
|
|
4990
4987
|
ctx.make_impl(quote(
|
|
4991
4988
|
Hash(
|
|
4992
4989
|
(hash) : ((self) -> u64(0))
|
|
4993
4990
|
)
|
|
4994
4991
|
))
|
|
4995
|
-
|
|
4992
|
+
|
|
4996
4993
|
)
|
|
4997
4994
|
}
|
|
4998
4995
|
);
|
|
@@ -5035,7 +5032,7 @@ __derive_ord_struct_body :: (fn(comptime(T) : Type, comptime(op) : comptime_stri
|
|
|
5035
5032
|
|
|
5036
5033
|
// Helper: generate lexicographic comparison for enum variant bindings
|
|
5037
5034
|
__derive_ord_variant_body :: (fn(comptime(v) : VariantInfo, comptime(op) : comptime_string) -> comptime(comptime_string))(
|
|
5038
|
-
|
|
5035
|
+
|
|
5039
5036
|
cond(
|
|
5040
5037
|
(v.fields.len() == 1) => {
|
|
5041
5038
|
fname :: v.fields.get(0).name;
|
|
@@ -5062,7 +5059,7 @@ __derive_ord_variant_body :: (fn(comptime(v) : VariantInfo, comptime(op) : compt
|
|
|
5062
5059
|
__s3("cond(\n ", branches, "\n )")
|
|
5063
5060
|
}
|
|
5064
5061
|
)
|
|
5065
|
-
|
|
5062
|
+
|
|
5066
5063
|
);
|
|
5067
5064
|
|
|
5068
5065
|
__derive_ord :: (fn(comptime(T) : Type, comptime(ctx) : DeriveContext, comptime(trait_params) : ComptimeList(Expr)) -> comptime(Expr))(
|
|
@@ -5073,7 +5070,7 @@ __derive_ord :: (fn(comptime(T) : Type, comptime(ctx) : DeriveContext, comptime(
|
|
|
5073
5070
|
fields :: Type.get_struct_fields(T);
|
|
5074
5071
|
fc :: fields.len();
|
|
5075
5072
|
cond(
|
|
5076
|
-
(fc == 0) =>
|
|
5073
|
+
(fc == 0) =>
|
|
5077
5074
|
ctx.make_impl(quote(
|
|
5078
5075
|
Ord(...#(trait_params))(
|
|
5079
5076
|
(<) : ((lhs, rhs) -> false),
|
|
@@ -5082,7 +5079,7 @@ __derive_ord :: (fn(comptime(T) : Type, comptime(ctx) : DeriveContext, comptime(
|
|
|
5082
5079
|
(>=) : ((lhs, rhs) -> true)
|
|
5083
5080
|
)
|
|
5084
5081
|
))
|
|
5085
|
-
|
|
5082
|
+
,
|
|
5086
5083
|
true => {
|
|
5087
5084
|
lt_body :: __derive_ord_struct_body(T, "<");
|
|
5088
5085
|
le_body :: __derive_ord_struct_body(T, "<=");
|
|
@@ -5168,7 +5165,7 @@ __derive_ord :: (fn(comptime(T) : Type, comptime(ctx) : DeriveContext, comptime(
|
|
|
5168
5165
|
)
|
|
5169
5166
|
))
|
|
5170
5167
|
},
|
|
5171
|
-
true =>
|
|
5168
|
+
true =>
|
|
5172
5169
|
ctx.make_impl(quote(
|
|
5173
5170
|
Ord(...#(trait_params))(
|
|
5174
5171
|
(<) : ((lhs, rhs) -> false),
|
|
@@ -5177,13 +5174,12 @@ __derive_ord :: (fn(comptime(T) : Type, comptime(ctx) : DeriveContext, comptime(
|
|
|
5177
5174
|
(>=) : ((lhs, rhs) -> true)
|
|
5178
5175
|
)
|
|
5179
5176
|
))
|
|
5180
|
-
|
|
5177
|
+
|
|
5181
5178
|
)
|
|
5182
5179
|
}
|
|
5183
5180
|
);
|
|
5184
5181
|
derive_rule(Ord, __derive_ord);
|
|
5185
5182
|
|
|
5186
|
-
|
|
5187
5183
|
/// Result — a value that is either success (`Ok`) or failure (`Err`).
|
|
5188
5184
|
///
|
|
5189
5185
|
/// `Result(OkType, ErrorType)` has two variants:
|
|
@@ -5491,7 +5487,6 @@ impl(forall(T : Type), Iso(T),
|
|
|
5491
5487
|
)
|
|
5492
5488
|
);
|
|
5493
5489
|
|
|
5494
|
-
|
|
5495
5490
|
(^) :: (fn(quote(v) : Expr) -> unquote(Expr))({
|
|
5496
5491
|
temp :: cond(
|
|
5497
5492
|
v.is_atom() => v,
|
package/std/process/command.yo
CHANGED
|
@@ -163,7 +163,7 @@ _spawn_with_fds :: (fn(
|
|
|
163
163
|
stdout_fd: i32,
|
|
164
164
|
stderr_fd: i32,
|
|
165
165
|
using(io : IO, exn : Exception)
|
|
166
|
-
) -> Impl(Future(i32, IO, Exception)))(
|
|
166
|
+
) -> Impl(Future(i32, IO, Exception)))(
|
|
167
167
|
io.async((using(io, exn)) => {
|
|
168
168
|
storage := _build_cstr_storage(self);
|
|
169
169
|
argc := storage.len();
|
|
@@ -197,11 +197,11 @@ _spawn_with_fds :: (fn(
|
|
|
197
197
|
|
|
198
198
|
IOError.check(pid)
|
|
199
199
|
})
|
|
200
|
-
|
|
200
|
+
);
|
|
201
201
|
|
|
202
202
|
// Read all available bytes from `fd` into a freshly returned ArrayList(u8)
|
|
203
203
|
// until EOF (read returns 0).
|
|
204
|
-
_drain_fd :: (fn(fd: i32, using(io : IO, exn : Exception)) -> Impl(Future(ArrayList(u8), IO, Exception)))(
|
|
204
|
+
_drain_fd :: (fn(fd: i32, using(io : IO, exn : Exception)) -> Impl(Future(ArrayList(u8), IO, Exception)))(
|
|
205
205
|
io.async((using(io, exn)) => {
|
|
206
206
|
buf_size := usize(4096);
|
|
207
207
|
buf := *(u8)(malloc(buf_size).unwrap());
|
|
@@ -226,7 +226,7 @@ _drain_fd :: (fn(fd: i32, using(io : IO, exn : Exception)) -> Impl(Future(ArrayL
|
|
|
226
226
|
free(.Some(*(void)(buf)));
|
|
227
227
|
out
|
|
228
228
|
})
|
|
229
|
-
|
|
229
|
+
);
|
|
230
230
|
|
|
231
231
|
// ============================================================================
|
|
232
232
|
// Public Command methods (status / output)
|
|
@@ -235,18 +235,18 @@ _drain_fd :: (fn(fd: i32, using(io : IO, exn : Exception)) -> Impl(Future(ArrayL
|
|
|
235
235
|
impl(Command,
|
|
236
236
|
/// Spawn the child with stdio inherited from the parent, wait for it to
|
|
237
237
|
/// exit, and return its `ExitStatus`.
|
|
238
|
-
status : (fn(self: *(Self), using(io : IO)) -> Impl(Future(ExitStatus, IO, Exception)))(
|
|
238
|
+
status : (fn(self: *(Self), using(io : IO)) -> Impl(Future(ExitStatus, IO, Exception)))(
|
|
239
239
|
io.async((using(io, exn)) => {
|
|
240
240
|
pid := io.await(_spawn_with_fds(self, i32(-1), i32(-1), i32(-1)));
|
|
241
241
|
raw := io.await(IO_process.waitpid(pid, i32(0)));
|
|
242
242
|
IOError.check(raw);
|
|
243
243
|
ExitStatus(raw: raw)
|
|
244
244
|
})
|
|
245
|
-
|
|
245
|
+
),
|
|
246
246
|
|
|
247
247
|
/// Spawn the child with stdout and stderr captured through pipes. Waits for
|
|
248
248
|
/// the child to exit and returns the exit status plus the captured bytes.
|
|
249
|
-
output : (fn(self: *(Self), using(io : IO)) -> Impl(Future(Output, IO, Exception)))(
|
|
249
|
+
output : (fn(self: *(Self), using(io : IO)) -> Impl(Future(Output, IO, Exception)))(
|
|
250
250
|
io.async((using(io, exn)) => {
|
|
251
251
|
// Create stdout and stderr pipes.
|
|
252
252
|
out_fd_buf := MaybeUninit(Array(i32, usize(2))).new();
|
|
@@ -295,7 +295,7 @@ impl(Command,
|
|
|
295
295
|
stderr: stderr_buf
|
|
296
296
|
)
|
|
297
297
|
})
|
|
298
|
-
|
|
298
|
+
)
|
|
299
299
|
);
|
|
300
300
|
|
|
301
301
|
export
|