ffi 1.20: #jni_call(f64) → CallDoubleMethod (slot 58) — make-green

One-line addition to the switch: `.f64 => Jni.CallDoubleMethod`.
First non-integer JNI return type; same lazy-cache + dispatch
infrastructure from 1.17 handles the rest.

IR snapshot updated: `ret double undef` replaced by the full
sequence through vtable slot 58 keyed on `("getValue", "()D")`.
This commit is contained in:
agra
2026-05-19 22:32:40 +03:00
parent 5e8145af93
commit ca4ba7589c
2 changed files with 28 additions and 1 deletions

View File

@@ -1243,6 +1243,7 @@ pub const LLVMEmitter = struct {
.void => Jni.CallVoidMethod,
.s32 => Jni.CallIntMethod,
.s64 => Jni.CallLongMethod,
.f64 => Jni.CallDoubleMethod,
else => {
self.mapRef(c.LLVMGetUndef(self.toLLVMType(instruction.ty)));
return;

View File

@@ -3,6 +3,8 @@
@g_should_call = internal global i1 false
@str = private unnamed_addr constant [9 x i8] c"getValue\00", align 1
@str.1 = private unnamed_addr constant [4 x i8] c"()D\00", align 1
@SX_JNI_CLS_getValue____D = internal global ptr null
@SX_JNI_MID_getValue____D = internal global ptr null
@str.2 = private unnamed_addr constant [4 x i8] c"ok\0A\00", align 1
@str.3 = private unnamed_addr constant [1 x i8] zeroinitializer, align 1
@@ -205,7 +207,31 @@ entry:
store ptr %1, ptr %allocaN, align 8
%load = load ptr, ptr %alloca, align 8
%loadN = load ptr, ptr %allocaN, align 8
ret double undef
%jni.ifs = load ptr, ptr %load, align 8
%jni.cached.mid = load ptr, ptr @SX_JNI_MID_getValue____D, align 8
%jni.is.cached = icmp ne ptr %jni.cached.mid, null
br i1 %jni.is.cached, label %jni.cont, label %jni.miss
jni.miss: ; preds = %entry
%2 = getelementptr inbounds ptr, ptr %jni.ifs, i32 31
%jni.GetObjectClass = load ptr, ptr %2, align 8
%jni.cls = call ptr %jni.GetObjectClass(ptr %load, ptr %loadN)
%3 = getelementptr inbounds ptr, ptr %jni.ifs, i32 21
%jni.NewGlobalRef = load ptr, ptr %3, align 8
%jni.global.cls = call ptr %jni.NewGlobalRef(ptr %load, ptr %jni.cls)
store ptr %jni.global.cls, ptr @SX_JNI_CLS_getValue____D, align 8
%4 = getelementptr inbounds ptr, ptr %jni.ifs, i32 33
%jni.GetMethodID = load ptr, ptr %4, align 8
%jni.fresh.mid = call ptr %jni.GetMethodID(ptr %load, ptr %jni.global.cls, ptr @str, ptr @str.1)
store ptr %jni.fresh.mid, ptr @SX_JNI_MID_getValue____D, align 8
br label %jni.cont
jni.cont: ; preds = %jni.miss, %entry
%jni.mid = phi ptr [ %jni.cached.mid, %entry ], [ %jni.fresh.mid, %jni.miss ]
%5 = getelementptr inbounds ptr, ptr %jni.ifs, i32 58
%jni.callfn = load ptr, ptr %5, align 8
%jni.ret = call double %jni.callfn(ptr %load, ptr %loadN, ptr %jni.mid)
ret double %jni.ret
}
; Function Attrs: nounwind