@shd101wyy/yo 0.0.23 → 0.0.25
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/out/cjs/index.cjs +560 -520
- package/out/cjs/yo-cli.cjs +598 -558
- package/out/esm/index.mjs +551 -511
- package/out/types/src/codegen/exprs/arc.d.ts +5 -0
- package/out/types/src/codegen/types/generation.d.ts +2 -0
- package/out/types/src/codegen/utils/index.d.ts +8 -1
- package/out/types/src/evaluator/builtins/rc-fns.d.ts +5 -0
- package/out/types/src/evaluator/calls/arc.d.ts +15 -0
- package/out/types/src/evaluator/calls/trait-type.d.ts +8 -1
- package/out/types/src/evaluator/context.d.ts +11 -1
- package/out/types/src/evaluator/types/utils.d.ts +8 -3
- package/out/types/src/evaluator/utils/closure.d.ts +7 -1
- package/out/types/src/evaluator/values/impl.d.ts +8 -0
- package/out/types/src/expr.d.ts +6 -0
- package/out/types/src/test-runner.d.ts +2 -0
- package/out/types/src/types/creators.d.ts +2 -1
- package/out/types/src/types/definitions.d.ts +10 -0
- package/out/types/src/types/guards.d.ts +2 -1
- package/out/types/src/types/tags.d.ts +1 -0
- package/out/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/std/collections/array_list.yo +80 -10
- package/std/collections/btree_map.yo +120 -2
- package/std/collections/deque.yo +98 -6
- package/std/collections/hash_map.yo +137 -1
- package/std/collections/hash_set.yo +85 -1
- package/std/collections/linked_list.yo +61 -1
- package/std/collections/priority_queue.yo +70 -1
- package/std/crypto/md5.yo +4 -4
- package/std/crypto/random.yo +3 -3
- package/std/crypto/sha256.yo +8 -7
- package/std/encoding/base64.yo +6 -6
- package/std/encoding/hex.yo +27 -22
- package/std/encoding/json.yo +185 -186
- package/std/encoding/utf16.yo +2 -2
- package/std/fmt/display.yo +1 -1
- package/std/fmt/writer.yo +2 -4
- package/std/fs/dir.yo +5 -5
- package/std/fs/file.yo +21 -13
- package/std/fs/metadata.yo +4 -4
- package/std/fs/temp.yo +3 -3
- package/std/fs/types.yo +1 -1
- package/std/fs/walker.yo +1 -1
- package/std/net/addr.yo +2 -2
- package/std/net/dns.yo +21 -20
- package/std/net/errors.yo +1 -1
- package/std/net/tcp.yo +134 -100
- package/std/net/udp.yo +51 -42
- package/std/os/env.yo +21 -23
- package/std/os/signal.yo +10 -9
- package/std/prelude.yo +158 -22
- package/std/string/string.yo +99 -1
- package/std/sync/once.yo +1 -1
- package/std/{io → sys}/advise.yo +1 -1
- package/std/sys/bufio/buf_reader.yo +300 -0
- package/std/sys/bufio/buf_writer.yo +168 -0
- package/std/{io → sys}/clock.yo +1 -1
- package/std/{io → sys}/constants.yo +1 -1
- package/std/{io → sys}/copy.yo +1 -1
- package/std/{io → sys}/dir.yo +6 -6
- package/std/{io → sys}/dns.yo +3 -3
- package/std/{io → sys}/errors.yo +1 -1
- package/std/{io → sys}/events.yo +1 -1
- package/std/{io → sys}/externs.yo +1 -1
- package/std/{io → sys}/fallocate.yo +1 -1
- package/std/{io → sys}/fcntl.yo +1 -1
- package/std/{io → sys}/file.yo +1 -1
- package/std/{io → sys}/future.yo +1 -1
- package/std/{io → sys}/iov.yo +1 -1
- package/std/{io → sys}/lock.yo +1 -1
- package/std/{io → sys}/mmap.yo +1 -1
- package/std/{io → sys}/path.yo +1 -1
- package/std/{io → sys}/perm.yo +3 -3
- package/std/{io → sys}/pipe.yo +1 -1
- package/std/{io → sys}/process.yo +1 -1
- package/std/{io → sys}/seek.yo +1 -1
- package/std/{io → sys}/signal.yo +1 -1
- package/std/{io → sys}/signals.yo +1 -1
- package/std/{io → sys}/socket.yo +1 -1
- package/std/{io → sys}/socketpair.yo +1 -1
- package/std/{io → sys}/sockinfo.yo +1 -1
- package/std/{io → sys}/statfs.yo +2 -2
- package/std/{io → sys}/statx.yo +1 -1
- package/std/{io → sys}/sysinfo.yo +1 -1
- package/std/{io → sys}/tcp.yo +3 -3
- package/std/{io → sys}/temp.yo +1 -1
- package/std/{io → sys}/time.yo +2 -2
- package/std/{io → sys}/timer.yo +1 -1
- package/std/{io → sys}/tty.yo +1 -1
- package/std/{io → sys}/udp.yo +4 -4
- package/std/{io → sys}/umask.yo +1 -1
- package/std/{io → sys}/unix.yo +1 -1
- package/std/time/datetime.yo +18 -23
- package/std/time/instant.yo +13 -11
- package/std/url/url.yo +533 -0
- package/std/math/functions.yo +0 -74
- package/std/math/random.yo +0 -94
|
@@ -118,4 +118,73 @@ impl(forall(T : Type), PriorityQueue(T),
|
|
|
118
118
|
})
|
|
119
119
|
);
|
|
120
120
|
|
|
121
|
-
|
|
121
|
+
/**
|
|
122
|
+
* Value iterator for PriorityQueue - yields elements in heap (arbitrary) order
|
|
123
|
+
* Note: This iterates in internal storage order, NOT sorted order.
|
|
124
|
+
*/
|
|
125
|
+
PriorityQueueIter :: (fn(comptime(T) : Type) -> comptime(Type))(
|
|
126
|
+
struct(
|
|
127
|
+
_data : ArrayList(T),
|
|
128
|
+
_index : usize
|
|
129
|
+
)
|
|
130
|
+
);
|
|
131
|
+
|
|
132
|
+
impl(forall(T : Type), PriorityQueueIter(T), Iterator(
|
|
133
|
+
Item : T,
|
|
134
|
+
next : (fn(self : *(Self)) -> Option(T))(
|
|
135
|
+
cond(
|
|
136
|
+
(self._index >= self._data.len()) => .None,
|
|
137
|
+
true => {
|
|
138
|
+
value := self._data.get(self._index).unwrap();
|
|
139
|
+
self._index = (self._index + usize(1));
|
|
140
|
+
.Some(value)
|
|
141
|
+
}
|
|
142
|
+
)
|
|
143
|
+
)
|
|
144
|
+
));
|
|
145
|
+
|
|
146
|
+
impl(forall(T : Type), PriorityQueue(T),
|
|
147
|
+
into_iter : (fn(self : Self) -> PriorityQueueIter(T))(
|
|
148
|
+
PriorityQueueIter(T)(_data: self._data, _index: usize(0))
|
|
149
|
+
)
|
|
150
|
+
);
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* Pointer iterator for PriorityQueue - yields pointers to elements in heap order
|
|
154
|
+
*/
|
|
155
|
+
PriorityQueueIterPtr :: (fn(comptime(T) : Type) -> comptime(Type))(
|
|
156
|
+
struct(
|
|
157
|
+
_data : ArrayList(T),
|
|
158
|
+
_index : usize
|
|
159
|
+
)
|
|
160
|
+
);
|
|
161
|
+
|
|
162
|
+
impl(forall(T : Type), PriorityQueueIterPtr(T), Iterator(
|
|
163
|
+
Item : *(T),
|
|
164
|
+
next : (fn(self : *(Self)) -> Option(*(T)))(
|
|
165
|
+
cond(
|
|
166
|
+
(self._index >= self._data.len()) => .None,
|
|
167
|
+
true =>
|
|
168
|
+
match(self._data._ptr,
|
|
169
|
+
.Some(ptr) => {
|
|
170
|
+
element_ptr := (ptr &+ self._index);
|
|
171
|
+
self._index = (self._index + usize(1));
|
|
172
|
+
.Some(element_ptr)
|
|
173
|
+
},
|
|
174
|
+
.None => .None
|
|
175
|
+
)
|
|
176
|
+
)
|
|
177
|
+
)
|
|
178
|
+
));
|
|
179
|
+
|
|
180
|
+
impl(forall(T : Type), PriorityQueue(T),
|
|
181
|
+
iter : (fn(self : *(Self)) -> PriorityQueueIterPtr(T))(
|
|
182
|
+
PriorityQueueIterPtr(T)(_data: self.*._data, _index: usize(0))
|
|
183
|
+
)
|
|
184
|
+
);
|
|
185
|
+
|
|
186
|
+
export
|
|
187
|
+
PriorityQueue,
|
|
188
|
+
PriorityQueueIter,
|
|
189
|
+
PriorityQueueIterPtr
|
|
190
|
+
;
|
package/std/crypto/md5.yo
CHANGED
|
@@ -51,8 +51,8 @@ _rotl32 :: (fn(x: u32, n: u32) -> u32)(
|
|
|
51
51
|
);
|
|
52
52
|
|
|
53
53
|
_le32 :: (fn(p: *(u8)) -> u32)(
|
|
54
|
-
(u32(p.*) | (u32((p &+ usize(1)).*) << u32(8)) |
|
|
55
|
-
(u32((p &+ usize(2)).*) << u32(16)) | (u32((p &+ usize(3)).*) << u32(24)))
|
|
54
|
+
((u32(p.*) | (u32((p &+ usize(1)).*) << u32(8))) |
|
|
55
|
+
((u32((p &+ usize(2)).*) << u32(16)) | (u32((p &+ usize(3)).*) << u32(24))))
|
|
56
56
|
);
|
|
57
57
|
|
|
58
58
|
_md5_block :: (fn(block: *(u8), h: *(u32)) -> unit)({
|
|
@@ -74,7 +74,7 @@ _md5_block :: (fn(block: *(u8), h: *(u32)) -> unit)({
|
|
|
74
74
|
g = (((i * usize(5)) + usize(1)) % usize(16));
|
|
75
75
|
},
|
|
76
76
|
(i < usize(48)) => {
|
|
77
|
-
fv = (b ^ c ^ d);
|
|
77
|
+
fv = ((b ^ c) ^ d);
|
|
78
78
|
g = (((i * usize(3)) + usize(5)) % usize(16));
|
|
79
79
|
},
|
|
80
80
|
true => {
|
|
@@ -104,7 +104,7 @@ md5 :: (fn(data: ArrayList(u8)) -> Array(u8, usize(16)))({
|
|
|
104
104
|
// Process full blocks
|
|
105
105
|
i := usize(0);
|
|
106
106
|
while ((i + usize(64)) <= n), (i = (i + usize(64))), {
|
|
107
|
-
chunk_ptr := *(u8)(data.ptr().unwrap()) &+ i;
|
|
107
|
+
chunk_ptr := (*(u8)(data.ptr().unwrap()) &+ i);
|
|
108
108
|
_md5_block(chunk_ptr, h_ptr);
|
|
109
109
|
};
|
|
110
110
|
// Final block(s) with padding
|
package/std/crypto/random.yo
CHANGED
|
@@ -93,12 +93,12 @@ random_f64 :: (fn() -> f64)(
|
|
|
93
93
|
|
|
94
94
|
// Return a random integer in the half-open range [min, max).
|
|
95
95
|
random_range :: (fn(min: i64, max: i64) -> i64)({
|
|
96
|
-
span :=
|
|
96
|
+
span := (max - min);
|
|
97
97
|
cond(
|
|
98
98
|
(span <= i64(0)) => min,
|
|
99
99
|
true => {
|
|
100
|
-
r :=
|
|
101
|
-
(min + (r % span))
|
|
100
|
+
r := random_u64();
|
|
101
|
+
(min + i64((r % u64(span))))
|
|
102
102
|
}
|
|
103
103
|
)
|
|
104
104
|
});
|
package/std/crypto/sha256.yo
CHANGED
|
@@ -39,7 +39,7 @@ _rotr32 :: (fn(x: u32, n: u32) -> u32)(
|
|
|
39
39
|
);
|
|
40
40
|
|
|
41
41
|
_ch :: (fn(e: u32, f: u32, g: u32) -> u32)( ((e & f) ^ ((~e) & g)) );
|
|
42
|
-
_maj :: (fn(a: u32, b: u32, c: u32) -> u32)( ((a & b) ^ (a & c) ^ (b & c)) );
|
|
42
|
+
_maj :: (fn(a: u32, b: u32, c: u32) -> u32)( (((a & b) ^ (a & c)) ^ (b & c)) );
|
|
43
43
|
_ep0 :: (fn(a: u32) -> u32)( ((_rotr32(a, u32(2)) ^ _rotr32(a, u32(13))) ^ _rotr32(a, u32(22))) );
|
|
44
44
|
_ep1 :: (fn(e: u32) -> u32)( ((_rotr32(e, u32(6)) ^ _rotr32(e, u32(11))) ^ _rotr32(e, u32(25))) );
|
|
45
45
|
_sg0 :: (fn(x: u32) -> u32)( ((_rotr32(x, u32(7)) ^ _rotr32(x, u32(18))) ^ (x >> u32(3))) );
|
|
@@ -53,15 +53,16 @@ _sha256_block :: (fn(block: *(u8), h: *(u32)) -> unit)({
|
|
|
53
53
|
while (i < usize(16)), (i = (i + usize(1))), {
|
|
54
54
|
off := (i * usize(4));
|
|
55
55
|
w(i) = (
|
|
56
|
-
((u32((block &+ off).*) << u32(24)) |
|
|
57
|
-
(u32((block &+ (off + usize(1))).*) << u32(16)) |
|
|
58
|
-
(u32((block &+ (off + usize(2))).*) << u32(8)) |
|
|
59
|
-
u32((block &+ (off + usize(3))).*)
|
|
60
|
-
)
|
|
56
|
+
(((u32((block &+ off).*) << u32(24)) |
|
|
57
|
+
(u32((block &+ (off + usize(1))).*) << u32(16))) |
|
|
58
|
+
((u32((block &+ (off + usize(2))).*) << u32(8)) |
|
|
59
|
+
u32((block &+ (off + usize(3))).*)))
|
|
61
60
|
);
|
|
62
61
|
};
|
|
63
62
|
while (i < usize(64)), (i = (i + usize(1))), {
|
|
64
|
-
|
|
63
|
+
s1 := _sg1(w((i - usize(2))));
|
|
64
|
+
s0 := _sg0(w((i - usize(15))));
|
|
65
|
+
w(i) = (((s1 + w((i - usize(7)))) + s0) + w((i - usize(16))));
|
|
65
66
|
};
|
|
66
67
|
// Compression
|
|
67
68
|
a := (h &+ usize(0)).*;
|
package/std/encoding/base64.yo
CHANGED
|
@@ -30,8 +30,8 @@ _encode_with :: (fn(data: ArrayList(u8), alpha: str, pad: bool) -> String)({
|
|
|
30
30
|
i := usize(0);
|
|
31
31
|
while (i < n), (i = (i + usize(3))), {
|
|
32
32
|
b0 := data.get(i).unwrap();
|
|
33
|
-
b1 := cond((i + usize(1)) < n => data.get((i + usize(1))).unwrap(), true => u8(0));
|
|
34
|
-
b2 := cond((i + usize(2)) < n => data.get((i + usize(2))).unwrap(), true => u8(0));
|
|
33
|
+
b1 := cond(((i + usize(1)) < n) => data.get((i + usize(1))).unwrap(), true => u8(0));
|
|
34
|
+
b2 := cond(((i + usize(2)) < n) => data.get((i + usize(2))).unwrap(), true => u8(0));
|
|
35
35
|
|
|
36
36
|
out.push(alpha.bytes(usize((b0 >> u8(2)))));
|
|
37
37
|
out.push(alpha.bytes(usize(((b0 & u8(3)) << u8(4)) | (b1 >> u8(4)))));
|
|
@@ -87,22 +87,22 @@ _decode_char :: (fn(c: u8, alpha: str) -> Result(u8, EncodingError))({
|
|
|
87
87
|
_decode_with :: (fn(s: str, alpha: str) -> Result(ArrayList(u8), EncodingError))({
|
|
88
88
|
// Strip trailing padding
|
|
89
89
|
len := s.len();
|
|
90
|
-
while ((len > usize(0)) && (s.bytes((len - usize(1))) == _PAD)), (len = (len - usize(1))),
|
|
90
|
+
while ((len > usize(0)) && (s.bytes((len - usize(1))) == _PAD)), (len = (len - usize(1))), ();
|
|
91
91
|
out := ArrayList(u8).with_capacity(((len * usize(3)) / usize(4)));
|
|
92
92
|
i := usize(0);
|
|
93
93
|
while (i < len), (i = (i + usize(4))), {
|
|
94
94
|
c0_r := _decode_char(s.bytes(i), alpha);
|
|
95
95
|
c1_r := cond(
|
|
96
96
|
((i + usize(1)) < len) => _decode_char(s.bytes((i + usize(1))), alpha),
|
|
97
|
-
true => .Ok(u8(0))
|
|
97
|
+
true => Result(u8, EncodingError).Ok(u8(0))
|
|
98
98
|
);
|
|
99
99
|
c2_r := cond(
|
|
100
100
|
((i + usize(2)) < len) => _decode_char(s.bytes((i + usize(2))), alpha),
|
|
101
|
-
true => .Ok(u8(0))
|
|
101
|
+
true => Result(u8, EncodingError).Ok(u8(0))
|
|
102
102
|
);
|
|
103
103
|
c3_r := cond(
|
|
104
104
|
((i + usize(3)) < len) => _decode_char(s.bytes((i + usize(3))), alpha),
|
|
105
|
-
true => .Ok(u8(0))
|
|
105
|
+
true => Result(u8, EncodingError).Ok(u8(0))
|
|
106
106
|
);
|
|
107
107
|
match(c0_r,
|
|
108
108
|
.Err(e) => { return .Err(e); },
|
package/std/encoding/hex.yo
CHANGED
|
@@ -29,19 +29,23 @@ export EncodingError;
|
|
|
29
29
|
_HEX_CHARS :: "0123456789abcdef";
|
|
30
30
|
|
|
31
31
|
// Encode bytes as lowercase hexadecimal.
|
|
32
|
-
|
|
32
|
+
_hex_encode_impl :: (fn(data: ArrayList(u8), hex_chars: str) -> String)({
|
|
33
33
|
out := ArrayList(u8).with_capacity((data.len() * usize(2)));
|
|
34
34
|
i := usize(0);
|
|
35
35
|
while (i < data.len()), (i = (i + usize(1))), {
|
|
36
36
|
b := data.get(i).unwrap();
|
|
37
37
|
hi := usize(((b >> u8(4)) & u8(0xF)));
|
|
38
38
|
lo := usize((b & u8(0xF)));
|
|
39
|
-
out.push(
|
|
40
|
-
out.push(
|
|
39
|
+
out.push(hex_chars.bytes(hi));
|
|
40
|
+
out.push(hex_chars.bytes(lo));
|
|
41
41
|
};
|
|
42
42
|
String.from_bytes(out)
|
|
43
43
|
});
|
|
44
44
|
|
|
45
|
+
hex_encode :: (fn(data: ArrayList(u8)) -> String)(
|
|
46
|
+
_hex_encode_impl(data, _HEX_CHARS)
|
|
47
|
+
);
|
|
48
|
+
|
|
45
49
|
export hex_encode;
|
|
46
50
|
|
|
47
51
|
// ============================================================================
|
|
@@ -60,28 +64,29 @@ _hex_nibble :: (fn(c: u8) -> Result(u8, EncodingError))(
|
|
|
60
64
|
// Decode a hexadecimal string into bytes.
|
|
61
65
|
hex_decode :: (fn(s: str) -> Result(ArrayList(u8), EncodingError))({
|
|
62
66
|
cond(
|
|
63
|
-
(((s.len() % usize(2)) != usize(0))) =>
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
67
|
+
(((s.len() % usize(2)) != usize(0))) => {
|
|
68
|
+
return .Err(.OddLength);
|
|
69
|
+
},
|
|
70
|
+
true => ()
|
|
71
|
+
);
|
|
72
|
+
out := ArrayList(u8).with_capacity((s.len() / usize(2)));
|
|
73
|
+
i := usize(0);
|
|
74
|
+
while (i < s.len()), (i = (i + usize(2))), {
|
|
75
|
+
hi_r := _hex_nibble(s.bytes(i));
|
|
76
|
+
lo_r := _hex_nibble(s.bytes((i + usize(1))));
|
|
77
|
+
match(hi_r,
|
|
78
|
+
.Err(e) => { return .Err(e); },
|
|
79
|
+
.Ok(hi) => {
|
|
80
|
+
match(lo_r,
|
|
71
81
|
.Err(e) => { return .Err(e); },
|
|
72
|
-
.Ok(
|
|
73
|
-
|
|
74
|
-
.Err(e) => { return .Err(e); },
|
|
75
|
-
.Ok(lo) => {
|
|
76
|
-
out.push(((hi << u8(4)) | lo));
|
|
77
|
-
}
|
|
78
|
-
);
|
|
82
|
+
.Ok(lo) => {
|
|
83
|
+
out.push(((hi << u8(4)) | lo));
|
|
79
84
|
}
|
|
80
85
|
);
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
)
|
|
86
|
+
}
|
|
87
|
+
);
|
|
88
|
+
};
|
|
89
|
+
.Ok(out)
|
|
85
90
|
});
|
|
86
91
|
|
|
87
92
|
export hex_decode;
|