@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
@@ -10,23 +10,20 @@
10
10
  //! words := utf8_to_utf16("hello");
11
11
  //! s := utf16_to_utf8(words);
12
12
  //! ```
13
-
14
- open import "../string";
15
- { ArrayList } :: import "../collections/array_list";
16
- { EncodingError } :: import "./hex";
17
- { Error, AnyError, Exception } :: import "../error";
18
-
13
+ open(import("../string"));
14
+ { ArrayList } :: import("../collections/array_list");
15
+ { EncodingError } :: import("./hex");
16
+ { Error, AnyError, Exception } :: import("../error");
19
17
  // ============================================================================
20
18
  // UTF-8 → UTF-16
21
19
  // ============================================================================
22
-
23
20
  /// Convert a UTF-8 string to an `ArrayList(u16)` of UTF-16 code units.
24
21
  ///
25
22
  /// Handles BMP characters directly and encodes supplementary characters as surrogate pairs.
26
- utf8_to_utf16 :: (fn(s: str) -> ArrayList(u16))({
23
+ utf8_to_utf16 :: (fn(s : str) -> ArrayList(u16))({
27
24
  out := ArrayList(u16).new();
28
- i := usize(0);
29
- while (i < s.len()), {
25
+ i := usize(0);
26
+ while(i < s.len(), {
30
27
  b0 := u32(s.bytes(i));
31
28
  cond(
32
29
  (b0 < u32(0x80)) => {
@@ -34,73 +31,70 @@ utf8_to_utf16 :: (fn(s: str) -> ArrayList(u16))({
34
31
  i = (i + usize(1));
35
32
  },
36
33
  ((b0 & u32(0xE0)) == u32(0xC0)) => {
37
- b1 := u32(s.bytes((i + usize(1))));
38
- cp := (((b0 & u32(0x1F)) << u32(6)) | (b1 & u32(0x3F)));
34
+ b1 := u32(s.bytes(i + usize(1)));
35
+ cp := (((b0 & u32(0x1F)) << u32(6)) | (b1 & u32(0x3F)));
39
36
  out.push(u16(cp));
40
37
  i = (i + usize(2));
41
38
  },
42
39
  ((b0 & u32(0xF0)) == u32(0xE0)) => {
43
- b1 := u32(s.bytes((i + usize(1))));
44
- b2 := u32(s.bytes((i + usize(2))));
45
- cp := ((((b0 & u32(0x0F)) << u32(12)) | ((b1 & u32(0x3F)) << u32(6))) | (b2 & u32(0x3F)));
40
+ b1 := u32(s.bytes(i + usize(1)));
41
+ b2 := u32(s.bytes(i + usize(2)));
42
+ cp := ((((b0 & u32(0x0F)) << u32(12)) | ((b1 & u32(0x3F)) << u32(6))) | (b2 & u32(0x3F)));
46
43
  out.push(u16(cp));
47
44
  i = (i + usize(3));
48
45
  },
49
46
  true => {
50
47
  // 4-byte sequence → surrogate pair
51
- b1 := u32(s.bytes((i + usize(1))));
52
- b2 := u32(s.bytes((i + usize(2))));
53
- b3 := u32(s.bytes((i + usize(3))));
54
- cp := (((((b0 & u32(0x07)) << u32(18)) | ((b1 & u32(0x3F)) << u32(12))) | ((b2 & u32(0x3F)) << u32(6))) | (b3 & u32(0x3F)));
48
+ b1 := u32(s.bytes(i + usize(1)));
49
+ b2 := u32(s.bytes(i + usize(2)));
50
+ b3 := u32(s.bytes(i + usize(3)));
51
+ cp := (((((b0 & u32(0x07)) << u32(18)) | ((b1 & u32(0x3F)) << u32(12))) | ((b2 & u32(0x3F)) << u32(6))) | (b3 & u32(0x3F)));
55
52
  cp2 := (cp - u32(0x10000));
56
- hi := u16(((cp2 >> u32(10)) + u32(0xD800)));
57
- lo := u16(((cp2 & u32(0x3FF)) + u32(0xDC00)));
53
+ hi := u16((cp2 >> u32(10)) + u32(0xD800));
54
+ lo := u16((cp2 & u32(0x3FF)) + u32(0xDC00));
58
55
  out.push(hi);
59
56
  out.push(lo);
60
57
  i = (i + usize(4));
61
58
  }
62
59
  );
63
- };
60
+ });
64
61
  out
65
62
  });
66
-
67
- export utf8_to_utf16;
68
-
63
+ export(utf8_to_utf16);
69
64
  // ============================================================================
70
65
  // UTF-16 → UTF-8
71
66
  // ============================================================================
72
-
73
67
  /// Convert UTF-16 code units to a UTF-8 `String`.
74
68
  ///
75
69
  /// Decodes surrogate pairs back into supplementary code points.
76
70
  /// Throws via `Exception` on unpaired surrogates.
77
- utf16_to_utf8 :: (fn(data: ArrayList(u16), using(exn : Exception)) -> String)({
71
+ utf16_to_utf8 :: (fn(data : ArrayList(u16), using(exn : Exception)) -> String)({
78
72
  out := ArrayList(u8).new();
79
- i := usize(0);
80
- while (i < data.len()), {
73
+ i := usize(0);
74
+ while(i < data.len(), {
81
75
  w := u32(data.get(i).unwrap());
82
76
  cond(
83
77
  // Surrogate pair: high surrogate 0xD800-0xDBFF
84
78
  ((w >= u32(0xD800)) && (w <= u32(0xDBFF))) => {
85
79
  cond(
86
80
  ((i + usize(1)) >= data.len()) => {
87
- exn.throw(dyn EncodingError.InvalidChar(u8(0)));
81
+ exn.throw(dyn(EncodingError.InvalidChar(u8(0))));
88
82
  },
89
83
  true => ()
90
84
  );
91
- w2 := u32(data.get((i + usize(1))).unwrap());
85
+ w2 := u32(data.get(i + usize(1)).unwrap());
92
86
  cond(
93
87
  ((w2 < u32(0xDC00)) || (w2 > u32(0xDFFF))) => {
94
- exn.throw(dyn EncodingError.InvalidChar(u8(0)));
88
+ exn.throw(dyn(EncodingError.InvalidChar(u8(0))));
95
89
  },
96
90
  true => ()
97
91
  );
98
92
  cp := ((((w - u32(0xD800)) << u32(10)) + (w2 - u32(0xDC00))) + u32(0x10000));
99
93
  // Encode as 4-byte UTF-8
100
- out.push(u8((u32(0xF0) | (cp >> u32(18)))));
101
- out.push(u8((u32(0x80) | ((cp >> u32(12)) & u32(0x3F)))));
102
- out.push(u8((u32(0x80) | ((cp >> u32(6)) & u32(0x3F)))));
103
- out.push(u8((u32(0x80) | (cp & u32(0x3F)))));
94
+ out.push(u8(u32(0xF0) | (cp >> u32(18))));
95
+ out.push(u8(u32(0x80) | ((cp >> u32(12)) & u32(0x3F))));
96
+ out.push(u8(u32(0x80) | ((cp >> u32(6)) & u32(0x3F))));
97
+ out.push(u8(u32(0x80) | (cp & u32(0x3F))));
104
98
  i = (i + usize(2));
105
99
  },
106
100
  (w < u32(0x80)) => {
@@ -108,19 +102,18 @@ utf16_to_utf8 :: (fn(data: ArrayList(u16), using(exn : Exception)) -> String)({
108
102
  i = (i + usize(1));
109
103
  },
110
104
  (w < u32(0x800)) => {
111
- out.push(u8((u32(0xC0) | (w >> u32(6)))));
112
- out.push(u8((u32(0x80) | (w & u32(0x3F)))));
105
+ out.push(u8(u32(0xC0) | (w >> u32(6))));
106
+ out.push(u8(u32(0x80) | (w & u32(0x3F))));
113
107
  i = (i + usize(1));
114
108
  },
115
109
  true => {
116
- out.push(u8((u32(0xE0) | (w >> u32(12)))));
117
- out.push(u8((u32(0x80) | ((w >> u32(6)) & u32(0x3F)))));
118
- out.push(u8((u32(0x80) | (w & u32(0x3F)))));
110
+ out.push(u8(u32(0xE0) | (w >> u32(12))));
111
+ out.push(u8(u32(0x80) | ((w >> u32(6)) & u32(0x3F))));
112
+ out.push(u8(u32(0x80) | (w & u32(0x3F))));
119
113
  i = (i + usize(1));
120
114
  }
121
115
  );
122
- };
116
+ });
123
117
  String.from_bytes(out)
124
118
  });
125
-
126
- export utf16_to_utf8;
119
+ export(utf16_to_utf8);
package/std/env.yo CHANGED
@@ -3,96 +3,83 @@
3
3
  //!
4
4
  //! Mirrors the layout of Rust's `std::env`. Platform/architecture detection
5
5
  //! and child-process spawning live in `std/process`.
6
-
7
- open import "./collections/array_list";
8
- open import "./string";
9
- open import "./path";
10
- { platform, Platform } :: import "./process";
11
- { GlobalAllocator } :: import "./allocator";
6
+ open(import("./collections/array_list"));
7
+ open(import("./string"));
8
+ open(import("./path"));
9
+ { platform, Platform } :: import("./process");
10
+ { GlobalAllocator } :: import("./allocator");
12
11
  { malloc, free } :: GlobalAllocator;
13
-
14
12
  // === Low-level C interface ===
15
-
16
- extern "Yo",
13
+ extern(
14
+ "Yo",
17
15
  __yo_argc : i32,
18
16
  __yo_argv : *(*(u8)),
19
17
  __yo_args : [*(u8)]
20
- ;
21
-
18
+ );
22
19
  // === Raw command-line arguments ===
23
-
24
20
  /// Get raw command-line arguments as a slice of C strings.
25
21
  /// The first element is the program name.
26
- raw_args :: (fn() -> [*(u8)]) {
27
- return __yo_args;
28
- };
29
- export raw_args;
30
-
22
+ raw_args :: (fn() -> [*(u8)])({
23
+ return(__yo_args);
24
+ });
25
+ export(raw_args);
31
26
  /// Get the number of command-line arguments (including program name).
32
- argc :: (fn() -> i32) {
33
- return __yo_argc;
34
- };
35
- export argc;
36
-
27
+ argc :: (fn() -> i32)({
28
+ return(__yo_argc);
29
+ });
30
+ export(argc);
37
31
  /// Get the raw `argv` pointer (`*(*(u8))`).
38
- argv :: (fn() -> *(*(u8))) {
39
- return __yo_argv;
40
- };
41
- export argv;
42
-
32
+ argv :: (fn() -> *(*(u8)))({
33
+ return(__yo_argv);
34
+ });
35
+ export(argv);
43
36
  // === Convenient command-line arguments ===
44
-
45
37
  /// Get command-line arguments as an `ArrayList(String)`.
46
38
  /// The first element is the program name.
47
- args :: (fn() -> ArrayList(String)) {
39
+ args :: (fn() -> ArrayList(String))({
48
40
  raw := raw_args();
49
41
  i := usize(0);
50
42
  len := usize(argc());
51
-
52
43
  result := ArrayList(String).with_capacity(len);
53
-
54
- while i < len, {
44
+ while(i < len, {
55
45
  arg_ptr := raw(i);
56
46
  arg_str := String.from_cstr(arg_ptr).unwrap();
57
47
  result.push(arg_str);
58
48
  i = (i + 1);
59
- };
60
- return result;
61
- };
62
- export args;
63
-
49
+ });
50
+ return(result);
51
+ });
52
+ export(args);
64
53
  /// Environment variable access and manipulation.
65
- env :: impl {
66
- { getenv, setenv } :: import "./libc/stdlib";
67
-
54
+ env :: impl({
55
+ { getenv, setenv } :: import("./libc/stdlib");
68
56
  /// Get the value of an environment variable by name.
69
57
  /// Returns `.None` if the variable is not set.
70
- get :: (fn(name : String) -> Option(String)) {
58
+ get :: (fn(name : String) -> Option(String))({
71
59
  name_cstr := name.to_cstr().ptr().unwrap();
72
60
  val_ptr := getenv(*(char)(name_cstr));
73
- match(val_ptr,
74
- .None => .None,
75
- .Some(ptr) => .Some(String.from_cstr(*(u8)(ptr)).unwrap())
61
+ match(
62
+ val_ptr,
63
+ .None =>.None,
64
+ .Some(ptr) =>.Some(String.from_cstr(*(u8)(ptr)).unwrap())
76
65
  )
77
- };
78
- export get;
79
-
66
+ });
67
+ export(get);
80
68
  /// Set an environment variable. If `overwrite` is false and the variable
81
69
  /// already exists, it is not modified. Returns true on success.
82
- set :: (fn(name : String, value : String, (overwrite : bool) ?= true) -> bool) {
70
+ set :: (fn(name : String, value : String, (overwrite : bool) ?= true) -> bool)({
83
71
  name_cstr := name.to_cstr().ptr().unwrap();
84
72
  value_cstr := value.to_cstr().ptr().unwrap();
85
-
86
73
  result := cond(
87
74
  (platform == Platform.Windows) => {
88
- { _putenv_s } :: import "./libc/windows";
89
-
75
+ { _putenv_s } :: import("./libc/windows");
90
76
  cond(
91
77
  overwrite =>
92
78
  _putenv_s(*(char)(name_cstr), *(char)(value_cstr)),
93
79
  true => {
94
80
  existing := getenv(*(char)(name_cstr));
95
- match(existing,
81
+ match(
82
+ existing,
96
83
  .Some(_) => int(0),
97
84
  .None => _putenv_s(*(char)(name_cstr), *(char)(value_cstr))
98
85
  )
@@ -107,28 +94,23 @@ env :: impl {
107
94
  setenv(*(char)(name_cstr), *(char)(value_cstr), overwrite_int)
108
95
  }
109
96
  );
110
-
111
- return result == int(0);
112
- };
113
- export set;
114
- };
115
- export env;
116
-
97
+ return(result == int(0));
98
+ });
99
+ export(set);
100
+ });
101
+ export(env);
117
102
  /// Get the current working directory as a `Path`.
118
103
  /// Returns `Err` with a message on failure.
119
104
  cwd :: (fn() -> Result(Path, String))(
120
105
  cond(
121
106
  (platform == Platform.Windows) => {
122
- { GetCurrentDirectoryW, WideCharToMultiByte, CP_UTF8, WCHAR, DWORD } :: import "./libc/windows";
123
-
124
- required_size := GetCurrentDirectoryW(ulong(0), .None);
107
+ { GetCurrentDirectoryW, WideCharToMultiByte, CP_UTF8, WCHAR, DWORD } :: import("./libc/windows");
108
+ required_size := GetCurrentDirectoryW(ulong(0),.None);
125
109
  cond(
126
- (required_size == ulong(0)) => .Err(`Failed to get current working directory on Windows`),
110
+ (required_size == ulong(0)) =>.Err(`Failed to get current working directory on Windows`),
127
111
  true => {
128
- wbuf := *(WCHAR)(malloc((usize(required_size) * usize(2))).unwrap());
129
-
130
- actual_size := GetCurrentDirectoryW(required_size, .Some(wbuf));
131
-
112
+ wbuf := *(WCHAR)(malloc(usize(required_size) * usize(2)).unwrap());
113
+ actual_size := GetCurrentDirectoryW(required_size,.Some(wbuf));
132
114
  cond(
133
115
  (actual_size == ulong(0)) => {
134
116
  free(.Some(*(void)(wbuf)));
@@ -145,15 +127,13 @@ cwd :: (fn() -> Result(Path, String))(
145
127
  .None,
146
128
  .None
147
129
  );
148
-
149
130
  cond(
150
131
  (utf8_size <= i32(0)) => {
151
132
  free(.Some(*(void)(wbuf)));
152
133
  .Err(`Failed to convert directory path to UTF-8`)
153
134
  },
154
135
  true => {
155
- utf8_buf := *(u8)(malloc((usize(utf8_size) + usize(1))).unwrap());
156
-
136
+ utf8_buf := *(u8)(malloc(usize(utf8_size) + usize(1)).unwrap());
157
137
  result := WideCharToMultiByte(
158
138
  CP_UTF8,
159
139
  ulong(0),
@@ -164,9 +144,7 @@ cwd :: (fn() -> Result(Path, String))(
164
144
  .None,
165
145
  .None
166
146
  );
167
-
168
147
  free(.Some(*(void)(wbuf)));
169
-
170
148
  cond(
171
149
  (result <= i32(0)) => {
172
150
  free(.Some(*(void)(utf8_buf)));
@@ -187,14 +165,12 @@ cwd :: (fn() -> Result(Path, String))(
187
165
  )
188
166
  },
189
167
  true => {
190
- { getcwd } :: import "./libc/unistd";
191
-
168
+ { getcwd } :: import("./libc/unistd");
192
169
  buf_size := usize(4096);
193
170
  buf := *(char)(malloc(buf_size).unwrap());
194
-
195
171
  result_ptr := getcwd(buf, buf_size);
196
-
197
- match(result_ptr,
172
+ match(
173
+ result_ptr,
198
174
  .None => {
199
175
  free(.Some(*(void)(buf)));
200
176
  .Err(`Failed to get current working directory`)
@@ -208,36 +184,31 @@ cwd :: (fn() -> Result(Path, String))(
208
184
  }
209
185
  )
210
186
  );
211
- export cwd;
212
-
187
+ export(cwd);
213
188
  /// Change the current working directory to `path`.
214
189
  /// Returns `Ok(())` on success, or `Err` with a message on failure.
215
- chdir :: (fn(path: Path) -> Result(unit, String))(
190
+ chdir :: (fn(path : Path) -> Result(unit, String))(
216
191
  cond(
217
192
  (platform == Platform.Windows) => {
218
- { SetCurrentDirectoryA, BOOL } :: import "./libc/windows";
219
-
193
+ { SetCurrentDirectoryA, BOOL } :: import("./libc/windows");
220
194
  path_str := path.to_string();
221
195
  path_cstr := path_str.to_cstr().ptr().unwrap();
222
196
  result := SetCurrentDirectoryA(*(char)(path_cstr));
223
-
224
197
  cond(
225
- (result == int(0)) => .Err(`Failed to change directory to: ${path_str}`),
226
- true => .Ok(())
198
+ (result == int(0)) =>.Err(`Failed to change directory to: ${path_str}`),
199
+ true =>.Ok(())
227
200
  )
228
201
  },
229
202
  true => {
230
- { chdir : unix_chdir } :: import "./libc/unistd";
231
-
203
+ { chdir : unix_chdir } :: import("./libc/unistd");
232
204
  path_str := path.to_string();
233
205
  path_cstr := path_str.to_cstr().ptr().unwrap();
234
206
  result := unix_chdir(*(char)(path_cstr));
235
-
236
207
  cond(
237
- (result != int(0)) => .Err(`Failed to change directory to: ${path_str}`),
238
- true => .Ok(())
208
+ (result != int(0)) =>.Err(`Failed to change directory to: ${path_str}`),
209
+ true =>.Ok(())
239
210
  )
240
211
  }
241
212
  )
242
213
  );
243
- export chdir;
214
+ export(chdir);
package/std/error.yo CHANGED
@@ -1,37 +1,29 @@
1
1
  //! Standard error handling types and traits for Yo.
2
-
3
- open import "./string";
4
- open import "./fmt";
5
-
2
+ open(import("./string"));
3
+ open(import("./fmt"));
6
4
  /// Standard error trait for typed error propagation.
7
5
  /// All error types should implement this trait along with `ToString`.
8
6
  Error :: trait(
9
- (source : (fn(self: *(Self)) -> Option(Dyn(SelfTrait)))) ?= ((self) -> .None),
10
-
7
+ (source : (fn(self : *(Self)) -> Option(Dyn(SelfTrait)))) ?= ((self) ->.None),
11
8
  where(Self <: ToString)
12
9
  );
13
- export Error;
14
-
10
+ export(Error);
15
11
  /// Type-erased dynamic error type. Wraps any type implementing `Error`.
16
12
  AnyError :: Dyn(Error);
17
- export AnyError;
18
-
13
+ export(AnyError);
19
14
  /// Allows using `String` directly as an error type.
20
15
  impl(String, Error());
21
-
22
- /// Non-resumable exception handling effect module.
16
+ /// Non-resumable exception handling effect record.
23
17
  /// Use `throw` to raise an `AnyError` and abort the current computation.
24
- Exception :: module(
18
+ Exception :: struct(
25
19
  throw : (fn(forall(ResumeType : Type), error : AnyError) -> ResumeType)
26
20
  );
27
- export Exception;
28
-
29
-
30
- /// Creates a resumable exception module parameterized by the resume type.
21
+ export(Exception);
22
+ /// Creates a resumable exception effect record parameterized by the resume type.
31
23
  /// Unlike `Exception`, the handler can return a value to resume the computation.
32
- ResumableException :: (fn(comptime(ResumeType) : Type) -> comptime(Module))(
33
- module(
24
+ ResumableException :: (fn(comptime(ResumeType) : Type) -> comptime(Type))(
25
+ struct(
34
26
  throw : (fn(error : AnyError) -> ResumeType)
35
27
  )
36
28
  );
37
- export ResumableException;
29
+ export(ResumableException);
@@ -9,16 +9,12 @@
9
9
  //! )
10
10
  //! ));
11
11
  //! ```
12
-
13
- { Writer } :: import "./writer";
14
-
12
+ { Writer } :: import("./writer");
15
13
  /// Trait for formatting values by writing to a `Writer` rather than allocating a `String`.
16
14
  /// Complement to `ToString` for streaming output into an existing buffer.
17
-
18
- Display :: (fn(comptime(T) : Type) -> comptime(Trait))
15
+ Display :: (fn(comptime(T) : Type) -> comptime(Trait))(
19
16
  trait(
20
- display : (fn(self: *(T), writer: Writer) -> Writer)
17
+ display : (fn(self : *(T), writer : Writer) -> Writer)
21
18
  )
22
- ;
23
-
24
- export Display;
19
+ );
20
+ export(Display);
package/std/fmt/index.yo CHANGED
@@ -1,11 +1,8 @@
1
1
  //! Formatted output to stdout and stderr.
2
-
3
- { fwrite, stdout, stderr } :: import "../libc/stdio";
4
- { String } :: import "../string";
5
- { ToString } :: import "./to_string.yo";
6
-
7
- export ToString;
8
-
2
+ { fwrite, stdout, stderr } :: import("../libc/stdio");
3
+ { String } :: import("../string");
4
+ { ToString } :: import("./to_string.yo");
5
+ export(ToString);
9
6
  /// Print a value that implements `ToString` to stdout, followed by a newline.
10
7
  println :: (fn(forall(T : Type), v : T, where(T <: ToString)) -> unit)({
11
8
  s := v.to_string();
@@ -20,8 +17,7 @@ println :: (fn(forall(T : Type), v : T, where(T <: ToString)) -> unit)({
20
17
  );
21
18
  fwrite(*(void)(*(u8)("\n")), usize(1), usize(1), stdout);
22
19
  });
23
- export println;
24
-
20
+ export(println);
25
21
  /// Print a value that implements `ToString` to stdout, without a trailing newline.
26
22
  print :: (fn(forall(T : Type), v : T, where(T <: ToString)) -> unit)({
27
23
  s := v.to_string();
@@ -35,8 +31,7 @@ print :: (fn(forall(T : Type), v : T, where(T <: ToString)) -> unit)({
35
31
  true => ()
36
32
  );
37
33
  });
38
- export print;
39
-
34
+ export(print);
40
35
  /// Print a value that implements `ToString` to stderr, followed by a newline.
41
36
  eprintln :: (fn(forall(T : Type), v : T, where(T <: ToString)) -> unit)({
42
37
  s := v.to_string();
@@ -51,8 +46,7 @@ eprintln :: (fn(forall(T : Type), v : T, where(T <: ToString)) -> unit)({
51
46
  );
52
47
  fwrite(*(void)(*(u8)("\n")), usize(1), usize(1), stderr);
53
48
  });
54
- export eprintln;
55
-
49
+ export(eprintln);
56
50
  /// Print a value that implements `ToString` to stderr, without a trailing newline.
57
51
  eprint :: (fn(forall(T : Type), v : T, where(T <: ToString)) -> unit)({
58
52
  s := v.to_string();
@@ -66,4 +60,4 @@ eprint :: (fn(forall(T : Type), v : T, where(T <: ToString)) -> unit)({
66
60
  true => ()
67
61
  );
68
62
  });
69
- export eprint;
63
+ export(eprint);