`static name :: ...` was redundant — instance methods always declare `self: *Self` as their first param by convention. The parser now derives `is_static` from the first param's TYPE: if it's `*Self` the method is an instance method; anything else (including no params at all) is a class method. Removes a token from the surface, keeps the dispatch behavior identical. The receiver param's NAME doesn't matter — only its type. Calling the first param `this`, `me`, `receiver`, etc. is fine as long as the type is `*Self`. This mirrors how the rest of sx handles receiver dispatch. Migration of every site that used the keyword: - `library/modules/platform/android.sx` — `SurfaceView.new(ctx)`. - `examples/ffi-jni-class-03-static.sx` — `Math.abs(n)`. - `examples/ffi-jni-main-03-ctor.sx` — `SurfaceView.new(ctx)` in the `#jni_main` body. - `examples/ffi-objc-dsl-05-static.sx` — NSObject's `.class()` / `.description()`. 164/164 example tests; chess clean on macOS / iOS sim / Android via `tools/verify-step.sh`.
44 lines
1.6 KiB
Plaintext
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/compiler.sx";
|
|
|
|
NSObject :: #foreign #objc_class("NSObject") {
|
|
// `+(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 :: () -> s32 {
|
|
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;
|
|
}
|