Files
sx/examples/1330-ffi-objc-call-04-primitive-returns.sx
agra 12bf61a9fc std: restructure step 3 — ffi/ moves, build.sx, math dir spelling, fixtures
- objc.sx, objc_block.sx (from std/) + sdl3/opengl/raylib/stb/stb_truetype/
  wasm vendor bindings (from modules/ root) -> modules/ffi/
- std/uikit.sx deleted: platform/uikit.sx already declares UIApplicationMain
  and imports objc; '#framework "UIKit"' cannot live in a file imported on
  macOS targets (unconditional link directive, UIKit is iOS-only), so the
  three iOS-only examples carry the 3-line glue inline. 1607/1608/1616 also
  un-rotted (dead ns_string -> 'xx "..."' Into conversions, callconv(.c)
  msgSend fn-ptrs) — all three build for ios-sim/ios again.
- math/math.sx -> math/scalar.sx; one spelling '#import "modules/math"'
  everywhere (4 pinned IR snapshots regenerated: dir import adds Vec2/Mat4
  to the type tables).
- compiler.sx -> build.sx (imports, CLAUDE.md bundling table, specs.md).
- testpkg/ + test_c.sx -> tests/fixtures/ (resolve CWD-relative from repo
  root, same as vendors/).
- library-internal imports use full modules/... paths (std.sx tail,
  platform/bundle.sx, fixtures).
2026-06-11 08:37:22 +03:00

42 lines
1.7 KiB
Plaintext

// Phase 1 step 1.6 (PLAN-FFI.md): non-void return shapes through
// `#objc_call`. Each return type triggers a distinct LLVMBuildCall2
// function-type combination so emit_llvm's per-call-site lowering
// has to pick the right ABI per call.
//
// We exercise both nil-recv (libobjc guarantees zero result for
// every shape) and real-recv paths so the ABI is verified beyond
// "the runtime no-oped the call."
#import "modules/std.sx";
#import "modules/build.sx";
#import "modules/ffi/objc.sx";
main :: () -> s32 {
inline if OS == .macos {
// ── Nil-recv quick smoke ───────────────────────────────────
nil_cls := #objc_call(*void)(null, "class");
print("nil class = {}\n", nil_cls == null);
nil_n := #objc_call(s64)(null, "hash");
print("nil hash = {}\n", nil_n);
// ── Real-recv: NSObject ────────────────────────────────────
// *void return: [NSObject class] -> NSObject's metaclass (non-null,
// and conveniently == self when sent to the class itself).
ns_object := objc_getClass("NSObject".ptr);
meta := #objc_call(*void)(ns_object, "class");
print("meta non-null = {}\n", meta != null);
// s64 return: [obj hash] returns NSUInteger. On the NSObject
// class itself the value is implementation-defined but stable
// within a process — pinning it as non-zero is enough for ABI
// verification.
h := #objc_call(s64)(ns_object, "hash");
print("hash non-zero = {}\n", h != 0);
}
inline if OS != .macos {
print("skipped (not macos)\n");
}
0
}