kwasm.format.text.type

Kwasm.format.text.type

package kwasm.format.text.type

Methods

parseFunctionType

fun List<Token>.parseFunctionType(fromIndex: Int): ParseResult<FunctionType>

Parses a FunctionType from a list of Tokens. From the docs:


functype ::=  ‘(’ ‘func’  t1:vec(param)  t2:vec(result) ‘)’ => [t1]→[t2]
param    ::=  ‘(’ ‘param’  id?  t:valtype ‘)’                 => t
result   ::=  ‘(’ ‘result’  t:valtype ‘)’                     => t

Receiver

Name Description
List<Token>

Parameters

Name Description
fromIndex: Int

ReturnValue

Name Description
ParseResult<FunctionType>

parseParamList

fun List<Token>.parseParamList(currentIndex: Int): ParseResult<AstNodeList<Param>>

Parses a list of Param from a list of tokens.

Receiver

Name Description
List<Token>

Parameters

Name Description
currentIndex: Int

ReturnValue

Name Description
ParseResult<AstNodeList<Param>>

a Pair containing the list of Params and an integer tracking the number of tokens parsed

parseResultList

fun List<Token>.parseResultList(currentIndex: Int): ParseResult<AstNodeList<Result>>

Parses a list of Result from a list of tokens.

Receiver

Name Description
List<Token>

Parameters

Name Description
currentIndex: Int

ReturnValue

Name Description
ParseResult<AstNodeList<Result>>

a Pair containing the list of Results and an integer tracking the number of tokens parsed

parseGlobalType

fun List<Token>.parseGlobalType(currentIndex: Int): ParseResult<GlobalType>

Parses a GlobalType from a list of Tokens. From the docs:


globaltype ::=  t:valtype                => const t
‘(’ ‘mut’  t:valtype ‘)’ => var t

Receiver

Name Description
List<Token>

Parameters

Name Description
currentIndex: Int

ReturnValue

Name Description
ParseResult<GlobalType>

parseLimits

fun List<Token>.parseLimits(startingIndex: Int): ParseResult<Limits>

From the spec:


limits ::=  n:u32        => {min n, max ϵ}
|   n:u32  m:u32 => {min n, max m}

Receiver

Name Description
List<Token>

Parameters

Name Description
startingIndex: Int

ReturnValue

Name Description
ParseResult<Limits>

parseMemoryType

fun List<Token>.parseMemoryType(startingIndex: Int): ParseResult<MemoryType>

From the spec:


memtype ::= lim:limits => lim

Receiver

Name Description
List<Token>

Parameters

Name Description
startingIndex: Int

ReturnValue

Name Description
ParseResult<MemoryType>

parseParam

fun List<Token>.parseParam(fromIndex: Int): ParseResult<AstNodeList<Param>>

Parses a Param from a list of Tokens. from the docs:


param    ::=  ‘(’ ‘param’  id?  t:valtype ‘)’  => t

Receiver

Name Description
List<Token>

Parameters

Name Description
fromIndex: Int

ReturnValue

Name Description
ParseResult<AstNodeList<Param>>

parseResult

fun List<Token>.parseResult(fromIndex: Int): ParseResult<AstNodeList<Result>>

Parses a Result from a list of Tokens. from the docs:


result   ::=  ‘(’ ‘result’  t:valtype ‘)’  => t

Receiver

Name Description
List<Token>

Parameters

Name Description
fromIndex: Int

ReturnValue

Name Description
ParseResult<AstNodeList<Result>>

parseResultType

fun List<Token>.parseResultType(currentIndex: Int): ParseResult<ResultType>

Parses a Result from a list of Tokens. From the docs:


resultType   ::=  (t:result)?  => [t?]

Receiver

Name Description
List<Token>

Parameters

Name Description
currentIndex: Int

ReturnValue

Name Description
ParseResult<ResultType>

parseTableType

fun List<Token>.parseTableType(startingIndex: Int): ParseResult<TableType>

From the spec:


tabletype ::= lim:limits  et:elemtype => lim et
elemtype  ::= ‘funcref’               => funcref

Receiver

Name Description
List<Token>

Parameters

Name Description
startingIndex: Int

ReturnValue

Name Description
ParseResult<TableType>

parseValueType

fun List<Token>.parseValueType(currentIndex: Int): ParseResult<ValueType>

Parses a ValueType from a list of Tokens. From the docs:


valtype ::=  { 'i32' -> I32
'i64' -> I64
'f32' -> F32
'f64' -> F64 }

Receiver

Name Description
List<Token>

Parameters

Name Description
currentIndex: Int

ReturnValue

Name Description
ParseResult<ValueType>

parseOptionalValueType

fun List<Token>.parseOptionalValueType(currentIndex: Int): ParseResult<ValueType>?

Similar to parseValueType, but does not throw if a ValueType is null.

Receiver

Name Description
List<Token>

Parameters

Name Description
currentIndex: Int

ReturnValue

Name Description
ParseResult<ValueType>?

parseValueTypes

fun List<Token>.parseValueTypes(fromIndex: Int, minRequired: Int, maxAllowed: Int): ParseResult<AstNodeList<ValueType>>

Parses an AstNodeList of ValueTypes from the receiving List of Tokens.

See parseValueType.

Receiver

Name Description
List<Token>

Parameters

Name Description
fromIndex: Int
minRequired: Int
maxAllowed: Int

ReturnValue

Name Description
ParseResult<AstNodeList<ValueType>>