ffi 2.16b xfail: omitted env in #jni_call inside #jni_env

`#jni_call(void)(target, "name", "sig")` (3 args before the first
string literal) should work inside an enclosing `#jni_env(env) { ... }`
scope, picking up the env from the block's value directly. Today's
lowering expects 4+ args and errors with "#jni_call requires env,
target, method name, and signature".

The make-green follow-up adds a lowering-side env stack maintained
across the `#jni_env` body walk, and a disambiguation in
`lowerJniCall` that detects "env omitted" via the position of the
first string-literal arg (method name at index 1 → omitted; at index
2 → explicit env).
This commit is contained in:
agra
2026-05-20 10:47:07 +03:00
parent 5bd2c84bb6
commit e463385404
3 changed files with 32 additions and 0 deletions

View File

@@ -0,0 +1,30 @@
// Phase 2 step 2.16b (PLAN-FFI.md): xfail then green for the
// lexical-direct env resolution inside a `#jni_env` scope.
//
// `#jni_call(T)(target, "name", "sig", args...)` — three args before
// the first string literal — has the env omitted. The lowering walks
// the in-progress AST visit stack to find the enclosing `#jni_env(env)`
// block and uses that env value directly as the IR-level env arg.
// No thread-local read, no per-call lookup; env stays register-
// resident across loop bodies (the hot-path optimisation).
//
// Today's lower expects 4+ args and errors when called with 3.
#import "modules/std.sx";
g_should_call : bool = false;
unused_jni :: (env: *void, target: *void) {
#jni_env(env) {
// Omitted env — env comes from the enclosing #jni_env scope.
#jni_call(void)(target, "noop", "()V");
}
}
main :: () -> s32 {
if g_should_call {
unused_jni(null, null);
}
print("ok\n");
0;
}

View File

@@ -0,0 +1 @@
1

View File

@@ -0,0 +1 @@
/Users/agra/projects/sx/examples/ffi-jni-env-02-lexical-direct.sx: error: #jni_call requires env, target, method name, and signature