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:
agra
2026-05-20 16:57:30 +03:00
parent d43f21f39e
commit d946e3d577
7 changed files with 288 additions and 2 deletions

View File

@@ -36,6 +36,10 @@ TUPLES=(
# #jni_class(...)` decl must continue to lower + link cleanly for
# android even without an APK build (compile-only check).
"android|examples/ffi-jni-main-01-emit.sx"
# `super.method(args)` dispatch: lowers to JNI CallNonvirtualVoidMethod
# against the parent class (Activity by default). Compile-only check
# — runtime correctness is verified by on-device chess deploy.
"android|examples/ffi-jni-main-02-super.sx"
)
PASS=0

View File

@@ -0,0 +1 @@
0

View File

@@ -0,0 +1 @@