@shd101wyy/yo 0.1.25 → 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 (194) hide show
  1. package/.github/skills/yo-async-effects/SKILL.md +4 -4
  2. package/.github/skills/yo-async-effects/async-effects-recipes.md +40 -40
  3. package/.github/skills/yo-core-patterns/SKILL.md +1 -1
  4. package/.github/skills/yo-core-patterns/core-patterns-cheatsheet.md +30 -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 +78 -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 +583 -567
  12. package/out/cjs/yo-cli.cjs +664 -632
  13. package/out/cjs/yo-lsp.cjs +510 -485
  14. package/out/esm/index.mjs +538 -522
  15. package/out/types/src/codegen/codegen-c.d.ts +2 -2
  16. package/out/types/src/codegen/functions/collection.d.ts +2 -2
  17. package/out/types/src/codegen/functions/context.d.ts +3 -2
  18. package/out/types/src/codegen/types/collection.d.ts +2 -2
  19. package/out/types/src/codegen/utils/index.d.ts +3 -1
  20. package/out/types/src/doc/builder.d.ts +2 -2
  21. package/out/types/src/evaluator/calls/closure-type.d.ts +2 -2
  22. package/out/types/src/evaluator/calls/record-type.d.ts +11 -0
  23. package/out/types/src/evaluator/context.d.ts +8 -9
  24. package/out/types/src/evaluator/index.d.ts +3 -3
  25. package/out/types/src/evaluator/types/record.d.ts +14 -0
  26. package/out/types/src/evaluator/types/validation.d.ts +2 -2
  27. package/out/types/src/evaluator/values/anonymous-module.d.ts +5 -5
  28. package/out/types/src/evaluator/values/impl.d.ts +1 -1
  29. package/out/types/src/expr.d.ts +1 -4
  30. package/out/types/src/formatter.d.ts +11 -0
  31. package/out/types/src/function-value.d.ts +1 -1
  32. package/out/types/src/lsp/document-manager.d.ts +1 -1
  33. package/out/types/src/lsp/formatting.d.ts +2 -0
  34. package/out/types/src/module-manager.d.ts +3 -3
  35. package/out/types/src/tests/formatter.test.d.ts +1 -0
  36. package/out/types/src/types/creators.d.ts +3 -4
  37. package/out/types/src/types/definitions.d.ts +8 -19
  38. package/out/types/src/types/guards.d.ts +3 -3
  39. package/out/types/src/types/tags.d.ts +0 -1
  40. package/out/types/src/types/utils.d.ts +1 -1
  41. package/out/types/src/value-tag.d.ts +0 -1
  42. package/out/types/src/value.d.ts +6 -13
  43. package/out/types/tsconfig.tsbuildinfo +1 -1
  44. package/package.json +1 -1
  45. package/std/alg/hash.yo +13 -21
  46. package/std/allocator.yo +25 -40
  47. package/std/async.yo +3 -7
  48. package/std/build.yo +105 -151
  49. package/std/cli/arg_parser.yo +184 -169
  50. package/std/collections/array_list.yo +350 -314
  51. package/std/collections/btree_map.yo +142 -131
  52. package/std/collections/deque.yo +132 -128
  53. package/std/collections/hash_map.yo +542 -566
  54. package/std/collections/hash_set.yo +623 -687
  55. package/std/collections/linked_list.yo +275 -293
  56. package/std/collections/ordered_map.yo +113 -85
  57. package/std/collections/priority_queue.yo +73 -73
  58. package/std/crypto/md5.yo +191 -95
  59. package/std/crypto/random.yo +56 -64
  60. package/std/crypto/sha256.yo +151 -107
  61. package/std/encoding/base64.yo +87 -81
  62. package/std/encoding/hex.yo +43 -50
  63. package/std/encoding/html.yo +56 -81
  64. package/std/encoding/html_char_utils.yo +7 -13
  65. package/std/encoding/html_entities.yo +2248 -2253
  66. package/std/encoding/json.yo +316 -224
  67. package/std/encoding/punycode.yo +86 -116
  68. package/std/encoding/toml.yo +67 -66
  69. package/std/encoding/utf16.yo +37 -44
  70. package/std/env.yo +62 -91
  71. package/std/error.yo +12 -20
  72. package/std/fmt/display.yo +5 -9
  73. package/std/fmt/index.yo +8 -14
  74. package/std/fmt/to_string.yo +330 -315
  75. package/std/fmt/writer.yo +58 -87
  76. package/std/fs/dir.yo +83 -102
  77. package/std/fs/file.yo +147 -180
  78. package/std/fs/metadata.yo +45 -78
  79. package/std/fs/temp.yo +55 -65
  80. package/std/fs/types.yo +27 -40
  81. package/std/fs/walker.yo +53 -68
  82. package/std/gc.yo +5 -8
  83. package/std/glob.yo +30 -43
  84. package/std/http/client.yo +107 -120
  85. package/std/http/http.yo +106 -96
  86. package/std/http/index.yo +4 -6
  87. package/std/imm/list.yo +88 -93
  88. package/std/imm/map.yo +528 -464
  89. package/std/imm/set.yo +52 -57
  90. package/std/imm/sorted_map.yo +340 -286
  91. package/std/imm/sorted_set.yo +57 -63
  92. package/std/imm/string.yo +404 -345
  93. package/std/imm/vec.yo +173 -181
  94. package/std/io/reader.yo +3 -6
  95. package/std/io/writer.yo +4 -8
  96. package/std/libc/assert.yo +5 -9
  97. package/std/libc/ctype.yo +32 -22
  98. package/std/libc/dirent.yo +26 -25
  99. package/std/libc/errno.yo +164 -90
  100. package/std/libc/fcntl.yo +52 -45
  101. package/std/libc/float.yo +66 -44
  102. package/std/libc/limits.yo +42 -33
  103. package/std/libc/math.yo +53 -82
  104. package/std/libc/signal.yo +72 -47
  105. package/std/libc/stdatomic.yo +217 -188
  106. package/std/libc/stdint.yo +5 -29
  107. package/std/libc/stdio.yo +5 -29
  108. package/std/libc/stdlib.yo +32 -39
  109. package/std/libc/string.yo +5 -23
  110. package/std/libc/sys/stat.yo +58 -56
  111. package/std/libc/time.yo +5 -19
  112. package/std/libc/unistd.yo +5 -20
  113. package/std/libc/wctype.yo +6 -9
  114. package/std/libc/windows.yo +26 -30
  115. package/std/log.yo +41 -55
  116. package/std/net/addr.yo +102 -97
  117. package/std/net/dns.yo +27 -28
  118. package/std/net/errors.yo +50 -49
  119. package/std/net/tcp.yo +113 -124
  120. package/std/net/udp.yo +55 -66
  121. package/std/os/env.yo +35 -33
  122. package/std/os/signal.yo +15 -25
  123. package/std/path.yo +276 -311
  124. package/std/prelude.yo +6316 -4333
  125. package/std/process/command.yo +87 -103
  126. package/std/process/index.yo +12 -31
  127. package/std/regex/compiler.yo +196 -95
  128. package/std/regex/flags.yo +58 -39
  129. package/std/regex/index.yo +157 -173
  130. package/std/regex/match.yo +20 -31
  131. package/std/regex/node.yo +134 -152
  132. package/std/regex/parser.yo +283 -259
  133. package/std/regex/unicode.yo +172 -202
  134. package/std/regex/vm.yo +155 -171
  135. package/std/string/index.yo +5 -7
  136. package/std/string/rune.yo +45 -55
  137. package/std/string/string.yo +937 -964
  138. package/std/string/string_builder.yo +94 -104
  139. package/std/string/unicode.yo +46 -64
  140. package/std/sync/channel.yo +72 -73
  141. package/std/sync/cond.yo +31 -36
  142. package/std/sync/mutex.yo +30 -32
  143. package/std/sync/once.yo +13 -16
  144. package/std/sync/rwlock.yo +26 -31
  145. package/std/sync/waitgroup.yo +20 -25
  146. package/std/sys/advise.yo +16 -24
  147. package/std/sys/bufio/buf_reader.yo +77 -93
  148. package/std/sys/bufio/buf_writer.yo +52 -65
  149. package/std/sys/clock.yo +4 -9
  150. package/std/sys/constants.yo +77 -61
  151. package/std/sys/copy.yo +4 -10
  152. package/std/sys/dir.yo +26 -43
  153. package/std/sys/dns.yo +41 -61
  154. package/std/sys/errors.yo +95 -103
  155. package/std/sys/events.yo +45 -57
  156. package/std/sys/externs.yo +319 -267
  157. package/std/sys/fallocate.yo +7 -11
  158. package/std/sys/fcntl.yo +14 -22
  159. package/std/sys/file.yo +26 -40
  160. package/std/sys/future.yo +5 -8
  161. package/std/sys/iov.yo +12 -25
  162. package/std/sys/lock.yo +12 -13
  163. package/std/sys/mmap.yo +38 -43
  164. package/std/sys/path.yo +3 -8
  165. package/std/sys/perm.yo +7 -21
  166. package/std/sys/pipe.yo +5 -12
  167. package/std/sys/process.yo +23 -29
  168. package/std/sys/seek.yo +10 -12
  169. package/std/sys/signal.yo +7 -13
  170. package/std/sys/signals.yo +52 -35
  171. package/std/sys/socket.yo +63 -58
  172. package/std/sys/socketpair.yo +3 -6
  173. package/std/sys/sockinfo.yo +11 -20
  174. package/std/sys/statfs.yo +11 -34
  175. package/std/sys/statx.yo +25 -52
  176. package/std/sys/sysinfo.yo +15 -20
  177. package/std/sys/tcp.yo +62 -92
  178. package/std/sys/temp.yo +5 -9
  179. package/std/sys/time.yo +5 -15
  180. package/std/sys/timer.yo +6 -11
  181. package/std/sys/tty.yo +10 -18
  182. package/std/sys/udp.yo +22 -39
  183. package/std/sys/umask.yo +3 -6
  184. package/std/sys/unix.yo +33 -52
  185. package/std/testing/bench.yo +49 -52
  186. package/std/thread.yo +10 -15
  187. package/std/time/datetime.yo +105 -89
  188. package/std/time/duration.yo +43 -56
  189. package/std/time/instant.yo +13 -18
  190. package/std/time/sleep.yo +5 -9
  191. package/std/url/index.yo +184 -209
  192. package/std/worker.yo +6 -10
  193. package/out/types/src/evaluator/calls/module-type.d.ts +0 -11
  194. package/out/types/src/evaluator/types/module.d.ts +0 -19
package/std/imm/vec.yo CHANGED
@@ -16,114 +16,117 @@
16
16
  //! assert((v.get(usize(0)).unwrap() == i32(1)), "first element");
17
17
  //! assert((v.len() == usize(3)), "length is 3");
18
18
  //! ```
19
-
20
- { GlobalAllocator } :: import "../allocator.yo";
19
+ { GlobalAllocator } :: import("../allocator.yo");
21
20
  { malloc, free } :: GlobalAllocator;
22
-
23
21
  /// Persistent immutable vector.
24
22
  ///
25
23
  /// Backed by a shared flat array with copy-on-write semantics.
26
24
  /// All mutations create a new vector, sharing the backing buffer via
27
25
  /// atomic reference counting when possible.
28
26
  Vec :: (fn(comptime(T) : Type, where(T <: Send)) -> comptime(Type))(
29
- atomic object(
30
- _ptr : *(T),
31
- _len : usize,
32
- _cap : usize
27
+ atomic(
28
+ object(
29
+ _ptr : *(T),
30
+ _len : usize,
31
+ _cap : usize
32
+ )
33
+ )
34
+ );
35
+ impl(
36
+ forall(T : Type),
37
+ where(T <: Send),
38
+ Vec(T),
39
+ Dispose(
40
+ dispose : (fn(self : Self) -> unit)({
41
+ i := usize(0);
42
+ while(i < self._len, i = (i + usize(1)), {
43
+ unsafe.drop((self._ptr &+ i).*);
44
+ });
45
+ free(.Some(*(void)(self._ptr)));
46
+ })
33
47
  )
34
48
  );
35
-
36
- impl(forall(T : Type), where(T <: Send), Vec(T), Dispose(
37
- dispose : (fn(self: Self) -> unit)({
38
- i := usize(0);
39
- while (i < self._len), (i = (i + usize(1))), {
40
- unsafe.drop((self._ptr &+ i).*);
41
- };
42
- free(.Some(*(void)(self._ptr)));
43
- })
44
- ));
45
-
46
49
  /// Result of a pop operation.
47
50
  PopResult :: (fn(comptime(T) : Type, where(T <: Send)) -> comptime(Type))(
48
- struct(vec: Vec(T), value: Option(T))
51
+ struct(vec : Vec(T), value : Option(T))
49
52
  );
50
-
51
- impl(forall(T : Type), where(T <: Send), Vec(T),
53
+ impl(
54
+ forall(T : Type),
55
+ where(T <: Send),
56
+ Vec(T),
52
57
  /// Allocate raw buffer without creating an intermediate atomic object.
53
- _raw_alloc : (fn(cap: usize) -> *(T))({
58
+ _raw_alloc : (fn(cap : usize) -> *(T))({
54
59
  alloc_cap := cond(
55
60
  (cap > usize(0)) => cap,
56
61
  true => usize(1)
57
62
  );
58
63
  sz := (sizeof(T) * alloc_cap);
59
- match(malloc(sz),
64
+ match(
65
+ malloc(sz),
60
66
  .Some(p) => *(T)(p),
61
67
  .None => panic("imm.Vec: allocation failed")
62
68
  )
63
69
  }),
64
-
65
70
  /// Copy elements element-by-element so RC-backed values duplicate correctly.
66
- _copy_elems : (fn(
67
- dst: *(T), src: *(T),
68
- dst_offset: usize, src_offset: usize, count: usize
69
- ) -> unit)({
71
+ _copy_elems : (
72
+ fn(
73
+ dst : *(T),
74
+ src : *(T),
75
+ dst_offset : usize,
76
+ src_offset : usize,
77
+ count : usize
78
+ ) -> unit
79
+ )({
70
80
  i := usize(0);
71
- while (i < count), (i = (i + usize(1))), {
81
+ while(i < count, i = (i + usize(1)), {
72
82
  consume((dst &+ (dst_offset + i)).* = (src &+ (src_offset + i)).*);
73
- };
83
+ });
74
84
  }),
75
-
76
85
  /// Create a new empty vector.
77
86
  new : (fn() -> Self)(
78
- Self(_ptr: Self._raw_alloc(usize(4)), _len: usize(0), _cap: usize(4))
87
+ Self(_ptr : Self._raw_alloc(usize(4)), _len : usize(0), _cap : usize(4))
79
88
  ),
80
-
81
89
  /// Create a new empty vector with the given initial capacity.
82
- with_capacity : (fn(cap: usize) -> Self)(
83
- Self(_ptr: Self._raw_alloc(cap), _len: usize(0), _cap: cap)
90
+ with_capacity : (fn(cap : usize) -> Self)(
91
+ Self(_ptr : Self._raw_alloc(cap), _len : usize(0), _cap : cap)
84
92
  ),
85
-
86
93
  /// Number of elements in the vector.
87
- len : (fn(self: Self) -> usize)(self._len),
88
-
94
+ len : (fn(self : Self) -> usize)(self._len),
89
95
  /// Check if the vector is empty.
90
- is_empty : (fn(self: Self) -> bool)(self._len == usize(0)),
91
-
96
+ is_empty : (fn(self : Self) -> bool)(self._len == usize(0)),
92
97
  /// Get the element at `idx`, or `.None` if out of bounds.
93
- get : (fn(self: Self, idx: usize) -> Option(T))({
94
- if((idx >= self._len), {
95
- return .None;
98
+ get : (fn(self : Self, idx : usize) -> Option(T))({
99
+ if(idx >= self._len, {
100
+ return(.None);
96
101
  });
97
102
  .Some((self._ptr &+ idx).*)
98
103
  }),
99
-
100
104
  /// Return a new vector with the element at `idx` replaced by `val`.
101
105
  /// Panics if `idx >= len`.
102
- set : (fn(own(self): Self, idx: usize, val: T) -> Self)({
103
- assert((idx < self._len), "imm.Vec.set: index out of bounds");
104
- if((rc(self) == usize(1)), {
106
+ set : (fn(own(self) : Self, idx : usize, val : T) -> Self)({
107
+ assert(idx < self._len, "imm.Vec.set: index out of bounds");
108
+ if(rc(self) == usize(1), {
105
109
  unsafe.drop((self._ptr &+ idx).*);
106
110
  consume((self._ptr &+ idx).* = val);
107
- return self;
111
+ return(self);
108
112
  });
109
113
  new_ptr := Self._raw_alloc(self._len);
110
- if((self._len > usize(0)), {
114
+ if(self._len > usize(0), {
111
115
  Self._copy_elems(new_ptr, self._ptr, usize(0), usize(0), self._len);
112
116
  });
113
117
  unsafe.drop((new_ptr &+ idx).*);
114
118
  consume((new_ptr &+ idx).* = val);
115
- result := Self(_ptr: new_ptr, _len: self._len, _cap: self._len);
119
+ result := Self(_ptr : new_ptr, _len : self._len, _cap : self._len);
116
120
  unsafe.drop(self);
117
121
  result
118
122
  }),
119
-
120
123
  /// Return a new vector with `val` appended.
121
- push : (fn(own(self): Self, val: T) -> Self)({
122
- if((rc(self) == usize(1)), {
123
- if((self._len >= self._cap), {
124
+ push : (fn(own(self) : Self, val : T) -> Self)({
125
+ if(rc(self) == usize(1), {
126
+ if(self._len >= self._cap, {
124
127
  new_cap := (self._cap * usize(2));
125
128
  new_ptr := Self._raw_alloc(new_cap);
126
- if((self._len > usize(0)), {
129
+ if(self._len > usize(0), {
127
130
  Self._copy_elems(new_ptr, self._ptr, usize(0), usize(0), self._len);
128
131
  });
129
132
  free(.Some(*(void)(self._ptr)));
@@ -132,7 +135,7 @@ impl(forall(T : Type), where(T <: Send), Vec(T),
132
135
  });
133
136
  consume((self._ptr &+ self._len).* = val);
134
137
  self._len = (self._len + usize(1));
135
- return self;
138
+ return(self);
136
139
  });
137
140
  new_cap := cond(
138
141
  (self._len < self._cap) => self._cap,
@@ -140,53 +143,49 @@ impl(forall(T : Type), where(T <: Send), Vec(T),
140
143
  true => (self._cap * usize(2))
141
144
  );
142
145
  new_ptr := Self._raw_alloc(new_cap);
143
- if((self._len > usize(0)), {
146
+ if(self._len > usize(0), {
144
147
  Self._copy_elems(new_ptr, self._ptr, usize(0), usize(0), self._len);
145
148
  });
146
149
  consume((new_ptr &+ self._len).* = val);
147
- result := Self(_ptr: new_ptr, _len: (self._len + usize(1)), _cap: new_cap);
150
+ result := Self(_ptr : new_ptr, _len : (self._len + usize(1)), _cap : new_cap);
148
151
  unsafe.drop(self);
149
152
  result
150
153
  }),
151
-
152
154
  /// Return the first element, or `.None` if empty.
153
- first : (fn(self: Self) -> Option(T))({
155
+ first : (fn(self : Self) -> Option(T))({
154
156
  if(self.is_empty(), {
155
- return .None;
157
+ return(.None);
156
158
  });
157
159
  .Some(self._ptr.*)
158
160
  }),
159
-
160
161
  /// Return the last element, or `.None` if empty.
161
- last : (fn(self: Self) -> Option(T))({
162
+ last : (fn(self : Self) -> Option(T))({
162
163
  if(self.is_empty(), {
163
- return .None;
164
+ return(.None);
164
165
  });
165
166
  .Some((self._ptr &+ (self._len - usize(1))).*)
166
167
  }),
167
-
168
168
  /// Return a new vector without the last element, and the removed element.
169
- pop : (fn(own(self): Self) -> PopResult(T))({
169
+ pop : (fn(own(self) : Self) -> PopResult(T))({
170
170
  if(self.is_empty(), {
171
- return PopResult(T)(vec: self, value: .None);
171
+ return(PopResult(T)(vec : self, value :.None));
172
172
  });
173
173
  val := (self._ptr &+ (self._len - usize(1))).*;
174
174
  new_len := (self._len - usize(1));
175
- if((rc(self) == usize(1)), {
175
+ if(rc(self) == usize(1), {
176
176
  self._len = new_len;
177
- return PopResult(T)(vec: self, value: .Some(val));
177
+ return(PopResult(T)(vec : self, value :.Some(val)));
178
178
  });
179
179
  new_ptr := Self._raw_alloc(self._cap);
180
- if((new_len > usize(0)), {
180
+ if(new_len > usize(0), {
181
181
  Self._copy_elems(new_ptr, self._ptr, usize(0), usize(0), new_len);
182
182
  });
183
- new_vec := Self(_ptr: new_ptr, _len: new_len, _cap: self._cap);
183
+ new_vec := Self(_ptr : new_ptr, _len : new_len, _cap : self._cap);
184
184
  unsafe.drop(self);
185
- PopResult(T)(vec: new_vec, value: .Some(val))
185
+ PopResult(T)(vec : new_vec, value :.Some(val))
186
186
  }),
187
-
188
187
  /// Return a new vector containing only elements in range [start, end).
189
- slice : (fn(self: Self, start: usize, end: usize) -> Self)({
188
+ slice : (fn(self : Self, start : usize, end : usize) -> Self)({
190
189
  (actual_start : usize) = cond(
191
190
  (start > self._len) => self._len,
192
191
  true => start
@@ -195,262 +194,255 @@ impl(forall(T : Type), where(T <: Send), Vec(T),
195
194
  (end > self._len) => self._len,
196
195
  true => end
197
196
  );
198
- if((actual_start >= actual_end), {
199
- return Self.new();
197
+ if(actual_start >= actual_end, {
198
+ return(Self.new());
200
199
  });
201
200
  new_len := (actual_end - actual_start);
202
201
  new_ptr := Self._raw_alloc(new_len);
203
202
  Self._copy_elems(new_ptr, self._ptr, usize(0), actual_start, new_len);
204
- Self(_ptr: new_ptr, _len: new_len, _cap: new_len)
203
+ Self(_ptr : new_ptr, _len : new_len, _cap : new_len)
205
204
  }),
206
-
207
205
  /// Return a new vector that is the concatenation of self and other.
208
- concat : (fn(own(self): Self, other: Self) -> Self)({
206
+ concat : (fn(own(self) : Self, other : Self) -> Self)({
209
207
  total := (self._len + other._len);
210
- if((rc(self) == usize(1)), {
211
- if((total <= self._cap), {
212
- if((other._len > usize(0)), {
208
+ if(rc(self) == usize(1), {
209
+ if(total <= self._cap, {
210
+ if(other._len > usize(0), {
213
211
  Self._copy_elems(self._ptr, other._ptr, self._len, usize(0), other._len);
214
212
  });
215
213
  self._len = total;
216
- return self;
214
+ return(self);
217
215
  });
218
216
  new_cap := cond(
219
217
  (total > (self._cap * usize(2))) => total,
220
218
  true => (self._cap * usize(2))
221
219
  );
222
220
  new_ptr := Self._raw_alloc(new_cap);
223
- if((self._len > usize(0)), {
221
+ if(self._len > usize(0), {
224
222
  Self._copy_elems(new_ptr, self._ptr, usize(0), usize(0), self._len);
225
223
  });
226
- if((other._len > usize(0)), {
224
+ if(other._len > usize(0), {
227
225
  Self._copy_elems(new_ptr, other._ptr, self._len, usize(0), other._len);
228
226
  });
229
227
  free(.Some(*(void)(self._ptr)));
230
228
  self._ptr = new_ptr;
231
229
  self._len = total;
232
230
  self._cap = new_cap;
233
- return self;
231
+ return(self);
234
232
  });
235
233
  new_ptr := Self._raw_alloc(total);
236
- if((self._len > usize(0)), {
234
+ if(self._len > usize(0), {
237
235
  Self._copy_elems(new_ptr, self._ptr, usize(0), usize(0), self._len);
238
236
  });
239
- if((other._len > usize(0)), {
237
+ if(other._len > usize(0), {
240
238
  Self._copy_elems(new_ptr, other._ptr, self._len, usize(0), other._len);
241
239
  });
242
- result := Self(_ptr: new_ptr, _len: total, _cap: total);
240
+ result := Self(_ptr : new_ptr, _len : total, _cap : total);
243
241
  unsafe.drop(self);
244
242
  result
245
243
  }),
246
-
247
244
  /// Return a new vector with elements reversed.
248
- reverse : (fn(own(self): Self) -> Self)({
249
- if((self._len <= usize(1)), {
250
- return self;
245
+ reverse : (fn(own(self) : Self) -> Self)({
246
+ if(self._len <= usize(1), {
247
+ return(self);
251
248
  });
252
- if((rc(self) == usize(1)), {
249
+ if(rc(self) == usize(1), {
253
250
  left := usize(0);
254
251
  right := (self._len - usize(1));
255
- while (left < right), { left = (left + usize(1)); right = (right - usize(1)); }, {
252
+ while(left < right, {
253
+ left = (left + usize(1));
254
+ right = (right - usize(1));
255
+ }, {
256
256
  tmp := (self._ptr &+ left).*;
257
257
  consume((self._ptr &+ left).* = (self._ptr &+ right).*);
258
258
  consume((self._ptr &+ right).* = tmp);
259
- };
260
- return self;
259
+ });
260
+ return(self);
261
261
  });
262
262
  new_ptr := Self._raw_alloc(self._len);
263
263
  i := usize(0);
264
- while (i < self._len), (i = (i + usize(1))), {
264
+ while(i < self._len, i = (i + usize(1)), {
265
265
  (new_ptr &+ i).* = (self._ptr &+ ((self._len - usize(1)) - i)).*;
266
- };
267
- result := Self(_ptr: new_ptr, _len: self._len, _cap: self._len);
266
+ });
267
+ result := Self(_ptr : new_ptr, _len : self._len, _cap : self._len);
268
268
  unsafe.drop(self);
269
269
  result
270
270
  }),
271
-
272
271
  /// Apply a function to each element, producing a new vector.
273
- map : (fn(forall(U : Type), self: Self, f: Impl(Fn(a: T) -> U), where(U <: Send)) -> Vec(U))({
272
+ map : (fn(forall(U : Type), self : Self, f : Impl(Fn(a : T) -> U), where(U <: Send)) -> Vec(U))({
274
273
  new_ptr := Vec(U)._raw_alloc(self._len);
275
274
  i := usize(0);
276
- while (i < self._len), (i = (i + usize(1))), {
275
+ while(i < self._len, i = (i + usize(1)), {
277
276
  (new_ptr &+ i).* = f((self._ptr &+ i).*);
278
- };
279
- Vec(U)(_ptr: new_ptr, _len: self._len, _cap: self._len)
277
+ });
278
+ Vec(U)(_ptr : new_ptr, _len : self._len, _cap : self._len)
280
279
  }),
281
-
282
280
  /// Filter elements by a predicate, returning a new vector.
283
- filter : (fn(self: Self, f: Impl(Fn(a: T) -> bool)) -> Self)({
281
+ filter : (fn(self : Self, f : Impl(Fn(a : T) -> bool)) -> Self)({
284
282
  new_ptr := Self._raw_alloc(self._len);
285
283
  count := usize(0);
286
284
  i := usize(0);
287
- while (i < self._len), (i = (i + usize(1))), {
285
+ while(i < self._len, i = (i + usize(1)), {
288
286
  elem := (self._ptr &+ i).*;
289
287
  if(f(elem), {
290
288
  (new_ptr &+ count).* = elem;
291
289
  count = (count + usize(1));
292
290
  });
293
- };
294
- Self(_ptr: new_ptr, _len: count, _cap: self._len)
291
+ });
292
+ Self(_ptr : new_ptr, _len : count, _cap : self._len)
295
293
  }),
296
-
297
294
  /// Left fold over elements.
298
- fold : (fn(forall(U : Type), self: Self, init: U, f: Impl(Fn(acc: U, elem: T) -> U)) -> U)({
295
+ fold : (fn(forall(U : Type), self : Self, init : U, f : Impl(Fn(acc : U, elem : T) -> U)) -> U)({
299
296
  (acc : U) = init;
300
297
  i := usize(0);
301
- while (i < self._len), (i = (i + usize(1))), {
298
+ while(i < self._len, i = (i + usize(1)), {
302
299
  acc = f(acc, (self._ptr &+ i).*);
303
- };
300
+ });
304
301
  acc
305
302
  }),
306
-
307
303
  /// Check if any element satisfies the predicate.
308
- any : (fn(self: Self, f: Impl(Fn(a: T) -> bool)) -> bool)({
304
+ any : (fn(self : Self, f : Impl(Fn(a : T) -> bool)) -> bool)({
309
305
  i := usize(0);
310
306
  (found : bool) = false;
311
- while ((i < self._len) && !(found)), (i = (i + usize(1))), {
307
+ while((i < self._len) && !(found), i = (i + usize(1)), {
312
308
  if(f((self._ptr &+ i).*), {
313
309
  found = true;
314
310
  });
315
- };
311
+ });
316
312
  found
317
313
  }),
318
-
319
314
  /// Check if all elements satisfy the predicate.
320
- all : (fn(self: Self, f: Impl(Fn(a: T) -> bool)) -> bool)({
315
+ all : (fn(self : Self, f : Impl(Fn(a : T) -> bool)) -> bool)({
321
316
  i := usize(0);
322
317
  (ok : bool) = true;
323
- while ((i < self._len) && ok), (i = (i + usize(1))), {
318
+ while((i < self._len) && ok, i = (i + usize(1)), {
324
319
  if(!(f((self._ptr &+ i).*)), {
325
320
  ok = false;
326
321
  });
327
- };
322
+ });
328
323
  ok
329
324
  }),
330
-
331
325
  /// Find the first element satisfying the predicate.
332
- find : (fn(self: Self, f: Impl(Fn(a: T) -> bool)) -> Option(T))({
326
+ find : (fn(self : Self, f : Impl(Fn(a : T) -> bool)) -> Option(T))({
333
327
  i := usize(0);
334
- (result : Option(T)) = .None;
335
- while ((i < self._len) && result.is_none()), (i = (i + usize(1))), {
328
+ (result : Option(T)) =.None;
329
+ while((i < self._len) && result.is_none(), i = (i + usize(1)), {
336
330
  elem := (self._ptr &+ i).*;
337
331
  if(f(elem), {
338
- result = .Some(elem);
332
+ result =.Some(elem);
339
333
  });
340
- };
334
+ });
341
335
  result
342
336
  }),
343
-
344
337
  /// Return the index of the first element equal to `val`, or `.None`.
345
- index_of : (fn(self: Self, val: T, where(T <: Eq(T))) -> Option(usize))({
338
+ index_of : (fn(self : Self, val : T, where(T <: Eq(T))) -> Option(usize))({
346
339
  i := usize(0);
347
- (result : Option(usize)) = .None;
348
- while ((i < self._len) && result.is_none()), (i = (i + usize(1))), {
349
- if(((self._ptr &+ i).* == val), {
350
- result = .Some(i);
340
+ (result : Option(usize)) =.None;
341
+ while((i < self._len) && result.is_none(), i = (i + usize(1)), {
342
+ if((self._ptr &+ i).* == val, {
343
+ result =.Some(i);
351
344
  });
352
- };
345
+ });
353
346
  result
354
347
  }),
355
-
356
348
  /// Check if the vector contains `val`.
357
- contains : (fn(self: Self, val: T, where(T <: Eq(T))) -> bool)(
349
+ contains : (fn(self : Self, val : T, where(T <: Eq(T))) -> bool)(
358
350
  self.index_of(val).is_some()
359
351
  ),
360
-
361
352
  /// Return a new vector with duplicate elements removed (preserves first occurrence).
362
- dedup : (fn(own(self): Self, where(T <: Eq(T))) -> Self)({
363
- if((self._len <= usize(1)), {
364
- return self;
353
+ dedup : (fn(own(self) : Self, where(T <: Eq(T))) -> Self)({
354
+ if(self._len <= usize(1), {
355
+ return(self);
365
356
  });
366
- if((rc(self) == usize(1)), {
357
+ if(rc(self) == usize(1), {
367
358
  count := usize(1);
368
359
  i := usize(1);
369
- while (i < self._len), (i = (i + usize(1))), {
360
+ while(i < self._len, i = (i + usize(1)), {
370
361
  elem := (self._ptr &+ i).*;
371
362
  (found : bool) = false;
372
363
  j := usize(0);
373
- while ((j < count) && !(found)), (j = (j + usize(1))), {
374
- if(((self._ptr &+ j).* == elem), {
364
+ while((j < count) && !(found), j = (j + usize(1)), {
365
+ if((self._ptr &+ j).* == elem, {
375
366
  found = true;
376
367
  });
377
- };
368
+ });
378
369
  if(!(found), {
379
- if((count != i), {
370
+ if(count != i, {
380
371
  consume((self._ptr &+ count).* = elem);
381
372
  });
382
373
  count = (count + usize(1));
383
374
  });
384
- };
375
+ });
385
376
  self._len = count;
386
- return self;
377
+ return(self);
387
378
  });
388
379
  new_ptr := Self._raw_alloc(self._len);
389
380
  count := usize(0);
390
381
  i := usize(0);
391
- while (i < self._len), (i = (i + usize(1))), {
382
+ while(i < self._len, i = (i + usize(1)), {
392
383
  elem := (self._ptr &+ i).*;
393
384
  (found : bool) = false;
394
385
  j := usize(0);
395
- while ((j < count) && !(found)), (j = (j + usize(1))), {
396
- if(((new_ptr &+ j).* == elem), {
386
+ while((j < count) && !(found), j = (j + usize(1)), {
387
+ if((new_ptr &+ j).* == elem, {
397
388
  found = true;
398
389
  });
399
- };
390
+ });
400
391
  if(!(found), {
401
392
  (new_ptr &+ count).* = elem;
402
393
  count = (count + usize(1));
403
394
  });
404
- };
405
- result := Self(_ptr: new_ptr, _len: count, _cap: self._len);
395
+ });
396
+ result := Self(_ptr : new_ptr, _len : count, _cap : self._len);
406
397
  unsafe.drop(self);
407
398
  result
408
399
  }),
409
-
410
400
  /// Zip two vectors together using a combining function.
411
- zip_with : (fn(forall(U : Type, V : Type), self: Self, other: Vec(U), f: Impl(Fn(a: T, b: U) -> V), where(U <: Send, V <: Send)) -> Vec(V))({
401
+ zip_with : (fn(forall(U : Type, V : Type), self : Self, other : Vec(U), f : Impl(Fn(a : T, b : U) -> V), where(U <: Send, V <: Send)) -> Vec(V))({
412
402
  min_len := cond(
413
403
  (self._len < other._len) => self._len,
414
404
  true => other._len
415
405
  );
416
406
  new_ptr := Vec(V)._raw_alloc(min_len);
417
407
  i := usize(0);
418
- while (i < min_len), (i = (i + usize(1))), {
408
+ while(i < min_len, i = (i + usize(1)), {
419
409
  (new_ptr &+ i).* = f((self._ptr &+ i).*, other.get(i).unwrap());
420
- };
421
- Vec(V)(_ptr: new_ptr, _len: min_len, _cap: min_len)
410
+ });
411
+ Vec(V)(_ptr : new_ptr, _len : min_len, _cap : min_len)
422
412
  }),
423
-
424
413
  /// Create a vector from a slice, copying all elements.
425
- from_slice : (fn(s: Slice(T)) -> Self)({
414
+ from_slice : (fn(s : Slice(T)) -> Self)({
426
415
  slen := s.len();
427
416
  cap := cond(
428
417
  (slen > usize(0)) => slen,
429
418
  true => usize(4)
430
419
  );
431
420
  new_ptr := Self._raw_alloc(cap);
432
- if((slen > usize(0)), {
421
+ if(slen > usize(0), {
433
422
  Self._copy_elems(new_ptr, s.ptr(), usize(0), usize(0), slen);
434
423
  });
435
- Self(_ptr: new_ptr, _len: slen, _cap: cap)
424
+ Self(_ptr : new_ptr, _len : slen, _cap : cap)
436
425
  })
437
426
  );
438
-
439
427
  /// Eq trait for Vec(T) — element-wise equality.
440
- impl(forall(T : Type), where(T <: (Send, Eq(T))), Vec(T), Eq(Vec(T))(
441
- (==) : (fn(lhs: Self, rhs: Self) -> bool)({
442
- if((lhs._len != rhs._len), {
443
- return false;
444
- });
445
- i := usize(0);
446
- (equal : bool) = true;
447
- while ((i < lhs._len) && equal), (i = (i + usize(1))), {
448
- if(((lhs._ptr &+ i).* != (rhs._ptr &+ i).*), {
449
- equal = false;
428
+ impl(
429
+ forall(T : Type),
430
+ where(T <: (Send, Eq(T))),
431
+ Vec(T),
432
+ Eq(Vec(T))(
433
+ (==) : (fn(lhs : Self, rhs : Self) -> bool)({
434
+ if(lhs._len != rhs._len, {
435
+ return(false);
450
436
  });
451
- };
452
- equal
453
- })
454
- ));
455
-
456
- export Vec, PopResult;
437
+ i := usize(0);
438
+ (equal : bool) = true;
439
+ while((i < lhs._len) && equal, i = (i + usize(1)), {
440
+ if((lhs._ptr &+ i).* != (rhs._ptr &+ i).*, {
441
+ equal = false;
442
+ });
443
+ });
444
+ equal
445
+ })
446
+ )
447
+ );
448
+ export(Vec, PopResult);
package/std/io/reader.yo CHANGED
@@ -1,13 +1,10 @@
1
1
  //! Reader trait for byte-level input.
2
-
3
- { Exception } :: import "../error";
4
-
2
+ { Exception } :: import("../error");
5
3
  /// Common interface for reading bytes from various sources.
6
4
  Reader :: trait(
7
5
  /// Read up to `size` bytes into buffer `buf`.
8
6
  /// Returns the number of bytes actually read (0 at end-of-stream).
9
7
  read :
10
- fn(self: *(Self), buf: *(u8), size: usize, using(exn : Exception)) -> usize
8
+ fn(self : *(Self), buf : *(u8), size : usize, using(exn : Exception)) -> usize
11
9
  );
12
-
13
- export Reader;
10
+ export(Reader);
package/std/io/writer.yo CHANGED
@@ -1,16 +1,12 @@
1
1
  //! Writer trait for byte-level output.
2
-
3
- { Exception } :: import "../error";
4
-
2
+ { Exception } :: import("../error");
5
3
  /// Common interface for writing bytes to a destination.
6
4
  Writer :: trait(
7
5
  /// Write bytes from buffer. Returns number of bytes written.
8
6
  write :
9
- fn(self: *(Self), buf: *(u8), size: usize, using(exn : Exception)) -> usize,
10
-
7
+ fn(self : *(Self), buf : *(u8), size : usize, using(exn : Exception)) -> usize,
11
8
  /// Flush any buffered data to the underlying destination.
12
9
  flush :
13
- fn(self: *(Self), using(exn : Exception)) -> unit
10
+ fn(self : *(Self), using(exn : Exception)) -> unit
14
11
  );
15
-
16
- export Writer;
12
+ export(Writer);