Class PanamaLinker<T>

java.lang.Object
ai.tegmentum.wasmtime4j.panama.PanamaLinker<T>
Type Parameters:
T - the type of user data associated with stores
All Implemented Interfaces:
ai.tegmentum.wasmtime4j.Linker<T>, Closeable, AutoCloseable

public final class PanamaLinker<T> extends Object implements ai.tegmentum.wasmtime4j.Linker<T>
Panama FFI implementation of WebAssembly Linker.
Since:
1.0.0
  • Nested Class Summary

    Nested classes/interfaces inherited from interface ai.tegmentum.wasmtime4j.Linker

    ai.tegmentum.wasmtime4j.Linker.LinkerDefinition
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates a new Panama linker.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    alias(String fromModule, String fromName, String toModule, String toName)
     
    void
    aliasModule(String module, String asModule)
     
    ai.tegmentum.wasmtime4j.Linker<T>
    allowShadowing(boolean allow)
     
    ai.tegmentum.wasmtime4j.Linker<T>
    allowUnknownExports(boolean allow)
     
    void
     
    void
    define(ai.tegmentum.wasmtime4j.Store store, String moduleName, String name, ai.tegmentum.wasmtime4j.Extern extern)
     
    void
    defineGlobal(ai.tegmentum.wasmtime4j.Store store, String moduleName, String name, ai.tegmentum.wasmtime4j.WasmGlobal global)
     
    void
    defineHostFunction(String moduleName, String name, ai.tegmentum.wasmtime4j.type.FunctionType functionType, ai.tegmentum.wasmtime4j.func.HostFunction implementation)
     
    void
    defineInstance(ai.tegmentum.wasmtime4j.Store store, String moduleName, ai.tegmentum.wasmtime4j.Instance instance)
     
    void
    defineMemory(ai.tegmentum.wasmtime4j.Store store, String moduleName, String name, ai.tegmentum.wasmtime4j.WasmMemory memory)
     
    void
    defineName(ai.tegmentum.wasmtime4j.Store store, String name, ai.tegmentum.wasmtime4j.Extern extern)
     
    void
    defineTable(ai.tegmentum.wasmtime4j.Store store, String moduleName, String name, ai.tegmentum.wasmtime4j.WasmTable table)
     
    void
    defineUnknownImportsAsDefaultValues(ai.tegmentum.wasmtime4j.Store store, ai.tegmentum.wasmtime4j.Module module)
     
    void
    defineUnknownImportsAsTraps(ai.tegmentum.wasmtime4j.Store store, ai.tegmentum.wasmtime4j.Module module)
     
    void
     
    void
    funcNewUnchecked(ai.tegmentum.wasmtime4j.Store store, String moduleName, String name, ai.tegmentum.wasmtime4j.type.FunctionType functionType, ai.tegmentum.wasmtime4j.func.HostFunction implementation)
     
    ai.tegmentum.wasmtime4j.Extern
    getByImport(ai.tegmentum.wasmtime4j.Store store, String moduleName, String name)
     
    ai.tegmentum.wasmtime4j.WasmFunction
    getDefault(ai.tegmentum.wasmtime4j.Store store, String moduleName)
     
    ai.tegmentum.wasmtime4j.Engine
     
    List<ai.tegmentum.wasmtime4j.validation.ImportInfo>
     
    Gets the native linker pointer.
    Gets the WASI context set on this linker.
    boolean
    hasImport(String moduleName, String name)
     
    ai.tegmentum.wasmtime4j.Instance
    instantiate(ai.tegmentum.wasmtime4j.Store store, ai.tegmentum.wasmtime4j.Module module)
     
    ai.tegmentum.wasmtime4j.Instance
    instantiate(ai.tegmentum.wasmtime4j.Store store, String moduleName, ai.tegmentum.wasmtime4j.Module module)
     
    ai.tegmentum.wasmtime4j.InstancePre
    instantiatePre(ai.tegmentum.wasmtime4j.Module module)
     
    static int
    invokeHostFunctionCallback(long callbackId, MemorySegment paramsPtr, int paramsLen, MemorySegment resultsPtr, int resultsLen, MemorySegment errorMsgPtr, int errorMsgLen)
    Callback function invoked from native code when a host function is called.
    boolean
     
    boolean
    Checks if WASI has been enabled for this linker.
    Iterable<ai.tegmentum.wasmtime4j.Linker.LinkerDefinition>
     
    Iterable<ai.tegmentum.wasmtime4j.Linker.LinkerDefinition>
    iter(ai.tegmentum.wasmtime4j.Store store)
     
    void
    module(ai.tegmentum.wasmtime4j.Store store, String moduleName, ai.tegmentum.wasmtime4j.Module module)
     
    void
    Sets the WASI context for this linker.
    ai.tegmentum.wasmtime4j.validation.ImportValidation
    validateImports(ai.tegmentum.wasmtime4j.Module... modules)
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface ai.tegmentum.wasmtime4j.Linker

    defineHostFunctionAsync, defineName, getByImport, getOneByName, instantiateAsync, moduleAsync
  • Constructor Details

    • PanamaLinker

      public PanamaLinker(PanamaEngine engine) throws ai.tegmentum.wasmtime4j.exception.WasmException
      Creates a new Panama linker.
      Parameters:
      engine - the engine to create the linker for
      Throws:
      ai.tegmentum.wasmtime4j.exception.WasmException - if linker creation fails
  • Method Details

    • defineHostFunction

      public void defineHostFunction(String moduleName, String name, ai.tegmentum.wasmtime4j.type.FunctionType functionType, ai.tegmentum.wasmtime4j.func.HostFunction implementation) throws ai.tegmentum.wasmtime4j.exception.WasmException
      Specified by:
      defineHostFunction in interface ai.tegmentum.wasmtime4j.Linker<T>
      Throws:
      ai.tegmentum.wasmtime4j.exception.WasmException
    • defineMemory

      public void defineMemory(ai.tegmentum.wasmtime4j.Store store, String moduleName, String name, ai.tegmentum.wasmtime4j.WasmMemory memory) throws ai.tegmentum.wasmtime4j.exception.WasmException
      Specified by:
      defineMemory in interface ai.tegmentum.wasmtime4j.Linker<T>
      Throws:
      ai.tegmentum.wasmtime4j.exception.WasmException
    • defineTable

      public void defineTable(ai.tegmentum.wasmtime4j.Store store, String moduleName, String name, ai.tegmentum.wasmtime4j.WasmTable table) throws ai.tegmentum.wasmtime4j.exception.WasmException
      Specified by:
      defineTable in interface ai.tegmentum.wasmtime4j.Linker<T>
      Throws:
      ai.tegmentum.wasmtime4j.exception.WasmException
    • defineGlobal

      public void defineGlobal(ai.tegmentum.wasmtime4j.Store store, String moduleName, String name, ai.tegmentum.wasmtime4j.WasmGlobal global) throws ai.tegmentum.wasmtime4j.exception.WasmException
      Specified by:
      defineGlobal in interface ai.tegmentum.wasmtime4j.Linker<T>
      Throws:
      ai.tegmentum.wasmtime4j.exception.WasmException
    • defineInstance

      public void defineInstance(ai.tegmentum.wasmtime4j.Store store, String moduleName, ai.tegmentum.wasmtime4j.Instance instance) throws ai.tegmentum.wasmtime4j.exception.WasmException
      Specified by:
      defineInstance in interface ai.tegmentum.wasmtime4j.Linker<T>
      Throws:
      ai.tegmentum.wasmtime4j.exception.WasmException
    • alias

      public void alias(String fromModule, String fromName, String toModule, String toName) throws ai.tegmentum.wasmtime4j.exception.WasmException
      Specified by:
      alias in interface ai.tegmentum.wasmtime4j.Linker<T>
      Throws:
      ai.tegmentum.wasmtime4j.exception.WasmException
    • aliasModule

      public void aliasModule(String module, String asModule) throws ai.tegmentum.wasmtime4j.exception.WasmException
      Specified by:
      aliasModule in interface ai.tegmentum.wasmtime4j.Linker<T>
      Throws:
      ai.tegmentum.wasmtime4j.exception.WasmException
    • instantiate

      public ai.tegmentum.wasmtime4j.Instance instantiate(ai.tegmentum.wasmtime4j.Store store, ai.tegmentum.wasmtime4j.Module module) throws ai.tegmentum.wasmtime4j.exception.WasmException
      Specified by:
      instantiate in interface ai.tegmentum.wasmtime4j.Linker<T>
      Throws:
      ai.tegmentum.wasmtime4j.exception.WasmException
    • instantiate

      public ai.tegmentum.wasmtime4j.Instance instantiate(ai.tegmentum.wasmtime4j.Store store, String moduleName, ai.tegmentum.wasmtime4j.Module module) throws ai.tegmentum.wasmtime4j.exception.WasmException
      Specified by:
      instantiate in interface ai.tegmentum.wasmtime4j.Linker<T>
      Throws:
      ai.tegmentum.wasmtime4j.exception.WasmException
    • instantiatePre

      public ai.tegmentum.wasmtime4j.InstancePre instantiatePre(ai.tegmentum.wasmtime4j.Module module) throws ai.tegmentum.wasmtime4j.exception.WasmException
      Specified by:
      instantiatePre in interface ai.tegmentum.wasmtime4j.Linker<T>
      Throws:
      ai.tegmentum.wasmtime4j.exception.WasmException
    • enableWasi

      public void enableWasi() throws ai.tegmentum.wasmtime4j.exception.WasmException
      Specified by:
      enableWasi in interface ai.tegmentum.wasmtime4j.Linker<T>
      Throws:
      ai.tegmentum.wasmtime4j.exception.WasmException
    • isWasiEnabled

      public boolean isWasiEnabled()
      Checks if WASI has been enabled for this linker.
      Returns:
      true if WASI is enabled, false otherwise
    • setWasiContext

      public void setWasiContext(PanamaWasiContext wasiCtx)
      Sets the WASI context for this linker.

      The WASI context will be automatically attached to the store during instantiation.

      Parameters:
      wasiCtx - the WASI context to use
    • getWasiContext

      public PanamaWasiContext getWasiContext()
      Gets the WASI context set on this linker.
      Returns:
      the WASI context, or null if not set
    • getEngine

      public ai.tegmentum.wasmtime4j.Engine getEngine()
      Specified by:
      getEngine in interface ai.tegmentum.wasmtime4j.Linker<T>
    • isValid

      public boolean isValid()
      Specified by:
      isValid in interface ai.tegmentum.wasmtime4j.Linker<T>
    • hasImport

      public boolean hasImport(String moduleName, String name)
      Specified by:
      hasImport in interface ai.tegmentum.wasmtime4j.Linker<T>
    • validateImports

      public ai.tegmentum.wasmtime4j.validation.ImportValidation validateImports(ai.tegmentum.wasmtime4j.Module... modules)
      Specified by:
      validateImports in interface ai.tegmentum.wasmtime4j.Linker<T>
    • getImportRegistry

      public List<ai.tegmentum.wasmtime4j.validation.ImportInfo> getImportRegistry()
      Specified by:
      getImportRegistry in interface ai.tegmentum.wasmtime4j.Linker<T>
    • close

      public void close()
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Specified by:
      close in interface ai.tegmentum.wasmtime4j.Linker<T>
    • getNativeLinker

      public MemorySegment getNativeLinker()
      Gets the native linker pointer.
      Returns:
      native linker memory segment
    • invokeHostFunctionCallback

      public static int invokeHostFunctionCallback(long callbackId, MemorySegment paramsPtr, int paramsLen, MemorySegment resultsPtr, int resultsLen, MemorySegment errorMsgPtr, int errorMsgLen)
      Callback function invoked from native code when a host function is called.

      This method is called via Panama FFI function pointer.

      Parameters:
      callbackId - the callback ID
      paramsPtr - pointer to parameter array
      paramsLen - number of parameters
      resultsPtr - pointer to results buffer
      resultsLen - expected number of results
      errorMsgPtr - pointer to error message buffer (for writing on failure)
      errorMsgLen - size of error message buffer
      Returns:
      0 on success, non-zero on error
    • allowShadowing

      public ai.tegmentum.wasmtime4j.Linker<T> allowShadowing(boolean allow)
      Specified by:
      allowShadowing in interface ai.tegmentum.wasmtime4j.Linker<T>
    • allowUnknownExports

      public ai.tegmentum.wasmtime4j.Linker<T> allowUnknownExports(boolean allow)
      Specified by:
      allowUnknownExports in interface ai.tegmentum.wasmtime4j.Linker<T>
    • defineUnknownImportsAsTraps

      public void defineUnknownImportsAsTraps(ai.tegmentum.wasmtime4j.Store store, ai.tegmentum.wasmtime4j.Module module) throws ai.tegmentum.wasmtime4j.exception.WasmException
      Specified by:
      defineUnknownImportsAsTraps in interface ai.tegmentum.wasmtime4j.Linker<T>
      Throws:
      ai.tegmentum.wasmtime4j.exception.WasmException
    • defineUnknownImportsAsDefaultValues

      public void defineUnknownImportsAsDefaultValues(ai.tegmentum.wasmtime4j.Store store, ai.tegmentum.wasmtime4j.Module module) throws ai.tegmentum.wasmtime4j.exception.WasmException
      Specified by:
      defineUnknownImportsAsDefaultValues in interface ai.tegmentum.wasmtime4j.Linker<T>
      Throws:
      ai.tegmentum.wasmtime4j.exception.WasmException
    • funcNewUnchecked

      public void funcNewUnchecked(ai.tegmentum.wasmtime4j.Store store, String moduleName, String name, ai.tegmentum.wasmtime4j.type.FunctionType functionType, ai.tegmentum.wasmtime4j.func.HostFunction implementation) throws ai.tegmentum.wasmtime4j.exception.WasmException
      Specified by:
      funcNewUnchecked in interface ai.tegmentum.wasmtime4j.Linker<T>
      Throws:
      ai.tegmentum.wasmtime4j.exception.WasmException
    • iter

      public Iterable<ai.tegmentum.wasmtime4j.Linker.LinkerDefinition> iter()
      Specified by:
      iter in interface ai.tegmentum.wasmtime4j.Linker<T>
    • iter

      public Iterable<ai.tegmentum.wasmtime4j.Linker.LinkerDefinition> iter(ai.tegmentum.wasmtime4j.Store store) throws ai.tegmentum.wasmtime4j.exception.WasmException
      Specified by:
      iter in interface ai.tegmentum.wasmtime4j.Linker<T>
      Throws:
      ai.tegmentum.wasmtime4j.exception.WasmException
    • getByImport

      public ai.tegmentum.wasmtime4j.Extern getByImport(ai.tegmentum.wasmtime4j.Store store, String moduleName, String name)
      Specified by:
      getByImport in interface ai.tegmentum.wasmtime4j.Linker<T>
    • defineName

      public void defineName(ai.tegmentum.wasmtime4j.Store store, String name, ai.tegmentum.wasmtime4j.Extern extern) throws ai.tegmentum.wasmtime4j.exception.WasmException
      Specified by:
      defineName in interface ai.tegmentum.wasmtime4j.Linker<T>
      Throws:
      ai.tegmentum.wasmtime4j.exception.WasmException
    • define

      public void define(ai.tegmentum.wasmtime4j.Store store, String moduleName, String name, ai.tegmentum.wasmtime4j.Extern extern) throws ai.tegmentum.wasmtime4j.exception.WasmException
      Specified by:
      define in interface ai.tegmentum.wasmtime4j.Linker<T>
      Throws:
      ai.tegmentum.wasmtime4j.exception.WasmException
    • module

      public void module(ai.tegmentum.wasmtime4j.Store store, String moduleName, ai.tegmentum.wasmtime4j.Module module) throws ai.tegmentum.wasmtime4j.exception.WasmException
      Specified by:
      module in interface ai.tegmentum.wasmtime4j.Linker<T>
      Throws:
      ai.tegmentum.wasmtime4j.exception.WasmException
    • getDefault

      public ai.tegmentum.wasmtime4j.WasmFunction getDefault(ai.tegmentum.wasmtime4j.Store store, String moduleName)
      Specified by:
      getDefault in interface ai.tegmentum.wasmtime4j.Linker<T>