Files
sx/examples/1343-ffi-objc-dsl-03-multi-keyword.sx
agra a68f7c2e64 refactor(ffi-linkage): Phase 7.2 — migrate 13xx ffi-objc examples #foreign→extern
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).
2026-06-15 06:53:33 +03:00

35 lines
1.1 KiB
Plaintext

// Phase 3 step 3.0: multi-keyword selector mangling. The sx method
// name is split on `_`; each piece becomes a keyword with a trailing
// `:`. `combine_and(a, b)` → `combine:and:` — two keywords, two args.
//
// 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";
SxProbeMultiKeyword :: #objc_class("SxProbeMultiKeyword") extern {
combine_and :: (self: *Self, a: i32, b: i32) -> i32;
}
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);
cls := objc_allocateClassPair(ns_object, "SxProbeMultiKeyword".ptr, 0);
sel := sel_registerName("combine:and:".ptr);
class_addMethod(cls, sel, xx combine_imp, "i@:ii".ptr);
objc_registerClassPair(cls);
inst : *SxProbeMultiKeyword = xx class_createInstance(cls, 0);
n := inst.combine_and(7, 42);
print("combine_and(7, 42) = {}\n", n);
}
inline if OS != .macos {
print("skipped (not macos)\n");
}
0
}