Files
sx/examples/1345-ffi-objc-dsl-05-static.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

44 lines
1.6 KiB
Plaintext

// Phase 3 step 3.1 (PLAN-FFI.md): static call `Cls.class_method(args)`
// on an `#objc_class` alias lowers to `objc_msg_send` against the class
// object (loaded once per module via `objc_getClass` and cached). The
// selector is derived by the same default mangling as Phase 3.0
// (`stringWithUTF8String_(s)` → "stringWithUTF8String:").
//
// Mirrors JNI's static-dispatch surface (`Alias.new(...)` etc.); the
// lowering disambiguates static vs instance by looking at
// `method.is_static` on the foreign-class member.
//
// Uses NSObject because the cached class slot is populated by a
// constructor at module-load — runtime-created test classes wouldn't
// exist yet when `objc_getClass` runs. NSObject is always available
// on macOS via libobjc.
#import "modules/std.sx";
#import "modules/build.sx";
NSObject :: #objc_class("NSObject") extern {
// `+(Class)class` — niladic, name verbatim, selector = "class".
// Returns the class object itself. No `self: *Self` first param ⇒
// class method (sx parser keys on the param TYPE).
class :: () -> *void;
// `+(NSString *)description` on the class returns a description
// string. Niladic, selector = "description".
description :: () -> *void;
}
main :: () -> i32 {
inline if OS == .macos {
c := NSObject.class();
if c != null {
print("class non-null\n");
}
d := NSObject.description();
if d != null {
print("description non-null\n");
}
}
inline if OS != .macos {
print("skipped (not macos)\n");
}
0
}