@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
@@ -18,116 +18,96 @@
18
18
  //! printf("is file: %d\n", i32(m.is_file()));
19
19
  //! });
20
20
  //! ```
21
-
22
- { GlobalAllocator } :: import "../allocator";
21
+ { GlobalAllocator } :: import("../allocator");
23
22
  { malloc, free } :: GlobalAllocator;
24
- open import "../string";
25
- { Path } :: import "../path";
26
- { IOError } :: import "../sys/errors";
27
- { Error, AnyError, Exception } :: import "../error";
28
- { Statx } :: import "../sys/statx";
29
- IO_file :: import "../sys/file";
30
- {
31
- AT_FDCWD, AT_SYMLINK_NOFOLLOW, AT_STATX_SYNC_AS_STAT,
32
- STATX_BASIC_STATS, S_IFMT, S_IFREG, S_IFDIR, S_IFLNK,
33
- S_IWUSR, S_IWGRP, S_IWOTH
34
- } :: import "../sys/constants";
35
-
23
+ open(import("../string"));
24
+ { Path } :: import("../path");
25
+ { IOError } :: import("../sys/errors");
26
+ { Error, AnyError, Exception } :: import("../error");
27
+ { Statx } :: import("../sys/statx");
28
+ IO_file :: import("../sys/file");
29
+ { AT_FDCWD, AT_SYMLINK_NOFOLLOW, AT_STATX_SYNC_AS_STAT, STATX_BASIC_STATS, S_IFMT, S_IFREG, S_IFDIR, S_IFLNK, S_IWUSR, S_IWGRP, S_IWOTH } :: import("../sys/constants");
36
30
  /// File metadata wrapper around `Statx`.
37
31
  Metadata :: object(
38
32
  _statx : Statx,
39
33
  _buf_ptr : *(u8)
40
34
  );
41
-
42
- impl(Metadata,
35
+ impl(
36
+ Metadata,
43
37
  // File size in bytes.
44
- size : (fn(self: Self) -> i64)(
38
+ size : (fn(self : Self) -> i64)(
45
39
  self._statx.size()
46
40
  ),
47
-
48
41
  // Raw permission mode bits.
49
- mode : (fn(self: Self) -> u32)(
42
+ mode : (fn(self : Self) -> u32)(
50
43
  self._statx.mode()
51
44
  ),
52
-
53
45
  // True if this is a regular file.
54
- is_file : (fn(self: Self) -> bool)(
46
+ is_file : (fn(self : Self) -> bool)(
55
47
  self._statx.is_file()
56
48
  ),
57
-
58
49
  // True if this is a directory.
59
- is_dir : (fn(self: Self) -> bool)(
50
+ is_dir : (fn(self : Self) -> bool)(
60
51
  self._statx.is_directory()
61
52
  ),
62
-
63
53
  // True if this is a symbolic link.
64
- is_symlink : (fn(self: Self) -> bool)(
54
+ is_symlink : (fn(self : Self) -> bool)(
65
55
  self._statx.is_symlink()
66
56
  ),
67
-
68
57
  // Last modification time (seconds since epoch).
69
- modified_time : (fn(self: Self) -> i64)(
58
+ modified_time : (fn(self : Self) -> i64)(
70
59
  self._statx.mtime_sec()
71
60
  ),
72
-
73
61
  // Last access time (seconds since epoch).
74
- accessed_time : (fn(self: Self) -> i64)(
62
+ accessed_time : (fn(self : Self) -> i64)(
75
63
  self._statx.atime_sec()
76
64
  ),
77
-
78
65
  // Status change time (seconds since epoch).
79
- created_time : (fn(self: Self) -> i64)(
66
+ created_time : (fn(self : Self) -> i64)(
80
67
  self._statx.ctime_sec()
81
68
  ),
82
-
83
69
  // True if the file is read-only (no write permission for anyone).
84
- is_readonly : (fn(self: Self) -> bool)({
70
+ is_readonly : (fn(self : Self) -> bool)({
85
71
  m := self._statx.mode();
86
- ((m & ((S_IWUSR | S_IWGRP) | S_IWOTH)) == u32(0))
72
+ (m & ((S_IWUSR | S_IWGRP) | S_IWOTH)) == u32(0)
87
73
  }),
88
-
89
74
  // Owner user ID.
90
- uid : (fn(self: Self) -> u32)(
75
+ uid : (fn(self : Self) -> u32)(
91
76
  self._statx.uid()
92
77
  ),
93
-
94
78
  // Owner group ID.
95
- gid : (fn(self: Self) -> u32)(
79
+ gid : (fn(self : Self) -> u32)(
96
80
  self._statx.gid()
97
81
  ),
98
-
99
82
  // Inode number.
100
- ino : (fn(self: Self) -> u64)(
83
+ ino : (fn(self : Self) -> u64)(
101
84
  self._statx.ino()
102
85
  ),
103
-
104
86
  // Number of hard links.
105
- nlink : (fn(self: Self) -> u64)(
87
+ nlink : (fn(self : Self) -> u64)(
106
88
  self._statx.nlink()
107
89
  )
108
90
  );
109
-
110
- impl(Metadata, Dispose(
111
- dispose : (fn(self: Self) -> unit)({
112
- free(.Some(*(void)(self._buf_ptr)));
113
- })
114
- ));
115
-
116
- export Metadata;
117
-
91
+ impl(
92
+ Metadata,
93
+ Dispose(
94
+ dispose : (fn(self : Self) -> unit)({
95
+ free(.Some(*(void)(self._buf_ptr)));
96
+ })
97
+ )
98
+ );
99
+ export(Metadata);
118
100
  // ============================================================================
119
101
  // Statx buffer size extern
120
102
  // ============================================================================
121
-
122
- extern "Yo",
103
+ extern(
104
+ "Yo",
123
105
  __yo_statx_buf_size : (fn() -> usize)
124
- ;
125
-
106
+ );
126
107
  // ============================================================================
127
108
  // Internal helper to stat a path
128
109
  // ============================================================================
129
-
130
- _stat_path :: (fn(path: Path, flags: i32, using(io : IO)) -> Impl(Future(Metadata, IO, Exception)))(
110
+ _stat_path :: (fn(path : Path, flags : i32, using(io : IO)) -> Impl(Future(Metadata, IO, Exception)))(
131
111
  io.async((using(io, exn)) => {
132
112
  cstr_bytes := path.to_string().to_cstr();
133
113
  cstr := cstr_bytes.ptr().unwrap();
@@ -137,34 +117,21 @@ _stat_path :: (fn(path: Path, flags: i32, using(io : IO)) -> Impl(Future(Metadat
137
117
  cond(
138
118
  (result < i32(0)) => {
139
119
  free(.Some(*(void)(buf)));
140
- exn.throw(dyn IOError.from_errno((i32(0) - result)))
120
+ exn.throw(dyn(IOError.from_errno(i32(0) - result)))
141
121
  },
142
122
  true => {
143
- sx := Statx(_buf_ptr: buf, _buf_size: buf_size);
144
- Metadata(_statx: sx, _buf_ptr: buf)
123
+ sx := Statx(_buf_ptr : buf, _buf_size : buf_size);
124
+ Metadata(_statx : sx, _buf_ptr : buf)
145
125
  }
146
126
  )
147
127
  })
148
128
  );
149
-
150
129
  /// Get metadata for a path (follows symlinks).
151
- metadata :: (fn(path: Path, using(io : IO)) -> Impl(Future(Metadata, IO, Exception)))
152
- _stat_path(path, AT_STATX_SYNC_AS_STAT)
153
- ;
154
-
130
+ metadata :: (fn(path : Path, using(io : IO)) -> Impl(Future(Metadata, IO, Exception)))(_stat_path(path, AT_STATX_SYNC_AS_STAT));
155
131
  /// Get metadata for a path given as a raw string (follows symlinks).
156
- metadata_str :: (fn(path: str, using(io : IO)) -> Impl(Future(Metadata, IO, Exception)))
157
- metadata(Path.new(String.from(path)))
158
- ;
159
-
132
+ metadata_str :: (fn(path : str, using(io : IO)) -> Impl(Future(Metadata, IO, Exception)))(metadata(Path.new(String.from(path))));
160
133
  /// Get metadata for a path (does NOT follow symlinks).
161
- symlink_metadata :: (fn(path: Path, using(io : IO)) -> Impl(Future(Metadata, IO, Exception)))
162
- _stat_path(path, (AT_SYMLINK_NOFOLLOW | AT_STATX_SYNC_AS_STAT))
163
- ;
164
-
134
+ symlink_metadata :: (fn(path : Path, using(io : IO)) -> Impl(Future(Metadata, IO, Exception)))(_stat_path(path, AT_SYMLINK_NOFOLLOW | AT_STATX_SYNC_AS_STAT));
165
135
  /// Get metadata for a path given as a raw string (does NOT follow symlinks).
166
- symlink_metadata_str :: (fn(path: str, using(io : IO)) -> Impl(Future(Metadata, IO, Exception)))
167
- symlink_metadata(Path.new(String.from(path)))
168
- ;
169
-
170
- export metadata, metadata_str, symlink_metadata, symlink_metadata_str;
136
+ symlink_metadata_str :: (fn(path : str, using(io : IO)) -> Impl(Future(Metadata, IO, Exception)))(symlink_metadata(Path.new(String.from(path))));
137
+ export(metadata, metadata_str, symlink_metadata, symlink_metadata_str);
package/std/fs/temp.yo CHANGED
@@ -17,31 +17,31 @@
17
17
  //! io.await(dir.remove());
18
18
  //! });
19
19
  //! ```
20
-
21
- { GlobalAllocator } :: import "../allocator";
20
+ { GlobalAllocator } :: import("../allocator");
22
21
  { malloc, free } :: GlobalAllocator;
23
- open import "../string";
24
- open import "../fmt";
25
- { Path } :: import "../path";
26
- { IOError } :: import "../sys/errors";
27
- { Error, AnyError, Exception } :: import "../error";
28
- _file_mod :: import "./file";
29
- _dir_mod :: import "./dir";
30
- IO_temp :: import "../sys/temp";
31
- IO_file :: import "../sys/file";
32
- { memcpy } :: import "../libc/string";
33
- { platform, Platform } :: import "../process";
34
- { env } :: import "../env";
35
-
22
+ open(import("../string"));
23
+ open(import("../fmt"));
24
+ { Path } :: import("../path");
25
+ { IOError } :: import("../sys/errors");
26
+ { Error, AnyError, Exception } :: import("../error");
27
+ _file_mod :: import("./file");
28
+ _dir_mod :: import("./dir");
29
+ IO_temp :: import("../sys/temp");
30
+ IO_file :: import("../sys/file");
31
+ { memcpy } :: import("../libc/string");
32
+ { platform, Platform } :: import("../process");
33
+ { env } :: import("../env");
36
34
  _default_tmp_dir :: (fn() -> String)(
37
35
  cond(
38
36
  (platform == Platform.Windows) => {
39
37
  temp := env.get(`TEMP`);
40
- match(temp,
38
+ match(
39
+ temp,
41
40
  .Some(v) => v,
42
41
  .None => {
43
42
  tmp := env.get(`TMP`);
44
- match(tmp,
43
+ match(
44
+ tmp,
45
45
  .Some(v2) => v2,
46
46
  .None => `C:\\Temp`
47
47
  )
@@ -51,17 +51,15 @@ _default_tmp_dir :: (fn() -> String)(
51
51
  true => `/tmp`
52
52
  )
53
53
  );
54
-
55
-
56
54
  /// Temporary directory that can be cleaned up with `remove`.
57
55
  TempDir :: object(
58
- _path : Path,
56
+ _path : Path,
59
57
  _removed : bool
60
58
  );
61
-
62
- impl(TempDir,
59
+ impl(
60
+ TempDir,
63
61
  // Create a temporary directory in the given parent directory.
64
- new_in : (fn(parent: Path, using(io : IO)) -> Impl(Future(TempDir, IO, Exception)))(
62
+ new_in : (fn(parent : Path, using(io : IO)) -> Impl(Future(TempDir, IO, Exception)))(
65
63
  io.async((using(io, exn)) => {
66
64
  // Build template: parent/yo_tmp_XXXXXX
67
65
  template_path := parent.join(Path.new(`yo_tmp_XXXXXX`));
@@ -76,53 +74,49 @@ impl(TempDir,
76
74
  cond(
77
75
  (result < i32(0)) => {
78
76
  free(.Some(*(void)(buf)));
79
- exn.throw(dyn IOError.from_errno((i32(0) - result)));
77
+ exn.throw(dyn(IOError.from_errno(i32(0) - result)));
80
78
  },
81
79
  true => ()
82
80
  );
83
81
  path_str := String.from_cstr(buf).unwrap();
84
82
  free(.Some(*(void)(buf)));
85
- TempDir(_path: Path.new(path_str), _removed: false)
83
+ TempDir(_path : Path.new(path_str), _removed : false)
86
84
  })
87
85
  ),
88
-
89
86
  // Create a temporary directory in the system temp dir.
90
87
  new : (fn(using(io : IO)) -> Impl(Future(TempDir, IO, Exception)))(
91
88
  TempDir.new_in(Path.new(_default_tmp_dir()))
92
89
  ),
93
-
94
90
  // Get the path of the temporary directory.
95
- path : (fn(self: Self) -> Path)(
91
+ path : (fn(self : Self) -> Path)(
96
92
  self._path
97
93
  ),
98
-
99
94
  // Remove the temporary directory.
100
- remove : (fn(self: Self, using(io : IO)) -> Impl(Future(unit, IO, Exception)))({
95
+ remove : (fn(self : Self, using(io : IO)) -> Impl(Future(unit, IO, Exception)))({
101
96
  self_path := self._path;
102
- io.async((using(io, exn)) =>
103
- cond(
104
- self._removed => (),
105
- true => {
106
- io.await(_dir_mod.remove_dir(self_path));
107
- self._removed = true;
108
- }
109
- )
97
+ io.async(
98
+ (using(io, exn)) =>
99
+ cond(
100
+ self._removed => (),
101
+ true => {
102
+ io.await(_dir_mod.remove_dir(self_path));
103
+ self._removed = true;
104
+ }
105
+ )
110
106
  )
111
107
  })
112
108
  );
113
-
114
- export TempDir;
115
-
109
+ export(TempDir);
116
110
  /// Temporary file backed by a `File` handle.
117
111
  TempFile :: object(
118
112
  _file : _file_mod.File,
119
113
  _path : Path,
120
114
  _removed : bool
121
115
  );
122
-
123
- impl(TempFile,
116
+ impl(
117
+ TempFile,
124
118
  // Create a temporary file in the given parent directory.
125
- new_in : (fn(parent: Path, using(io : IO)) -> Impl(Future(TempFile, IO, Exception)))(
119
+ new_in : (fn(parent : Path, using(io : IO)) -> Impl(Future(TempFile, IO, Exception)))(
126
120
  io.async((using(io, exn)) => {
127
121
  // Build template: parent/yo_tmp_XXXXXX
128
122
  template_path := parent.join(Path.new(`yo_tmp_XXXXXX`));
@@ -136,48 +130,44 @@ impl(TempFile,
136
130
  cond(
137
131
  (fd < i32(0)) => {
138
132
  free(.Some(*(void)(buf)));
139
- exn.throw(dyn IOError.from_errno((i32(0) - fd)));
133
+ exn.throw(dyn(IOError.from_errno(i32(0) - fd)));
140
134
  },
141
135
  true => ()
142
136
  );
143
137
  path_str := String.from_cstr(buf).unwrap();
144
138
  free(.Some(*(void)(buf)));
145
139
  path := Path.new(path_str);
146
- file := _file_mod.File(_fd: fd, _path: path, _is_closed: false);
147
- TempFile(_file: file, _path: path, _removed: false)
140
+ file := _file_mod.File(_fd : fd, _path : path, _is_closed : false);
141
+ TempFile(_file : file, _path : path, _removed : false)
148
142
  })
149
143
  ),
150
-
151
144
  // Create a temporary file in the system temp dir.
152
145
  new : (fn(using(io : IO)) -> Impl(Future(TempFile, IO, Exception)))(
153
146
  TempFile.new_in(Path.new(_default_tmp_dir()))
154
147
  ),
155
-
156
148
  // Get the underlying File object.
157
- file : (fn(self: Self) -> _file_mod.File)(
149
+ file : (fn(self : Self) -> _file_mod.File)(
158
150
  self._file
159
151
  ),
160
-
161
152
  // Get the path of the temporary file.
162
- path : (fn(self: Self) -> Path)(
153
+ path : (fn(self : Self) -> Path)(
163
154
  self._path
164
155
  ),
165
-
166
156
  // Remove the temporary file.
167
- remove : (fn(self: Self, using(io : IO)) -> Impl(Future(unit, IO, Exception)))({
157
+ remove : (fn(self : Self, using(io : IO)) -> Impl(Future(unit, IO, Exception)))({
168
158
  self_file := self._file;
169
159
  self_path := self._path;
170
- io.async((using(io, exn)) =>
171
- cond(
172
- self._removed => (),
173
- true => {
174
- io.await(self_file.close());
175
- io.await(_dir_mod.remove_file(self_path));
176
- self._removed = true;
177
- }
178
- )
160
+ io.async(
161
+ (using(io, exn)) =>
162
+ cond(
163
+ self._removed => (),
164
+ true => {
165
+ io.await(self_file.close());
166
+ io.await(_dir_mod.remove_file(self_path));
167
+ self._removed = true;
168
+ }
169
+ )
179
170
  )
180
171
  })
181
172
  );
182
-
183
- export TempFile;
173
+ export(TempFile);
package/std/fs/types.yo CHANGED
@@ -1,10 +1,5 @@
1
1
  //! File system types for open modes, permissions, and seek positions.
2
-
3
- {
4
- O_RDONLY, O_WRONLY, O_RDWR, O_CREAT, O_TRUNC, O_APPEND,
5
- O_EXCL, O_CLOEXEC, DEFAULT_FILE_MODE
6
- } :: import "../sys/constants";
7
-
2
+ { O_RDONLY, O_WRONLY, O_RDWR, O_CREAT, O_TRUNC, O_APPEND, O_EXCL, O_CLOEXEC, DEFAULT_FILE_MODE } :: import("../sys/constants");
8
3
  /// Determines how a file is opened.
9
4
  OpenMode :: enum(
10
5
  /// Read an existing file (O_RDONLY).
@@ -18,62 +13,55 @@ OpenMode :: enum(
18
13
  /// Create a new file, fail if it already exists (O_WRONLY | O_CREAT | O_EXCL).
19
14
  CreateNew
20
15
  );
21
-
22
16
  // Convert OpenMode to POSIX open flags.
23
- _open_mode_to_flags :: (fn(mode: OpenMode) -> i32)(
24
- match(mode,
25
- .Read => (O_RDONLY | O_CLOEXEC),
26
- .Write => (((O_WRONLY | O_CREAT) | O_TRUNC) | O_CLOEXEC),
27
- .Append => (((O_WRONLY | O_CREAT) | O_APPEND) | O_CLOEXEC),
17
+ _open_mode_to_flags :: (fn(mode : OpenMode) -> i32)(
18
+ match(
19
+ mode,
20
+ .Read => (O_RDONLY | O_CLOEXEC),
21
+ .Write => (((O_WRONLY | O_CREAT) | O_TRUNC) | O_CLOEXEC),
22
+ .Append => (((O_WRONLY | O_CREAT) | O_APPEND) | O_CLOEXEC),
28
23
  .ReadWrite => (O_RDWR | O_CLOEXEC),
29
24
  .CreateNew => (((O_WRONLY | O_CREAT) | O_EXCL) | O_CLOEXEC)
30
25
  )
31
26
  );
32
-
33
27
  // Returns the POSIX mode for an OpenMode.
34
28
  // Read/ReadWrite don't create files, so mode is 0.
35
29
  // Write/Append/CreateNew create files, so use the given permission.
36
- _open_mode_needs_perm :: (fn(mode: OpenMode) -> bool)(
37
- match(mode,
38
- .Read => false,
39
- .Write => true,
40
- .Append => true,
30
+ _open_mode_needs_perm :: (fn(mode : OpenMode) -> bool)(
31
+ match(
32
+ mode,
33
+ .Read => false,
34
+ .Write => true,
35
+ .Append => true,
41
36
  .ReadWrite => false,
42
37
  .CreateNew => true
43
38
  )
44
39
  );
45
-
46
- export OpenMode, _open_mode_to_flags, _open_mode_needs_perm;
47
-
40
+ export(OpenMode, _open_mode_to_flags, _open_mode_needs_perm);
48
41
  /// POSIX file permission bits.
49
42
  FilePermission :: newtype(
50
43
  mode : u32
51
44
  );
52
-
53
- impl(FilePermission,
45
+ impl(
46
+ FilePermission,
54
47
  // Default file permissions: rw-r--r-- (0o644)
55
48
  default : (fn() -> Self)(
56
- Self(mode: u32(0o644))
49
+ Self(mode : u32(0o644))
57
50
  ),
58
-
59
51
  // Executable permissions: rwxr-xr-x (0o755)
60
52
  executable : (fn() -> Self)(
61
- Self(mode: u32(0o755))
53
+ Self(mode : u32(0o755))
62
54
  ),
63
-
64
55
  // Read-only permissions: r--r--r-- (0o444)
65
56
  readonly : (fn() -> Self)(
66
- Self(mode: u32(0o444))
57
+ Self(mode : u32(0o444))
67
58
  ),
68
-
69
59
  // Private permissions: rw------- (0o600)
70
60
  private : (fn() -> Self)(
71
- Self(mode: u32(0o600))
61
+ Self(mode : u32(0o600))
72
62
  )
73
63
  );
74
-
75
- export FilePermission;
76
-
64
+ export(FilePermission);
77
65
  /// Reference point for file seek operations.
78
66
  SeekFrom :: enum(
79
67
  /// Seek from the beginning of the file.
@@ -83,14 +71,13 @@ SeekFrom :: enum(
83
71
  /// Seek relative to the end of the file.
84
72
  End
85
73
  );
86
-
87
74
  // Convert SeekFrom to POSIX whence constant (i32).
88
- _seek_from_to_whence :: (fn(from: SeekFrom) -> i32)(
89
- match(from,
90
- .Start => i32(0),
75
+ _seek_from_to_whence :: (fn(from : SeekFrom) -> i32)(
76
+ match(
77
+ from,
78
+ .Start => i32(0),
91
79
  .Current => i32(1),
92
- .End => i32(2)
80
+ .End => i32(2)
93
81
  )
94
82
  );
95
-
96
- export SeekFrom, _seek_from_to_whence;
83
+ export(SeekFrom, _seek_from_to_whence);