@shd101wyy/yo 0.1.26 → 0.1.27

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 (167) hide show
  1. package/.github/skills/yo-async-effects/SKILL.md +4 -4
  2. package/.github/skills/yo-async-effects/async-effects-recipes.md +34 -34
  3. package/.github/skills/yo-core-patterns/SKILL.md +1 -1
  4. package/.github/skills/yo-core-patterns/core-patterns-cheatsheet.md +26 -26
  5. package/.github/skills/yo-project-workflow/SKILL.md +6 -3
  6. package/.github/skills/yo-project-workflow/workflow-cheatsheet.md +34 -11
  7. package/.github/skills/yo-syntax/SKILL.md +7 -6
  8. package/.github/skills/yo-syntax/syntax-cheatsheet.md +73 -60
  9. package/.github/skills/yo-wasm-integration/wasm-integration-cheatsheet.md +3 -3
  10. package/README.md +10 -8
  11. package/out/cjs/index.cjs +456 -438
  12. package/out/cjs/yo-cli.cjs +576 -543
  13. package/out/cjs/yo-lsp.cjs +559 -532
  14. package/out/esm/index.mjs +281 -263
  15. package/out/types/src/formatter.d.ts +11 -0
  16. package/out/types/src/lsp/formatting.d.ts +2 -0
  17. package/out/types/src/tests/formatter.test.d.ts +1 -0
  18. package/out/types/tsconfig.tsbuildinfo +1 -1
  19. package/package.json +1 -1
  20. package/std/alg/hash.yo +13 -21
  21. package/std/allocator.yo +25 -40
  22. package/std/async.yo +3 -7
  23. package/std/build.yo +105 -151
  24. package/std/cli/arg_parser.yo +184 -169
  25. package/std/collections/array_list.yo +350 -314
  26. package/std/collections/btree_map.yo +142 -131
  27. package/std/collections/deque.yo +132 -128
  28. package/std/collections/hash_map.yo +542 -566
  29. package/std/collections/hash_set.yo +623 -687
  30. package/std/collections/linked_list.yo +275 -293
  31. package/std/collections/ordered_map.yo +113 -85
  32. package/std/collections/priority_queue.yo +73 -73
  33. package/std/crypto/md5.yo +191 -95
  34. package/std/crypto/random.yo +56 -64
  35. package/std/crypto/sha256.yo +151 -107
  36. package/std/encoding/base64.yo +87 -81
  37. package/std/encoding/hex.yo +43 -50
  38. package/std/encoding/html.yo +56 -81
  39. package/std/encoding/html_char_utils.yo +7 -13
  40. package/std/encoding/html_entities.yo +2248 -2253
  41. package/std/encoding/json.yo +316 -224
  42. package/std/encoding/punycode.yo +86 -116
  43. package/std/encoding/toml.yo +67 -66
  44. package/std/encoding/utf16.yo +37 -44
  45. package/std/env.yo +62 -91
  46. package/std/error.yo +7 -15
  47. package/std/fmt/display.yo +5 -9
  48. package/std/fmt/index.yo +8 -14
  49. package/std/fmt/to_string.yo +330 -315
  50. package/std/fmt/writer.yo +58 -87
  51. package/std/fs/dir.yo +83 -102
  52. package/std/fs/file.yo +147 -180
  53. package/std/fs/metadata.yo +45 -78
  54. package/std/fs/temp.yo +55 -65
  55. package/std/fs/types.yo +27 -40
  56. package/std/fs/walker.yo +53 -68
  57. package/std/gc.yo +5 -8
  58. package/std/glob.yo +30 -43
  59. package/std/http/client.yo +107 -120
  60. package/std/http/http.yo +106 -96
  61. package/std/http/index.yo +4 -6
  62. package/std/imm/list.yo +88 -93
  63. package/std/imm/map.yo +528 -464
  64. package/std/imm/set.yo +52 -57
  65. package/std/imm/sorted_map.yo +340 -286
  66. package/std/imm/sorted_set.yo +57 -63
  67. package/std/imm/string.yo +404 -345
  68. package/std/imm/vec.yo +173 -181
  69. package/std/io/reader.yo +3 -6
  70. package/std/io/writer.yo +4 -8
  71. package/std/libc/assert.yo +5 -9
  72. package/std/libc/ctype.yo +32 -22
  73. package/std/libc/dirent.yo +26 -25
  74. package/std/libc/errno.yo +164 -90
  75. package/std/libc/fcntl.yo +52 -45
  76. package/std/libc/float.yo +66 -44
  77. package/std/libc/limits.yo +42 -33
  78. package/std/libc/math.yo +53 -82
  79. package/std/libc/signal.yo +72 -47
  80. package/std/libc/stdatomic.yo +217 -188
  81. package/std/libc/stdint.yo +5 -29
  82. package/std/libc/stdio.yo +5 -29
  83. package/std/libc/stdlib.yo +32 -39
  84. package/std/libc/string.yo +5 -23
  85. package/std/libc/sys/stat.yo +58 -56
  86. package/std/libc/time.yo +5 -19
  87. package/std/libc/unistd.yo +5 -20
  88. package/std/libc/wctype.yo +6 -9
  89. package/std/libc/windows.yo +26 -30
  90. package/std/log.yo +41 -55
  91. package/std/net/addr.yo +102 -97
  92. package/std/net/dns.yo +27 -28
  93. package/std/net/errors.yo +50 -49
  94. package/std/net/tcp.yo +113 -124
  95. package/std/net/udp.yo +55 -66
  96. package/std/os/env.yo +35 -33
  97. package/std/os/signal.yo +15 -25
  98. package/std/path.yo +276 -311
  99. package/std/prelude.yo +6304 -4315
  100. package/std/process/command.yo +87 -103
  101. package/std/process/index.yo +12 -31
  102. package/std/regex/compiler.yo +196 -95
  103. package/std/regex/flags.yo +58 -39
  104. package/std/regex/index.yo +157 -173
  105. package/std/regex/match.yo +20 -31
  106. package/std/regex/node.yo +134 -152
  107. package/std/regex/parser.yo +283 -259
  108. package/std/regex/unicode.yo +172 -202
  109. package/std/regex/vm.yo +155 -171
  110. package/std/string/index.yo +5 -7
  111. package/std/string/rune.yo +45 -55
  112. package/std/string/string.yo +937 -964
  113. package/std/string/string_builder.yo +94 -104
  114. package/std/string/unicode.yo +46 -64
  115. package/std/sync/channel.yo +72 -73
  116. package/std/sync/cond.yo +31 -36
  117. package/std/sync/mutex.yo +30 -32
  118. package/std/sync/once.yo +13 -16
  119. package/std/sync/rwlock.yo +26 -31
  120. package/std/sync/waitgroup.yo +20 -25
  121. package/std/sys/advise.yo +16 -24
  122. package/std/sys/bufio/buf_reader.yo +77 -93
  123. package/std/sys/bufio/buf_writer.yo +52 -65
  124. package/std/sys/clock.yo +4 -9
  125. package/std/sys/constants.yo +77 -61
  126. package/std/sys/copy.yo +4 -10
  127. package/std/sys/dir.yo +26 -43
  128. package/std/sys/dns.yo +41 -61
  129. package/std/sys/errors.yo +95 -103
  130. package/std/sys/events.yo +45 -57
  131. package/std/sys/externs.yo +319 -267
  132. package/std/sys/fallocate.yo +7 -11
  133. package/std/sys/fcntl.yo +14 -22
  134. package/std/sys/file.yo +26 -40
  135. package/std/sys/future.yo +5 -8
  136. package/std/sys/iov.yo +12 -25
  137. package/std/sys/lock.yo +12 -13
  138. package/std/sys/mmap.yo +38 -43
  139. package/std/sys/path.yo +3 -8
  140. package/std/sys/perm.yo +7 -21
  141. package/std/sys/pipe.yo +5 -12
  142. package/std/sys/process.yo +23 -29
  143. package/std/sys/seek.yo +10 -12
  144. package/std/sys/signal.yo +7 -13
  145. package/std/sys/signals.yo +52 -35
  146. package/std/sys/socket.yo +63 -58
  147. package/std/sys/socketpair.yo +3 -6
  148. package/std/sys/sockinfo.yo +11 -20
  149. package/std/sys/statfs.yo +11 -34
  150. package/std/sys/statx.yo +25 -52
  151. package/std/sys/sysinfo.yo +15 -20
  152. package/std/sys/tcp.yo +62 -92
  153. package/std/sys/temp.yo +5 -9
  154. package/std/sys/time.yo +5 -15
  155. package/std/sys/timer.yo +6 -11
  156. package/std/sys/tty.yo +10 -18
  157. package/std/sys/udp.yo +22 -39
  158. package/std/sys/umask.yo +3 -6
  159. package/std/sys/unix.yo +33 -52
  160. package/std/testing/bench.yo +49 -52
  161. package/std/thread.yo +10 -15
  162. package/std/time/datetime.yo +105 -89
  163. package/std/time/duration.yo +43 -56
  164. package/std/time/instant.yo +13 -18
  165. package/std/time/sleep.yo +5 -9
  166. package/std/url/index.yo +184 -209
  167. package/std/worker.yo +6 -10
package/std/net/addr.yo CHANGED
@@ -7,56 +7,52 @@
7
7
  // { IpAddr, SocketAddr } :: import "std/net/addr";
8
8
  //
9
9
  // addr := SocketAddr.new(IpAddr.loopback_v4(), u16(8080));
10
-
11
- open import "../string";
12
- { ToString } :: import "../fmt";
13
- { Writer } :: import "../fmt/writer";
14
- { NetError } :: import "./errors";
15
- { snprintf } :: import "../libc/stdio";
16
- { GlobalAllocator } :: import "../allocator";
10
+ open(import("../string"));
11
+ { ToString } :: import("../fmt");
12
+ { Writer } :: import("../fmt/writer");
13
+ { NetError } :: import("./errors");
14
+ { snprintf } :: import("../libc/stdio");
15
+ { GlobalAllocator } :: import("../allocator");
17
16
  { malloc, free } :: GlobalAllocator;
18
- { Error, AnyError, Exception } :: import "../error";
19
-
17
+ { Error, AnyError, Exception } :: import("../error");
20
18
  // ============================================================================
21
19
  // IpAddr
22
20
  // ============================================================================
23
-
24
21
  // ASCII constants for parsing
25
- _ASCII_DOT :: u8(46); // '.'
26
- _ASCII_ZERO :: u8(48); // '0'
27
- _ASCII_NINE :: u8(57); // '9'
28
-
22
+ _ASCII_DOT :: u8(46); // '.'
23
+ _ASCII_ZERO :: u8(48); // '0'
24
+ _ASCII_NINE :: u8(57); // '9'
29
25
  /// An IP address, either IPv4 or IPv6.
30
26
  IpAddr :: enum(
31
27
  /// An IPv4 address represented as four octets.
32
- V4(a: u8, b: u8, c: u8, d: u8),
28
+ V4(a : u8, b : u8, c : u8, d : u8),
33
29
  /// An IPv6 address represented as eight 16-bit segments.
34
- V6(segments: Array(u16, usize(8)))
30
+ V6(segments : Array(u16, usize(8)))
35
31
  );
36
-
37
- impl(IpAddr,
32
+ impl(
33
+ IpAddr,
38
34
  /// Parse an IPv4 address from a dotted-decimal `String` (e.g. "127.0.0.1").
39
35
  /// Throws on invalid input.
40
- parse_v4 : (fn(s: String, using(exn : Exception)) -> IpAddr)({
36
+ parse_v4 : (fn(s : String, using(exn : Exception)) -> IpAddr)({
41
37
  bytes := s.as_bytes();
42
38
  parts := Array(u8, usize(4)).fill(u8(0));
43
39
  part_idx := usize(0);
44
40
  val := u32(0);
45
41
  i := usize(0);
46
- while runtime((i < bytes.len())), {
42
+ while(runtime(i < bytes.len()), {
47
43
  ch := bytes.get(i).unwrap();
48
44
  cond(
49
45
  (ch == _ASCII_DOT) => {
50
46
  // '.' separator
51
47
  cond(
52
48
  (part_idx >= usize(3)) => {
53
- exn.throw(dyn NetError.Other(String.from("invalid IPv4 address")));
49
+ exn.throw(dyn(NetError.Other(String.from("invalid IPv4 address"))));
54
50
  },
55
51
  true => ()
56
52
  );
57
53
  cond(
58
54
  (val > u32(255)) => {
59
- exn.throw(dyn NetError.Other(String.from("IPv4 octet out of range")));
55
+ exn.throw(dyn(NetError.Other(String.from("IPv4 octet out of range"))));
60
56
  },
61
57
  true => ()
62
58
  );
@@ -66,151 +62,160 @@ impl(IpAddr,
66
62
  },
67
63
  ((ch >= _ASCII_ZERO) && (ch <= _ASCII_NINE)) => {
68
64
  // digit
69
- val = ((val * u32(10)) + u32((ch - _ASCII_ZERO)));
65
+ val = ((val * u32(10)) + u32(ch - _ASCII_ZERO));
70
66
  },
71
67
  true => {
72
- exn.throw(dyn NetError.Other(String.from("invalid character in IPv4 address")));
68
+ exn.throw(dyn(NetError.Other(String.from("invalid character in IPv4 address"))));
73
69
  }
74
70
  );
75
71
  i = (i + usize(1));
76
- };
72
+ });
77
73
  cond(
78
74
  (part_idx != usize(3)) => {
79
- exn.throw(dyn NetError.Other(String.from("invalid IPv4 address")));
75
+ exn.throw(dyn(NetError.Other(String.from("invalid IPv4 address"))));
80
76
  },
81
77
  true => ()
82
78
  );
83
79
  cond(
84
80
  (val > u32(255)) => {
85
- exn.throw(dyn NetError.Other(String.from("IPv4 octet out of range")));
81
+ exn.throw(dyn(NetError.Other(String.from("IPv4 octet out of range"))));
86
82
  },
87
83
  true => ()
88
84
  );
89
85
  parts(usize(3)) = u8(val);
90
86
  .V4(parts(usize(0)), parts(usize(1)), parts(usize(2)), parts(usize(3)))
91
87
  }),
92
-
93
88
  /// Return the IPv4 loopback address (127.0.0.1).
94
89
  loopback_v4 : (fn() -> IpAddr)(
95
90
  .V4(u8(127), u8(0), u8(0), u8(1))
96
91
  ),
97
-
98
92
  /// Return the IPv6 loopback address (::1).
99
93
  loopback_v6 : (fn() -> IpAddr)({
100
94
  segs := Array(u16, usize(8)).fill(u16(0));
101
95
  segs(usize(7)) = u16(1);
102
96
  .V6(segs)
103
97
  }),
104
-
105
98
  /// Return the IPv4 unspecified address (0.0.0.0).
106
99
  any_v4 : (fn() -> IpAddr)(
107
100
  .V4(u8(0), u8(0), u8(0), u8(0))
108
101
  ),
109
-
110
102
  /// Return `true` if this is a loopback address.
111
- is_loopback : (fn(self: Self) -> bool)(
112
- match(self,
103
+ is_loopback : (fn(self : Self) -> bool)(
104
+ match(
105
+ self,
113
106
  .V4(a, _, _, _) => (a == u8(127)),
114
107
  .V6(segs) => {
115
108
  // ::1
116
109
  all_zero := true;
117
110
  i := usize(0);
118
- while runtime((i < usize(7))), {
111
+ while(runtime(i < usize(7)), {
119
112
  cond(
120
- (segs(i) != u16(0)) => { all_zero = false; },
113
+ (segs(i) != u16(0)) => {
114
+ all_zero = false;
115
+ },
121
116
  true => ()
122
117
  );
123
118
  i = (i + usize(1));
124
- };
125
- (all_zero && (segs(usize(7)) == u16(1)))
119
+ });
120
+ all_zero && (segs(usize(7)) == u16(1))
126
121
  }
127
122
  )
128
123
  ),
129
-
130
124
  /// Return `true` if this is an IPv4 address.
131
- is_v4 : (fn(self: Self) -> bool)(
132
- match(self,
125
+ is_v4 : (fn(self : Self) -> bool)(
126
+ match(
127
+ self,
133
128
  .V4(_, _, _, _) => true,
134
129
  .V6(_) => false
135
130
  )
136
131
  ),
137
-
138
132
  /// Return `true` if this is an IPv6 address.
139
- is_v6 : (fn(self: Self) -> bool)(
140
- match(self,
133
+ is_v6 : (fn(self : Self) -> bool)(
134
+ match(
135
+ self,
141
136
  .V4(_, _, _, _) => false,
142
137
  .V6(_) => true
143
138
  )
144
139
  )
145
140
  );
146
-
147
- impl(IpAddr, ToString(
148
- to_string : (self -> {
149
- return match(self.*,
150
- .V4(a, b, c, d) => {
151
- buf := Array(u8, usize(16)).fill(u8(0));
152
- snprintf(*(char)(&(buf(usize(0)))), usize(16), "%d.%d.%d.%d", i32(a), i32(b), i32(c), i32(d));
153
- String.from_cstr(&(buf(usize(0)))).unwrap()
154
- },
155
- .V6(segs) => {
156
- w := Writer.new();
157
- i := usize(0);
158
- while runtime((i < usize(8))), {
159
- cond(
160
- (i > usize(0)) => { w.write_str(":"); },
161
- true => ()
162
- );
163
- w.write_hex(u64(segs(i)));
164
- i = (i + usize(1));
165
- };
166
- w.to_string()
141
+ impl(
142
+ IpAddr,
143
+ ToString(
144
+ to_string : (
145
+ self -> {
146
+ return(
147
+ match(
148
+ self.*,
149
+ .V4(a, b, c, d) => {
150
+ 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
+ String.from_cstr(&(buf(usize(0)))).unwrap()
153
+ },
154
+ .V6(segs) => {
155
+ w := Writer.new();
156
+ i := usize(0);
157
+ while(runtime(i < usize(8)), {
158
+ cond(
159
+ (i > usize(0)) => {
160
+ w.write_str(":");
161
+ },
162
+ true => ()
163
+ );
164
+ w.write_hex(u64(segs(i)));
165
+ i = (i + usize(1));
166
+ });
167
+ w.to_string()
168
+ }
169
+ )
170
+ );
167
171
  }
168
- );
169
- })
170
- ));
171
-
172
- export IpAddr;
173
-
172
+ )
173
+ )
174
+ );
175
+ export(IpAddr);
174
176
  // ============================================================================
175
177
  // SocketAddr
176
178
  // ============================================================================
177
-
178
179
  /// An IP address paired with a port number.
179
180
  SocketAddr :: struct(
180
181
  /// The IP address.
181
- ip : IpAddr,
182
+ ip : IpAddr,
182
183
  /// The port number.
183
184
  port : u16
184
185
  );
185
-
186
- impl(SocketAddr,
186
+ impl(
187
+ SocketAddr,
187
188
  /// Create a new socket address from an IP and port.
188
- new : (fn(ip: IpAddr, port: u16) -> Self)(
189
- Self(ip: ip, port: port)
189
+ new : (fn(ip : IpAddr, port : u16) -> Self)(
190
+ Self(ip : ip, port : port)
190
191
  ),
191
-
192
192
  /// Create an IPv4 loopback socket address (127.0.0.1) with the given port.
193
- loopback : (fn(port: u16) -> Self)(
194
- Self(ip: IpAddr.loopback_v4(), port: port)
193
+ loopback : (fn(port : u16) -> Self)(
194
+ Self(ip : IpAddr.loopback_v4(), port : port)
195
195
  ),
196
-
197
196
  /// Create an IPv4 unspecified socket address (0.0.0.0) with the given port.
198
- any : (fn(port: u16) -> Self)(
199
- Self(ip: IpAddr.any_v4(), port: port)
197
+ any : (fn(port : u16) -> Self)(
198
+ Self(ip : IpAddr.any_v4(), port : port)
200
199
  )
201
200
  );
202
-
203
- impl(SocketAddr, ToString(
204
- to_string : (self -> {
205
- ip_str := self.ip.to_string();
206
- buf := Array(u8, usize(8)).fill(u8(0));
207
- snprintf(*(char)(&(buf(usize(0)))), usize(8), "%d", i32(self.port));
208
- port_str := String.from_cstr(&(buf(usize(0)))).unwrap();
209
- return match(self.ip,
210
- .V4(_, _, _, _) => `${ip_str}:${port_str}`,
211
- .V6(_) => `[${ip_str}]:${port_str}`
212
- );
213
- })
214
- ));
215
-
216
- export SocketAddr;
201
+ impl(
202
+ SocketAddr,
203
+ ToString(
204
+ to_string : (
205
+ self -> {
206
+ ip_str := self.ip.to_string();
207
+ buf := Array(u8, usize(8)).fill(u8(0));
208
+ snprintf(*(char)(&(buf(usize(0)))), usize(8), "%d", i32(self.port));
209
+ port_str := String.from_cstr(&(buf(usize(0)))).unwrap();
210
+ return(
211
+ match(
212
+ self.ip,
213
+ .V4(_, _, _, _) => `${ip_str}:${port_str}`,
214
+ .V6(_) => `[${ip_str}]:${port_str}`
215
+ )
216
+ );
217
+ }
218
+ )
219
+ )
220
+ );
221
+ export(SocketAddr);
package/std/net/dns.yo CHANGED
@@ -21,40 +21,38 @@
21
21
  // i = (i + usize(1));
22
22
  // };
23
23
  // });
24
-
25
- { GlobalAllocator } :: import "../allocator";
24
+ { GlobalAllocator } :: import("../allocator");
26
25
  { malloc, free } :: GlobalAllocator;
27
- { ArrayList } :: import "../collections/array_list";
28
- open import "../string";
29
- open import "../fmt";
30
- { NetError } :: import "./errors";
31
- { IpAddr, SocketAddr } :: import "./addr";
32
- { Error, AnyError, Exception } :: import "../error";
33
- IO_dns :: import "../sys/dns";
34
- { AF_INET, AF_INET6 } :: import "../sys/socket";
35
-
26
+ { ArrayList } :: import("../collections/array_list");
27
+ open(import("../string"));
28
+ open(import("../fmt"));
29
+ { NetError } :: import("./errors");
30
+ { IpAddr, SocketAddr } :: import("./addr");
31
+ { Error, AnyError, Exception } :: import("../error");
32
+ IO_dns :: import("../sys/dns");
33
+ { AF_INET, AF_INET6 } :: import("../sys/socket");
36
34
  // ============================================================================
37
35
  // DNS lookup
38
36
  // ============================================================================
39
-
40
37
  /// Resolve a hostname to a list of IP addresses.
41
- lookup_host :: (fn(host: String, using(io : IO)) -> Impl(Future(ArrayList(IpAddr), IO, Exception)))(
38
+ lookup_host :: (fn(host : String, using(io : IO)) -> Impl(Future(ArrayList(IpAddr), IO, Exception)))(
42
39
  io.async((using(io : IO, exn : Exception)) => {
43
40
  host_cstr_bytes := host.to_cstr();
44
41
  host_cstr := host_cstr_bytes.ptr().unwrap();
45
42
  result_ptr := IO_dns.alloc_result();
46
- ret := io.await(IO_dns.getaddrinfo(host_cstr, .None, .None, result_ptr));
43
+ ret := io.await(IO_dns.getaddrinfo(host_cstr,.None,.None, result_ptr));
47
44
  cond(
48
45
  (ret != i32(0)) => {
49
46
  IO_dns.free_result(result_ptr);
50
- exn.throw(dyn NetError.DNSFailed(host));
47
+ exn.throw(dyn(NetError.DNSFailed(host)));
51
48
  },
52
49
  true => ()
53
50
  );
54
51
  addrs := ArrayList(IpAddr).new();
55
52
  cur := IO_dns.get_result(result_ptr);
56
- while runtime(true), {
57
- match(cur,
53
+ while(runtime(true), {
54
+ match(
55
+ cur,
58
56
  .Some(ai) => {
59
57
  family := IO_dns.addrinfo_family(ai);
60
58
  addr_ptr := IO_dns.addrinfo_addr(ai);
@@ -72,32 +70,33 @@ lookup_host :: (fn(host: String, using(io : IO)) -> Impl(Future(ArrayList(IpAddr
72
70
  );
73
71
  cur = IO_dns.addrinfo_next(ai);
74
72
  },
75
- .None => { break; }
73
+ .None => {
74
+ break;
75
+ }
76
76
  );
77
- };
77
+ });
78
78
  // Free the result
79
- match(IO_dns.get_result(result_ptr),
79
+ match(
80
+ IO_dns.get_result(result_ptr),
80
81
  .Some(ai) => IO_dns.freeaddrinfo(ai),
81
82
  .None => ()
82
83
  );
83
84
  IO_dns.free_result(result_ptr);
84
- return addrs;
85
+ return(addrs);
85
86
  })
86
87
  );
87
-
88
88
  /// Resolve a hostname and port to a list of socket addresses.
89
- resolve :: (fn(host: String, port: u16, using(io : IO)) -> Impl(Future(ArrayList(SocketAddr), IO, Exception)))(
89
+ resolve :: (fn(host : String, port : u16, using(io : IO)) -> Impl(Future(ArrayList(SocketAddr), IO, Exception)))(
90
90
  io.async((using(io : IO, exn : Exception)) => {
91
91
  addrs := io.await(lookup_host(host, using(io)));
92
92
  result := ArrayList(SocketAddr).new();
93
93
  i := usize(0);
94
- while runtime((i < addrs.len())), {
94
+ while(runtime(i < addrs.len()), {
95
95
  ip := addrs.get(i).unwrap();
96
96
  result.push(SocketAddr.new(ip, port));
97
97
  i = (i + usize(1));
98
- };
99
- return result;
98
+ });
99
+ return(result);
100
100
  })
101
101
  );
102
-
103
- export lookup_host, resolve;
102
+ export(lookup_host, resolve);
package/std/net/errors.yo CHANGED
@@ -5,16 +5,13 @@
5
5
  //
6
6
  // Example:
7
7
  // { NetError } :: import "std/net/errors";
8
-
9
- open import "../string";
10
- { IOError } :: import "../sys/errors";
11
- { ToString } :: import "../fmt";
12
- { Error, AnyError, Exception } :: import "../error";
13
-
8
+ open(import("../string"));
9
+ { IOError } :: import("../sys/errors");
10
+ { ToString } :: import("../fmt");
11
+ { Error, AnyError, Exception } :: import("../error");
14
12
  // ============================================================================
15
13
  // NetError
16
14
  // ============================================================================
17
-
18
15
  /// Network-specific error type wrapping lower-level I/O errors.
19
16
  NetError :: enum(
20
17
  /// The remote host refused the connection.
@@ -34,60 +31,64 @@ NetError :: enum(
34
31
  /// The network is unreachable.
35
32
  NetworkUnreachable,
36
33
  /// DNS resolution failed.
37
- DNSFailed(msg: String),
34
+ DNSFailed(msg : String),
38
35
  /// A wrapped lower-level I/O error.
39
- IO(err: IOError),
36
+ IO(err : IOError),
40
37
  /// An unclassified network error with a message.
41
- Other(msg: String)
38
+ Other(msg : String)
42
39
  );
43
-
44
- impl(NetError,
40
+ impl(
41
+ NetError,
45
42
  /// Convert an `IOError` into the corresponding `NetError` variant.
46
- from_io : (fn(err: IOError) -> Self)(
47
- match(err,
48
- .ConnectionRefused => .ConnectionRefused,
49
- .ConnectionReset => .ConnectionReset,
50
- .ConnectionAborted => .ConnectionAborted,
51
- .AddressInUse => .AddrInUse,
52
- .AddressNotAvailable => .AddrNotAvailable,
53
- .TimedOut => .TimedOut,
54
- .HostUnreachable => .HostUnreachable,
55
- .NetworkUnreachable => .NetworkUnreachable,
56
- _ => .IO(err)
43
+ from_io : (fn(err : IOError) -> Self)(
44
+ match(
45
+ err,
46
+ .ConnectionRefused =>.ConnectionRefused,
47
+ .ConnectionReset =>.ConnectionReset,
48
+ .ConnectionAborted =>.ConnectionAborted,
49
+ .AddressInUse =>.AddrInUse,
50
+ .AddressNotAvailable =>.AddrNotAvailable,
51
+ .TimedOut =>.TimedOut,
52
+ .HostUnreachable =>.HostUnreachable,
53
+ .NetworkUnreachable =>.NetworkUnreachable,
54
+ _ =>.IO(err)
55
+ )
56
+ )
57
+ );
58
+ impl(
59
+ NetError,
60
+ ToString(
61
+ to_string : (
62
+ self -> {
63
+ s := match(
64
+ self,
65
+ .ConnectionRefused => String.from("connection refused"),
66
+ .ConnectionReset => String.from("connection reset by peer"),
67
+ .ConnectionAborted => String.from("connection aborted"),
68
+ .AddrInUse => String.from("address already in use"),
69
+ .AddrNotAvailable => String.from("address not available"),
70
+ .TimedOut => String.from("operation timed out"),
71
+ .HostUnreachable => String.from("host unreachable"),
72
+ .NetworkUnreachable => String.from("network unreachable"),
73
+ .DNSFailed(msg) => `DNS lookup failed: ${msg}`,
74
+ .IO(err) => err.to_string(),
75
+ .Other(msg) => msg
76
+ );
77
+ return(s);
78
+ }
57
79
  )
58
80
  )
59
81
  );
60
-
61
- impl(NetError, ToString(
62
- to_string : (self -> {
63
- s := match(self,
64
- .ConnectionRefused => String.from("connection refused"),
65
- .ConnectionReset => String.from("connection reset by peer"),
66
- .ConnectionAborted => String.from("connection aborted"),
67
- .AddrInUse => String.from("address already in use"),
68
- .AddrNotAvailable => String.from("address not available"),
69
- .TimedOut => String.from("operation timed out"),
70
- .HostUnreachable => String.from("host unreachable"),
71
- .NetworkUnreachable => String.from("network unreachable"),
72
- .DNSFailed(msg) => `DNS lookup failed: ${msg}`,
73
- .IO(err) => err.to_string(),
74
- .Other(msg) => msg
75
- );
76
- return s;
77
- })
78
- ));
79
-
80
82
  impl(NetError, Error());
81
-
82
- impl(NetError,
83
+ impl(
84
+ NetError,
83
85
  /// Check a raw syscall result and throw on error.
84
86
  /// Positive values are returned as-is; negative values are converted to a `NetError` and thrown.
85
- check : (fn(result: i32, using(exn : Exception)) -> i32)(
87
+ check : (fn(result : i32, using(exn : Exception)) -> i32)(
86
88
  cond(
87
89
  (result >= i32(0)) => result,
88
- 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))))
89
91
  )
90
92
  )
91
93
  );
92
-
93
- export NetError;
94
+ export(NetError);