For each bodied instance method on a sx-defined #objc_class,
emit a C-callconv trampoline function '__<Cls>_<method>_imp':
void __SxFoo_bump_imp(ptr obj, ptr _cmd, ...user_args) {
ivar = load @__SxFoo_state_ivar
state = object_getIvar(obj, ivar)
call @SxFoo.bump(__sx_default_context, state, ...user_args)
ret
}
The trampoline bridges the Obj-C runtime's IMP calling convention
('id self, SEL _cmd, ...args' as C ABI) to the sx body's
default-callconv shape ('__sx_ctx ptr, state ptr, ...user_args').
Implicit context comes from '&__sx_default_context'; the body
keeps its sx-side personality intact and can use 'self.field'
through the substituted state-struct pointer (M1.2 A.2b + A.3).
New helpers in lower.zig:
- 'getObjcObjectGetIvarFid' lazily declares object_getIvar.
- 'emitObjcDefinedClassImps' + 'emitObjcDefinedClassImp' walk the
cache and synthesise each trampoline.
- 'lookupGlobalIdByName' for finding the per-class ivar handle
global. Linear scan — same N-is-small rationale as the other
Obj-C caches.
Dead code at this commit: the trampolines exist in the module
but no class_addMethod call registers them with the runtime.
'objc_msgSend(obj, sel_bump)' would still fall through to the
parent class (NSObject 'doesNotRecognizeSelector:') today.
A.4b.iii wires up class_addMethod in emit_llvm's class-pair-init
constructor — that's when the trampolines come alive.
142's IR snapshot refreshed to show the trampoline.
173 example tests pass. zig build test green.