Files
sx/examples/1334-ffi-objc-call-08-multi-keyword.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

42 lines
1.5 KiB
Plaintext

// Phase 1 step 1.10 (PLAN-FFI.md): multi-keyword Obj-C selectors
// through `#objc_call`. Selector mangling matches clang's: every
// `:` in the source-level selector becomes a `_` in the symbol
// name of the cached SEL slot (so `initWithFrame:options:` →
// `OBJC_SELECTOR_REFERENCES_initWithFrame_options_`).
//
// The selector is opaque text to the lowering — no codegen change
// needed beyond Phase 1.6's variadic argument list. This test
// pins that the round-trip works end-to-end via class_addMethod
// + a real IMP that consumes both keyword args.
#import "modules/std.sx";
#import "modules/build.sx";
#import "modules/ffi/objc.sx";
combine_imp :: (self: *void, _cmd: *void, a: i32, b: i32) -> i32 callconv(.c) {
a * 100 + b
}
main :: () -> i32 {
inline if OS == .macos {
ns_object := objc_getClass("NSObject".ptr);
my_cls := objc_allocateClassPair(ns_object, "SxComboProbe".ptr, 0);
// Two-keyword selector: `combine:and:`.
// Method type encoding: i@:ii → returns int, implicit (self, _cmd),
// takes two ints. (`i` = int, `@` = id, `:` = SEL.)
sel := sel_registerName("combine:and:".ptr);
ok := class_addMethod(my_cls, sel, xx combine_imp, "i@:ii".ptr);
print("addMethod = {}\n", ok);
objc_registerClassPair(my_cls);
instance := class_createInstance(my_cls, 0);
r := #objc_call(i32)(instance, "combine:and:", 7, 42);
print("combine(7, 42) = {}\n", r);
}
inline if OS != .macos {
print("skipped (not macos)\n");
}
0
}