Class PanamaTypedFunc
java.lang.Object
ai.tegmentum.wasmtime4j.panama.PanamaTypedFunc
- All Implemented Interfaces:
ai.tegmentum.wasmtime4j.func.TypedFunc,AutoCloseable
Panama FFI implementation of typed WebAssembly function calls.
This class provides zero-cost typed function calls by caching type information and avoiding runtime type checking on each invocation. This is a significant performance optimization for frequently called functions with known signatures.
TypedFunc wraps a regular WasmFunction with compile-time type information, enabling:
- Zero-cost abstraction - no runtime type checking overhead
- Direct memory layout matching between Java and WebAssembly
- Optimized parameter/result marshalling for common type combinations
- Type safety through signature validation at creation time
Supported signatures:
- () -> void
- (i32) -> i32
- (i32, i32) -> i32
- (i32, i32, i32) -> i32
- (i64) -> i64
- (i64, i64) -> i64
- (i64, i64, i64) -> i64
- (f32) -> f32
- (f32, f32) -> f32
- (f64) -> f64
- (f64, f64) -> f64
Example usage:
WasmFunction func = instance.getFunction("add").get();
PanamaTypedFunc typedAdd = new PanamaTypedFunc(func, "ii->i");
int result = typedAdd.callI32I32ToI32(10, 20); // Returns 30
- Since:
- 1.0.0
-
Nested Class Summary
Nested classes/interfaces inherited from interface ai.tegmentum.wasmtime4j.func.TypedFunc
ai.tegmentum.wasmtime4j.func.TypedFunc.TypedFunctionSupport -
Constructor Summary
ConstructorsConstructorDescriptionPanamaTypedFunc(ai.tegmentum.wasmtime4j.WasmFunction func, String signature) Creates a typed function wrapper from a regular function. -
Method Summary
Modifier and TypeMethodDescriptionfloatcallF32F32F32ToF32(float param1, float param2, float param3) Calls a typed function with (f32, f32, f32) parameters and f32 result: (f32, f32, f32) -> f32.floatcallF32F32ToF32(float param1, float param2) Calls a typed function with (f32, f32) parameters and f32 result: (f32, f32) -> f32.floatcallF32I32ToF32(float param1, int param2) Calls a typed function with (f32, i32) parameters and f32 result: (f32, i32) -> f32.floatcallF32ToF32(float param) Calls a typed function with f32 parameter and f32 result: (f32) -> f32.doublecallF64F64F64ToF64(double param1, double param2, double param3) Calls a typed function with (f64, f64, f64) parameters and f64 result: (f64, f64, f64) -> f64.doublecallF64F64ToF64(double param1, double param2) Calls a typed function with (f64, f64) parameters and f64 result: (f64, f64) -> f64.doublecallF64ToF64(double param) Calls a typed function with f64 parameter and f64 result: (f64) -> f64.floatcallI32F32ToF32(int param1, float param2) Calls a typed function with (i32, f32) parameters and f32 result: (i32, f32) -> f32.intcallI32I32I32ToI32(int param1, int param2, int param3) Calls a typed function with (i32, i32, i32) parameters and i32 result: (i32, i32, i32) -> i32.intcallI32I32ToI32(int param1, int param2) Calls a typed function with (i32, i32) parameters and i32 result: (i32, i32) -> i32.longcallI32I32ToI64(int param1, int param2) Calls a typed function with (i32, i32) parameters and i64 result: (i32, i32) -> i64.voidcallI32I32ToVoid(int param1, int param2) Calls a typed function with (i32, i32) parameters and void result: (i32, i32) -> ().intcallI32ToI32(int param) Calls a typed function with i32 parameter and i32 result: (i32) -> i32.voidcallI32ToVoid(int param) Calls a typed function with i32 parameter and void result: (i32) -> ().longcallI64I64I64ToI64(long param1, long param2, long param3) Calls a typed function with (i64, i64, i64) parameters and i64 result: (i64, i64, i64) -> i64.longcallI64I64ToI64(long param1, long param2) Calls a typed function with (i64, i64) parameters and i64 result: (i64, i64) -> i64.voidcallI64I64ToVoid(long param1, long param2) Calls a typed function with (i64, i64) parameters and void result: (i64, i64) -> ().intcallI64ToI32(long param) Calls a typed function with i64 parameter and i32 result: (i64) -> i32.longcallI64ToI64(long param) Calls a typed function with i64 parameter and i64 result: (i64) -> i64.voidcallI64ToVoid(long param) Calls a typed function with i64 parameter and void result: (i64) -> ().voidCalls a typed function with no parameters and no return value: () -> ().voidclose()Closes the typed function and releases resources.ai.tegmentum.wasmtime4j.WasmFunctionMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface ai.tegmentum.wasmtime4j.func.TypedFunc
callAsyncF32F32F32ToF32, callAsyncF32F32ToF32, callAsyncF32I32ToF32, callAsyncF32ToF32, callAsyncF64F64F64ToF64, callAsyncF64F64ToF64, callAsyncF64ToF64, callAsyncI32F32ToF32, callAsyncI32I32I32ToI32, callAsyncI32I32ToI32, callAsyncI32I32ToI64, callAsyncI32I32ToVoid, callAsyncI32ToI32, callAsyncI32ToVoid, callAsyncI64I64I64ToI64, callAsyncI64I64ToI64, callAsyncI64I64ToVoid, callAsyncI64ToI32, callAsyncI64ToI64, callAsyncI64ToVoid, callAsyncVoidToVoid
-
Constructor Details
-
PanamaTypedFunc
Creates a typed function wrapper from a regular function.The signature string encodes parameter and return types:
- "i" = i32
- "I" = i64
- "f" = f32
- "F" = f64
- "v" = void/none
Format: "params->results", e.g., "ii->i" for (i32, i32) -> i32
- Parameters:
func- the function to wrap with type informationsignature- the signature string encoding parameter and return types- Throws:
IllegalArgumentException- if function or signature is invalid
-
-
Method Details
-
callVoidToVoid
public void callVoidToVoid() throws ai.tegmentum.wasmtime4j.exception.WasmExceptionCalls a typed function with no parameters and no return value: () -> ().- Specified by:
callVoidToVoidin interfaceai.tegmentum.wasmtime4j.func.TypedFunc- Throws:
ai.tegmentum.wasmtime4j.exception.WasmException- if function execution fails
-
callI32ToVoid
public void callI32ToVoid(int param) throws ai.tegmentum.wasmtime4j.exception.WasmException Calls a typed function with i32 parameter and void result: (i32) -> ().- Specified by:
callI32ToVoidin interfaceai.tegmentum.wasmtime4j.func.TypedFunc- Parameters:
param- the i32 parameter- Throws:
ai.tegmentum.wasmtime4j.exception.WasmException- if function execution fails
-
callI32I32ToVoid
public void callI32I32ToVoid(int param1, int param2) throws ai.tegmentum.wasmtime4j.exception.WasmException Calls a typed function with (i32, i32) parameters and void result: (i32, i32) -> ().- Specified by:
callI32I32ToVoidin interfaceai.tegmentum.wasmtime4j.func.TypedFunc- Parameters:
param1- the first i32 parameterparam2- the second i32 parameter- Throws:
ai.tegmentum.wasmtime4j.exception.WasmException- if function execution fails
-
callI64ToVoid
public void callI64ToVoid(long param) throws ai.tegmentum.wasmtime4j.exception.WasmException Calls a typed function with i64 parameter and void result: (i64) -> ().- Specified by:
callI64ToVoidin interfaceai.tegmentum.wasmtime4j.func.TypedFunc- Parameters:
param- the i64 parameter- Throws:
ai.tegmentum.wasmtime4j.exception.WasmException- if function execution fails
-
callI64I64ToVoid
public void callI64I64ToVoid(long param1, long param2) throws ai.tegmentum.wasmtime4j.exception.WasmException Calls a typed function with (i64, i64) parameters and void result: (i64, i64) -> ().- Specified by:
callI64I64ToVoidin interfaceai.tegmentum.wasmtime4j.func.TypedFunc- Parameters:
param1- the first i64 parameterparam2- the second i64 parameter- Throws:
ai.tegmentum.wasmtime4j.exception.WasmException- if function execution fails
-
callI32ToI32
public int callI32ToI32(int param) throws ai.tegmentum.wasmtime4j.exception.WasmException Calls a typed function with i32 parameter and i32 result: (i32) -> i32.- Specified by:
callI32ToI32in interfaceai.tegmentum.wasmtime4j.func.TypedFunc- Parameters:
param- the i32 parameter- Returns:
- the i32 result
- Throws:
ai.tegmentum.wasmtime4j.exception.WasmException- if function execution fails
-
callI32I32ToI32
public int callI32I32ToI32(int param1, int param2) throws ai.tegmentum.wasmtime4j.exception.WasmException Calls a typed function with (i32, i32) parameters and i32 result: (i32, i32) -> i32.- Specified by:
callI32I32ToI32in interfaceai.tegmentum.wasmtime4j.func.TypedFunc- Parameters:
param1- the first i32 parameterparam2- the second i32 parameter- Returns:
- the i32 result
- Throws:
ai.tegmentum.wasmtime4j.exception.WasmException- if function execution fails
-
callI64ToI64
public long callI64ToI64(long param) throws ai.tegmentum.wasmtime4j.exception.WasmException Calls a typed function with i64 parameter and i64 result: (i64) -> i64.- Specified by:
callI64ToI64in interfaceai.tegmentum.wasmtime4j.func.TypedFunc- Parameters:
param- the i64 parameter- Returns:
- the i64 result
- Throws:
ai.tegmentum.wasmtime4j.exception.WasmException- if function execution fails
-
callI64I64ToI64
public long callI64I64ToI64(long param1, long param2) throws ai.tegmentum.wasmtime4j.exception.WasmException Calls a typed function with (i64, i64) parameters and i64 result: (i64, i64) -> i64.- Specified by:
callI64I64ToI64in interfaceai.tegmentum.wasmtime4j.func.TypedFunc- Parameters:
param1- the first i64 parameterparam2- the second i64 parameter- Returns:
- the i64 result
- Throws:
ai.tegmentum.wasmtime4j.exception.WasmException- if function execution fails
-
callF32ToF32
public float callF32ToF32(float param) throws ai.tegmentum.wasmtime4j.exception.WasmException Calls a typed function with f32 parameter and f32 result: (f32) -> f32.- Specified by:
callF32ToF32in interfaceai.tegmentum.wasmtime4j.func.TypedFunc- Parameters:
param- the f32 parameter- Returns:
- the f32 result
- Throws:
ai.tegmentum.wasmtime4j.exception.WasmException- if function execution fails
-
callF64ToF64
public double callF64ToF64(double param) throws ai.tegmentum.wasmtime4j.exception.WasmException Calls a typed function with f64 parameter and f64 result: (f64) -> f64.- Specified by:
callF64ToF64in interfaceai.tegmentum.wasmtime4j.func.TypedFunc- Parameters:
param- the f64 parameter- Returns:
- the f64 result
- Throws:
ai.tegmentum.wasmtime4j.exception.WasmException- if function execution fails
-
callF32F32ToF32
public float callF32F32ToF32(float param1, float param2) throws ai.tegmentum.wasmtime4j.exception.WasmException Calls a typed function with (f32, f32) parameters and f32 result: (f32, f32) -> f32.- Specified by:
callF32F32ToF32in interfaceai.tegmentum.wasmtime4j.func.TypedFunc- Parameters:
param1- the first f32 parameterparam2- the second f32 parameter- Returns:
- the f32 result
- Throws:
ai.tegmentum.wasmtime4j.exception.WasmException- if function execution fails
-
callF64F64ToF64
public double callF64F64ToF64(double param1, double param2) throws ai.tegmentum.wasmtime4j.exception.WasmException Calls a typed function with (f64, f64) parameters and f64 result: (f64, f64) -> f64.- Specified by:
callF64F64ToF64in interfaceai.tegmentum.wasmtime4j.func.TypedFunc- Parameters:
param1- the first f64 parameterparam2- the second f64 parameter- Returns:
- the f64 result
- Throws:
ai.tegmentum.wasmtime4j.exception.WasmException- if function execution fails
-
callI32I32I32ToI32
public int callI32I32I32ToI32(int param1, int param2, int param3) throws ai.tegmentum.wasmtime4j.exception.WasmException Calls a typed function with (i32, i32, i32) parameters and i32 result: (i32, i32, i32) -> i32.- Specified by:
callI32I32I32ToI32in interfaceai.tegmentum.wasmtime4j.func.TypedFunc- Parameters:
param1- the first i32 parameterparam2- the second i32 parameterparam3- the third i32 parameter- Returns:
- the i32 result
- Throws:
ai.tegmentum.wasmtime4j.exception.WasmException- if function execution fails
-
callI64I64I64ToI64
public long callI64I64I64ToI64(long param1, long param2, long param3) throws ai.tegmentum.wasmtime4j.exception.WasmException Calls a typed function with (i64, i64, i64) parameters and i64 result: (i64, i64, i64) -> i64.- Specified by:
callI64I64I64ToI64in interfaceai.tegmentum.wasmtime4j.func.TypedFunc- Parameters:
param1- the first i64 parameterparam2- the second i64 parameterparam3- the third i64 parameter- Returns:
- the i64 result
- Throws:
ai.tegmentum.wasmtime4j.exception.WasmException- if function execution fails
-
getSignature
- Specified by:
getSignaturein interfaceai.tegmentum.wasmtime4j.func.TypedFunc
-
getFunction
public ai.tegmentum.wasmtime4j.WasmFunction getFunction()- Specified by:
getFunctionin interfaceai.tegmentum.wasmtime4j.func.TypedFunc
-
callF32F32F32ToF32
public float callF32F32F32ToF32(float param1, float param2, float param3) throws ai.tegmentum.wasmtime4j.exception.WasmException Calls a typed function with (f32, f32, f32) parameters and f32 result: (f32, f32, f32) -> f32.- Specified by:
callF32F32F32ToF32in interfaceai.tegmentum.wasmtime4j.func.TypedFunc- Parameters:
param1- the first f32 parameterparam2- the second f32 parameterparam3- the third f32 parameter- Returns:
- the f32 result
- Throws:
ai.tegmentum.wasmtime4j.exception.WasmException- if function execution fails
-
callF64F64F64ToF64
public double callF64F64F64ToF64(double param1, double param2, double param3) throws ai.tegmentum.wasmtime4j.exception.WasmException Calls a typed function with (f64, f64, f64) parameters and f64 result: (f64, f64, f64) -> f64.- Specified by:
callF64F64F64ToF64in interfaceai.tegmentum.wasmtime4j.func.TypedFunc- Parameters:
param1- the first f64 parameterparam2- the second f64 parameterparam3- the third f64 parameter- Returns:
- the f64 result
- Throws:
ai.tegmentum.wasmtime4j.exception.WasmException- if function execution fails
-
callI32I32ToI64
public long callI32I32ToI64(int param1, int param2) throws ai.tegmentum.wasmtime4j.exception.WasmException Calls a typed function with (i32, i32) parameters and i64 result: (i32, i32) -> i64.- Specified by:
callI32I32ToI64in interfaceai.tegmentum.wasmtime4j.func.TypedFunc- Parameters:
param1- the first i32 parameterparam2- the second i32 parameter- Returns:
- the i64 result
- Throws:
ai.tegmentum.wasmtime4j.exception.WasmException- if function execution fails
-
callI64ToI32
public int callI64ToI32(long param) throws ai.tegmentum.wasmtime4j.exception.WasmException Calls a typed function with i64 parameter and i32 result: (i64) -> i32.- Specified by:
callI64ToI32in interfaceai.tegmentum.wasmtime4j.func.TypedFunc- Parameters:
param- the i64 parameter- Returns:
- the i32 result
- Throws:
ai.tegmentum.wasmtime4j.exception.WasmException- if function execution fails
-
callI32F32ToF32
public float callI32F32ToF32(int param1, float param2) throws ai.tegmentum.wasmtime4j.exception.WasmException Calls a typed function with (i32, f32) parameters and f32 result: (i32, f32) -> f32.- Specified by:
callI32F32ToF32in interfaceai.tegmentum.wasmtime4j.func.TypedFunc- Parameters:
param1- the i32 parameterparam2- the f32 parameter- Returns:
- the f32 result
- Throws:
ai.tegmentum.wasmtime4j.exception.WasmException- if function execution fails
-
callF32I32ToF32
public float callF32I32ToF32(float param1, int param2) throws ai.tegmentum.wasmtime4j.exception.WasmException Calls a typed function with (f32, i32) parameters and f32 result: (f32, i32) -> f32.- Specified by:
callF32I32ToF32in interfaceai.tegmentum.wasmtime4j.func.TypedFunc- Parameters:
param1- the f32 parameterparam2- the i32 parameter- Returns:
- the f32 result
- Throws:
ai.tegmentum.wasmtime4j.exception.WasmException- if function execution fails
-
close
public void close()Closes the typed function and releases resources.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceai.tegmentum.wasmtime4j.func.TypedFunc
-