@shd101wyy/yo 0.1.0 → 0.1.2
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 +50 -71
- package/out/cjs/index.cjs +1266 -513
- package/out/cjs/yo-cli.cjs +1404 -649
- package/out/esm/index.mjs +1292 -539
- package/out/types/src/codegen/async/runtime-io-wasm.d.ts +4 -0
- package/out/types/src/codegen/codegen-c.d.ts +2 -0
- package/out/types/src/compiler-utils.d.ts +1 -0
- package/out/types/src/expr.d.ts +2 -0
- package/out/types/src/module-manager.d.ts +1 -0
- package/out/types/src/target.d.ts +3 -1
- package/out/types/src/test-runner.d.ts +2 -0
- package/out/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/std/build.yo +14 -0
- package/std/crypto/random.yo +21 -1
- package/std/fs/dir.yo +5 -4
- package/std/prelude.yo +12 -3
- package/std/process.yo +2 -0
- package/std/regex/index.yo +1 -1
- package/std/regex/vm.yo +4 -4
- package/std/string/string.yo +3 -3
package/package.json
CHANGED
package/std/build.yo
CHANGED
|
@@ -51,6 +51,20 @@ StepKind :: enum(
|
|
|
51
51
|
);
|
|
52
52
|
export StepKind;
|
|
53
53
|
|
|
54
|
+
// ── Compilation targets ──────────────────────────────────────────────
|
|
55
|
+
|
|
56
|
+
CompilationTarget :: {
|
|
57
|
+
X86_64_Linux_Gnu: "x86_64-linux-gnu",
|
|
58
|
+
X86_64_Linux_Musl: "x86_64-linux-musl",
|
|
59
|
+
Aarch64_Linux_Gnu: "aarch64-linux-gnu",
|
|
60
|
+
Aarch64_Macos: "aarch64-macos",
|
|
61
|
+
X86_64_Macos: "x86_64-macos",
|
|
62
|
+
X86_64_Windows_Msvc: "x86_64-windows-msvc",
|
|
63
|
+
Wasm32_Emscripten: "wasm32-emscripten",
|
|
64
|
+
Wasm32_Wasi: "wasm32-wasi"
|
|
65
|
+
};
|
|
66
|
+
export CompilationTarget;
|
|
67
|
+
|
|
54
68
|
// ── Target utilities ─────────────────────────────────────────────────
|
|
55
69
|
|
|
56
70
|
target_host :: __yo_build_target_host();
|
package/std/crypto/random.yo
CHANGED
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
// Linux/others: getrandom()
|
|
5
5
|
// macOS: arc4random_buf()
|
|
6
6
|
// Windows: BCryptGenRandom()
|
|
7
|
+
// WASI/WASM: getentropy()
|
|
7
8
|
//
|
|
8
9
|
// Example:
|
|
9
10
|
// { random_u64, uuid_v4 } :: import "std/crypto/random";
|
|
@@ -47,7 +48,8 @@ export CryptoError;
|
|
|
47
48
|
extern "Yo",
|
|
48
49
|
__yo_getrandom : (fn(buf: *(u8), buflen: usize, flags: u32) -> isize),
|
|
49
50
|
__yo_arc4random_buf: (fn(buf: *(u8), nbytes: usize) -> unit),
|
|
50
|
-
__yo_bcrypt_gen_random: (fn(buf: *(u8), size: u32) -> i32)
|
|
51
|
+
__yo_bcrypt_gen_random: (fn(buf: *(u8), size: u32) -> i32),
|
|
52
|
+
__yo_getentropy: (fn(buf: *(u8), buflen: usize) -> i32)
|
|
51
53
|
;
|
|
52
54
|
|
|
53
55
|
// ============================================================================
|
|
@@ -66,6 +68,24 @@ random_bytes :: (fn(buf: *(u8), size: usize, using(exn : Exception)) -> unit)(
|
|
|
66
68
|
true => { exn.throw(dyn CryptoError.Unavailable); }
|
|
67
69
|
);
|
|
68
70
|
},
|
|
71
|
+
((platform == Platform.Emscripten) || (platform == Platform.Wasi)) => {
|
|
72
|
+
// WASM/Emscripten/WASI: getentropy() via WASI random_get (max 256 bytes per call)
|
|
73
|
+
remaining := size;
|
|
74
|
+
offset := usize(0);
|
|
75
|
+
while (remaining > usize(0)), {
|
|
76
|
+
chunk := cond(
|
|
77
|
+
(remaining > usize(256)) => usize(256),
|
|
78
|
+
true => remaining
|
|
79
|
+
);
|
|
80
|
+
ret := __yo_getentropy((buf &+ offset), chunk);
|
|
81
|
+
cond(
|
|
82
|
+
(ret < i32(0)) => { exn.throw(dyn CryptoError.Unavailable); },
|
|
83
|
+
true => ()
|
|
84
|
+
);
|
|
85
|
+
offset = (offset + chunk);
|
|
86
|
+
remaining = (remaining - chunk);
|
|
87
|
+
};
|
|
88
|
+
},
|
|
69
89
|
true => {
|
|
70
90
|
// Linux: getrandom syscall
|
|
71
91
|
ret := __yo_getrandom(buf, size, u32(0));
|
package/std/fs/dir.yo
CHANGED
|
@@ -25,6 +25,7 @@ open import "../string";
|
|
|
25
25
|
{ Path } :: import "../path";
|
|
26
26
|
{ IOError } :: import "../sys/errors";
|
|
27
27
|
{ Error, AnyError, Exception } :: import "../error";
|
|
28
|
+
{ EEXIST, ENOENT } :: import "../libc/errno";
|
|
28
29
|
IO_dir :: import "../sys/dir";
|
|
29
30
|
IO_file :: import "../sys/file";
|
|
30
31
|
{ platform, Platform } :: import "../process";
|
|
@@ -96,9 +97,9 @@ create_dir_all :: (fn(path: Path, using(io : IO)) -> Impl(Future(unit, IO, Excep
|
|
|
96
97
|
errno := (i32(0) - result);
|
|
97
98
|
cond(
|
|
98
99
|
// Already exists is OK
|
|
99
|
-
(errno == i32(
|
|
100
|
+
(errno == i32(EEXIST)) => (),
|
|
100
101
|
// ENOENT - try to create parents
|
|
101
|
-
(errno == i32(
|
|
102
|
+
(errno == i32(ENOENT)) => {
|
|
102
103
|
// Walk the path and create each component
|
|
103
104
|
bytes := path_s.as_bytes();
|
|
104
105
|
i := usize(1);
|
|
@@ -129,7 +130,7 @@ create_dir_all :: (fn(path: Path, using(io : IO)) -> Impl(Future(unit, IO, Excep
|
|
|
129
130
|
r := io.await(IO_dir.mkdir(AT_FDCWD, prefix_cstr, i32(DEFAULT_DIR_MODE)));
|
|
130
131
|
// Ignore EEXIST errors
|
|
131
132
|
cond(
|
|
132
|
-
((r < i32(0)) && ((i32(0) - r) != i32(
|
|
133
|
+
((r < i32(0)) && ((i32(0) - r) != i32(EEXIST))) => {
|
|
133
134
|
exn.throw(dyn IOError.from_errno((i32(0) - r)));
|
|
134
135
|
},
|
|
135
136
|
true => ()
|
|
@@ -146,7 +147,7 @@ create_dir_all :: (fn(path: Path, using(io : IO)) -> Impl(Future(unit, IO, Excep
|
|
|
146
147
|
true => {
|
|
147
148
|
final_errno := (i32(0) - final_result);
|
|
148
149
|
cond(
|
|
149
|
-
(final_errno == i32(
|
|
150
|
+
(final_errno == i32(EEXIST)) => (),
|
|
150
151
|
true => exn.throw(dyn IOError.from_errno(final_errno))
|
|
151
152
|
)
|
|
152
153
|
}
|
package/std/prelude.yo
CHANGED
|
@@ -2241,8 +2241,14 @@ export f64 : _f64;
|
|
|
2241
2241
|
|
|
2242
2242
|
/// isize
|
|
2243
2243
|
impl(isize,
|
|
2244
|
-
MIN :
|
|
2245
|
-
|
|
2244
|
+
MIN : cond(
|
|
2245
|
+
(__yo_pointer_size_bits() == 32) => isize(-2147483648),
|
|
2246
|
+
true => isize(-9223372036854775808)
|
|
2247
|
+
),
|
|
2248
|
+
MAX : cond(
|
|
2249
|
+
(__yo_pointer_size_bits() == 32) => isize(2147483647),
|
|
2250
|
+
true => isize(9223372036854775807)
|
|
2251
|
+
)
|
|
2246
2252
|
);
|
|
2247
2253
|
impl(isize, Send());
|
|
2248
2254
|
impl(isize, Acyclic());
|
|
@@ -2394,7 +2400,10 @@ export isize : _isize;
|
|
|
2394
2400
|
/// usize
|
|
2395
2401
|
impl(usize,
|
|
2396
2402
|
MIN : usize(0),
|
|
2397
|
-
MAX :
|
|
2403
|
+
MAX : cond(
|
|
2404
|
+
(__yo_pointer_size_bits() == 32) => usize(4294967295),
|
|
2405
|
+
true => usize(18446744073709551615)
|
|
2406
|
+
)
|
|
2398
2407
|
);
|
|
2399
2408
|
impl(usize, Send());
|
|
2400
2409
|
impl(usize, Acyclic());
|
package/std/process.yo
CHANGED
|
@@ -14,6 +14,7 @@ open import "./path";
|
|
|
14
14
|
* - "macos"
|
|
15
15
|
* - "windows"
|
|
16
16
|
* - "freebsd"
|
|
17
|
+
* - "emscripten"
|
|
17
18
|
* - "wasi"
|
|
18
19
|
*/
|
|
19
20
|
platform :: __yo_process_platform();
|
|
@@ -24,6 +25,7 @@ Platform :: {
|
|
|
24
25
|
Macos : "macos",
|
|
25
26
|
Windows : "windows",
|
|
26
27
|
FreeBSD : "freebsd",
|
|
28
|
+
Emscripten : "emscripten",
|
|
27
29
|
Wasi : "wasi"
|
|
28
30
|
};
|
|
29
31
|
export Platform;
|
package/std/regex/index.yo
CHANGED
|
@@ -143,7 +143,7 @@ impl(Regex,
|
|
|
143
143
|
impl(Regex,
|
|
144
144
|
_build_match : (fn(self : Self, slots : ArrayList(usize), input : String) -> RegexMatch)({
|
|
145
145
|
bytes := input.as_bytes();
|
|
146
|
-
unset := usize
|
|
146
|
+
unset := usize.MAX;
|
|
147
147
|
|
|
148
148
|
match_start_byte := slots.get(usize(0)).unwrap();
|
|
149
149
|
match_end_byte := slots.get(usize(1)).unwrap();
|
package/std/regex/vm.yo
CHANGED
|
@@ -24,8 +24,8 @@ impl(NfaThread,
|
|
|
24
24
|
s := ArrayList(usize).with_capacity(n_slots);
|
|
25
25
|
i := usize(0);
|
|
26
26
|
while (i < n_slots), (i = (i + usize(1))), {
|
|
27
|
-
//
|
|
28
|
-
s.push(usize
|
|
27
|
+
// usize.MAX signals "unset"
|
|
28
|
+
s.push(usize.MAX);
|
|
29
29
|
};
|
|
30
30
|
Self(pc: pc, slots: s)
|
|
31
31
|
}),
|
|
@@ -321,7 +321,7 @@ impl(NfaVm,
|
|
|
321
321
|
// Run a sub-VM starting at sub_start_pc from start_byte.
|
|
322
322
|
// If required_end is not UNSET, only succeed when Match is found at exactly required_end.
|
|
323
323
|
_run_sub_vm : (fn(self : Self, sub_start_pc : usize, start_byte : usize, required_end : usize) -> bool)({
|
|
324
|
-
unset := usize
|
|
324
|
+
unset := usize.MAX;
|
|
325
325
|
sub_current := ArrayList(NfaThread).new();
|
|
326
326
|
sub_next := ArrayList(NfaThread).new();
|
|
327
327
|
|
|
@@ -458,7 +458,7 @@ impl(NfaVm,
|
|
|
458
458
|
best_match := VmMatch(matched: false, slots: ArrayList(usize).new());
|
|
459
459
|
byte_pos := start_byte;
|
|
460
460
|
input_len := self._bytes.len();
|
|
461
|
-
unset := usize
|
|
461
|
+
unset := usize.MAX;
|
|
462
462
|
|
|
463
463
|
while (byte_pos <= input_len), {
|
|
464
464
|
(cur_cp : u32) = u32(0);
|
package/std/string/string.yo
CHANGED
|
@@ -587,7 +587,7 @@ impl(String,
|
|
|
587
587
|
* Returns the character index of the last match, or None if not found
|
|
588
588
|
* from_index specifies the character index to start searching backwards from
|
|
589
589
|
*/
|
|
590
|
-
last_index_of : (fn(self: Self, substr: Self, (from_index : usize) ?=
|
|
590
|
+
last_index_of : (fn(self: Self, substr: Self, (from_index : usize) ?= usize.MAX) -> Option(usize))(
|
|
591
591
|
cond(
|
|
592
592
|
substr.is_empty() => .Some(self.len()),
|
|
593
593
|
true => {
|
|
@@ -786,7 +786,7 @@ impl(String,
|
|
|
786
786
|
* Check if the string ends with the specified substring (like JavaScript endsWith)
|
|
787
787
|
* end_position: The character length to consider (default is string length)
|
|
788
788
|
*/
|
|
789
|
-
ends_with : (fn(self: Self, suffix: Self, (end_position : usize) ?=
|
|
789
|
+
ends_with : (fn(self: Self, suffix: Self, (end_position : usize) ?= usize.MAX) -> bool)({
|
|
790
790
|
suffix_bytes := suffix._bytes.len();
|
|
791
791
|
self_bytes := self._bytes.len();
|
|
792
792
|
|
|
@@ -796,7 +796,7 @@ impl(String,
|
|
|
796
796
|
// Determine the effective end position in characters
|
|
797
797
|
string_char_len := self.len();
|
|
798
798
|
effective_end := cond(
|
|
799
|
-
(end_position == usize
|
|
799
|
+
(end_position == usize.MAX) => string_char_len,
|
|
800
800
|
(end_position > string_char_len) => string_char_len,
|
|
801
801
|
true => end_position
|
|
802
802
|
);
|