Class PanamaComponentTypedFunc

java.lang.Object
ai.tegmentum.wasmtime4j.panama.PanamaComponentTypedFunc
All Implemented Interfaces:
ai.tegmentum.wasmtime4j.component.ComponentTypedFunc, AutoCloseable

public final class PanamaComponentTypedFunc extends Object implements ai.tegmentum.wasmtime4j.component.ComponentTypedFunc
Panama FFI implementation of typed WebAssembly Component Model 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 Component Model functions with known signatures.

ComponentTypedFunc wraps a regular ComponentFunc with compile-time type information, enabling:

  • Zero-cost abstraction - no runtime type checking overhead
  • Direct primitive parameter passing without ComponentVal boxing
  • Optimized parameter/result marshalling for common type combinations
  • Type safety through signature validation at creation time

Supported signatures use Component Model type names:

  • "s32" = signed 32-bit integer
  • "s64" = signed 64-bit integer
  • "f32" = 32-bit float
  • "f64" = 64-bit float
  • "string" = UTF-8 string
  • "bool" = boolean
  • "void" = no value

Example usage:


 ComponentFunc func = instance.getFunc("add");
 PanamaComponentTypedFunc typedAdd = new PanamaComponentTypedFunc(func, "s32,s32->s32");
 int result = typedAdd.callS32S32ToS32(10, 20); // Returns 30
 
Since:
1.0.0
  • Constructor Details

    • PanamaComponentTypedFunc

      public PanamaComponentTypedFunc(ai.tegmentum.wasmtime4j.component.ComponentFunc func, String signature)
      Creates a typed component function wrapper from a regular component function.

      The signature string encodes parameter and return types using Component Model names:

      • "s8", "s16", "s32", "s64" = signed integers
      • "u8", "u16", "u32", "u64" = unsigned integers
      • "f32", "f64" = floating point
      • "bool" = boolean
      • "string" = string
      • "void" or empty = no value

      Format: "params->results", e.g., "s32,s32->s32" for (s32, s32) -> s32

      Parameters:
      func - the component function to wrap with type information
      signature - 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.WasmException
      Specified by:
      callVoidToVoid in interface ai.tegmentum.wasmtime4j.component.ComponentTypedFunc
      Throws:
      ai.tegmentum.wasmtime4j.exception.WasmException
    • callS32ToVoid

      public void callS32ToVoid(int param) throws ai.tegmentum.wasmtime4j.exception.WasmException
      Specified by:
      callS32ToVoid in interface ai.tegmentum.wasmtime4j.component.ComponentTypedFunc
      Throws:
      ai.tegmentum.wasmtime4j.exception.WasmException
    • callS32S32ToVoid

      public void callS32S32ToVoid(int param1, int param2) throws ai.tegmentum.wasmtime4j.exception.WasmException
      Specified by:
      callS32S32ToVoid in interface ai.tegmentum.wasmtime4j.component.ComponentTypedFunc
      Throws:
      ai.tegmentum.wasmtime4j.exception.WasmException
    • callS64ToVoid

      public void callS64ToVoid(long param) throws ai.tegmentum.wasmtime4j.exception.WasmException
      Specified by:
      callS64ToVoid in interface ai.tegmentum.wasmtime4j.component.ComponentTypedFunc
      Throws:
      ai.tegmentum.wasmtime4j.exception.WasmException
    • callS64S64ToVoid

      public void callS64S64ToVoid(long param1, long param2) throws ai.tegmentum.wasmtime4j.exception.WasmException
      Specified by:
      callS64S64ToVoid in interface ai.tegmentum.wasmtime4j.component.ComponentTypedFunc
      Throws:
      ai.tegmentum.wasmtime4j.exception.WasmException
    • callStringToVoid

      public void callStringToVoid(String param) throws ai.tegmentum.wasmtime4j.exception.WasmException
      Specified by:
      callStringToVoid in interface ai.tegmentum.wasmtime4j.component.ComponentTypedFunc
      Throws:
      ai.tegmentum.wasmtime4j.exception.WasmException
    • callS32ToS32

      public int callS32ToS32(int param) throws ai.tegmentum.wasmtime4j.exception.WasmException
      Specified by:
      callS32ToS32 in interface ai.tegmentum.wasmtime4j.component.ComponentTypedFunc
      Throws:
      ai.tegmentum.wasmtime4j.exception.WasmException
    • callS32S32ToS32

      public int callS32S32ToS32(int param1, int param2) throws ai.tegmentum.wasmtime4j.exception.WasmException
      Specified by:
      callS32S32ToS32 in interface ai.tegmentum.wasmtime4j.component.ComponentTypedFunc
      Throws:
      ai.tegmentum.wasmtime4j.exception.WasmException
    • callS32S32S32ToS32

      public int callS32S32S32ToS32(int param1, int param2, int param3) throws ai.tegmentum.wasmtime4j.exception.WasmException
      Specified by:
      callS32S32S32ToS32 in interface ai.tegmentum.wasmtime4j.component.ComponentTypedFunc
      Throws:
      ai.tegmentum.wasmtime4j.exception.WasmException
    • callS64ToS32

      public int callS64ToS32(long param) throws ai.tegmentum.wasmtime4j.exception.WasmException
      Specified by:
      callS64ToS32 in interface ai.tegmentum.wasmtime4j.component.ComponentTypedFunc
      Throws:
      ai.tegmentum.wasmtime4j.exception.WasmException
    • callS64ToS64

      public long callS64ToS64(long param) throws ai.tegmentum.wasmtime4j.exception.WasmException
      Specified by:
      callS64ToS64 in interface ai.tegmentum.wasmtime4j.component.ComponentTypedFunc
      Throws:
      ai.tegmentum.wasmtime4j.exception.WasmException
    • callS64S64ToS64

      public long callS64S64ToS64(long param1, long param2) throws ai.tegmentum.wasmtime4j.exception.WasmException
      Specified by:
      callS64S64ToS64 in interface ai.tegmentum.wasmtime4j.component.ComponentTypedFunc
      Throws:
      ai.tegmentum.wasmtime4j.exception.WasmException
    • callS64S64S64ToS64

      public long callS64S64S64ToS64(long param1, long param2, long param3) throws ai.tegmentum.wasmtime4j.exception.WasmException
      Specified by:
      callS64S64S64ToS64 in interface ai.tegmentum.wasmtime4j.component.ComponentTypedFunc
      Throws:
      ai.tegmentum.wasmtime4j.exception.WasmException
    • callS32S32ToS64

      public long callS32S32ToS64(int param1, int param2) throws ai.tegmentum.wasmtime4j.exception.WasmException
      Specified by:
      callS32S32ToS64 in interface ai.tegmentum.wasmtime4j.component.ComponentTypedFunc
      Throws:
      ai.tegmentum.wasmtime4j.exception.WasmException
    • callF32ToF32

      public float callF32ToF32(float param) throws ai.tegmentum.wasmtime4j.exception.WasmException
      Specified by:
      callF32ToF32 in interface ai.tegmentum.wasmtime4j.component.ComponentTypedFunc
      Throws:
      ai.tegmentum.wasmtime4j.exception.WasmException
    • callF32F32ToF32

      public float callF32F32ToF32(float param1, float param2) throws ai.tegmentum.wasmtime4j.exception.WasmException
      Specified by:
      callF32F32ToF32 in interface ai.tegmentum.wasmtime4j.component.ComponentTypedFunc
      Throws:
      ai.tegmentum.wasmtime4j.exception.WasmException
    • callF32F32F32ToF32

      public float callF32F32F32ToF32(float param1, float param2, float param3) throws ai.tegmentum.wasmtime4j.exception.WasmException
      Specified by:
      callF32F32F32ToF32 in interface ai.tegmentum.wasmtime4j.component.ComponentTypedFunc
      Throws:
      ai.tegmentum.wasmtime4j.exception.WasmException
    • callF64ToF64

      public double callF64ToF64(double param) throws ai.tegmentum.wasmtime4j.exception.WasmException
      Specified by:
      callF64ToF64 in interface ai.tegmentum.wasmtime4j.component.ComponentTypedFunc
      Throws:
      ai.tegmentum.wasmtime4j.exception.WasmException
    • callF64F64ToF64

      public double callF64F64ToF64(double param1, double param2) throws ai.tegmentum.wasmtime4j.exception.WasmException
      Specified by:
      callF64F64ToF64 in interface ai.tegmentum.wasmtime4j.component.ComponentTypedFunc
      Throws:
      ai.tegmentum.wasmtime4j.exception.WasmException
    • callF64F64F64ToF64

      public double callF64F64F64ToF64(double param1, double param2, double param3) throws ai.tegmentum.wasmtime4j.exception.WasmException
      Specified by:
      callF64F64F64ToF64 in interface ai.tegmentum.wasmtime4j.component.ComponentTypedFunc
      Throws:
      ai.tegmentum.wasmtime4j.exception.WasmException
    • callVoidToString

      public String callVoidToString() throws ai.tegmentum.wasmtime4j.exception.WasmException
      Specified by:
      callVoidToString in interface ai.tegmentum.wasmtime4j.component.ComponentTypedFunc
      Throws:
      ai.tegmentum.wasmtime4j.exception.WasmException
    • callStringToString

      public String callStringToString(String param) throws ai.tegmentum.wasmtime4j.exception.WasmException
      Specified by:
      callStringToString in interface ai.tegmentum.wasmtime4j.component.ComponentTypedFunc
      Throws:
      ai.tegmentum.wasmtime4j.exception.WasmException
    • callStringStringToString

      public String callStringStringToString(String param1, String param2) throws ai.tegmentum.wasmtime4j.exception.WasmException
      Specified by:
      callStringStringToString in interface ai.tegmentum.wasmtime4j.component.ComponentTypedFunc
      Throws:
      ai.tegmentum.wasmtime4j.exception.WasmException
    • callVoidToBool

      public boolean callVoidToBool() throws ai.tegmentum.wasmtime4j.exception.WasmException
      Specified by:
      callVoidToBool in interface ai.tegmentum.wasmtime4j.component.ComponentTypedFunc
      Throws:
      ai.tegmentum.wasmtime4j.exception.WasmException
    • callBoolToBool

      public boolean callBoolToBool(boolean param) throws ai.tegmentum.wasmtime4j.exception.WasmException
      Specified by:
      callBoolToBool in interface ai.tegmentum.wasmtime4j.component.ComponentTypedFunc
      Throws:
      ai.tegmentum.wasmtime4j.exception.WasmException
    • getSignature

      public String getSignature()
      Specified by:
      getSignature in interface ai.tegmentum.wasmtime4j.component.ComponentTypedFunc
    • getFunction

      public ai.tegmentum.wasmtime4j.component.ComponentFunc getFunction()
      Specified by:
      getFunction in interface ai.tegmentum.wasmtime4j.component.ComponentTypedFunc
    • close

      public void close()
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface ai.tegmentum.wasmtime4j.component.ComponentTypedFunc
    • toString

      public String toString()
      Ensures the typed function is not closed.
      Overrides:
      toString in class Object
      Throws:
      IllegalStateException - if closed