Interface ExternVal

All Known Subinterfaces:
Func, Global, Memory, Table
All Known Implementing Classes:
Func.HandleFunc, Global.BoxGlobal, Global.HandleGlobal, Memory.ByteBufferMemory, Memory.HandleMemory, Table.AbstractArrayTable, Table.ArrayTable, Table.HandleTable

public interface ExternVal
An extern, a value that can be exported from a module instance, or provided as an import.
  • Method Details

    • getType

      @NotNull @NotNull ExternType getType()
      Get the type of this extern.
      Returns:
      The type.
    • matchesType

      default boolean matchesType(@Nullable @Nullable ExternType expected, ExternType.Kind kind)
      Check whether this extern matches the given expected type.
      Parameters:
      expected - The expected type, or null if only the kind should be matched.
      kind - The expected kind.
      Returns:
      Whether the type matched.
    • getAsTable

      default Table getAsTable()
      Get this as a table, or throw an exception.
      Returns:
      The table.
    • getAsGlobal

      default Global getAsGlobal()
      Get this as a global, or throw an exception.
      Returns:
      The global.
    • getAsMemory

      default Memory getAsMemory()
      Get this as a memory, or throw an exception.
      Returns:
      The memory.
    • getAsFunc

      default Func getAsFunc()
      Get this as a function, or throw an exception.
      Returns:
      The function.
    • getAsHandleRaw

      default MethodHandle getAsHandleRaw()
      Get the underlying method handle of this function.

      Throws an exception if this is not a function.

      Returns:
      The method handle.
    • getAsHandle

      default MethodHandle getAsHandle(MethodType type)
      Get this function as a method handle of the given type.

      Throws an exception if this is not a function, or cannot be cast to the type.

      Parameters:
      type - The type of the handle.
      Returns:
      The cast handle.
    • func

      static ExternVal func(MethodHandle handle)
      Create a function ExternVal directly from a MethodHandle.
      Parameters:
      handle - The method handle.
      Returns:
      The ExternVal.
    • func

      static <F> ExternVal func(Class<? super F> functionalInterfaceClass, F f)
      Create a function ExternVal from an instance of a functional interface.

      The class provided must be suitable for an FunctionalInterface annotation. That is, it must be an interface with exactly one abstract method.

      This method is provided to make creating function ExternVals easy from Java.

      
       // using existing functional interfaces
       ExternVal.func(Runnable.class, () -> System.out.println("Hello, world!"));
       ExternVal.func(IntUnaryOperator.class, x -> -x);
       // using ad-hoc functional interfaces
       interface IntIntDoubleDouble { double call(int x, int y, double z); }
       ExternVal.func(IntIntDoubleDouble.class, (x, y, z) -> x + y * z);
       
      Type Parameters:
      F - The type of the function.
      Parameters:
      functionalInterfaceClass - The functional interface class.
      f - An instance of the functional interface.
      Returns:
      The ExternVal.