ffi 3.2 C2: migrate uikit.sx Notifications + Bundle cluster
Second cluster: NSNotification, NSBundle, NSNotificationCenter move
from `#objc_call(T)(recv, "sel:", args)` to declarative
`#foreign #objc_class("Cls") { ... }` blocks.
Classes declared (alongside the C1 Foundation utility group):
- NSNotification → userInfo (instance, returns *NSDictionary)
- NSBundle → mainBundle (class), resourcePath (instance)
- NSNotificationCenter → defaultCenter (class),
addObserver_selector_name_object (instance)
The 4-keyword `addObserver:selector:name:object:` selector derives
from the underscore-separated sx name via the default mangling rule
— no `#selector` override needed.
Cleanup wins:
- `objc_getClass("NSBundle")` and `objc_getClass("NSNotificationCenter")`
call sites gone — class slots now populated by emit_llvm's
`__sx_objc_class_init` constructor.
- `userInfo`'s return type is `*NSDictionary` directly, so the
previous `*void → *NSDictionary` cast at the keyboard-frame
callsite collapses.
166/166 tests; chess builds clean on macOS + iOS + Android via
`sx build main.sx`.
This commit is contained in:
@@ -553,8 +553,15 @@ foreign-class pointer at the dispatch site. The `objc_getClass(...)`
|
|||||||
calls for these classes are gone — the class slot is now populated
|
calls for these classes are gone — the class slot is now populated
|
||||||
by emit_llvm's `__sx_objc_class_init` constructor (Phase 3.1).
|
by emit_llvm's `__sx_objc_class_init` constructor (Phase 3.1).
|
||||||
|
|
||||||
|
Phase 3.2 C2 landed: notifications + bundle cluster migrated.
|
||||||
|
NSNotification (`userInfo`), NSBundle (`mainBundle`, `resourcePath`),
|
||||||
|
NSNotificationCenter (`defaultCenter`, `addObserver_selector_name_object`)
|
||||||
|
declared as `#foreign #objc_class` blocks. The 4-keyword
|
||||||
|
`addObserver:selector:name:object:` selector derives cleanly from
|
||||||
|
the underscore-separated sx name (`addObserver_selector_name_object`).
|
||||||
|
|
||||||
Open work:
|
Open work:
|
||||||
- **Phase 3 step 3.2 — C2..C5** — uikit.sx migration, one cluster
|
- **Phase 3 step 3.2 — C3..C5** — uikit.sx migration, one cluster
|
||||||
per commit, chess regression after each.
|
per commit, chess regression after each.
|
||||||
test for the default-mangling table. Escape hatch for selectors
|
test for the default-mangling table. Escape hatch for selectors
|
||||||
that don't fit the underscore-split rule (e.g. `tableView_
|
that don't fit the underscore-split rule (e.g. `tableView_
|
||||||
|
|||||||
@@ -84,6 +84,22 @@ NSSet :: #foreign #objc_class("NSSet") {
|
|||||||
anyObject :: (self: *Self) -> *void;
|
anyObject :: (self: *Self) -> *void;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ── Notifications + Bundle (Phase 3.2 C2) ──────────────────────────────
|
||||||
|
|
||||||
|
NSNotification :: #foreign #objc_class("NSNotification") {
|
||||||
|
userInfo :: (self: *Self) -> *NSDictionary;
|
||||||
|
}
|
||||||
|
|
||||||
|
NSBundle :: #foreign #objc_class("NSBundle") {
|
||||||
|
mainBundle :: () -> *NSBundle;
|
||||||
|
resourcePath :: (self: *Self) -> *void;
|
||||||
|
}
|
||||||
|
|
||||||
|
NSNotificationCenter :: #foreign #objc_class("NSNotificationCenter") {
|
||||||
|
defaultCenter :: () -> *NSNotificationCenter;
|
||||||
|
addObserver_selector_name_object :: (self: *Self, observer: *void, sel: *void, name: *void, obj: *void);
|
||||||
|
}
|
||||||
|
|
||||||
// GLenum constants for renderbuffer/framebuffer setup that aren't in opengl.sx's
|
// GLenum constants for renderbuffer/framebuffer setup that aren't in opengl.sx's
|
||||||
// loader path (they live on the framework's symbol table directly).
|
// loader path (they live on the framework's symbol table directly).
|
||||||
GL_RENDERBUFFER :u32: 0x8D41;
|
GL_RENDERBUFFER :u32: 0x8D41;
|
||||||
@@ -304,9 +320,8 @@ uikit_refresh_safe_insets :: (plat: *UIKitPlatform) {
|
|||||||
|
|
||||||
uikit_chdir_to_bundle :: () {
|
uikit_chdir_to_bundle :: () {
|
||||||
inline if OS != .ios { return; }
|
inline if OS != .ios { return; }
|
||||||
NSBundle := objc_getClass("NSBundle".ptr);
|
bundle := NSBundle.mainBundle();
|
||||||
bundle := #objc_call(*void)(NSBundle, "mainBundle");
|
rsrc := bundle.resourcePath();
|
||||||
rsrc := #objc_call(*void)(bundle, "resourcePath");
|
|
||||||
if rsrc == null { return; }
|
if rsrc == null { return; }
|
||||||
chdir(c_string(rsrc));
|
chdir(c_string(rsrc));
|
||||||
}
|
}
|
||||||
@@ -388,9 +403,9 @@ uikit_keyboard_will_change_frame :: (self: *void, _cmd: *void, notification: *vo
|
|||||||
if g_uikit_plat == null { return; }
|
if g_uikit_plat == null { return; }
|
||||||
plat := g_uikit_plat;
|
plat := g_uikit_plat;
|
||||||
|
|
||||||
user_info_raw := #objc_call(*void)(notification, "userInfo");
|
notif : *NSNotification = xx notification;
|
||||||
if user_info_raw == null { return; }
|
user_info := notif.userInfo();
|
||||||
user_info : *NSDictionary = xx user_info_raw;
|
if user_info == null { return; }
|
||||||
|
|
||||||
end_value_raw := user_info.objectForKey(ns_string("UIKeyboardFrameEndUserInfoKey".ptr));
|
end_value_raw := user_info.objectForKey(ns_string("UIKeyboardFrameEndUserInfoKey".ptr));
|
||||||
if end_value_raw == null { return; }
|
if end_value_raw == null { return; }
|
||||||
@@ -494,9 +509,8 @@ uikit_did_finish_launching :: (self: *void, _cmd: *void, app: *void, opts: *void
|
|||||||
|
|
||||||
uikit_subscribe_keyboard_notifications :: (delegate: *void) {
|
uikit_subscribe_keyboard_notifications :: (delegate: *void) {
|
||||||
inline if OS != .ios { return; }
|
inline if OS != .ios { return; }
|
||||||
NSNotificationCenter := objc_getClass("NSNotificationCenter".ptr);
|
center := NSNotificationCenter.defaultCenter();
|
||||||
center := #objc_call(*void)(NSNotificationCenter, "defaultCenter");
|
center.addObserver_selector_name_object(
|
||||||
#objc_call(void)(center, "addObserver:selector:name:object:",
|
|
||||||
delegate,
|
delegate,
|
||||||
sel_registerName("sxKeyboardWillChangeFrame:".ptr),
|
sel_registerName("sxKeyboardWillChangeFrame:".ptr),
|
||||||
ns_string("UIKeyboardWillChangeFrameNotification".ptr),
|
ns_string("UIKeyboardWillChangeFrameNotification".ptr),
|
||||||
|
|||||||
Reference in New Issue
Block a user