ffi #jni_main: sx-side super.method(args) dispatch via CallNonvirtual<T>Method
Inside a `#jni_main` (or any sx-defined `#jni_class`) bodied method,
`super.method(args)` lowers to JNI's nonvirtual dispatch against the
parent class resolved via `#extends` (default `android.app.Activity`).
- lower.zig: tracks `current_foreign_class` + `current_foreign_method`
around each `synthesizeJniMainStub` body; pushes the JNIEnv* arg
onto the lexical `#jni_env` stack so omitted-env JNI calls inside
the body see env without a wrapper. New `lowerSuperCall` handles
the `super.method(args)` receiver pattern: derives parent path,
reuses the enclosing method's signature when names match (the
common `super.<override>(args)` case), or looks up the method on
the parent class declared as `#foreign #jni_class`.
- inst.zig: `JniMsgSend` gains `is_nonvirtual: bool` and
`parent_class_path: ?[]const u8` — the dispatch tag + super class
foreign path. Mutually exclusive with `is_static`.
- emit_llvm.zig: new `CallNonvirtual<T>Method` vtable slots + a
fourth dispatch arm. Resolves the parent jclass via
`FindClass(env, parent_path)` (per-call; caching is follow-up),
then `GetMethodID(env, parent_cls, name, sig)`, then
`CallNonvirtual<T>Method(env, obj, parent_cls, mid, args...)`.
Disassembly on the smoke confirms the chain:
`ldr [env+0x30]` (FindClass) → `ldr [env+0x108]` (GetMethodID) →
`ldr [env+0x2d8]` (CallNonvirtualVoidMethod) with `(env, self,
parent_cls, mid, bundle)`.
132 host / 5 cross / zig build test all green. The slice unblocks
Activity lifecycle overrides (onCreate, onResume, onPause) calling
their required `super.<method>(args)` without raw `#jni_call`
boilerplate.
This commit is contained in:
24
examples/ffi-jni-main-02-super.sx
Normal file
24
examples/ffi-jni-main-02-super.sx
Normal file
@@ -0,0 +1,24 @@
|
||||
// `super.method(args)` dispatch inside a `#jni_main` Activity body
|
||||
// (chess-on-Pixel migration, R.6). The override of a lifecycle method
|
||||
// like `onCreate` needs to invoke the parent's `onCreate` so the
|
||||
// Android runtime's setup completes (`SuperNotCalledException`
|
||||
// otherwise) — the sx-side body calls `super.onCreate(b)` and the
|
||||
// compiler lowers it to JNI `CallNonvirtualVoidMethod` against the
|
||||
// parent class declared via `#extends`.
|
||||
//
|
||||
// No `#extends` here → defaults to `android.app.Activity`. The smoke
|
||||
// is compile-only — runtime correctness is verified by APK install
|
||||
// + on-device launch, which is the chess deploy.
|
||||
|
||||
#import "modules/std.sx";
|
||||
#import "modules/compiler.sx";
|
||||
|
||||
Bundle :: #foreign #jni_class("android/os/Bundle") { }
|
||||
|
||||
SxApp :: #jni_main #jni_class("co/swipelab/sxjnimainsuper/SxApp") {
|
||||
onCreate :: (self: *Self, b: *Bundle) {
|
||||
super.onCreate(b);
|
||||
}
|
||||
}
|
||||
|
||||
main :: () -> s32 { 0; }
|
||||
Reference in New Issue
Block a user