Move examples/*.sx and their expected/ snapshots into per-category subfolders (examples/<category>/...). Folder = leading filename token, with ffi-objc/ffi-jni kept whole; filenames are unchanged. The corpus runner and LSP sweep now discover each category's expected/ dir, while issues/ stays flat. Example 1058's repo-root-relative companion import is made file-relative. Path strings embedded in 164 snapshots were regenerated (path-only changes). Test-layout docs in CLAUDE.md updated.
17 lines
699 B
Plaintext
17 lines
699 B
Plaintext
// Atomic($T).swap — atomic exchange (LLVM atomicrmw xchg): store the new value,
|
|
// return the OLD one. Stream A (atomics) A.3. Single-thread.
|
|
// Covers swap at BOTH comptime (#run) and runtime — they must agree.
|
|
#import "modules/std.sx";
|
|
#import "modules/std/atomic.sx";
|
|
|
|
c_swap :: () -> i64 { a := Atomic(i64).init(7); old := a.swap(42, .seq_cst); return old * 100 + a.load(.seq_cst); }
|
|
G_SWAP :: #run c_swap(); // 742 (old 7, now 42)
|
|
|
|
main :: () {
|
|
a := Atomic(i64).init(7);
|
|
old := a.swap(42, .acq_rel);
|
|
print("swap old: {}\n", old); // 7
|
|
print("swap now: {}\n", a.load(.acquire)); // 42
|
|
print("comptime swap: {}\n", G_SWAP); // 742 (matches runtime)
|
|
}
|