@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/imm/string.yo
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
//!
|
|
3
3
|
//! Uses atomic reference counting for safe sharing across threads.
|
|
4
4
|
//! All "modification" operations return a new string; the original is unchanged.
|
|
5
|
+
pragma(Pragma.AllowUnsafe);
|
|
5
6
|
{ GlobalAllocator } :: import("../allocator.yo");
|
|
6
7
|
{ malloc, free } :: GlobalAllocator;
|
|
7
8
|
{ memcpy, memcmp } :: import("../libc/string.yo");
|
|
@@ -57,7 +58,7 @@ impl(
|
|
|
57
58
|
return(Self(_ptr :.None, _len : usize(0), _capacity : usize(0)));
|
|
58
59
|
});
|
|
59
60
|
ptr := _alloc_bytes(slen);
|
|
60
|
-
memcpy(*(void)(ptr), *(void)(s.ptr()), slen);
|
|
61
|
+
unsafe(memcpy(*(void)(ptr), *(void)(s.ptr()), slen));
|
|
61
62
|
return(Self(_ptr :.Some(ptr), _len : slen, _capacity : slen));
|
|
62
63
|
}),
|
|
63
64
|
/// Create a string from a standard (mutable) String by copying its bytes.
|
|
@@ -68,7 +69,7 @@ impl(
|
|
|
68
69
|
});
|
|
69
70
|
ptr := _alloc_bytes(slen);
|
|
70
71
|
(as_str : str) = s.as_str();
|
|
71
|
-
memcpy(*(void)(ptr), *(void)(as_str.ptr()), slen);
|
|
72
|
+
unsafe(memcpy(*(void)(ptr), *(void)(as_str.ptr()), slen));
|
|
72
73
|
return(Self(_ptr :.Some(ptr), _len : slen, _capacity : slen));
|
|
73
74
|
}),
|
|
74
75
|
/// Byte length of the string.
|
|
@@ -138,7 +139,7 @@ impl(
|
|
|
138
139
|
.Some(op) => match(
|
|
139
140
|
self._ptr,
|
|
140
141
|
.Some(sp) => {
|
|
141
|
-
memcpy(*(void)(sp &+ self._len), *(void)(op), other._len);
|
|
142
|
+
unsafe(memcpy(*(void)(sp &+ self._len), *(void)(op), other._len));
|
|
142
143
|
},
|
|
143
144
|
.None => ()
|
|
144
145
|
),
|
|
@@ -155,7 +156,7 @@ impl(
|
|
|
155
156
|
match(
|
|
156
157
|
self._ptr,
|
|
157
158
|
.Some(sp) => {
|
|
158
|
-
memcpy(*(void)(ptr), *(void)(sp), self._len);
|
|
159
|
+
unsafe(memcpy(*(void)(ptr), *(void)(sp), self._len));
|
|
159
160
|
free(.Some(*(void)(sp)));
|
|
160
161
|
},
|
|
161
162
|
.None => ()
|
|
@@ -163,7 +164,7 @@ impl(
|
|
|
163
164
|
match(
|
|
164
165
|
other._ptr,
|
|
165
166
|
.Some(op) => {
|
|
166
|
-
memcpy(*(void)(ptr &+ self._len), *(void)(op), other._len);
|
|
167
|
+
unsafe(memcpy(*(void)(ptr &+ self._len), *(void)(op), other._len));
|
|
167
168
|
},
|
|
168
169
|
.None => ()
|
|
169
170
|
);
|
|
@@ -176,14 +177,14 @@ impl(
|
|
|
176
177
|
match(
|
|
177
178
|
self._ptr,
|
|
178
179
|
.Some(sp) => {
|
|
179
|
-
memcpy(*(void)(ptr), *(void)(sp), self._len);
|
|
180
|
+
unsafe(memcpy(*(void)(ptr), *(void)(sp), self._len));
|
|
180
181
|
},
|
|
181
182
|
.None => ()
|
|
182
183
|
);
|
|
183
184
|
match(
|
|
184
185
|
other._ptr,
|
|
185
186
|
.Some(op) => {
|
|
186
|
-
memcpy(*(void)(ptr &+ self._len), *(void)(op), other._len);
|
|
187
|
+
unsafe(memcpy(*(void)(ptr &+ self._len), *(void)(op), other._len));
|
|
187
188
|
},
|
|
188
189
|
.None => ()
|
|
189
190
|
);
|
|
@@ -203,7 +204,7 @@ impl(
|
|
|
203
204
|
match(
|
|
204
205
|
self._ptr,
|
|
205
206
|
.Some(sp) => {
|
|
206
|
-
memcpy(*(void)(ptr), *(void)(sp &+ clamped_start), new_len);
|
|
207
|
+
unsafe(memcpy(*(void)(ptr), *(void)(sp &+ clamped_start), new_len));
|
|
207
208
|
},
|
|
208
209
|
.None => ()
|
|
209
210
|
);
|
|
@@ -221,7 +222,7 @@ impl(
|
|
|
221
222
|
self._ptr,
|
|
222
223
|
.Some(sp) => match(
|
|
223
224
|
prefix._ptr,
|
|
224
|
-
.Some(pp) => (memcmp(*(void)(sp), *(void)(pp), prefix._len) == int(0)),
|
|
225
|
+
.Some(pp) => (unsafe(memcmp(*(void)(sp), *(void)(pp), prefix._len)) == int(0)),
|
|
225
226
|
.None => true
|
|
226
227
|
),
|
|
227
228
|
.None => (prefix._len == usize(0))
|
|
@@ -240,7 +241,7 @@ impl(
|
|
|
240
241
|
self._ptr,
|
|
241
242
|
.Some(sp) => match(
|
|
242
243
|
suffix._ptr,
|
|
243
|
-
.Some(xp) => (memcmp(*(void)(sp &+ offset), *(void)(xp), suffix._len) == int(0)),
|
|
244
|
+
.Some(xp) => (unsafe(memcmp(*(void)(sp &+ offset), *(void)(xp), suffix._len)) == int(0)),
|
|
244
245
|
.None => true
|
|
245
246
|
),
|
|
246
247
|
.None => (suffix._len == usize(0))
|
|
@@ -269,7 +270,7 @@ impl(
|
|
|
269
270
|
i := from_index;
|
|
270
271
|
limit := ((self._len - needle._len) + usize(1));
|
|
271
272
|
while(i < limit, i = (i + usize(1)), {
|
|
272
|
-
if(memcmp(*(void)(sp &+ i), *(void)(np), needle._len) == int(0), {
|
|
273
|
+
if(unsafe(memcmp(*(void)(sp &+ i), *(void)(np), needle._len)) == int(0), {
|
|
273
274
|
return(.Some(i));
|
|
274
275
|
});
|
|
275
276
|
});
|
|
@@ -410,7 +411,7 @@ impl(
|
|
|
410
411
|
return(self);
|
|
411
412
|
});
|
|
412
413
|
ptr := _alloc_bytes(self._len);
|
|
413
|
-
memcpy(*(void)(ptr), *(void)(sp), self._len);
|
|
414
|
+
unsafe(memcpy(*(void)(ptr), *(void)(sp), self._len));
|
|
414
415
|
i := usize(0);
|
|
415
416
|
while(i < self._len, i = (i + usize(1)), {
|
|
416
417
|
(b : u8) = (ptr &+ i).*;
|
|
@@ -447,7 +448,7 @@ impl(
|
|
|
447
448
|
return(self);
|
|
448
449
|
});
|
|
449
450
|
ptr := _alloc_bytes(self._len);
|
|
450
|
-
memcpy(*(void)(ptr), *(void)(sp), self._len);
|
|
451
|
+
unsafe(memcpy(*(void)(ptr), *(void)(sp), self._len));
|
|
451
452
|
i := usize(0);
|
|
452
453
|
while(i < self._len, i = (i + usize(1)), {
|
|
453
454
|
(b : u8) = (ptr &+ i).*;
|
|
@@ -516,7 +517,7 @@ impl(
|
|
|
516
517
|
.Some(sp) => {
|
|
517
518
|
i := usize(0);
|
|
518
519
|
while(i < n, i = (i + usize(1)), {
|
|
519
|
-
memcpy(*(void)(ptr &+ (i * self._len)), *(void)(sp), self._len);
|
|
520
|
+
unsafe(memcpy(*(void)(ptr &+ (i * self._len)), *(void)(sp), self._len));
|
|
520
521
|
});
|
|
521
522
|
},
|
|
522
523
|
.None => ()
|
|
@@ -623,7 +624,7 @@ impl(
|
|
|
623
624
|
self._ptr,
|
|
624
625
|
.Some(sp) => match(
|
|
625
626
|
other._ptr,
|
|
626
|
-
.Some(op) => (memcmp(*(void)(sp), *(void)(op), self._len) == int(0)),
|
|
627
|
+
.Some(op) => (unsafe(memcmp(*(void)(sp), *(void)(op), self._len)) == int(0)),
|
|
627
628
|
.None => false
|
|
628
629
|
),
|
|
629
630
|
.None => match(
|
|
@@ -653,7 +654,7 @@ impl(
|
|
|
653
654
|
});
|
|
654
655
|
match(
|
|
655
656
|
self._ptr,
|
|
656
|
-
.Some(sp) => (memcmp(*(void)(sp), *(void)(other.ptr()), self._len) == int(0)),
|
|
657
|
+
.Some(sp) => (unsafe(memcmp(*(void)(sp), *(void)(other.ptr()), self._len)) == int(0)),
|
|
657
658
|
.None => (other_len == usize(0))
|
|
658
659
|
)
|
|
659
660
|
})
|
|
@@ -670,7 +671,7 @@ impl(
|
|
|
670
671
|
.Some(sp) => match(
|
|
671
672
|
other._ptr,
|
|
672
673
|
.Some(op) => {
|
|
673
|
-
(cmp_result : int) = memcmp(*(void)(sp), *(void)(op), min_len);
|
|
674
|
+
(cmp_result : int) = unsafe(memcmp(*(void)(sp), *(void)(op), min_len));
|
|
674
675
|
if(cmp_result != int(0), {
|
|
675
676
|
return(cmp_result < int(0));
|
|
676
677
|
});
|
|
@@ -697,15 +698,18 @@ impl(
|
|
|
697
698
|
impl(
|
|
698
699
|
String,
|
|
699
700
|
Hash(
|
|
700
|
-
(hash) : (fn(self :
|
|
701
|
+
(hash) : (fn(ref(self) : Self) -> u64)({
|
|
701
702
|
h := u64(14695981039346656037);
|
|
702
703
|
match(
|
|
703
|
-
self
|
|
704
|
+
self._ptr,
|
|
704
705
|
.None => (),
|
|
705
706
|
.Some(p) => {
|
|
706
707
|
i := usize(0);
|
|
707
|
-
while(i < self
|
|
708
|
-
|
|
708
|
+
while(i < self._len, i = (i + usize(1)), {
|
|
709
|
+
// SAFETY: `p` points at the Rc-managed UTF-8 byte
|
|
710
|
+
// buffer of length `self._len`; the loop guard
|
|
711
|
+
// `i < self._len` keeps `p &+ i` inside the allocation.
|
|
712
|
+
h = (h ^ u64(unsafe((p &+ i).*)));
|
|
709
713
|
h = (h * u64(1099511628211));
|
|
710
714
|
});
|
|
711
715
|
}
|
|
@@ -718,8 +722,8 @@ impl(
|
|
|
718
722
|
impl(
|
|
719
723
|
String,
|
|
720
724
|
ToString(
|
|
721
|
-
to_string : (fn(self :
|
|
722
|
-
std_string.String.from(self
|
|
725
|
+
to_string : (fn(ref(self) : Self) -> std_string.String)(
|
|
726
|
+
std_string.String.from(self.as_str())
|
|
723
727
|
)
|
|
724
728
|
)
|
|
725
729
|
);
|
package/std/imm/vec.yo
CHANGED
|
@@ -13,9 +13,10 @@
|
|
|
13
13
|
//!
|
|
14
14
|
//! v := Vec(i32).new();
|
|
15
15
|
//! v = v.push(i32(1)).push(i32(2)).push(i32(3));
|
|
16
|
-
//! assert((v
|
|
16
|
+
//! assert((v(usize(0)) == i32(1)), "first element");
|
|
17
17
|
//! assert((v.len() == usize(3)), "length is 3");
|
|
18
18
|
//! ```
|
|
19
|
+
pragma(Pragma.AllowUnsafe);
|
|
19
20
|
{ GlobalAllocator } :: import("../allocator.yo");
|
|
20
21
|
{ malloc, free } :: GlobalAllocator;
|
|
21
22
|
/// Persistent immutable vector.
|
|
@@ -406,7 +407,7 @@ impl(
|
|
|
406
407
|
new_ptr := Vec(V)._raw_alloc(min_len);
|
|
407
408
|
i := usize(0);
|
|
408
409
|
while(i < min_len, i = (i + usize(1)), {
|
|
409
|
-
(new_ptr &+ i).* = f((self._ptr &+ i).*, other
|
|
410
|
+
(new_ptr &+ i).* = f((self._ptr &+ i).*, other(i));
|
|
410
411
|
});
|
|
411
412
|
Vec(V)(_ptr : new_ptr, _len : min_len, _cap : min_len)
|
|
412
413
|
}),
|
|
@@ -445,4 +446,19 @@ impl(
|
|
|
445
446
|
})
|
|
446
447
|
)
|
|
447
448
|
);
|
|
449
|
+
/// Index trait — `vec(idx)` returns the element at `idx`, panicking if
|
|
450
|
+
/// out of bounds. Body takes `&(self)` so the dispatcher's inlined call
|
|
451
|
+
/// passes the right C-ABI shape. See plans/ITERATOR_REDESIGN.md.
|
|
452
|
+
impl(
|
|
453
|
+
forall(T : Type),
|
|
454
|
+
where(T <: Send),
|
|
455
|
+
Vec(T),
|
|
456
|
+
Index(usize)(
|
|
457
|
+
Output : T,
|
|
458
|
+
index : (fn(ref(self) : Self, idx : usize) -> *(Self.Output))({
|
|
459
|
+
assert(idx < self._len, "imm.Vec: index out of bounds");
|
|
460
|
+
self._ptr &+ idx
|
|
461
|
+
})
|
|
462
|
+
)
|
|
463
|
+
);
|
|
448
464
|
export(Vec, PopResult);
|
package/std/io/reader.yo
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
//! Reader trait for byte-level input.
|
|
2
|
+
pragma(Pragma.AllowUnsafe);
|
|
2
3
|
{ Exception } :: import("../error");
|
|
3
4
|
/// Common interface for reading bytes from various sources.
|
|
4
5
|
Reader :: trait(
|
|
5
6
|
/// Read up to `size` bytes into buffer `buf`.
|
|
6
7
|
/// Returns the number of bytes actually read (0 at end-of-stream).
|
|
7
8
|
read :
|
|
8
|
-
fn(self :
|
|
9
|
+
fn(ref(self) : Self, buf : *(u8), size : usize, exn : Exception) -> usize
|
|
9
10
|
);
|
|
10
11
|
export(Reader);
|
package/std/io/writer.yo
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
//! Writer trait for byte-level output.
|
|
2
|
+
pragma(Pragma.AllowUnsafe);
|
|
2
3
|
{ Exception } :: import("../error");
|
|
3
4
|
/// Common interface for writing bytes to a destination.
|
|
4
5
|
Writer :: trait(
|
|
5
6
|
/// Write bytes from buffer. Returns number of bytes written.
|
|
6
7
|
write :
|
|
7
|
-
fn(self :
|
|
8
|
+
fn(ref(self) : Self, buf : *(u8), size : usize, exn : Exception) -> usize,
|
|
8
9
|
/// Flush any buffered data to the underlying destination.
|
|
9
10
|
flush :
|
|
10
|
-
fn(self :
|
|
11
|
+
fn(ref(self) : Self, exn : Exception) -> unit
|
|
11
12
|
);
|
|
12
13
|
export(Writer);
|
package/std/libc/assert.yo
CHANGED
package/std/libc/ctype.yo
CHANGED
package/std/libc/dirent.yo
CHANGED
package/std/libc/errno.yo
CHANGED
package/std/libc/fcntl.yo
CHANGED
package/std/libc/float.yo
CHANGED
package/std/libc/limits.yo
CHANGED
package/std/libc/math.yo
CHANGED
package/std/libc/signal.yo
CHANGED
package/std/libc/stdatomic.yo
CHANGED
package/std/libc/stdint.yo
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
//! Note: Yo already has `i8`, `i16`, `i32`, `i64`, `u8`, `u16`, `u32`, `u64`.
|
|
4
4
|
//! This file provides C-compatible aliases and additional types/constants.
|
|
5
5
|
// Type aliases for C compatibility (mapping Yo types to C stdint names)
|
|
6
|
+
pragma(Pragma.AllowUnsafe);
|
|
6
7
|
int8_t :: i8;
|
|
7
8
|
int16_t :: i16;
|
|
8
9
|
int32_t :: i32;
|
package/std/libc/stdio.yo
CHANGED
package/std/libc/stdlib.yo
CHANGED
package/std/libc/string.yo
CHANGED
package/std/libc/sys/stat.yo
CHANGED
package/std/libc/time.yo
CHANGED
package/std/libc/unistd.yo
CHANGED
package/std/libc/wctype.yo
CHANGED
package/std/libc/windows.yo
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
//! Windows-specific C API bindings.
|
|
2
2
|
//! Only available when compiling for Windows.
|
|
3
3
|
// Windows type aliases (using Yo types that match the C types)
|
|
4
|
+
pragma(Pragma.AllowUnsafe);
|
|
5
|
+
pragma(Pragma.AllowUnsafe);
|
|
4
6
|
DWORD :: ulong; // unsigned long on Windows
|
|
5
7
|
WCHAR :: ushort; // unsigned short (UTF-16 code unit)
|
|
6
8
|
BOOL :: int; // int
|
package/std/log.yo
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
//! Structured logging with configurable level and output destination.
|
|
2
|
+
pragma(Pragma.AllowUnsafe);
|
|
2
3
|
open(import("./string"));
|
|
3
4
|
{ ToString } :: import("./fmt");
|
|
4
5
|
{ fwrite, stdout, stderr, FILE } :: import("./libc/stdio");
|
|
@@ -7,9 +8,9 @@ Level :: enum(Trace, Debug, Info, Warn, Error);
|
|
|
7
8
|
impl(
|
|
8
9
|
Level,
|
|
9
10
|
ToString(
|
|
10
|
-
to_string : (fn(self :
|
|
11
|
+
to_string : (fn(ref(self) : Self) -> String)(
|
|
11
12
|
match(
|
|
12
|
-
self
|
|
13
|
+
self,
|
|
13
14
|
.Trace => String.from("TRACE"),
|
|
14
15
|
.Debug => String.from("DEBUG"),
|
|
15
16
|
.Info => String.from("INFO "),
|
|
@@ -60,7 +61,7 @@ _write_string :: (fn(s : String, dest : *(FILE)) -> unit)({
|
|
|
60
61
|
cond(
|
|
61
62
|
(bytes.len() > usize(0)) => {
|
|
62
63
|
ptr := bytes.ptr().unwrap();
|
|
63
|
-
fwrite(*(void)(ptr), usize(1), bytes.len(), dest);
|
|
64
|
+
unsafe(fwrite(*(void)(ptr), usize(1), bytes.len(), dest));
|
|
64
65
|
},
|
|
65
66
|
true => ()
|
|
66
67
|
);
|
|
@@ -79,11 +80,11 @@ log :: (fn(level : Level, msg : String) -> unit)({
|
|
|
79
80
|
.Stderr => stderr
|
|
80
81
|
);
|
|
81
82
|
// Write "[LEVEL] msg\n"
|
|
82
|
-
fwrite(*(void)(*(u8)("[")), usize(1), usize(1), dest);
|
|
83
|
+
unsafe(fwrite(*(void)(*(u8)("[")), usize(1), usize(1), dest));
|
|
83
84
|
_write_string(level_str, dest);
|
|
84
|
-
fwrite(*(void)(*(u8)("] ")), usize(1), usize(2), dest);
|
|
85
|
+
unsafe(fwrite(*(void)(*(u8)("] ")), usize(1), usize(2), dest));
|
|
85
86
|
_write_string(msg, dest);
|
|
86
|
-
fwrite(*(void)(*(u8)("\n")), usize(1), usize(1), dest);
|
|
87
|
+
unsafe(fwrite(*(void)(*(u8)("\n")), usize(1), usize(1), dest));
|
|
87
88
|
});
|
|
88
89
|
export(log);
|
|
89
90
|
// ============================================================================
|
package/std/net/addr.yo
CHANGED
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
// { IpAddr, SocketAddr } :: import "std/net/addr";
|
|
8
8
|
//
|
|
9
9
|
// addr := SocketAddr.new(IpAddr.loopback_v4(), u16(8080));
|
|
10
|
+
pragma(Pragma.AllowUnsafe);
|
|
10
11
|
open(import("../string"));
|
|
11
12
|
{ ToString } :: import("../fmt");
|
|
12
13
|
{ Writer } :: import("../fmt/writer");
|
|
@@ -33,14 +34,14 @@ impl(
|
|
|
33
34
|
IpAddr,
|
|
34
35
|
/// Parse an IPv4 address from a dotted-decimal `String` (e.g. "127.0.0.1").
|
|
35
36
|
/// Throws on invalid input.
|
|
36
|
-
parse_v4 : (fn(s : String,
|
|
37
|
+
parse_v4 : (fn(s : String, exn : Exception) -> IpAddr)({
|
|
37
38
|
bytes := s.as_bytes();
|
|
38
39
|
parts := Array(u8, usize(4)).fill(u8(0));
|
|
39
40
|
part_idx := usize(0);
|
|
40
41
|
val := u32(0);
|
|
41
42
|
i := usize(0);
|
|
42
43
|
while(runtime(i < bytes.len()), {
|
|
43
|
-
ch := bytes
|
|
44
|
+
ch := bytes(i);
|
|
44
45
|
cond(
|
|
45
46
|
(ch == _ASCII_DOT) => {
|
|
46
47
|
// '.' separator
|
|
@@ -145,10 +146,10 @@ impl(
|
|
|
145
146
|
self -> {
|
|
146
147
|
return(
|
|
147
148
|
match(
|
|
148
|
-
self
|
|
149
|
+
self,
|
|
149
150
|
.V4(a, b, c, d) => {
|
|
150
151
|
buf := Array(u8, usize(16)).fill(u8(0));
|
|
151
|
-
snprintf(*(char)(&(buf(usize(0)))), usize(16), "%d.%d.%d.%d", i32(a), i32(b), i32(c), i32(d));
|
|
152
|
+
unsafe(snprintf(*(char)(&(buf(usize(0)))), usize(16), "%d.%d.%d.%d", i32(a), i32(b), i32(c), i32(d)));
|
|
152
153
|
String.from_cstr(&(buf(usize(0)))).unwrap()
|
|
153
154
|
},
|
|
154
155
|
.V6(segs) => {
|
|
@@ -205,7 +206,7 @@ impl(
|
|
|
205
206
|
self -> {
|
|
206
207
|
ip_str := self.ip.to_string();
|
|
207
208
|
buf := Array(u8, usize(8)).fill(u8(0));
|
|
208
|
-
snprintf(*(char)(&(buf(usize(0)))), usize(8), "%d", i32(self.port));
|
|
209
|
+
unsafe(snprintf(*(char)(&(buf(usize(0)))), usize(8), "%d", i32(self.port)));
|
|
209
210
|
port_str := String.from_cstr(&(buf(usize(0)))).unwrap();
|
|
210
211
|
return(
|
|
211
212
|
match(
|
package/std/net/dns.yo
CHANGED
|
@@ -9,18 +9,15 @@
|
|
|
9
9
|
// { IpAddr } :: import "std/net/addr";
|
|
10
10
|
// { Exception } :: import "std/error";
|
|
11
11
|
//
|
|
12
|
-
// main :: (fn(
|
|
13
|
-
//
|
|
14
|
-
// println(err.message());
|
|
15
|
-
// escape ();
|
|
16
|
-
// }));
|
|
17
|
-
// addrs := io.await(lookup_host(`localhost`));
|
|
12
|
+
// main :: (fn(io : Io, exn : Exception) -> unit)({
|
|
13
|
+
// addrs := io.await(lookup_host(`localhost`, io), { io, exn });
|
|
18
14
|
// i := usize(0);
|
|
19
15
|
// while runtime((i < addrs.len())), {
|
|
20
|
-
// println(addrs
|
|
16
|
+
// println(addrs(i).to_string());
|
|
21
17
|
// i = (i + usize(1));
|
|
22
18
|
// };
|
|
23
19
|
// });
|
|
20
|
+
pragma(Pragma.AllowUnsafe);
|
|
24
21
|
{ GlobalAllocator } :: import("../allocator");
|
|
25
22
|
{ malloc, free } :: GlobalAllocator;
|
|
26
23
|
{ ArrayList } :: import("../collections/array_list");
|
|
@@ -28,23 +25,23 @@ open(import("../string"));
|
|
|
28
25
|
open(import("../fmt"));
|
|
29
26
|
{ NetError } :: import("./errors");
|
|
30
27
|
{ IpAddr, SocketAddr } :: import("./addr");
|
|
31
|
-
{ Error, AnyError, Exception } :: import("../error");
|
|
28
|
+
{ Error, AnyError, Exception, IoExn } :: import("../error");
|
|
32
29
|
IO_dns :: import("../sys/dns");
|
|
33
30
|
{ AF_INET, AF_INET6 } :: import("../sys/socket");
|
|
34
31
|
// ============================================================================
|
|
35
32
|
// DNS lookup
|
|
36
33
|
// ============================================================================
|
|
37
34
|
/// Resolve a hostname to a list of IP addresses.
|
|
38
|
-
lookup_host :: (fn(host : String,
|
|
39
|
-
io.async((
|
|
35
|
+
lookup_host :: (fn(host : String, io : Io) -> Impl(Future(ArrayList(IpAddr), IoExn)))(
|
|
36
|
+
io.async((e) => {
|
|
40
37
|
host_cstr_bytes := host.to_cstr();
|
|
41
38
|
host_cstr := host_cstr_bytes.ptr().unwrap();
|
|
42
39
|
result_ptr := IO_dns.alloc_result();
|
|
43
|
-
ret := io.await(IO_dns.getaddrinfo(host_cstr,.None,.None, result_ptr));
|
|
40
|
+
ret := e.io.await(IO_dns.getaddrinfo(host_cstr,.None,.None, result_ptr), e.io);
|
|
44
41
|
cond(
|
|
45
42
|
(ret != i32(0)) => {
|
|
46
43
|
IO_dns.free_result(result_ptr);
|
|
47
|
-
exn.throw(dyn(NetError.DNSFailed(host)));
|
|
44
|
+
e.exn.throw(dyn(NetError.DNSFailed(host)));
|
|
48
45
|
},
|
|
49
46
|
true => ()
|
|
50
47
|
);
|
|
@@ -86,13 +83,13 @@ lookup_host :: (fn(host : String, using(io : IO)) -> Impl(Future(ArrayList(IpAdd
|
|
|
86
83
|
})
|
|
87
84
|
);
|
|
88
85
|
/// Resolve a hostname and port to a list of socket addresses.
|
|
89
|
-
resolve :: (fn(host : String, port : u16,
|
|
90
|
-
io.async((
|
|
91
|
-
addrs := io.await(lookup_host(host,
|
|
86
|
+
resolve :: (fn(host : String, port : u16, io : Io) -> Impl(Future(ArrayList(SocketAddr), IoExn)))(
|
|
87
|
+
io.async((e) => {
|
|
88
|
+
addrs := e.io.await(lookup_host(host, io), e);
|
|
92
89
|
result := ArrayList(SocketAddr).new();
|
|
93
90
|
i := usize(0);
|
|
94
91
|
while(runtime(i < addrs.len()), {
|
|
95
|
-
ip := addrs
|
|
92
|
+
ip := addrs(i);
|
|
96
93
|
result.push(SocketAddr.new(ip, port));
|
|
97
94
|
i = (i + usize(1));
|
|
98
95
|
});
|
package/std/net/errors.yo
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
//! Network error types.
|
|
2
2
|
// std/net/errors.yo - Network error type
|
|
3
3
|
//
|
|
4
|
-
// Higher-level network error that wraps
|
|
4
|
+
// Higher-level network error that wraps IoError with network-specific variants.
|
|
5
5
|
//
|
|
6
6
|
// Example:
|
|
7
7
|
// { NetError } :: import "std/net/errors";
|
|
8
8
|
open(import("../string"));
|
|
9
|
-
{
|
|
9
|
+
{ IoError } :: import("../sys/errors");
|
|
10
10
|
{ ToString } :: import("../fmt");
|
|
11
11
|
{ Error, AnyError, Exception } :: import("../error");
|
|
12
12
|
// ============================================================================
|
|
@@ -33,14 +33,14 @@ NetError :: enum(
|
|
|
33
33
|
/// DNS resolution failed.
|
|
34
34
|
DNSFailed(msg : String),
|
|
35
35
|
/// A wrapped lower-level I/O error.
|
|
36
|
-
|
|
36
|
+
Io(err : IoError),
|
|
37
37
|
/// An unclassified network error with a message.
|
|
38
38
|
Other(msg : String)
|
|
39
39
|
);
|
|
40
40
|
impl(
|
|
41
41
|
NetError,
|
|
42
|
-
/// Convert an `
|
|
43
|
-
from_io : (fn(err :
|
|
42
|
+
/// Convert an `IoError` into the corresponding `NetError` variant.
|
|
43
|
+
from_io : (fn(err : IoError) -> Self)(
|
|
44
44
|
match(
|
|
45
45
|
err,
|
|
46
46
|
.ConnectionRefused =>.ConnectionRefused,
|
|
@@ -51,7 +51,7 @@ impl(
|
|
|
51
51
|
.TimedOut =>.TimedOut,
|
|
52
52
|
.HostUnreachable =>.HostUnreachable,
|
|
53
53
|
.NetworkUnreachable =>.NetworkUnreachable,
|
|
54
|
-
_ =>.
|
|
54
|
+
_ =>.Io(err)
|
|
55
55
|
)
|
|
56
56
|
)
|
|
57
57
|
);
|
|
@@ -71,7 +71,7 @@ impl(
|
|
|
71
71
|
.HostUnreachable => String.from("host unreachable"),
|
|
72
72
|
.NetworkUnreachable => String.from("network unreachable"),
|
|
73
73
|
.DNSFailed(msg) => `DNS lookup failed: ${msg}`,
|
|
74
|
-
.
|
|
74
|
+
.Io(err) => err.to_string(),
|
|
75
75
|
.Other(msg) => msg
|
|
76
76
|
);
|
|
77
77
|
return(s);
|
|
@@ -84,10 +84,10 @@ impl(
|
|
|
84
84
|
NetError,
|
|
85
85
|
/// Check a raw syscall result and throw on error.
|
|
86
86
|
/// Positive values are returned as-is; negative values are converted to a `NetError` and thrown.
|
|
87
|
-
check : (fn(result : i32,
|
|
87
|
+
check : (fn(result : i32, exn : Exception) -> i32)(
|
|
88
88
|
cond(
|
|
89
89
|
(result >= i32(0)) => result,
|
|
90
|
-
true => exn.throw(dyn(Self.from_io(
|
|
90
|
+
true => exn.throw(dyn(Self.from_io(IoError.from_errno(i32(0) - result))))
|
|
91
91
|
)
|
|
92
92
|
)
|
|
93
93
|
);
|