@shd101wyy/yo 0.1.11 → 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 +579 -573
- package/out/cjs/yo-cli.cjs +1413 -592
- package/out/esm/index.mjs +437 -431
- 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/evaluator/exprs/import.d.ts +2 -0
- package/out/types/src/expr.d.ts +2 -1
- package/out/types/src/tests/import-path.test.d.ts +1 -0
- 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/collections/deque.yo
CHANGED
|
@@ -1,22 +1,20 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
1
|
+
//! Double-ended queue (ring buffer) with O(1) push/pop at both ends.
|
|
2
|
+
//!
|
|
3
|
+
//! # Example
|
|
4
|
+
//!
|
|
5
|
+
//! ```rust
|
|
6
|
+
//! { Deque } :: import "std/collections/deque";
|
|
7
|
+
//!
|
|
8
|
+
//! d := Deque(i32).new();
|
|
9
|
+
//! d.push_back(1);
|
|
10
|
+
//! d.push_front(0);
|
|
11
|
+
//! x := d.pop_front().unwrap(); // 0
|
|
12
|
+
//! ```
|
|
12
13
|
|
|
13
14
|
{ GlobalAllocator, AllocError } :: import "../allocator";
|
|
14
15
|
{ malloc, realloc, free } :: GlobalAllocator;
|
|
15
16
|
|
|
16
|
-
|
|
17
|
-
// Deque
|
|
18
|
-
// ============================================================================
|
|
19
|
-
|
|
17
|
+
/// Circular buffer supporting efficient push/pop at both front and back.
|
|
20
18
|
Deque :: (fn(comptime(T) : Type) -> comptime(Type))(
|
|
21
19
|
object(
|
|
22
20
|
_buf : ?*(T),
|
|
@@ -1,59 +1,31 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
*
|
|
4
|
-
* SwissTable is a state-of-the-art hash table design developed by Google for Abseil.
|
|
5
|
-
* Key features:
|
|
6
|
-
* - SIMD-accelerated lookup using control bytes
|
|
7
|
-
* - Quadratic probing for collision resolution
|
|
8
|
-
* - 7/8 max load factor for good performance
|
|
9
|
-
* - Compact memory layout with metadata array
|
|
10
|
-
*
|
|
11
|
-
* Memory layout:
|
|
12
|
-
* - ctrl: Array of control bytes (metadata), one per bucket
|
|
13
|
-
* - data: Array of key-value pairs
|
|
14
|
-
*
|
|
15
|
-
* Control byte values:
|
|
16
|
-
* - 0xFF (EMPTY): Bucket is empty and never used
|
|
17
|
-
* - 0xFE (DELETED): Bucket was used but is now deleted
|
|
18
|
-
* - 0x00-0x7F: Lower 7 bits of hash (H2 hash), indicates occupied bucket
|
|
19
|
-
*
|
|
20
|
-
* Hash function splits hash into two parts:
|
|
21
|
-
* - H1: Upper bits used to find bucket group
|
|
22
|
-
* - H2: Lower 7 bits stored in control byte for fast SIMD comparison
|
|
23
|
-
*/
|
|
1
|
+
//! Hash map using SwissTable algorithm with SIMD-accelerated lookup.
|
|
2
|
+
|
|
24
3
|
{ GlobalAllocator, AllocError } :: import "../allocator.yo";
|
|
25
4
|
{ malloc, calloc, realloc, free } :: GlobalAllocator;
|
|
26
5
|
|
|
27
|
-
|
|
28
|
-
* HashMap error types
|
|
29
|
-
*/
|
|
6
|
+
/// Error variants for HashMap operations.
|
|
30
7
|
HashMapError :: enum(
|
|
8
|
+
/// Memory allocation failed.
|
|
31
9
|
AllocError(error : AllocError),
|
|
10
|
+
/// The requested key was not found.
|
|
32
11
|
KeyNotFound,
|
|
12
|
+
/// Capacity calculation overflowed.
|
|
33
13
|
CapacityOverflow
|
|
34
14
|
);
|
|
35
15
|
|
|
36
|
-
|
|
37
|
-
* Control byte constants for SwissTable
|
|
38
|
-
*/
|
|
16
|
+
/// Control byte for an empty bucket (never used).
|
|
39
17
|
CTRL_EMPTY :: u8(255);
|
|
18
|
+
/// Control byte for a deleted bucket (tombstone).
|
|
40
19
|
CTRL_DELETED :: u8(254);
|
|
41
20
|
|
|
42
|
-
|
|
43
|
-
* Default initial capacity (must be power of 2)
|
|
44
|
-
*/
|
|
21
|
+
/// Default initial capacity (must be power of 2).
|
|
45
22
|
DEFAULT_CAPACITY :: usize(16);
|
|
46
23
|
|
|
47
|
-
|
|
48
|
-
* Maximum load factor: 7/8 = 0.875
|
|
49
|
-
* We resize when: size > capacity * 7 / 8
|
|
50
|
-
*/
|
|
24
|
+
/// Maximum load factor numerator (7/8 = 0.875). Resize when `size > capacity * 7 / 8`.
|
|
51
25
|
MAX_LOAD_FACTOR_NUMERATOR :: usize(7);
|
|
52
26
|
MAX_LOAD_FACTOR_DENOMINATOR :: usize(8);
|
|
53
27
|
|
|
54
|
-
|
|
55
|
-
* Bucket - Internal structure to store key-value pairs
|
|
56
|
-
*/
|
|
28
|
+
/// Key-value pair stored in a hash map bucket.
|
|
57
29
|
Bucket :: (fn(comptime(K): Type, comptime(V): Type) -> comptime(Type))
|
|
58
30
|
struct(
|
|
59
31
|
key : K,
|
|
@@ -61,29 +33,18 @@ Bucket :: (fn(comptime(K): Type, comptime(V): Type) -> comptime(Type))
|
|
|
61
33
|
)
|
|
62
34
|
;
|
|
63
35
|
|
|
64
|
-
|
|
65
|
-
* Extract H2 hash (lower 7 bits) from full hash
|
|
66
|
-
*/
|
|
36
|
+
/// Extract H2 hash (lower 7 bits) from full hash for control byte comparison.
|
|
67
37
|
h2_hash :: (fn(hash: u64) -> u8)
|
|
68
38
|
u8(hash & u64(127))
|
|
69
39
|
;
|
|
70
40
|
|
|
71
|
-
|
|
72
|
-
* Extract H1 hash (upper bits) for bucket index
|
|
73
|
-
*/
|
|
41
|
+
/// Extract H1 hash (upper bits) for bucket index calculation.
|
|
74
42
|
h1_hash :: (fn(hash: u64, capacity: usize) -> usize)
|
|
75
43
|
(usize((hash >> u64(7))) % capacity)
|
|
76
44
|
;
|
|
77
45
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
*
|
|
81
|
-
* Memory layout:
|
|
82
|
-
* - ctrl: Pointer to control bytes array (length = capacity)
|
|
83
|
-
* - data: Pointer to buckets array (length = capacity)
|
|
84
|
-
* - capacity: Total number of buckets (always power of 2)
|
|
85
|
-
* - size: Current number of occupied buckets
|
|
86
|
-
*/
|
|
46
|
+
/// High-performance hash map using SwissTable algorithm.
|
|
47
|
+
/// Keys must implement `Eq` and `Hash`. Provides O(1) average lookup, insert, and delete.
|
|
87
48
|
HashMap :: (fn(
|
|
88
49
|
comptime(K): Type,
|
|
89
50
|
comptime(V): Type,
|
|
@@ -1,78 +1,42 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
*
|
|
4
|
-
* This implementation uses the same SwissTable design as HashMap, providing:
|
|
5
|
-
* - SIMD-accelerated lookup using control bytes
|
|
6
|
-
* - Quadratic probing for collision resolution
|
|
7
|
-
* - 7/8 max load factor for optimal performance
|
|
8
|
-
* - Compact memory layout with metadata array
|
|
9
|
-
*
|
|
10
|
-
* Memory layout:
|
|
11
|
-
* - ctrl: Array of control bytes (metadata), one per slot
|
|
12
|
-
* - data: Array of elements
|
|
13
|
-
*
|
|
14
|
-
* Control byte values:
|
|
15
|
-
* - 0xFF (EMPTY): Slot is empty and never used
|
|
16
|
-
* - 0xFE (DELETED): Slot was used but is now deleted
|
|
17
|
-
* - 0x00-0x7F: Lower 7 bits of hash (H2 hash), indicates occupied slot
|
|
18
|
-
*
|
|
19
|
-
* Hash function splits hash into two parts:
|
|
20
|
-
* - H1: Upper bits used to find slot group
|
|
21
|
-
* - H2: Lower 7 bits stored in control byte for fast SIMD comparison
|
|
22
|
-
*/
|
|
1
|
+
//! Hash set using SwissTable algorithm with set-theoretic operations.
|
|
2
|
+
|
|
23
3
|
{ GlobalAllocator, AllocError } :: import "../allocator.yo";
|
|
24
4
|
{ malloc, calloc, realloc, free } :: GlobalAllocator;
|
|
25
5
|
|
|
26
|
-
|
|
27
|
-
* HashSet error types
|
|
28
|
-
*/
|
|
6
|
+
/// Error variants for HashSet operations.
|
|
29
7
|
HashSetError :: enum(
|
|
8
|
+
/// Memory allocation failed.
|
|
30
9
|
AllocError(error : AllocError),
|
|
10
|
+
/// The element was not found in the set.
|
|
31
11
|
ElementNotFound,
|
|
12
|
+
/// Capacity calculation overflowed.
|
|
32
13
|
CapacityOverflow
|
|
33
14
|
);
|
|
34
15
|
|
|
35
|
-
|
|
36
|
-
* Control byte constants for SwissTable
|
|
37
|
-
*/
|
|
16
|
+
/// Control byte for an empty slot.
|
|
38
17
|
CTRL_EMPTY :: u8(255);
|
|
18
|
+
/// Control byte for a deleted slot (tombstone).
|
|
39
19
|
CTRL_DELETED :: u8(254);
|
|
40
20
|
|
|
41
|
-
|
|
42
|
-
* Default initial capacity (must be power of 2)
|
|
43
|
-
*/
|
|
21
|
+
/// Default initial capacity (must be power of 2).
|
|
44
22
|
DEFAULT_CAPACITY :: usize(16);
|
|
45
23
|
|
|
46
|
-
|
|
47
|
-
* Maximum load factor: 7/8 = 0.875
|
|
48
|
-
* We resize when: size > capacity * 7 / 8
|
|
49
|
-
*/
|
|
24
|
+
/// Maximum load factor numerator (7/8 = 0.875).
|
|
50
25
|
MAX_LOAD_FACTOR_NUMERATOR :: usize(7);
|
|
51
26
|
MAX_LOAD_FACTOR_DENOMINATOR :: usize(8);
|
|
52
27
|
|
|
53
|
-
|
|
54
|
-
* Extract H2 hash (lower 7 bits) from full hash
|
|
55
|
-
*/
|
|
28
|
+
/// Extract H2 hash (lower 7 bits) from full hash.
|
|
56
29
|
h2_hash :: (fn(hash: u64) -> u8)
|
|
57
30
|
(u8((hash & u64(127))))
|
|
58
31
|
;
|
|
59
32
|
|
|
60
|
-
|
|
61
|
-
* Extract H1 hash (upper bits) for slot index
|
|
62
|
-
*/
|
|
33
|
+
/// Extract H1 hash (upper bits) for slot index.
|
|
63
34
|
h1_hash :: (fn(hash: u64, capacity: usize) -> usize)
|
|
64
35
|
((usize((hash >> u64(7))) % capacity))
|
|
65
36
|
;
|
|
66
37
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
*
|
|
70
|
-
* Memory layout:
|
|
71
|
-
* - ctrl: Pointer to control bytes array (length = capacity)
|
|
72
|
-
* - data: Pointer to elements array (length = capacity)
|
|
73
|
-
* - capacity: Total number of slots (always power of 2)
|
|
74
|
-
* - size: Current number of occupied slots
|
|
75
|
-
*/
|
|
38
|
+
/// High-performance hash set using SwissTable algorithm.
|
|
39
|
+
/// Elements must implement `Eq` and `Hash`. Provides O(1) average lookup and insert.
|
|
76
40
|
HashSet :: (fn(
|
|
77
41
|
comptime(T): Type,
|
|
78
42
|
where(T <: (Eq(T), Hash))
|
|
@@ -1,29 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
* LinkedList - A doubly-linked list implementation for Yo language
|
|
3
|
-
*
|
|
4
|
-
* Features:
|
|
5
|
-
* - O(1) push/pop from front and back
|
|
6
|
-
* - O(1) insertion/removal at known positions (with node reference)
|
|
7
|
-
* - RAII for automatic cleanup
|
|
8
|
-
* - True linked list using object indirection
|
|
9
|
-
*
|
|
10
|
-
* Memory layout:
|
|
11
|
-
* - Each node is an object (reference-counted)
|
|
12
|
-
* - Nodes contain: value, optional next node, optional prev node
|
|
13
|
-
*/
|
|
1
|
+
//! Doubly-linked list with O(1) push/pop at both ends.
|
|
14
2
|
|
|
15
|
-
|
|
16
|
-
* LinkedList error types
|
|
17
|
-
*/
|
|
3
|
+
/// Error variants for LinkedList operations.
|
|
18
4
|
LinkedListError :: enum(
|
|
5
|
+
/// Index is out of bounds for the current length.
|
|
19
6
|
IndexOutOfBounds(index: usize, length: usize),
|
|
7
|
+
/// Attempted to access an element from an empty list.
|
|
20
8
|
EmptyList
|
|
21
9
|
);
|
|
22
10
|
|
|
23
|
-
|
|
24
|
-
* Node - Internal structure for linked list nodes
|
|
25
|
-
* Since Node is an object (reference-counted), no Box needed
|
|
26
|
-
*/
|
|
11
|
+
/// Internal node for the linked list. Reference-counted via `object`.
|
|
27
12
|
Node :: (fn(comptime(T): Type) -> comptime(Type))
|
|
28
13
|
object(
|
|
29
14
|
value : T,
|
|
@@ -32,9 +17,7 @@ Node :: (fn(comptime(T): Type) -> comptime(Type))
|
|
|
32
17
|
)
|
|
33
18
|
;
|
|
34
19
|
|
|
35
|
-
|
|
36
|
-
* LinkedList - Doubly-linked list with O(1) operations at both ends
|
|
37
|
-
*/
|
|
20
|
+
/// Doubly-linked list with O(1) push/pop at both ends.
|
|
38
21
|
LinkedList :: (fn(comptime(T): Type) -> comptime(Type))
|
|
39
22
|
object(
|
|
40
23
|
head : Option(Node(T)),
|
|
@@ -1,23 +1,21 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
1
|
+
//! Binary min-heap priority queue.
|
|
2
|
+
//!
|
|
3
|
+
//! # Example
|
|
4
|
+
//!
|
|
5
|
+
//! ```rust
|
|
6
|
+
//! { PriorityQueue } :: import "std/collections/priority_queue";
|
|
7
|
+
//!
|
|
8
|
+
//! pq := PriorityQueue(i32).new();
|
|
9
|
+
//! pq.push(5);
|
|
10
|
+
//! pq.push(1);
|
|
11
|
+
//! pq.push(3);
|
|
12
|
+
//! x := pq.pop().unwrap(); // 1
|
|
13
|
+
//! ```
|
|
14
14
|
|
|
15
15
|
{ ArrayList } :: import "./array_list";
|
|
16
16
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
// ============================================================================
|
|
20
|
-
|
|
17
|
+
/// Min-heap backed by an ArrayList.
|
|
18
|
+
/// Elements are ordered ascending (smallest first). Negate keys for max-heap behavior.
|
|
21
19
|
PriorityQueue :: (fn(comptime(T) : Type) -> comptime(Type))(
|
|
22
20
|
object(
|
|
23
21
|
_data : ArrayList(T)
|
package/std/crypto/md5.yo
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
1
|
+
//! MD5 hash function (RFC 1321), pure Yo implementation.
|
|
2
|
+
//! MD5 is considered cryptographically broken — use SHA-256 for security.
|
|
3
|
+
//!
|
|
4
|
+
//! # Example
|
|
5
|
+
//!
|
|
6
|
+
//! ```rust
|
|
7
|
+
//! { md5_hex } :: import "std/crypto/md5";
|
|
8
|
+
//!
|
|
9
|
+
//! digest := md5_hex(data); // "5d41402abc4b2a76b9719d911017c592"
|
|
10
|
+
//! ```
|
|
10
11
|
|
|
11
12
|
{ ArrayList } :: import "../collections/array_list";
|
|
12
13
|
{ hex_encode } :: import "../encoding/hex";
|
package/std/crypto/random.yo
CHANGED
|
@@ -1,15 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
// id := uuid_v4(); // "550e8400-e29b-41d4-a716-446655440000"
|
|
1
|
+
//! Cryptographically secure random number generation.
|
|
2
|
+
//! Uses OS entropy sources (getrandom on Linux, arc4random_buf on macOS,
|
|
3
|
+
//! BCryptGenRandom on Windows, getentropy on WASI).
|
|
4
|
+
//!
|
|
5
|
+
//! # Example
|
|
6
|
+
//!
|
|
7
|
+
//! ```rust
|
|
8
|
+
//! { random_u64, uuid_v4 } :: import "std/crypto/random";
|
|
9
|
+
//!
|
|
10
|
+
//! id := uuid_v4(); // "550e8400-e29b-41d4-a716-446655440000"
|
|
11
|
+
//! ```
|
|
13
12
|
|
|
14
13
|
{ ArrayList } :: import "../collections/array_list";
|
|
15
14
|
{ platform, Platform } :: import "../process";
|
|
@@ -23,8 +22,11 @@ open import "../string";
|
|
|
23
22
|
// Error type
|
|
24
23
|
// ============================================================================
|
|
25
24
|
|
|
25
|
+
/// Errors that can occur during cryptographic random operations.
|
|
26
26
|
CryptoError :: enum(
|
|
27
|
+
/// Platform does not support secure random generation.
|
|
27
28
|
Unavailable,
|
|
29
|
+
/// Other platform-specific error.
|
|
28
30
|
Other(msg: String)
|
|
29
31
|
);
|
|
30
32
|
|
package/std/crypto/sha256.yo
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
//! SHA-256 hash function (FIPS 180-4), pure Yo implementation.
|
|
2
|
+
//!
|
|
3
|
+
//! # Example
|
|
4
|
+
//!
|
|
5
|
+
//! ```rust
|
|
6
|
+
//! { sha256_hex } :: import "std/crypto/sha256";
|
|
7
|
+
//!
|
|
8
|
+
//! digest := sha256_hex(data); // "2cf24dba..."
|
|
9
|
+
//! ```
|
|
9
10
|
|
|
10
11
|
{ ArrayList } :: import "../collections/array_list";
|
|
11
12
|
{ hex_encode } :: import "../encoding/hex";
|
package/std/encoding/base64.yo
CHANGED
|
@@ -1,12 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
// s := base64_encode(data);
|
|
9
|
-
// b := base64_decode(s.to_str()).unwrap();
|
|
1
|
+
//! Base64 encoding and decoding (RFC 4648) with standard and URL-safe variants.
|
|
2
|
+
//!
|
|
3
|
+
//! Example:
|
|
4
|
+
//! { base64_encode, base64_decode } :: import "std/encoding/base64";
|
|
5
|
+
//!
|
|
6
|
+
//! s := base64_encode(data);
|
|
7
|
+
//! b := base64_decode(s.to_str()).unwrap();
|
|
10
8
|
|
|
11
9
|
open import "../string";
|
|
12
10
|
{ ArrayList } :: import "../collections/array_list";
|
|
@@ -58,12 +56,12 @@ _encode_with :: (fn(data: ArrayList(u8), alpha: str, pad: bool) -> String)({
|
|
|
58
56
|
String.from_bytes(out)
|
|
59
57
|
});
|
|
60
58
|
|
|
61
|
-
|
|
59
|
+
/// Encode bytes as standard base64 with padding.
|
|
62
60
|
base64_encode :: (fn(data: ArrayList(u8)) -> String)(
|
|
63
61
|
_encode_with(data, _STD_ALPHA, true)
|
|
64
62
|
);
|
|
65
63
|
|
|
66
|
-
|
|
64
|
+
/// Encode bytes as URL-safe base64 without padding.
|
|
67
65
|
base64_encode_url :: (fn(data: ArrayList(u8)) -> String)(
|
|
68
66
|
_encode_with(data, _URL_ALPHA, false)
|
|
69
67
|
);
|
|
@@ -116,12 +114,12 @@ _decode_with :: (fn(s: str, alpha: str, using(exn : Exception)) -> ArrayList(u8)
|
|
|
116
114
|
out
|
|
117
115
|
});
|
|
118
116
|
|
|
119
|
-
|
|
117
|
+
/// Decode a standard base64 string to bytes. Throws via `Exception` on invalid input.
|
|
120
118
|
base64_decode :: (fn(s: str, using(exn : Exception)) -> ArrayList(u8))(
|
|
121
119
|
_decode_with(s, _STD_ALPHA)
|
|
122
120
|
);
|
|
123
121
|
|
|
124
|
-
|
|
122
|
+
/// Decode a URL-safe base64 string to bytes. Throws via `Exception` on invalid input.
|
|
125
123
|
base64_decode_url :: (fn(s: str, using(exn : Exception)) -> ArrayList(u8))(
|
|
126
124
|
_decode_with(s, _URL_ALPHA)
|
|
127
125
|
);
|
|
@@ -132,7 +130,7 @@ export base64_decode, base64_decode_url;
|
|
|
132
130
|
// String-level convenience API
|
|
133
131
|
// ============================================================================
|
|
134
132
|
|
|
135
|
-
|
|
133
|
+
/// Encode a `String` to standard base64.
|
|
136
134
|
base64_encode_string :: (fn(input: String) -> String)(
|
|
137
135
|
_encode_with(input.as_bytes(), _STD_ALPHA, true)
|
|
138
136
|
);
|
|
@@ -150,7 +148,7 @@ _base64_index :: (fn(c: u8) -> i32)({
|
|
|
150
148
|
i32(-1)
|
|
151
149
|
});
|
|
152
150
|
|
|
153
|
-
|
|
151
|
+
/// Decode a base64 `String`, ignoring whitespace. Returns `Result(String, String)`.
|
|
154
152
|
base64_decode_string :: (fn(input: String) -> Result(String, String))({
|
|
155
153
|
raw := input.as_str();
|
|
156
154
|
cleaned := ArrayList(u8).new();
|
package/std/encoding/hex.yo
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
1
|
+
//! Hexadecimal encoding and decoding.
|
|
2
|
+
//!
|
|
3
|
+
//! Converts between raw bytes (`ArrayList(u8)`) and hex strings.
|
|
4
|
+
//!
|
|
5
|
+
//! Example:
|
|
6
|
+
//! { hex_encode, hex_decode } :: import "std/encoding/hex";
|
|
7
|
+
//!
|
|
8
|
+
//! s := hex_encode(data); // "deadbeef"
|
|
9
|
+
//! b := hex_decode("deadbeef");
|
|
10
10
|
|
|
11
11
|
open import "../string";
|
|
12
12
|
{ ArrayList } :: import "../collections/array_list";
|
|
@@ -17,8 +17,11 @@ open import "../string";
|
|
|
17
17
|
// Error type
|
|
18
18
|
// ============================================================================
|
|
19
19
|
|
|
20
|
+
/// Encoding/decoding error type.
|
|
20
21
|
EncodingError :: enum(
|
|
22
|
+
/// Invalid character encountered during decoding.
|
|
21
23
|
InvalidChar(ch: u8),
|
|
24
|
+
/// Input string has odd length (hex requires even length).
|
|
22
25
|
OddLength
|
|
23
26
|
);
|
|
24
27
|
|
|
@@ -55,6 +58,7 @@ _hex_encode_impl :: (fn(data: ArrayList(u8), hex_chars: str) -> String)({
|
|
|
55
58
|
String.from_bytes(out)
|
|
56
59
|
});
|
|
57
60
|
|
|
61
|
+
/// Encode bytes as a lowercase hexadecimal string.
|
|
58
62
|
hex_encode :: (fn(data: ArrayList(u8)) -> String)(
|
|
59
63
|
_hex_encode_impl(data, _HEX_CHARS)
|
|
60
64
|
);
|
|
@@ -74,7 +78,7 @@ _hex_nibble :: (fn(c: u8, using(exn : Exception)) -> u8)(
|
|
|
74
78
|
)
|
|
75
79
|
);
|
|
76
80
|
|
|
77
|
-
|
|
81
|
+
/// Decode a hexadecimal string to bytes. Throws via `Exception` on invalid input.
|
|
78
82
|
hex_decode :: (fn(s: str, using(exn : Exception)) -> ArrayList(u8))({
|
|
79
83
|
cond(
|
|
80
84
|
(((s.len() % usize(2)) != usize(0))) => {
|
package/std/encoding/html.yo
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
1
|
+
//! HTML entity decoding — named, decimal, and hexadecimal character references.
|
|
2
|
+
//!
|
|
3
|
+
//! Decodes named (&), decimal (&), and hex (&) HTML character references.
|
|
4
|
+
//! Uses Legacy mode — entities without trailing semicolon are also decoded.
|
|
5
|
+
//!
|
|
6
|
+
//! Example:
|
|
7
|
+
//! { decode_html } :: import "std/encoding/html";
|
|
8
|
+
//!
|
|
9
|
+
//! result := decode_html(`& < & &`);
|
|
10
|
+
//! assert((result == `& < & &`), "decoded entities");
|
|
11
11
|
|
|
12
12
|
open import "../string";
|
|
13
13
|
{ HashMap } :: import "../collections/hash_map";
|
|
@@ -64,7 +64,10 @@ _is_alpha_numeric :: (fn(c: rune) -> bool)(
|
|
|
64
64
|
((((c >= rune(u32('a'))) && (c <= rune(u32('z')))) || ((c >= rune(u32('A'))) && (c <= rune(u32('Z'))))) || ((c >= rune(u32('0'))) && (c <= rune(u32('9')))))
|
|
65
65
|
);
|
|
66
66
|
|
|
67
|
-
|
|
67
|
+
/// Decode HTML entities in a string.
|
|
68
|
+
///
|
|
69
|
+
/// Supports named (`&`), decimal (`&`), and hexadecimal (`&`) character
|
|
70
|
+
/// references. Legacy mode — entities without trailing semicolons are also decoded.
|
|
68
71
|
decode_html :: (fn(input: String) -> String)({
|
|
69
72
|
_ensure_init();
|
|
70
73
|
|
|
@@ -1,16 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
1
|
+
//! HTML character utility functions.
|
|
2
|
+
//!
|
|
3
|
+
//! Provides Unicode codepoint validation and conversion for HTML entity processing.
|
|
4
|
+
//!
|
|
5
|
+
//! # Example
|
|
6
|
+
//!
|
|
7
|
+
//! ```rust
|
|
8
|
+
//! { is_valid_entity_code, from_code_point } :: import "std/encoding/html_char_utils";
|
|
9
|
+
//!
|
|
10
|
+
//! assert(is_valid_entity_code(i32(65)), "A is valid");
|
|
11
|
+
//! s := from_code_point(i32(65)); // "A"
|
|
12
|
+
//! ```
|
|
10
13
|
|
|
11
14
|
open import "../string";
|
|
12
15
|
|
|
13
|
-
|
|
16
|
+
/// Check if a Unicode codepoint is a valid HTML entity value.
|
|
14
17
|
is_valid_entity_code :: (fn(c: i32) -> bool)(
|
|
15
18
|
cond(
|
|
16
19
|
((c >= i32(0xD800)) && (c <= i32(0xDFFF))) => false,
|
|
@@ -25,7 +28,7 @@ is_valid_entity_code :: (fn(c: i32) -> bool)(
|
|
|
25
28
|
)
|
|
26
29
|
);
|
|
27
30
|
|
|
28
|
-
|
|
31
|
+
/// Convert a Unicode codepoint to a `String`.
|
|
29
32
|
from_code_point :: (fn(c: i32) -> String)(
|
|
30
33
|
{
|
|
31
34
|
(r : rune) = rune(u32(c));
|
|
@@ -1,17 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
// Import: { _build_entity_map, _build_legacy_set } :: import "std/encoding/html_entities";
|
|
1
|
+
//! HTML5 named character references data.
|
|
2
|
+
//!
|
|
3
|
+
//! Auto-generated from <https://html.spec.whatwg.org/entities.json>.
|
|
4
|
+
//! Total: 2125 entities.
|
|
5
|
+
//!
|
|
6
|
+
//! This module provides the entity name-to-string mapping used by `decode_html`.
|
|
8
7
|
|
|
9
8
|
open import "../string";
|
|
10
9
|
{ HashMap } :: import "../collections/hash_map";
|
|
11
10
|
{ HashSet } :: import "../collections/hash_set";
|
|
12
11
|
{ from_code_point } :: import "./html_char_utils";
|
|
13
12
|
|
|
14
|
-
|
|
13
|
+
/// Returns a `HashMap` mapping entity names (without `&` and `;`) to decoded strings.
|
|
15
14
|
_build_entity_map :: (fn() -> HashMap(String, String))(
|
|
16
15
|
{
|
|
17
16
|
(m : HashMap(String, String)) = HashMap(String, String).new();
|