Kwasm.format.text.module
package kwasm.format.text.module
Methods
parseDataSegment
fun List<Token>.parseDataSegment(fromIndex: Int, counts: TextModuleCounts): Pair
Receiver
Name | Description |
---|---|
List<Token>
|
Parameters
Name | Description |
---|---|
fromIndex: Int
|
|
counts: TextModuleCounts
|
ReturnValue
Name | Description |
---|---|
Pair
|
parseElementSegment
fun List<Token>.parseElementSegment(fromIndex: Int, counts: TextModuleCounts): Pair
Parses an ElementSegment from the receiving List of Tokens.
From the docs:
elem_I ::= ‘(’ ‘elem’ x:tableidx_I ‘(’ ‘offset’ e:expr_I ‘)’ y*:vec(funcidx_I) ‘)’
\ => {table x, offset e, init y*}
Receiver
Name | Description |
---|---|
List<Token>
|
Parameters
Name | Description |
---|---|
fromIndex: Int
|
|
counts: TextModuleCounts
|
ReturnValue
Name | Description |
---|---|
Pair
|
parseExport
fun List<Token>.parseExport(fromIndex: Int, counts: TextModuleCounts): Pair
Parses an Export from the receiving List of Tokens.
From the docs:
export_I ::= ‘(’ ‘export’ nm:name d:exportdesc_I ‘)’ => {name nm, desc d}
Receiver
Name | Description |
---|---|
List<Token>
|
Parameters
Name | Description |
---|---|
fromIndex: Int
|
|
counts: TextModuleCounts
|
ReturnValue
Name | Description |
---|---|
Pair
|
parseExportDescriptor
fun List<Token>.parseExportDescriptor(fromIndex: Int): ParseResult<ExportDescriptor<*>>
Parses an ExportDescriptor from the receiving List of Tokens.
From the docs:
exportdesc_I ::= ‘(’ ‘func’ x:funcidx_I ‘)’ => func x
‘(’ ‘table’ x:tableidx_I ‘)’ => table x
‘(’ ‘memory’ x:memidx_I ‘)’ => mem x
‘(’ ‘global’ x:globalidx_I ‘)’ => global x
Receiver
Name | Description |
---|---|
List<Token>
|
Parameters
Name | Description |
---|---|
fromIndex: Int
|
ReturnValue
Name | Description |
---|---|
ParseResult<ExportDescriptor<*>>
|
parseGlobal
fun List<Token>.parseGlobal(fromIndex: Int, counts: TextModuleCounts): Pair
Parses a Global from the receiving List of Tokens.
From the docs:
global_I ::= ‘(’ ‘global’ id? gt:globaltype e:expr_I ‘)’ => {type gt, init e}
Receiver
Name | Description |
---|---|
List<Token>
|
Parameters
Name | Description |
---|---|
fromIndex: Int
|
|
counts: TextModuleCounts
|
ReturnValue
Name | Description |
---|---|
Pair
|
parseInlineGlobalImport
fun List<Token>.parseInlineGlobalImport(fromIndex: Int, counts: TextModuleCounts): Pair
Parses an inline Global-Import from the receiving List of Tokens.
From the docs:
‘(’ ‘global’ id? ‘(’ ‘import’ name^1 name^2 ‘)’ globaltype ‘)’
== ‘(’ ‘import’ name^1 name^2 ‘(’ ‘global’ id? globaltype ‘)’ ‘)’
Receiver
Name | Description |
---|---|
List<Token>
|
Parameters
Name | Description |
---|---|
fromIndex: Int
|
|
counts: TextModuleCounts
|
ReturnValue
Name | Description |
---|---|
Pair
|
parseInlineGlobalExport
fun List<Token>.parseInlineGlobalExport(fromIndex: Int, counts: TextModuleCounts): Pair
Parses an inline Global-Export from the receiving List of Tokens.
From the docs:
‘(’ ‘global’ id? ‘(’ ‘export’ name ‘)’ ... ‘)’
== ‘(’ ‘export’ name ‘(’ ‘global’ id′ ‘)’ ‘)’ ‘(’ ‘global’ id′ ... ‘)’
(if id′ = id? != ϵ ∨ id′ fresh)
Where “...” can contain another import or export.
Receiver
Name | Description |
---|---|
List<Token>
|
Parameters
Name | Description |
---|---|
fromIndex: Int
|
|
counts: TextModuleCounts
|
ReturnValue
Name | Description |
---|---|
Pair
|
parseImport
fun List<Token>.parseImport(fromIndex: Int, counts: TextModuleCounts): Pair
Parses an Import from the receiving List of Tokens.
From the docs:
import_I ::= ‘(’ ‘import’ mod:name nm:name d:importdesc_I ‘)’ => {module mod, name nm, desc d}
Receiver
Name | Description |
---|---|
List<Token>
|
Parameters
Name | Description |
---|---|
fromIndex: Int
|
|
counts: TextModuleCounts
|
ReturnValue
Name | Description |
---|---|
Pair
|
parseImportDescriptor
fun List<Token>.parseImportDescriptor(fromIndex: Int, counts: TextModuleCounts): Pair
Parses an ImportDescriptor of type T from the receiving List of Tokens.
From the docs:
importdesc_I ::= ‘(’ ‘func’ id? x,I':typeuse_I ‘)’ => func x
‘(’ ‘table’ id? tt:tabletype ‘)’ => table tt
‘(’ ‘memory’ id? mt:memtype ‘)’ => mem mt
‘(’ ‘global’ id? gt:globaltype ‘)’ => global gt
Receiver
Name | Description |
---|---|
List<Token>
|
Parameters
Name | Description |
---|---|
fromIndex: Int
|
|
counts: TextModuleCounts
|
ReturnValue
Name | Description |
---|---|
Pair
|
parseIndex
fun <T : Identifier> List<Token>.parseIndex(fromIndex: Int): ParseResult<Index<T>>
Receiver
Name | Description |
---|---|
List<Token>
|
Parameters
Name | Description |
---|---|
fromIndex: Int
|
ReturnValue
Name | Description |
---|---|
ParseResult<Index<T>>
|
parseIndices
fun <T : Identifier> List<Token>.parseIndices(fromIndex: Int, min: Int, max: Int): ParseResult<AstNodeList<Index<T>>>
Parses up to maxes from the receiving List of Tokens starting at fromIndex. If no indices are found, returns a ParseResult with an empty AstNodeList.
Receiver
Name | Description |
---|---|
List<Token>
|
Parameters
Name | Description |
---|---|
fromIndex: Int
|
|
min: Int
|
|
max: Int
|
ReturnValue
Name | Description |
---|---|
ParseResult<AstNodeList<Index<T>>>
|
parseLocal
fun List<Token>.parseLocal(fromIndex: Int): ParseResult<AstNodeList<Local>>?
Parses a Local from the receiving List of Tokens.
From the docs:
local ::= ‘(’ ‘local’ id? t:valtype ‘)’ => t
Receiver
Name | Description |
---|---|
List<Token>
|
Parameters
Name | Description |
---|---|
fromIndex: Int
|
ReturnValue
Name | Description |
---|---|
ParseResult<AstNodeList<Local>>?
|
parseLocals
fun List<Token>.parseLocals(fromIndex: Int): ParseResult<AstNodeList<Local>>
Parses an AstNodeList of Locals from the receiving List of Tokens.
See parseLocal.
Receiver
Name | Description |
---|---|
List<Token>
|
Parameters
Name | Description |
---|---|
fromIndex: Int
|
ReturnValue
Name | Description |
---|---|
ParseResult<AstNodeList<Local>>
|
parseMemory
fun List<Token>.parseMemory(fromIndex: Int, counts: TextModuleCounts): Pair
Parses a Memory from the receiving List of Tokens.
From the docs:
mem_I ::= ‘(’ 'memory' id? mt:memtype ‘)’ =>
Abbreviations
A data segment can be given inline with a memory definition, in which case its offset is 0
the
limits of the memory type are inferred from the length of the data, rounded up to page size:
‘(’ ‘memory’ id? ‘(’ ‘data’ bn:datastring ‘)’ ‘)’
≡ ‘(’ ‘memory’ id′ m m ‘)’ ‘(’ ‘data’ id′ ‘(’ ‘i32.const’ ‘0’ ‘)’ datastring ‘)’
(if id′ = id? != ϵ ∨ id′ fresh, m=ceil(n/64Ki))
Receiver
Name | Description |
---|---|
List<Token>
|
Parameters
Name | Description |
---|---|
fromIndex: Int
|
|
counts: TextModuleCounts
|
ReturnValue
Name | Description |
---|---|
Pair
|
parseInlineMemoryImport
fun List<Token>.parseInlineMemoryImport(fromIndex: Int, counts: TextModuleCounts): Pair
Parses an inline Memory-Import from the receiving List of Tokens.
From the docs:
‘(’ ‘memory’ id? ‘(’ ‘import’ name^1 name^2 ‘)’ memtype ‘)’
== ‘(’ ‘import’ name^1 name^2 ‘(’ ‘memory’ id? memtype ‘)’ ‘)’
Receiver
Name | Description |
---|---|
List<Token>
|
Parameters
Name | Description |
---|---|
fromIndex: Int
|
|
counts: TextModuleCounts
|
ReturnValue
Name | Description |
---|---|
Pair
|
parseInlineMemoryExport
fun List<Token>.parseInlineMemoryExport(fromIndex: Int, counts: TextModuleCounts): Pair
Parses an inline Memory-Export from the receiving List of Tokens.
From the docs:
‘(’ ‘memory’ id? ‘(’ ‘export’ name ‘)’ ... ‘)’
== ‘(’ ‘export’ name ‘(’ ‘memory’ id′ ‘)’ ‘)’ ‘(’ ‘memory’ id′ ... ‘)’
(if id′ = id? != ϵ ∨ id′ fresh)
Where “...” can contain another import or export or an inline data segment.
Receiver
Name | Description |
---|---|
List<Token>
|
Parameters
Name | Description |
---|---|
fromIndex: Int
|
|
counts: TextModuleCounts
|
ReturnValue
Name | Description |
---|---|
Pair
|
parseOffset
fun List<Token>.parseOffset(fromIndex: Int, maxExpressionLength: Int): ParseResult<Offset>
Receiver
Name | Description |
---|---|
List<Token>
|
Parameters
Name | Description |
---|---|
fromIndex: Int
|
|
maxExpressionLength: Int
|
ReturnValue
Name | Description |
---|---|
ParseResult<Offset>
|
parseStartFunction
fun List<Token>.parseStartFunction(fromIndex: Int, counts: TextModuleCounts): Pair
Parses a StartFunction from the receiving List of Tokens.
From the docs:
A start function is defined in terms of its index.
start_I ::= ‘(’ ‘start’ x:funcidx_I ‘)’ =>
Receiver
Name | Description |
---|---|
List<Token>
|
Parameters
Name | Description |
---|---|
fromIndex: Int
|
|
counts: TextModuleCounts
|
ReturnValue
Name | Description |
---|---|
Pair
|
parseTable
fun List<Token>.parseTable(fromIndex: Int, counts: TextModuleCounts): Pair
Parses a Table and (optionally) an ElementType from the receiving List of Tokens.
From the docs:
table_I ::= ‘(’ ‘table’ id? tt:tabletype ‘)’ =>
Abbreviations
An element segment can be given inline with a table definition, in which case its offset is 0
and the limits of the table type are inferred from the length of the given segment:
‘(’ ‘table’ id? elemtype ‘(’ ‘elem’ xn:vec(funcidx) ‘)’ ‘)’
== ‘(’ ‘table’ id′ n n elemtype ‘)’ ‘(’ ‘elem’ id′ ‘(’ ‘i32.const’ ‘0’ ‘)’ vec(funcidx) ‘)’
(if id′ == id? != ϵ ∨ id′ fresh)
Receiver
Name | Description |
---|---|
List<Token>
|
Parameters
Name | Description |
---|---|
fromIndex: Int
|
|
counts: TextModuleCounts
|
ReturnValue
Name | Description |
---|---|
Pair
|
parseInlineTableImport
fun List<Token>.parseInlineTableImport(fromIndex: Int, counts: TextModuleCounts): Pair
Parses an inline Table-Import from the receiving List of Tokens.
From the docs:
‘(’ ‘table’ id? ‘(’ ‘import’ name^1 name^2 ‘)’ tabletype ‘)’
== ‘(’ ‘import’ name^1 name^2 ‘(’ ‘table’ id? tabletype ‘)’ ‘)’
Receiver
Name | Description |
---|---|
List<Token>
|
Parameters
Name | Description |
---|---|
fromIndex: Int
|
|
counts: TextModuleCounts
|
ReturnValue
Name | Description |
---|---|
Pair
|
parseInlineTableExport
fun List<Token>.parseInlineTableExport(fromIndex: Int, counts: TextModuleCounts): Pair
Parses an inline Table-Export from the receiving List of Tokens.
From the docs:
‘(’ ‘table’ id? ‘(’ ‘export’ name ‘)’ ... ‘)’
== ‘(’ ‘export’ name ‘(’ ‘table’ id′ ‘)’ ‘)’ ‘(’ ‘table’ id′ ... ‘)’
(if id′ = id? != ϵ ∨ id′ fresh)
Where “...” can contain another import or export or an inline elements segment.
Receiver
Name | Description |
---|---|
List<Token>
|
Parameters
Name | Description |
---|---|
fromIndex: Int
|
|
counts: TextModuleCounts
|
ReturnValue
Name | Description |
---|---|
Pair
|
parseType
fun List<Token>.parseType(fromIndex: Int, counts: TextModuleCounts): Pair
Parses a type as a FunctionType from the receiving List of Tokens.
From the docs:
type ::= ‘(’ ‘type’ id? ft:functype ‘)’ => ft
Receiver
Name | Description |
---|---|
List<Token>
|
Parameters
Name | Description |
---|---|
fromIndex: Int
|
|
counts: TextModuleCounts
|
ReturnValue
Name | Description |
---|---|
Pair
|
parseTypeUse
fun List<Token>.parseTypeUse(fromIndex: Int): ParseResult<TypeUse>
Parses a TypeUse out of the Token according to the following grammar from the docs.
For the required runtime checks are see TypeUse:
typeuse(I) ::=
empty => TypeUse(null)
(t_1:param)* (t_2:result)* => TypeUse(x, [t_1], [t_2])
‘(’ ‘type’ x:typeidx(I) ‘)’ => TypeUse(x)
‘(’ ‘type’ x:typeidx(I) ‘)’ (t_1:param)* (t_2:result)* => TypeUse(x, [t_1], [t_2])
Receiver
Name | Description |
---|---|
List<Token>
|
Parameters
Name | Description |
---|---|
fromIndex: Int
|
ReturnValue
Name | Description |
---|---|
ParseResult<TypeUse>
|
parseWasmFunction
fun List<Token>.parseWasmFunction(fromIndex: Int, counts: TextModuleCounts): Pair
Parses a WasmFunction from the receiving List of Tokens.
From the docs:
func_I ::= ‘(’ ‘func’ id? x,I′:typeuse_I (t:local)* (in:instr_I′‘)‘* ‘)’
=> {type x, locals t*, body in* end}
Receiver
Name | Description |
---|---|
List<Token>
|
Parameters
Name | Description |
---|---|
fromIndex: Int
|
|
counts: TextModuleCounts
|
ReturnValue
Name | Description |
---|---|
Pair
|
parseInlineWasmFunctionImport
fun List<Token>.parseInlineWasmFunctionImport(fromIndex: Int, counts: TextModuleCounts): Pair
Parses an inline-import function declaration from the receiving List of Tokens.
From the docs:
‘(’ ‘func’ id? ‘(’ ‘import’ name^1 name^2 ‘)’ typeuse ‘)’
== ‘(’ ‘import’ name^1 name^2 ‘(’ ‘func’ id? typeuse ‘)’ ‘)’
Receiver
Name | Description |
---|---|
List<Token>
|
Parameters
Name | Description |
---|---|
fromIndex: Int
|
|
counts: TextModuleCounts
|
ReturnValue
Name | Description |
---|---|
Pair
|
parseInlineWasmFunctionExport
fun List<Token>.parseInlineWasmFunctionExport(fromIndex: Int, counts: TextModuleCounts): Pair
Parses an inline-export function from the receiving List of Tokens.
From the docs:
‘(’ ‘func’ id? ‘(’ ‘export’ name ‘)’ … ‘)’
== ‘(’ ‘export’ name ‘(’ ‘func’ id′ ‘)’ ‘)’ ‘(’ ‘func’ id′ … ‘)’
(if id′ == id? != ϵ ∨ id′ fresh)
Receiver
Name | Description |
---|---|
List<Token>
|
Parameters
Name | Description |
---|---|
fromIndex: Int
|
|
counts: TextModuleCounts
|
ReturnValue
Name | Description |
---|---|
Pair
|
parseModule
fun List<Token>.parseModule(fromIndex: Int): ParseResult<WasmModule>?
Parses a WasmModule from the receiving List of Tokens.
From the docs:
A module consists of a sequence of fields that can occur in any order. All definitions and their respective bound identifiers scope over the entire module, including the text preceding them.
A module may optionally bind an identifier that names the module. The name serves a documentary role only.
module ::= ‘(’ ‘module’ id? (m:modulefield_I)* ‘)’ => ⨁m*
(if I = ⨁ idc(modulefield)* well-formed)
modulefield_I ::= ty:type =>
im:import_I =>
fn:func_I =>
ta:table_I =>
me:mem_I =>
gl:global_I =>
ex:export_I =>
st:start_I =>
el:elem_I =>
da:data_I =>
Receiver
Name | Description |
---|---|
List<Token>
|
Parameters
Name | Description |
---|---|
fromIndex: Int
|
ReturnValue
Name | Description |
---|---|
ParseResult<WasmModule>?
|
Parses a DataSegment from the receiving List of Tokens.
From the docs:
Note:* In the current version of WebAssembly, the only valid memory index is
0
or a symbolic memory identifier resolving to the same value.