Files
sx/examples/concurrency/1800-concurrency-naked-asm.sx
agra 66bdc70bf1 test: group examples into per-category folders
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.
2026-06-21 14:41:34 +03:00

26 lines
1.1 KiB
Plaintext

// Stream B1 (fibers) — `abi(.naked)` emits a naked function end-to-end.
//
// An `abi(.naked)` function has no calling-convention prologue/epilogue/frame
// and no implicit `__sx_ctx`: its body is a single asm block that sets the
// return register and emits its own `ret`. This is the substrate the per-arch
// fiber context-switch is built on (design §4.6) — a `.c` epilogue would
// restore SP from the wrong stack across a switch (SP-in ≠ SP-out by design).
//
// Lowered via LLVM's `naked` function attribute: the body is emitted verbatim
// (the inline asm + its own `ret`) with NO frame setup; the IR shows
// `attributes #N = { naked noinline nounwind }` and the bare asm. aarch64-pinned
// (the asm body is per-arch); runs end-to-end here (exit 42), ir-only on a
// mismatch. See the x86_64 sibling 1802. NOTE: the `.ir` proves the `naked`
// keyword + asm emitted, NOT register-save correctness (that's the B1.3
// switch-stress harness's job).
answer :: () -> i64 abi(.naked) {
asm volatile {
#string ASM
mov x0, #42
ret
ASM
};
}
main :: () -> i64 { return answer(); }