ffi: drop static keyword on foreign-class methods; param type discriminates
`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`.
This commit is contained in:
@@ -1,16 +1,16 @@
|
||||
// Phase 2 step 2.3 (PLAN-FFI.md): xfail then green for the `static`
|
||||
// method body item inside a `#jni_class` declaration.
|
||||
// Phase 2 step 2.3 (PLAN-FFI.md): xfail then green for class/static
|
||||
// method declarations inside a `#jni_class` body.
|
||||
//
|
||||
// `static name :: (args...) -> Ret;` declares a class/static method —
|
||||
// no implicit `self`, dispatched via `GetStaticMethodID` / `CallStatic*`
|
||||
// at lowering time (Phase 2.12). Step 2.3 extends `parseJniClassDecl`
|
||||
// to recognise the `static` prefix and mark the resulting
|
||||
// `JniMethodDecl` with `is_static = true`.
|
||||
// Instance vs class method is determined by the first param's TYPE:
|
||||
// `(self: *Self, ...)` ⇒ instance, anything else (here, `(n: s32)`)
|
||||
// ⇒ class method, dispatched via `GetStaticMethodID` /
|
||||
// `CallStatic*` at lowering time (Phase 2.12). No explicit `static`
|
||||
// keyword; the param shape carries the signal.
|
||||
|
||||
#import "modules/std.sx";
|
||||
|
||||
Math :: #foreign #jni_class("java/lang/Math") {
|
||||
static abs :: (n: s32) -> s32;
|
||||
abs :: (n: s32) -> s32; // no `self: *Self` → class method
|
||||
}
|
||||
|
||||
main :: () -> s32 {
|
||||
|
||||
@@ -13,7 +13,7 @@ Bundle :: #foreign #jni_class("android/os/Bundle") { }
|
||||
JContext :: #foreign #jni_class("android/content/Context") { }
|
||||
|
||||
SurfaceView :: #foreign #jni_class("android/view/SurfaceView") {
|
||||
static new :: (ctx: *JContext) -> *Self;
|
||||
new :: (ctx: *JContext) -> *Self; // no `self: *Self` → class method
|
||||
}
|
||||
|
||||
g_held_view : *void = null;
|
||||
|
||||
@@ -17,11 +17,12 @@
|
||||
|
||||
NSObject :: #foreign #objc_class("NSObject") {
|
||||
// `+(Class)class` — niladic, name verbatim, selector = "class".
|
||||
// Returns the class object itself.
|
||||
static class :: () -> *void;
|
||||
// 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".
|
||||
static description :: () -> *void;
|
||||
description :: () -> *void;
|
||||
}
|
||||
|
||||
main :: () -> s32 {
|
||||
|
||||
Reference in New Issue
Block a user