Files
sx/examples/ffi-jni-main-03-ctor.sx
agra 56414407fc 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`.
2026-05-25 16:32:32 +03:00

31 lines
1.1 KiB
Plaintext

// `Alias.new(args)` constructor dispatch on a `#foreign #jni_class`
// (chess-on-Pixel migration, R.6). The sx-side `static new :: (...) ->
// *Self;` member lowers to JNI `FindClass + GetMethodID("<init>", sig)
// + NewObject(env, clazz, mid, args...)`.
//
// This smoke instantiates a `SurfaceView` from inside the Activity's
// `onCreate` body — chess's render surface starts the same way.
#import "modules/std.sx";
#import "modules/compiler.sx";
Bundle :: #foreign #jni_class("android/os/Bundle") { }
JContext :: #foreign #jni_class("android/content/Context") { }
SurfaceView :: #foreign #jni_class("android/view/SurfaceView") {
new :: (ctx: *JContext) -> *Self; // no `self: *Self` → class method
}
g_held_view : *void = null;
SxApp :: #jni_main #jni_class("co/swipelab/sxjnictor/SxApp") {
onCreate :: (self: *Self, b: *Bundle) {
super.onCreate(b);
ctx : *JContext = xx self; // Activity IS a JContext (extends JContext).
view := SurfaceView.new(ctx);
g_held_view = xx view; // keep alive so LLVM doesn't DCE the construction.
}
}
main :: () -> s32 { 0; }