@shd101wyy/yo 0.1.29 → 0.1.30

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 (174) hide show
  1. package/.github/skills/yo-async-effects/SKILL.md +3 -3
  2. package/.github/skills/yo-async-effects/async-effects-recipes.md +19 -11
  3. package/.github/skills/yo-core-patterns/core-patterns-cheatsheet.md +33 -13
  4. package/.github/skills/yo-project-workflow/workflow-cheatsheet.md +1 -1
  5. package/.github/skills/yo-syntax/syntax-cheatsheet.md +59 -21
  6. package/README.md +4 -3
  7. package/out/cjs/index.cjs +771 -676
  8. package/out/cjs/yo-cli.cjs +1003 -898
  9. package/out/cjs/yo-lsp.cjs +834 -739
  10. package/out/esm/index.mjs +716 -621
  11. package/out/types/src/codegen/exprs/async.d.ts +2 -0
  12. package/out/types/src/codegen/exprs/await.d.ts +1 -0
  13. package/out/types/src/codegen/exprs/closures.d.ts +4 -0
  14. package/out/types/src/codegen/functions/context.d.ts +6 -0
  15. package/out/types/src/env.d.ts +2 -0
  16. package/out/types/src/evaluator/builtins/pragma.d.ts +9 -0
  17. package/out/types/src/evaluator/builtins/unsafe.d.ts +8 -0
  18. package/out/types/src/evaluator/context.d.ts +2 -0
  19. package/out/types/src/evaluator/index.d.ts +1 -1
  20. package/out/types/src/evaluator/memory-safety.d.ts +14 -0
  21. package/out/types/src/evaluator/types/flowability.d.ts +6 -0
  22. package/out/types/src/expr-traversal.d.ts +1 -0
  23. package/out/types/src/expr.d.ts +4 -1
  24. package/out/types/src/public-safe-report.d.ts +19 -0
  25. package/out/types/src/tests/comptime-ref-gate.test.d.ts +1 -0
  26. package/out/types/src/tests/pragma-validation.test.d.ts +1 -0
  27. package/out/types/src/tests/public-safe-report.test.d.ts +1 -0
  28. package/out/types/src/tests/type-representation-pointer.test.d.ts +1 -0
  29. package/out/types/src/tests/unsafe-gate.test.d.ts +1 -0
  30. package/out/types/src/tests/unsafe-report-classify.test.d.ts +1 -0
  31. package/out/types/src/types/definitions.d.ts +2 -0
  32. package/out/types/src/types/utils.d.ts +4 -0
  33. package/out/types/src/unsafe-report.d.ts +29 -0
  34. package/out/types/src/value.d.ts +1 -0
  35. package/out/types/tsconfig.tsbuildinfo +1 -1
  36. package/package.json +1 -1
  37. package/scripts/add-pragma-for-pointer-decls.ts +134 -0
  38. package/scripts/add-pragma.ts +58 -0
  39. package/scripts/migrate-amp-method-calls.ts +186 -0
  40. package/scripts/migrate-clone-calls.ts +93 -0
  41. package/scripts/migrate-get-unwrap.ts +166 -0
  42. package/scripts/migrate-index-patterns.ts +210 -0
  43. package/scripts/migrate-index-trait.ts +142 -0
  44. package/scripts/migrate-iterator.ts +150 -0
  45. package/scripts/migrate-self-ptr.ts +220 -0
  46. package/scripts/migrate-skip-pragmas.ts +109 -0
  47. package/scripts/migrate-tostring.ts +134 -0
  48. package/scripts/trim-pragma.ts +130 -0
  49. package/scripts/wrap-extern-calls.ts +161 -0
  50. package/std/alg/hash.yo +3 -2
  51. package/std/allocator.yo +6 -5
  52. package/std/async.yo +2 -2
  53. package/std/collections/array_list.yo +59 -40
  54. package/std/collections/btree_map.yo +19 -18
  55. package/std/collections/deque.yo +9 -8
  56. package/std/collections/hash_map.yo +101 -13
  57. package/std/collections/hash_set.yo +5 -4
  58. package/std/collections/linked_list.yo +39 -4
  59. package/std/collections/ordered_map.yo +3 -3
  60. package/std/collections/priority_queue.yo +14 -13
  61. package/std/crypto/md5.yo +2 -1
  62. package/std/crypto/random.yo +16 -15
  63. package/std/crypto/sha256.yo +2 -1
  64. package/std/encoding/base64.yo +14 -14
  65. package/std/encoding/hex.yo +3 -3
  66. package/std/encoding/json.yo +59 -10
  67. package/std/encoding/punycode.yo +24 -23
  68. package/std/encoding/toml.yo +4 -3
  69. package/std/encoding/utf16.yo +2 -2
  70. package/std/env.yo +43 -28
  71. package/std/error.yo +6 -6
  72. package/std/fmt/display.yo +2 -2
  73. package/std/fmt/index.yo +6 -5
  74. package/std/fmt/to_string.yo +39 -38
  75. package/std/fmt/writer.yo +9 -8
  76. package/std/fs/dir.yo +34 -33
  77. package/std/fs/file.yo +52 -51
  78. package/std/fs/metadata.yo +10 -9
  79. package/std/fs/temp.yo +24 -13
  80. package/std/fs/walker.yo +10 -9
  81. package/std/gc.yo +1 -0
  82. package/std/glob.yo +7 -7
  83. package/std/http/client.yo +15 -14
  84. package/std/http/http.yo +6 -6
  85. package/std/http/index.yo +1 -1
  86. package/std/imm/list.yo +33 -0
  87. package/std/imm/map.yo +2 -1
  88. package/std/imm/set.yo +1 -0
  89. package/std/imm/sorted_map.yo +1 -0
  90. package/std/imm/sorted_set.yo +1 -0
  91. package/std/imm/string.yo +27 -23
  92. package/std/imm/vec.yo +18 -2
  93. package/std/io/reader.yo +2 -1
  94. package/std/io/writer.yo +3 -2
  95. package/std/libc/assert.yo +1 -0
  96. package/std/libc/ctype.yo +1 -0
  97. package/std/libc/dirent.yo +1 -0
  98. package/std/libc/errno.yo +1 -0
  99. package/std/libc/fcntl.yo +1 -0
  100. package/std/libc/float.yo +1 -0
  101. package/std/libc/limits.yo +1 -0
  102. package/std/libc/math.yo +1 -0
  103. package/std/libc/signal.yo +1 -0
  104. package/std/libc/stdatomic.yo +1 -0
  105. package/std/libc/stdint.yo +1 -0
  106. package/std/libc/stdio.yo +1 -0
  107. package/std/libc/stdlib.yo +1 -0
  108. package/std/libc/string.yo +1 -0
  109. package/std/libc/sys/stat.yo +1 -0
  110. package/std/libc/time.yo +1 -0
  111. package/std/libc/unistd.yo +1 -0
  112. package/std/libc/wctype.yo +1 -0
  113. package/std/libc/windows.yo +2 -0
  114. package/std/log.yo +7 -6
  115. package/std/net/addr.yo +5 -4
  116. package/std/net/dns.yo +7 -6
  117. package/std/net/errors.yo +8 -8
  118. package/std/net/tcp.yo +19 -18
  119. package/std/net/udp.yo +13 -12
  120. package/std/os/signal.yo +3 -3
  121. package/std/path.yo +1 -0
  122. package/std/prelude.yo +353 -182
  123. package/std/process/command.yo +40 -23
  124. package/std/process/index.yo +2 -1
  125. package/std/regex/compiler.yo +10 -9
  126. package/std/regex/index.yo +41 -41
  127. package/std/regex/match.yo +2 -2
  128. package/std/regex/parser.yo +21 -21
  129. package/std/regex/vm.yo +42 -41
  130. package/std/string/string.yo +95 -40
  131. package/std/string/string_builder.yo +9 -9
  132. package/std/string/unicode.yo +50 -49
  133. package/std/sync/channel.yo +2 -1
  134. package/std/sync/cond.yo +5 -4
  135. package/std/sync/mutex.yo +4 -3
  136. package/std/sys/advise.yo +1 -0
  137. package/std/sys/bufio/buf_reader.yo +17 -16
  138. package/std/sys/bufio/buf_writer.yo +10 -9
  139. package/std/sys/clock.yo +1 -0
  140. package/std/sys/copy.yo +1 -0
  141. package/std/sys/dir.yo +10 -9
  142. package/std/sys/dns.yo +6 -5
  143. package/std/sys/errors.yo +11 -11
  144. package/std/sys/events.yo +1 -0
  145. package/std/sys/externs.yo +38 -37
  146. package/std/sys/file.yo +17 -16
  147. package/std/sys/future.yo +4 -3
  148. package/std/sys/iov.yo +1 -0
  149. package/std/sys/mmap.yo +1 -0
  150. package/std/sys/path.yo +1 -0
  151. package/std/sys/perm.yo +2 -1
  152. package/std/sys/pipe.yo +1 -0
  153. package/std/sys/process.yo +5 -4
  154. package/std/sys/signal.yo +1 -0
  155. package/std/sys/socketpair.yo +1 -0
  156. package/std/sys/sockinfo.yo +1 -0
  157. package/std/sys/statfs.yo +2 -1
  158. package/std/sys/statx.yo +1 -0
  159. package/std/sys/sysinfo.yo +1 -0
  160. package/std/sys/tcp.yo +15 -14
  161. package/std/sys/temp.yo +1 -0
  162. package/std/sys/time.yo +2 -1
  163. package/std/sys/timer.yo +6 -6
  164. package/std/sys/tty.yo +2 -1
  165. package/std/sys/udp.yo +13 -12
  166. package/std/sys/unix.yo +12 -11
  167. package/std/testing/bench.yo +4 -3
  168. package/std/thread.yo +7 -6
  169. package/std/time/datetime.yo +18 -15
  170. package/std/time/duration.yo +11 -10
  171. package/std/time/instant.yo +4 -4
  172. package/std/time/sleep.yo +1 -0
  173. package/std/url/index.yo +3 -3
  174. package/std/worker.yo +4 -3
@@ -9,6 +9,7 @@
9
9
  //! println(d.as_secs()); // 0
10
10
  //! println(d.as_millis()); // 500
11
11
  //! ```
12
+ pragma(Pragma.AllowUnsafe);
12
13
  { String } :: import("../string");
13
14
  { ToString } :: import("../fmt");
14
15
  { snprintf } :: import("../libc/stdio");
@@ -40,27 +41,27 @@ impl(
40
41
  Self(secs : (nanos / i64(1000000000)), nanos : (nanos % i64(1000000000)))
41
42
  ),
42
43
  // Total whole seconds in the duration.
43
- as_secs : (fn(self : *(Self)) -> i64)(
44
+ as_secs : (fn(ref(self) : Self) -> i64)(
44
45
  self.secs
45
46
  ),
46
47
  // Total milliseconds (truncated).
47
- as_millis : (fn(self : *(Self)) -> i64)(
48
+ as_millis : (fn(ref(self) : Self) -> i64)(
48
49
  (self.secs * i64(1000)) + (self.nanos / i64(1000000))
49
50
  ),
50
51
  // Total microseconds (truncated).
51
- as_micros : (fn(self : *(Self)) -> i64)(
52
+ as_micros : (fn(ref(self) : Self) -> i64)(
52
53
  (self.secs * i64(1000000)) + (self.nanos / i64(1000))
53
54
  ),
54
55
  // Total nanoseconds.
55
- as_nanos : (fn(self : *(Self)) -> i64)(
56
+ as_nanos : (fn(ref(self) : Self) -> i64)(
56
57
  (self.secs * i64(1000000000)) + self.nanos
57
58
  ),
58
59
  // Total seconds as a floating-point number.
59
- as_secs_f64 : (fn(self : *(Self)) -> f64)(
60
+ as_secs_f64 : (fn(ref(self) : Self) -> f64)(
60
61
  f64(self.secs) + (f64(self.nanos) / f64(1000000000.0))
61
62
  ),
62
63
  // Add two durations together.
63
- add : (fn(self : *(Self), other : Duration) -> Duration)({
64
+ add : (fn(ref(self) : Self, other : Duration) -> Duration)({
64
65
  total_nanos := (self.nanos + other.nanos);
65
66
  carry := (total_nanos / i64(1000000000));
66
67
  Duration(
@@ -69,7 +70,7 @@ impl(
69
70
  )
70
71
  }),
71
72
  // Subtract another duration (saturates to zero if negative).
72
- sub : (fn(self : *(Self), other : Duration) -> Duration)({
73
+ sub : (fn(ref(self) : Self, other : Duration) -> Duration)({
73
74
  self_ns := self.as_nanos();
74
75
  other_ns := other.as_nanos();
75
76
  cond(
@@ -78,17 +79,17 @@ impl(
78
79
  )
79
80
  }),
80
81
  // Return true if this duration is zero.
81
- is_zero : (fn(self : *(Self)) -> bool)(
82
+ is_zero : (fn(ref(self) : Self) -> bool)(
82
83
  (self.secs == i64(0)) && (self.nanos == i64(0))
83
84
  )
84
85
  );
85
86
  impl(
86
87
  Duration,
87
88
  ToString(
88
- to_string : (fn(self : *(Self)) -> String)({
89
+ to_string : (fn(ref(self) : Self) -> String)({
89
90
  buf := Array(u8, usize(64)).fill(u8(0));
90
91
  buf_ptr := &(buf(usize(0)));
91
- snprintf(*(char)(buf_ptr), usize(64), "%llds %lldns", self.secs, self.nanos);
92
+ unsafe(snprintf(*(char)(buf_ptr), usize(64), "%llds %lldns", self.secs, self.nanos));
92
93
  String.from_cstr(buf_ptr).unwrap()
93
94
  })
94
95
  )
@@ -10,6 +10,7 @@
10
10
  //! elapsed := start.elapsed();
11
11
  //! println(elapsed.as_millis());
12
12
  //! ```
13
+ pragma(Pragma.AllowUnsafe);
13
14
  { Duration } :: import("./duration");
14
15
  { CLOCK_MONOTONIC, clock_gettime } :: import("../sys/clock");
15
16
  /// Snapshot from the monotonic clock. Use `elapsed` to measure durations.
@@ -29,7 +30,7 @@ impl(
29
30
  }),
30
31
  // Duration between this instant and an earlier one.
31
32
  // Returns Duration.zero() if `earlier` is actually later.
32
- duration_since : (fn(self : *(Self), earlier : Instant) -> Duration)({
33
+ duration_since : (fn(ref(self) : Self, earlier : Instant) -> Duration)({
33
34
  self_ns := ((self.secs * i64(1000000000)) + self.nanos);
34
35
  earlier_ns := ((earlier.secs * i64(1000000000)) + earlier.nanos);
35
36
  cond(
@@ -38,10 +39,9 @@ impl(
38
39
  )
39
40
  }),
40
41
  // Duration elapsed since this instant was created.
41
- elapsed : (fn(self : *(Self)) -> Duration)({
42
+ elapsed : (fn(ref(self) : Self) -> Duration)({
42
43
  current := Instant.now();
43
- cur_ptr := (&(current));
44
- cur_ptr.duration_since(self.*)
44
+ current.duration_since(self)
45
45
  })
46
46
  );
47
47
  export(Instant);
package/std/time/sleep.yo CHANGED
@@ -6,6 +6,7 @@
6
6
  //! { sleep } :: import "std/time/sleep";
7
7
  //! sleep(usize(100)); // sleep 100ms
8
8
  //! ```
9
+ pragma(Pragma.AllowUnsafe);
9
10
  extern(
10
11
  "Yo",
11
12
  __yo_ms_sleep : (fn(ms : usize) -> unit)
package/std/url/index.yo CHANGED
@@ -234,7 +234,7 @@ impl(
234
234
  after_bracket := (bracket_end + usize(1));
235
235
  cond(
236
236
  ((after_bracket < auth_end) && (s.bytes(after_bracket) == _COLON)) => {
237
- port =.Some(_parse_port(s, after_bracket + usize(1), auth_end));
237
+ port =.Some(_parse_port(s, after_bracket + usize(1), auth_end, exn));
238
238
  },
239
239
  true => ()
240
240
  );
@@ -264,7 +264,7 @@ impl(
264
264
  hh2 = (hh2 + usize(1));
265
265
  });
266
266
  host =.Some(String.from_bytes(host_b));
267
- port =.Some(_parse_port(s, cp_val + usize(1), auth_end));
267
+ port =.Some(_parse_port(s, cp_val + usize(1), auth_end, exn));
268
268
  },
269
269
  .None => {
270
270
  // No port, entire range is host
@@ -363,7 +363,7 @@ impl(
363
363
  );
364
364
  // Ensure authority-based URLs have a path starting with "/" or empty
365
365
  cond(
366
- (has_authority && ((!(path_str.is_empty())) && (path_str.as_bytes().get(usize(0)).unwrap() != _SLASH))) => {
366
+ (has_authority && ((!(path_str.is_empty())) && (path_str.as_bytes()(usize(0)) != _SLASH))) => {
367
367
  exn.throw(dyn(UrlError.Other(`authority path must start with '/'`)));
368
368
  },
369
369
  true => ()
package/std/worker.yo CHANGED
@@ -1,16 +1,17 @@
1
1
  //! Thread pool with per-core thread affinity and round-robin task distribution.
2
2
  //!
3
3
  //! Each task is pinned to a worker thread (no work stealing).
4
- //! Each worker thread has its own GC heap and async IO event loop.
4
+ //! Each worker thread has its own GC heap and async Io event loop.
5
+ pragma(Pragma.AllowUnsafe);
5
6
  extern(
6
7
  "Yo",
7
- __yo_worker_spawn : (fn(cb : Impl(Fn(io : IO) -> unit, Send)) -> unit),
8
+ __yo_worker_spawn : (fn(cb : Impl(Fn(io : Io) -> unit, Send)) -> unit),
8
9
  __yo_worker_get_num_threads : (fn() -> usize),
9
10
  __yo_worker_set_num_threads : (fn(num : usize) -> unit)
10
11
  );
11
12
  /// Spawn a task on the thread pool. Returns immediately; the task runs in the background.
12
13
  /// Tasks are distributed round-robin to worker threads.
13
- spawn :: (fn(cb : Impl(Fn(io : IO) -> unit, Send)) -> unit)({
14
+ spawn :: (fn(cb : Impl(Fn(io : Io) -> unit, Send)) -> unit)({
14
15
  __yo_worker_spawn(cb);
15
16
  });
16
17
  /// Get the number of worker threads in the pool.