88/88 regression tests pass (+ffi-02-small-struct).
vendors/ffi_structs/ defines:
Vec2 — 8 B, two f32 — register-pair (float) ABI
Vec4f — 16 B, four f32 — homogeneous float aggregate (HFA) on AAPCS64
Both pass cleanly today: the sx-side struct declarations match the C
ABI for these float-only shapes, and the call-site / foreign-decl
type representations agree.
`#source` only (no `#include`) — c_import's type mapping rewrites
struct-typed params/returns to *void, which would link but pass
through the wrong ABI silently. The hand-written #foreign decls keep
sx's struct types end to end.
16-byte integer-only shapes (`{s64, s64}`, `{s32, s32, s32, s32}`)
discovered to trip the LLVM verifier (`[2 x i64]` vs `{ i64, i64 }`
mismatch between foreign decl and call site). Excluded from this
baseline; filed separately in the next commit as issue-0036.
19 lines
790 B
C
19 lines
790 B
C
// FFI struct-marshalling baselines. Two shapes covered today:
|
|
// Vec2 — 8 bytes (two f32) — register pair, float path
|
|
// Vec4f — 16 bytes (four f32) — homogeneous float aggregate (HFA)
|
|
// Declared here so the .c has a header to include; the sx side
|
|
// imports via `#source` only and re-declares the structs natively
|
|
// (c_import currently rewrites struct-typed params/returns to *void,
|
|
// which loses the by-value ABI).
|
|
|
|
typedef struct { float x; float y; } Vec2;
|
|
typedef struct { float x; float y; float z; float w; } Vec4f;
|
|
|
|
Vec2 ffi_vec2_make (float x, float y);
|
|
Vec2 ffi_vec2_swap (Vec2 v);
|
|
float ffi_vec2_sum (Vec2 v);
|
|
|
|
Vec4f ffi_vec4f_make (float x, float y, float z, float w);
|
|
Vec4f ffi_vec4f_reverse(Vec4f v);
|
|
float ffi_vec4f_sum (Vec4f v);
|