Files
sx/examples/1337-ffi-objc-call-11-bool-return.sx
agra d8076b9333 lang: rename signed integer types sN -> iN
Surface rename of the signed integer family: s1..s64 become i1..i64
(u1..u64, usize, isize unchanged). 'string' keeps the s-prefix arm in
name classification; width parsing moves to the i-prefix arm next to
isize.

Internal TypeId tags follow the surface (.s8/.s16/.s32/.s64 ->
.i8/.i16/.i32/.i64), as do mono-key mangle fragments (ptr_i64,
tu_i64_bool) and all display/diagnostic formatting (i{d}).

Migrated in the same sweep: stdlib + examples + issue repros + FFI C
companions (shared symbol names like ffi_id_i64), expected
stdout/stderr/ir snapshots, specs.md, readme.md, CLAUDE.md/AGENTS.md,
implementation_plan.md, docs/, issue writeups. Vendored stb_image and
historical flow state left untouched.

zig build test: 426/426; examples suite: 595/595.
2026-06-12 09:31:53 +03:00

49 lines
1.9 KiB
Plaintext

// Backfill for Phase 1D cluster 1.28 (PLAN-FFI.md): `#objc_call(bool)`
// against `BOOL`-returning selectors. Obj-C `BOOL` is single-byte on
// every Apple ABI we ship to (signed char on i386, native `bool` on
// arm64), so the slot shape is identical to `#objc_call(u8)` — this
// test is about the source-level type being meaningful, not a
// distinct ABI path.
//
// Two IMPs are installed: `yes_imp` returns true, `no_imp` returns
// false. Both are dispatched through `#objc_call(bool)` and the
// results are checked.
#import "modules/std.sx";
#import "modules/build.sx";
#import "modules/ffi/objc.sx";
yes_imp :: (self: *void, _cmd: *void) -> bool callconv(.c) { true }
no_imp :: (self: *void, _cmd: *void) -> bool callconv(.c) { false }
main :: () -> i32 {
inline if OS == .macos {
// Nil-recv: libobjc returns a zeroed slot, which decodes as false.
nil_b := #objc_call(bool)(null, "isEqual:");
print("nil bool = {}\n", nil_b);
ns_object := objc_getClass("NSObject".ptr);
my_cls := objc_allocateClassPair(ns_object, "SxBoolProbe".ptr, 0);
// BOOL type-encoded as `B` (C99 _Bool) in `B@:` — implicit
// (self: id, _cmd: SEL) return BOOL. Some toolchains prefer
// `c` (signed char) for BOOL on i386, but `B` is unambiguous
// on arm64 and works for runtime-registered IMPs.
sel_yes := sel_registerName("yes".ptr);
sel_no := sel_registerName("no".ptr);
class_addMethod(my_cls, sel_yes, xx yes_imp, "B@:".ptr);
class_addMethod(my_cls, sel_no, xx no_imp, "B@:".ptr);
objc_registerClassPair(my_cls);
instance := class_createInstance(my_cls, 0);
y := #objc_call(bool)(instance, "yes");
n := #objc_call(bool)(instance, "no");
print("yes = {}\n", y);
print("no = {}\n", n);
}
inline if OS != .macos {
print("skipped (not macos)\n");
}
0
}