test(ffi-linkage): xfail export fn called from C via AOT (Phase 2.0)
Phase 2 of the extern/export stream verifies `export` (define + expose a
C-ABI sx symbol) end-to-end. C->sx-by-name linkage cannot work under the
corpus's `sx run` JIT mode — a JIT-resident symbol is invisible to a
dlopen'd C dylib's flat-namespace lookup — so this lands a new AOT
execution mode for the corpus: an `expected/<name>.aot` marker switches an
example from JIT `sx run` to a `sx build` + execute flow, linking the sx
object with its C `#source` companions into a native binary.
example/1226 defines `sx_square :: (n: i32) -> i32 export { ... }` and a
companion .c that declares `extern int sx_square(int)` and calls it back.
RED: with `export` not yet lowered, the AOT link fails with an undefined
`_sx_square` (the define path still emits it `internal` + with an implicit
ctx slot, and lazy lowering leaves an uncalled export fn as a bodiless
declare). Phase 2.1 greens it.
Also retires the standalone `tests/run_examples.sh` runner — `zig build
test` (src/corpus_run.test.zig) is now the sole corpus runner, and the
shell mirror would have needed its own AOT-mode port to stay in lockstep.
verify-step.sh drops its redundant step (zig build test already runs the
corpus); CLAUDE.md documents the `.aot` mode.
This commit is contained in:
8
examples/1226-ffi-export-fn.c
Normal file
8
examples/1226-ffi-export-fn.c
Normal file
@@ -0,0 +1,8 @@
|
||||
#include "1226-ffi-export-fn.h"
|
||||
|
||||
// Defined on the sx side via `export` — a plain C-ABI symbol, no sx context.
|
||||
extern int sx_square(int n);
|
||||
|
||||
int call_sx_square(int n) {
|
||||
return sx_square(n) + 1;
|
||||
}
|
||||
7
examples/1226-ffi-export-fn.h
Normal file
7
examples/1226-ffi-export-fn.h
Normal file
@@ -0,0 +1,7 @@
|
||||
#ifndef SX_EXPORT_FN_H
|
||||
#define SX_EXPORT_FN_H
|
||||
|
||||
// Calls back into the sx-exported `sx_square` and adds 1.
|
||||
int call_sx_square(int n);
|
||||
|
||||
#endif
|
||||
28
examples/1226-ffi-export-fn.sx
Normal file
28
examples/1226-ffi-export-fn.sx
Normal file
@@ -0,0 +1,28 @@
|
||||
// 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
|
||||
}
|
||||
0
examples/expected/1226-ffi-export-fn.aot
Normal file
0
examples/expected/1226-ffi-export-fn.aot
Normal file
1
examples/expected/1226-ffi-export-fn.exit
Normal file
1
examples/expected/1226-ffi-export-fn.exit
Normal file
@@ -0,0 +1 @@
|
||||
0
|
||||
0
examples/expected/1226-ffi-export-fn.stderr
Normal file
0
examples/expected/1226-ffi-export-fn.stderr
Normal file
2
examples/expected/1226-ffi-export-fn.stdout
Normal file
2
examples/expected/1226-ffi-export-fn.stdout
Normal file
@@ -0,0 +1,2 @@
|
||||
call_sx_square(6) = 37
|
||||
call_sx_square(9) = 82
|
||||
Reference in New Issue
Block a user