@shd101wyy/yo 0.1.26 → 0.1.27
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 +4 -4
- package/.github/skills/yo-async-effects/async-effects-recipes.md +34 -34
- package/.github/skills/yo-core-patterns/SKILL.md +1 -1
- package/.github/skills/yo-core-patterns/core-patterns-cheatsheet.md +26 -26
- package/.github/skills/yo-project-workflow/SKILL.md +6 -3
- package/.github/skills/yo-project-workflow/workflow-cheatsheet.md +34 -11
- package/.github/skills/yo-syntax/SKILL.md +7 -6
- package/.github/skills/yo-syntax/syntax-cheatsheet.md +73 -60
- package/.github/skills/yo-wasm-integration/wasm-integration-cheatsheet.md +3 -3
- package/README.md +10 -8
- package/out/cjs/index.cjs +456 -438
- package/out/cjs/yo-cli.cjs +576 -543
- package/out/cjs/yo-lsp.cjs +559 -532
- package/out/esm/index.mjs +281 -263
- package/out/types/src/formatter.d.ts +11 -0
- package/out/types/src/lsp/formatting.d.ts +2 -0
- package/out/types/src/tests/formatter.test.d.ts +1 -0
- package/out/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/std/alg/hash.yo +13 -21
- package/std/allocator.yo +25 -40
- package/std/async.yo +3 -7
- package/std/build.yo +105 -151
- package/std/cli/arg_parser.yo +184 -169
- package/std/collections/array_list.yo +350 -314
- package/std/collections/btree_map.yo +142 -131
- package/std/collections/deque.yo +132 -128
- package/std/collections/hash_map.yo +542 -566
- package/std/collections/hash_set.yo +623 -687
- package/std/collections/linked_list.yo +275 -293
- package/std/collections/ordered_map.yo +113 -85
- package/std/collections/priority_queue.yo +73 -73
- package/std/crypto/md5.yo +191 -95
- package/std/crypto/random.yo +56 -64
- package/std/crypto/sha256.yo +151 -107
- package/std/encoding/base64.yo +87 -81
- package/std/encoding/hex.yo +43 -50
- package/std/encoding/html.yo +56 -81
- package/std/encoding/html_char_utils.yo +7 -13
- package/std/encoding/html_entities.yo +2248 -2253
- package/std/encoding/json.yo +316 -224
- package/std/encoding/punycode.yo +86 -116
- package/std/encoding/toml.yo +67 -66
- package/std/encoding/utf16.yo +37 -44
- package/std/env.yo +62 -91
- package/std/error.yo +7 -15
- package/std/fmt/display.yo +5 -9
- package/std/fmt/index.yo +8 -14
- package/std/fmt/to_string.yo +330 -315
- package/std/fmt/writer.yo +58 -87
- package/std/fs/dir.yo +83 -102
- package/std/fs/file.yo +147 -180
- package/std/fs/metadata.yo +45 -78
- package/std/fs/temp.yo +55 -65
- package/std/fs/types.yo +27 -40
- package/std/fs/walker.yo +53 -68
- package/std/gc.yo +5 -8
- package/std/glob.yo +30 -43
- package/std/http/client.yo +107 -120
- package/std/http/http.yo +106 -96
- package/std/http/index.yo +4 -6
- package/std/imm/list.yo +88 -93
- package/std/imm/map.yo +528 -464
- package/std/imm/set.yo +52 -57
- package/std/imm/sorted_map.yo +340 -286
- package/std/imm/sorted_set.yo +57 -63
- package/std/imm/string.yo +404 -345
- package/std/imm/vec.yo +173 -181
- package/std/io/reader.yo +3 -6
- package/std/io/writer.yo +4 -8
- package/std/libc/assert.yo +5 -9
- package/std/libc/ctype.yo +32 -22
- package/std/libc/dirent.yo +26 -25
- package/std/libc/errno.yo +164 -90
- package/std/libc/fcntl.yo +52 -45
- package/std/libc/float.yo +66 -44
- package/std/libc/limits.yo +42 -33
- package/std/libc/math.yo +53 -82
- package/std/libc/signal.yo +72 -47
- package/std/libc/stdatomic.yo +217 -188
- package/std/libc/stdint.yo +5 -29
- package/std/libc/stdio.yo +5 -29
- package/std/libc/stdlib.yo +32 -39
- package/std/libc/string.yo +5 -23
- package/std/libc/sys/stat.yo +58 -56
- package/std/libc/time.yo +5 -19
- package/std/libc/unistd.yo +5 -20
- package/std/libc/wctype.yo +6 -9
- package/std/libc/windows.yo +26 -30
- package/std/log.yo +41 -55
- package/std/net/addr.yo +102 -97
- package/std/net/dns.yo +27 -28
- package/std/net/errors.yo +50 -49
- package/std/net/tcp.yo +113 -124
- package/std/net/udp.yo +55 -66
- package/std/os/env.yo +35 -33
- package/std/os/signal.yo +15 -25
- package/std/path.yo +276 -311
- package/std/prelude.yo +6304 -4315
- package/std/process/command.yo +87 -103
- package/std/process/index.yo +12 -31
- package/std/regex/compiler.yo +196 -95
- package/std/regex/flags.yo +58 -39
- package/std/regex/index.yo +157 -173
- package/std/regex/match.yo +20 -31
- package/std/regex/node.yo +134 -152
- package/std/regex/parser.yo +283 -259
- package/std/regex/unicode.yo +172 -202
- package/std/regex/vm.yo +155 -171
- package/std/string/index.yo +5 -7
- package/std/string/rune.yo +45 -55
- package/std/string/string.yo +937 -964
- package/std/string/string_builder.yo +94 -104
- package/std/string/unicode.yo +46 -64
- package/std/sync/channel.yo +72 -73
- package/std/sync/cond.yo +31 -36
- package/std/sync/mutex.yo +30 -32
- package/std/sync/once.yo +13 -16
- package/std/sync/rwlock.yo +26 -31
- package/std/sync/waitgroup.yo +20 -25
- package/std/sys/advise.yo +16 -24
- package/std/sys/bufio/buf_reader.yo +77 -93
- package/std/sys/bufio/buf_writer.yo +52 -65
- package/std/sys/clock.yo +4 -9
- package/std/sys/constants.yo +77 -61
- package/std/sys/copy.yo +4 -10
- package/std/sys/dir.yo +26 -43
- package/std/sys/dns.yo +41 -61
- package/std/sys/errors.yo +95 -103
- package/std/sys/events.yo +45 -57
- package/std/sys/externs.yo +319 -267
- package/std/sys/fallocate.yo +7 -11
- package/std/sys/fcntl.yo +14 -22
- package/std/sys/file.yo +26 -40
- package/std/sys/future.yo +5 -8
- package/std/sys/iov.yo +12 -25
- package/std/sys/lock.yo +12 -13
- package/std/sys/mmap.yo +38 -43
- package/std/sys/path.yo +3 -8
- package/std/sys/perm.yo +7 -21
- package/std/sys/pipe.yo +5 -12
- package/std/sys/process.yo +23 -29
- package/std/sys/seek.yo +10 -12
- package/std/sys/signal.yo +7 -13
- package/std/sys/signals.yo +52 -35
- package/std/sys/socket.yo +63 -58
- package/std/sys/socketpair.yo +3 -6
- package/std/sys/sockinfo.yo +11 -20
- package/std/sys/statfs.yo +11 -34
- package/std/sys/statx.yo +25 -52
- package/std/sys/sysinfo.yo +15 -20
- package/std/sys/tcp.yo +62 -92
- package/std/sys/temp.yo +5 -9
- package/std/sys/time.yo +5 -15
- package/std/sys/timer.yo +6 -11
- package/std/sys/tty.yo +10 -18
- package/std/sys/udp.yo +22 -39
- package/std/sys/umask.yo +3 -6
- package/std/sys/unix.yo +33 -52
- package/std/testing/bench.yo +49 -52
- package/std/thread.yo +10 -15
- package/std/time/datetime.yo +105 -89
- package/std/time/duration.yo +43 -56
- package/std/time/instant.yo +13 -18
- package/std/time/sleep.yo +5 -9
- package/std/url/index.yo +184 -209
- package/std/worker.yo +6 -10
package/std/process/command.yo
CHANGED
|
@@ -23,21 +23,18 @@
|
|
|
23
23
|
//! assert(out.status.success(), "echo should succeed");
|
|
24
24
|
//! });
|
|
25
25
|
//! ```
|
|
26
|
-
|
|
27
|
-
open
|
|
28
|
-
|
|
29
|
-
{
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
{ GlobalAllocator } :: import "../allocator";
|
|
26
|
+
open(import("../collections/array_list"));
|
|
27
|
+
open(import("../string"));
|
|
28
|
+
{ Exception } :: import("../error");
|
|
29
|
+
{ IOError } :: import("../sys/errors");
|
|
30
|
+
IO_process :: import("../sys/process");
|
|
31
|
+
IO_file :: import("../sys/file");
|
|
32
|
+
IO_pipe :: import("../sys/pipe");
|
|
33
|
+
{ GlobalAllocator } :: import("../allocator");
|
|
35
34
|
{ malloc, free } :: GlobalAllocator;
|
|
36
|
-
|
|
37
35
|
// ============================================================================
|
|
38
36
|
// ExitStatus
|
|
39
37
|
// ============================================================================
|
|
40
|
-
|
|
41
38
|
/// The result of a finished child process.
|
|
42
39
|
///
|
|
43
40
|
/// Holds the raw waitpid status code along with helpers to extract the exit
|
|
@@ -47,30 +44,26 @@ ExitStatus :: struct(
|
|
|
47
44
|
/// reading this directly when possible.
|
|
48
45
|
raw : i32
|
|
49
46
|
);
|
|
50
|
-
|
|
51
|
-
|
|
47
|
+
impl(
|
|
48
|
+
ExitStatus,
|
|
52
49
|
/// Returns the process exit code (0..255 on Unix). Returns 0 when the
|
|
53
50
|
/// process was terminated by a signal.
|
|
54
|
-
code : (fn(self: Self) -> i32)(
|
|
51
|
+
code : (fn(self : Self) -> i32)(
|
|
55
52
|
IO_process.exit_status(self.raw)
|
|
56
53
|
),
|
|
57
|
-
|
|
58
54
|
/// Returns the signal number that terminated the process, or 0 if the
|
|
59
55
|
/// process exited normally.
|
|
60
|
-
signal : (fn(self: Self) -> i32)(
|
|
56
|
+
signal : (fn(self : Self) -> i32)(
|
|
61
57
|
IO_process.term_signal(self.raw)
|
|
62
58
|
),
|
|
63
|
-
|
|
64
59
|
/// Returns true if the child exited with status code 0.
|
|
65
|
-
success : (fn(self: Self) -> bool)(
|
|
66
|
-
(
|
|
60
|
+
success : (fn(self : Self) -> bool)(
|
|
61
|
+
(IO_process.exit_status(self.raw) == i32(0)) && (IO_process.term_signal(self.raw) == i32(0))
|
|
67
62
|
)
|
|
68
63
|
);
|
|
69
|
-
|
|
70
64
|
// ============================================================================
|
|
71
65
|
// Output
|
|
72
66
|
// ============================================================================
|
|
73
|
-
|
|
74
67
|
/// Captured output of a child process.
|
|
75
68
|
///
|
|
76
69
|
/// Returned by `Command.output`. Holds the exit status plus the bytes captured
|
|
@@ -80,185 +73,184 @@ Output :: object(
|
|
|
80
73
|
stdout : ArrayList(u8),
|
|
81
74
|
stderr : ArrayList(u8)
|
|
82
75
|
);
|
|
83
|
-
|
|
84
76
|
// ============================================================================
|
|
85
77
|
// Command
|
|
86
78
|
// ============================================================================
|
|
87
|
-
|
|
88
79
|
/// Builder for a child-process invocation.
|
|
89
80
|
///
|
|
90
81
|
/// Construct with `Command.new(program)`, then chain mutating builder methods
|
|
91
82
|
/// (`arg`, `args`, `env_clear`) before invoking `status()` or `output()`.
|
|
92
83
|
Command :: object(
|
|
93
84
|
_program : String,
|
|
94
|
-
_args
|
|
95
|
-
_stdin_fd
|
|
85
|
+
_args : ArrayList(String),
|
|
86
|
+
_stdin_fd : i32,
|
|
96
87
|
_stdout_fd : i32,
|
|
97
88
|
_stderr_fd : i32
|
|
98
89
|
);
|
|
99
|
-
|
|
100
|
-
|
|
90
|
+
impl(
|
|
91
|
+
Command,
|
|
101
92
|
/// Create a new `Command` invoking `program`. The program name is also used
|
|
102
93
|
/// as `argv[0]` unless a different first arg is pushed manually before
|
|
103
94
|
/// invocation.
|
|
104
|
-
new : (fn(program: String) -> Self)(
|
|
95
|
+
new : (fn(program : String) -> Self)(
|
|
105
96
|
Self(
|
|
106
|
-
_program: program,
|
|
107
|
-
_args: ArrayList(String).new(),
|
|
108
|
-
_stdin_fd: i32(-1),
|
|
109
|
-
_stdout_fd: i32(-1),
|
|
110
|
-
_stderr_fd: i32(-1)
|
|
97
|
+
_program : program,
|
|
98
|
+
_args : ArrayList(String).new(),
|
|
99
|
+
_stdin_fd : i32(-(1)),
|
|
100
|
+
_stdout_fd : i32(-(1)),
|
|
101
|
+
_stderr_fd : i32(-(1))
|
|
111
102
|
)
|
|
112
103
|
),
|
|
113
|
-
|
|
114
104
|
/// Append a single argument to the argv list.
|
|
115
|
-
arg : (fn(self: *(Self), a: String) -> unit)({
|
|
105
|
+
arg : (fn(self : *(Self), a : String) -> unit)({
|
|
116
106
|
self._args.push(a);
|
|
117
107
|
()
|
|
118
108
|
}),
|
|
119
|
-
|
|
120
109
|
/// Append multiple arguments to the argv list.
|
|
121
|
-
args : (fn(self: *(Self), more: ArrayList(String)) -> unit)({
|
|
110
|
+
args : (fn(self : *(Self), more : ArrayList(String)) -> unit)({
|
|
122
111
|
n := more.len();
|
|
123
112
|
i := usize(0);
|
|
124
|
-
while
|
|
125
|
-
match(
|
|
126
|
-
.
|
|
113
|
+
while(runtime(i < n), {
|
|
114
|
+
match(
|
|
115
|
+
more.get(i),
|
|
116
|
+
.Some(s) => {
|
|
117
|
+
self._args.push(s);
|
|
118
|
+
},
|
|
127
119
|
.None => ()
|
|
128
120
|
);
|
|
129
121
|
i = (i + usize(1));
|
|
130
|
-
};
|
|
122
|
+
});
|
|
131
123
|
})
|
|
132
124
|
);
|
|
133
|
-
|
|
134
125
|
// ============================================================================
|
|
135
126
|
// Internal helpers
|
|
136
127
|
// ============================================================================
|
|
137
|
-
|
|
138
128
|
// Convert each entry of `(program + args)` into an owned NUL-terminated
|
|
139
129
|
// `ArrayList(u8)`. The returned list owns the C-string storage; callers
|
|
140
130
|
// extract the raw `*(u8)` pointers separately.
|
|
141
|
-
_build_cstr_storage :: (fn(self: *(Command)) -> ArrayList(ArrayList(u8)))({
|
|
131
|
+
_build_cstr_storage :: (fn(self : *(Command)) -> ArrayList(ArrayList(u8)))({
|
|
142
132
|
storage := ArrayList(ArrayList(u8)).new();
|
|
143
133
|
storage.push(self._program.to_cstr());
|
|
144
134
|
n := self._args.len();
|
|
145
135
|
i := usize(0);
|
|
146
|
-
while
|
|
147
|
-
match(
|
|
148
|
-
.
|
|
136
|
+
while(runtime(i < n), {
|
|
137
|
+
match(
|
|
138
|
+
self._args.get(i),
|
|
139
|
+
.Some(s) => {
|
|
140
|
+
storage.push(s.to_cstr());
|
|
141
|
+
},
|
|
149
142
|
.None => ()
|
|
150
143
|
);
|
|
151
144
|
i = (i + usize(1));
|
|
152
|
-
};
|
|
153
|
-
return
|
|
145
|
+
});
|
|
146
|
+
return(storage);
|
|
154
147
|
});
|
|
155
|
-
|
|
156
148
|
// Spawn the child with the given inherited/redirected fds and return the pid.
|
|
157
149
|
// Builds argv as a fixed `?*(u8)` array on the heap. Caller is responsible for
|
|
158
150
|
// freeing `argv_buf` AND keeping `storage` alive until after `__yo_async_spawn_start`
|
|
159
151
|
// returns the pid (since the kernel reads argv synchronously inside the syscall).
|
|
160
|
-
_spawn_with_fds :: (
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
152
|
+
_spawn_with_fds :: (
|
|
153
|
+
fn(
|
|
154
|
+
self : *(Command),
|
|
155
|
+
stdin_fd : i32,
|
|
156
|
+
stdout_fd : i32,
|
|
157
|
+
stderr_fd : i32,
|
|
158
|
+
using(io : IO, exn : Exception)
|
|
159
|
+
) -> Impl(Future(i32, IO, Exception))
|
|
160
|
+
)(
|
|
167
161
|
io.async((using(io, exn)) => {
|
|
168
162
|
storage := _build_cstr_storage(self);
|
|
169
163
|
argc := storage.len();
|
|
170
|
-
|
|
171
164
|
// Allocate argv buffer: argc entries + 1 null terminator.
|
|
172
165
|
argv_bytes := (sizeof(?*(u8)) * (argc + usize(1)));
|
|
173
166
|
argv_raw := malloc(argv_bytes).unwrap();
|
|
174
167
|
argv_buf := *(?*(u8))(argv_raw);
|
|
175
|
-
|
|
176
168
|
// Fill argv pointers from each owning ArrayList(u8) in storage.
|
|
177
169
|
j := usize(0);
|
|
178
|
-
while
|
|
179
|
-
match(
|
|
180
|
-
.
|
|
181
|
-
|
|
182
|
-
.
|
|
170
|
+
while(runtime(j < argc), {
|
|
171
|
+
match(
|
|
172
|
+
storage.get(j),
|
|
173
|
+
.Some(cs) => match(
|
|
174
|
+
cs.ptr(),
|
|
175
|
+
.Some(p) => {
|
|
176
|
+
(argv_buf &+ j).* =.Some(p);
|
|
177
|
+
},
|
|
178
|
+
.None => {
|
|
179
|
+
(argv_buf &+ j).* =.None;
|
|
180
|
+
}
|
|
183
181
|
),
|
|
184
|
-
.None => {
|
|
182
|
+
.None => {
|
|
183
|
+
(argv_buf &+ j).* =.None;
|
|
184
|
+
}
|
|
185
185
|
);
|
|
186
186
|
j = (j + usize(1));
|
|
187
|
-
};
|
|
188
|
-
(argv_buf &+ argc).*
|
|
189
|
-
|
|
187
|
+
});
|
|
188
|
+
(argv_buf &+ argc).* =.None;
|
|
190
189
|
// Resolve program path C string (always present — _build_cstr_storage pushes program first).
|
|
191
190
|
program_cstr := (argv_buf &+ usize(0)).*.unwrap();
|
|
192
|
-
|
|
193
|
-
pid := io.await(IO_process.spawn(program_cstr, argv_buf, .None, stdin_fd, stdout_fd, stderr_fd));
|
|
194
|
-
|
|
191
|
+
pid := io.await(IO_process.spawn(program_cstr, argv_buf,.None, stdin_fd, stdout_fd, stderr_fd));
|
|
195
192
|
// Free argv buffer (storage is dropped naturally at scope end).
|
|
196
193
|
free(.Some(argv_raw));
|
|
197
|
-
|
|
198
194
|
IOError.check(pid)
|
|
199
195
|
})
|
|
200
196
|
);
|
|
201
|
-
|
|
202
197
|
// Read all available bytes from `fd` into a freshly returned ArrayList(u8)
|
|
203
198
|
// until EOF (read returns 0).
|
|
204
|
-
_drain_fd :: (fn(fd: i32, using(io : IO, exn : Exception)) -> Impl(Future(ArrayList(u8), IO, Exception)))(
|
|
199
|
+
_drain_fd :: (fn(fd : i32, using(io : IO, exn : Exception)) -> Impl(Future(ArrayList(u8), IO, Exception)))(
|
|
205
200
|
io.async((using(io, exn)) => {
|
|
206
201
|
buf_size := usize(4096);
|
|
207
202
|
buf := *(u8)(malloc(buf_size).unwrap());
|
|
208
203
|
out := ArrayList(u8).new();
|
|
209
|
-
while
|
|
204
|
+
while(runtime(true), {
|
|
210
205
|
n := io.await(IO_file.read(fd, buf, u32(buf_size), u64(0)));
|
|
211
206
|
cond(
|
|
212
207
|
(n < i32(0)) => {
|
|
213
208
|
free(.Some(*(void)(buf)));
|
|
214
|
-
exn.throw(dyn
|
|
209
|
+
exn.throw(dyn(IOError.from_errno(i32(0) - n)));
|
|
215
210
|
},
|
|
216
211
|
(n == i32(0)) => break,
|
|
217
212
|
true => {
|
|
218
213
|
k := usize(0);
|
|
219
|
-
while
|
|
214
|
+
while(runtime(k < usize(n)), {
|
|
220
215
|
out.push((buf &+ k).*);
|
|
221
216
|
k = (k + usize(1));
|
|
222
|
-
};
|
|
217
|
+
});
|
|
223
218
|
}
|
|
224
219
|
);
|
|
225
|
-
};
|
|
220
|
+
});
|
|
226
221
|
free(.Some(*(void)(buf)));
|
|
227
222
|
out
|
|
228
223
|
})
|
|
229
224
|
);
|
|
230
|
-
|
|
231
225
|
// ============================================================================
|
|
232
226
|
// Public Command methods (status / output)
|
|
233
227
|
// ============================================================================
|
|
234
|
-
|
|
235
|
-
|
|
228
|
+
impl(
|
|
229
|
+
Command,
|
|
236
230
|
/// Spawn the child with stdio inherited from the parent, wait for it to
|
|
237
231
|
/// exit, and return its `ExitStatus`.
|
|
238
|
-
status : (fn(self: *(Self), using(io : IO)) -> Impl(Future(ExitStatus, IO, Exception)))(
|
|
232
|
+
status : (fn(self : *(Self), using(io : IO)) -> Impl(Future(ExitStatus, IO, Exception)))(
|
|
239
233
|
io.async((using(io, exn)) => {
|
|
240
|
-
pid := io.await(_spawn_with_fds(self, i32(-1), i32(-1), i32(-1)));
|
|
234
|
+
pid := io.await(_spawn_with_fds(self, i32(-(1)), i32(-(1)), i32(-(1))));
|
|
241
235
|
raw := io.await(IO_process.waitpid(pid, i32(0)));
|
|
242
236
|
IOError.check(raw);
|
|
243
|
-
ExitStatus(raw: raw)
|
|
237
|
+
ExitStatus(raw : raw)
|
|
244
238
|
})
|
|
245
239
|
),
|
|
246
|
-
|
|
247
240
|
/// Spawn the child with stdout and stderr captured through pipes. Waits for
|
|
248
241
|
/// 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)))(
|
|
242
|
+
output : (fn(self : *(Self), using(io : IO)) -> Impl(Future(Output, IO, Exception)))(
|
|
250
243
|
io.async((using(io, exn)) => {
|
|
251
244
|
// Create stdout and stderr pipes.
|
|
252
245
|
out_fd_buf := MaybeUninit(Array(i32, usize(2))).new();
|
|
253
246
|
out_fd := *(i32)(out_fd_buf.as_ptr());
|
|
254
247
|
pr1 := IO_pipe.pipe(out_fd);
|
|
255
248
|
cond(
|
|
256
|
-
(pr1 < i32(0)) => exn.throw(dyn
|
|
249
|
+
(pr1 < i32(0)) => exn.throw(dyn(IOError.from_errno(i32(0) - pr1))),
|
|
257
250
|
true => ()
|
|
258
251
|
);
|
|
259
252
|
out_read := (out_fd &+ usize(0)).*;
|
|
260
253
|
out_write := (out_fd &+ usize(1)).*;
|
|
261
|
-
|
|
262
254
|
err_fd_buf := MaybeUninit(Array(i32, usize(2))).new();
|
|
263
255
|
err_fd := *(i32)(err_fd_buf.as_ptr());
|
|
264
256
|
pr2 := IO_pipe.pipe(err_fd);
|
|
@@ -266,38 +258,30 @@ impl(Command,
|
|
|
266
258
|
(pr2 < i32(0)) => {
|
|
267
259
|
io.await(IO_file.close(out_read));
|
|
268
260
|
io.await(IO_file.close(out_write));
|
|
269
|
-
exn.throw(dyn
|
|
261
|
+
exn.throw(dyn(IOError.from_errno(i32(0) - pr2)));
|
|
270
262
|
},
|
|
271
263
|
true => ()
|
|
272
264
|
);
|
|
273
265
|
err_read := (err_fd &+ usize(0)).*;
|
|
274
266
|
err_write := (err_fd &+ usize(1)).*;
|
|
275
|
-
|
|
276
267
|
// Spawn child with the write ends of both pipes.
|
|
277
|
-
pid := io.await(_spawn_with_fds(self, i32(-1), out_write, err_write));
|
|
278
|
-
|
|
268
|
+
pid := io.await(_spawn_with_fds(self, i32(-(1)), out_write, err_write));
|
|
279
269
|
// Close write ends in parent so reads see EOF when child exits.
|
|
280
270
|
io.await(IO_file.close(out_write));
|
|
281
271
|
io.await(IO_file.close(err_write));
|
|
282
|
-
|
|
283
272
|
// Drain both pipes sequentially.
|
|
284
273
|
stdout_buf := io.await(_drain_fd(out_read));
|
|
285
274
|
stderr_buf := io.await(_drain_fd(err_read));
|
|
286
|
-
|
|
287
275
|
io.await(IO_file.close(out_read));
|
|
288
276
|
io.await(IO_file.close(err_read));
|
|
289
|
-
|
|
290
277
|
raw := io.await(IO_process.waitpid(pid, i32(0)));
|
|
291
278
|
IOError.check(raw);
|
|
292
279
|
Output(
|
|
293
|
-
status: ExitStatus(raw: raw),
|
|
294
|
-
stdout: stdout_buf,
|
|
295
|
-
stderr: stderr_buf
|
|
280
|
+
status : ExitStatus(raw : raw),
|
|
281
|
+
stdout : stdout_buf,
|
|
282
|
+
stderr : stderr_buf
|
|
296
283
|
)
|
|
297
284
|
})
|
|
298
285
|
)
|
|
299
286
|
);
|
|
300
|
-
|
|
301
|
-
export
|
|
302
|
-
Command, ExitStatus, Output
|
|
303
|
-
;
|
|
287
|
+
export(Command, ExitStatus, Output);
|
package/std/process/index.yo
CHANGED
|
@@ -2,44 +2,25 @@
|
|
|
2
2
|
//!
|
|
3
3
|
//! Environment variables, command-line arguments, and current working
|
|
4
4
|
//! directory live in `std/env`.
|
|
5
|
-
|
|
6
5
|
/// Current target platform as a compile-time string.
|
|
7
6
|
/// One of: "linux", "macos", "windows", "freebsd", "emscripten", "wasi".
|
|
8
7
|
platform :: __yo_process_platform();
|
|
9
|
-
export
|
|
10
|
-
|
|
8
|
+
export(platform);
|
|
11
9
|
/// Platform constants for compile-time platform comparisons.
|
|
12
|
-
Platform :: {
|
|
13
|
-
|
|
14
|
-
Macos : "macos",
|
|
15
|
-
Windows : "windows",
|
|
16
|
-
FreeBSD : "freebsd",
|
|
17
|
-
Emscripten : "emscripten",
|
|
18
|
-
Wasi : "wasi"
|
|
19
|
-
};
|
|
20
|
-
export Platform;
|
|
21
|
-
|
|
10
|
+
Platform :: { Linux : "linux", Macos : "macos", Windows : "windows", FreeBSD : "freebsd", Emscripten : "emscripten", Wasi : "wasi" };
|
|
11
|
+
export(Platform);
|
|
22
12
|
/// Current target architecture as a compile-time string.
|
|
23
13
|
/// One of: "x86_64", "aarch64", "x86", "arm", "wasm32".
|
|
24
14
|
arch :: __yo_process_arch();
|
|
25
|
-
export
|
|
26
|
-
|
|
15
|
+
export(arch);
|
|
27
16
|
/// Architecture constants for compile-time architecture comparisons.
|
|
28
|
-
Arch :: {
|
|
29
|
-
|
|
30
|
-
Aarch64 : "aarch64",
|
|
31
|
-
X86 : "x86",
|
|
32
|
-
Arm : "arm",
|
|
33
|
-
Wasm32 : "wasm32"
|
|
34
|
-
};
|
|
35
|
-
export Arch;
|
|
36
|
-
|
|
17
|
+
Arch :: { X86_64 : "x86_64", Aarch64 : "aarch64", X86 : "x86", Arm : "arm", Wasm32 : "wasm32" };
|
|
18
|
+
export(Arch);
|
|
37
19
|
/// Exit the process with the given status code.
|
|
38
|
-
exit :: (fn(code : usize) -> unit)
|
|
39
|
-
{ exit : _exit } :: import
|
|
20
|
+
exit :: (fn(code : usize) -> unit)({
|
|
21
|
+
{ exit : _exit } :: import("../libc/stdlib");
|
|
40
22
|
_exit(int(code));
|
|
41
|
-
};
|
|
42
|
-
export
|
|
43
|
-
|
|
44
|
-
_command
|
|
45
|
-
export ...(_command);
|
|
23
|
+
});
|
|
24
|
+
export(exit);
|
|
25
|
+
_command :: import("./command.yo");
|
|
26
|
+
export(...(_command));
|