Store

Store

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:


store  ::= {
funcs funcinst*,
tables tableinst*,
mems meminst*,
globals globalinst*
}

Fields

Name Description
val functions: List<FunctionInstance>
val tables: List<Table>
val memories: List<Memory>
val globals: List<Global<*>>

Methods

allocateFunction

fun allocateFunction(function: FunctionInstance): Allocation<Function>

Allocates the provided FunctionInstance.

Parameters

Name Description
function: FunctionInstance

ReturnValue

Name Description
Allocation<Function>

allocateTable

fun allocateTable(table: Table): Allocation<Table>

Allocates the provided Table.

Parameters

Name Description
table: Table

ReturnValue

Name Description
Allocation<Table>

allocateMemory

fun allocateMemory(memory: Memory): Allocation<Memory>

Allocates the provided Memory.

Parameters

Name Description
memory: Memory

ReturnValue

Name Description
Allocation<Memory>

allocateGlobal

fun allocateGlobal(global: Global<*>): Allocation<Global>

Allocates the provided Global.

Parameters

Name Description
global: Global<*>

ReturnValue

Name Description
Allocation<Global>

Extensions

allocate

fun <T : Number> Store.allocate(globalType: GlobalType, value: T): Allocation<Global>

From the docs:

  1. Let globaltype be the global type to allocate and val the value to initialize the global with.
  2. Let mut t be the structure of global type globaltype.
  3. Let a be the first free global address in S.
  4. Let globalinst be the global instance {value val, mut mut}.
  5. Append globalinst to the globals of S.
  6. Return a.

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:

  1. Let memtype be the memory type to allocate.
  2. Let {min n, max m?} be the structure of memory type memtype.
  3. Let a be the first free memory address in S.
  4. Let meminst be the memory instance {data (0x00)^(n⋅64Ki), max m?} that contains n pages of zeroed bytes.
  5. Append meminst to the mems of S.
  6. Return a.

Receiver

Name Description
Store

Parameters

Name Description
memoryProvider: MemoryProvider
memoryType: MemoryType

ReturnValue

Name Description
Allocation<Memory>

allocate

fun Store.allocate(tableType: TableType): Allocation<Table>

From the docs:

  1. Let tabletype be the table type to allocate.
  2. Let ({min n, max m?} elemtype) be the structure of table type tabletype.
  3. Let a be the first free table address in S.
  4. Let tableinst be the table instance {elem(ϵ)^n, max m?} with n empty elements.
  5. Append tableinst to the tables of S.
  6. Return a.

Receiver

Name Description
Store

Parameters

Name Description
tableType: TableType

ReturnValue

Name Description
Allocation<Table>