Files
sx/vendors/ffi_structs/ffi_structs.c
agra 84b3fc8866 ffi 0.2: small struct baseline (Vec2, Vec4f) by-value through #foreign
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.
2026-05-19 11:21:16 +03:00

30 lines
495 B
C

#include "ffi_structs.h"
Vec2 ffi_vec2_make(float x, float y) {
Vec2 r = { x, y };
return r;
}
Vec2 ffi_vec2_swap(Vec2 v) {
Vec2 r = { v.y, v.x };
return r;
}
float ffi_vec2_sum(Vec2 v) {
return v.x + v.y;
}
Vec4f ffi_vec4f_make(float x, float y, float z, float w) {
Vec4f r = { x, y, z, w };
return r;
}
Vec4f ffi_vec4f_reverse(Vec4f v) {
Vec4f r = { v.w, v.z, v.y, v.x };
return r;
}
float ffi_vec4f_sum(Vec4f v) {
return v.x + v.y + v.z + v.w;
}