18 obj-c examples migrated (1308/1311-1317/1319/1320/1321/1341-1347): import
runtime classes '#foreign #objc_class("X") {' → '#objc_class("X") extern {'
(prefix→postfix) + fn/comment '#foreign'→'extern'. No 13xx snapshot asserts on
'foreign' text → all behavior-preserving; empty snapshot diff, corpus-validated.
Per the keep-list policy: KEPT identity-#foreign tests 1306/1318 (filename
ffi-*-foreign*); LEFT comment-only #foreign in the extern/export test files
1332/1348/1349 (no decls). Bare defined #objc_class examples (no #foreign) untouched
— not a purge target. Suite green (647 corpus / 444 unit, 0 failed).
36 lines
1.1 KiB
Plaintext
36 lines
1.1 KiB
Plaintext
// Phase 3 step 3.0: one-arg selector mangling. `addObject(o)` derives
|
|
// `addObject:` — the sx method name becomes the keyword, a single
|
|
// trailing `:` for the single arg. Selector arity (count of `:`) must
|
|
// equal sx-side arity excluding self.
|
|
//
|
|
// Pre-3.0: bails at lower.zig with the Phase 3/4 diagnostic.
|
|
#import "modules/std.sx";
|
|
#import "modules/build.sx";
|
|
#import "modules/ffi/objc.sx";
|
|
|
|
SxProbeOneArg :: #objc_class("SxProbeOneArg") extern {
|
|
addObject :: (self: *Self, val: i32) -> i32;
|
|
}
|
|
|
|
addObject_imp :: (self: *void, _cmd: *void, val: i32) -> i32 callconv(.c) {
|
|
val * 2
|
|
}
|
|
|
|
main :: () -> i32 {
|
|
inline if OS == .macos {
|
|
ns_object := objc_getClass("NSObject".ptr);
|
|
cls := objc_allocateClassPair(ns_object, "SxProbeOneArg".ptr, 0);
|
|
sel := sel_registerName("addObject:".ptr);
|
|
class_addMethod(cls, sel, xx addObject_imp, "i@:i".ptr);
|
|
objc_registerClassPair(cls);
|
|
|
|
inst : *SxProbeOneArg = xx class_createInstance(cls, 0);
|
|
n := inst.addObject(21);
|
|
print("addObject(21) = {}\n", n);
|
|
}
|
|
inline if OS != .macos {
|
|
print("skipped (not macos)\n");
|
|
}
|
|
0
|
|
}
|