Kwasm.runtime
package kwasm.runtime
Classes
Name | Description |
---|---|
sealed class Address
|
Addresses for FunctionInstances, Memorys, Tables, and Globals. From the docs: Function instances, table instances, memory instances, and global instances in the store are referenced with abstract addresses. These are simply indices into the respective store component.
An embedder may assign identity to exported store objects corresponding to their addresses, even where this identity is not observable from within WebAssembly code itself (such as for function instances or immutable globals). |
sealed class Export
|
Represents a runtime exported value. From the docs: An export instance is the runtime representation of an export. It defines the export’s name and the associated external value.
|
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.
A host function is a function expressed outside WebAssembly but passed to a module as an import. |
sealed class Global
|
From the docs: A global instance is the runtime representation of a global variable. It holds an individual value and a flag indicating whether it is mutable.
The value of mutable globals can be mutated through variable instructions or by external means provided by the embedder. |
data class IdentifierContext
|
From the docs: Where
|
sealed class ImportExtern
|
Represents an external value imported by a WasmModule. Its address will be used to populate a ModuleInstance so that lookups happen correctly at runtime.
|
interface Memory
|
Defines runtime memory for use by a wasm program, along with facilities for accessing and mutating memory by the host JVM application. From the docs: A memory instance is the runtime representation of a linear memory. It holds a vector of bytes and an optional maximum size, if one was specified at the definition site of the memory.
The length of the vector always is a multiple of the WebAssembly page size, which is defined to
be the constant The bytes can be mutated through memory instructions, the execution of a data segment, or by external means provided by the embedder. It is an invariant of the semantics that the length of the byte vector, divided by page size, never exceeds the maximum size, if present. |
data class ModuleInstance
|
Represents an instantiated kwasm.ast.module.WasmModule. From the docs: A module instance is the runtime representation of a module. It is created by instantiating a module, and collects runtime representations of all entities that are imported, defined, or exported by the module.
Each component references runtime instances corresponding to respective declarations from the original module – whether imported or defined – in the order of their static indices. Function instances, table instances, memory instances, and global instances are referenced with an indirection through their respective addresses in the store. It is an invariant of the semantics that all export instances in a given module instance have different names. |
data class ModuleAllocationResult
|
Result of allocating a module using WasmModule.allocate. |
interface StackElement
|
Defines an element in one of the runtime Stacks. |
data class Store
|
From the docs: The store represents all global state that can be manipulated by WebAssembly programs. It consists of the runtime representation of all instances of functions, tables, memories, and globals that have been allocated during the life time of the abstract machine. Syntactically, the store is defined as a record listing the existing instances of each category:
|
data class Table
|
Runtime representation of a WebAssembly Table. From the docs: A table instance is the runtime representation of a table. It holds a vector of function elements and an optional maximum size, if one was specified in the table type at the table’s definition site. Each function element is either empty, representing an uninitialized table entry, or a function address. Function elements can be mutated through the execution of an element segment or by external means provided by the embedder.
It is an invariant of the semantics that the length of the element vector never exceeds the maximum size, if present. |
interface Value
|
Defines a value for use in WebAssembly at runtime. From the docs: WebAssembly computations manipulate values of the four basic value types: integers and floating-point data of 32 or 64 bit width each, respectively. In most places of the semantics, values of different types can occur. In order to avoid
ambiguities, values are therefore represented with an abstract syntax that makes their type
explicit. It is convenient to reuse the same notation as for the
|
object EmptyValue
|
Represents an empty value. Should only ever be used as a return-type for a void/Unit kwasm.api.HostFunction. |
inline class IntValue
|
Holds a 32-bit integer Value. |
inline class LongValue
|
Holds a 64-bit integer Value. |
inline class FloatValue
|
Holds a 32-bit floating-point Value. |
inline class DoubleValue
|
Holds a 64-bit floating-point Value. |
Subpackages
Name | Description |
---|---|
package kwasm.runtime.instruction
|
|
package kwasm.runtime.memory
|
|
package kwasm.runtime.stack
|
|
package kwasm.runtime.util
|
Fields
Methods
allocate
fun <T : Number> Store.allocate(globalType: GlobalType, value: T): Allocation<Global>
Receiver
Name | Description |
---|---|
Store
|
Parameters
Name | Description |
---|---|
globalType: GlobalType
|
|
value: T
|
ReturnValue
Name | Description |
---|---|
Allocation<Global>
|
allocate
fun Store.allocate(memoryProvider: MemoryProvider, memoryType: MemoryType): Allocation<Memory>
From the docs:
- Let
memtype
be the memory type to allocate. - Let
{min n, max m?}
be the structure of memory typememtype
. - Let
a
be the first free memory address inS
. - Let
meminst
be the memory instance{data (0x00)^(n⋅64Ki), max m?}
that containsn
pages of zeroed bytes. - Append
meminst
to themems
ofS
. - Return
a
.
Receiver
Name | Description |
---|---|
Store
|
Parameters
Name | Description |
---|---|
memoryProvider: MemoryProvider
|
|
memoryType: MemoryType
|
ReturnValue
Name | Description |
---|---|
Allocation<Memory>
|
allocate
fun WasmModule.allocate(validationContext: Module, memoryProvider: MemoryProvider, externalValues: List<ImportExtern<Address>>, store: Store): ModuleAllocationResult
Instantiates a WasmModule into a ModuleInstance given a Store.
From the docs:
- Let
module
be the module to allocate andexternval*_im
the vector of external values providing the module’s imports, andval*
the initialization values of the module’s globals. For each function
func_i
inmodule.funcs
, do:- Let
funcaddr_i
be the function address resulting from allocatingfunc_i
for the module instancemoduleinst
defined below.
- Let
For each table
table_i
inmodule.tables
, do:- Let
tableaddr_i
be the table address resulting from allocatingtable_i.type
.
- Let
For each memory
mem_i
inmodule.mems
, do:- Let
memaddr_i
be the memory address resulting from allocatingmem_i.type
.
- Let
For each global
global_i
inmodule.globals
, do:- Let
globaladdr_i
be the global address resulting from allocatingglobal_i.type
with initializer valueval*[i]
.
- Let
- Let
funcaddr*
be the the concatenation of the function addressesfuncaddr_i
in index order. - Let
tableaddr*
be the the concatenation of the table addressestableaddr_i
in index order. - Let
memaddr*
be the the concatenation of the memory addressesmemaddr_i
in index order. - Let
globaladdr*
be the the concatenation of the global addressesglobaladdr_i
in index order. - Let
funcaddr*_mod
be the list of function addresses extracted fromexternval*_im
, concatenated withfuncaddr*
. - Let
tableaddr*_mod
be the list of table addresses extracted fromexternval*_im
, concatenated withtableaddr*
. - Let
memaddr*_mod
be the list of memory addresses extracted fromexternval*_im
, concatenated withmemaddr*
. - Let
globaladdr*_mod
be the list of global addresses extracted fromexternval*_im
, concatenated withglobaladdr*
. For each export
export_i
inmodule.exports
, do:- If
export_i
is a function export for function indexx
, then letexternval_i
be the external valuefunc (funcaddr*_mod[x])
. - Else, if
export_i
is a table export for table indexx
, then letexternval_i
be the external valuetable (tableaddr*_mod[x])
. - Else, if
export_i
is a memory export for memory indexx
, then letexternval_i
be the external valuemem (memaddr*_mod[x])
. - Else, if
export_i
is a global export for global indexx
, then letexternval_i
be the external valueglobal (globaladdr*_mod[x])
. - Let
exportinst_i
be the export instance{name (export_i.name), value externval_i}
.
- If
- Let
exportinst*
be the the concatenation of the export instancesexportinst_i
in index order. - Let
moduleinst
be the module instance{ types (module.types), funcaddrs funcaddr*_mod, tableaddrs tableaddr*_mod, memaddrs memaddr*_mod, globaladdrs globaladdr*_mod, exports exportinst* }
. - Return
moduleinst
.
Receiver
Name | Description |
---|---|
WasmModule
|
Parameters
Name | Description |
---|---|
validationContext: Module
|
|
memoryProvider: MemoryProvider
|
|
externalValues: List<ImportExtern<Address>>
|
|
store: Store
|
ReturnValue
Name | Description |
---|---|
ModuleAllocationResult
|
allocate
fun Store.allocate(tableType: TableType): Allocation<Table>
From the docs:
- Let
tabletype
be the table type to allocate. - Let
({min n, max m?} elemtype)
be the structure of table typetabletype
. - Let
a
be the first free table address inS
. - Let
tableinst
be the table instance{elem(ϵ)^n, max m?}
withn
empty elements. - Append
tableinst
to thetables
ofS
. - Return
a
.
Receiver
Name | Description |
---|---|
Store
|
Parameters
Name | Description |
---|---|
tableType: TableType
|
ReturnValue
Name | Description |
---|---|
Allocation<Table>
|
collectImportExterns
fun WasmModule.collectImportExterns(): List<ImportExtern<Address>>
Transforms a WasmModule's raw list of Imports into ImportExterns.
Receiver
Name | Description |
---|---|
WasmModule
|
ReturnValue
Name | Description |
---|---|
List<ImportExtern<Address>>
|
Table
fun Table(tableType: TableType, builder: (MutableMap<Int, Function?>)->Unit): Table
Builder to create a Table given a TableType and a builder function used to add elements to the Table's elements.
ReturnValue
Name | Description |
---|---|
Table
|
toValue
fun UInt.toValue(): IntValue
Receiver
Name | Description |
---|---|
UInt
|
ReturnValue
Name | Description |
---|---|
IntValue
|
toValue
fun <T : Number> T.toValue(): Value<*>
Wraps the receiving value as a Value instance.
Receiver
Name | Description |
---|---|
T
|
ReturnValue
Name | Description |
---|---|
Value<*>
|
checkType
fun Value<*>.checkType(expected: ValueType)
Receiver
Name | Description |
---|---|
Value<*>
|
Parameters
Name | Description |
---|---|
expected: ValueType
|
ReturnValue
Name | Description |
---|---|
Unit
|
isType
fun Value<*>.isType(expected: ValueType): Boolean
Receiver
Name | Description |
---|---|
Value<*>
|
Parameters
Name | Description |
---|---|
expected: ValueType
|
ReturnValue
Name | Description |
---|---|
Boolean
|
toValue
fun Int.toValue(): IntValue
Wraps an Int in an IntValue.
Receiver
Name | Description |
---|---|
Int
|
ReturnValue
Name | Description |
---|---|
IntValue
|
toValue
fun Long.toValue(): LongValue
Wraps a Long in a LongValue.
Receiver
Name | Description |
---|---|
Long
|
ReturnValue
Name | Description |
---|---|
LongValue
|
toValue
fun Float.toValue(): FloatValue
Wraps a Float in a FloatValue.
Receiver
Name | Description |
---|---|
Float
|
ReturnValue
Name | Description |
---|---|
FloatValue
|
toValue
fun Double.toValue(): DoubleValue
Wraps a Double in a DoubleValue.
Receiver
Name | Description |
---|---|
Double
|
ReturnValue
Name | Description |
---|---|
DoubleValue
|
From the docs:
globaltype
be the global type to allocate andval
the value to initialize the global with.mut t
be the structure of global typeglobaltype
.a
be the first free global address inS
.globalinst
be the global instance{value val, mut mut}
.globalinst
to theglobals
ofS
.a
.