类型¶
注意
在某些地方,可能的类型包括类型构造函数或由 类型索引 表示的类型。因此,类型构造函数的二进制格式对应于小负 \(\href{../binary/values.html#binary-sint}{\href{../syntax/values.html#syntax-int}{\mathit{s}N}}\) 值的编码,这样它们就可以与(正)类型索引在相同位置无歧义地出现。
数字类型¶
数字类型 由单个字节编码。
\[\begin{split}\begin{array}{llclll@{\qquad\qquad}l} \def\mathdef1914#1{{}}\mathdef1914{数字类型} & \href{../binary/types.html#binary-numtype}{\mathtt{numtype}} &::=& \def\mathdef1953#1{\mathtt{0x#1}}\mathdef1953{7F} &\Rightarrow& \href{../syntax/types.html#syntax-valtype}{\mathsf{i32}} \\ &&|& \def\mathdef1954#1{\mathtt{0x#1}}\mathdef1954{7E} &\Rightarrow& \href{../syntax/types.html#syntax-valtype}{\mathsf{i64}} \\ &&|& \def\mathdef1955#1{\mathtt{0x#1}}\mathdef1955{7D} &\Rightarrow& \href{../syntax/types.html#syntax-valtype}{\mathsf{f32}} \\ &&|& \def\mathdef1956#1{\mathtt{0x#1}}\mathdef1956{7C} &\Rightarrow& \href{../syntax/types.html#syntax-valtype}{\mathsf{f64}} \\ \end{array}\end{split}\]
向量类型¶
向量类型 也由单个字节编码。
\[\begin{split}\begin{array}{llclll@{\qquad\qquad}l} \def\mathdef1914#1{{}}\mathdef1914{向量类型} & \href{../binary/types.html#binary-vectype}{\mathtt{vectype}} &::=& \def\mathdef1957#1{\mathtt{0x#1}}\mathdef1957{7B} &\Rightarrow& \href{../syntax/types.html#syntax-valtype}{\mathsf{v128}} \\ \end{array}\end{split}\]
引用类型¶
引用类型 也由单个字节编码。
\[\begin{split}\begin{array}{llclll@{\qquad\qquad}l} \def\mathdef1914#1{{}}\mathdef1914{引用类型} & \href{../binary/types.html#binary-reftype}{\mathtt{reftype}} &::=& \def\mathdef1958#1{\mathtt{0x#1}}\mathdef1958{70} &\Rightarrow& \href{../syntax/types.html#syntax-reftype}{\mathsf{funcref}} \\ &&|& \def\mathdef1959#1{\mathtt{0x#1}}\mathdef1959{6F} &\Rightarrow& \href{../syntax/types.html#syntax-reftype}{\mathsf{externref}} \\ \end{array}\end{split}\]
值类型¶
值类型 使用其各自的编码作为 数字类型、向量类型 或 引用类型 编码。
\[\begin{split}\begin{array}{llclll@{\qquad\qquad}l} \def\mathdef1914#1{{}}\mathdef1914{值类型} & \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}\]
注意
值类型可以出现在允许 类型索引 的上下文中,例如在 块类型 的情况下。因此,类型的二进制格式对应于小负 \(\href{../syntax/values.html#syntax-int}{\mathit{s}N}\) 值的 有符号 LEB128 编码,以便它们将来可以与(正)类型索引共存。
结果类型¶
\[\begin{split}\begin{array}{llclll@{\qquad\qquad}l} \def\mathdef1914#1{{}}\mathdef1914{结果类型} & \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}\]
函数类型¶
函数类型 由字节 \(\def\mathdef1960#1{\mathtt{0x#1}}\mathdef1960{60}\) 以及各自的参数和结果类型的 向量 编码。
\[\begin{split}\begin{array}{llclll@{\qquad\qquad}l} \def\mathdef1914#1{{}}\mathdef1914{函数类型} & \href{../binary/types.html#binary-functype}{\mathtt{functype}} &::=& \def\mathdef1961#1{\mathtt{0x#1}}\mathdef1961{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}\]
限制¶
限制 由一个指示是否存在最大值的标志进行编码。
\[\begin{split}\begin{array}{llclll} \def\mathdef1914#1{{}}\mathdef1914{限制} & \href{../binary/types.html#binary-limits}{\mathtt{limits}} &::=& \def\mathdef1962#1{\mathtt{0x#1}}\mathdef1962{00}~~n{:}\href{../binary/values.html#binary-int}{\def\mathdef1919#1{{\mathtt{u}#1}}\mathdef1919{\mathtt{32}}} &\Rightarrow& \{ \href{../syntax/types.html#syntax-limits}{\mathsf{min}}~n, \href{../syntax/types.html#syntax-limits}{\mathsf{max}}~\epsilon \} \\ &&|& \def\mathdef1963#1{\mathtt{0x#1}}\mathdef1963{01}~~n{:}\href{../binary/values.html#binary-int}{\def\mathdef1919#1{{\mathtt{u}#1}}\mathdef1919{\mathtt{32}}}~~m{:}\href{../binary/values.html#binary-int}{\def\mathdef1919#1{{\mathtt{u}#1}}\mathdef1919{\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\mathdef1914#1{{}}\mathdef1914{内存类型} & \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}\]
表格类型¶
\[\begin{split}\begin{array}{llclll} \def\mathdef1914#1{{}}\mathdef1914{表格类型} & \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}\]
全局类型¶
\[\begin{split}\begin{array}{llclll} \def\mathdef1914#1{{}}\mathdef1914{全局类型} & \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\mathdef1914#1{{}}\mathdef1914{可变性} & \href{../binary/types.html#binary-mut}{\mathtt{mut}} &::=& \def\mathdef1964#1{\mathtt{0x#1}}\mathdef1964{00} &\Rightarrow& \href{../syntax/types.html#syntax-mut}{\mathsf{const}} \\ &&|& \def\mathdef1965#1{\mathtt{0x#1}}\mathdef1965{01} &\Rightarrow& \href{../syntax/types.html#syntax-mut}{\mathsf{var}} \\ \end{array}\end{split}\]