diff --git a/examples/ffi-jni-env-02-lexical-direct.sx b/examples/ffi-jni-env-02-lexical-direct.sx new file mode 100644 index 0000000..60ed654 --- /dev/null +++ b/examples/ffi-jni-env-02-lexical-direct.sx @@ -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; +} diff --git a/tests/expected/ffi-jni-env-02-lexical-direct.exit b/tests/expected/ffi-jni-env-02-lexical-direct.exit new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/tests/expected/ffi-jni-env-02-lexical-direct.exit @@ -0,0 +1 @@ +1 diff --git a/tests/expected/ffi-jni-env-02-lexical-direct.txt b/tests/expected/ffi-jni-env-02-lexical-direct.txt new file mode 100644 index 0000000..ff683ca --- /dev/null +++ b/tests/expected/ffi-jni-env-02-lexical-direct.txt @@ -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