FunctionInstance

FunctionInstance

sealed class FunctionInstance

Represents either a WasmFunction from a ModuleInstance, or a HostFunction exposed to the ModuleInstance via imports.

From the docs:

A function instance is the runtime representation of a function. It effectively is a closure of the original function over the runtime module instance of its originating module. The module instance is used to resolve references to other definitions during execution of the function.


funcinst   ::= {type functype, module moduleinst, code func}
{type functype, hostcode hostfunc}
hostfunc ::= ...

A host function is a function expressed outside WebAssembly but passed to a module as an import.

Fields

Name Description
open type: FunctionType

CompanionObject

FunctionInstance

sealed class FunctionInstance

Represents either a WasmFunction from a ModuleInstance, or a HostFunction exposed to the ModuleInstance via imports.

From the docs:

A function instance is the runtime representation of a function. It effectively is a closure of the original function over the runtime module instance of its originating module. The module instance is used to resolve references to other definitions during execution of the function.


funcinst   ::= {type functype, module moduleinst, code func}
{type functype, hostcode hostfunc}
hostfunc ::= ...

A host function is a function expressed outside WebAssembly but passed to a module as an import.

Methods

allocate

fun Store.allocate(moduleInstance: ModuleInstance, wasmFunction: WasmFunction): Allocation<Function>

From the docs:

  1. Let func be the function to allocate and moduleinst its module instance.
  2. Let a be the first free function address in S.
  3. Let functype be the function type moduleinst.types[func.type].
  4. Let funcinst be the function instance {type functype, module moduleinst, code func}.
  5. Append funcinst to the funcs of S.
  6. Return a.

Receiver

Name Description
Store

Parameters

Name Description
moduleInstance: ModuleInstance
wasmFunction: WasmFunction

ReturnValue

Name Description
Allocation<Function>

allocate

fun Store.allocate(hostFunction: HostFunction<*>): Allocation<Function>

From the * docs:

  1. Let hostfunc be the host function to allocate and functype its function type.
  2. Let a be the first free function address in S.
  3. Let funcinst be the function instance {type functype, hostcode hostfunc}.
  4. Append funcinst to the funcs of S.
  5. Return a.

Receiver

Name Description
Store

Parameters

Name Description
hostFunction: HostFunction<*>

ReturnValue

Name Description
Allocation<Function>