@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/sys/advise.yo CHANGED
@@ -2,35 +2,27 @@
2
2
  //!
3
3
  //! Advisory wrappers for file and memory access pattern hints.
4
4
  //! Returns 0 on success, -errno / negative platform error on failure.
5
-
6
- {
7
- __yo_sync_fadvise,
8
- __yo_sync_madvise
9
- } :: import "./externs.yo";
10
-
11
- POSIX_FADV_NORMAL :: i32(0);
12
- POSIX_FADV_RANDOM :: i32(1);
5
+ { __yo_sync_fadvise, __yo_sync_madvise } :: import("./externs.yo");
6
+ POSIX_FADV_NORMAL :: i32(0);
7
+ POSIX_FADV_RANDOM :: i32(1);
13
8
  POSIX_FADV_SEQUENTIAL :: i32(2);
14
- POSIX_FADV_WILLNEED :: i32(3);
15
- POSIX_FADV_DONTNEED :: i32(4);
16
- POSIX_FADV_NOREUSE :: i32(5);
17
-
18
- MADV_NORMAL :: i32(0);
19
- MADV_RANDOM :: i32(1);
9
+ POSIX_FADV_WILLNEED :: i32(3);
10
+ POSIX_FADV_DONTNEED :: i32(4);
11
+ POSIX_FADV_NOREUSE :: i32(5);
12
+ MADV_NORMAL :: i32(0);
13
+ MADV_RANDOM :: i32(1);
20
14
  MADV_SEQUENTIAL :: i32(2);
21
- MADV_WILLNEED :: i32(3);
22
- MADV_DONTNEED :: i32(4);
23
-
24
- fadvise :: (fn(fd: i32, offset: i64, len: i64, advice: i32) -> i32)(
15
+ MADV_WILLNEED :: i32(3);
16
+ MADV_DONTNEED :: i32(4);
17
+ fadvise :: (fn(fd : i32, offset : i64, len : i64, advice : i32) -> i32)(
25
18
  __yo_sync_fadvise(fd, offset, len, advice)
26
19
  );
27
-
28
- madvise :: (fn(addr: *(u8), length: usize, advice: i32) -> i32)(
20
+ madvise :: (fn(addr : *(u8), length : usize, advice : i32) -> i32)(
29
21
  __yo_sync_madvise(addr, length, advice)
30
22
  );
31
-
32
- export
33
- fadvise, madvise,
23
+ export(
24
+ fadvise,
25
+ madvise,
34
26
  POSIX_FADV_NORMAL,
35
27
  POSIX_FADV_RANDOM,
36
28
  POSIX_FADV_SEQUENTIAL,
@@ -42,4 +34,4 @@ export
42
34
  MADV_SEQUENTIAL,
43
35
  MADV_WILLNEED,
44
36
  MADV_DONTNEED
45
- ;
37
+ );
@@ -17,77 +17,69 @@
17
17
  //! .Err(e) => println(e.to_string())
18
18
  //! );
19
19
  //! ```
20
-
21
- { ArrayList } :: import "../../collections/array_list";
22
- open import "../../string";
23
- { IOError } :: import "../errors";
24
- IO_file :: import "../file";
25
- { GlobalAllocator } :: import "../../allocator";
20
+ { ArrayList } :: import("../../collections/array_list");
21
+ open(import("../../string"));
22
+ { IOError } :: import("../errors");
23
+ IO_file :: import("../file");
24
+ { GlobalAllocator } :: import("../../allocator");
26
25
  { malloc, free } :: GlobalAllocator;
27
-
28
26
  _DEFAULT_BUF_SIZE :: usize(4096);
29
27
  _NEWLINE :: u8(10); // '\n'
30
-
31
28
  BufReader :: object(
32
- _fd : i32,
33
- _buf : ArrayList(u8),
34
- _pos : usize,
35
- _filled : usize,
36
- _offset : u64,
29
+ _fd : i32,
30
+ _buf : ArrayList(u8),
31
+ _pos : usize,
32
+ _filled : usize,
33
+ _offset : u64,
37
34
  _capacity : usize
38
35
  );
39
-
40
- impl(BufReader,
36
+ impl(
37
+ BufReader,
41
38
  // Create a buffered reader with default buffer size (4096 bytes).
42
- new : (fn(fd: i32) -> Self)(
39
+ new : (fn(fd : i32) -> Self)(
43
40
  Self(
44
- _fd: fd,
45
- _buf: ArrayList(u8).with_capacity(_DEFAULT_BUF_SIZE),
46
- _pos: usize(0),
47
- _filled: usize(0),
48
- _offset: u64(0),
49
- _capacity: _DEFAULT_BUF_SIZE
41
+ _fd : fd,
42
+ _buf : ArrayList(u8).with_capacity(_DEFAULT_BUF_SIZE),
43
+ _pos : usize(0),
44
+ _filled : usize(0),
45
+ _offset : u64(0),
46
+ _capacity : _DEFAULT_BUF_SIZE
50
47
  )
51
48
  ),
52
-
53
49
  // Create a buffered reader with a custom buffer size.
54
- with_capacity : (fn(fd: i32, capacity: usize) -> Self)(
50
+ with_capacity : (fn(fd : i32, capacity : usize) -> Self)(
55
51
  Self(
56
- _fd: fd,
57
- _buf: ArrayList(u8).with_capacity(capacity),
58
- _pos: usize(0),
59
- _filled: usize(0),
60
- _offset: u64(0),
61
- _capacity: capacity
52
+ _fd : fd,
53
+ _buf : ArrayList(u8).with_capacity(capacity),
54
+ _pos : usize(0),
55
+ _filled : usize(0),
56
+ _offset : u64(0),
57
+ _capacity : capacity
62
58
  )
63
59
  ),
64
-
65
60
  // Return the underlying file descriptor.
66
- fd : (fn(self: Self) -> i32)(
61
+ fd : (fn(self : Self) -> i32)(
67
62
  self._fd
68
63
  ),
69
-
70
64
  // Return the number of buffered bytes available to read without I/O.
71
- buffered : (fn(self: Self) -> usize)(
72
- (self._filled - self._pos)
65
+ buffered : (fn(self : Self) -> usize)(
66
+ self._filled - self._pos
73
67
  ),
74
-
75
68
  // Read a line from the reader (up to and including '\n').
76
69
  // Returns .None on EOF when no data is available.
77
70
  // Returns .Some(line) with the line content (without the trailing '\n').
78
- read_line : (fn(self: Self, using(io : IO)) -> Impl(Future(Result(Option(String), IOError), IO)))({
71
+ read_line : (fn(self : Self, using(io : IO)) -> Impl(Future(Result(Option(String), IOError), IO)))({
79
72
  the_fd := self._fd;
80
73
  io.async((using(io : IO)) => {
81
74
  line_bytes := ArrayList(u8).new();
82
75
  found_newline := false;
83
76
  hit_eof := false;
84
- (read_err : Option(IOError)) = .None;
85
-
86
- while runtime((((!(found_newline)) && (!(hit_eof))) && read_err.is_none())), {
77
+ (read_err : Option(IOError)) =.None;
78
+ while(runtime(((!(found_newline)) && (!(hit_eof))) && read_err.is_none()), {
87
79
  cond(
88
80
  (self._pos < self._filled) => {
89
81
  scan := self._pos;
90
- while runtime(((scan < self._filled) && (!(found_newline)))), {
82
+ while(runtime((scan < self._filled) && (!(found_newline))), {
91
83
  b := self._buf.get(scan).unwrap();
92
84
  cond(
93
85
  (b == _NEWLINE) => {
@@ -98,7 +90,7 @@ impl(BufReader,
98
90
  }
99
91
  );
100
92
  scan = (scan + usize(1));
101
- };
93
+ });
102
94
  self._pos = scan;
103
95
  },
104
96
  true => {
@@ -107,7 +99,7 @@ impl(BufReader,
107
99
  cond(
108
100
  (n < i32(0)) => {
109
101
  free(.Some(*(void)(raw_buf)));
110
- read_err = .Some(IOError.from_errno((i32(0) - n)));
102
+ read_err =.Some(IOError.from_errno(i32(0) - n));
111
103
  },
112
104
  (n == i32(0)) => {
113
105
  free(.Some(*(void)(raw_buf)));
@@ -117,10 +109,10 @@ impl(BufReader,
117
109
  self._offset = (self._offset + u64(n));
118
110
  self._buf = ArrayList(u8).with_capacity(self._capacity);
119
111
  i := usize(0);
120
- while runtime((i < usize(n))), {
112
+ while(runtime(i < usize(n)), {
121
113
  self._buf.push((raw_buf &+ i).*);
122
114
  i = (i + usize(1));
123
- };
115
+ });
124
116
  self._pos = usize(0);
125
117
  self._filled = usize(n);
126
118
  free(.Some(*(void)(raw_buf)));
@@ -128,29 +120,27 @@ impl(BufReader,
128
120
  );
129
121
  }
130
122
  );
131
- };
132
-
133
- match(read_err,
134
- .Some(e) => .Err(e),
123
+ });
124
+ match(
125
+ read_err,
126
+ .Some(e) =>.Err(e),
135
127
  .None =>
136
128
  cond(
137
- (hit_eof && (line_bytes.len() == usize(0))) => .Ok(.None),
138
- true => .Ok(.Some(String.from_bytes(line_bytes)))
129
+ (hit_eof && (line_bytes.len() == usize(0))) =>.Ok(.None),
130
+ true =>.Ok(.Some(String.from_bytes(line_bytes)))
139
131
  )
140
132
  )
141
133
  })
142
134
  }),
143
-
144
135
  // Read up to `size` bytes into a provided buffer.
145
136
  // Returns the number of bytes actually read.
146
- read : (fn(self: Self, buf: *(u8), size: u32, using(io : IO)) -> Impl(Future(Result(i32, IOError), IO)))({
137
+ read : (fn(self : Self, buf : *(u8), size : u32, using(io : IO)) -> Impl(Future(Result(i32, IOError), IO)))({
147
138
  the_fd := self._fd;
148
139
  io.async((using(io : IO)) => {
149
140
  available := (self._filled - self._pos);
150
- (read_err : Option(IOError)) = .None;
141
+ (read_err : Option(IOError)) =.None;
151
142
  (read_n : i32) = i32(0);
152
143
  done := false;
153
-
154
144
  // If there's data already buffered, serve from buffer
155
145
  cond(
156
146
  (available > usize(0)) => {
@@ -159,25 +149,24 @@ impl(BufReader,
159
149
  true => usize(size)
160
150
  );
161
151
  i := usize(0);
162
- while runtime((i < to_copy)), {
163
- b := self._buf.get((self._pos + i)).unwrap();
152
+ while(runtime(i < to_copy), {
153
+ b := self._buf.get(self._pos + i).unwrap();
164
154
  (buf &+ i).* = b;
165
155
  i = (i + usize(1));
166
- };
156
+ });
167
157
  self._pos = (self._pos + to_copy);
168
158
  read_n = i32(to_copy);
169
159
  done = true;
170
160
  },
171
161
  true => ()
172
162
  );
173
-
174
163
  // Buffer is empty and large read: bypass buffer
175
164
  cond(
176
165
  ((!(done)) && (usize(size) >= self._capacity)) => {
177
166
  n := io.await(IO_file.read(the_fd, buf, size, self._offset));
178
167
  cond(
179
168
  (n < i32(0)) => {
180
- read_err = .Some(IOError.from_errno((i32(0) - n)));
169
+ read_err =.Some(IOError.from_errno(i32(0) - n));
181
170
  },
182
171
  true => {
183
172
  self._offset = (self._offset + u64(n));
@@ -188,7 +177,6 @@ impl(BufReader,
188
177
  },
189
178
  true => ()
190
179
  );
191
-
192
180
  // Buffer is empty and small read: fill buffer first
193
181
  cond(
194
182
  (!(done)) => {
@@ -197,7 +185,7 @@ impl(BufReader,
197
185
  cond(
198
186
  (n < i32(0)) => {
199
187
  free(.Some(*(void)(raw_buf)));
200
- read_err = .Some(IOError.from_errno((i32(0) - n)));
188
+ read_err =.Some(IOError.from_errno(i32(0) - n));
201
189
  },
202
190
  (n == i32(0)) => {
203
191
  free(.Some(*(void)(raw_buf)));
@@ -207,24 +195,23 @@ impl(BufReader,
207
195
  self._offset = (self._offset + u64(n));
208
196
  self._buf = ArrayList(u8).with_capacity(self._capacity);
209
197
  i := usize(0);
210
- while runtime((i < usize(n))), {
198
+ while(runtime(i < usize(n)), {
211
199
  self._buf.push((raw_buf &+ i).*);
212
200
  i = (i + usize(1));
213
- };
201
+ });
214
202
  self._pos = usize(0);
215
203
  self._filled = usize(n);
216
204
  free(.Some(*(void)(raw_buf)));
217
-
218
205
  to_copy := cond(
219
206
  (usize(n) < usize(size)) => usize(n),
220
207
  true => usize(size)
221
208
  );
222
209
  j := usize(0);
223
- while runtime((j < to_copy)), {
210
+ while(runtime(j < to_copy), {
224
211
  b := self._buf.get(j).unwrap();
225
212
  (buf &+ j).* = b;
226
213
  j = (j + usize(1));
227
- };
214
+ });
228
215
  self._pos = to_copy;
229
216
  read_n = i32(to_copy);
230
217
  }
@@ -232,72 +219,69 @@ impl(BufReader,
232
219
  },
233
220
  true => ()
234
221
  );
235
-
236
- match(read_err,
237
- .Some(e) => .Err(e),
238
- .None => .Ok(read_n)
222
+ match(
223
+ read_err,
224
+ .Some(e) =>.Err(e),
225
+ .None =>.Ok(read_n)
239
226
  )
240
227
  })
241
228
  }),
242
-
243
229
  // Read all remaining data into an ArrayList of bytes.
244
- read_bytes : (fn(self: Self, using(io : IO)) -> Impl(Future(Result(ArrayList(u8), IOError), IO)))({
230
+ read_bytes : (fn(self : Self, using(io : IO)) -> Impl(Future(Result(ArrayList(u8), IOError), IO)))({
245
231
  the_fd := self._fd;
246
232
  io.async((using(io : IO)) => {
247
233
  result := ArrayList(u8).new();
248
-
249
234
  // First drain any buffered data
250
235
  cond(
251
236
  (self._pos < self._filled) => {
252
237
  i := self._pos;
253
- while runtime((i < self._filled)), {
238
+ while(runtime(i < self._filled), {
254
239
  result.push(self._buf.get(i).unwrap());
255
240
  i = (i + usize(1));
256
- };
241
+ });
257
242
  self._pos = self._filled;
258
243
  },
259
244
  true => ()
260
245
  );
261
-
262
246
  // Then read the rest from fd
263
247
  raw_buf := *(u8)(malloc(self._capacity).unwrap());
264
- (read_err : Option(IOError)) = .None;
265
- while runtime(true), {
248
+ (read_err : Option(IOError)) =.None;
249
+ while(runtime(true), {
266
250
  n := io.await(IO_file.read(the_fd, raw_buf, u32(self._capacity), self._offset));
267
251
  cond(
268
252
  (n < i32(0)) => {
269
- read_err = .Some(IOError.from_errno((i32(0) - n)));
253
+ read_err =.Some(IOError.from_errno(i32(0) - n));
270
254
  break;
271
255
  },
272
256
  (n == i32(0)) => break,
273
257
  true => {
274
258
  self._offset = (self._offset + u64(n));
275
259
  j := usize(0);
276
- while runtime((j < usize(n))), {
260
+ while(runtime(j < usize(n)), {
277
261
  result.push((raw_buf &+ j).*);
278
262
  j = (j + usize(1));
279
- };
263
+ });
280
264
  }
281
265
  );
282
- };
266
+ });
283
267
  free(.Some(*(void)(raw_buf)));
284
- match(read_err,
285
- .Some(e) => .Err(e),
286
- .None => .Ok(result)
268
+ match(
269
+ read_err,
270
+ .Some(e) =>.Err(e),
271
+ .None =>.Ok(result)
287
272
  )
288
273
  })
289
274
  }),
290
-
291
275
  // Read all remaining data as a String.
292
- read_to_string : (fn(self: Self, using(io : IO)) -> Impl(Future(Result(String, IOError), IO)))(
276
+ read_to_string : (fn(self : Self, using(io : IO)) -> Impl(Future(Result(String, IOError), IO)))(
293
277
  io.async((using(io : IO)) => {
294
278
  bytes_result := io.await(self.read_bytes(using(io)));
295
- match(bytes_result,
296
- .Ok(bytes) => .Ok(String.from_bytes(bytes)),
297
- .Err(e) => .Err(e)
279
+ match(
280
+ bytes_result,
281
+ .Ok(bytes) =>.Ok(String.from_bytes(bytes)),
282
+ .Err(e) =>.Err(e)
298
283
  )
299
284
  })
300
285
  )
301
286
  );
302
-
303
- export BufReader;
287
+ export(BufReader);
@@ -12,110 +12,101 @@
12
12
  //! io.await(writer.write_string(`hello\n`, using(io)));
13
13
  //! io.await(writer.flush(using(io)));
14
14
  //! ```
15
-
16
- { ArrayList } :: import "../../collections/array_list";
17
- open import "../../string";
18
- { IOError } :: import "../errors";
19
- IO_file :: import "../file";
20
- { GlobalAllocator } :: import "../../allocator";
15
+ { ArrayList } :: import("../../collections/array_list");
16
+ open(import("../../string"));
17
+ { IOError } :: import("../errors");
18
+ IO_file :: import("../file");
19
+ { GlobalAllocator } :: import("../../allocator");
21
20
  { malloc, free } :: GlobalAllocator;
22
-
23
21
  _DEFAULT_BUF_SIZE :: usize(4096);
24
-
25
22
  BufWriter :: object(
26
- _fd : i32,
27
- _buf : ArrayList(u8),
28
- _offset : u64,
23
+ _fd : i32,
24
+ _buf : ArrayList(u8),
25
+ _offset : u64,
29
26
  _capacity : usize
30
27
  );
31
-
32
- impl(BufWriter,
28
+ impl(
29
+ BufWriter,
33
30
  // Create a buffered writer with default buffer size (4096 bytes).
34
- new : (fn(fd: i32) -> Self)(
31
+ new : (fn(fd : i32) -> Self)(
35
32
  Self(
36
- _fd: fd,
37
- _buf: ArrayList(u8).with_capacity(_DEFAULT_BUF_SIZE),
38
- _offset: u64(0),
39
- _capacity: _DEFAULT_BUF_SIZE
33
+ _fd : fd,
34
+ _buf : ArrayList(u8).with_capacity(_DEFAULT_BUF_SIZE),
35
+ _offset : u64(0),
36
+ _capacity : _DEFAULT_BUF_SIZE
40
37
  )
41
38
  ),
42
-
43
39
  // Create a buffered writer with a custom buffer size.
44
- with_capacity : (fn(fd: i32, capacity: usize) -> Self)(
40
+ with_capacity : (fn(fd : i32, capacity : usize) -> Self)(
45
41
  Self(
46
- _fd: fd,
47
- _buf: ArrayList(u8).with_capacity(capacity),
48
- _offset: u64(0),
49
- _capacity: capacity
42
+ _fd : fd,
43
+ _buf : ArrayList(u8).with_capacity(capacity),
44
+ _offset : u64(0),
45
+ _capacity : capacity
50
46
  )
51
47
  ),
52
-
53
48
  // Return the underlying file descriptor.
54
- fd : (fn(self: Self) -> i32)(
49
+ fd : (fn(self : Self) -> i32)(
55
50
  self._fd
56
51
  ),
57
-
58
52
  // Return the number of bytes currently buffered.
59
- buffered : (fn(self: Self) -> usize)(
53
+ buffered : (fn(self : Self) -> usize)(
60
54
  self._buf.len()
61
55
  ),
62
-
63
56
  // Internal: flush the buffer contents to fd.
64
- _flush_inner : (fn(self: Self, using(io : IO)) -> Impl(Future(Result(unit, IOError), IO)))({
57
+ _flush_inner : (fn(self : Self, using(io : IO)) -> Impl(Future(Result(unit, IOError), IO)))({
65
58
  the_fd := self._fd;
66
59
  io.async((using(io : IO)) => {
67
- (write_err : Option(IOError)) = .None;
68
-
60
+ (write_err : Option(IOError)) =.None;
69
61
  cond(
70
62
  (self._buf.len() > usize(0)) => {
71
63
  written := usize(0);
72
64
  total := self._buf.len();
73
-
74
- while runtime(((written < total) && write_err.is_none())), {
75
- remaining := u32((total - written));
65
+ while(runtime((written < total) && write_err.is_none()), {
66
+ remaining := u32(total - written);
76
67
  buf_ptr := self._buf.ptr().unwrap();
77
- n := io.await(IO_file.write(the_fd, (buf_ptr &+ written), remaining, self._offset));
68
+ n := io.await(IO_file.write(the_fd, buf_ptr &+ written, remaining, self._offset));
78
69
  cond(
79
70
  (n < i32(0)) => {
80
- write_err = .Some(IOError.from_errno((i32(0) - n)));
71
+ write_err =.Some(IOError.from_errno(i32(0) - n));
81
72
  },
82
73
  true => {
83
74
  written = (written + usize(n));
84
75
  self._offset = (self._offset + u64(n));
85
76
  }
86
77
  );
87
- };
88
-
78
+ });
89
79
  self._buf = ArrayList(u8).with_capacity(self._capacity);
90
80
  },
91
81
  true => ()
92
82
  );
93
-
94
- match(write_err,
95
- .Some(e) => .Err(e),
96
- .None => .Ok(())
83
+ match(
84
+ write_err,
85
+ .Some(e) =>.Err(e),
86
+ .None =>.Ok(())
97
87
  )
98
88
  })
99
89
  }),
100
-
101
90
  // Write bytes from a pointer into the buffer.
102
91
  // Automatically flushes when the buffer is full.
103
92
  // Returns total number of bytes written.
104
- write : (fn(self: Self, data: *(u8), size: u32, using(io : IO)) -> Impl(Future(Result(i32, IOError), IO)))({
93
+ write : (fn(self : Self, data : *(u8), size : u32, using(io : IO)) -> Impl(Future(Result(i32, IOError), IO)))({
105
94
  the_fd := self._fd;
106
95
  io.async((using(io : IO)) => {
107
96
  remaining := usize(size);
108
97
  src_pos := usize(0);
109
- (write_err : Option(IOError)) = .None;
110
-
111
- while runtime(((remaining > usize(0)) && write_err.is_none())), {
98
+ (write_err : Option(IOError)) =.None;
99
+ while(runtime((remaining > usize(0)) && write_err.is_none()), {
112
100
  space := (self._capacity - self._buf.len());
113
101
  cond(
114
102
  (space == usize(0)) => {
115
103
  // Buffer full, flush it
116
104
  flush_result := io.await(self._flush_inner(using(io)));
117
- match(flush_result,
118
- .Err(e) => { write_err = .Some(e); },
105
+ match(
106
+ flush_result,
107
+ .Err(e) => {
108
+ write_err =.Some(e);
109
+ },
119
110
  .Ok(_) => ()
120
111
  );
121
112
  },
@@ -125,47 +116,43 @@ impl(BufWriter,
125
116
  true => space
126
117
  );
127
118
  i := usize(0);
128
- while runtime((i < to_copy)), {
119
+ while(runtime(i < to_copy), {
129
120
  self._buf.push((data &+ (src_pos + i)).*);
130
121
  i = (i + usize(1));
131
- };
122
+ });
132
123
  src_pos = (src_pos + to_copy);
133
124
  remaining = (remaining - to_copy);
134
125
  }
135
126
  );
136
- };
137
-
138
- match(write_err,
139
- .Some(e) => .Err(e),
140
- .None => .Ok(i32(size))
127
+ });
128
+ match(
129
+ write_err,
130
+ .Some(e) =>.Err(e),
131
+ .None =>.Ok(i32(size))
141
132
  )
142
133
  })
143
134
  }),
144
-
145
135
  // Write a String to the buffer.
146
- write_string : (fn(self: Self, s: String, using(io : IO)) -> Impl(Future(Result(i32, IOError), IO)))(
136
+ write_string : (fn(self : Self, s : String, using(io : IO)) -> Impl(Future(Result(i32, IOError), IO)))(
147
137
  io.async((using(io : IO)) => {
148
138
  bytes := s.as_bytes();
149
139
  result := io.await(self.write(bytes.ptr().unwrap(), u32(bytes.len()), using(io)));
150
140
  result
151
141
  })
152
142
  ),
153
-
154
143
  // Write bytes from an ArrayList to the buffer.
155
- write_bytes : (fn(self: Self, data: ArrayList(u8), using(io : IO)) -> Impl(Future(Result(i32, IOError), IO)))(
144
+ write_bytes : (fn(self : Self, data : ArrayList(u8), using(io : IO)) -> Impl(Future(Result(i32, IOError), IO)))(
156
145
  io.async((using(io : IO)) => {
157
146
  result := io.await(self.write(data.ptr().unwrap(), u32(data.len()), using(io)));
158
147
  result
159
148
  })
160
149
  ),
161
-
162
150
  // Flush all buffered data to the underlying file descriptor.
163
- flush : (fn(self: Self, using(io : IO)) -> Impl(Future(Result(unit, IOError), IO)))(
151
+ flush : (fn(self : Self, using(io : IO)) -> Impl(Future(Result(unit, IOError), IO)))(
164
152
  io.async((using(io : IO)) => {
165
153
  flush_result := io.await(self._flush_inner(using(io)));
166
154
  flush_result
167
155
  })
168
156
  )
169
157
  );
170
-
171
- export BufWriter;
158
+ export(BufWriter);
package/std/sys/clock.yo CHANGED
@@ -2,22 +2,17 @@
2
2
  //!
3
3
  //! Provides a synchronous wrapper for reading wall-clock and monotonic time.
4
4
  //! Returns 0 on success, -errno / negative platform error on failure.
5
-
6
- { platform, Platform } :: import "../process";
7
- { __yo_sync_clock_gettime } :: import "./externs.yo";
8
-
5
+ { platform, Platform } :: import("../process");
6
+ { __yo_sync_clock_gettime } :: import("./externs.yo");
9
7
  // Wall clock time (Unix epoch seconds + nanoseconds)
10
8
  CLOCK_REALTIME :: i32(0);
11
-
12
9
  // Monotonic time (non-decreasing; use for durations)
13
10
  CLOCK_MONOTONIC :: cond(
14
11
  (platform == Platform.Macos) => i32(6),
15
12
  true => i32(1)
16
13
  );
17
-
18
14
  // Read current time from the selected clock source.
19
- clock_gettime :: (fn(clock_id: i32, sec: *(i64), nsec: *(i64)) -> i32)(
15
+ clock_gettime :: (fn(clock_id : i32, sec : *(i64), nsec : *(i64)) -> i32)(
20
16
  __yo_sync_clock_gettime(clock_id, sec, nsec)
21
17
  );
22
-
23
- export CLOCK_REALTIME, CLOCK_MONOTONIC, clock_gettime;
18
+ export(CLOCK_REALTIME, CLOCK_MONOTONIC, clock_gettime);