@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/fmt/to_string.yo
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
//! ToString trait and implementations for all primitive types.
|
|
2
|
+
pragma(Pragma.AllowUnsafe);
|
|
2
3
|
{ String, rune } :: import("../string");
|
|
3
4
|
{ snprintf } :: import("../libc/stdio");
|
|
4
5
|
/// Trait for converting values to their `String` representation.
|
|
5
6
|
/// Types implementing this trait can be used with `println`, `print`, and template strings.
|
|
6
7
|
ToString :: trait(
|
|
7
|
-
to_string : (fn(self :
|
|
8
|
+
to_string : (fn(ref(self) : Self) -> String)
|
|
8
9
|
);
|
|
9
10
|
export(ToString);
|
|
10
11
|
// === Helper function for integer conversion ===
|
|
@@ -16,10 +17,10 @@ _INT_BUFFER_SIZE :: usize(24);
|
|
|
16
17
|
impl(
|
|
17
18
|
i8,
|
|
18
19
|
ToString(
|
|
19
|
-
to_string : (fn(self :
|
|
20
|
+
to_string : (fn(ref(self) : Self) -> String)({
|
|
20
21
|
buffer := Array(u8, _INT_BUFFER_SIZE).fill(0);
|
|
21
22
|
buffer_ptr := (&(buffer(0)));
|
|
22
|
-
snprintf(*(char)(buffer_ptr), _INT_BUFFER_SIZE, "%hhd", self
|
|
23
|
+
unsafe(snprintf(*(char)(buffer_ptr), _INT_BUFFER_SIZE, "%hhd", self));
|
|
23
24
|
String.from_cstr(buffer_ptr).unwrap()
|
|
24
25
|
})
|
|
25
26
|
)
|
|
@@ -27,10 +28,10 @@ impl(
|
|
|
27
28
|
impl(
|
|
28
29
|
i16,
|
|
29
30
|
ToString(
|
|
30
|
-
to_string : (fn(self :
|
|
31
|
+
to_string : (fn(ref(self) : Self) -> String)({
|
|
31
32
|
buffer := Array(u8, _INT_BUFFER_SIZE).fill(0);
|
|
32
33
|
buffer_ptr := (&(buffer(0)));
|
|
33
|
-
snprintf(*(char)(buffer_ptr), _INT_BUFFER_SIZE, "%hd", self
|
|
34
|
+
unsafe(snprintf(*(char)(buffer_ptr), _INT_BUFFER_SIZE, "%hd", self));
|
|
34
35
|
String.from_cstr(buffer_ptr).unwrap()
|
|
35
36
|
})
|
|
36
37
|
)
|
|
@@ -38,10 +39,10 @@ impl(
|
|
|
38
39
|
impl(
|
|
39
40
|
i32,
|
|
40
41
|
ToString(
|
|
41
|
-
to_string : (fn(self :
|
|
42
|
+
to_string : (fn(ref(self) : Self) -> String)({
|
|
42
43
|
buffer := Array(u8, _INT_BUFFER_SIZE).fill(0);
|
|
43
44
|
buffer_ptr := (&(buffer(0)));
|
|
44
|
-
snprintf(*(char)(buffer_ptr), _INT_BUFFER_SIZE, "%d", self
|
|
45
|
+
unsafe(snprintf(*(char)(buffer_ptr), _INT_BUFFER_SIZE, "%d", self));
|
|
45
46
|
String.from_cstr(buffer_ptr).unwrap()
|
|
46
47
|
})
|
|
47
48
|
)
|
|
@@ -49,10 +50,10 @@ impl(
|
|
|
49
50
|
impl(
|
|
50
51
|
i64,
|
|
51
52
|
ToString(
|
|
52
|
-
to_string : (fn(self :
|
|
53
|
+
to_string : (fn(ref(self) : Self) -> String)({
|
|
53
54
|
buffer := Array(u8, _INT_BUFFER_SIZE).fill(0);
|
|
54
55
|
buffer_ptr := (&(buffer(0)));
|
|
55
|
-
snprintf(*(char)(buffer_ptr), _INT_BUFFER_SIZE, "%lld", self
|
|
56
|
+
unsafe(snprintf(*(char)(buffer_ptr), _INT_BUFFER_SIZE, "%lld", self));
|
|
56
57
|
String.from_cstr(buffer_ptr).unwrap()
|
|
57
58
|
})
|
|
58
59
|
)
|
|
@@ -60,10 +61,10 @@ impl(
|
|
|
60
61
|
impl(
|
|
61
62
|
isize,
|
|
62
63
|
ToString(
|
|
63
|
-
to_string : (fn(self :
|
|
64
|
+
to_string : (fn(ref(self) : Self) -> String)({
|
|
64
65
|
buffer := Array(u8, _INT_BUFFER_SIZE).fill(0);
|
|
65
66
|
buffer_ptr := (&(buffer(0)));
|
|
66
|
-
snprintf(*(char)(buffer_ptr), _INT_BUFFER_SIZE, "%zd", self
|
|
67
|
+
unsafe(snprintf(*(char)(buffer_ptr), _INT_BUFFER_SIZE, "%zd", self));
|
|
67
68
|
String.from_cstr(buffer_ptr).unwrap()
|
|
68
69
|
})
|
|
69
70
|
)
|
|
@@ -72,10 +73,10 @@ impl(
|
|
|
72
73
|
impl(
|
|
73
74
|
u8,
|
|
74
75
|
ToString(
|
|
75
|
-
to_string : (fn(self :
|
|
76
|
+
to_string : (fn(ref(self) : Self) -> String)({
|
|
76
77
|
buffer := Array(u8, _INT_BUFFER_SIZE).fill(0);
|
|
77
78
|
buffer_ptr := (&(buffer(0)));
|
|
78
|
-
snprintf(*(char)(buffer_ptr), _INT_BUFFER_SIZE, "%hhu", self
|
|
79
|
+
unsafe(snprintf(*(char)(buffer_ptr), _INT_BUFFER_SIZE, "%hhu", self));
|
|
79
80
|
String.from_cstr(buffer_ptr).unwrap()
|
|
80
81
|
})
|
|
81
82
|
)
|
|
@@ -83,10 +84,10 @@ impl(
|
|
|
83
84
|
impl(
|
|
84
85
|
u16,
|
|
85
86
|
ToString(
|
|
86
|
-
to_string : (fn(self :
|
|
87
|
+
to_string : (fn(ref(self) : Self) -> String)({
|
|
87
88
|
buffer := Array(u8, _INT_BUFFER_SIZE).fill(0);
|
|
88
89
|
buffer_ptr := (&(buffer(0)));
|
|
89
|
-
snprintf(*(char)(buffer_ptr), _INT_BUFFER_SIZE, "%hu", self
|
|
90
|
+
unsafe(snprintf(*(char)(buffer_ptr), _INT_BUFFER_SIZE, "%hu", self));
|
|
90
91
|
String.from_cstr(buffer_ptr).unwrap()
|
|
91
92
|
})
|
|
92
93
|
)
|
|
@@ -94,10 +95,10 @@ impl(
|
|
|
94
95
|
impl(
|
|
95
96
|
u32,
|
|
96
97
|
ToString(
|
|
97
|
-
to_string : (fn(self :
|
|
98
|
+
to_string : (fn(ref(self) : Self) -> String)({
|
|
98
99
|
buffer := Array(u8, _INT_BUFFER_SIZE).fill(0);
|
|
99
100
|
buffer_ptr := (&(buffer(0)));
|
|
100
|
-
snprintf(*(char)(buffer_ptr), _INT_BUFFER_SIZE, "%u", self
|
|
101
|
+
unsafe(snprintf(*(char)(buffer_ptr), _INT_BUFFER_SIZE, "%u", self));
|
|
101
102
|
String.from_cstr(buffer_ptr).unwrap()
|
|
102
103
|
})
|
|
103
104
|
)
|
|
@@ -105,10 +106,10 @@ impl(
|
|
|
105
106
|
impl(
|
|
106
107
|
u64,
|
|
107
108
|
ToString(
|
|
108
|
-
to_string : (fn(self :
|
|
109
|
+
to_string : (fn(ref(self) : Self) -> String)({
|
|
109
110
|
buffer := Array(u8, _INT_BUFFER_SIZE).fill(0);
|
|
110
111
|
buffer_ptr := (&(buffer(0)));
|
|
111
|
-
snprintf(*(char)(buffer_ptr), _INT_BUFFER_SIZE, "%llu", self
|
|
112
|
+
unsafe(snprintf(*(char)(buffer_ptr), _INT_BUFFER_SIZE, "%llu", self));
|
|
112
113
|
String.from_cstr(buffer_ptr).unwrap()
|
|
113
114
|
})
|
|
114
115
|
)
|
|
@@ -116,10 +117,10 @@ impl(
|
|
|
116
117
|
impl(
|
|
117
118
|
usize,
|
|
118
119
|
ToString(
|
|
119
|
-
to_string : (fn(self :
|
|
120
|
+
to_string : (fn(ref(self) : Self) -> String)({
|
|
120
121
|
buffer := Array(u8, _INT_BUFFER_SIZE).fill(0);
|
|
121
122
|
buffer_ptr := (&(buffer(0)));
|
|
122
|
-
snprintf(*(char)(buffer_ptr), _INT_BUFFER_SIZE, "%zu", self
|
|
123
|
+
unsafe(snprintf(*(char)(buffer_ptr), _INT_BUFFER_SIZE, "%zu", self));
|
|
123
124
|
String.from_cstr(buffer_ptr).unwrap()
|
|
124
125
|
})
|
|
125
126
|
)
|
|
@@ -131,11 +132,11 @@ _FLOAT_BUFFER_SIZE :: usize(64);
|
|
|
131
132
|
impl(
|
|
132
133
|
f32,
|
|
133
134
|
ToString(
|
|
134
|
-
to_string : (fn(self :
|
|
135
|
+
to_string : (fn(ref(self) : Self) -> String)({
|
|
135
136
|
buffer := Array(u8, _FLOAT_BUFFER_SIZE).fill(0);
|
|
136
137
|
buffer_ptr := (&(buffer(0)));
|
|
137
138
|
// Use %g for general format (removes trailing zeros)
|
|
138
|
-
snprintf(*(char)(buffer_ptr), _FLOAT_BUFFER_SIZE, "%g", f64(self
|
|
139
|
+
unsafe(snprintf(*(char)(buffer_ptr), _FLOAT_BUFFER_SIZE, "%g", f64(self)));
|
|
139
140
|
String.from_cstr(buffer_ptr).unwrap()
|
|
140
141
|
})
|
|
141
142
|
)
|
|
@@ -143,11 +144,11 @@ impl(
|
|
|
143
144
|
impl(
|
|
144
145
|
f64,
|
|
145
146
|
ToString(
|
|
146
|
-
to_string : (fn(self :
|
|
147
|
+
to_string : (fn(ref(self) : Self) -> String)({
|
|
147
148
|
buffer := Array(u8, _FLOAT_BUFFER_SIZE).fill(0);
|
|
148
149
|
buffer_ptr := (&(buffer(0)));
|
|
149
150
|
// Use %g for general format (removes trailing zeros)
|
|
150
|
-
snprintf(*(char)(buffer_ptr), _FLOAT_BUFFER_SIZE, "%g", self
|
|
151
|
+
unsafe(snprintf(*(char)(buffer_ptr), _FLOAT_BUFFER_SIZE, "%g", self));
|
|
151
152
|
String.from_cstr(buffer_ptr).unwrap()
|
|
152
153
|
})
|
|
153
154
|
)
|
|
@@ -156,9 +157,9 @@ impl(
|
|
|
156
157
|
impl(
|
|
157
158
|
bool,
|
|
158
159
|
ToString(
|
|
159
|
-
to_string : (fn(self :
|
|
160
|
+
to_string : (fn(ref(self) : Self) -> String)(
|
|
160
161
|
cond(
|
|
161
|
-
self
|
|
162
|
+
self => String.from("true"),
|
|
162
163
|
true => String.from("false")
|
|
163
164
|
)
|
|
164
165
|
)
|
|
@@ -168,10 +169,10 @@ impl(
|
|
|
168
169
|
impl(
|
|
169
170
|
char,
|
|
170
171
|
ToString(
|
|
171
|
-
to_string : (fn(self :
|
|
172
|
+
to_string : (fn(ref(self) : Self) -> String)({
|
|
172
173
|
// char is a single byte, create a 2-byte buffer (char + null)
|
|
173
174
|
buffer := Array(u8, usize(2)).fill(0);
|
|
174
|
-
buffer(0) = u8(self
|
|
175
|
+
buffer(0) = u8(self);
|
|
175
176
|
buffer_ptr := (&(buffer(0)));
|
|
176
177
|
String.from_cstr(buffer_ptr).unwrap()
|
|
177
178
|
})
|
|
@@ -181,9 +182,9 @@ impl(
|
|
|
181
182
|
impl(
|
|
182
183
|
String,
|
|
183
184
|
ToString(
|
|
184
|
-
to_string : (fn(self :
|
|
185
|
+
to_string : (fn(ref(self) : Self) -> String)(
|
|
185
186
|
// String already is a string, just return a clone
|
|
186
|
-
self
|
|
187
|
+
self
|
|
187
188
|
)
|
|
188
189
|
)
|
|
189
190
|
);
|
|
@@ -191,9 +192,9 @@ impl(
|
|
|
191
192
|
impl(
|
|
192
193
|
str,
|
|
193
194
|
ToString(
|
|
194
|
-
to_string : (fn(self :
|
|
195
|
+
to_string : (fn(ref(self) : Self) -> String)({
|
|
195
196
|
// Convert byte array to String assuming UTF-8
|
|
196
|
-
return(String.from(self
|
|
197
|
+
return(String.from(self));
|
|
197
198
|
})
|
|
198
199
|
)
|
|
199
200
|
);
|
|
@@ -202,9 +203,9 @@ impl(
|
|
|
202
203
|
impl(
|
|
203
204
|
rune,
|
|
204
205
|
ToString(
|
|
205
|
-
to_string : (fn(self :
|
|
206
|
+
to_string : (fn(ref(self) : Self) -> String)({
|
|
206
207
|
// Get the code point value
|
|
207
|
-
code := self
|
|
208
|
+
code := self.char;
|
|
208
209
|
// UTF-8 encoding:
|
|
209
210
|
// 0x00-0x7F: 1 byte
|
|
210
211
|
// 0x80-0x7FF: 2 bytes
|
|
@@ -309,7 +310,7 @@ __derive_tostring :: (fn(comptime(T) : Type, comptime(ctx) : DeriveContext, comp
|
|
|
309
310
|
(fi == 0) => a,
|
|
310
311
|
true => __derive_join_plus(a, "String.from(\", \")")
|
|
311
312
|
);
|
|
312
|
-
__derive_join_plus(with_sep, __ts_s3("
|
|
313
|
+
__derive_join_plus(with_sep, __ts_s3("self.", fname, ".to_string()"))
|
|
313
314
|
})
|
|
314
315
|
);
|
|
315
316
|
full_body :: __derive_join_plus(body, "String.from(\")\")");
|
|
@@ -355,7 +356,7 @@ __derive_tostring :: (fn(comptime(T) : Type, comptime(ctx) : DeriveContext, comp
|
|
|
355
356
|
(fi == 0) => a,
|
|
356
357
|
true => __derive_join_plus(a, "String.from(\", \")")
|
|
357
358
|
);
|
|
358
|
-
__derive_join_plus(with_sep, __ts_s3("
|
|
359
|
+
__derive_join_plus(with_sep, __ts_s3("__v_", fname, ".to_string()"))
|
|
359
360
|
})
|
|
360
361
|
);
|
|
361
362
|
full_body :: __derive_join_plus(body, "String.from(\")\")");
|
|
@@ -368,7 +369,7 @@ __derive_tostring :: (fn(comptime(T) : Type, comptime(ctx) : DeriveContext, comp
|
|
|
368
369
|
)
|
|
369
370
|
})
|
|
370
371
|
);
|
|
371
|
-
match_body :: __ts_s3("match(self
|
|
372
|
+
match_body :: __ts_s3("match(self,\n ", ts_branches, "\n )");
|
|
372
373
|
ctx.make_impl(
|
|
373
374
|
quote(
|
|
374
375
|
ToString(
|
package/std/fmt/writer.yo
CHANGED
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
//! .write_byte(u8(33));
|
|
12
12
|
//! s := w.to_string(); // "hello world!"
|
|
13
13
|
//! ```
|
|
14
|
+
pragma(Pragma.AllowUnsafe);
|
|
14
15
|
{ String } :: import("../string");
|
|
15
16
|
{ ArrayList } :: import("../collections/array_list");
|
|
16
17
|
{ rune } :: import("../string/rune");
|
|
@@ -46,7 +47,7 @@ impl(
|
|
|
46
47
|
bytes := s.as_bytes();
|
|
47
48
|
i := usize(0);
|
|
48
49
|
while(i < bytes.len(), i = (i + usize(1)), {
|
|
49
|
-
self.buf.push(bytes
|
|
50
|
+
self.buf.push(bytes(i));
|
|
50
51
|
});
|
|
51
52
|
self
|
|
52
53
|
}),
|
|
@@ -59,7 +60,7 @@ impl(
|
|
|
59
60
|
write_bytes : (fn(self : Self, data : ArrayList(u8)) -> Self)({
|
|
60
61
|
i := usize(0);
|
|
61
62
|
while(i < data.len(), i = (i + usize(1)), {
|
|
62
|
-
self.buf.push(data
|
|
63
|
+
self.buf.push(data(i));
|
|
63
64
|
});
|
|
64
65
|
self
|
|
65
66
|
}),
|
|
@@ -92,7 +93,7 @@ impl(
|
|
|
92
93
|
write_i64 : (fn(self : Self, n : i64) -> Self)({
|
|
93
94
|
buf := Array(u8, usize(24)).fill(u8(0));
|
|
94
95
|
buf_ptr := &(buf(usize(0)));
|
|
95
|
-
snprintf(*(char)(buf_ptr), usize(24), "%lld", n);
|
|
96
|
+
unsafe(snprintf(*(char)(buf_ptr), usize(24), "%lld", n));
|
|
96
97
|
s := String.from_cstr(buf_ptr).unwrap();
|
|
97
98
|
self.write_string(s)
|
|
98
99
|
}),
|
|
@@ -100,7 +101,7 @@ impl(
|
|
|
100
101
|
write_u64 : (fn(self : Self, n : u64) -> Self)({
|
|
101
102
|
buf := Array(u8, usize(24)).fill(u8(0));
|
|
102
103
|
buf_ptr := &(buf(usize(0)));
|
|
103
|
-
snprintf(*(char)(buf_ptr), usize(24), "%llu", n);
|
|
104
|
+
unsafe(snprintf(*(char)(buf_ptr), usize(24), "%llu", n));
|
|
104
105
|
s := String.from_cstr(buf_ptr).unwrap();
|
|
105
106
|
self.write_string(s)
|
|
106
107
|
}),
|
|
@@ -108,7 +109,7 @@ impl(
|
|
|
108
109
|
write_f64 : (fn(self : Self, n : f64, precision : i32) -> Self)({
|
|
109
110
|
buf := Array(u8, usize(64)).fill(u8(0));
|
|
110
111
|
buf_ptr := &(buf(usize(0)));
|
|
111
|
-
snprintf(*(char)(buf_ptr), usize(64), "%.*f", precision, n);
|
|
112
|
+
unsafe(snprintf(*(char)(buf_ptr), usize(64), "%.*f", precision, n));
|
|
112
113
|
s := String.from_cstr(buf_ptr).unwrap();
|
|
113
114
|
self.write_string(s)
|
|
114
115
|
}),
|
|
@@ -123,7 +124,7 @@ impl(
|
|
|
123
124
|
write_hex : (fn(self : Self, n : u64) -> Self)({
|
|
124
125
|
buf := Array(u8, usize(20)).fill(u8(0));
|
|
125
126
|
buf_ptr := &(buf(usize(0)));
|
|
126
|
-
snprintf(*(char)(buf_ptr), usize(20), "%llx", n);
|
|
127
|
+
unsafe(snprintf(*(char)(buf_ptr), usize(20), "%llx", n));
|
|
127
128
|
s := String.from_cstr(buf_ptr).unwrap();
|
|
128
129
|
self.write_string(s)
|
|
129
130
|
}),
|
|
@@ -131,7 +132,7 @@ impl(
|
|
|
131
132
|
write_octal : (fn(self : Self, n : u64) -> Self)({
|
|
132
133
|
buf := Array(u8, usize(24)).fill(u8(0));
|
|
133
134
|
buf_ptr := &(buf(usize(0)));
|
|
134
|
-
snprintf(*(char)(buf_ptr), usize(24), "%llo", n);
|
|
135
|
+
unsafe(snprintf(*(char)(buf_ptr), usize(24), "%llo", n));
|
|
135
136
|
s := String.from_cstr(buf_ptr).unwrap();
|
|
136
137
|
self.write_string(s)
|
|
137
138
|
}),
|
|
@@ -152,7 +153,7 @@ impl(
|
|
|
152
153
|
// Push in reverse order (most significant first)
|
|
153
154
|
i := bits.len();
|
|
154
155
|
while(i > usize(0), i = (i - usize(1)), {
|
|
155
|
-
self.buf.push(bits
|
|
156
|
+
self.buf.push(bits(i - usize(1)));
|
|
156
157
|
});
|
|
157
158
|
}
|
|
158
159
|
);
|
package/std/fs/dir.yo
CHANGED
|
@@ -8,25 +8,20 @@
|
|
|
8
8
|
//! { create_dir, remove_dir, read_dir } :: import "std/fs/dir";
|
|
9
9
|
//! { Path } :: import "std/path";
|
|
10
10
|
//!
|
|
11
|
-
//! main :: (fn(
|
|
12
|
-
//!
|
|
13
|
-
//!
|
|
14
|
-
//!
|
|
15
|
-
//! )
|
|
16
|
-
//! };
|
|
17
|
-
//!
|
|
18
|
-
//! io.await(create_dir(Path.new(`/tmp/yo_test`)));
|
|
19
|
-
//! entries := io.await(read_dir(Path.new(`/tmp/yo_test`)));
|
|
20
|
-
//! io.await(remove_dir(Path.new(`/tmp/yo_test`)));
|
|
11
|
+
//! main :: (fn(io : Io, exn : Exception) -> unit)({
|
|
12
|
+
//! io.await(create_dir(Path.new(`/tmp/yo_test`), io), { io, exn });
|
|
13
|
+
//! entries := io.await(read_dir(Path.new(`/tmp/yo_test`), io), { io, exn });
|
|
14
|
+
//! io.await(remove_dir(Path.new(`/tmp/yo_test`), io), { io, exn });
|
|
21
15
|
//! });
|
|
22
16
|
//! ```
|
|
17
|
+
pragma(Pragma.AllowUnsafe);
|
|
23
18
|
{ GlobalAllocator } :: import("../allocator");
|
|
24
19
|
{ malloc, free } :: GlobalAllocator;
|
|
25
20
|
{ ArrayList } :: import("../collections/array_list");
|
|
26
21
|
open(import("../string"));
|
|
27
22
|
{ Path } :: import("../path");
|
|
28
|
-
{
|
|
29
|
-
{ Error, AnyError, Exception } :: import("../error");
|
|
23
|
+
{ IoError } :: import("../sys/errors");
|
|
24
|
+
{ Error, AnyError, Exception, IoExn } :: import("../error");
|
|
30
25
|
{ EEXIST, ENOENT } :: import("../libc/errno");
|
|
31
26
|
IO_dir :: import("../sys/dir");
|
|
32
27
|
IO_file :: import("../sys/file");
|
|
@@ -61,30 +56,30 @@ export(DirEntry);
|
|
|
61
56
|
// Directory operations
|
|
62
57
|
// ============================================================================
|
|
63
58
|
/// Create a directory at the given path.
|
|
64
|
-
create_dir :: (fn(path : Path,
|
|
65
|
-
io.async((
|
|
59
|
+
create_dir :: (fn(path : Path, io : Io) -> Impl(Future(unit, IoExn)))(
|
|
60
|
+
io.async((e) => {
|
|
66
61
|
cstr_bytes := path.to_string().to_cstr();
|
|
67
62
|
cstr := cstr_bytes.ptr().unwrap();
|
|
68
|
-
result := io.await(IO_dir.mkdir(AT_FDCWD, cstr, i32(DEFAULT_DIR_MODE)));
|
|
63
|
+
result := e.io.await(IO_dir.mkdir(AT_FDCWD, cstr, i32(DEFAULT_DIR_MODE)), e.io);
|
|
69
64
|
cond(
|
|
70
|
-
(result < i32(0)) => exn.throw(dyn(
|
|
65
|
+
(result < i32(0)) => e.exn.throw(dyn(IoError.from_errno(i32(0) - result))),
|
|
71
66
|
true => ()
|
|
72
67
|
)
|
|
73
68
|
})
|
|
74
69
|
);
|
|
75
70
|
/// Create a directory (`str` path variant).
|
|
76
|
-
create_dir_str :: (fn(path : str,
|
|
77
|
-
create_dir(Path.new(String.from(path)))
|
|
71
|
+
create_dir_str :: (fn(path : str, io : Io) -> Impl(Future(unit, IoExn)))(
|
|
72
|
+
create_dir(Path.new(String.from(path)), io)
|
|
78
73
|
);
|
|
79
74
|
/// Create a directory and all missing parent directories.
|
|
80
75
|
/// Does not error if the directory already exists.
|
|
81
|
-
create_dir_all :: (fn(path : Path,
|
|
82
|
-
io.async((
|
|
76
|
+
create_dir_all :: (fn(path : Path, io : Io) -> Impl(Future(unit, IoExn)))(
|
|
77
|
+
io.async((e) => {
|
|
83
78
|
path_s := path.to_string();
|
|
84
79
|
cstr_bytes := path_s.to_cstr();
|
|
85
80
|
cstr := cstr_bytes.ptr().unwrap();
|
|
86
81
|
// Try creating the directory directly first
|
|
87
|
-
result := io.await(IO_dir.mkdir(AT_FDCWD, cstr, i32(DEFAULT_DIR_MODE)));
|
|
82
|
+
result := e.io.await(IO_dir.mkdir(AT_FDCWD, cstr, i32(DEFAULT_DIR_MODE)), e.io);
|
|
88
83
|
cond(
|
|
89
84
|
(result >= i32(0)) => (),
|
|
90
85
|
true => {
|
|
@@ -103,8 +98,8 @@ create_dir_all :: (fn(path : Path, using(io : IO)) -> Impl(Future(unit, IO, Exce
|
|
|
103
98
|
(platform == Platform.Windows) => {
|
|
104
99
|
cond(
|
|
105
100
|
(bytes.len() >= usize(3)) => {
|
|
106
|
-
first := bytes
|
|
107
|
-
second := bytes
|
|
101
|
+
first := bytes(usize(0));
|
|
102
|
+
second := bytes(usize(1));
|
|
108
103
|
is_drive_root := ((((first >= u8(65)) && (first <= u8(90))) || ((first >= u8(97)) && (first <= u8(122)))) && (second == u8(58)));
|
|
109
104
|
cond(
|
|
110
105
|
is_drive_root => {
|
|
@@ -119,18 +114,18 @@ create_dir_all :: (fn(path : Path, using(io : IO)) -> Impl(Future(unit, IO, Exce
|
|
|
119
114
|
true => ()
|
|
120
115
|
);
|
|
121
116
|
while(runtime(i < bytes.len()), {
|
|
122
|
-
b := bytes
|
|
117
|
+
b := bytes(i);
|
|
123
118
|
cond(
|
|
124
119
|
((b == u8(47)) || (b == u8(92))) => {
|
|
125
120
|
// '/' found - try to create this prefix
|
|
126
121
|
prefix := path_s.substring(usize(0), i);
|
|
127
122
|
prefix_cstr_bytes := prefix.to_cstr();
|
|
128
123
|
prefix_cstr := prefix_cstr_bytes.ptr().unwrap();
|
|
129
|
-
r := io.await(IO_dir.mkdir(AT_FDCWD, prefix_cstr, i32(DEFAULT_DIR_MODE)));
|
|
124
|
+
r := e.io.await(IO_dir.mkdir(AT_FDCWD, prefix_cstr, i32(DEFAULT_DIR_MODE)), e.io);
|
|
130
125
|
// Ignore EEXIST errors
|
|
131
126
|
cond(
|
|
132
127
|
((r < i32(0)) && ((i32(0) - r) != i32(EEXIST))) => {
|
|
133
|
-
exn.throw(dyn(
|
|
128
|
+
e.exn.throw(dyn(IoError.from_errno(i32(0) - r)));
|
|
134
129
|
},
|
|
135
130
|
true => ()
|
|
136
131
|
);
|
|
@@ -140,114 +135,114 @@ create_dir_all :: (fn(path : Path, using(io : IO)) -> Impl(Future(unit, IO, Exce
|
|
|
140
135
|
i = (i + usize(1));
|
|
141
136
|
});
|
|
142
137
|
// Create the final directory
|
|
143
|
-
final_result := io.await(IO_dir.mkdir(AT_FDCWD, cstr, i32(DEFAULT_DIR_MODE)));
|
|
138
|
+
final_result := e.io.await(IO_dir.mkdir(AT_FDCWD, cstr, i32(DEFAULT_DIR_MODE)), e.io);
|
|
144
139
|
cond(
|
|
145
140
|
(final_result >= i32(0)) => (),
|
|
146
141
|
true => {
|
|
147
142
|
final_errno := (i32(0) - final_result);
|
|
148
143
|
cond(
|
|
149
144
|
(final_errno == i32(EEXIST)) => (),
|
|
150
|
-
true => exn.throw(dyn(
|
|
145
|
+
true => e.exn.throw(dyn(IoError.from_errno(final_errno)))
|
|
151
146
|
)
|
|
152
147
|
}
|
|
153
148
|
)
|
|
154
149
|
},
|
|
155
|
-
true => exn.throw(dyn(
|
|
150
|
+
true => e.exn.throw(dyn(IoError.from_errno(errno)))
|
|
156
151
|
)
|
|
157
152
|
}
|
|
158
153
|
)
|
|
159
154
|
})
|
|
160
155
|
);
|
|
161
156
|
/// Create a directory and all missing parents (`str` path variant).
|
|
162
|
-
create_dir_all_str :: (fn(path : str,
|
|
163
|
-
create_dir_all(Path.new(String.from(path)))
|
|
157
|
+
create_dir_all_str :: (fn(path : str, io : Io) -> Impl(Future(unit, IoExn)))(
|
|
158
|
+
create_dir_all(Path.new(String.from(path)), io)
|
|
164
159
|
);
|
|
165
160
|
/// Remove an empty directory. Throws if the directory is not empty.
|
|
166
|
-
remove_dir :: (fn(path : Path,
|
|
167
|
-
io.async((
|
|
161
|
+
remove_dir :: (fn(path : Path, io : Io) -> Impl(Future(unit, IoExn)))(
|
|
162
|
+
io.async((e) => {
|
|
168
163
|
cstr_bytes := path.to_string().to_cstr();
|
|
169
164
|
cstr := cstr_bytes.ptr().unwrap();
|
|
170
|
-
result := io.await(IO_dir.unlink(AT_FDCWD, cstr, AT_REMOVEDIR));
|
|
165
|
+
result := e.io.await(IO_dir.unlink(AT_FDCWD, cstr, AT_REMOVEDIR), e.io);
|
|
171
166
|
cond(
|
|
172
|
-
(result < i32(0)) => exn.throw(dyn(
|
|
167
|
+
(result < i32(0)) => e.exn.throw(dyn(IoError.from_errno(i32(0) - result))),
|
|
173
168
|
true => ()
|
|
174
169
|
)
|
|
175
170
|
})
|
|
176
171
|
);
|
|
177
|
-
remove_dir_str :: (fn(path : str,
|
|
178
|
-
remove_dir(Path.new(String.from(path)))
|
|
172
|
+
remove_dir_str :: (fn(path : str, io : Io) -> Impl(Future(unit, IoExn)))(
|
|
173
|
+
remove_dir(Path.new(String.from(path)), io)
|
|
179
174
|
);
|
|
180
175
|
/// Remove a file at the given path.
|
|
181
|
-
remove_file :: (fn(path : Path,
|
|
182
|
-
io.async((
|
|
176
|
+
remove_file :: (fn(path : Path, io : Io) -> Impl(Future(unit, IoExn)))(
|
|
177
|
+
io.async((e) => {
|
|
183
178
|
cstr_bytes := path.to_string().to_cstr();
|
|
184
179
|
cstr := cstr_bytes.ptr().unwrap();
|
|
185
|
-
result := io.await(IO_dir.unlink(AT_FDCWD, cstr, i32(0)));
|
|
180
|
+
result := e.io.await(IO_dir.unlink(AT_FDCWD, cstr, i32(0)), e.io);
|
|
186
181
|
cond(
|
|
187
|
-
(result < i32(0)) => exn.throw(dyn(
|
|
182
|
+
(result < i32(0)) => e.exn.throw(dyn(IoError.from_errno(i32(0) - result))),
|
|
188
183
|
true => ()
|
|
189
184
|
)
|
|
190
185
|
})
|
|
191
186
|
);
|
|
192
|
-
remove_file_str :: (fn(path : str,
|
|
187
|
+
remove_file_str :: (fn(path : str, io : Io) -> Impl(Future(unit, IoExn)))(remove_file(Path.new(String.from(path)), io));
|
|
193
188
|
/// Rename or move a file or directory from `from` to `to`.
|
|
194
|
-
rename :: (fn(from : Path, to : Path,
|
|
195
|
-
io.async((
|
|
189
|
+
rename :: (fn(from : Path, to : Path, io : Io) -> Impl(Future(unit, IoExn)))(
|
|
190
|
+
io.async((e) => {
|
|
196
191
|
from_cstr_bytes := from.to_string().to_cstr();
|
|
197
192
|
from_cstr := from_cstr_bytes.ptr().unwrap();
|
|
198
193
|
to_cstr_bytes := to.to_string().to_cstr();
|
|
199
194
|
to_cstr := to_cstr_bytes.ptr().unwrap();
|
|
200
|
-
result := io.await(IO_dir.rename(AT_FDCWD, from_cstr, AT_FDCWD, to_cstr));
|
|
195
|
+
result := e.io.await(IO_dir.rename(AT_FDCWD, from_cstr, AT_FDCWD, to_cstr), e.io);
|
|
201
196
|
cond(
|
|
202
|
-
(result < i32(0)) => exn.throw(dyn(
|
|
197
|
+
(result < i32(0)) => e.exn.throw(dyn(IoError.from_errno(i32(0) - result))),
|
|
203
198
|
true => ()
|
|
204
199
|
)
|
|
205
200
|
})
|
|
206
201
|
);
|
|
207
|
-
rename_str :: (fn(from : str, to : str,
|
|
202
|
+
rename_str :: (fn(from : str, to : str, io : Io) -> Impl(Future(unit, IoExn)))(rename(Path.new(String.from(from)), Path.new(String.from(to)), io));
|
|
208
203
|
/// Create a hard link from `src` to `dst`.
|
|
209
|
-
hard_link :: (fn(src : Path, dst : Path,
|
|
210
|
-
io.async((
|
|
204
|
+
hard_link :: (fn(src : Path, dst : Path, io : Io) -> Impl(Future(unit, IoExn)))(
|
|
205
|
+
io.async((e) => {
|
|
211
206
|
src_cstr_bytes := src.to_string().to_cstr();
|
|
212
207
|
src_cstr := src_cstr_bytes.ptr().unwrap();
|
|
213
208
|
dst_cstr_bytes := dst.to_string().to_cstr();
|
|
214
209
|
dst_cstr := dst_cstr_bytes.ptr().unwrap();
|
|
215
|
-
result := io.await(IO_dir.link(AT_FDCWD, src_cstr, AT_FDCWD, dst_cstr, i32(0)));
|
|
210
|
+
result := e.io.await(IO_dir.link(AT_FDCWD, src_cstr, AT_FDCWD, dst_cstr, i32(0)), e.io);
|
|
216
211
|
cond(
|
|
217
|
-
(result < i32(0)) => exn.throw(dyn(
|
|
212
|
+
(result < i32(0)) => e.exn.throw(dyn(IoError.from_errno(i32(0) - result))),
|
|
218
213
|
true => ()
|
|
219
214
|
)
|
|
220
215
|
})
|
|
221
216
|
);
|
|
222
|
-
hard_link_str :: (fn(src : str, dst : str,
|
|
217
|
+
hard_link_str :: (fn(src : str, dst : str, io : Io) -> Impl(Future(unit, IoExn)))(hard_link(Path.new(String.from(src)), Path.new(String.from(dst)), io));
|
|
223
218
|
/// Create a symbolic link at `dst` pointing to `src`.
|
|
224
|
-
symlink :: (fn(src : Path, dst : Path,
|
|
225
|
-
io.async((
|
|
219
|
+
symlink :: (fn(src : Path, dst : Path, io : Io) -> Impl(Future(unit, IoExn)))(
|
|
220
|
+
io.async((e) => {
|
|
226
221
|
src_cstr_bytes := src.to_string().to_cstr();
|
|
227
222
|
src_cstr := src_cstr_bytes.ptr().unwrap();
|
|
228
223
|
dst_cstr_bytes := dst.to_string().to_cstr();
|
|
229
224
|
dst_cstr := dst_cstr_bytes.ptr().unwrap();
|
|
230
|
-
result := io.await(IO_dir.symlink(src_cstr, AT_FDCWD, dst_cstr));
|
|
225
|
+
result := e.io.await(IO_dir.symlink(src_cstr, AT_FDCWD, dst_cstr), e.io);
|
|
231
226
|
cond(
|
|
232
|
-
(result < i32(0)) => exn.throw(dyn(
|
|
227
|
+
(result < i32(0)) => e.exn.throw(dyn(IoError.from_errno(i32(0) - result))),
|
|
233
228
|
true => ()
|
|
234
229
|
)
|
|
235
230
|
})
|
|
236
231
|
);
|
|
237
|
-
symlink_str :: (fn(src : str, dst : str,
|
|
232
|
+
symlink_str :: (fn(src : str, dst : str, io : Io) -> Impl(Future(unit, IoExn)))(symlink(Path.new(String.from(src)), Path.new(String.from(dst)), io));
|
|
238
233
|
// ============================================================================
|
|
239
234
|
// Directory listing
|
|
240
235
|
// ============================================================================
|
|
241
236
|
/// Read all entries from a directory, returning an `ArrayList(DirEntry)`.
|
|
242
237
|
/// Skips the `.` and `..` entries.
|
|
243
|
-
read_dir :: (fn(path : Path,
|
|
244
|
-
io.async((
|
|
238
|
+
read_dir :: (fn(path : Path, io : Io) -> Impl(Future(ArrayList(DirEntry), IoExn)))(
|
|
239
|
+
io.async((e) => {
|
|
245
240
|
cstr_bytes := path.to_string().to_cstr();
|
|
246
241
|
cstr := cstr_bytes.ptr().unwrap();
|
|
247
242
|
// Open the directory
|
|
248
|
-
fd_result := io.await(IO_file.openat(AT_FDCWD, cstr, O_RDONLY | O_DIRECTORY, i32(0)));
|
|
243
|
+
fd_result := e.io.await(IO_file.openat(AT_FDCWD, cstr, O_RDONLY | O_DIRECTORY, i32(0)), e.io);
|
|
249
244
|
cond(
|
|
250
|
-
(fd_result < i32(0)) => exn.throw(dyn(
|
|
245
|
+
(fd_result < i32(0)) => e.exn.throw(dyn(IoError.from_errno(i32(0) - fd_result))),
|
|
251
246
|
true => ()
|
|
252
247
|
);
|
|
253
248
|
fd := fd_result;
|
|
@@ -255,12 +250,12 @@ read_dir :: (fn(path : Path, using(io : IO)) -> Impl(Future(ArrayList(DirEntry),
|
|
|
255
250
|
buf_size := u32(4096);
|
|
256
251
|
buf := *(u8)(malloc(usize(buf_size)).unwrap());
|
|
257
252
|
while(runtime(true), {
|
|
258
|
-
n := io.await(IO_dir.getdents(fd, buf, buf_size));
|
|
253
|
+
n := e.io.await(IO_dir.getdents(fd, buf, buf_size), e.io);
|
|
259
254
|
cond(
|
|
260
255
|
(n < i32(0)) => {
|
|
261
256
|
free(.Some(*(void)(buf)));
|
|
262
|
-
io.await(IO_file.close(fd));
|
|
263
|
-
exn.throw(dyn(
|
|
257
|
+
e.io.await(IO_file.close(fd), e.io);
|
|
258
|
+
e.exn.throw(dyn(IoError.from_errno(i32(0) - n)));
|
|
264
259
|
},
|
|
265
260
|
(n == i32(0)) => {
|
|
266
261
|
break;
|
|
@@ -297,11 +292,11 @@ read_dir :: (fn(path : Path, using(io : IO)) -> Impl(Future(ArrayList(DirEntry),
|
|
|
297
292
|
);
|
|
298
293
|
});
|
|
299
294
|
free(.Some(*(void)(buf)));
|
|
300
|
-
io.await(IO_file.close(fd));
|
|
295
|
+
e.io.await(IO_file.close(fd), e.io);
|
|
301
296
|
entries
|
|
302
297
|
})
|
|
303
298
|
);
|
|
304
|
-
read_dir_str :: (fn(path : str,
|
|
299
|
+
read_dir_str :: (fn(path : str, io : Io) -> Impl(Future(ArrayList(DirEntry), IoExn)))(read_dir(Path.new(String.from(path)), io));
|
|
305
300
|
export(
|
|
306
301
|
create_dir,
|
|
307
302
|
create_dir_str,
|