@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
package/std/libc/time.yo CHANGED
@@ -1,4 +1,5 @@
1
1
  //! C11 `<time.h>` — date and time functions.
2
+ pragma(Pragma.AllowUnsafe);
2
3
  c_include(
3
4
  "<time.h>",
4
5
  // Types
@@ -1,4 +1,5 @@
1
1
  //! POSIX `<unistd.h>` — standard symbolic constants and types.
2
+ pragma(Pragma.AllowUnsafe);
2
3
  c_include(
3
4
  "<unistd.h>",
4
5
  // Types
@@ -1,4 +1,5 @@
1
1
  //! C11 `<wctype.h>` — wide character classification and conversion functions.
2
+ pragma(Pragma.AllowUnsafe);
2
3
  { wint_t } :: import("./stdint");
3
4
  c_include(
4
5
  "<wctype.h>",
@@ -1,6 +1,8 @@
1
1
  //! Windows-specific C API bindings.
2
2
  //! Only available when compiling for Windows.
3
3
  // Windows type aliases (using Yo types that match the C types)
4
+ pragma(Pragma.AllowUnsafe);
5
+ pragma(Pragma.AllowUnsafe);
4
6
  DWORD :: ulong; // unsigned long on Windows
5
7
  WCHAR :: ushort; // unsigned short (UTF-16 code unit)
6
8
  BOOL :: int; // int
package/std/log.yo CHANGED
@@ -1,4 +1,5 @@
1
1
  //! Structured logging with configurable level and output destination.
2
+ pragma(Pragma.AllowUnsafe);
2
3
  open(import("./string"));
3
4
  { ToString } :: import("./fmt");
4
5
  { fwrite, stdout, stderr, FILE } :: import("./libc/stdio");
@@ -7,9 +8,9 @@ Level :: enum(Trace, Debug, Info, Warn, Error);
7
8
  impl(
8
9
  Level,
9
10
  ToString(
10
- to_string : (fn(self : *(Self)) -> String)(
11
+ to_string : (fn(ref(self) : Self) -> String)(
11
12
  match(
12
- self.*,
13
+ self,
13
14
  .Trace => String.from("TRACE"),
14
15
  .Debug => String.from("DEBUG"),
15
16
  .Info => String.from("INFO "),
@@ -60,7 +61,7 @@ _write_string :: (fn(s : String, dest : *(FILE)) -> unit)({
60
61
  cond(
61
62
  (bytes.len() > usize(0)) => {
62
63
  ptr := bytes.ptr().unwrap();
63
- fwrite(*(void)(ptr), usize(1), bytes.len(), dest);
64
+ unsafe(fwrite(*(void)(ptr), usize(1), bytes.len(), dest));
64
65
  },
65
66
  true => ()
66
67
  );
@@ -79,11 +80,11 @@ log :: (fn(level : Level, msg : String) -> unit)({
79
80
  .Stderr => stderr
80
81
  );
81
82
  // Write "[LEVEL] msg\n"
82
- fwrite(*(void)(*(u8)("[")), usize(1), usize(1), dest);
83
+ unsafe(fwrite(*(void)(*(u8)("[")), usize(1), usize(1), dest));
83
84
  _write_string(level_str, dest);
84
- fwrite(*(void)(*(u8)("] ")), usize(1), usize(2), dest);
85
+ unsafe(fwrite(*(void)(*(u8)("] ")), usize(1), usize(2), dest));
85
86
  _write_string(msg, dest);
86
- fwrite(*(void)(*(u8)("\n")), usize(1), usize(1), dest);
87
+ unsafe(fwrite(*(void)(*(u8)("\n")), usize(1), usize(1), dest));
87
88
  });
88
89
  export(log);
89
90
  // ============================================================================
package/std/net/addr.yo CHANGED
@@ -7,6 +7,7 @@
7
7
  // { IpAddr, SocketAddr } :: import "std/net/addr";
8
8
  //
9
9
  // addr := SocketAddr.new(IpAddr.loopback_v4(), u16(8080));
10
+ pragma(Pragma.AllowUnsafe);
10
11
  open(import("../string"));
11
12
  { ToString } :: import("../fmt");
12
13
  { Writer } :: import("../fmt/writer");
@@ -40,7 +41,7 @@ impl(
40
41
  val := u32(0);
41
42
  i := usize(0);
42
43
  while(runtime(i < bytes.len()), {
43
- ch := bytes.get(i).unwrap();
44
+ ch := bytes(i);
44
45
  cond(
45
46
  (ch == _ASCII_DOT) => {
46
47
  // '.' separator
@@ -145,10 +146,10 @@ impl(
145
146
  self -> {
146
147
  return(
147
148
  match(
148
- self.*,
149
+ self,
149
150
  .V4(a, b, c, d) => {
150
151
  buf := Array(u8, usize(16)).fill(u8(0));
151
- snprintf(*(char)(&(buf(usize(0)))), usize(16), "%d.%d.%d.%d", i32(a), i32(b), i32(c), i32(d));
152
+ unsafe(snprintf(*(char)(&(buf(usize(0)))), usize(16), "%d.%d.%d.%d", i32(a), i32(b), i32(c), i32(d)));
152
153
  String.from_cstr(&(buf(usize(0)))).unwrap()
153
154
  },
154
155
  .V6(segs) => {
@@ -205,7 +206,7 @@ impl(
205
206
  self -> {
206
207
  ip_str := self.ip.to_string();
207
208
  buf := Array(u8, usize(8)).fill(u8(0));
208
- snprintf(*(char)(&(buf(usize(0)))), usize(8), "%d", i32(self.port));
209
+ unsafe(snprintf(*(char)(&(buf(usize(0)))), usize(8), "%d", i32(self.port)));
209
210
  port_str := String.from_cstr(&(buf(usize(0)))).unwrap();
210
211
  return(
211
212
  match(
package/std/net/dns.yo CHANGED
@@ -9,14 +9,15 @@
9
9
  // { IpAddr } :: import "std/net/addr";
10
10
  // { Exception } :: import "std/error";
11
11
  //
12
- // main :: (fn(io : IO, exn : Exception) -> unit)({
12
+ // main :: (fn(io : Io, exn : Exception) -> unit)({
13
13
  // addrs := io.await(lookup_host(`localhost`, io), { io, exn });
14
14
  // i := usize(0);
15
15
  // while runtime((i < addrs.len())), {
16
- // println(addrs.get(i).unwrap().to_string());
16
+ // println(addrs(i).to_string());
17
17
  // i = (i + usize(1));
18
18
  // };
19
19
  // });
20
+ pragma(Pragma.AllowUnsafe);
20
21
  { GlobalAllocator } :: import("../allocator");
21
22
  { malloc, free } :: GlobalAllocator;
22
23
  { ArrayList } :: import("../collections/array_list");
@@ -24,14 +25,14 @@ open(import("../string"));
24
25
  open(import("../fmt"));
25
26
  { NetError } :: import("./errors");
26
27
  { IpAddr, SocketAddr } :: import("./addr");
27
- { Error, AnyError, Exception, IOErr } :: import("../error");
28
+ { Error, AnyError, Exception, IoExn } :: import("../error");
28
29
  IO_dns :: import("../sys/dns");
29
30
  { AF_INET, AF_INET6 } :: import("../sys/socket");
30
31
  // ============================================================================
31
32
  // DNS lookup
32
33
  // ============================================================================
33
34
  /// Resolve a hostname to a list of IP addresses.
34
- lookup_host :: (fn(host : String, io : IO) -> Impl(Future(ArrayList(IpAddr), IOErr)))(
35
+ lookup_host :: (fn(host : String, io : Io) -> Impl(Future(ArrayList(IpAddr), IoExn)))(
35
36
  io.async((e) => {
36
37
  host_cstr_bytes := host.to_cstr();
37
38
  host_cstr := host_cstr_bytes.ptr().unwrap();
@@ -82,13 +83,13 @@ lookup_host :: (fn(host : String, io : IO) -> Impl(Future(ArrayList(IpAddr), IOE
82
83
  })
83
84
  );
84
85
  /// Resolve a hostname and port to a list of socket addresses.
85
- resolve :: (fn(host : String, port : u16, io : IO) -> Impl(Future(ArrayList(SocketAddr), IOErr)))(
86
+ resolve :: (fn(host : String, port : u16, io : Io) -> Impl(Future(ArrayList(SocketAddr), IoExn)))(
86
87
  io.async((e) => {
87
88
  addrs := e.io.await(lookup_host(host, io), e);
88
89
  result := ArrayList(SocketAddr).new();
89
90
  i := usize(0);
90
91
  while(runtime(i < addrs.len()), {
91
- ip := addrs.get(i).unwrap();
92
+ ip := addrs(i);
92
93
  result.push(SocketAddr.new(ip, port));
93
94
  i = (i + usize(1));
94
95
  });
package/std/net/errors.yo CHANGED
@@ -1,12 +1,12 @@
1
1
  //! Network error types.
2
2
  // std/net/errors.yo - Network error type
3
3
  //
4
- // Higher-level network error that wraps IOError with network-specific variants.
4
+ // Higher-level network error that wraps IoError with network-specific variants.
5
5
  //
6
6
  // Example:
7
7
  // { NetError } :: import "std/net/errors";
8
8
  open(import("../string"));
9
- { IOError } :: import("../sys/errors");
9
+ { IoError } :: import("../sys/errors");
10
10
  { ToString } :: import("../fmt");
11
11
  { Error, AnyError, Exception } :: import("../error");
12
12
  // ============================================================================
@@ -33,14 +33,14 @@ NetError :: enum(
33
33
  /// DNS resolution failed.
34
34
  DNSFailed(msg : String),
35
35
  /// A wrapped lower-level I/O error.
36
- IO(err : IOError),
36
+ Io(err : IoError),
37
37
  /// An unclassified network error with a message.
38
38
  Other(msg : String)
39
39
  );
40
40
  impl(
41
41
  NetError,
42
- /// Convert an `IOError` into the corresponding `NetError` variant.
43
- from_io : (fn(err : IOError) -> Self)(
42
+ /// Convert an `IoError` into the corresponding `NetError` variant.
43
+ from_io : (fn(err : IoError) -> Self)(
44
44
  match(
45
45
  err,
46
46
  .ConnectionRefused =>.ConnectionRefused,
@@ -51,7 +51,7 @@ impl(
51
51
  .TimedOut =>.TimedOut,
52
52
  .HostUnreachable =>.HostUnreachable,
53
53
  .NetworkUnreachable =>.NetworkUnreachable,
54
- _ =>.IO(err)
54
+ _ =>.Io(err)
55
55
  )
56
56
  )
57
57
  );
@@ -71,7 +71,7 @@ impl(
71
71
  .HostUnreachable => String.from("host unreachable"),
72
72
  .NetworkUnreachable => String.from("network unreachable"),
73
73
  .DNSFailed(msg) => `DNS lookup failed: ${msg}`,
74
- .IO(err) => err.to_string(),
74
+ .Io(err) => err.to_string(),
75
75
  .Other(msg) => msg
76
76
  );
77
77
  return(s);
@@ -87,7 +87,7 @@ impl(
87
87
  check : (fn(result : i32, exn : Exception) -> i32)(
88
88
  cond(
89
89
  (result >= i32(0)) => result,
90
- true => exn.throw(dyn(Self.from_io(IOError.from_errno(i32(0) - result))))
90
+ true => exn.throw(dyn(Self.from_io(IoError.from_errno(i32(0) - result))))
91
91
  )
92
92
  )
93
93
  );
package/std/net/tcp.yo CHANGED
@@ -9,21 +9,22 @@
9
9
  // { SocketAddr, IpAddr } :: import "std/net/addr";
10
10
  // { Exception } :: import "std/error";
11
11
  //
12
- // main :: (fn(io : IO, exn : Exception) -> unit)({
12
+ // main :: (fn(io : Io, exn : Exception) -> unit)({
13
13
  // addr := SocketAddr.new(IpAddr.any_v4(), u16(8080));
14
14
  // listener := io.await(TcpListener.bind(addr, io), { io, exn });
15
15
  // stream := io.await(listener.accept(io), { io, exn });
16
16
  // // ...
17
17
  // });
18
+ pragma(Pragma.AllowUnsafe);
18
19
  { GlobalAllocator } :: import("../allocator");
19
20
  { malloc, free } :: GlobalAllocator;
20
21
  { ArrayList } :: import("../collections/array_list");
21
22
  open(import("../string"));
22
23
  open(import("../fmt"));
23
24
  { NetError } :: import("./errors");
24
- { IOError } :: import("../sys/errors");
25
+ { IoError } :: import("../sys/errors");
25
26
  { IpAddr, SocketAddr } :: import("./addr");
26
- { Error, AnyError, Exception, IOErr } :: import("../error");
27
+ { Error, AnyError, Exception, IoExn } :: import("../error");
27
28
  IO_tcp :: import("../sys/tcp");
28
29
  { AF_INET, AF_INET6, SOCK_STREAM, SOL_SOCKET, SO_REUSEADDR, IPPROTO_TCP, TCP_NODELAY, SO_KEEPALIVE } :: import("../sys/socket");
29
30
  // ============================================================================
@@ -37,7 +38,7 @@ _make_sockaddr :: (fn(addr : SocketAddr) -> IO_tcp.SockAddr)(
37
38
  // Build the IP string "a.b.c.d"
38
39
  { snprintf } :: import("../libc/stdio");
39
40
  buf := Array(u8, usize(16)).fill(u8(0));
40
- snprintf(*(char)(&(buf(usize(0)))), usize(16), "%d.%d.%d.%d", i32(a), i32(b), i32(c), i32(d));
41
+ unsafe(snprintf(*(char)(&(buf(usize(0)))), usize(16), "%d.%d.%d.%d", i32(a), i32(b), i32(c), i32(d)));
41
42
  IO_tcp.make_sockaddr_in(&(buf(usize(0))), addr.port)
42
43
  },
43
44
  .V6(_) =>
@@ -46,7 +47,7 @@ _make_sockaddr :: (fn(addr : SocketAddr) -> IO_tcp.SockAddr)(
46
47
  )
47
48
  );
48
49
  _throw_io :: (fn(errno_val : i32, exn : Exception) -> unit)(
49
- exn.throw(dyn(NetError.from_io(IOError.from_errno(errno_val))))
50
+ exn.throw(dyn(NetError.from_io(IoError.from_errno(errno_val))))
50
51
  );
51
52
  // ============================================================================
52
53
  // TcpStream (declared before TcpListener so accept can reference it)
@@ -69,7 +70,7 @@ TcpListener :: object(
69
70
  impl(
70
71
  TcpListener,
71
72
  /// Bind to a socket address and start listening.
72
- bind : (fn(addr : SocketAddr, io : IO) -> Impl(Future(TcpListener, IOErr)))(
73
+ bind : (fn(addr : SocketAddr, io : Io) -> Impl(Future(TcpListener, IoExn)))(
73
74
  io.async((e) => {
74
75
  domain := cond(
75
76
  addr.ip.is_v4() => AF_INET,
@@ -106,7 +107,7 @@ impl(
106
107
  })
107
108
  ),
108
109
  /// Accept an incoming connection, returning a new `TcpStream`.
109
- accept : (fn(self : Self, io : IO) -> Impl(Future(TcpStream, IOErr)))({
110
+ accept : (fn(self : Self, io : Io) -> Impl(Future(TcpStream, IoExn)))({
110
111
  fd := self._fd;
111
112
  io.async((e) => {
112
113
  // Allocate space for the peer address
@@ -141,7 +142,7 @@ impl(
141
142
  self._local_addr
142
143
  ),
143
144
  /// Close the listener socket.
144
- close : (fn(self : Self, io : IO) -> Impl(Future(unit, IOErr)))({
145
+ close : (fn(self : Self, io : Io) -> Impl(Future(unit, IoExn)))({
145
146
  fd := self._fd;
146
147
  io.async((e) => {
147
148
  cond(
@@ -186,7 +187,7 @@ export(TcpListener);
186
187
  impl(
187
188
  TcpStream,
188
189
  /// Connect to a remote address, returning a new `TcpStream`.
189
- connect : (fn(addr : SocketAddr, io : IO) -> Impl(Future(TcpStream, IOErr)))(
190
+ connect : (fn(addr : SocketAddr, io : Io) -> Impl(Future(TcpStream, IoExn)))(
190
191
  io.async((e) => {
191
192
  domain := cond(
192
193
  addr.ip.is_v4() => AF_INET,
@@ -215,7 +216,7 @@ impl(
215
216
  ),
216
217
  /// Read bytes from the stream into `buf`.
217
218
  /// Returns the number of bytes read, or 0 if the peer closed the connection.
218
- read : (fn(self : Self, buf : *(u8), size : usize, io : IO) -> Impl(Future(i32, IOErr)))({
219
+ read : (fn(self : Self, buf : *(u8), size : usize, io : Io) -> Impl(Future(i32, IoExn)))({
219
220
  fd := self._fd;
220
221
  io.async((e) => {
221
222
  r := e.io.await(IO_tcp.recv(fd, buf, size, i32(0)), e.io);
@@ -224,7 +225,7 @@ impl(
224
225
  }),
225
226
  /// Write a `str` to the stream.
226
227
  /// Returns the number of bytes written.
227
- write_str : (fn(self : Self, data : str, io : IO) -> Impl(Future(i32, IOErr)))({
228
+ write_str : (fn(self : Self, data : str, io : Io) -> Impl(Future(i32, IoExn)))({
228
229
  fd := self._fd;
229
230
  s := String.from(data);
230
231
  s_bytes := s.as_bytes();
@@ -235,7 +236,7 @@ impl(
235
236
  }),
236
237
  /// Write a `String` to the stream.
237
238
  /// Returns the number of bytes written.
238
- write_string : (fn(self : Self, data : String, io : IO) -> Impl(Future(i32, IOErr)))({
239
+ write_string : (fn(self : Self, data : String, io : Io) -> Impl(Future(i32, IoExn)))({
239
240
  fd := self._fd;
240
241
  data_bytes := data.as_bytes();
241
242
  io.async((e) => {
@@ -245,7 +246,7 @@ impl(
245
246
  }),
246
247
  /// Write raw bytes from an `ArrayList(u8)` to the stream.
247
248
  /// Returns the number of bytes written.
248
- write_bytes : (fn(self : Self, data : ArrayList(u8), io : IO) -> Impl(Future(i32, IOErr)))({
249
+ write_bytes : (fn(self : Self, data : ArrayList(u8), io : Io) -> Impl(Future(i32, IoExn)))({
249
250
  fd := self._fd;
250
251
  io.async((e) => {
251
252
  r := e.io.await(IO_tcp.send(fd, data.ptr().unwrap(), data.len(), i32(0)), e.io);
@@ -253,7 +254,7 @@ impl(
253
254
  })
254
255
  }),
255
256
  /// Read all available data from the stream into a byte list.
256
- read_bytes : (fn(self : Self, io : IO) -> Impl(Future(ArrayList(u8), IOErr)))({
257
+ read_bytes : (fn(self : Self, io : Io) -> Impl(Future(ArrayList(u8), IoExn)))({
257
258
  fd := self._fd;
258
259
  io.async((e) => {
259
260
  buf_size := usize(4096);
@@ -286,7 +287,7 @@ impl(
286
287
  }),
287
288
  /// Shut down part or all of the connection.
288
289
  /// `how`: 0 = read, 1 = write, 2 = both.
289
- shutdown : (fn(self : Self, how : i32, io : IO) -> Impl(Future(unit, IOErr)))({
290
+ shutdown : (fn(self : Self, how : i32, io : Io) -> Impl(Future(unit, IoExn)))({
290
291
  fd := self._fd;
291
292
  io.async((e) => {
292
293
  r := e.io.await(IO_tcp.shutdown(fd, how), e.io);
@@ -299,7 +300,7 @@ impl(
299
300
  })
300
301
  }),
301
302
  /// Close the stream.
302
- close : (fn(self : Self, io : IO) -> Impl(Future(unit, IOErr)))({
303
+ close : (fn(self : Self, io : Io) -> Impl(Future(unit, IoExn)))({
303
304
  fd := self._fd;
304
305
  io.async((e) => {
305
306
  cond(
@@ -326,7 +327,7 @@ impl(
326
327
  self._fd
327
328
  ),
328
329
  /// Enable or disable TCP_NODELAY (disables Nagle's algorithm).
329
- set_nodelay : (fn(self : Self, nodelay : bool, io : IO) -> Impl(Future(unit, IOErr)))({
330
+ set_nodelay : (fn(self : Self, nodelay : bool, io : Io) -> Impl(Future(unit, IoExn)))({
330
331
  sock_fd := self._fd;
331
332
  io.async((e) => {
332
333
  val := cond(nodelay => i32(1), true => i32(0));
@@ -341,7 +342,7 @@ impl(
341
342
  })
342
343
  }),
343
344
  /// Enable or disable SO_KEEPALIVE on the socket.
344
- set_keepalive : (fn(self : Self, enabled : bool, io : IO) -> Impl(Future(unit, IOErr)))({
345
+ set_keepalive : (fn(self : Self, enabled : bool, io : Io) -> Impl(Future(unit, IoExn)))({
345
346
  sock_fd := self._fd;
346
347
  io.async((e) => {
347
348
  val := cond(enabled => i32(1), true => i32(0));
package/std/net/udp.yo CHANGED
@@ -9,20 +9,21 @@
9
9
  // { SocketAddr, IpAddr } :: import "std/net/addr";
10
10
  // { Exception } :: import "std/error";
11
11
  //
12
- // main :: (fn(io : IO, exn : Exception) -> unit)({
12
+ // main :: (fn(io : Io, exn : Exception) -> unit)({
13
13
  // addr := SocketAddr.new(IpAddr.loopback_v4(), u16(9999));
14
14
  // sock := io.await(UdpSocket.bind(addr, io), { io, exn });
15
15
  // io.await(sock.close(io), { io, exn });
16
16
  // });
17
+ pragma(Pragma.AllowUnsafe);
17
18
  { GlobalAllocator } :: import("../allocator");
18
19
  { malloc, free } :: GlobalAllocator;
19
20
  { ArrayList } :: import("../collections/array_list");
20
21
  open(import("../string"));
21
22
  open(import("../fmt"));
22
23
  { NetError } :: import("./errors");
23
- { IOError } :: import("../sys/errors");
24
+ { IoError } :: import("../sys/errors");
24
25
  { IpAddr, SocketAddr } :: import("./addr");
25
- { Error, AnyError, Exception, IOErr } :: import("../error");
26
+ { Error, AnyError, Exception, IoExn } :: import("../error");
26
27
  IO_udp :: import("../sys/udp");
27
28
  IO_tcp :: import("../sys/tcp");
28
29
  { AF_INET, AF_INET6, SOCK_DGRAM, SOL_SOCKET, SO_BROADCAST } :: import("../sys/socket");
@@ -35,7 +36,7 @@ _make_sockaddr :: (fn(addr : SocketAddr) -> IO_tcp.SockAddr)(
35
36
  addr.ip,
36
37
  .V4(a, b, c, d) => {
37
38
  buf := Array(u8, usize(16)).fill(u8(0));
38
- snprintf(*(char)(&(buf(usize(0)))), usize(16), "%d.%d.%d.%d", i32(a), i32(b), i32(c), i32(d));
39
+ unsafe(snprintf(*(char)(&(buf(usize(0)))), usize(16), "%d.%d.%d.%d", i32(a), i32(b), i32(c), i32(d)));
39
40
  IO_tcp.make_sockaddr_in(&(buf(usize(0))), addr.port)
40
41
  },
41
42
  .V6(_) =>
@@ -43,7 +44,7 @@ _make_sockaddr :: (fn(addr : SocketAddr) -> IO_tcp.SockAddr)(
43
44
  )
44
45
  );
45
46
  _throw_net_io :: (fn(errno_val : i32, exn : Exception) -> unit)(
46
- exn.throw(dyn(NetError.from_io(IOError.from_errno(errno_val))))
47
+ exn.throw(dyn(NetError.from_io(IoError.from_errno(errno_val))))
47
48
  );
48
49
  // ============================================================================
49
50
  // UdpSocket
@@ -57,7 +58,7 @@ UdpSocket :: object(
57
58
  impl(
58
59
  UdpSocket,
59
60
  /// Create and bind a UDP socket to the given address.
60
- bind : (fn(addr : SocketAddr, io : IO) -> Impl(Future(UdpSocket, IOErr)))(
61
+ bind : (fn(addr : SocketAddr, io : Io) -> Impl(Future(UdpSocket, IoExn)))(
61
62
  io.async((e) => {
62
63
  domain := cond(
63
64
  addr.ip.is_v4() => AF_INET,
@@ -80,7 +81,7 @@ impl(
80
81
  ),
81
82
  /// Send a datagram to a specific address.
82
83
  /// Returns the number of bytes sent.
83
- send_to : (fn(self : Self, data : ArrayList(u8), addr : SocketAddr, io : IO) -> Impl(Future(i32, IOErr)))({
84
+ send_to : (fn(self : Self, data : ArrayList(u8), addr : SocketAddr, io : Io) -> Impl(Future(i32, IoExn)))({
84
85
  fd := self._fd;
85
86
  io.async((e) => {
86
87
  saddr := _make_sockaddr(addr);
@@ -91,7 +92,7 @@ impl(
91
92
  }),
92
93
  /// Receive a datagram into the provided buffer.
93
94
  /// Returns the number of bytes received.
94
- recv : (fn(self : Self, buf : *(u8), size : usize, io : IO) -> Impl(Future(i32, IOErr)))({
95
+ recv : (fn(self : Self, buf : *(u8), size : usize, io : Io) -> Impl(Future(i32, IoExn)))({
95
96
  fd := self._fd;
96
97
  io.async((e) => {
97
98
  r := e.io.await(IO_udp.recv(fd, buf, size, i32(0)), e.io);
@@ -100,7 +101,7 @@ impl(
100
101
  }),
101
102
  /// Receive a datagram and retrieve the sender's address.
102
103
  /// Returns the number of bytes received.
103
- recv_from : (fn(self : Self, buf : *(u8), size : usize, src_addr : *(u8), src_addr_len : *(u32), io : IO) -> Impl(Future(i32, IOErr)))({
104
+ recv_from : (fn(self : Self, buf : *(u8), size : usize, src_addr : *(u8), src_addr_len : *(u32), io : Io) -> Impl(Future(i32, IoExn)))({
104
105
  fd := self._fd;
105
106
  io.async((e) => {
106
107
  r := e.io.await(IO_udp.recvfrom(fd, buf, size, i32(0), src_addr, src_addr_len), e.io);
@@ -108,7 +109,7 @@ impl(
108
109
  })
109
110
  }),
110
111
  /// Send data on a connected socket (requires prior connect).
111
- send : (fn(self : Self, data : ArrayList(u8), io : IO) -> Impl(Future(i32, IOErr)))({
112
+ send : (fn(self : Self, data : ArrayList(u8), io : Io) -> Impl(Future(i32, IoExn)))({
112
113
  fd := self._fd;
113
114
  io.async((e) => {
114
115
  r := e.io.await(IO_udp.send(fd, data.ptr().unwrap(), data.len(), i32(0)), e.io);
@@ -116,7 +117,7 @@ impl(
116
117
  })
117
118
  }),
118
119
  /// Close the socket.
119
- close : (fn(self : Self, io : IO) -> Impl(Future(unit, IOErr)))({
120
+ close : (fn(self : Self, io : Io) -> Impl(Future(unit, IoExn)))({
120
121
  fd := self._fd;
121
122
  io.async((e) => {
122
123
  cond(
@@ -135,7 +136,7 @@ impl(
135
136
  })
136
137
  }),
137
138
  /// Enable or disable SO_BROADCAST on the socket.
138
- set_broadcast : (fn(self : Self, enabled : bool, io : IO) -> Impl(Future(unit, IOErr)))({
139
+ set_broadcast : (fn(self : Self, enabled : bool, io : Io) -> Impl(Future(unit, IoExn)))({
139
140
  fd := self._fd;
140
141
  io.async((e) => {
141
142
  val := cond(enabled => i32(1), true => i32(0));
package/std/os/signal.yo CHANGED
@@ -10,7 +10,7 @@
10
10
  //! handler :: (fn(data: *(u8)) -> unit)({ println("Caught SIGINT"); });
11
11
  //! on_signal(.Interrupt, handler);
12
12
  //! ```
13
- { IOError } :: import("../sys/errors");
13
+ { IoError } :: import("../sys/errors");
14
14
  { on_signal : _on_signal, off_signal : _off_signal, SignalHandler } :: import("../sys/signal");
15
15
  { platform, Platform } :: import("../process");
16
16
  { Error, AnyError, Exception } :: import("../error");
@@ -83,7 +83,7 @@ on_signal :: (fn(sig : Signal, handler : SignalHandler, exn : Exception) -> unit
83
83
  r := _on_signal(num, handler);
84
84
  cond(
85
85
  (r < i32(0)) => {
86
- exn.throw(dyn(IOError.from_errno(i32(0) - r)));
86
+ exn.throw(dyn(IoError.from_errno(i32(0) - r)));
87
87
  },
88
88
  true => ()
89
89
  );
@@ -94,7 +94,7 @@ off_signal :: (fn(sig : Signal, exn : Exception) -> unit)({
94
94
  r := _off_signal(num);
95
95
  cond(
96
96
  (r < i32(0)) => {
97
- exn.throw(dyn(IOError.from_errno(i32(0) - r)));
97
+ exn.throw(dyn(IoError.from_errno(i32(0) - r)));
98
98
  },
99
99
  true => ()
100
100
  );
package/std/path.yo CHANGED
@@ -1,4 +1,5 @@
1
1
  //! Cross-platform filesystem path manipulation.
2
+ pragma(Pragma.AllowUnsafe);
2
3
  open(import("./string"));
3
4
  open(import("./fmt"));
4
5
  open(import("./collections/array_list"));