ffi 1.18: lock in undef shape for #jni_call(s32)

Adds `examples/ffi-jni-call-04-jint-return.sx` exercising
`#jni_call(s32)(env, target, "getCount", "()I")` inside a runtime-
reachable but never-invoked helper (`g_should_call` stays false, so
the dereferences don't fire). Today the emit_llvm switch falls
through to `LLVMGetUndef` for any non-void return — the IR snapshot
captures that placeholder.

The next commit adds the `.s32 => 49` (CallIntMethod) arm. The
snapshot will update to show the full GetObjectClass → GetMethodID →
CallIntMethod sequence (reusing the slot interning landed in 1.17,
since `("getCount", "()I")` is a fresh literal pair).
This commit is contained in:
agra
2026-05-19 22:26:03 +03:00
parent 0d883b412d
commit 1d7ea72dc8
4 changed files with 297 additions and 0 deletions

View File

@@ -0,0 +1,26 @@
// Phase 1 step 1.18 (PLAN-FFI.md): `#jni_call(s32)` (jint return).
// Today the lowering for any non-void return drops to `LLVMGetUndef`
// — the IR snapshot captures that placeholder. Step 1.18-fix wires
// the `.s32 => 49` (`CallIntMethod`) arm and the snapshot updates to
// show the full GetObjectClass + GetMethodID + CallIntMethod
// sequence (using the cache machinery landed in 1.17).
//
// Runtime: unreachable. Same `g_should_call` global pattern as
// `ffi-jni-call-03` — keeps `read_int` alive so the IR snapshot has
// the JNI lowering visible, but the dereferences never execute.
#import "modules/std.sx";
g_should_call : bool = false;
read_int :: (env: *void, target: *void) -> s32 {
#jni_call(s32)(env, target, "getCount", "()I");
}
main :: () -> s32 {
if g_should_call {
_ := read_int(null, null);
}
print("ok\n");
0;
}