Types
Value Types
Value types are encoded by a single byte.
\[\begin{split}\begin{array}{llclll@{\qquad\qquad}l}
\def\mathdef1168#1{{}}\mathdef1168{value type} & \href{../binary/types.html#binary-valtype}{\mathtt{valtype}} &::=&
\def\mathdef1225#1{\mathtt{0x#1}}\mathdef1225{7F} &\Rightarrow& \href{../syntax/types.html#syntax-valtype}{\mathsf{i32}} \\ &&|&
\def\mathdef1226#1{\mathtt{0x#1}}\mathdef1226{7E} &\Rightarrow& \href{../syntax/types.html#syntax-valtype}{\mathsf{i64}} \\ &&|&
\def\mathdef1227#1{\mathtt{0x#1}}\mathdef1227{7D} &\Rightarrow& \href{../syntax/types.html#syntax-valtype}{\mathsf{f32}} \\ &&|&
\def\mathdef1228#1{\mathtt{0x#1}}\mathdef1228{7C} &\Rightarrow& \href{../syntax/types.html#syntax-valtype}{\mathsf{f64}} \\
\end{array}\end{split}\]
Note
In future versions of WebAssembly, value types may include types denoted by type indices.
Thus, the binary format for types corresponds to the encodings of small negative \(\href{../binary/values.html#binary-sint}{\href{../syntax/values.html#syntax-int}{\def\mathdef1176#1{{\mathit{s}#1}}\mathdef1176{N}}}\) values, so that they can coexist with (positive) type indices in the future.
Result Types
The only result types occurring in the binary format are the types of blocks. These are encoded in special compressed form, by either the byte \(\def\mathdef1229#1{\mathtt{0x#1}}\mathdef1229{40}\) indicating the empty type or as a single value type.
\[\begin{split}\begin{array}{llclll@{\qquad\qquad}l}
\def\mathdef1168#1{{}}\mathdef1168{result type} & \href{../binary/types.html#binary-blocktype}{\mathtt{blocktype}} &::=&
\def\mathdef1230#1{\mathtt{0x#1}}\mathdef1230{40} &\Rightarrow& [] \\ &&|&
t{:}\href{../binary/types.html#binary-valtype}{\mathtt{valtype}} &\Rightarrow& [t] \\
\end{array}\end{split}\]
Note
In future versions of WebAssembly, this scheme may be extended to support multiple results or more general block types.
Function Types
Function types are encoded by the byte \(\def\mathdef1231#1{\mathtt{0x#1}}\mathdef1231{60}\) followed by the respective vectors of parameter and result types.
\[\begin{split}\begin{array}{llclll@{\qquad\qquad}l}
\def\mathdef1168#1{{}}\mathdef1168{function type} & \href{../binary/types.html#binary-functype}{\mathtt{functype}} &::=&
\def\mathdef1232#1{\mathtt{0x#1}}\mathdef1232{60}~~t_1^\ast{:\,}\href{../binary/conventions.html#binary-vec}{\mathtt{vec}}(\href{../binary/types.html#binary-valtype}{\mathtt{valtype}})~~t_2^\ast{:\,}\href{../binary/conventions.html#binary-vec}{\mathtt{vec}}(\href{../binary/types.html#binary-valtype}{\mathtt{valtype}})
&\Rightarrow& [t_1^\ast] \href{../syntax/types.html#syntax-functype}{\rightarrow} [t_2^\ast] \\
\end{array}\end{split}\]
Limits
Limits are encoded with a preceding flag indicating whether a maximum is present.
\[\begin{split}\begin{array}{llclll}
\def\mathdef1168#1{{}}\mathdef1168{limits} & \href{../binary/types.html#binary-limits}{\mathtt{limits}} &::=&
\def\mathdef1233#1{\mathtt{0x#1}}\mathdef1233{00}~~n{:}\href{../binary/values.html#binary-int}{\def\mathdef1194#1{{\mathtt{u}#1}}\mathdef1194{\mathtt{32}}} &\Rightarrow& \{ \href{../syntax/types.html#syntax-limits}{\mathsf{min}}~n, \href{../syntax/types.html#syntax-limits}{\mathsf{max}}~\epsilon \} \\ &&|&
\def\mathdef1234#1{\mathtt{0x#1}}\mathdef1234{01}~~n{:}\href{../binary/values.html#binary-int}{\def\mathdef1194#1{{\mathtt{u}#1}}\mathdef1194{\mathtt{32}}}~~m{:}\href{../binary/values.html#binary-int}{\def\mathdef1194#1{{\mathtt{u}#1}}\mathdef1194{\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\mathdef1168#1{{}}\mathdef1168{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\mathdef1168#1{{}}\mathdef1168{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\mathdef1168#1{{}}\mathdef1168{element type} & \href{../binary/types.html#binary-elemtype}{\mathtt{elemtype}} &::=&
\def\mathdef1235#1{\mathtt{0x#1}}\mathdef1235{70} &\Rightarrow& \href{../syntax/types.html#syntax-elemtype}{\mathsf{anyfunc}} \\
\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\mathdef1168#1{{}}\mathdef1168{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\mathdef1168#1{{}}\mathdef1168{mutability} & \href{../binary/types.html#binary-mut}{\mathtt{mut}} &::=&
\def\mathdef1236#1{\mathtt{0x#1}}\mathdef1236{00} &\Rightarrow& \href{../syntax/types.html#syntax-mut}{\mathsf{const}} \\ &&|&
\def\mathdef1237#1{\mathtt{0x#1}}\mathdef1237{01} &\Rightarrow& \href{../syntax/types.html#syntax-mut}{\mathsf{var}} \\
\end{array}\end{split}\]