@shd101wyy/yo 0.1.12 → 0.1.13
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/README.md +10 -1
- package/out/cjs/index.cjs +578 -572
- package/out/cjs/yo-cli.cjs +1413 -592
- package/out/esm/index.mjs +434 -428
- package/out/types/src/build-runner.d.ts +1 -1
- package/out/types/src/doc/builder.d.ts +21 -0
- package/out/types/src/doc/builder.test.d.ts +1 -0
- package/out/types/src/doc/extractor.d.ts +27 -0
- package/out/types/src/doc/extractor.test.d.ts +1 -0
- package/out/types/src/doc/model.d.ts +87 -0
- package/out/types/src/doc/render-html.d.ts +23 -0
- package/out/types/src/doc/render-html.test.d.ts +1 -0
- package/out/types/src/doc/render-json.d.ts +7 -0
- package/out/types/src/doc/render-json.test.d.ts +1 -0
- package/out/types/src/doc/render-markdown.d.ts +13 -0
- package/out/types/src/doc/render-markdown.test.d.ts +1 -0
- package/out/types/src/doc/sections.d.ts +7 -0
- package/out/types/src/doc/sections.test.d.ts +1 -0
- package/out/types/src/doc-command.d.ts +10 -0
- package/out/types/src/env.d.ts +1 -0
- package/out/types/src/evaluator/builtins/build.d.ts +17 -0
- package/out/types/src/evaluator/context.d.ts +1 -0
- package/out/types/src/expr.d.ts +2 -1
- package/out/types/src/token.d.ts +4 -0
- package/out/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +2 -1
- package/scripts/build-site.ts +461 -0
- package/std/alg/hash.yo +12 -24
- package/std/allocator.yo +21 -29
- package/std/async.yo +4 -2
- package/std/build.yo +188 -42
- package/std/cli/arg_parser.yo +37 -1
- package/std/collections/array_list.yo +8 -20
- package/std/collections/btree_map.yo +15 -20
- package/std/collections/deque.yo +13 -15
- package/std/collections/hash_map.yo +15 -54
- package/std/collections/hash_set.yo +14 -50
- package/std/collections/linked_list.yo +6 -23
- package/std/collections/priority_queue.yo +15 -17
- package/std/crypto/md5.yo +10 -9
- package/std/crypto/random.yo +14 -12
- package/std/crypto/sha256.yo +9 -8
- package/std/encoding/base64.yo +13 -15
- package/std/encoding/hex.yo +14 -10
- package/std/encoding/html.yo +14 -11
- package/std/encoding/html_char_utils.yo +14 -11
- package/std/encoding/html_entities.yo +7 -8
- package/std/encoding/json.yo +36 -19
- package/std/encoding/punycode.yo +21 -18
- package/std/encoding/toml.yo +23 -9
- package/std/encoding/utf16.yo +16 -9
- package/std/error.yo +10 -23
- package/std/fmt/display.yo +15 -17
- package/std/fmt/index.yo +6 -27
- package/std/fmt/to_string.yo +4 -10
- package/std/fmt/writer.yo +33 -34
- package/std/fs/dir.yo +37 -30
- package/std/fs/file.yo +77 -75
- package/std/fs/metadata.yo +25 -25
- package/std/fs/temp.yo +21 -27
- package/std/fs/types.yo +20 -23
- package/std/fs/walker.yo +26 -31
- package/std/gc.yo +5 -0
- package/std/glob/index.yo +3 -0
- package/std/http/client.yo +25 -11
- package/std/http/http.yo +20 -0
- package/std/http/index.yo +1 -0
- package/std/io/reader.yo +4 -8
- package/std/io/writer.yo +4 -7
- package/std/libc/assert.yo +2 -2
- package/std/libc/ctype.yo +1 -2
- package/std/libc/dirent.yo +1 -2
- package/std/libc/errno.yo +1 -2
- package/std/libc/fcntl.yo +2 -2
- package/std/libc/float.yo +1 -2
- package/std/libc/limits.yo +1 -2
- package/std/libc/math.yo +2 -0
- package/std/libc/signal.yo +1 -2
- package/std/libc/stdatomic.yo +1 -2
- package/std/libc/stdint.yo +4 -3
- package/std/libc/stdio.yo +2 -0
- package/std/libc/stdlib.yo +2 -0
- package/std/libc/string.yo +2 -0
- package/std/libc/sys/stat.yo +1 -2
- package/std/libc/time.yo +2 -2
- package/std/libc/unistd.yo +2 -0
- package/std/libc/wctype.yo +1 -2
- package/std/libc/windows.yo +2 -2
- package/std/log/index.yo +11 -26
- package/std/net/addr.yo +18 -11
- package/std/net/dns.yo +3 -2
- package/std/net/errors.yo +16 -2
- package/std/net/tcp.yo +25 -22
- package/std/net/udp.yo +14 -12
- package/std/os/env.yo +23 -18
- package/std/os/signal.yo +31 -19
- package/std/path.yo +23 -74
- package/std/prelude.yo +284 -113
- package/std/process.yo +23 -37
- package/std/regex/compiler.yo +3 -5
- package/std/regex/flags.yo +11 -11
- package/std/regex/index.yo +2 -13
- package/std/regex/match.yo +3 -5
- package/std/regex/node.yo +6 -6
- package/std/regex/parser.yo +2 -4
- package/std/regex/unicode.yo +5 -5
- package/std/regex/vm.yo +5 -5
- package/std/string/index.yo +2 -1
- package/std/string/rune.yo +25 -1
- package/std/string/string.yo +31 -19
- package/std/string/unicode.yo +14 -15
- package/std/sync/channel.yo +18 -28
- package/std/sync/cond.yo +4 -0
- package/std/sync/mutex.yo +4 -1
- package/std/sync/once.yo +17 -19
- package/std/sync/rwlock.yo +19 -22
- package/std/sync/waitgroup.yo +21 -23
- package/std/sys/advise.yo +4 -4
- package/std/sys/bufio/buf_reader.yo +19 -16
- package/std/sys/bufio/buf_writer.yo +14 -11
- package/std/sys/clock.yo +4 -4
- package/std/sys/constants.yo +5 -5
- package/std/sys/copy.yo +9 -8
- package/std/sys/dir.yo +9 -8
- package/std/sys/dns.yo +8 -8
- package/std/sys/errors.yo +35 -6
- package/std/sys/events.yo +3 -3
- package/std/sys/externs.yo +3 -3
- package/std/sys/fallocate.yo +4 -4
- package/std/sys/fcntl.yo +8 -6
- package/std/sys/file.yo +7 -8
- package/std/sys/future.yo +1 -3
- package/std/sys/iov.yo +4 -4
- package/std/sys/lock.yo +7 -7
- package/std/sys/mmap.yo +7 -8
- package/std/sys/path.yo +4 -7
- package/std/sys/perm.yo +8 -8
- package/std/sys/pipe.yo +9 -8
- package/std/sys/process.yo +8 -8
- package/std/sys/seek.yo +4 -4
- package/std/sys/signal.yo +4 -4
- package/std/sys/signals.yo +4 -4
- package/std/sys/socket.yo +4 -4
- package/std/sys/socketpair.yo +4 -4
- package/std/sys/sockinfo.yo +4 -4
- package/std/sys/statfs.yo +8 -8
- package/std/sys/statx.yo +4 -4
- package/std/sys/sysinfo.yo +4 -4
- package/std/sys/tcp.yo +8 -8
- package/std/sys/temp.yo +9 -8
- package/std/sys/time.yo +8 -8
- package/std/sys/timer.yo +7 -8
- package/std/sys/tty.yo +13 -10
- package/std/sys/udp.yo +8 -8
- package/std/sys/umask.yo +4 -4
- package/std/sys/unix.yo +5 -5
- package/std/testing/bench.yo +21 -10
- package/std/thread.yo +18 -9
- package/std/time/datetime.yo +12 -14
- package/std/time/duration.yo +12 -14
- package/std/time/instant.yo +13 -16
- package/std/time/sleep.yo +9 -8
- package/std/url/index.yo +3 -19
- package/std/worker.yo +10 -18
package/std/fs/walker.yo
CHANGED
|
@@ -1,25 +1,26 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
1
|
+
//! Recursive directory traversal.
|
|
2
|
+
//!
|
|
3
|
+
//! # Example
|
|
4
|
+
//!
|
|
5
|
+
//! ```rust
|
|
6
|
+
//! { walk, WalkEntry } :: import "std/fs/walker";
|
|
7
|
+
//!
|
|
8
|
+
//! main :: (fn(using(io : IO)) -> unit)({
|
|
9
|
+
//! given(exn) : Exception = {
|
|
10
|
+
//! throw : (fn(forall(T : Type), error: AnyError) -> T)(
|
|
11
|
+
//! { println(error.to_string()); exit(i32(1)); }
|
|
12
|
+
//! )
|
|
13
|
+
//! };
|
|
14
|
+
//!
|
|
15
|
+
//! entries := io.await(walk(`/tmp`));
|
|
16
|
+
//! i := usize(0);
|
|
17
|
+
//! while runtime((i < entries.len())), {
|
|
18
|
+
//! e := entries.get(i).unwrap();
|
|
19
|
+
//! println(e.path);
|
|
20
|
+
//! i = (i + usize(1));
|
|
21
|
+
//! };
|
|
22
|
+
//! });
|
|
23
|
+
//! ```
|
|
23
24
|
|
|
24
25
|
{ ArrayList } :: import "../collections/array_list";
|
|
25
26
|
open import "../string";
|
|
@@ -30,10 +31,7 @@ open import "../string";
|
|
|
30
31
|
{ DirEntry } :: import "./dir";
|
|
31
32
|
_dir :: import "./dir";
|
|
32
33
|
|
|
33
|
-
|
|
34
|
-
// WalkEntry
|
|
35
|
-
// ============================================================================
|
|
36
|
-
|
|
34
|
+
/// Entry returned by the directory walker.
|
|
37
35
|
WalkEntry :: struct(
|
|
38
36
|
path : Path,
|
|
39
37
|
name : String,
|
|
@@ -43,10 +41,7 @@ WalkEntry :: struct(
|
|
|
43
41
|
|
|
44
42
|
export WalkEntry;
|
|
45
43
|
|
|
46
|
-
|
|
47
|
-
// WalkOptions
|
|
48
|
-
// ============================================================================
|
|
49
|
-
|
|
44
|
+
/// Options controlling directory walk behavior.
|
|
50
45
|
WalkOptions :: struct(
|
|
51
46
|
max_depth : ?(u32),
|
|
52
47
|
follow_symlinks : bool,
|
|
@@ -147,7 +142,7 @@ walk_with_cstr :: (fn(root: *(u8), options: WalkOptions, using(io : IO)) -> Impl
|
|
|
147
142
|
walk_with(Path.from_cstr(root), options)
|
|
148
143
|
);
|
|
149
144
|
|
|
150
|
-
|
|
145
|
+
/// Walk a directory tree with default options.
|
|
151
146
|
walk :: (fn(root: Path, using(io : IO)) -> Impl(Future(ArrayList(WalkEntry), IO, Exception)))
|
|
152
147
|
walk_with(root, WalkOptions.defaults())
|
|
153
148
|
;
|
package/std/gc.yo
CHANGED
|
@@ -1,9 +1,14 @@
|
|
|
1
|
+
//! Garbage collection interface for cycle collection.
|
|
2
|
+
|
|
1
3
|
extern "Yo",
|
|
2
4
|
__yo_gc_collect : (fn() -> unit),
|
|
3
5
|
__yo_gc_tracked_count : (fn() -> u64)
|
|
4
6
|
;
|
|
5
7
|
|
|
8
|
+
/// Trigger the cycle collector to reclaim reference cycles.
|
|
6
9
|
collect :: __yo_gc_collect;
|
|
10
|
+
|
|
11
|
+
/// Get the number of objects currently tracked by the cycle collector.
|
|
7
12
|
tracked_count :: __yo_gc_tracked_count;
|
|
8
13
|
|
|
9
14
|
export collect;
|
package/std/glob/index.yo
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
//! Glob pattern matching for file paths.
|
|
2
|
+
|
|
1
3
|
open import "../string";
|
|
2
4
|
{ ArrayList } :: import "../collections/array_list";
|
|
3
5
|
|
|
@@ -190,6 +192,7 @@ glob_match :: (fn(pattern: String, text: String) -> bool)(
|
|
|
190
192
|
_glob_match_impl(pattern.as_bytes(), usize(0), text.as_bytes(), usize(0))
|
|
191
193
|
);
|
|
192
194
|
|
|
195
|
+
/// Compiled glob pattern that can be matched against strings.
|
|
193
196
|
GlobPattern :: object(
|
|
194
197
|
_pattern : String
|
|
195
198
|
);
|
package/std/http/client.yo
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
//! Async HTTP client with high-level fetch API.
|
|
1
2
|
// std/http/client.yo - Async HTTP client using TCP
|
|
2
3
|
//
|
|
3
4
|
// Provides an async HTTP client and a high-level `fetch` function
|
|
@@ -35,13 +36,21 @@ open import "../fmt";
|
|
|
35
36
|
// HttpError
|
|
36
37
|
// ============================================================================
|
|
37
38
|
|
|
39
|
+
/// HTTP client error variants.
|
|
38
40
|
HttpError :: enum(
|
|
41
|
+
/// Failed to connect to the remote host.
|
|
39
42
|
ConnectionFailed(msg: String),
|
|
43
|
+
/// The URL could not be parsed.
|
|
40
44
|
InvalidUrl(msg: String),
|
|
45
|
+
/// The request timed out.
|
|
41
46
|
Timeout,
|
|
47
|
+
/// Too many HTTP redirects.
|
|
42
48
|
TooManyRedirects,
|
|
49
|
+
/// The URL scheme is not supported (only http/https).
|
|
43
50
|
UnsupportedScheme(scheme: String),
|
|
51
|
+
/// The response body exceeds the size limit.
|
|
44
52
|
ResponseTooLarge,
|
|
53
|
+
/// An unclassified HTTP error.
|
|
45
54
|
Other(msg: String)
|
|
46
55
|
);
|
|
47
56
|
|
|
@@ -67,6 +76,7 @@ export HttpError;
|
|
|
67
76
|
// FetchOptions
|
|
68
77
|
// ============================================================================
|
|
69
78
|
|
|
79
|
+
/// Options for configuring an HTTP request.
|
|
70
80
|
FetchOptions :: object(
|
|
71
81
|
method : HttpMethod,
|
|
72
82
|
headers : ArrayList(HttpHeader),
|
|
@@ -74,6 +84,7 @@ FetchOptions :: object(
|
|
|
74
84
|
);
|
|
75
85
|
|
|
76
86
|
impl(FetchOptions,
|
|
87
|
+
/// Create default options (GET, no headers, empty body).
|
|
77
88
|
new : (fn() -> Self)(
|
|
78
89
|
Self(
|
|
79
90
|
method: .GET,
|
|
@@ -82,16 +93,19 @@ impl(FetchOptions,
|
|
|
82
93
|
)
|
|
83
94
|
),
|
|
84
95
|
|
|
96
|
+
/// Set the HTTP method.
|
|
85
97
|
with_method : (fn(self: Self, method: HttpMethod) -> Self)({
|
|
86
98
|
self.method = method;
|
|
87
99
|
self
|
|
88
100
|
}),
|
|
89
101
|
|
|
102
|
+
/// Add a request header.
|
|
90
103
|
with_header : (fn(self: Self, name: String, value: String) -> Self)({
|
|
91
104
|
self.headers.push(HttpHeader.new(name, value));
|
|
92
105
|
self
|
|
93
106
|
}),
|
|
94
107
|
|
|
108
|
+
/// Set the request body.
|
|
95
109
|
with_body : (fn(self: Self, body: String) -> Self)({
|
|
96
110
|
self.body = body;
|
|
97
111
|
self
|
|
@@ -229,11 +243,11 @@ _read_http_response :: (fn(stream: TcpStream, using(io : IO, exn : Exception)) -
|
|
|
229
243
|
// fetch — High-level async HTTP request (like JavaScript's fetch)
|
|
230
244
|
// ============================================================================
|
|
231
245
|
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
246
|
+
/// Perform an HTTP request with custom options.
|
|
247
|
+
///
|
|
248
|
+
/// Example:
|
|
249
|
+
/// opts := FetchOptions.new().with_method(.POST).with_body(`{"key": "value"}`);
|
|
250
|
+
/// resp := io.await(fetch_with(`http://example.com/api`, opts, using(io)));
|
|
237
251
|
fetch_with :: (fn(url_str: String, opts: FetchOptions, using(io : IO)) ->
|
|
238
252
|
Impl(Future(HttpResponse, IO, Exception))
|
|
239
253
|
)(
|
|
@@ -342,12 +356,12 @@ fetch_with :: (fn(url_str: String, opts: FetchOptions, using(io : IO)) ->
|
|
|
342
356
|
|
|
343
357
|
export fetch_with;
|
|
344
358
|
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
359
|
+
/// Perform an HTTP GET request to the given URL string.
|
|
360
|
+
/// Returns the `HttpResponse` on success.
|
|
361
|
+
///
|
|
362
|
+
/// Example:
|
|
363
|
+
/// resp := io.await(fetch(`http://example.com`, using(io)));
|
|
364
|
+
/// cond(resp.is_ok() => println(resp.body), true => println(`Error`));
|
|
351
365
|
fetch :: (fn(url_str: String, using(io : IO)) ->
|
|
352
366
|
Impl(Future(HttpResponse, IO, Exception))
|
|
353
367
|
)(
|
package/std/http/http.yo
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
|
+
//! HTTP core types — methods, headers, requests, and responses.
|
|
1
2
|
// std/http/http.yo - HTTP types and request/response builders
|
|
2
3
|
|
|
3
4
|
open import "../string";
|
|
4
5
|
{ ArrayList } :: import "../collections/array_list";
|
|
5
6
|
{ ToString } :: import "../fmt";
|
|
6
7
|
|
|
8
|
+
/// Standard HTTP request methods.
|
|
7
9
|
HttpMethod :: enum(GET, POST, PUT, DELETE, HEAD, PATCH);
|
|
8
10
|
|
|
9
11
|
impl(HttpMethod, ToString(
|
|
@@ -19,14 +21,17 @@ impl(HttpMethod, ToString(
|
|
|
19
21
|
)
|
|
20
22
|
));
|
|
21
23
|
|
|
24
|
+
/// An HTTP header as a name-value pair.
|
|
22
25
|
HttpHeader :: object(name: String, value: String);
|
|
23
26
|
|
|
24
27
|
impl(HttpHeader,
|
|
28
|
+
/// Create a new header with the given name and value.
|
|
25
29
|
new : (fn(name: String, value: String) -> Self)(
|
|
26
30
|
Self(name: name, value: value)
|
|
27
31
|
)
|
|
28
32
|
);
|
|
29
33
|
|
|
34
|
+
/// An HTTP request with method, path, headers, and optional body.
|
|
30
35
|
HttpRequest :: object(
|
|
31
36
|
method: HttpMethod,
|
|
32
37
|
path: String,
|
|
@@ -35,32 +40,39 @@ HttpRequest :: object(
|
|
|
35
40
|
);
|
|
36
41
|
|
|
37
42
|
impl(HttpRequest,
|
|
43
|
+
/// Create a new request with the given method and path.
|
|
38
44
|
new : (fn(method: HttpMethod, path: String) -> Self)(
|
|
39
45
|
Self(method: method, path: path, headers: ArrayList(HttpHeader).new(), body: ``)
|
|
40
46
|
),
|
|
41
47
|
|
|
48
|
+
/// Add a header and return the request (builder pattern).
|
|
42
49
|
header : (fn(self: Self, name: String, value: String) -> Self)({
|
|
43
50
|
self.headers.push(HttpHeader.new(name, value));
|
|
44
51
|
self
|
|
45
52
|
}),
|
|
46
53
|
|
|
54
|
+
/// Set the request body and return the request (builder pattern).
|
|
47
55
|
with_body : (fn(self: Self, body: String) -> Self)({
|
|
48
56
|
self.body = body;
|
|
49
57
|
self
|
|
50
58
|
}),
|
|
51
59
|
|
|
60
|
+
/// Set the Host header.
|
|
52
61
|
set_host : (fn(self: Self, host: String) -> unit)({
|
|
53
62
|
self.headers.push(HttpHeader.new(`Host`, host));
|
|
54
63
|
}),
|
|
55
64
|
|
|
65
|
+
/// Append a header to the request.
|
|
56
66
|
set_header : (fn(self: Self, name: String, value: String) -> unit)({
|
|
57
67
|
self.headers.push(HttpHeader.new(name, value));
|
|
58
68
|
}),
|
|
59
69
|
|
|
70
|
+
/// Set the request body.
|
|
60
71
|
set_body : (fn(self: Self, body: String) -> unit)({
|
|
61
72
|
self.body = body;
|
|
62
73
|
}),
|
|
63
74
|
|
|
75
|
+
/// Serialize the request to an HTTP/1.1 wire-format string.
|
|
64
76
|
to_string : (fn(self: Self) -> String)({
|
|
65
77
|
result := `${self.method.to_string()} ${self.path} HTTP/1.1\r\n`;
|
|
66
78
|
i := usize(0);
|
|
@@ -77,6 +89,7 @@ impl(HttpRequest,
|
|
|
77
89
|
})
|
|
78
90
|
);
|
|
79
91
|
|
|
92
|
+
/// An HTTP response with status code, headers, and body.
|
|
80
93
|
HttpResponse :: object(
|
|
81
94
|
status_code: i32,
|
|
82
95
|
status_text: String,
|
|
@@ -85,10 +98,12 @@ HttpResponse :: object(
|
|
|
85
98
|
);
|
|
86
99
|
|
|
87
100
|
impl(HttpResponse,
|
|
101
|
+
/// Create a new response with the given status code and text.
|
|
88
102
|
new : (fn(status_code: i32, status_text: String) -> Self)(
|
|
89
103
|
Self(status_code: status_code, status_text: status_text, headers: ArrayList(HttpHeader).new(), body: ``)
|
|
90
104
|
),
|
|
91
105
|
|
|
106
|
+
/// Look up a header value by name (case-insensitive).
|
|
92
107
|
get_header : (fn(self: Self, name: String) -> Option(String))({
|
|
93
108
|
lower_name := name.to_lowercase();
|
|
94
109
|
i := usize(0);
|
|
@@ -99,19 +114,23 @@ impl(HttpResponse,
|
|
|
99
114
|
.None
|
|
100
115
|
}),
|
|
101
116
|
|
|
117
|
+
/// Return `true` if the status code is in the 2xx range.
|
|
102
118
|
is_ok : (fn(self: Self) -> bool)(
|
|
103
119
|
((self.status_code >= i32(200)) && (self.status_code < i32(300)))
|
|
104
120
|
),
|
|
105
121
|
|
|
122
|
+
/// Return `true` if the status code is in the 3xx range.
|
|
106
123
|
is_redirect : (fn(self: Self) -> bool)(
|
|
107
124
|
((self.status_code >= i32(300)) && (self.status_code < i32(400)))
|
|
108
125
|
),
|
|
109
126
|
|
|
127
|
+
/// Return `true` if the status code is 4xx or higher.
|
|
110
128
|
is_error : (fn(self: Self) -> bool)(
|
|
111
129
|
(self.status_code >= i32(400))
|
|
112
130
|
)
|
|
113
131
|
);
|
|
114
132
|
|
|
133
|
+
/// Parse a raw HTTP response string into an `HttpResponse`.
|
|
115
134
|
parse_response :: (fn(raw: String) -> Result(HttpResponse, String))({
|
|
116
135
|
lines := raw.split(`\r\n`);
|
|
117
136
|
cond((lines.len() == usize(0)) => { return .Err(`Empty response`); }, true => ());
|
|
@@ -174,6 +193,7 @@ parse_response :: (fn(raw: String) -> Result(HttpResponse, String))({
|
|
|
174
193
|
.Ok(resp)
|
|
175
194
|
});
|
|
176
195
|
|
|
196
|
+
/// Return the standard status text for an HTTP status code.
|
|
177
197
|
http_status_text :: (fn(code: i32) -> String)(
|
|
178
198
|
cond(
|
|
179
199
|
(code == i32(200)) => `OK`,
|
package/std/http/index.yo
CHANGED
package/std/io/reader.yo
CHANGED
|
@@ -1,15 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
//
|
|
3
|
-
// Provides a common interface for reading bytes from various sources
|
|
4
|
-
// (files, network streams, buffers, etc.)
|
|
1
|
+
//! Reader trait for byte-level input.
|
|
5
2
|
|
|
6
3
|
{ Exception } :: import "../error";
|
|
7
4
|
|
|
8
|
-
|
|
9
|
-
// Types implementing Reader provide `read` for reading into a buffer.
|
|
5
|
+
/// Common interface for reading bytes from various sources.
|
|
10
6
|
Reader :: trait(
|
|
11
|
-
|
|
12
|
-
|
|
7
|
+
/// Read up to `size` bytes into buffer `buf`.
|
|
8
|
+
/// Returns the number of bytes actually read (0 at end-of-stream).
|
|
13
9
|
read :
|
|
14
10
|
fn(self: *(Self), buf: *(u8), size: usize, using(exn : Exception)) -> usize
|
|
15
11
|
);
|
package/std/io/writer.yo
CHANGED
|
@@ -1,17 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
//
|
|
3
|
-
// Provides a common interface for writing bytes to various destinations
|
|
4
|
-
// (files, network streams, buffers, etc.)
|
|
1
|
+
//! Writer trait for byte-level output.
|
|
5
2
|
|
|
6
3
|
{ Exception } :: import "../error";
|
|
7
4
|
|
|
8
|
-
|
|
5
|
+
/// Common interface for writing bytes to a destination.
|
|
9
6
|
Writer :: trait(
|
|
10
|
-
|
|
7
|
+
/// Write bytes from buffer. Returns number of bytes written.
|
|
11
8
|
write :
|
|
12
9
|
fn(self: *(Self), buf: *(u8), size: usize, using(exn : Exception)) -> usize,
|
|
13
10
|
|
|
14
|
-
|
|
11
|
+
/// Flush any buffered data to the underlying destination.
|
|
15
12
|
flush :
|
|
16
13
|
fn(self: *(Self), using(exn : Exception)) -> unit
|
|
17
14
|
);
|
package/std/libc/assert.yo
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
//! C11 `<assert.h>` — assertion debugging facility.
|
|
2
|
+
//! Provides runtime assertion checking for debugging.
|
|
3
3
|
|
|
4
4
|
c_include "<assert.h>",
|
|
5
5
|
// The actual assertion function called by the assert macro
|
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
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
//! C11 `<stdint.h>` — fixed-width integer types and limits.
|
|
2
|
+
//!
|
|
3
|
+
//! Note: Yo already has `i8`, `i16`, `i32`, `i64`, `u8`, `u16`, `u32`, `u64`.
|
|
4
|
+
//! This file provides C-compatible aliases and additional types/constants.
|
|
4
5
|
|
|
5
6
|
// Type aliases for C compatibility (mapping Yo types to C stdint names)
|
|
6
7
|
int8_t :: i8;
|
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,5 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
//! Windows-specific C API bindings.
|
|
2
|
+
//! Only available when compiling for Windows.
|
|
3
3
|
|
|
4
4
|
// Windows type aliases (using Yo types that match the C types)
|
|
5
5
|
DWORD :: ulong; // unsigned long on Windows
|
package/std/log/index.yo
CHANGED
|
@@ -1,22 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
//
|
|
3
|
-
// Provides a global logger with configurable level and output destination.
|
|
4
|
-
//
|
|
5
|
-
// Example:
|
|
6
|
-
// { info, warn, error, set_level, Level } :: import "std/log";
|
|
7
|
-
//
|
|
8
|
-
// set_level(.Info);
|
|
9
|
-
// info(String.from("application started"));
|
|
10
|
-
// warn(String.from("disk usage high"));
|
|
1
|
+
//! Structured logging with configurable level and output destination.
|
|
11
2
|
|
|
12
3
|
open import "../string";
|
|
13
4
|
{ ToString } :: import "../fmt";
|
|
14
|
-
{ fwrite, stdout, stderr } :: import "../libc/stdio";
|
|
15
|
-
|
|
16
|
-
// ============================================================================
|
|
17
|
-
// Level
|
|
18
|
-
// ============================================================================
|
|
5
|
+
{ fwrite, stdout, stderr, FILE } :: import "../libc/stdio";
|
|
19
6
|
|
|
7
|
+
/// Log severity level.
|
|
20
8
|
Level :: enum(Trace, Debug, Info, Warn, Error);
|
|
21
9
|
|
|
22
10
|
impl(Level, ToString(
|
|
@@ -33,10 +21,7 @@ impl(Level, ToString(
|
|
|
33
21
|
|
|
34
22
|
export Level;
|
|
35
23
|
|
|
36
|
-
|
|
37
|
-
// LogOutput
|
|
38
|
-
// ============================================================================
|
|
39
|
-
|
|
24
|
+
/// Where log messages are written.
|
|
40
25
|
LogOutput :: enum(
|
|
41
26
|
Stderr,
|
|
42
27
|
Stdout
|
|
@@ -55,13 +40,13 @@ _global_output := LogOutput.Stderr;
|
|
|
55
40
|
// Configuration
|
|
56
41
|
// ============================================================================
|
|
57
42
|
|
|
58
|
-
set_level :: (fn(level: Level) -> unit)(
|
|
59
|
-
_global_level = level
|
|
60
|
-
);
|
|
43
|
+
set_level :: (fn(level: Level) -> unit)({
|
|
44
|
+
_global_level = level;
|
|
45
|
+
});
|
|
61
46
|
|
|
62
|
-
set_output :: (fn(output: LogOutput) -> unit)(
|
|
63
|
-
_global_output = output
|
|
64
|
-
);
|
|
47
|
+
set_output :: (fn(output: LogOutput) -> unit)({
|
|
48
|
+
_global_output = output;
|
|
49
|
+
});
|
|
65
50
|
|
|
66
51
|
export set_level, set_output;
|
|
67
52
|
|
|
@@ -80,7 +65,7 @@ _level_value :: (fn(l: Level) -> i32)(
|
|
|
80
65
|
);
|
|
81
66
|
|
|
82
67
|
// Write all bytes from a String to the file handle.
|
|
83
|
-
_write_string :: (fn(s: String, dest: *(
|
|
68
|
+
_write_string :: (fn(s: String, dest: *(FILE)) -> unit)({
|
|
84
69
|
bytes := s.as_bytes();
|
|
85
70
|
cond(
|
|
86
71
|
(bytes.len() > usize(0)) => {
|