@shd101wyy/yo 0.1.29 → 0.1.31
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.
- package/.github/skills/yo-async-effects/SKILL.md +3 -3
- package/.github/skills/yo-async-effects/async-effects-recipes.md +19 -11
- package/.github/skills/yo-core-patterns/core-patterns-cheatsheet.md +33 -13
- package/.github/skills/yo-project-workflow/workflow-cheatsheet.md +1 -1
- package/.github/skills/yo-syntax/syntax-cheatsheet.md +59 -21
- package/README.md +4 -3
- package/out/cjs/index.cjs +964 -710
- package/out/cjs/yo-cli.cjs +1119 -855
- package/out/cjs/yo-lsp.cjs +1003 -749
- package/out/esm/index.mjs +964 -710
- package/out/types/src/codegen/exprs/async.d.ts +2 -0
- package/out/types/src/codegen/exprs/await.d.ts +1 -0
- package/out/types/src/codegen/exprs/closures.d.ts +4 -0
- package/out/types/src/codegen/functions/context.d.ts +6 -0
- package/out/types/src/codegen/index.d.ts +1 -1
- package/out/types/src/compiler-utils.d.ts +1 -1
- package/out/types/src/env.d.ts +2 -0
- package/out/types/src/evaluator/builtins/pragma.d.ts +9 -0
- package/out/types/src/evaluator/builtins/unsafe.d.ts +8 -0
- package/out/types/src/evaluator/context.d.ts +2 -0
- package/out/types/src/evaluator/index.d.ts +1 -1
- package/out/types/src/evaluator/memory-safety.d.ts +14 -0
- package/out/types/src/evaluator/types/flowability.d.ts +6 -0
- package/out/types/src/evaluator/utils/closure.d.ts +2 -1
- package/out/types/src/evaluator/utils.d.ts +3 -0
- package/out/types/src/evaluator/values/impl.d.ts +14 -0
- package/out/types/src/expr-traversal.d.ts +1 -0
- package/out/types/src/expr.d.ts +4 -1
- package/out/types/src/public-safe-report.d.ts +19 -0
- package/out/types/src/tests/comptime-ref-gate.test.d.ts +1 -0
- package/out/types/src/tests/pragma-validation.test.d.ts +1 -0
- package/out/types/src/tests/public-safe-report.test.d.ts +1 -0
- package/out/types/src/tests/thread-safety-codegen.test.d.ts +1 -0
- package/out/types/src/tests/type-representation-pointer.test.d.ts +1 -0
- package/out/types/src/tests/unsafe-gate.test.d.ts +1 -0
- package/out/types/src/tests/unsafe-report-classify.test.d.ts +1 -0
- package/out/types/src/types/definitions.d.ts +2 -0
- package/out/types/src/types/utils.d.ts +4 -0
- package/out/types/src/unsafe-report.d.ts +29 -0
- package/out/types/src/value.d.ts +1 -0
- package/out/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/scripts/add-pragma-for-pointer-decls.ts +134 -0
- package/scripts/add-pragma.ts +58 -0
- package/scripts/migrate-amp-method-calls.ts +186 -0
- package/scripts/migrate-clone-calls.ts +93 -0
- package/scripts/migrate-get-unwrap.ts +166 -0
- package/scripts/migrate-index-patterns.ts +210 -0
- package/scripts/migrate-index-trait.ts +142 -0
- package/scripts/migrate-iterator.ts +150 -0
- package/scripts/migrate-self-ptr.ts +220 -0
- package/scripts/migrate-skip-pragmas.ts +109 -0
- package/scripts/migrate-tostring.ts +134 -0
- package/scripts/trim-pragma.ts +130 -0
- package/scripts/wrap-extern-calls.ts +161 -0
- package/std/alg/hash.yo +3 -2
- package/std/allocator.yo +6 -5
- package/std/async.yo +2 -2
- package/std/build.yo +5 -2
- package/std/collections/array_list.yo +59 -40
- package/std/collections/btree_map.yo +19 -18
- package/std/collections/deque.yo +9 -8
- package/std/collections/hash_map.yo +101 -13
- package/std/collections/hash_set.yo +5 -4
- package/std/collections/linked_list.yo +39 -4
- package/std/collections/ordered_map.yo +3 -3
- package/std/collections/priority_queue.yo +14 -13
- package/std/crypto/md5.yo +2 -1
- package/std/crypto/random.yo +16 -15
- package/std/crypto/sha256.yo +2 -1
- package/std/encoding/base64.yo +14 -14
- package/std/encoding/hex.yo +3 -3
- package/std/encoding/json.yo +59 -10
- package/std/encoding/punycode.yo +24 -23
- package/std/encoding/toml.yo +4 -3
- package/std/encoding/utf16.yo +2 -2
- package/std/env.yo +43 -28
- package/std/error.yo +6 -6
- package/std/fmt/display.yo +2 -2
- package/std/fmt/index.yo +6 -5
- package/std/fmt/to_string.yo +39 -38
- package/std/fmt/writer.yo +9 -8
- package/std/fs/dir.yo +34 -33
- package/std/fs/file.yo +52 -51
- package/std/fs/metadata.yo +10 -9
- package/std/fs/temp.yo +24 -13
- package/std/fs/walker.yo +10 -9
- package/std/gc.yo +1 -0
- package/std/glob.yo +7 -7
- package/std/http/client.yo +15 -14
- package/std/http/http.yo +6 -6
- package/std/http/index.yo +1 -1
- package/std/imm/list.yo +34 -1
- package/std/imm/map.yo +2 -1
- package/std/imm/set.yo +1 -0
- package/std/imm/sorted_map.yo +2 -1
- package/std/imm/sorted_set.yo +1 -0
- package/std/imm/string.yo +27 -23
- package/std/imm/vec.yo +18 -2
- package/std/io/reader.yo +2 -1
- package/std/io/writer.yo +3 -2
- package/std/libc/assert.yo +1 -0
- package/std/libc/ctype.yo +1 -0
- package/std/libc/dirent.yo +1 -0
- package/std/libc/errno.yo +1 -0
- package/std/libc/fcntl.yo +1 -0
- package/std/libc/float.yo +1 -0
- package/std/libc/limits.yo +1 -0
- package/std/libc/math.yo +1 -0
- package/std/libc/signal.yo +1 -0
- package/std/libc/stdatomic.yo +251 -1
- package/std/libc/stdint.yo +1 -0
- package/std/libc/stdio.yo +1 -0
- package/std/libc/stdlib.yo +1 -0
- package/std/libc/string.yo +1 -0
- package/std/libc/sys/stat.yo +1 -0
- package/std/libc/time.yo +1 -0
- package/std/libc/unistd.yo +1 -0
- package/std/libc/wctype.yo +1 -0
- package/std/libc/windows.yo +2 -0
- package/std/log.yo +7 -6
- package/std/net/addr.yo +5 -4
- package/std/net/dns.yo +7 -6
- package/std/net/errors.yo +8 -8
- package/std/net/tcp.yo +19 -18
- package/std/net/udp.yo +13 -12
- package/std/os/signal.yo +3 -3
- package/std/path.yo +1 -0
- package/std/prelude.yo +398 -184
- package/std/process/command.yo +40 -23
- package/std/process/index.yo +2 -1
- package/std/regex/compiler.yo +10 -9
- package/std/regex/index.yo +41 -41
- package/std/regex/match.yo +2 -2
- package/std/regex/parser.yo +21 -21
- package/std/regex/vm.yo +42 -41
- package/std/string/rune.yo +4 -0
- package/std/string/string.yo +95 -40
- package/std/string/string_builder.yo +9 -9
- package/std/string/unicode.yo +50 -49
- package/std/sync/atomic.yo +557 -0
- package/std/sync/channel.yo +59 -43
- package/std/sync/cond.yo +12 -7
- package/std/sync/mutex.yo +79 -18
- package/std/sync/once.yo +25 -19
- package/std/sync/rwlock.yo +18 -15
- package/std/sync/waitgroup.yo +25 -16
- package/std/sys/advise.yo +1 -0
- package/std/sys/bufio/buf_reader.yo +17 -16
- package/std/sys/bufio/buf_writer.yo +10 -9
- package/std/sys/clock.yo +1 -0
- package/std/sys/copy.yo +1 -0
- package/std/sys/dir.yo +10 -9
- package/std/sys/dns.yo +6 -5
- package/std/sys/errors.yo +11 -11
- package/std/sys/events.yo +1 -0
- package/std/sys/externs.yo +38 -37
- package/std/sys/file.yo +17 -16
- package/std/sys/future.yo +4 -3
- package/std/sys/iov.yo +1 -0
- package/std/sys/mmap.yo +1 -0
- package/std/sys/path.yo +1 -0
- package/std/sys/perm.yo +2 -1
- package/std/sys/pipe.yo +1 -0
- package/std/sys/process.yo +5 -4
- package/std/sys/signal.yo +1 -0
- package/std/sys/socketpair.yo +1 -0
- package/std/sys/sockinfo.yo +1 -0
- package/std/sys/statfs.yo +2 -1
- package/std/sys/statx.yo +1 -0
- package/std/sys/sysinfo.yo +1 -0
- package/std/sys/tcp.yo +15 -14
- package/std/sys/temp.yo +1 -0
- package/std/sys/time.yo +2 -1
- package/std/sys/timer.yo +6 -6
- package/std/sys/tty.yo +2 -1
- package/std/sys/udp.yo +13 -12
- package/std/sys/unix.yo +12 -11
- package/std/testing/bench.yo +4 -3
- package/std/thread.yo +7 -6
- package/std/time/datetime.yo +18 -15
- package/std/time/duration.yo +11 -10
- package/std/time/instant.yo +4 -4
- package/std/time/sleep.yo +1 -0
- package/std/url/index.yo +3 -3
- package/std/worker.yo +4 -3
package/std/libc/stdatomic.yo
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
//! C11 `<stdatomic.h>` — atomic operations and types.
|
|
2
|
+
pragma(Pragma.AllowUnsafe);
|
|
2
3
|
c_include(
|
|
3
4
|
"<stdatomic.h>",
|
|
4
5
|
// Atomic types
|
|
@@ -137,6 +138,209 @@ c_include(
|
|
|
137
138
|
ATOMIC_LLONG_LOCK_FREE : i32,
|
|
138
139
|
ATOMIC_POINTER_LOCK_FREE : i32
|
|
139
140
|
);
|
|
141
|
+
// SAFETY: C11 atomic typedefs (atomic_bool, atomic_int, etc.) are opaque C
|
|
142
|
+
// types backed by _Atomic-qualified primitives. They contain no heap
|
|
143
|
+
// allocations or thread-local state — they are trivially safe to send
|
|
144
|
+
// across threads. They are Acyclic because they don't participate in Yo's
|
|
145
|
+
// ARC reference-counting cycle analysis.
|
|
146
|
+
impl(atomic_bool, Send());
|
|
147
|
+
impl(atomic_bool, Acyclic());
|
|
148
|
+
impl(atomic_char, Send());
|
|
149
|
+
impl(atomic_char, Acyclic());
|
|
150
|
+
impl(atomic_schar, Send());
|
|
151
|
+
impl(atomic_schar, Acyclic());
|
|
152
|
+
impl(atomic_uchar, Send());
|
|
153
|
+
impl(atomic_uchar, Acyclic());
|
|
154
|
+
impl(atomic_short, Send());
|
|
155
|
+
impl(atomic_short, Acyclic());
|
|
156
|
+
impl(atomic_ushort, Send());
|
|
157
|
+
impl(atomic_ushort, Acyclic());
|
|
158
|
+
impl(atomic_int, Send());
|
|
159
|
+
impl(atomic_int, Acyclic());
|
|
160
|
+
impl(atomic_uint, Send());
|
|
161
|
+
impl(atomic_uint, Acyclic());
|
|
162
|
+
impl(atomic_long, Send());
|
|
163
|
+
impl(atomic_long, Acyclic());
|
|
164
|
+
impl(atomic_ulong, Send());
|
|
165
|
+
impl(atomic_ulong, Acyclic());
|
|
166
|
+
impl(atomic_llong, Send());
|
|
167
|
+
impl(atomic_llong, Acyclic());
|
|
168
|
+
impl(atomic_ullong, Send());
|
|
169
|
+
impl(atomic_ullong, Acyclic());
|
|
170
|
+
impl(atomic_char16_t, Send());
|
|
171
|
+
impl(atomic_char16_t, Acyclic());
|
|
172
|
+
impl(atomic_char32_t, Send());
|
|
173
|
+
impl(atomic_char32_t, Acyclic());
|
|
174
|
+
impl(atomic_wchar_t, Send());
|
|
175
|
+
impl(atomic_wchar_t, Acyclic());
|
|
176
|
+
impl(atomic_int_least8_t, Send());
|
|
177
|
+
impl(atomic_int_least8_t, Acyclic());
|
|
178
|
+
impl(atomic_uint_least8_t, Send());
|
|
179
|
+
impl(atomic_uint_least8_t, Acyclic());
|
|
180
|
+
impl(atomic_int_least16_t, Send());
|
|
181
|
+
impl(atomic_int_least16_t, Acyclic());
|
|
182
|
+
impl(atomic_uint_least16_t, Send());
|
|
183
|
+
impl(atomic_uint_least16_t, Acyclic());
|
|
184
|
+
impl(atomic_int_least32_t, Send());
|
|
185
|
+
impl(atomic_int_least32_t, Acyclic());
|
|
186
|
+
impl(atomic_uint_least32_t, Send());
|
|
187
|
+
impl(atomic_uint_least32_t, Acyclic());
|
|
188
|
+
impl(atomic_int_least64_t, Send());
|
|
189
|
+
impl(atomic_int_least64_t, Acyclic());
|
|
190
|
+
impl(atomic_uint_least64_t, Send());
|
|
191
|
+
impl(atomic_uint_least64_t, Acyclic());
|
|
192
|
+
impl(atomic_int_fast8_t, Send());
|
|
193
|
+
impl(atomic_int_fast8_t, Acyclic());
|
|
194
|
+
impl(atomic_uint_fast8_t, Send());
|
|
195
|
+
impl(atomic_uint_fast8_t, Acyclic());
|
|
196
|
+
impl(atomic_int_fast16_t, Send());
|
|
197
|
+
impl(atomic_int_fast16_t, Acyclic());
|
|
198
|
+
impl(atomic_uint_fast16_t, Send());
|
|
199
|
+
impl(atomic_uint_fast16_t, Acyclic());
|
|
200
|
+
impl(atomic_int_fast32_t, Send());
|
|
201
|
+
impl(atomic_int_fast32_t, Acyclic());
|
|
202
|
+
impl(atomic_uint_fast32_t, Send());
|
|
203
|
+
impl(atomic_uint_fast32_t, Acyclic());
|
|
204
|
+
impl(atomic_int_fast64_t, Send());
|
|
205
|
+
impl(atomic_int_fast64_t, Acyclic());
|
|
206
|
+
impl(atomic_uint_fast64_t, Send());
|
|
207
|
+
impl(atomic_uint_fast64_t, Acyclic());
|
|
208
|
+
impl(atomic_intptr_t, Send());
|
|
209
|
+
impl(atomic_intptr_t, Acyclic());
|
|
210
|
+
impl(atomic_uintptr_t, Send());
|
|
211
|
+
impl(atomic_uintptr_t, Acyclic());
|
|
212
|
+
impl(atomic_size_t, Send());
|
|
213
|
+
impl(atomic_size_t, Acyclic());
|
|
214
|
+
impl(atomic_ptrdiff_t, Send());
|
|
215
|
+
impl(atomic_ptrdiff_t, Acyclic());
|
|
216
|
+
impl(atomic_intmax_t, Send());
|
|
217
|
+
impl(atomic_intmax_t, Acyclic());
|
|
218
|
+
impl(atomic_uintmax_t, Send());
|
|
219
|
+
impl(atomic_uintmax_t, Acyclic());
|
|
220
|
+
// Phase C (THREAD_SAFETY): int-specific atomic operations. The c_include
|
|
221
|
+
// block only declares load/store/exchange for atomic_bool. These Yo-runtime
|
|
222
|
+
// wrappers forward to the C11 _Generic macros in <stdatomic.h> so AtomicI32
|
|
223
|
+
// can use the full atomic API.
|
|
224
|
+
extern(
|
|
225
|
+
"Yo",
|
|
226
|
+
__yo_atomic_load_int :
|
|
227
|
+
fn(obj : *(atomic_int), order : memory_order) -> i32,
|
|
228
|
+
__yo_atomic_store_int :
|
|
229
|
+
fn(obj : *(atomic_int), desired : i32, order : memory_order) -> unit,
|
|
230
|
+
__yo_atomic_exchange_int :
|
|
231
|
+
fn(obj : *(atomic_int), desired : i32, order : memory_order) -> i32,
|
|
232
|
+
__yo_atomic_compare_exchange_int :
|
|
233
|
+
fn(
|
|
234
|
+
obj : *(atomic_int),
|
|
235
|
+
expected : *(i32),
|
|
236
|
+
desired : i32,
|
|
237
|
+
success : memory_order,
|
|
238
|
+
failure : memory_order
|
|
239
|
+
) -> bool
|
|
240
|
+
);
|
|
241
|
+
// Phase C: size_t-specific atomic operations (for AtomicUsize)
|
|
242
|
+
extern(
|
|
243
|
+
"Yo",
|
|
244
|
+
__yo_atomic_load_size_t :
|
|
245
|
+
fn(obj : *(atomic_size_t), order : memory_order) -> usize,
|
|
246
|
+
__yo_atomic_store_size_t :
|
|
247
|
+
fn(obj : *(atomic_size_t), desired : usize, order : memory_order) -> unit,
|
|
248
|
+
__yo_atomic_exchange_size_t :
|
|
249
|
+
fn(obj : *(atomic_size_t), desired : usize, order : memory_order) -> usize,
|
|
250
|
+
__yo_atomic_compare_exchange_size_t :
|
|
251
|
+
fn(
|
|
252
|
+
obj : *(atomic_size_t),
|
|
253
|
+
expected : *(usize),
|
|
254
|
+
desired : usize,
|
|
255
|
+
success : memory_order,
|
|
256
|
+
failure : memory_order
|
|
257
|
+
) -> bool
|
|
258
|
+
);
|
|
259
|
+
// Phase C: long-long-specific atomic operations (for AtomicI64)
|
|
260
|
+
extern(
|
|
261
|
+
"Yo",
|
|
262
|
+
__yo_atomic_load_llong :
|
|
263
|
+
fn(obj : *(atomic_llong), order : memory_order) -> i64,
|
|
264
|
+
__yo_atomic_store_llong :
|
|
265
|
+
fn(obj : *(atomic_llong), desired : i64, order : memory_order) -> unit,
|
|
266
|
+
__yo_atomic_exchange_llong :
|
|
267
|
+
fn(obj : *(atomic_llong), desired : i64, order : memory_order) -> i64,
|
|
268
|
+
__yo_atomic_compare_exchange_llong :
|
|
269
|
+
fn(
|
|
270
|
+
obj : *(atomic_llong),
|
|
271
|
+
expected : *(i64),
|
|
272
|
+
desired : i64,
|
|
273
|
+
success : memory_order,
|
|
274
|
+
failure : memory_order
|
|
275
|
+
) -> bool
|
|
276
|
+
);
|
|
277
|
+
// Phase C: remaining atomic type wrappers
|
|
278
|
+
extern(
|
|
279
|
+
"Yo",
|
|
280
|
+
__yo_atomic_load_schar :
|
|
281
|
+
fn(obj : *(atomic_schar), order : memory_order) -> i8,
|
|
282
|
+
__yo_atomic_store_schar :
|
|
283
|
+
fn(obj : *(atomic_schar), desired : i8, order : memory_order) -> unit,
|
|
284
|
+
__yo_atomic_exchange_schar :
|
|
285
|
+
fn(obj : *(atomic_schar), desired : i8, order : memory_order) -> i8,
|
|
286
|
+
__yo_atomic_compare_exchange_schar :
|
|
287
|
+
fn(obj : *(atomic_schar), expected : *(i8), desired : i8,
|
|
288
|
+
success : memory_order, failure : memory_order) -> bool,
|
|
289
|
+
__yo_atomic_load_short :
|
|
290
|
+
fn(obj : *(atomic_short), order : memory_order) -> i16,
|
|
291
|
+
__yo_atomic_store_short :
|
|
292
|
+
fn(obj : *(atomic_short), desired : i16, order : memory_order) -> unit,
|
|
293
|
+
__yo_atomic_exchange_short :
|
|
294
|
+
fn(obj : *(atomic_short), desired : i16, order : memory_order) -> i16,
|
|
295
|
+
__yo_atomic_compare_exchange_short :
|
|
296
|
+
fn(obj : *(atomic_short), expected : *(i16), desired : i16,
|
|
297
|
+
success : memory_order, failure : memory_order) -> bool,
|
|
298
|
+
__yo_atomic_load_uchar :
|
|
299
|
+
fn(obj : *(atomic_uchar), order : memory_order) -> u8,
|
|
300
|
+
__yo_atomic_store_uchar :
|
|
301
|
+
fn(obj : *(atomic_uchar), desired : u8, order : memory_order) -> unit,
|
|
302
|
+
__yo_atomic_exchange_uchar :
|
|
303
|
+
fn(obj : *(atomic_uchar), desired : u8, order : memory_order) -> u8,
|
|
304
|
+
__yo_atomic_compare_exchange_uchar :
|
|
305
|
+
fn(obj : *(atomic_uchar), expected : *(u8), desired : u8,
|
|
306
|
+
success : memory_order, failure : memory_order) -> bool,
|
|
307
|
+
__yo_atomic_load_ushort :
|
|
308
|
+
fn(obj : *(atomic_ushort), order : memory_order) -> u16,
|
|
309
|
+
__yo_atomic_store_ushort :
|
|
310
|
+
fn(obj : *(atomic_ushort), desired : u16, order : memory_order) -> unit,
|
|
311
|
+
__yo_atomic_exchange_ushort :
|
|
312
|
+
fn(obj : *(atomic_ushort), desired : u16, order : memory_order) -> u16,
|
|
313
|
+
__yo_atomic_compare_exchange_ushort :
|
|
314
|
+
fn(obj : *(atomic_ushort), expected : *(u16), desired : u16,
|
|
315
|
+
success : memory_order, failure : memory_order) -> bool,
|
|
316
|
+
__yo_atomic_load_uint :
|
|
317
|
+
fn(obj : *(atomic_uint), order : memory_order) -> u32,
|
|
318
|
+
__yo_atomic_store_uint :
|
|
319
|
+
fn(obj : *(atomic_uint), desired : u32, order : memory_order) -> unit,
|
|
320
|
+
__yo_atomic_exchange_uint :
|
|
321
|
+
fn(obj : *(atomic_uint), desired : u32, order : memory_order) -> u32,
|
|
322
|
+
__yo_atomic_compare_exchange_uint :
|
|
323
|
+
fn(obj : *(atomic_uint), expected : *(u32), desired : u32,
|
|
324
|
+
success : memory_order, failure : memory_order) -> bool,
|
|
325
|
+
__yo_atomic_load_ullong :
|
|
326
|
+
fn(obj : *(atomic_ullong), order : memory_order) -> u64,
|
|
327
|
+
__yo_atomic_store_ullong :
|
|
328
|
+
fn(obj : *(atomic_ullong), desired : u64, order : memory_order) -> unit,
|
|
329
|
+
__yo_atomic_exchange_ullong :
|
|
330
|
+
fn(obj : *(atomic_ullong), desired : u64, order : memory_order) -> u64,
|
|
331
|
+
__yo_atomic_compare_exchange_ullong :
|
|
332
|
+
fn(obj : *(atomic_ullong), expected : *(u64), desired : u64,
|
|
333
|
+
success : memory_order, failure : memory_order) -> bool,
|
|
334
|
+
__yo_atomic_load_ptrdiff :
|
|
335
|
+
fn(obj : *(atomic_ptrdiff_t), order : memory_order) -> isize,
|
|
336
|
+
__yo_atomic_store_ptrdiff :
|
|
337
|
+
fn(obj : *(atomic_ptrdiff_t), desired : isize, order : memory_order) -> unit,
|
|
338
|
+
__yo_atomic_exchange_ptrdiff :
|
|
339
|
+
fn(obj : *(atomic_ptrdiff_t), desired : isize, order : memory_order) -> isize,
|
|
340
|
+
__yo_atomic_compare_exchange_ptrdiff :
|
|
341
|
+
fn(obj : *(atomic_ptrdiff_t), expected : *(isize), desired : isize,
|
|
342
|
+
success : memory_order, failure : memory_order) -> bool
|
|
343
|
+
);
|
|
140
344
|
export(
|
|
141
345
|
// Atomic types
|
|
142
346
|
atomic_bool,
|
|
@@ -237,5 +441,51 @@ export(
|
|
|
237
441
|
ATOMIC_LLONG_LOCK_FREE,
|
|
238
442
|
ATOMIC_POINTER_LOCK_FREE,
|
|
239
443
|
// Kill dependency
|
|
240
|
-
kill_dependency
|
|
444
|
+
kill_dependency,
|
|
445
|
+
// Phase C (THREAD_SAFETY): int-specific atomic wrappers
|
|
446
|
+
__yo_atomic_load_int,
|
|
447
|
+
__yo_atomic_store_int,
|
|
448
|
+
__yo_atomic_exchange_int,
|
|
449
|
+
__yo_atomic_compare_exchange_int,
|
|
450
|
+
// Phase C: size_t atomic wrappers
|
|
451
|
+
__yo_atomic_load_size_t,
|
|
452
|
+
__yo_atomic_store_size_t,
|
|
453
|
+
__yo_atomic_exchange_size_t,
|
|
454
|
+
__yo_atomic_compare_exchange_size_t,
|
|
455
|
+
// Phase C: llong atomic wrappers
|
|
456
|
+
__yo_atomic_load_llong,
|
|
457
|
+
__yo_atomic_store_llong,
|
|
458
|
+
__yo_atomic_exchange_llong,
|
|
459
|
+
__yo_atomic_compare_exchange_llong,
|
|
460
|
+
// Phase C: signed narrow atomics
|
|
461
|
+
__yo_atomic_load_schar,
|
|
462
|
+
__yo_atomic_store_schar,
|
|
463
|
+
__yo_atomic_exchange_schar,
|
|
464
|
+
__yo_atomic_compare_exchange_schar,
|
|
465
|
+
__yo_atomic_load_short,
|
|
466
|
+
__yo_atomic_store_short,
|
|
467
|
+
__yo_atomic_exchange_short,
|
|
468
|
+
__yo_atomic_compare_exchange_short,
|
|
469
|
+
// Phase C: unsigned atomics
|
|
470
|
+
__yo_atomic_load_uchar,
|
|
471
|
+
__yo_atomic_store_uchar,
|
|
472
|
+
__yo_atomic_exchange_uchar,
|
|
473
|
+
__yo_atomic_compare_exchange_uchar,
|
|
474
|
+
__yo_atomic_load_ushort,
|
|
475
|
+
__yo_atomic_store_ushort,
|
|
476
|
+
__yo_atomic_exchange_ushort,
|
|
477
|
+
__yo_atomic_compare_exchange_ushort,
|
|
478
|
+
__yo_atomic_load_uint,
|
|
479
|
+
__yo_atomic_store_uint,
|
|
480
|
+
__yo_atomic_exchange_uint,
|
|
481
|
+
__yo_atomic_compare_exchange_uint,
|
|
482
|
+
__yo_atomic_load_ullong,
|
|
483
|
+
__yo_atomic_store_ullong,
|
|
484
|
+
__yo_atomic_exchange_ullong,
|
|
485
|
+
__yo_atomic_compare_exchange_ullong,
|
|
486
|
+
// Phase C: isize
|
|
487
|
+
__yo_atomic_load_ptrdiff,
|
|
488
|
+
__yo_atomic_store_ptrdiff,
|
|
489
|
+
__yo_atomic_exchange_ptrdiff,
|
|
490
|
+
__yo_atomic_compare_exchange_ptrdiff
|
|
241
491
|
);
|
package/std/libc/stdint.yo
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
//! Note: Yo already has `i8`, `i16`, `i32`, `i64`, `u8`, `u16`, `u32`, `u64`.
|
|
4
4
|
//! This file provides C-compatible aliases and additional types/constants.
|
|
5
5
|
// Type aliases for C compatibility (mapping Yo types to C stdint names)
|
|
6
|
+
pragma(Pragma.AllowUnsafe);
|
|
6
7
|
int8_t :: i8;
|
|
7
8
|
int16_t :: i16;
|
|
8
9
|
int32_t :: i32;
|
package/std/libc/stdio.yo
CHANGED
package/std/libc/stdlib.yo
CHANGED
package/std/libc/string.yo
CHANGED
package/std/libc/sys/stat.yo
CHANGED
package/std/libc/time.yo
CHANGED
package/std/libc/unistd.yo
CHANGED
package/std/libc/wctype.yo
CHANGED
package/std/libc/windows.yo
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
//! Windows-specific C API bindings.
|
|
2
2
|
//! Only available when compiling for Windows.
|
|
3
3
|
// Windows type aliases (using Yo types that match the C types)
|
|
4
|
+
pragma(Pragma.AllowUnsafe);
|
|
5
|
+
pragma(Pragma.AllowUnsafe);
|
|
4
6
|
DWORD :: ulong; // unsigned long on Windows
|
|
5
7
|
WCHAR :: ushort; // unsigned short (UTF-16 code unit)
|
|
6
8
|
BOOL :: int; // int
|
package/std/log.yo
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
//! Structured logging with configurable level and output destination.
|
|
2
|
+
pragma(Pragma.AllowUnsafe);
|
|
2
3
|
open(import("./string"));
|
|
3
4
|
{ ToString } :: import("./fmt");
|
|
4
5
|
{ fwrite, stdout, stderr, FILE } :: import("./libc/stdio");
|
|
@@ -7,9 +8,9 @@ Level :: enum(Trace, Debug, Info, Warn, Error);
|
|
|
7
8
|
impl(
|
|
8
9
|
Level,
|
|
9
10
|
ToString(
|
|
10
|
-
to_string : (fn(self :
|
|
11
|
+
to_string : (fn(ref(self) : Self) -> String)(
|
|
11
12
|
match(
|
|
12
|
-
self
|
|
13
|
+
self,
|
|
13
14
|
.Trace => String.from("TRACE"),
|
|
14
15
|
.Debug => String.from("DEBUG"),
|
|
15
16
|
.Info => String.from("INFO "),
|
|
@@ -60,7 +61,7 @@ _write_string :: (fn(s : String, dest : *(FILE)) -> unit)({
|
|
|
60
61
|
cond(
|
|
61
62
|
(bytes.len() > usize(0)) => {
|
|
62
63
|
ptr := bytes.ptr().unwrap();
|
|
63
|
-
fwrite(*(void)(ptr), usize(1), bytes.len(), dest);
|
|
64
|
+
unsafe(fwrite(*(void)(ptr), usize(1), bytes.len(), dest));
|
|
64
65
|
},
|
|
65
66
|
true => ()
|
|
66
67
|
);
|
|
@@ -79,11 +80,11 @@ log :: (fn(level : Level, msg : String) -> unit)({
|
|
|
79
80
|
.Stderr => stderr
|
|
80
81
|
);
|
|
81
82
|
// Write "[LEVEL] msg\n"
|
|
82
|
-
fwrite(*(void)(*(u8)("[")), usize(1), usize(1), dest);
|
|
83
|
+
unsafe(fwrite(*(void)(*(u8)("[")), usize(1), usize(1), dest));
|
|
83
84
|
_write_string(level_str, dest);
|
|
84
|
-
fwrite(*(void)(*(u8)("] ")), usize(1), usize(2), dest);
|
|
85
|
+
unsafe(fwrite(*(void)(*(u8)("] ")), usize(1), usize(2), dest));
|
|
85
86
|
_write_string(msg, dest);
|
|
86
|
-
fwrite(*(void)(*(u8)("\n")), usize(1), usize(1), dest);
|
|
87
|
+
unsafe(fwrite(*(void)(*(u8)("\n")), usize(1), usize(1), dest));
|
|
87
88
|
});
|
|
88
89
|
export(log);
|
|
89
90
|
// ============================================================================
|
package/std/net/addr.yo
CHANGED
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
// { IpAddr, SocketAddr } :: import "std/net/addr";
|
|
8
8
|
//
|
|
9
9
|
// addr := SocketAddr.new(IpAddr.loopback_v4(), u16(8080));
|
|
10
|
+
pragma(Pragma.AllowUnsafe);
|
|
10
11
|
open(import("../string"));
|
|
11
12
|
{ ToString } :: import("../fmt");
|
|
12
13
|
{ Writer } :: import("../fmt/writer");
|
|
@@ -40,7 +41,7 @@ impl(
|
|
|
40
41
|
val := u32(0);
|
|
41
42
|
i := usize(0);
|
|
42
43
|
while(runtime(i < bytes.len()), {
|
|
43
|
-
ch := bytes
|
|
44
|
+
ch := bytes(i);
|
|
44
45
|
cond(
|
|
45
46
|
(ch == _ASCII_DOT) => {
|
|
46
47
|
// '.' separator
|
|
@@ -145,10 +146,10 @@ impl(
|
|
|
145
146
|
self -> {
|
|
146
147
|
return(
|
|
147
148
|
match(
|
|
148
|
-
self
|
|
149
|
+
self,
|
|
149
150
|
.V4(a, b, c, d) => {
|
|
150
151
|
buf := Array(u8, usize(16)).fill(u8(0));
|
|
151
|
-
snprintf(*(char)(&(buf(usize(0)))), usize(16), "%d.%d.%d.%d", i32(a), i32(b), i32(c), i32(d));
|
|
152
|
+
unsafe(snprintf(*(char)(&(buf(usize(0)))), usize(16), "%d.%d.%d.%d", i32(a), i32(b), i32(c), i32(d)));
|
|
152
153
|
String.from_cstr(&(buf(usize(0)))).unwrap()
|
|
153
154
|
},
|
|
154
155
|
.V6(segs) => {
|
|
@@ -205,7 +206,7 @@ impl(
|
|
|
205
206
|
self -> {
|
|
206
207
|
ip_str := self.ip.to_string();
|
|
207
208
|
buf := Array(u8, usize(8)).fill(u8(0));
|
|
208
|
-
snprintf(*(char)(&(buf(usize(0)))), usize(8), "%d", i32(self.port));
|
|
209
|
+
unsafe(snprintf(*(char)(&(buf(usize(0)))), usize(8), "%d", i32(self.port)));
|
|
209
210
|
port_str := String.from_cstr(&(buf(usize(0)))).unwrap();
|
|
210
211
|
return(
|
|
211
212
|
match(
|
package/std/net/dns.yo
CHANGED
|
@@ -9,14 +9,15 @@
|
|
|
9
9
|
// { IpAddr } :: import "std/net/addr";
|
|
10
10
|
// { Exception } :: import "std/error";
|
|
11
11
|
//
|
|
12
|
-
// main :: (fn(io :
|
|
12
|
+
// main :: (fn(io : Io, exn : Exception) -> unit)({
|
|
13
13
|
// addrs := io.await(lookup_host(`localhost`, io), { io, exn });
|
|
14
14
|
// i := usize(0);
|
|
15
15
|
// while runtime((i < addrs.len())), {
|
|
16
|
-
// println(addrs
|
|
16
|
+
// println(addrs(i).to_string());
|
|
17
17
|
// i = (i + usize(1));
|
|
18
18
|
// };
|
|
19
19
|
// });
|
|
20
|
+
pragma(Pragma.AllowUnsafe);
|
|
20
21
|
{ GlobalAllocator } :: import("../allocator");
|
|
21
22
|
{ malloc, free } :: GlobalAllocator;
|
|
22
23
|
{ ArrayList } :: import("../collections/array_list");
|
|
@@ -24,14 +25,14 @@ open(import("../string"));
|
|
|
24
25
|
open(import("../fmt"));
|
|
25
26
|
{ NetError } :: import("./errors");
|
|
26
27
|
{ IpAddr, SocketAddr } :: import("./addr");
|
|
27
|
-
{ Error, AnyError, Exception,
|
|
28
|
+
{ Error, AnyError, Exception, IoExn } :: import("../error");
|
|
28
29
|
IO_dns :: import("../sys/dns");
|
|
29
30
|
{ AF_INET, AF_INET6 } :: import("../sys/socket");
|
|
30
31
|
// ============================================================================
|
|
31
32
|
// DNS lookup
|
|
32
33
|
// ============================================================================
|
|
33
34
|
/// Resolve a hostname to a list of IP addresses.
|
|
34
|
-
lookup_host :: (fn(host : String, io :
|
|
35
|
+
lookup_host :: (fn(host : String, io : Io) -> Impl(Future(ArrayList(IpAddr), IoExn)))(
|
|
35
36
|
io.async((e) => {
|
|
36
37
|
host_cstr_bytes := host.to_cstr();
|
|
37
38
|
host_cstr := host_cstr_bytes.ptr().unwrap();
|
|
@@ -82,13 +83,13 @@ lookup_host :: (fn(host : String, io : IO) -> Impl(Future(ArrayList(IpAddr), IOE
|
|
|
82
83
|
})
|
|
83
84
|
);
|
|
84
85
|
/// Resolve a hostname and port to a list of socket addresses.
|
|
85
|
-
resolve :: (fn(host : String, port : u16, io :
|
|
86
|
+
resolve :: (fn(host : String, port : u16, io : Io) -> Impl(Future(ArrayList(SocketAddr), IoExn)))(
|
|
86
87
|
io.async((e) => {
|
|
87
88
|
addrs := e.io.await(lookup_host(host, io), e);
|
|
88
89
|
result := ArrayList(SocketAddr).new();
|
|
89
90
|
i := usize(0);
|
|
90
91
|
while(runtime(i < addrs.len()), {
|
|
91
|
-
ip := addrs
|
|
92
|
+
ip := addrs(i);
|
|
92
93
|
result.push(SocketAddr.new(ip, port));
|
|
93
94
|
i = (i + usize(1));
|
|
94
95
|
});
|
package/std/net/errors.yo
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
//! Network error types.
|
|
2
2
|
// std/net/errors.yo - Network error type
|
|
3
3
|
//
|
|
4
|
-
// Higher-level network error that wraps
|
|
4
|
+
// Higher-level network error that wraps IoError with network-specific variants.
|
|
5
5
|
//
|
|
6
6
|
// Example:
|
|
7
7
|
// { NetError } :: import "std/net/errors";
|
|
8
8
|
open(import("../string"));
|
|
9
|
-
{
|
|
9
|
+
{ IoError } :: import("../sys/errors");
|
|
10
10
|
{ ToString } :: import("../fmt");
|
|
11
11
|
{ Error, AnyError, Exception } :: import("../error");
|
|
12
12
|
// ============================================================================
|
|
@@ -33,14 +33,14 @@ NetError :: enum(
|
|
|
33
33
|
/// DNS resolution failed.
|
|
34
34
|
DNSFailed(msg : String),
|
|
35
35
|
/// A wrapped lower-level I/O error.
|
|
36
|
-
|
|
36
|
+
Io(err : IoError),
|
|
37
37
|
/// An unclassified network error with a message.
|
|
38
38
|
Other(msg : String)
|
|
39
39
|
);
|
|
40
40
|
impl(
|
|
41
41
|
NetError,
|
|
42
|
-
/// Convert an `
|
|
43
|
-
from_io : (fn(err :
|
|
42
|
+
/// Convert an `IoError` into the corresponding `NetError` variant.
|
|
43
|
+
from_io : (fn(err : IoError) -> Self)(
|
|
44
44
|
match(
|
|
45
45
|
err,
|
|
46
46
|
.ConnectionRefused =>.ConnectionRefused,
|
|
@@ -51,7 +51,7 @@ impl(
|
|
|
51
51
|
.TimedOut =>.TimedOut,
|
|
52
52
|
.HostUnreachable =>.HostUnreachable,
|
|
53
53
|
.NetworkUnreachable =>.NetworkUnreachable,
|
|
54
|
-
_ =>.
|
|
54
|
+
_ =>.Io(err)
|
|
55
55
|
)
|
|
56
56
|
)
|
|
57
57
|
);
|
|
@@ -71,7 +71,7 @@ impl(
|
|
|
71
71
|
.HostUnreachable => String.from("host unreachable"),
|
|
72
72
|
.NetworkUnreachable => String.from("network unreachable"),
|
|
73
73
|
.DNSFailed(msg) => `DNS lookup failed: ${msg}`,
|
|
74
|
-
.
|
|
74
|
+
.Io(err) => err.to_string(),
|
|
75
75
|
.Other(msg) => msg
|
|
76
76
|
);
|
|
77
77
|
return(s);
|
|
@@ -87,7 +87,7 @@ impl(
|
|
|
87
87
|
check : (fn(result : i32, exn : Exception) -> i32)(
|
|
88
88
|
cond(
|
|
89
89
|
(result >= i32(0)) => result,
|
|
90
|
-
true => exn.throw(dyn(Self.from_io(
|
|
90
|
+
true => exn.throw(dyn(Self.from_io(IoError.from_errno(i32(0) - result))))
|
|
91
91
|
)
|
|
92
92
|
)
|
|
93
93
|
);
|