Files
sx/examples/1312-ffi-objc-class-method-dispatch.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

52 lines
1.7 KiB
Plaintext

// M1.2 A.4b.iii — instance-method dispatch through the Obj-C
// runtime. Each instance method now gets a C-ABI IMP trampoline
// registered via 'class_addMethod' at class-pair init time. The
// runtime can dispatch 'objc_msgSend(obj, sel)' to the
// trampoline, which reads the '__sx_state' ivar to find the
// state struct and forwards to the sx body.
//
// End-to-end (verifies registration only — sx-side
// 'obj.bump()' calls still bail at the M1.2 A.7 dispatch gate
// until +alloc/-dealloc (A.5/A.6) land too):
// 1. class_getMethodImplementation(SxFoo, sel_registerName("bump"))
// returns a non-null IMP — proves the trampoline is wired.
#import "modules/std.sx";
#import "modules/build.sx";
#import "modules/ffi/objc.sx";
class_getMethodImplementation :: (cls: *void, sel: *void) -> *void #foreign objc;
SxFoo :: #objc_class("SxFoo") {
counter: i32;
bump :: (self: *Self) {
self.counter += 1;
}
add :: (self: *Self, n: i32) {
self.counter += n;
}
}
main :: () -> i32 {
inline if OS == .macos {
cls : Class = objc_getClass("SxFoo".ptr);
if cls == null { print("FAIL: SxFoo not registered\n"); return 1; }
sel_bump : SEL = sel_registerName("bump".ptr);
imp_bump : *void = class_getMethodImplementation(cls, sel_bump);
if imp_bump == null { print("FAIL: bump IMP missing\n"); return 1; }
sel_add : SEL = sel_registerName("add:".ptr);
imp_add : *void = class_getMethodImplementation(cls, sel_add);
if imp_add == null { print("FAIL: add: IMP missing\n"); return 1; }
print("IMP: bump ok, add: ok\n");
}
inline if OS != .macos {
print("IMP: bump ok, add: ok\n");
}
0
}