类型

数字类型

\[\begin{split}\begin{array}{llcll@{\qquad\qquad}l} \def\mathdef3799#1{{}}\mathdef3799{数字类型} & \href{../text/types.html#text-numtype}{\mathtt{numtype}} &::=& \def\mathdef3838#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3838{i32} &\Rightarrow& \href{../syntax/types.html#syntax-valtype}{\mathsf{i32}} \\ &&|& \def\mathdef3839#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3839{i64} &\Rightarrow& \href{../syntax/types.html#syntax-valtype}{\mathsf{i64}} \\ &&|& \def\mathdef3840#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3840{f32} &\Rightarrow& \href{../syntax/types.html#syntax-valtype}{\mathsf{f32}} \\ &&|& \def\mathdef3841#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3841{f64} &\Rightarrow& \href{../syntax/types.html#syntax-valtype}{\mathsf{f64}} \\ \end{array}\end{split}\]

向量类型

\[\begin{split}\begin{array}{llcll@{\qquad\qquad}l} \def\mathdef3799#1{{}}\mathdef3799{向量类型} & \href{../text/types.html#text-vectype}{\mathtt{vectype}} &::=& \def\mathdef3842#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3842{v128} &\Rightarrow& \href{../syntax/types.html#syntax-valtype}{\mathsf{v128}} \\ \end{array}\end{split}\]

引用类型

\[\begin{split}\begin{array}{llcll@{\qquad\qquad}l} \def\mathdef3799#1{{}}\mathdef3799{引用类型} & \href{../text/types.html#text-reftype}{\mathtt{reftype}} &::=& \def\mathdef3843#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3843{funcref} &\Rightarrow& \href{../syntax/types.html#syntax-reftype}{\mathsf{funcref}} \\ &&|& \def\mathdef3844#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3844{externref} &\Rightarrow& \href{../syntax/types.html#syntax-reftype}{\mathsf{externref}} \\ \def\mathdef3799#1{{}}\mathdef3799{堆类型} & \href{../text/types.html#text-heaptype}{\mathtt{heaptype}} &::=& \def\mathdef3845#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3845{func} &\Rightarrow& \href{../syntax/types.html#syntax-reftype}{\mathsf{funcref}} \\ &&|& \def\mathdef3846#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3846{extern} &\Rightarrow& \href{../syntax/types.html#syntax-reftype}{\mathsf{externref}} \\ \end{array}\end{split}\]

值类型

\[\begin{split}\begin{array}{llcll@{\qquad\qquad}l} \def\mathdef3799#1{{}}\mathdef3799{值类型} & \href{../text/types.html#text-valtype}{\mathtt{valtype}} &::=& t{:}\href{../text/types.html#text-numtype}{\mathtt{numtype}} &\Rightarrow& t \\ &&|& t{:}\href{../text/types.html#text-vectype}{\mathtt{vectype}} &\Rightarrow& t \\ &&|& t{:}\href{../text/types.html#text-reftype}{\mathtt{reftype}} &\Rightarrow& t \\ \end{array}\end{split}\]

函数类型

\[\begin{split}\begin{array}{llclll@{\qquad\qquad}l} \def\mathdef3799#1{{}}\mathdef3799{函数类型} & \href{../text/types.html#text-functype}{\mathtt{functype}} &::=& \def\mathdef3847#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3847{(}~\def\mathdef3848#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3848{func}~~t_1^\ast{:\,}\href{../text/conventions.html#text-vec}{\mathtt{vec}}(\href{../text/types.html#text-functype}{\mathtt{param}})~~t_2^\ast{:\,}\href{../text/conventions.html#text-vec}{\mathtt{vec}}(\href{../text/types.html#text-functype}{\mathtt{result}})~\def\mathdef3849#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3849{)} &\Rightarrow& [t_1^\ast] \href{../syntax/types.html#syntax-functype}{\rightarrow} [t_2^\ast] \\ \def\mathdef3799#1{{}}\mathdef3799{参数} & \href{../text/types.html#text-functype}{\mathtt{param}} &::=& \def\mathdef3850#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3850{(}~\def\mathdef3851#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3851{param}~~\href{../text/values.html#text-id}{\mathtt{id}}^?~~t{:}\href{../text/types.html#text-valtype}{\mathtt{valtype}}~\def\mathdef3852#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3852{)} &\Rightarrow& t \\ \def\mathdef3799#1{{}}\mathdef3799{结果} & \href{../text/types.html#text-functype}{\mathtt{result}} &::=& \def\mathdef3853#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3853{(}~\def\mathdef3854#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3854{result}~~t{:}\href{../text/types.html#text-valtype}{\mathtt{valtype}}~\def\mathdef3855#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3855{)} &\Rightarrow& t \\ \end{array}\end{split}\]

注意

函数类型中参数的可选标识符名称仅用于文档目的。它们不能从任何地方引用。

缩写

多个匿名参数或结果可以合并到一个声明中

\[\begin{split}\begin{array}{llclll} \def\mathdef3799#1{{}}\mathdef3799{参数} & \def\mathdef3856#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3856{(}~~\def\mathdef3857#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3857{param}~~\href{../text/types.html#text-valtype}{\mathtt{valtype}}^\ast~~\def\mathdef3858#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3858{)} &\equiv& (\def\mathdef3859#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3859{(}~~\def\mathdef3860#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3860{param}~~\href{../text/types.html#text-valtype}{\mathtt{valtype}}~~\def\mathdef3861#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3861{)})^\ast \\ \def\mathdef3799#1{{}}\mathdef3799{结果} & \def\mathdef3862#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3862{(}~~\def\mathdef3863#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3863{result}~~\href{../text/types.html#text-valtype}{\mathtt{valtype}}^\ast~~\def\mathdef3864#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3864{)} &\equiv& (\def\mathdef3865#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3865{(}~~\def\mathdef3866#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3866{result}~~\href{../text/types.html#text-valtype}{\mathtt{valtype}}~~\def\mathdef3867#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3867{)})^\ast \\ \end{array}\end{split}\]

限制

\[\begin{split}\begin{array}{llclll} \def\mathdef3799#1{{}}\mathdef3799{限制} & \href{../text/types.html#text-limits}{\mathtt{limits}} &::=& n{:}\href{../text/values.html#text-int}{\def\mathdef3824#1{{\mathtt{u}#1}}\mathdef3824{\mathtt{32}}} &\Rightarrow& \{ \href{../syntax/types.html#syntax-limits}{\mathsf{min}}~n, \href{../syntax/types.html#syntax-limits}{\mathsf{max}}~\epsilon \} \\ &&|& n{:}\href{../text/values.html#text-int}{\def\mathdef3824#1{{\mathtt{u}#1}}\mathdef3824{\mathtt{32}}}~~m{:}\href{../text/values.html#text-int}{\def\mathdef3824#1{{\mathtt{u}#1}}\mathdef3824{\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}\]

内存类型

\[\begin{split}\begin{array}{llclll@{\qquad\qquad}l} \def\mathdef3799#1{{}}\mathdef3799{内存类型} & \href{../text/types.html#text-memtype}{\mathtt{memtype}} &::=& \mathit{lim}{:}\href{../text/types.html#text-limits}{\mathtt{limits}} &\Rightarrow& \mathit{lim} \\ \end{array}\end{split}\]

表格类型

\[\begin{split}\begin{array}{llclll} \def\mathdef3799#1{{}}\mathdef3799{表格类型} & \href{../text/types.html#text-tabletype}{\mathtt{tabletype}} &::=& \mathit{lim}{:}\href{../text/types.html#text-limits}{\mathtt{limits}}~~\mathit{et}{:}\href{../text/types.html#text-reftype}{\mathtt{reftype}} &\Rightarrow& \mathit{lim}~\mathit{et} \\ \end{array}\end{split}\]

全局类型

\[\begin{split}\begin{array}{llclll} \def\mathdef3799#1{{}}\mathdef3799{全局类型} & \href{../text/types.html#text-globaltype}{\mathtt{globaltype}} &::=& t{:}\href{../text/types.html#text-valtype}{\mathtt{valtype}} &\Rightarrow& \href{../syntax/types.html#syntax-mut}{\mathsf{const}}~t \\ &&|& \def\mathdef3868#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3868{(}~\def\mathdef3869#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3869{mut}~~t{:}\href{../text/types.html#text-valtype}{\mathtt{valtype}}~\def\mathdef3870#1{\mbox{‘}\mathtt{#1}\mbox{’}}\mathdef3870{)} &\Rightarrow& \href{../syntax/types.html#syntax-mut}{\mathsf{var}}~t \\ \end{array}\end{split}\]