Types¶

Value Types¶

Value types are encoded by a single byte.

$\begin{split}\begin{array}{llclll@{\qquad\qquad}l} \def\mathdef902#1{{}}\mathdef902{value type} & \href{../binary/types.html#binary-valtype}{\mathtt{valtype}} &::=& \def\mathdef939#1{\mathtt{0x#1}}\mathdef939{7F} &\Rightarrow& \href{../syntax/types.html#syntax-valtype}{\mathsf{i32}} \\ &&|& \def\mathdef940#1{\mathtt{0x#1}}\mathdef940{7E} &\Rightarrow& \href{../syntax/types.html#syntax-valtype}{\mathsf{i64}} \\ &&|& \def\mathdef941#1{\mathtt{0x#1}}\mathdef941{7D} &\Rightarrow& \href{../syntax/types.html#syntax-valtype}{\mathsf{f32}} \\ &&|& \def\mathdef942#1{\mathtt{0x#1}}\mathdef942{7C} &\Rightarrow& \href{../syntax/types.html#syntax-valtype}{\mathsf{f64}} \\ \end{array}\end{split}$

Note

Value types can occur in contexts where type indices are also allowed, such as in the case of block types. Thus, the binary format for types corresponds to the signed LEB128 encoding of small negative $$\href{../syntax/values.html#syntax-int}{\mathit{s}N}$$ values, so that they can coexist with (positive) type indices in the future.

Result Types¶

Result types are encoded by the respective vectors of value types `.

$\begin{split}\begin{array}{llclll@{\qquad\qquad}l} \def\mathdef902#1{{}}\mathdef902{result type} & \href{../binary/types.html#binary-resulttype}{\mathtt{resulttype}} &::=& t^\ast{:\,}\href{../binary/conventions.html#binary-vec}{\mathtt{vec}}(\href{../binary/types.html#binary-valtype}{\mathtt{valtype}}) &\Rightarrow& [t^\ast] \\ \end{array}\end{split}$

Function Types¶

Function types are encoded by the byte $$\def\mathdef943#1{\mathtt{0x#1}}\mathdef943{60}$$ followed by the respective vectors of parameter and result types.

$\begin{split}\begin{array}{llclll@{\qquad\qquad}l} \def\mathdef902#1{{}}\mathdef902{function type} & \href{../binary/types.html#binary-functype}{\mathtt{functype}} &::=& \def\mathdef944#1{\mathtt{0x#1}}\mathdef944{60}~~\mathit{rt}_1{:\,}\href{../binary/types.html#binary-resulttype}{\mathtt{resulttype}}~~\mathit{rt}_2{:\,}\href{../binary/types.html#binary-resulttype}{\mathtt{resulttype}} &\Rightarrow& \mathit{rt}_1 \href{../syntax/types.html#syntax-functype}{\rightarrow} \mathit{rt}_2 \\ \end{array}\end{split}$

Limits¶

Limits are encoded with a preceding flag indicating whether a maximum is present.

$\begin{split}\begin{array}{llclll} \def\mathdef902#1{{}}\mathdef902{limits} & \href{../binary/types.html#binary-limits}{\mathtt{limits}} &::=& \def\mathdef945#1{\mathtt{0x#1}}\mathdef945{00}~~n{:}\href{../binary/values.html#binary-int}{\def\mathdef907#1{{\mathtt{u}#1}}\mathdef907{\mathtt{32}}} &\Rightarrow& \{ \href{../syntax/types.html#syntax-limits}{\mathsf{min}}~n, \href{../syntax/types.html#syntax-limits}{\mathsf{max}}~\epsilon \} \\ &&|& \def\mathdef946#1{\mathtt{0x#1}}\mathdef946{01}~~n{:}\href{../binary/values.html#binary-int}{\def\mathdef907#1{{\mathtt{u}#1}}\mathdef907{\mathtt{32}}}~~m{:}\href{../binary/values.html#binary-int}{\def\mathdef907#1{{\mathtt{u}#1}}\mathdef907{\mathtt{32}}} &\Rightarrow& \{ \href{../syntax/types.html#syntax-limits}{\mathsf{min}}~n, \href{../syntax/types.html#syntax-limits}{\mathsf{max}}~m \} \\ \end{array}\end{split}$

Memory Types¶

Memory types are encoded with their limits.

$\begin{split}\begin{array}{llclll@{\qquad\qquad}l} \def\mathdef902#1{{}}\mathdef902{memory type} & \href{../binary/types.html#binary-memtype}{\mathtt{memtype}} &::=& \mathit{lim}{:}\href{../binary/types.html#binary-limits}{\mathtt{limits}} &\Rightarrow& \mathit{lim} \\ \end{array}\end{split}$

Table Types¶

Table types are encoded with their limits and a constant byte indicating their element type.

$\begin{split}\begin{array}{llclll} \def\mathdef902#1{{}}\mathdef902{table type} & \href{../binary/types.html#binary-tabletype}{\mathtt{tabletype}} &::=& \mathit{et}{:}\href{../binary/types.html#binary-elemtype}{\mathtt{elemtype}}~~\mathit{lim}{:}\href{../binary/types.html#binary-limits}{\mathtt{limits}} &\Rightarrow& \mathit{lim}~\mathit{et} \\ \def\mathdef902#1{{}}\mathdef902{element type} & \href{../binary/types.html#binary-elemtype}{\mathtt{elemtype}} &::=& \def\mathdef947#1{\mathtt{0x#1}}\mathdef947{70} &\Rightarrow& \href{../syntax/types.html#syntax-elemtype}{\mathsf{funcref}} \\ \end{array}\end{split}$

Global Types¶

Global types are encoded by their value type and a flag for their mutability.

$\begin{split}\begin{array}{llclll} \def\mathdef902#1{{}}\mathdef902{global type} & \href{../binary/types.html#binary-globaltype}{\mathtt{globaltype}} &::=& t{:}\href{../binary/types.html#binary-valtype}{\mathtt{valtype}}~~m{:}\href{../binary/types.html#binary-mut}{\mathtt{mut}} &\Rightarrow& m~t \\ \def\mathdef902#1{{}}\mathdef902{mutability} & \href{../binary/types.html#binary-mut}{\mathtt{mut}} &::=& \def\mathdef948#1{\mathtt{0x#1}}\mathdef948{00} &\Rightarrow& \href{../syntax/types.html#syntax-mut}{\mathsf{const}} \\ &&|& \def\mathdef949#1{\mathtt{0x#1}}\mathdef949{01} &\Rightarrow& \href{../syntax/types.html#syntax-mut}{\mathsf{var}} \\ \end{array}\end{split}$