Types
Note
In some places, possible types include both type constructors or types denoted by type indices.
Thus, the binary format for type constructors corresponds to the encodings of small negative \(\href{../binary/values.html#binary-sint}{\href{../syntax/values.html#syntax-int}{\mathit{s}N}}\) values, such that they can unambiguously occur in the same place as (positive) type indices.
Number Types
Number types are encoded by a single byte.
\[\begin{split}\begin{array}{llclll@{\qquad\qquad}l}
\def\mathdef1928#1{{}}\mathdef1928{number type} & \href{../binary/types.html#binary-numtype}{\mathtt{numtype}} &::=&
\def\mathdef1967#1{\mathtt{0x#1}}\mathdef1967{7F} &\Rightarrow& \href{../syntax/types.html#syntax-valtype}{\mathsf{i32}} \\ &&|&
\def\mathdef1968#1{\mathtt{0x#1}}\mathdef1968{7E} &\Rightarrow& \href{../syntax/types.html#syntax-valtype}{\mathsf{i64}} \\ &&|&
\def\mathdef1969#1{\mathtt{0x#1}}\mathdef1969{7D} &\Rightarrow& \href{../syntax/types.html#syntax-valtype}{\mathsf{f32}} \\ &&|&
\def\mathdef1970#1{\mathtt{0x#1}}\mathdef1970{7C} &\Rightarrow& \href{../syntax/types.html#syntax-valtype}{\mathsf{f64}} \\
\end{array}\end{split}\]
Vector Types
Vector types are also encoded by a single byte.
\[\begin{split}\begin{array}{llclll@{\qquad\qquad}l}
\def\mathdef1928#1{{}}\mathdef1928{vector type} & \href{../binary/types.html#binary-vectype}{\mathtt{vectype}} &::=&
\def\mathdef1971#1{\mathtt{0x#1}}\mathdef1971{7B} &\Rightarrow& \href{../syntax/types.html#syntax-valtype}{\mathsf{v128}} \\
\end{array}\end{split}\]
Reference Types
Reference types are also encoded by a single byte.
\[\begin{split}\begin{array}{llclll@{\qquad\qquad}l}
\def\mathdef1928#1{{}}\mathdef1928{reference type} & \href{../binary/types.html#binary-reftype}{\mathtt{reftype}} &::=&
\def\mathdef1972#1{\mathtt{0x#1}}\mathdef1972{70} &\Rightarrow& \href{../syntax/types.html#syntax-reftype}{\mathsf{funcref}} \\ &&|&
\def\mathdef1973#1{\mathtt{0x#1}}\mathdef1973{6F} &\Rightarrow& \href{../syntax/types.html#syntax-reftype}{\mathsf{externref}} \\ &&|&
\def\mathdef1974#1{\mathtt{0x#1}}\mathdef1974{69} &\Rightarrow& \href{../syntax/types.html#syntax-reftype}{\mathsf{exnref}} \\
\end{array}\end{split}\]
Value Types
Value types are encoded with their respective encoding as a number type, vector type, or reference type.
\[\begin{split}\begin{array}{llclll@{\qquad\qquad}l}
\def\mathdef1928#1{{}}\mathdef1928{value type} & \href{../binary/types.html#binary-valtype}{\mathtt{valtype}} &::=&
t{:}\href{../binary/types.html#binary-numtype}{\mathtt{numtype}} &\Rightarrow& t \\ &&|&
t{:}\href{../binary/types.html#binary-vectype}{\mathtt{vectype}} &\Rightarrow& t \\ &&|&
t{:}\href{../binary/types.html#binary-reftype}{\mathtt{reftype}} &\Rightarrow& t \\
\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\mathdef1928#1{{}}\mathdef1928{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\mathdef1975#1{\mathtt{0x#1}}\mathdef1975{60}\) followed by the respective vectors of parameter and result types.
\[\begin{split}\begin{array}{llclll@{\qquad\qquad}l}
\def\mathdef1928#1{{}}\mathdef1928{function type} & \href{../binary/types.html#binary-functype}{\mathtt{functype}} &::=&
\def\mathdef1976#1{\mathtt{0x#1}}\mathdef1976{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\mathdef1928#1{{}}\mathdef1928{limits} & \href{../binary/types.html#binary-limits}{\mathtt{limits}} &::=&
\def\mathdef1977#1{\mathtt{0x#1}}\mathdef1977{00}~~n{:}\href{../binary/values.html#binary-int}{\def\mathdef1933#1{{\mathtt{u}#1}}\mathdef1933{\mathtt{32}}} &\Rightarrow& \{ \href{../syntax/types.html#syntax-limits}{\mathsf{min}}~n, \href{../syntax/types.html#syntax-limits}{\mathsf{max}}~\epsilon \} \\ &&|&
\def\mathdef1978#1{\mathtt{0x#1}}\mathdef1978{01}~~n{:}\href{../binary/values.html#binary-int}{\def\mathdef1933#1{{\mathtt{u}#1}}\mathdef1933{\mathtt{32}}}~~m{:}\href{../binary/values.html#binary-int}{\def\mathdef1933#1{{\mathtt{u}#1}}\mathdef1933{\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\mathdef1928#1{{}}\mathdef1928{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 the encoding of their element reference type.
\[\begin{split}\begin{array}{llclll}
\def\mathdef1928#1{{}}\mathdef1928{table type} & \href{../binary/types.html#binary-tabletype}{\mathtt{tabletype}} &::=&
\mathit{et}{:}\href{../binary/types.html#binary-reftype}{\mathtt{reftype}}~~\mathit{lim}{:}\href{../binary/types.html#binary-limits}{\mathtt{limits}} &\Rightarrow& \mathit{lim}~\mathit{et} \\
\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\mathdef1928#1{{}}\mathdef1928{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\mathdef1928#1{{}}\mathdef1928{mutability} & \href{../binary/types.html#binary-mut}{\mathtt{mut}} &::=&
\def\mathdef1979#1{\mathtt{0x#1}}\mathdef1979{00} &\Rightarrow& \href{../syntax/types.html#syntax-mut}{\mathsf{const}} \\ &&|&
\def\mathdef1980#1{\mathtt{0x#1}}\mathdef1980{01} &\Rightarrow& \href{../syntax/types.html#syntax-mut}{\mathsf{var}} \\
\end{array}\end{split}\]
Tag Types
Tag types are encoded by their function type.
\[\begin{split}\begin{array}{llclll}
\def\mathdef1928#1{{}}\mathdef1928{tag type} & \href{../binary/types.html#binary-tagtype}{\mathtt{tagtype}} &::=&
\def\mathdef1981#1{\mathtt{0x#1}}\mathdef1981{00}~~ft{:}\href{../binary/types.html#binary-functype}{\mathtt{functype}} &\Rightarrow& ft \\
\end{array}\end{split}\]
The \(\href{../binary/types.html#binary-functype}{\mathtt{functype}}\) of a tag is used to characterise exceptions.
The \(\def\mathdef1982#1{\mathtt{0x#1}}\mathdef1982{00}\) bit signifies an exception and is currently the only allowed value.
Note
In future versions of WebAssembly,
the preceding zero byte may encode additional flags.