FunctionInstance
sealed class FunctionInstance
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:
- Let
func
be the function to allocate andmoduleinst
its module instance. - Let
a
be the first free function address inS
. - Let
functype
be the function typemoduleinst.types[func.type]
. - Let
funcinst
be the function instance{type functype, module moduleinst, code func}
. - Append
funcinst
to thefuncs
ofS
. - 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:
- Let
hostfunc
be the host function to allocate andfunctype
its function type. - Let
a
be the first free function address inS
. - Let
funcinst
be the function instance{type functype, hostcode hostfunc}
. - Append
funcinst
to thefuncs
ofS
. - Return
a
.
Receiver
Name | Description |
---|---|
Store
|
Parameters
Name | Description |
---|---|
hostFunction: HostFunction<*>
|
ReturnValue
Name | Description |
---|---|
Allocation<Function>
|
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.
A host function is a function expressed outside WebAssembly but passed to a module as an import.