@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.
Files changed (97) hide show
  1. package/out/cjs/index.cjs +560 -520
  2. package/out/cjs/yo-cli.cjs +598 -558
  3. package/out/esm/index.mjs +551 -511
  4. package/out/types/src/codegen/exprs/arc.d.ts +5 -0
  5. package/out/types/src/codegen/types/generation.d.ts +2 -0
  6. package/out/types/src/codegen/utils/index.d.ts +8 -1
  7. package/out/types/src/evaluator/builtins/rc-fns.d.ts +5 -0
  8. package/out/types/src/evaluator/calls/arc.d.ts +15 -0
  9. package/out/types/src/evaluator/calls/trait-type.d.ts +8 -1
  10. package/out/types/src/evaluator/context.d.ts +11 -1
  11. package/out/types/src/evaluator/types/utils.d.ts +8 -3
  12. package/out/types/src/evaluator/utils/closure.d.ts +7 -1
  13. package/out/types/src/evaluator/values/impl.d.ts +8 -0
  14. package/out/types/src/expr.d.ts +6 -0
  15. package/out/types/src/test-runner.d.ts +2 -0
  16. package/out/types/src/types/creators.d.ts +2 -1
  17. package/out/types/src/types/definitions.d.ts +10 -0
  18. package/out/types/src/types/guards.d.ts +2 -1
  19. package/out/types/src/types/tags.d.ts +1 -0
  20. package/out/types/tsconfig.tsbuildinfo +1 -1
  21. package/package.json +1 -1
  22. package/std/collections/array_list.yo +80 -10
  23. package/std/collections/btree_map.yo +120 -2
  24. package/std/collections/deque.yo +98 -6
  25. package/std/collections/hash_map.yo +137 -1
  26. package/std/collections/hash_set.yo +85 -1
  27. package/std/collections/linked_list.yo +61 -1
  28. package/std/collections/priority_queue.yo +70 -1
  29. package/std/crypto/md5.yo +4 -4
  30. package/std/crypto/random.yo +3 -3
  31. package/std/crypto/sha256.yo +8 -7
  32. package/std/encoding/base64.yo +6 -6
  33. package/std/encoding/hex.yo +27 -22
  34. package/std/encoding/json.yo +185 -186
  35. package/std/encoding/utf16.yo +2 -2
  36. package/std/fmt/display.yo +1 -1
  37. package/std/fmt/writer.yo +2 -4
  38. package/std/fs/dir.yo +5 -5
  39. package/std/fs/file.yo +21 -13
  40. package/std/fs/metadata.yo +4 -4
  41. package/std/fs/temp.yo +3 -3
  42. package/std/fs/types.yo +1 -1
  43. package/std/fs/walker.yo +1 -1
  44. package/std/net/addr.yo +2 -2
  45. package/std/net/dns.yo +21 -20
  46. package/std/net/errors.yo +1 -1
  47. package/std/net/tcp.yo +134 -100
  48. package/std/net/udp.yo +51 -42
  49. package/std/os/env.yo +21 -23
  50. package/std/os/signal.yo +10 -9
  51. package/std/prelude.yo +158 -22
  52. package/std/string/string.yo +99 -1
  53. package/std/sync/once.yo +1 -1
  54. package/std/{io → sys}/advise.yo +1 -1
  55. package/std/sys/bufio/buf_reader.yo +300 -0
  56. package/std/sys/bufio/buf_writer.yo +168 -0
  57. package/std/{io → sys}/clock.yo +1 -1
  58. package/std/{io → sys}/constants.yo +1 -1
  59. package/std/{io → sys}/copy.yo +1 -1
  60. package/std/{io → sys}/dir.yo +6 -6
  61. package/std/{io → sys}/dns.yo +3 -3
  62. package/std/{io → sys}/errors.yo +1 -1
  63. package/std/{io → sys}/events.yo +1 -1
  64. package/std/{io → sys}/externs.yo +1 -1
  65. package/std/{io → sys}/fallocate.yo +1 -1
  66. package/std/{io → sys}/fcntl.yo +1 -1
  67. package/std/{io → sys}/file.yo +1 -1
  68. package/std/{io → sys}/future.yo +1 -1
  69. package/std/{io → sys}/iov.yo +1 -1
  70. package/std/{io → sys}/lock.yo +1 -1
  71. package/std/{io → sys}/mmap.yo +1 -1
  72. package/std/{io → sys}/path.yo +1 -1
  73. package/std/{io → sys}/perm.yo +3 -3
  74. package/std/{io → sys}/pipe.yo +1 -1
  75. package/std/{io → sys}/process.yo +1 -1
  76. package/std/{io → sys}/seek.yo +1 -1
  77. package/std/{io → sys}/signal.yo +1 -1
  78. package/std/{io → sys}/signals.yo +1 -1
  79. package/std/{io → sys}/socket.yo +1 -1
  80. package/std/{io → sys}/socketpair.yo +1 -1
  81. package/std/{io → sys}/sockinfo.yo +1 -1
  82. package/std/{io → sys}/statfs.yo +2 -2
  83. package/std/{io → sys}/statx.yo +1 -1
  84. package/std/{io → sys}/sysinfo.yo +1 -1
  85. package/std/{io → sys}/tcp.yo +3 -3
  86. package/std/{io → sys}/temp.yo +1 -1
  87. package/std/{io → sys}/time.yo +2 -2
  88. package/std/{io → sys}/timer.yo +1 -1
  89. package/std/{io → sys}/tty.yo +1 -1
  90. package/std/{io → sys}/udp.yo +4 -4
  91. package/std/{io → sys}/umask.yo +1 -1
  92. package/std/{io → sys}/unix.yo +1 -1
  93. package/std/time/datetime.yo +18 -23
  94. package/std/time/instant.yo +13 -11
  95. package/std/url/url.yo +533 -0
  96. package/std/math/functions.yo +0 -74
  97. package/std/math/random.yo +0 -94
@@ -1,4 +1,4 @@
1
- // std/io/socketpair.yo - Connected socket pair
1
+ // std/sys/socketpair.yo - Connected socket pair
2
2
  //
3
3
  // Synchronous wrapper for socketpair-like behavior.
4
4
  // Returns 0 on success, negative error on failure.
@@ -1,4 +1,4 @@
1
- // std/io/sockinfo.yo - Socket address and option query helpers
1
+ // std/sys/sockinfo.yo - Socket address and option query helpers
2
2
  //
3
3
  // Synchronous wrappers for socket metadata operations.
4
4
  // Returns 0 on success, -errno (or negative platform socket error) on failure.
@@ -1,4 +1,4 @@
1
- // std/io/statfs.yo - Filesystem statistics
1
+ // std/sys/statfs.yo - Filesystem statistics
2
2
  //
3
3
  // Provides a synchronous wrapper around statfs and typed accessors
4
4
  // for the statfs buffer returned by the C runtime.
@@ -8,7 +8,7 @@
8
8
  // - Negative value: -errno on failure
9
9
  //
10
10
  // Example:
11
- // statfs :: import "std/io/statfs";
11
+ // statfs :: import "std/sys/statfs";
12
12
  //
13
13
  // buf_size := statfs.statfs_buf_size();
14
14
  // buf := *(u8)(malloc(buf_size).unwrap());
@@ -1,4 +1,4 @@
1
- // std/io/statx.yo - Statx file status type
1
+ // std/sys/statx.yo - Statx file status type
2
2
  //
3
3
  // Object wrapper around the C statx buffer, providing
4
4
  // accessor methods for file metadata.
@@ -1,4 +1,4 @@
1
- // std/io/sysinfo.yo - Runtime system identification
1
+ // std/sys/sysinfo.yo - Runtime system identification
2
2
  //
3
3
  // Synchronous wrappers for uname/gethostname.
4
4
  // Returns 0 on success, -errno / negative platform error on failure.
@@ -1,4 +1,4 @@
1
- // std/io/tcp.yo - Async TCP socket operations
1
+ // std/sys/tcp.yo - Async TCP socket operations
2
2
  //
3
3
  // Provides TCP socket wrappers around the low-level C runtime externs.
4
4
  // Uses the socket address helpers to construct sockaddr_in/sockaddr_in6 buffers.
@@ -10,8 +10,8 @@
10
10
  // Example:
11
11
  // { GlobalAllocator } :: import "../allocator.yo";
12
12
  // { malloc, free } :: GlobalAllocator;
13
- // tcp :: import "std/io/tcp";
14
- // { AF_INET, SOCK_STREAM, SOL_SOCKET, SO_REUSEADDR, IPPROTO_TCP } :: import "std/io/socket";
13
+ // tcp :: import "std/sys/tcp";
14
+ // { AF_INET, SOCK_STREAM, SOL_SOCKET, SO_REUSEADDR, IPPROTO_TCP } :: import "std/sys/socket";
15
15
  //
16
16
  // async {
17
17
  // // Create a TCP socket
@@ -1,4 +1,4 @@
1
- // std/io/temp.yo - Temporary file/directory operations
1
+ // std/sys/temp.yo - Temporary file/directory operations
2
2
  //
3
3
  // Synchronous wrappers for mkdtemp/mkstemp.
4
4
  // These are inherently synchronous on all platforms.
@@ -1,4 +1,4 @@
1
- // std/io/time.yo - File timestamp operations
1
+ // std/sys/time.yo - File timestamp operations
2
2
  //
3
3
  // Provides synchronous wrappers for utime/futime/lutime to change file timestamps.
4
4
  // All operations return i32 directly (no IOFuture overhead).
@@ -12,7 +12,7 @@
12
12
  // or UTIME_OMIT (0x3ffffffe) to leave a timestamp unchanged.
13
13
  //
14
14
  // Example:
15
- // time :: import "std/io/time";
15
+ // time :: import "std/sys/time";
16
16
  //
17
17
  // // Set both atime and mtime to specific values
18
18
  // ret := time.utime(*(u8)("/tmp/test.txt"), i64(1000000), i64(0), i64(2000000), i64(0));
@@ -1,4 +1,4 @@
1
- // std/io/timer.yo - Async timer operations
1
+ // std/sys/timer.yo - Async timer operations
2
2
  //
3
3
  // Provides high-level async timer functions:
4
4
  // sleep(ms) - async sleep for the given number of milliseconds
@@ -1,4 +1,4 @@
1
- // std/io/tty.yo - TTY operations
1
+ // std/sys/tty.yo - TTY operations
2
2
 
3
3
  { __yo_tty_init, __yo_tty_set_mode, __yo_tty_reset_mode, __yo_tty_get_winsize, __yo_isatty } :: import "./externs.yo";
4
4
  { TTY_MODE_NORMAL, TTY_MODE_RAW, TTY_MODE_IO } :: import "./events.yo";
@@ -1,4 +1,4 @@
1
- // std/io/udp.yo - Async UDP socket operations
1
+ // std/sys/udp.yo - Async UDP socket operations
2
2
  //
3
3
  // Provides UDP socket wrappers around the low-level C runtime externs.
4
4
  // Reuses SockAddr and address helpers from tcp.yo.
@@ -10,9 +10,9 @@
10
10
  // Example:
11
11
  // { GlobalAllocator } :: import "../allocator.yo";
12
12
  // { malloc, free } :: GlobalAllocator;
13
- // udp :: import "std/io/udp";
14
- // tcp :: import "std/io/tcp";
15
- // { AF_INET, SOCK_DGRAM } :: import "std/io/socket";
13
+ // udp :: import "std/sys/udp";
14
+ // tcp :: import "std/sys/tcp";
15
+ // { AF_INET, SOCK_DGRAM } :: import "std/sys/socket";
16
16
  //
17
17
  // async {
18
18
  // sockfd := await udp.socket(AF_INET, i32(0));
@@ -1,4 +1,4 @@
1
- // std/io/umask.yo - Process file creation mask
1
+ // std/sys/umask.yo - Process file creation mask
2
2
  //
3
3
  // Synchronous wrapper for setting process umask.
4
4
  // Returns previous mask value.
@@ -1,4 +1,4 @@
1
- // std/io/unix.yo - Unix domain socket operations
1
+ // std/sys/unix.yo - Unix domain socket operations
2
2
  //
3
3
  // Provides Unix domain socket wrappers around the low-level C runtime externs.
4
4
  // Reuses the socket ops (bind/listen/accept/connect/send/recv/close) from the
@@ -11,7 +11,7 @@
11
11
 
12
12
  { String } :: import "../string";
13
13
  { ToString } :: import "../fmt";
14
- { CLOCK_REALTIME, clock_gettime } :: import "../io/clock";
14
+ { CLOCK_REALTIME, clock_gettime } :: import "../sys/clock";
15
15
  { snprintf } :: import "../libc/stdio";
16
16
 
17
17
  // ============================================================================
@@ -46,9 +46,13 @@ _from_unix_secs :: (fn(secs: i64, nanos: i64) -> DateTime)({
46
46
  rem := (secs % i64(86400));
47
47
 
48
48
  // Normalise negative remainders
49
- (rem_adj, days_adj) := cond(
50
- (rem < i64(0)) => struct(rem_v: (rem + i64(86400)), days_v: (days - i64(1))),
51
- true => struct(rem_v: rem, days_v: days)
49
+ rem_adj := cond(
50
+ (rem < i64(0)) => (rem + i64(86400)),
51
+ true => rem
52
+ );
53
+ days_adj := cond(
54
+ (rem < i64(0)) => (days - i64(1)),
55
+ true => days
52
56
  );
53
57
 
54
58
  hour := u8((rem_adj / i64(3600)));
@@ -65,7 +69,7 @@ _from_unix_secs :: (fn(secs: i64, nanos: i64) -> DateTime)({
65
69
  );
66
70
  doe := (z - (era * i64(146097)));
67
71
  yoe := (((doe - (doe / i64(1460))) + (doe / i64(36524))) - (doe / i64(146096)));
68
- yoe := (yoe / i64(365));
72
+ yoe = (yoe / i64(365));
69
73
  y := (yoe + (era * i64(400)));
70
74
  doy := (doe - (((i64(365) * yoe) + (yoe / i64(4))) - (yoe / i64(100))));
71
75
  mp := (((i64(5) * doy) + i64(2)) / i64(153));
@@ -96,7 +100,7 @@ impl(DateTime,
96
100
  now_utc : (fn() -> Self)({
97
101
  sec := i64(0);
98
102
  nsec := i64(0);
99
- clock_gettime(CLOCK_REALTIME, &sec, &nsec);
103
+ clock_gettime(CLOCK_REALTIME, (&sec), (&nsec));
100
104
  _from_unix_secs(sec, nsec)
101
105
  }),
102
106
 
@@ -131,8 +135,8 @@ impl(DateTime,
131
135
  );
132
136
  doy := ((((i64(153) * mp) + i64(2)) / i64(5)) + (d - i64(1)));
133
137
  doe := ((((yoe * i64(365)) + (yoe / i64(4))) - (yoe / i64(100))) + doy);
134
- days := ((era * i64(146097)) + doe - i64(719468));
135
- time_secs := ((i64(self.hour) * i64(3600)) + (i64(self.minute) * i64(60)) + i64(self.second));
138
+ days := (((era * i64(146097)) + doe) - i64(719468));
139
+ time_secs := (((i64(self.hour) * i64(3600)) + (i64(self.minute) * i64(60))) + i64(self.second));
136
140
  ((days * i64(86400)) + time_secs)
137
141
  }),
138
142
 
@@ -152,7 +156,8 @@ impl(DateTime,
152
156
  (i32(self.month) < i32(3)) => (self.year - i32(1)),
153
157
  true => self.year
154
158
  );
155
- dow := ((y + (y / i32(4)) - (y / i32(100)) + (y / i32(400)) + t(usize((i32(self.month) - i32(1)))) + i32(self.day)) % i32(7));
159
+ sum := (((((y + (y / i32(4))) - (y / i32(100))) + (y / i32(400))) + t(usize((i32(self.month) - i32(1))))) + i32(self.day));
160
+ dow := (sum % i32(7));
156
161
  // Convert: 0=Sun → remap to 0=Mon
157
162
  u8(cond(
158
163
  (dow == i32(0)) => i32(6),
@@ -179,9 +184,10 @@ impl(DateTime,
179
184
  );
180
185
  };
181
186
  u16(days)
182
- }),
187
+ })
188
+ );
183
189
 
184
- // Format as ISO 8601 UTC string: "YYYY-MM-DDTHH:MM:SSZ"
190
+ impl(DateTime, ToString(
185
191
  to_string : (fn(self: *(Self)) -> String)({
186
192
  buf := Array(u8, usize(32)).fill(u8(0));
187
193
  buf_ptr := &(buf(usize(0)));
@@ -189,18 +195,7 @@ impl(DateTime,
189
195
  self.year, self.month, self.day,
190
196
  self.hour, self.minute, self.second);
191
197
  String.from_cstr(buf_ptr).unwrap()
192
- }),
193
-
194
- // Alias to to_string.
195
- format : (fn(self: *(Self), _fmt: str) -> String)(
196
- self.to_string()
197
- )
198
- );
199
-
200
- impl(DateTime, ToString(
201
- to_string : (fn(self: *(Self)) -> String)(
202
- self.to_string()
203
- )
198
+ })
204
199
  ));
205
200
 
206
201
  export DateTime;
@@ -12,7 +12,7 @@
12
12
  // println(elapsed.as_millis());
13
13
 
14
14
  { Duration } :: import "./duration";
15
- { CLOCK_MONOTONIC, clock_gettime } :: import "../io/clock";
15
+ { CLOCK_MONOTONIC, clock_gettime } :: import "../sys/clock";
16
16
 
17
17
  // ============================================================================
18
18
  // Instant - monotonic clock snapshot
@@ -26,16 +26,11 @@ Instant :: struct(
26
26
  impl(Instant,
27
27
  // Capture the current monotonic time.
28
28
  now : (fn() -> Self)({
29
- sec := i64(0);
30
- nsec := i64(0);
31
- clock_gettime(CLOCK_MONOTONIC, &sec, &nsec);
32
- Self(secs: sec, nanos: nsec)
33
- }),
34
-
35
- // Duration elapsed since this instant was created.
36
- elapsed : (fn(self: *(Self)) -> Duration)({
37
- now := Instant.now();
38
- now.duration_since(self.*)
29
+ clk := CLOCK_MONOTONIC;
30
+ out_s := i64(0);
31
+ out_ns := i64(0);
32
+ clock_gettime(clk, (&out_s), (&out_ns));
33
+ Self(secs: out_s, nanos: out_ns)
39
34
  }),
40
35
 
41
36
  // Duration between this instant and an earlier one.
@@ -47,6 +42,13 @@ impl(Instant,
47
42
  (self_ns <= earlier_ns) => Duration.zero(),
48
43
  true => Duration.from_nanos((self_ns - earlier_ns))
49
44
  )
45
+ }),
46
+
47
+ // Duration elapsed since this instant was created.
48
+ elapsed : (fn(self: *(Self)) -> Duration)({
49
+ current := Instant.now();
50
+ cur_ptr := (&(current));
51
+ cur_ptr.duration_since(self.*)
50
52
  })
51
53
  );
52
54