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.
29 lines
1.1 KiB
Plaintext
29 lines
1.1 KiB
Plaintext
// export function (FFI-linkage stream, Phase 2): define an sx function with
|
||
// the bare `export` linkage modifier — external linkage + C ABI + no sx ctx —
|
||
// so a companion C translation unit can call back into it by its plain symbol
|
||
// name. The C side (`#source`) declares `sx_square` as a normal `extern int`
|
||
// and calls it; sx `main` drives the C side via `call_sx_square`. Mirrors the
|
||
// import-direction `extern` examples (1223–1225) for the define direction.
|
||
//
|
||
// Without `export`, an sx-defined fn is `internal` linkage + carries the
|
||
// implicit `__sx_ctx` slot, so the C object can neither resolve nor correctly
|
||
// call the symbol — this is the gap `export` fills.
|
||
#import "modules/std.sx";
|
||
|
||
#import c {
|
||
#include "1226-ffi-export-fn.h";
|
||
#source "1226-ffi-export-fn.c";
|
||
};
|
||
|
||
// sx-defined, exported to C: external linkage + C ABI + no implicit ctx.
|
||
sx_square :: (n: i32) -> i32 export {
|
||
return n * n;
|
||
}
|
||
|
||
main :: () -> i32 {
|
||
// call_sx_square (C) calls back into sx_square, adds 1.
|
||
print("call_sx_square(6) = {}\n", call_sx_square(6));
|
||
print("call_sx_square(9) = {}\n", call_sx_square(9));
|
||
0
|
||
}
|