指令

指令 根据描述指令如何操作操作数栈栈类型 \([t_1^\ast] \href{../syntax/types.html#syntax-functype}{\rightarrow} [t_2^\ast]\)进行分类。

\[\begin{split}\begin{array}{llll} \def\mathdef4083#1{{}}\mathdef4083{栈类型} & \href{../valid/instructions.html#syntax-stacktype}{\mathit{stacktype}} &::=& [\href{../valid/instructions.html#syntax-opdtype}{\mathit{opdtype}}^\ast] \href{../syntax/types.html#syntax-functype}{\rightarrow} [\href{../valid/instructions.html#syntax-opdtype}{\mathit{opdtype}}^\ast] \\ \def\mathdef4083#1{{}}\mathdef4083{操作数类型} & \href{../valid/instructions.html#syntax-opdtype}{\mathit{opdtype}} &::=& \href{../syntax/types.html#syntax-valtype}{\mathit{valtype}} ~|~ \bot \\ \end{array}\end{split}\]

这些类型描述了指令弹出的具有操作数类型 \(t_1^\ast\) 的所需输入栈,以及它压入的具有类型 \(t_2^\ast\) 的结果值的输出栈。栈类型类似于函数类型,但它们允许将单个操作数分类为 \(\bot\)底部),表示类型不受约束。作为一个辅助概念,如果 \(t_1\)\(\bot\) 或等于 \(t_2\),则操作数类型 \(t_1\) 与另一个操作数类型 \(t_2\) 匹配。这以逐点的方式扩展到栈类型。

\[\frac{ }{ \vdash t \leq t } \qquad \frac{ }{ \vdash \bot \leq t }\]
\[\frac{ (\vdash t \leq t')^\ast }{ \vdash [t^\ast] \leq [{t'}^\ast] }\]

注意

例如,指令 \(\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}.\href{../syntax/instructions.html#syntax-instr-numeric}{\mathsf{add}}\) 的类型为 \([\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}~\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}] \href{../syntax/types.html#syntax-functype}{\rightarrow} [\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}]\),它消耗两个 \(\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}\) 值并产生一个值。

类型推导扩展到指令序列 \(\href{../syntax/instructions.html#syntax-instr}{\mathit{instr}}^\ast\)。如果执行指令的累积效果是从操作数栈中消耗类型为 \(t_1^\ast\) 的值并压入类型为 \(t_2^\ast\) 的新值,则此序列具有栈类型 \([t_1^\ast] \href{../syntax/types.html#syntax-functype}{\rightarrow} [t_2^\ast]\)

对于某些指令,类型规则没有完全约束类型,因此允许多种类型。这样的指令称为多态指令。可以区分两种多态性

  • 值多态:一个或多个单个操作数的值类型 \(t\) 不受约束。对于所有参数化指令(如 \(\href{../syntax/instructions.html#syntax-instr-parametric}{\mathsf{drop}}\)\(\href{../syntax/instructions.html#syntax-instr-parametric}{\mathsf{select}}\))都是这种情况。

  • 栈多态:指令的整个(或大部分)栈类型 \([t_1^\ast] \href{../syntax/types.html#syntax-functype}{\rightarrow} [t_2^\ast]\) 不受约束。对于所有执行无条件控制转移控制指令(例如 \(\href{../syntax/instructions.html#syntax-instr-control}{\mathsf{unreachable}}\)\(\href{../syntax/instructions.html#syntax-instr-control}{\mathsf{br}}\)\(\href{../syntax/instructions.html#syntax-instr-control}{\mathsf{br\_table}}\)\(\href{../syntax/instructions.html#syntax-instr-control}{\mathsf{return}}\))都是这种情况。

在这两种情况下,只要满足程序周围部分施加的约束,就可以任意选择不受约束的类型或类型序列。

注意

例如,\(\href{../syntax/instructions.html#syntax-instr-parametric}{\mathsf{select}}\) 指令对于任何可能的数值类型 \(t\),都可以使用类型 \([t~t~\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}] \href{../syntax/types.html#syntax-functype}{\rightarrow} [t]\)。因此,以下两个指令序列

\[(\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}.\href{../syntax/instructions.html#syntax-instr-numeric}{\mathsf{const}}~1)~~(\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}.\href{../syntax/instructions.html#syntax-instr-numeric}{\mathsf{const}}~2)~~(\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}.\href{../syntax/instructions.html#syntax-instr-numeric}{\mathsf{const}}~3)~~\href{../syntax/instructions.html#syntax-instr-parametric}{\mathsf{select}}{}\]

\[(\href{../syntax/types.html#syntax-valtype}{\mathsf{f64}}.\href{../syntax/instructions.html#syntax-instr-numeric}{\mathsf{const}}~1.0)~~(\href{../syntax/types.html#syntax-valtype}{\mathsf{f64}}.\href{../syntax/instructions.html#syntax-instr-numeric}{\mathsf{const}}~2.0)~~(\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}.\href{../syntax/instructions.html#syntax-instr-numeric}{\mathsf{const}}~3)~~\href{../syntax/instructions.html#syntax-instr-parametric}{\mathsf{select}}{}\]

都是有效的,其中 \(\href{../syntax/instructions.html#syntax-instr-parametric}{\mathsf{select}}\) 的类型中的 \(t\) 分别被实例化为 \(\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}\)\(\href{../syntax/types.html#syntax-valtype}{\mathsf{f64}}\)

\(\href{../syntax/instructions.html#syntax-instr-control}{\mathsf{unreachable}}\) 指令对于任何可能的操作数类型 \(t_1^\ast\)\(t_2^\ast\) 序列,都具有类型 \([t_1^\ast] \href{../syntax/types.html#syntax-functype}{\rightarrow} [t_2^\ast]\)。因此,

\[\href{../syntax/instructions.html#syntax-instr-control}{\mathsf{unreachable}}~~\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}.\href{../syntax/instructions.html#syntax-instr-numeric}{\mathsf{add}}\]

通过为 \(\href{../syntax/instructions.html#syntax-instr-control}{\mathsf{unreachable}}\) 指令假设类型 \([] \href{../syntax/types.html#syntax-functype}{\rightarrow} [\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}~\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}]\) 是有效的。相反,

\[\href{../syntax/instructions.html#syntax-instr-control}{\mathsf{unreachable}}~~(\href{../syntax/types.html#syntax-valtype}{\mathsf{i64}}.\href{../syntax/instructions.html#syntax-instr-numeric}{\mathsf{const}}~0)~~\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}.\href{../syntax/instructions.html#syntax-instr-numeric}{\mathsf{add}}\]

是无效的,因为没有可以为 \(\href{../syntax/instructions.html#syntax-instr-control}{\mathsf{unreachable}}\) 指令选择的类型可以使序列类型正确。

附录 描述了一种类型检查算法,该算法有效地实现了此处给定规则规定的指令序列验证。

数值指令

\(t\mathsf{.}\href{../syntax/instructions.html#syntax-instr-numeric}{\mathsf{const}}~c\)

  • 该指令对于类型 \([] \href{../syntax/types.html#syntax-functype}{\rightarrow} [t]\) 是有效的。

\[\frac{ }{ C \href{../valid/instructions.html#valid-instr}{\vdash} t\mathsf{.}\href{../syntax/instructions.html#syntax-instr-numeric}{\mathsf{const}}~c : [] \href{../syntax/types.html#syntax-functype}{\rightarrow} [t] }\]

\(t\mathsf{.}\href{../syntax/instructions.html#syntax-unop}{\mathit{unop}}\)

  • 该指令对于类型 \([t] \href{../syntax/types.html#syntax-functype}{\rightarrow} [t]\) 是有效的。

\[\frac{ }{ C \href{../valid/instructions.html#valid-instr}{\vdash} t\mathsf{.}\href{../syntax/instructions.html#syntax-unop}{\mathit{unop}} : [t] \href{../syntax/types.html#syntax-functype}{\rightarrow} [t] }\]

\(t\mathsf{.}\href{../syntax/instructions.html#syntax-binop}{\mathit{binop}}\)

  • 该指令对于类型 \([t~t] \href{../syntax/types.html#syntax-functype}{\rightarrow} [t]\) 是有效的。

\[\frac{ }{ C \href{../valid/instructions.html#valid-instr}{\vdash} t\mathsf{.}\href{../syntax/instructions.html#syntax-binop}{\mathit{binop}} : [t~t] \href{../syntax/types.html#syntax-functype}{\rightarrow} [t] }\]

\(t\mathsf{.}\href{../syntax/instructions.html#syntax-testop}{\mathit{testop}}\)

  • 该指令对于类型 \([t] \href{../syntax/types.html#syntax-functype}{\rightarrow} [\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}]\) 是有效的。

\[\frac{ }{ C \href{../valid/instructions.html#valid-instr}{\vdash} t\mathsf{.}\href{../syntax/instructions.html#syntax-testop}{\mathit{testop}} : [t] \href{../syntax/types.html#syntax-functype}{\rightarrow} [\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}] }\]

\(t\mathsf{.}\href{../syntax/instructions.html#syntax-relop}{\mathit{relop}}\)

  • 该指令对于类型 \([t~t] \href{../syntax/types.html#syntax-functype}{\rightarrow} [\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}]\) 是有效的。

\[\frac{ }{ C \href{../valid/instructions.html#valid-instr}{\vdash} t\mathsf{.}\href{../syntax/instructions.html#syntax-relop}{\mathit{relop}} : [t~t] \href{../syntax/types.html#syntax-functype}{\rightarrow} [\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}] }\]

\(t_2\mathsf{.}\href{../syntax/instructions.html#syntax-cvtop}{\mathit{cvtop}}\mathsf{\_}t_1\mathsf{\_}\href{../syntax/instructions.html#syntax-sx}{\mathit{sx}}^?\)

  • 该指令对于类型 \([t_1] \href{../syntax/types.html#syntax-functype}{\rightarrow} [t_2]\) 是有效的。

\[\frac{ }{ C \href{../valid/instructions.html#valid-instr}{\vdash} t_2\mathsf{.}\href{../syntax/instructions.html#syntax-cvtop}{\mathit{cvtop}}\mathsf{\_}t_1\mathsf{\_}\href{../syntax/instructions.html#syntax-sx}{\mathit{sx}}^? : [t_1] \href{../syntax/types.html#syntax-functype}{\rightarrow} [t_2] }\]

引用指令

\(\href{../syntax/instructions.html#syntax-instr-ref}{\mathsf{ref{.}null}}~t\)

  • 该指令对于类型 \([] \href{../syntax/types.html#syntax-functype}{\rightarrow} [t]\) 是有效的。

\[\frac{ }{ C \href{../valid/instructions.html#valid-instr}{\vdash} \href{../syntax/instructions.html#syntax-instr-ref}{\mathsf{ref{.}null}}~t : [] \href{../syntax/types.html#syntax-functype}{\rightarrow} [t] }\]

注意

在 WebAssembly 的未来版本中,可能存在不允许空引用的引用类型。

\(\href{../syntax/instructions.html#syntax-instr-ref}{\mathsf{ref{.}is\_null}}\)

  • 该指令对于类型 \([t] \href{../syntax/types.html#syntax-functype}{\rightarrow} [\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}]\) 是有效的,其中 \(t\) 为任何引用类型

\[\frac{ t = \href{../syntax/types.html#syntax-reftype}{\mathit{reftype}} }{ C \href{../valid/instructions.html#valid-instr}{\vdash} \href{../syntax/instructions.html#syntax-instr-ref}{\mathsf{ref{.}is\_null}} : [t] \href{../syntax/types.html#syntax-functype}{\rightarrow} [\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}] }\]

\(\href{../syntax/instructions.html#syntax-instr-ref}{\mathsf{ref{.}func}}~x\)

  • 上下文必须定义函数 \(C.\href{../valid/conventions.html#context}{\mathsf{funcs}}[x]\)

  • 函数索引 \(x\) 必须包含在 \(C.\href{../valid/conventions.html#context}{\mathsf{refs}}\) 中。

  • 该指令的类型有效,为 \([] \href{../syntax/types.html#syntax-functype}{\rightarrow} [\href{../syntax/types.html#syntax-reftype}{\mathsf{funcref}}]\)

\[\frac{ C.\href{../valid/conventions.html#context}{\mathsf{funcs}}[x] = \href{../syntax/types.html#syntax-functype}{\mathit{functype}} \qquad x \in C.\href{../valid/conventions.html#context}{\mathsf{refs}} }{ C \href{../valid/instructions.html#valid-instr}{\vdash} \href{../syntax/instructions.html#syntax-instr-ref}{\mathsf{ref{.}func}}~x : [] \href{../syntax/types.html#syntax-functype}{\rightarrow} [\href{../syntax/types.html#syntax-reftype}{\mathsf{funcref}}] }\]

向量指令

向量指令可以带前缀来描述操作数的形状。打包数值类型,\(\href{../syntax/values.html#syntax-int}{\mathit{i8}}\)\(\href{../syntax/values.html#syntax-int}{\mathit{i16}}\),不是值类型。一个辅助函数将这些打包类型形状映射到值类型。

\[\begin{split}\begin{array}{lll@{\qquad}l} \href{../valid/instructions.html#aux-unpacked}{\mathrm{unpacked}}(\mathsf{i8x16}) &=& \href{../syntax/types.html#syntax-valtype}{\mathsf{i32}} \\ \href{../valid/instructions.html#aux-unpacked}{\mathrm{unpacked}}(\mathsf{i16x8}) &=& \href{../syntax/types.html#syntax-valtype}{\mathsf{i32}} \\ \href{../valid/instructions.html#aux-unpacked}{\mathrm{unpacked}}(t\mathsf{x}N) &=& t \end{array}\end{split}\]

以下辅助函数表示向量形状的车道数,即其维度

\[\begin{array}{lll@{\qquad}l} \href{../valid/instructions.html#aux-dim}{\mathrm{dim}}(t\mathsf{x}N) &=& N \end{array}\]

\(\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}\mathsf{.}\href{../syntax/instructions.html#syntax-instr-vec}{\mathsf{const}}~c\)

  • 该指令的类型有效,为 \([] \href{../syntax/types.html#syntax-functype}{\rightarrow} [\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}]\)

\[\frac{ }{ C \href{../valid/instructions.html#valid-instr}{\vdash} \href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}\mathsf{.}\href{../syntax/instructions.html#syntax-instr-vec}{\mathsf{const}}~c : [] \href{../syntax/types.html#syntax-functype}{\rightarrow} [\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}] }\]

\(\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}\mathsf{.}\href{../syntax/instructions.html#syntax-vvunop}{\mathit{vvunop}}\)

  • 该指令的类型有效,为 \([\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}] \href{../syntax/types.html#syntax-functype}{\rightarrow} [\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}]\)

\[\frac{ }{ C \href{../valid/instructions.html#valid-instr}{\vdash} \href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}\mathsf{.}\href{../syntax/instructions.html#syntax-vvunop}{\mathit{vvunop}} : [\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}] \href{../syntax/types.html#syntax-functype}{\rightarrow} [\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}] }\]

\(\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}\mathsf{.}\href{../syntax/instructions.html#syntax-vvbinop}{\mathit{vvbinop}}\)

  • 该指令的类型有效,为 \([\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}~\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}] \href{../syntax/types.html#syntax-functype}{\rightarrow} [\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}]\)

\[\frac{ }{ C \href{../valid/instructions.html#valid-instr}{\vdash} \href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}\mathsf{.}\href{../syntax/instructions.html#syntax-vvbinop}{\mathit{vvbinop}} : [\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}~\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}] \href{../syntax/types.html#syntax-functype}{\rightarrow} [\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}] }\]

\(\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}\mathsf{.}\href{../syntax/instructions.html#syntax-vvternop}{\mathit{vvternop}}\)

  • 该指令的类型有效,为 \([\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}~\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}~\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}] \href{../syntax/types.html#syntax-functype}{\rightarrow} [\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}]\)

\[\frac{ }{ C \href{../valid/instructions.html#valid-instr}{\vdash} \href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}\mathsf{.}\href{../syntax/instructions.html#syntax-vvternop}{\mathit{vvternop}} : [\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}~\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}~\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}] \href{../syntax/types.html#syntax-functype}{\rightarrow} [\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}] }\]

\(\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}\mathsf{.}\href{../syntax/instructions.html#syntax-vvtestop}{\mathit{vvtestop}}\)

  • 该指令的类型有效,为 \([\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}] \href{../syntax/types.html#syntax-functype}{\rightarrow} [\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}]\)

\[\frac{ }{ C \href{../valid/instructions.html#valid-instr}{\vdash} \href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}\mathsf{.}\href{../syntax/instructions.html#syntax-vvtestop}{\mathit{vvtestop}} : [\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}] \href{../syntax/types.html#syntax-functype}{\rightarrow} [\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}] }\]

\(\mathsf{i8x16.}\href{../syntax/instructions.html#syntax-instr-vec}{\mathsf{swizzle}}\)

  • 该指令的类型有效,为 \([\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}~\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}] \href{../syntax/types.html#syntax-functype}{\rightarrow} [\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}]\)

\[\frac{ }{ C \href{../valid/instructions.html#valid-instr}{\vdash} \mathsf{i8x16.}\href{../syntax/instructions.html#syntax-instr-vec}{\mathsf{swizzle}} : [\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}~\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}] \href{../syntax/types.html#syntax-functype}{\rightarrow} [\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}] }\]

\(\mathsf{i8x16.}\href{../syntax/instructions.html#syntax-instr-vec}{\mathsf{shuffle}}~\href{../syntax/instructions.html#syntax-laneidx}{\mathit{laneidx}}^{16}\)

  • 对于所有 \(\href{../syntax/instructions.html#syntax-laneidx}{\mathit{laneidx}}_i\),在 \(\href{../syntax/instructions.html#syntax-laneidx}{\mathit{laneidx}}^{16}\) 中,\(\href{../syntax/instructions.html#syntax-laneidx}{\mathit{laneidx}}_i\) 必须小于 \(32\)

  • 该指令的类型有效,为 \([\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}~\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}] \href{../syntax/types.html#syntax-functype}{\rightarrow} [\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}]\)

\[\frac{ (\href{../syntax/instructions.html#syntax-laneidx}{\mathit{laneidx}} < 32)^{16} }{ C \href{../valid/instructions.html#valid-instr}{\vdash} \mathsf{i8x16.}\href{../syntax/instructions.html#syntax-instr-vec}{\mathsf{shuffle}}~\href{../syntax/instructions.html#syntax-laneidx}{\mathit{laneidx}}^{16} : [\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}~\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}] \href{../syntax/types.html#syntax-functype}{\rightarrow} [\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}] }\]

\(\href{../syntax/instructions.html#syntax-shape}{\mathit{shape}}\mathsf{.}\href{../syntax/instructions.html#syntax-instr-vec}{\mathsf{splat}}\)

  • \(t\)\(\href{../valid/instructions.html#aux-unpacked}{\mathrm{unpacked}}(\href{../syntax/instructions.html#syntax-shape}{\mathit{shape}})\)

  • 该指令的类型有效,为 \([t] \href{../syntax/types.html#syntax-functype}{\rightarrow} [\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}]\)

\[\frac{ }{ C \href{../valid/instructions.html#valid-instr}{\vdash} \href{../syntax/instructions.html#syntax-shape}{\mathit{shape}}\mathsf{.}\href{../syntax/instructions.html#syntax-instr-vec}{\mathsf{splat}} : [\href{../valid/instructions.html#aux-unpacked}{\mathrm{unpacked}}(\href{../syntax/instructions.html#syntax-shape}{\mathit{shape}})] \href{../syntax/types.html#syntax-functype}{\rightarrow} [\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}] }\]

\(\href{../syntax/instructions.html#syntax-shape}{\mathit{shape}}\mathsf{.}\href{../syntax/instructions.html#syntax-instr-vec}{\mathsf{extract\_lane}}\mathsf{\_}\href{../syntax/instructions.html#syntax-sx}{\mathit{sx}}^?~\href{../syntax/instructions.html#syntax-laneidx}{\mathit{laneidx}}\)

  • 车道索引 \(\href{../syntax/instructions.html#syntax-laneidx}{\mathit{laneidx}}\) 必须小于 \(\href{../valid/instructions.html#aux-dim}{\mathrm{dim}}(\href{../syntax/instructions.html#syntax-shape}{\mathit{shape}})\)

  • 该指令的类型有效,为 \([\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}] \href{../syntax/types.html#syntax-functype}{\rightarrow} [\href{../valid/instructions.html#aux-unpacked}{\mathrm{unpacked}}(\href{../syntax/instructions.html#syntax-shape}{\mathit{shape}})]\)

\[\frac{ \href{../syntax/instructions.html#syntax-laneidx}{\mathit{laneidx}} < \href{../valid/instructions.html#aux-dim}{\mathrm{dim}}(\href{../syntax/instructions.html#syntax-shape}{\mathit{shape}}) }{ C \href{../valid/instructions.html#valid-instr}{\vdash} \href{../syntax/instructions.html#syntax-shape}{\mathit{shape}}\mathsf{.}\href{../syntax/instructions.html#syntax-instr-vec}{\mathsf{extract\_lane}}\mathsf{\_}\href{../syntax/instructions.html#syntax-sx}{\mathit{sx}}^?~\href{../syntax/instructions.html#syntax-laneidx}{\mathit{laneidx}} : [\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}] \href{../syntax/types.html#syntax-functype}{\rightarrow} [\href{../valid/instructions.html#aux-unpacked}{\mathrm{unpacked}}(\href{../syntax/instructions.html#syntax-shape}{\mathit{shape}})] }\]

\(\href{../syntax/instructions.html#syntax-shape}{\mathit{shape}}\mathsf{.}\href{../syntax/instructions.html#syntax-instr-vec}{\mathsf{replace\_lane}}~\href{../syntax/instructions.html#syntax-laneidx}{\mathit{laneidx}}\)

  • 车道索引 \(\href{../syntax/instructions.html#syntax-laneidx}{\mathit{laneidx}}\) 必须小于 \(\href{../valid/instructions.html#aux-dim}{\mathrm{dim}}(\href{../syntax/instructions.html#syntax-shape}{\mathit{shape}})\)

  • \(t\)\(\href{../valid/instructions.html#aux-unpacked}{\mathrm{unpacked}}(\href{../syntax/instructions.html#syntax-shape}{\mathit{shape}})\)

  • 该指令的类型有效,为 \([\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}~t] \href{../syntax/types.html#syntax-functype}{\rightarrow} [\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}]\)

\[\frac{ \href{../syntax/instructions.html#syntax-laneidx}{\mathit{laneidx}} < \href{../valid/instructions.html#aux-dim}{\mathrm{dim}}(\href{../syntax/instructions.html#syntax-shape}{\mathit{shape}}) }{ C \href{../valid/instructions.html#valid-instr}{\vdash} \href{../syntax/instructions.html#syntax-shape}{\mathit{shape}}\mathsf{.}\href{../syntax/instructions.html#syntax-instr-vec}{\mathsf{replace\_lane}}~\href{../syntax/instructions.html#syntax-laneidx}{\mathit{laneidx}} : [\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}~\href{../valid/instructions.html#aux-unpacked}{\mathrm{unpacked}}(\href{../syntax/instructions.html#syntax-shape}{\mathit{shape}})] \href{../syntax/types.html#syntax-functype}{\rightarrow} [\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}] }\]

\(\href{../syntax/instructions.html#syntax-shape}{\mathit{shape}}\mathsf{.}\href{../syntax/instructions.html#syntax-vunop}{\mathit{vunop}}\)

  • 该指令的类型有效,为 \([\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}] \href{../syntax/types.html#syntax-functype}{\rightarrow} [\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}]\)

\[\frac{ }{ C \href{../valid/instructions.html#valid-instr}{\vdash} \href{../syntax/instructions.html#syntax-shape}{\mathit{shape}}\mathsf{.}\href{../syntax/instructions.html#syntax-vunop}{\mathit{vunop}} : [\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}] \href{../syntax/types.html#syntax-functype}{\rightarrow} [\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}] }\]

\(\href{../syntax/instructions.html#syntax-shape}{\mathit{shape}}\mathsf{.}\href{../syntax/instructions.html#syntax-vbinop}{\mathit{vbinop}}\)

  • 该指令的类型有效,为 \([\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}~\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}] \href{../syntax/types.html#syntax-functype}{\rightarrow} [\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}]\)

\[\frac{ }{ C \href{../valid/instructions.html#valid-instr}{\vdash} \href{../syntax/instructions.html#syntax-shape}{\mathit{shape}}\mathsf{.}\href{../syntax/instructions.html#syntax-vbinop}{\mathit{vbinop}} : [\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}~\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}] \href{../syntax/types.html#syntax-functype}{\rightarrow} [\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}] }\]

\(\href{../syntax/instructions.html#syntax-shape}{\mathit{shape}}\mathsf{.}\href{../syntax/instructions.html#syntax-vrelop}{\mathit{vrelop}}\)

  • 该指令的类型有效,为 \([\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}~\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}] \href{../syntax/types.html#syntax-functype}{\rightarrow} [\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}]\)

\[\frac{ }{ C \href{../valid/instructions.html#valid-instr}{\vdash} \href{../syntax/instructions.html#syntax-shape}{\mathit{shape}}\mathsf{.}\href{../syntax/instructions.html#syntax-vrelop}{\mathit{vrelop}} : [\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}~\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}] \href{../syntax/types.html#syntax-functype}{\rightarrow} [\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}] }\]

\(\href{../syntax/instructions.html#syntax-shape}{\mathit{ishape}}\mathsf{.}\href{../syntax/instructions.html#syntax-vishiftop}{\mathit{vishiftop}}\)

  • 该指令的类型有效,为 \([\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}~\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}] \href{../syntax/types.html#syntax-functype}{\rightarrow} [\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}]\)

\[\frac{ }{ C \href{../valid/instructions.html#valid-instr}{\vdash} \href{../syntax/instructions.html#syntax-shape}{\mathit{ishape}}\mathsf{.}\href{../syntax/instructions.html#syntax-vishiftop}{\mathit{vishiftop}} : [\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}~\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}] \href{../syntax/types.html#syntax-functype}{\rightarrow} [\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}] }\]

\(\href{../syntax/instructions.html#syntax-shape}{\mathit{shape}}\mathsf{.}\href{../syntax/instructions.html#syntax-vtestop}{\mathit{vtestop}}\)

  • 该指令的类型有效,为 \([\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}] \href{../syntax/types.html#syntax-functype}{\rightarrow} [\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}]\)

\[\frac{ }{ C \href{../valid/instructions.html#valid-instr}{\vdash} \href{../syntax/instructions.html#syntax-shape}{\mathit{shape}}\mathsf{.}\href{../syntax/instructions.html#syntax-vtestop}{\mathit{vtestop}} : [\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}] \href{../syntax/types.html#syntax-functype}{\rightarrow} [\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}] }\]

\(\href{../syntax/instructions.html#syntax-shape}{\mathit{shape}}\mathsf{.}\href{../syntax/instructions.html#syntax-vcvtop}{\mathit{vcvtop}}\mathsf{\_}\href{../syntax/instructions.html#syntax-half}{\mathit{half}}^?\mathsf{\_}\href{../syntax/instructions.html#syntax-shape}{\mathit{shape}}\mathsf{\_}\href{../syntax/instructions.html#syntax-sx}{\mathit{sx}}^?\mathsf{\_zero}^?\)

  • 该指令的类型有效,为 \([\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}] \href{../syntax/types.html#syntax-functype}{\rightarrow} [\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}]\)

\[\frac{ }{ C \href{../valid/instructions.html#valid-instr}{\vdash} \href{../syntax/instructions.html#syntax-shape}{\mathit{shape}}\mathsf{.}\href{../syntax/instructions.html#syntax-vcvtop}{\mathit{vcvtop}}\mathsf{\_}\href{../syntax/instructions.html#syntax-half}{\mathit{half}}^?\mathsf{\_}\href{../syntax/instructions.html#syntax-shape}{\mathit{shape}}\mathsf{\_}\href{../syntax/instructions.html#syntax-sx}{\mathit{sx}}^?\mathsf{\_zero}^? : [\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}] \href{../syntax/types.html#syntax-functype}{\rightarrow} [\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}] }\]

\(\href{../syntax/instructions.html#syntax-shape}{\mathit{ishape}}_1\mathsf{.}\href{../syntax/instructions.html#syntax-instr-vec}{\mathsf{narrow}}\mathsf{\_}\href{../syntax/instructions.html#syntax-shape}{\mathit{ishape}}_2\mathsf{\_}\href{../syntax/instructions.html#syntax-sx}{\mathit{sx}}\)

  • 该指令的类型有效,为 \([\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}~\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}] \href{../syntax/types.html#syntax-functype}{\rightarrow} [\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}]\)

\[\frac{ }{ C \href{../valid/instructions.html#valid-instr}{\vdash} \href{../syntax/instructions.html#syntax-shape}{\mathit{ishape}}_1\mathsf{.}\href{../syntax/instructions.html#syntax-instr-vec}{\mathsf{narrow}}\mathsf{\_}\href{../syntax/instructions.html#syntax-shape}{\mathit{ishape}}_2\mathsf{\_}\href{../syntax/instructions.html#syntax-sx}{\mathit{sx}} : [\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}~\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}] \href{../syntax/types.html#syntax-functype}{\rightarrow} [\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}] }\]

\(\href{../syntax/instructions.html#syntax-shape}{\mathit{ishape}}\mathsf{.}\href{../syntax/instructions.html#syntax-instr-vec}{\mathsf{bitmask}}\)

  • 该指令的类型有效,为 \([\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}] \href{../syntax/types.html#syntax-functype}{\rightarrow} [\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}]\)

\[\frac{ }{ C \href{../valid/instructions.html#valid-instr}{\vdash} \href{../syntax/instructions.html#syntax-shape}{\mathit{ishape}}\mathsf{.}\href{../syntax/instructions.html#syntax-instr-vec}{\mathsf{bitmask}} : [\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}] \href{../syntax/types.html#syntax-functype}{\rightarrow} [\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}] }\]

\(\href{../syntax/instructions.html#syntax-shape}{\mathit{ishape}}_1\mathsf{.}\href{../syntax/instructions.html#syntax-instr-vec}{\mathsf{dot}}\mathsf{\_}\href{../syntax/instructions.html#syntax-shape}{\mathit{ishape}}_2\mathsf{\_s}\)

  • 该指令的类型有效,为 \([\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}~\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}] \href{../syntax/types.html#syntax-functype}{\rightarrow} [\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}]\)

\[\frac{ }{ C \href{../valid/instructions.html#valid-instr}{\vdash} \href{../syntax/instructions.html#syntax-shape}{\mathit{ishape}}_1\mathsf{.}\href{../syntax/instructions.html#syntax-instr-vec}{\mathsf{dot}}\mathsf{\_}\href{../syntax/instructions.html#syntax-shape}{\mathit{ishape}}_2\mathsf{\_s} : [\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}~\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}] \href{../syntax/types.html#syntax-functype}{\rightarrow} [\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}] }\]

\(\href{../syntax/instructions.html#syntax-shape}{\mathit{ishape}}_1\mathsf{.}\href{../syntax/instructions.html#syntax-instr-vec}{\mathsf{extmul}}\mathsf{\_}\href{../syntax/instructions.html#syntax-half}{\mathit{half}}\mathsf{\_}\href{../syntax/instructions.html#syntax-shape}{\mathit{ishape}}_2\mathsf{\_}\href{../syntax/instructions.html#syntax-sx}{\mathit{sx}}\)

  • 该指令的类型有效,为 \([\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}~\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}] \href{../syntax/types.html#syntax-functype}{\rightarrow} [\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}]\)

\[\frac{ }{ C \href{../valid/instructions.html#valid-instr}{\vdash} \href{../syntax/instructions.html#syntax-shape}{\mathit{ishape}}_1\mathsf{.}\href{../syntax/instructions.html#syntax-instr-vec}{\mathsf{extmul}}\mathsf{\_}\href{../syntax/instructions.html#syntax-half}{\mathit{half}}\mathsf{\_}\href{../syntax/instructions.html#syntax-shape}{\mathit{ishape}}_2\mathsf{\_}\href{../syntax/instructions.html#syntax-sx}{\mathit{sx}} : [\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}~\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}] \href{../syntax/types.html#syntax-functype}{\rightarrow} [\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}] }\]

\(\href{../syntax/instructions.html#syntax-shape}{\mathit{ishape}}_1\mathsf{.}\href{../syntax/instructions.html#syntax-instr-vec}{\mathsf{extadd\_pairwise}}\mathsf{\_}\href{../syntax/instructions.html#syntax-shape}{\mathit{ishape}}_2\mathsf{\_}\href{../syntax/instructions.html#syntax-sx}{\mathit{sx}}\)

  • 该指令的类型有效,为 \([\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}] \href{../syntax/types.html#syntax-functype}{\rightarrow} [\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}]\)

\[\frac{ }{ C \href{../valid/instructions.html#valid-instr}{\vdash} \href{../syntax/instructions.html#syntax-shape}{\mathit{ishape}}_1\mathsf{.}\href{../syntax/instructions.html#syntax-instr-vec}{\mathsf{extadd\_pairwise}}\mathsf{\_}\href{../syntax/instructions.html#syntax-shape}{\mathit{ishape}}_2\mathsf{\_}\href{../syntax/instructions.html#syntax-sx}{\mathit{sx}} : [\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}] \href{../syntax/types.html#syntax-functype}{\rightarrow} [\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}] }\]

参数化指令

\(\href{../syntax/instructions.html#syntax-instr-parametric}{\mathsf{drop}}\)

  • 该指令对于任何操作数类型 \(t\),其类型有效值为 \([t] \href{../syntax/types.html#syntax-functype}{\rightarrow} []\)

\[\frac{ }{ C \href{../valid/instructions.html#valid-instr}{\vdash} \href{../syntax/instructions.html#syntax-instr-parametric}{\mathsf{drop}} : [t] \href{../syntax/types.html#syntax-functype}{\rightarrow} [] }\]

注意

未带注释的 \(\href{../syntax/instructions.html#syntax-instr-parametric}{\mathsf{drop}}\)\(\href{../syntax/instructions.html#syntax-instr-parametric}{\mathsf{select}}\) 都是值多态指令。

\(\href{../syntax/instructions.html#syntax-instr-parametric}{\mathsf{select}}~(t^\ast)^?\)

  • 如果存在 \(t^\ast\),则

    • \(t^\ast\) 的长度必须为 \(1\)

    • 则该指令类型有效值为 \([t^\ast~t^\ast~\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}] \href{../syntax/types.html#syntax-functype}{\rightarrow} [t^\ast]\)

  • 否则

    • 该指令对于任何操作数类型 \(t\)(其匹配某些数字类型向量类型),其类型有效值为 \([t~t~\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}] \href{../syntax/types.html#syntax-functype}{\rightarrow} [t]\)

\[\frac{ }{ C \href{../valid/instructions.html#valid-instr}{\vdash} \href{../syntax/instructions.html#syntax-instr-parametric}{\mathsf{select}}~t : [t~t~\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}] \href{../syntax/types.html#syntax-functype}{\rightarrow} [t] } \qquad \frac{ \vdash t \leq \href{../syntax/types.html#syntax-numtype}{\mathit{numtype}} }{ C \href{../valid/instructions.html#valid-instr}{\vdash} \href{../syntax/instructions.html#syntax-instr-parametric}{\mathsf{select}} : [t~t~\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}] \href{../syntax/types.html#syntax-functype}{\rightarrow} [t] } \qquad \frac{ \vdash t \leq \href{../syntax/types.html#syntax-vectype}{\mathit{vectype}} }{ C \href{../valid/instructions.html#valid-instr}{\vdash} \href{../syntax/instructions.html#syntax-instr-parametric}{\mathsf{select}} : [t~t~\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}] \href{../syntax/types.html#syntax-functype}{\rightarrow} [t] }\]

注意

在 WebAssembly 的未来版本中,\(\href{../syntax/instructions.html#syntax-instr-parametric}{\mathsf{select}}\) 可能会允许每个选项有多个值。

变量指令

\(\href{../syntax/instructions.html#syntax-instr-variable}{\mathsf{local.get}}~x\)

  • 局部变量 \(C.\href{../valid/conventions.html#context}{\mathsf{locals}}[x]\) 必须在上下文中定义。

  • \(t\)值类型 \(C.\href{../valid/conventions.html#context}{\mathsf{locals}}[x]\)

  • 则该指令类型有效值为 \([] \href{../syntax/types.html#syntax-functype}{\rightarrow} [t]\)

\[\frac{ C.\href{../valid/conventions.html#context}{\mathsf{locals}}[x] = t }{ C \href{../valid/instructions.html#valid-instr}{\vdash} \href{../syntax/instructions.html#syntax-instr-variable}{\mathsf{local.get}}~x : [] \href{../syntax/types.html#syntax-functype}{\rightarrow} [t] }\]

\(\href{../syntax/instructions.html#syntax-instr-variable}{\mathsf{local.set}}~x\)

  • 局部变量 \(C.\href{../valid/conventions.html#context}{\mathsf{locals}}[x]\) 必须在上下文中定义。

  • \(t\)值类型 \(C.\href{../valid/conventions.html#context}{\mathsf{locals}}[x]\)

  • 则该指令类型有效值为 \([t] \href{../syntax/types.html#syntax-functype}{\rightarrow} []\)

\[\frac{ C.\href{../valid/conventions.html#context}{\mathsf{locals}}[x] = t }{ C \href{../valid/instructions.html#valid-instr}{\vdash} \href{../syntax/instructions.html#syntax-instr-variable}{\mathsf{local.set}}~x : [t] \href{../syntax/types.html#syntax-functype}{\rightarrow} [] }\]

\(\href{../syntax/instructions.html#syntax-instr-variable}{\mathsf{local.tee}}~x\)

  • 局部变量 \(C.\href{../valid/conventions.html#context}{\mathsf{locals}}[x]\) 必须在上下文中定义。

  • \(t\)值类型 \(C.\href{../valid/conventions.html#context}{\mathsf{locals}}[x]\)

  • 则该指令类型有效值为 \([t] \href{../syntax/types.html#syntax-functype}{\rightarrow} [t]\)

\[\frac{ C.\href{../valid/conventions.html#context}{\mathsf{locals}}[x] = t }{ C \href{../valid/instructions.html#valid-instr}{\vdash} \href{../syntax/instructions.html#syntax-instr-variable}{\mathsf{local.tee}}~x : [t] \href{../syntax/types.html#syntax-functype}{\rightarrow} [t] }\]

\(\href{../syntax/instructions.html#syntax-instr-variable}{\mathsf{global.get}}~x\)

  • 全局变量 \(C.\href{../valid/conventions.html#context}{\mathsf{globals}}[x]\) 必须在上下文中定义。

  • \(\href{../syntax/types.html#syntax-mut}{\mathit{mut}}~t\)全局类型 \(C.\href{../valid/conventions.html#context}{\mathsf{globals}}[x]\)

  • 则该指令类型有效值为 \([] \href{../syntax/types.html#syntax-functype}{\rightarrow} [t]\)

\[\frac{ C.\href{../valid/conventions.html#context}{\mathsf{globals}}[x] = \href{../syntax/types.html#syntax-mut}{\mathit{mut}}~t }{ C \href{../valid/instructions.html#valid-instr}{\vdash} \href{../syntax/instructions.html#syntax-instr-variable}{\mathsf{global.get}}~x : [] \href{../syntax/types.html#syntax-functype}{\rightarrow} [t] }\]

\(\href{../syntax/instructions.html#syntax-instr-variable}{\mathsf{global.set}}~x\)

  • 全局变量 \(C.\href{../valid/conventions.html#context}{\mathsf{globals}}[x]\) 必须在上下文中定义。

  • \(\href{../syntax/types.html#syntax-mut}{\mathit{mut}}~t\)全局类型 \(C.\href{../valid/conventions.html#context}{\mathsf{globals}}[x]\)

  • 可变性 \(\href{../syntax/types.html#syntax-mut}{\mathit{mut}}\) 必须为 \(\href{../syntax/types.html#syntax-mut}{\mathsf{var}}\)

  • 则该指令类型有效值为 \([t] \href{../syntax/types.html#syntax-functype}{\rightarrow} []\)

\[\frac{ C.\href{../valid/conventions.html#context}{\mathsf{globals}}[x] = \href{../syntax/types.html#syntax-mut}{\mathsf{var}}~t }{ C \href{../valid/instructions.html#valid-instr}{\vdash} \href{../syntax/instructions.html#syntax-instr-variable}{\mathsf{global.set}}~x : [t] \href{../syntax/types.html#syntax-functype}{\rightarrow} [] }\]

表指令

\(\href{../syntax/instructions.html#syntax-instr-table}{\mathsf{table.get}}~x\)

  • \(C.\href{../valid/conventions.html#context}{\mathsf{tables}}[x]\) 必须在上下文中定义。

  • \(\href{../syntax/types.html#syntax-limits}{\mathit{limits}}~t\)表类型 \(C.\href{../valid/conventions.html#context}{\mathsf{tables}}[x]\)

  • 则该指令类型有效值为 \([\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}] \href{../syntax/types.html#syntax-functype}{\rightarrow} [t]\)

\[\frac{ C.\href{../valid/conventions.html#context}{\mathsf{tables}}[x] = \href{../syntax/types.html#syntax-limits}{\mathit{limits}}~t }{ C \href{../valid/instructions.html#valid-instr}{\vdash} \href{../syntax/instructions.html#syntax-instr-table}{\mathsf{table.get}}~x : [\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}] \href{../syntax/types.html#syntax-functype}{\rightarrow} [t] }\]

\(\href{../syntax/instructions.html#syntax-instr-table}{\mathsf{table.set}}~x\)

  • \(C.\href{../valid/conventions.html#context}{\mathsf{tables}}[x]\) 必须在上下文中定义。

  • \(\href{../syntax/types.html#syntax-limits}{\mathit{limits}}~t\)表类型 \(C.\href{../valid/conventions.html#context}{\mathsf{tables}}[x]\)

  • 则该指令的类型为 \([\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}~t] \href{../syntax/types.html#syntax-functype}{\rightarrow} []\) 时有效。

\[\frac{ C.\href{../valid/conventions.html#context}{\mathsf{tables}}[x] = \href{../syntax/types.html#syntax-limits}{\mathit{limits}}~t }{ C \href{../valid/instructions.html#valid-instr}{\vdash} \href{../syntax/instructions.html#syntax-instr-table}{\mathsf{table.set}}~x : [\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}~t] \href{../syntax/types.html#syntax-functype}{\rightarrow} [] }\]

\(\href{../syntax/instructions.html#syntax-instr-table}{\mathsf{table.size}}~x\)

  • \(C.\href{../valid/conventions.html#context}{\mathsf{tables}}[x]\) 必须在上下文中定义。

  • 则该指令的类型为 \([] \href{../syntax/types.html#syntax-functype}{\rightarrow} [\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}]\) 时有效。

\[\frac{ C.\href{../valid/conventions.html#context}{\mathsf{tables}}[x] = \href{../syntax/types.html#syntax-tabletype}{\mathit{tabletype}} }{ C \href{../valid/instructions.html#valid-instr}{\vdash} \href{../syntax/instructions.html#syntax-instr-table}{\mathsf{table.size}}~x : [] \href{../syntax/types.html#syntax-functype}{\rightarrow} [\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}] }\]

\(\href{../syntax/instructions.html#syntax-instr-table}{\mathsf{table.grow}}~x\)

  • \(C.\href{../valid/conventions.html#context}{\mathsf{tables}}[x]\) 必须在上下文中定义。

  • \(\href{../syntax/types.html#syntax-limits}{\mathit{limits}}~t\)表类型 \(C.\href{../valid/conventions.html#context}{\mathsf{tables}}[x]\)

  • 则该指令的类型为 \([t~\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}] \href{../syntax/types.html#syntax-functype}{\rightarrow} [\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}]\) 时有效。

\[\frac{ C.\href{../valid/conventions.html#context}{\mathsf{tables}}[x] = \href{../syntax/types.html#syntax-limits}{\mathit{limits}}~t }{ C \href{../valid/instructions.html#valid-instr}{\vdash} \href{../syntax/instructions.html#syntax-instr-table}{\mathsf{table.grow}}~x : [t~\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}] \href{../syntax/types.html#syntax-functype}{\rightarrow} [\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}] }\]

\(\href{../syntax/instructions.html#syntax-instr-table}{\mathsf{table.fill}}~x\)

  • \(C.\href{../valid/conventions.html#context}{\mathsf{tables}}[x]\) 必须在上下文中定义。

  • \(\href{../syntax/types.html#syntax-limits}{\mathit{limits}}~t\)表类型 \(C.\href{../valid/conventions.html#context}{\mathsf{tables}}[x]\)

  • 则该指令的类型为 \([\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}~t~\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}] \href{../syntax/types.html#syntax-functype}{\rightarrow} []\) 时有效。

\[\frac{ C.\href{../valid/conventions.html#context}{\mathsf{tables}}[x] = \href{../syntax/types.html#syntax-limits}{\mathit{limits}}~t }{ C \href{../valid/instructions.html#valid-instr}{\vdash} \href{../syntax/instructions.html#syntax-instr-table}{\mathsf{table.fill}}~x : [\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}~t~\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}] \href{../syntax/types.html#syntax-functype}{\rightarrow} [] }\]

\(\href{../syntax/instructions.html#syntax-instr-table}{\mathsf{table.copy}}~x~y\)

  • \(C.\href{../valid/conventions.html#context}{\mathsf{tables}}[x]\) 必须在上下文中定义。

  • \(\href{../syntax/types.html#syntax-limits}{\mathit{limits}}_1~t_1\)表类型 \(C.\href{../valid/conventions.html#context}{\mathsf{tables}}[x]\)

  • \(C.\href{../valid/conventions.html#context}{\mathsf{tables}}[y]\) 必须在上下文中定义。

  • \(\href{../syntax/types.html#syntax-limits}{\mathit{limits}}_2~t_2\)表类型 \(C.\href{../valid/conventions.html#context}{\mathsf{tables}}[y]\)

  • 引用类型 \(t_1\) 必须与 \(t_2\) 相同。

  • 则该指令的类型为 \([\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}~\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}~\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}] \href{../syntax/types.html#syntax-functype}{\rightarrow} []\) 时有效。

\[\frac{ C.\href{../valid/conventions.html#context}{\mathsf{tables}}[x] = \href{../syntax/types.html#syntax-limits}{\mathit{limits}}_1~t \qquad C.\href{../valid/conventions.html#context}{\mathsf{tables}}[y] = \href{../syntax/types.html#syntax-limits}{\mathit{limits}}_2~t }{ C \href{../valid/instructions.html#valid-instr}{\vdash} \href{../syntax/instructions.html#syntax-instr-table}{\mathsf{table.copy}}~x~y : [\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}~\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}~\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}] \href{../syntax/types.html#syntax-functype}{\rightarrow} [] }\]

\(\href{../syntax/instructions.html#syntax-instr-table}{\mathsf{table.init}}~x~y\)

  • \(C.\href{../valid/conventions.html#context}{\mathsf{tables}}[x]\) 必须在上下文中定义。

  • \(\href{../syntax/types.html#syntax-limits}{\mathit{limits}}~t_1\)表类型 \(C.\href{../valid/conventions.html#context}{\mathsf{tables}}[x]\)

  • 元素段 \(C.\href{../valid/conventions.html#context}{\mathsf{elems}}[y]\) 必须在上下文中定义。

  • \(t_2\)引用类型 \(C.\href{../valid/conventions.html#context}{\mathsf{elems}}[y]\)

  • 引用类型 \(t_1\) 必须与 \(t_2\) 相同。

  • 则该指令的类型为 \([\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}~\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}~\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}] \href{../syntax/types.html#syntax-functype}{\rightarrow} []\) 时有效。

\[\frac{ C.\href{../valid/conventions.html#context}{\mathsf{tables}}[x] = \href{../syntax/types.html#syntax-limits}{\mathit{limits}}~t \qquad C.\href{../valid/conventions.html#context}{\mathsf{elems}}[y] = t }{ C \href{../valid/instructions.html#valid-instr}{\vdash} \href{../syntax/instructions.html#syntax-instr-table}{\mathsf{table.init}}~x~y : [\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}~\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}~\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}] \href{../syntax/types.html#syntax-functype}{\rightarrow} [] }\]

\(\href{../syntax/instructions.html#syntax-instr-table}{\mathsf{elem.drop}}~x\)

  • 元素段 \(C.\href{../valid/conventions.html#context}{\mathsf{elems}}[x]\) 必须在上下文中定义。

  • 则该指令的类型为 \([] \href{../syntax/types.html#syntax-functype}{\rightarrow} []\) 时有效。

\[\frac{ C.\href{../valid/conventions.html#context}{\mathsf{elems}}[x] = t }{ C \href{../valid/instructions.html#valid-instr}{\vdash} \href{../syntax/instructions.html#syntax-instr-table}{\mathsf{elem.drop}}~x : [] \href{../syntax/types.html#syntax-functype}{\rightarrow} [] }\]

内存指令

\(t\mathsf{.}\href{../syntax/instructions.html#syntax-instr-memory}{\mathsf{load}}~\href{../syntax/instructions.html#syntax-memarg}{\mathit{memarg}}\)

  • 内存 \(C.\href{../valid/conventions.html#context}{\mathsf{mems}}[0]\) 必须在上下文中定义。

  • 对齐 \(2^{\href{../syntax/instructions.html#syntax-memarg}{\mathit{memarg}}.\href{../syntax/instructions.html#syntax-instr-memory}{\mathsf{align}}}\) 不能大于 \(t\)位宽 除以 \(8\)

  • 则该指令类型有效值为 \([\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}] \href{../syntax/types.html#syntax-functype}{\rightarrow} [t]\)

\[\frac{ C.\href{../valid/conventions.html#context}{\mathsf{mems}}[0] = \href{../syntax/types.html#syntax-memtype}{\mathit{memtype}} \qquad 2^{\href{../syntax/instructions.html#syntax-memarg}{\mathit{memarg}}.\href{../syntax/instructions.html#syntax-instr-memory}{\mathsf{align}}} \leq |t|/8 }{ C \href{../valid/instructions.html#valid-instr}{\vdash} t\mathsf{.load}~\href{../syntax/instructions.html#syntax-memarg}{\mathit{memarg}} : [\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}] \href{../syntax/types.html#syntax-functype}{\rightarrow} [t] }\]

\(t\mathsf{.}\href{../syntax/instructions.html#syntax-instr-memory}{\mathsf{load}}{N}\mathsf{\_}\href{../syntax/instructions.html#syntax-sx}{\mathit{sx}}~\href{../syntax/instructions.html#syntax-memarg}{\mathit{memarg}}\)

  • 内存 \(C.\href{../valid/conventions.html#context}{\mathsf{mems}}[0]\) 必须在上下文中定义。

  • 对齐 \(2^{\href{../syntax/instructions.html#syntax-memarg}{\mathit{memarg}}.\href{../syntax/instructions.html#syntax-instr-memory}{\mathsf{align}}}\) 不能大于 \(N/8\)

  • 则该指令类型有效值为 \([\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}] \href{../syntax/types.html#syntax-functype}{\rightarrow} [t]\)

\[\frac{ C.\href{../valid/conventions.html#context}{\mathsf{mems}}[0] = \href{../syntax/types.html#syntax-memtype}{\mathit{memtype}} \qquad 2^{\href{../syntax/instructions.html#syntax-memarg}{\mathit{memarg}}.\href{../syntax/instructions.html#syntax-instr-memory}{\mathsf{align}}} \leq N/8 }{ C \href{../valid/instructions.html#valid-instr}{\vdash} t\mathsf{.load}N\mathsf{\_}\href{../syntax/instructions.html#syntax-sx}{\mathit{sx}}~\href{../syntax/instructions.html#syntax-memarg}{\mathit{memarg}} : [\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}] \href{../syntax/types.html#syntax-functype}{\rightarrow} [t] }\]

\(t\mathsf{.}\href{../syntax/instructions.html#syntax-instr-memory}{\mathsf{store}}~\href{../syntax/instructions.html#syntax-memarg}{\mathit{memarg}}\)

  • 内存 \(C.\href{../valid/conventions.html#context}{\mathsf{mems}}[0]\) 必须在上下文中定义。

  • 对齐 \(2^{\href{../syntax/instructions.html#syntax-memarg}{\mathit{memarg}}.\href{../syntax/instructions.html#syntax-instr-memory}{\mathsf{align}}}\) 不能大于 \(t\)位宽 除以 \(8\)

  • 则该指令的类型为 \([\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}~t] \href{../syntax/types.html#syntax-functype}{\rightarrow} []\) 时有效。

\[\frac{ C.\href{../valid/conventions.html#context}{\mathsf{mems}}[0] = \href{../syntax/types.html#syntax-memtype}{\mathit{memtype}} \qquad 2^{\href{../syntax/instructions.html#syntax-memarg}{\mathit{memarg}}.\href{../syntax/instructions.html#syntax-instr-memory}{\mathsf{align}}} \leq |t|/8 }{ C \href{../valid/instructions.html#valid-instr}{\vdash} t\mathsf{.store}~\href{../syntax/instructions.html#syntax-memarg}{\mathit{memarg}} : [\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}~t] \href{../syntax/types.html#syntax-functype}{\rightarrow} [] }\]

\(t\mathsf{.}\href{../syntax/instructions.html#syntax-instr-memory}{\mathsf{store}}{N}~\href{../syntax/instructions.html#syntax-memarg}{\mathit{memarg}}\)

  • 内存 \(C.\href{../valid/conventions.html#context}{\mathsf{mems}}[0]\) 必须在上下文中定义。

  • 对齐 \(2^{\href{../syntax/instructions.html#syntax-memarg}{\mathit{memarg}}.\href{../syntax/instructions.html#syntax-instr-memory}{\mathsf{align}}}\) 不能大于 \(N/8\)

  • 则该指令的类型为 \([\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}~t] \href{../syntax/types.html#syntax-functype}{\rightarrow} []\) 时有效。

\[\frac{ C.\href{../valid/conventions.html#context}{\mathsf{mems}}[0] = \href{../syntax/types.html#syntax-memtype}{\mathit{memtype}} \qquad 2^{\href{../syntax/instructions.html#syntax-memarg}{\mathit{memarg}}.\href{../syntax/instructions.html#syntax-instr-memory}{\mathsf{align}}} \leq N/8 }{ C \href{../valid/instructions.html#valid-instr}{\vdash} t\mathsf{.store}N~\href{../syntax/instructions.html#syntax-memarg}{\mathit{memarg}} : [\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}~t] \href{../syntax/types.html#syntax-functype}{\rightarrow} [] }\]

\(\mathsf{v128.}\href{../syntax/instructions.html#syntax-instr-memory}{\mathsf{load}}{N}\mathsf{x}M\_\href{../syntax/instructions.html#syntax-sx}{\mathit{sx}}~\href{../syntax/instructions.html#syntax-memarg}{\mathit{memarg}}\)

  • 内存 \(C.\href{../valid/conventions.html#context}{\mathsf{mems}}[0]\) 必须在上下文中定义。

  • 对齐 \(2^{\href{../syntax/instructions.html#syntax-memarg}{\mathit{memarg}}.\href{../syntax/instructions.html#syntax-instr-memory}{\mathsf{align}}}\) 不能大于 \(N/8 \cdot M\)

  • 则该指令的类型为 \([\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}] \href{../syntax/types.html#syntax-functype}{\rightarrow} [\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}]\) 时有效。

\[\frac{ C.\href{../valid/conventions.html#context}{\mathsf{mems}}[0] = \href{../syntax/types.html#syntax-memtype}{\mathit{memtype}} \qquad 2^{\href{../syntax/instructions.html#syntax-memarg}{\mathit{memarg}}.\href{../syntax/instructions.html#syntax-instr-memory}{\mathsf{align}}} \leq N/8 \cdot M }{ C \href{../valid/instructions.html#valid-instr}{\vdash} \mathsf{v128.}\href{../syntax/instructions.html#syntax-instr-memory}{\mathsf{load}}{N}\mathsf{x}M\_\href{../syntax/instructions.html#syntax-sx}{\mathit{sx}}~\href{../syntax/instructions.html#syntax-memarg}{\mathit{memarg}} : [\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}] \href{../syntax/types.html#syntax-functype}{\rightarrow} [\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}] }\]

\(\mathsf{v128.}\href{../syntax/instructions.html#syntax-instr-memory}{\mathsf{load}}{N}\mathsf{\_splat}~\href{../syntax/instructions.html#syntax-memarg}{\mathit{memarg}}\)

  • 内存 \(C.\href{../valid/conventions.html#context}{\mathsf{mems}}[0]\) 必须在上下文中定义。

  • 对齐 \(2^{\href{../syntax/instructions.html#syntax-memarg}{\mathit{memarg}}.\href{../syntax/instructions.html#syntax-instr-memory}{\mathsf{align}}}\) 不能大于 \(N/8\)

  • 则该指令的类型为 \([\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}] \href{../syntax/types.html#syntax-functype}{\rightarrow} [\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}]\) 时有效。

\[\frac{ C.\href{../valid/conventions.html#context}{\mathsf{mems}}[0] = \href{../syntax/types.html#syntax-memtype}{\mathit{memtype}} \qquad 2^{\href{../syntax/instructions.html#syntax-memarg}{\mathit{memarg}}.\href{../syntax/instructions.html#syntax-instr-memory}{\mathsf{align}}} \leq N/8 }{ C \href{../valid/instructions.html#valid-instr}{\vdash} \mathsf{v128.}\href{../syntax/instructions.html#syntax-instr-memory}{\mathsf{load}}{N}\mathsf{\_splat}~\href{../syntax/instructions.html#syntax-memarg}{\mathit{memarg}} : [\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}] \href{../syntax/types.html#syntax-functype}{\rightarrow} [\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}] }\]

\(\mathsf{v128.}\href{../syntax/instructions.html#syntax-instr-memory}{\mathsf{load}}{N}\mathsf{\_zero}~\href{../syntax/instructions.html#syntax-memarg}{\mathit{memarg}}\)

  • 内存 \(C.\href{../valid/conventions.html#context}{\mathsf{mems}}[0]\) 必须在上下文中定义。

  • 对齐 \(2^{\href{../syntax/instructions.html#syntax-memarg}{\mathit{memarg}}.\href{../syntax/instructions.html#syntax-instr-memory}{\mathsf{align}}}\) 不能大于 \(N/8\)

  • 则该指令的类型为 \([\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}] \href{../syntax/types.html#syntax-functype}{\rightarrow} [\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}]\) 时有效。

\[\frac{ C.\href{../valid/conventions.html#context}{\mathsf{mems}}[0] = \href{../syntax/types.html#syntax-memtype}{\mathit{memtype}} \qquad 2^{\href{../syntax/instructions.html#syntax-memarg}{\mathit{memarg}}.\href{../syntax/instructions.html#syntax-instr-memory}{\mathsf{align}}} \leq N/8 }{ C \href{../valid/instructions.html#valid-instr}{\vdash} \mathsf{v128.}\href{../syntax/instructions.html#syntax-instr-memory}{\mathsf{load}}{N}\mathsf{\_zero}~\href{../syntax/instructions.html#syntax-memarg}{\mathit{memarg}} : [\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}] \href{../syntax/types.html#syntax-functype}{\rightarrow} [\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}] }\]

\(\mathsf{v128.}\href{../syntax/instructions.html#syntax-instr-memory}{\mathsf{load}}{N}\mathsf{\_lane}~\href{../syntax/instructions.html#syntax-memarg}{\mathit{memarg}}~\href{../syntax/instructions.html#syntax-laneidx}{\mathit{laneidx}}\)

  • 通道索引 \(\href{../syntax/instructions.html#syntax-laneidx}{\mathit{laneidx}}\) 必须小于 \(128/N\)

  • 内存 \(C.\href{../valid/conventions.html#context}{\mathsf{mems}}[0]\) 必须在上下文中定义。

  • 对齐 \(2^{\href{../syntax/instructions.html#syntax-memarg}{\mathit{memarg}}.\href{../syntax/instructions.html#syntax-instr-memory}{\mathsf{align}}}\) 不能大于 \(N/8\)

  • 然后,该指令的类型有效,为 \([\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}~\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}] \href{../syntax/types.html#syntax-functype}{\rightarrow} [\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}]\)

\[\frac{ \href{../syntax/instructions.html#syntax-laneidx}{\mathit{laneidx}} < 128/N \qquad C.\href{../valid/conventions.html#context}{\mathsf{mems}}[0] = \href{../syntax/types.html#syntax-memtype}{\mathit{memtype}} \qquad 2^{\href{../syntax/instructions.html#syntax-memarg}{\mathit{memarg}}.\href{../syntax/instructions.html#syntax-instr-memory}{\mathsf{align}}} \leq N/8 }{ C \href{../valid/instructions.html#valid-instr}{\vdash} \mathsf{v128.}\href{../syntax/instructions.html#syntax-instr-memory}{\mathsf{load}}{N}\mathsf{\_lane}~\href{../syntax/instructions.html#syntax-memarg}{\mathit{memarg}}~\href{../syntax/instructions.html#syntax-laneidx}{\mathit{laneidx}} : [\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}~\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}] \href{../syntax/types.html#syntax-functype}{\rightarrow} [\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}] }\]

\(\mathsf{v128.}\href{../syntax/instructions.html#syntax-instr-memory}{\mathsf{store}}{N}\mathsf{\_lane}~\href{../syntax/instructions.html#syntax-memarg}{\mathit{memarg}}~\href{../syntax/instructions.html#syntax-laneidx}{\mathit{laneidx}}\)

  • 通道索引 \(\href{../syntax/instructions.html#syntax-laneidx}{\mathit{laneidx}}\) 必须小于 \(128/N\)

  • 内存 \(C.\href{../valid/conventions.html#context}{\mathsf{mems}}[0]\) 必须在上下文中定义。

  • 对齐 \(2^{\href{../syntax/instructions.html#syntax-memarg}{\mathit{memarg}}.\href{../syntax/instructions.html#syntax-instr-memory}{\mathsf{align}}}\) 不能大于 \(N/8\)

  • 然后,该指令的类型有效,为 \([\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}~\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}] \href{../syntax/types.html#syntax-functype}{\rightarrow} [\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}]\)

\[\frac{ \href{../syntax/instructions.html#syntax-laneidx}{\mathit{laneidx}} < 128/N \qquad C.\href{../valid/conventions.html#context}{\mathsf{mems}}[0] = \href{../syntax/types.html#syntax-memtype}{\mathit{memtype}} \qquad 2^{\href{../syntax/instructions.html#syntax-memarg}{\mathit{memarg}}.\href{../syntax/instructions.html#syntax-instr-memory}{\mathsf{align}}} \leq N/8 }{ C \href{../valid/instructions.html#valid-instr}{\vdash} \mathsf{v128.}\href{../syntax/instructions.html#syntax-instr-memory}{\mathsf{store}}{N}\mathsf{\_lane}~\href{../syntax/instructions.html#syntax-memarg}{\mathit{memarg}}~\href{../syntax/instructions.html#syntax-laneidx}{\mathit{laneidx}} : [\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}~\href{../syntax/types.html#syntax-valtype}{\mathsf{v128}}] \href{../syntax/types.html#syntax-functype}{\rightarrow} [] }\]

\(\href{../syntax/instructions.html#syntax-instr-memory}{\mathsf{memory.size}}\)

  • 内存 \(C.\href{../valid/conventions.html#context}{\mathsf{mems}}[0]\) 必须在上下文中定义。

  • 则该指令的类型为 \([] \href{../syntax/types.html#syntax-functype}{\rightarrow} [\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}]\) 时有效。

\[\frac{ C.\href{../valid/conventions.html#context}{\mathsf{mems}}[0] = \href{../syntax/types.html#syntax-memtype}{\mathit{memtype}} }{ C \href{../valid/instructions.html#valid-instr}{\vdash} \href{../syntax/instructions.html#syntax-instr-memory}{\mathsf{memory.size}} : [] \href{../syntax/types.html#syntax-functype}{\rightarrow} [\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}] }\]

\(\href{../syntax/instructions.html#syntax-instr-memory}{\mathsf{memory.grow}}\)

  • 内存 \(C.\href{../valid/conventions.html#context}{\mathsf{mems}}[0]\) 必须在上下文中定义。

  • 然后,该指令的类型有效,为 \([\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}] \href{../syntax/types.html#syntax-functype}{\rightarrow} [\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}]\)

\[\frac{ C.\href{../valid/conventions.html#context}{\mathsf{mems}}[0] = \href{../syntax/types.html#syntax-memtype}{\mathit{memtype}} }{ C \href{../valid/instructions.html#valid-instr}{\vdash} \href{../syntax/instructions.html#syntax-instr-memory}{\mathsf{memory.grow}} : [\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}] \href{../syntax/types.html#syntax-functype}{\rightarrow} [\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}] }\]

\(\href{../syntax/instructions.html#syntax-instr-memory}{\mathsf{memory.fill}}\)

  • 内存 \(C.\href{../valid/conventions.html#context}{\mathsf{mems}}[0]\) 必须在上下文中定义。

  • 则该指令的类型为 \([\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}~\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}~\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}] \href{../syntax/types.html#syntax-functype}{\rightarrow} []\) 时有效。

\[\frac{ C.\href{../valid/conventions.html#context}{\mathsf{mems}}[0] = \href{../syntax/types.html#syntax-memtype}{\mathit{memtype}} }{ C \href{../valid/instructions.html#valid-instr}{\vdash} \href{../syntax/instructions.html#syntax-instr-memory}{\mathsf{memory.fill}} : [\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}~\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}~\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}] \href{../syntax/types.html#syntax-functype}{\rightarrow} [] }\]

\(\href{../syntax/instructions.html#syntax-instr-memory}{\mathsf{memory.copy}}\)

  • 内存 \(C.\href{../valid/conventions.html#context}{\mathsf{mems}}[0]\) 必须在上下文中定义。

  • 则该指令的类型为 \([\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}~\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}~\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}] \href{../syntax/types.html#syntax-functype}{\rightarrow} []\) 时有效。

\[\frac{ C.\href{../valid/conventions.html#context}{\mathsf{mems}}[0] = \href{../syntax/types.html#syntax-memtype}{\mathit{memtype}} }{ C \href{../valid/instructions.html#valid-instr}{\vdash} \href{../syntax/instructions.html#syntax-instr-memory}{\mathsf{memory.copy}} : [\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}~\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}~\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}] \href{../syntax/types.html#syntax-functype}{\rightarrow} [] }\]

\(\href{../syntax/instructions.html#syntax-instr-memory}{\mathsf{memory.init}}~x\)

  • 内存 \(C.\href{../valid/conventions.html#context}{\mathsf{mems}}[0]\) 必须在上下文中定义。

  • 数据段 \(C.\href{../valid/conventions.html#context}{\mathsf{datas}}[x]\) 必须在上下文中定义。

  • 则该指令的类型为 \([\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}~\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}~\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}] \href{../syntax/types.html#syntax-functype}{\rightarrow} []\) 时有效。

\[\frac{ C.\href{../valid/conventions.html#context}{\mathsf{mems}}[0] = \href{../syntax/types.html#syntax-memtype}{\mathit{memtype}} \qquad C.\href{../valid/conventions.html#context}{\mathsf{datas}}[x] = {\mathrel{\mbox{ok}}} }{ C \href{../valid/instructions.html#valid-instr}{\vdash} \href{../syntax/instructions.html#syntax-instr-memory}{\mathsf{memory.init}}~x : [\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}~\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}~\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}] \href{../syntax/types.html#syntax-functype}{\rightarrow} [] }\]

\(\href{../syntax/instructions.html#syntax-instr-memory}{\mathsf{data.drop}}~x\)

  • 数据段 \(C.\href{../valid/conventions.html#context}{\mathsf{datas}}[x]\) 必须在上下文中定义。

  • 则该指令的类型为 \([] \href{../syntax/types.html#syntax-functype}{\rightarrow} []\) 时有效。

\[\frac{ C.\href{../valid/conventions.html#context}{\mathsf{datas}}[x] = {\mathrel{\mbox{ok}}} }{ C \href{../valid/instructions.html#valid-instr}{\vdash} \href{../syntax/instructions.html#syntax-instr-memory}{\mathsf{data.drop}}~x : [] \href{../syntax/types.html#syntax-functype}{\rightarrow} [] }\]

控制指令

\(\href{../syntax/instructions.html#syntax-instr-control}{\mathsf{nop}}\)

  • 该指令的类型有效,为 \([] \href{../syntax/types.html#syntax-functype}{\rightarrow} []\)

\[\frac{ }{ C \href{../valid/instructions.html#valid-instr}{\vdash} \href{../syntax/instructions.html#syntax-instr-control}{\mathsf{nop}} : [] \href{../syntax/types.html#syntax-functype}{\rightarrow} [] }\]

\(\href{../syntax/instructions.html#syntax-instr-control}{\mathsf{unreachable}}\)

  • 该指令的类型有效,为 \([t_1^\ast] \href{../syntax/types.html#syntax-functype}{\rightarrow} [t_2^\ast]\),对于任何操作数类型序列 operand types \(t_1^\ast\)\(t_2^\ast\)

\[\frac{ }{ C \href{../valid/instructions.html#valid-instr}{\vdash} \href{../syntax/instructions.html#syntax-instr-control}{\mathsf{unreachable}} : [t_1^\ast] \href{../syntax/types.html#syntax-functype}{\rightarrow} [t_2^\ast] }\]

注意

\(\href{../syntax/instructions.html#syntax-instr-control}{\mathsf{unreachable}}\) 指令是 stack-polymorphic 的。

\(\href{../syntax/instructions.html#syntax-instr-control}{\mathsf{block}}~\href{../syntax/instructions.html#syntax-blocktype}{\mathit{blocktype}}~\href{../syntax/instructions.html#syntax-instr}{\mathit{instr}}^\ast~\href{../syntax/instructions.html#syntax-instr-control}{\mathsf{end}}\)

  • 块类型必须作为某个函数类型 function type \([t_1^\ast] \href{../syntax/types.html#syntax-functype}{\rightarrow} [t_2^\ast]\) 有效

  • \(C'\)\(C\) 为相同的上下文 context,但将结果类型 result type \([t_2^\ast]\) 添加到 \(\href{../valid/conventions.html#context}{\mathsf{labels}}\) 向量的前端。

  • 在上下文 \(C'\) 下,指令序列 \(\href{../syntax/instructions.html#syntax-instr}{\mathit{instr}}^\ast\) 必须 有效,其类型为 \([t_1^\ast] \href{../syntax/types.html#syntax-functype}{\rightarrow} [t_2^\ast]\)

  • 然后,复合指令的类型有效,为 \([t_1^\ast] \href{../syntax/types.html#syntax-functype}{\rightarrow} [t_2^\ast]\)

\[\frac{ C \href{../valid/types.html#valid-blocktype}{\vdash} \href{../syntax/instructions.html#syntax-blocktype}{\mathit{blocktype}} : [t_1^\ast] \href{../syntax/types.html#syntax-functype}{\rightarrow} [t_2^\ast] \qquad C,\href{../valid/conventions.html#context}{\mathsf{labels}}\,[t_2^\ast] \href{../valid/instructions.html#valid-instr-seq}{\vdash} \href{../syntax/instructions.html#syntax-instr}{\mathit{instr}}^\ast : [t_1^\ast] \href{../syntax/types.html#syntax-functype}{\rightarrow} [t_2^\ast] }{ C \href{../valid/instructions.html#valid-instr}{\vdash} \href{../syntax/instructions.html#syntax-instr-control}{\mathsf{block}}~\href{../syntax/instructions.html#syntax-blocktype}{\mathit{blocktype}}~\href{../syntax/instructions.html#syntax-instr}{\mathit{instr}}^\ast~\href{../syntax/instructions.html#syntax-instr-control}{\mathsf{end}} : [t_1^\ast] \href{../syntax/types.html#syntax-functype}{\rightarrow} [t_2^\ast] }\]

注意

符号 \(C,\href{../valid/conventions.html#context}{\mathsf{labels}}\,[t^\ast]\) 将新的标签类型插入索引 \(0\) 处,并将所有其他标签类型向后移动。notation

\(\href{../syntax/instructions.html#syntax-instr-control}{\mathsf{loop}}~\href{../syntax/instructions.html#syntax-blocktype}{\mathit{blocktype}}~\href{../syntax/instructions.html#syntax-instr}{\mathit{instr}}^\ast~\href{../syntax/instructions.html#syntax-instr-control}{\mathsf{end}}\)

  • 块类型必须作为某个函数类型 function type \([t_1^\ast] \href{../syntax/types.html#syntax-functype}{\rightarrow} [t_2^\ast]\) 有效

  • \(C'\)\(C\) 为相同的上下文 context,但将结果类型 result type \([t_1^\ast]\) 添加到 \(\href{../valid/conventions.html#context}{\mathsf{labels}}\) 向量的前端。

  • 在上下文 \(C'\) 下,指令序列 \(\href{../syntax/instructions.html#syntax-instr}{\mathit{instr}}^\ast\) 必须 有效,其类型为 \([t_1^\ast] \href{../syntax/types.html#syntax-functype}{\rightarrow} [t_2^\ast]\)

  • 然后,复合指令的类型有效,为 \([t_1^\ast] \href{../syntax/types.html#syntax-functype}{\rightarrow} [t_2^\ast]\)

\[\frac{ C \href{../valid/types.html#valid-blocktype}{\vdash} \href{../syntax/instructions.html#syntax-blocktype}{\mathit{blocktype}} : [t_1^\ast] \href{../syntax/types.html#syntax-functype}{\rightarrow} [t_2^\ast] \qquad C,\href{../valid/conventions.html#context}{\mathsf{labels}}\,[t_1^\ast] \href{../valid/instructions.html#valid-instr-seq}{\vdash} \href{../syntax/instructions.html#syntax-instr}{\mathit{instr}}^\ast : [t_1^\ast] \href{../syntax/types.html#syntax-functype}{\rightarrow} [t_2^\ast] }{ C \href{../valid/instructions.html#valid-instr}{\vdash} \href{../syntax/instructions.html#syntax-instr-control}{\mathsf{loop}}~\href{../syntax/instructions.html#syntax-blocktype}{\mathit{blocktype}}~\href{../syntax/instructions.html#syntax-instr}{\mathit{instr}}^\ast~\href{../syntax/instructions.html#syntax-instr-control}{\mathsf{end}} : [t_1^\ast] \href{../syntax/types.html#syntax-functype}{\rightarrow} [t_2^\ast] }\]

注意

符号 \(C,\href{../valid/conventions.html#context}{\mathsf{labels}}\,[t^\ast]\) 将新的标签类型插入索引 \(0\) 处,并将所有其他标签类型向后移动。notation

\(\href{../syntax/instructions.html#syntax-instr-control}{\mathsf{if}}~\href{../syntax/instructions.html#syntax-blocktype}{\mathit{blocktype}}~\href{../syntax/instructions.html#syntax-instr}{\mathit{instr}}_1^\ast~\href{../syntax/instructions.html#syntax-instr-control}{\mathsf{else}}~\href{../syntax/instructions.html#syntax-instr}{\mathit{instr}}_2^\ast~\href{../syntax/instructions.html#syntax-instr-control}{\mathsf{end}}\)

  • 块类型必须作为某个函数类型 function type \([t_1^\ast] \href{../syntax/types.html#syntax-functype}{\rightarrow} [t_2^\ast]\) 有效

  • \(C'\)\(C\) 为相同的上下文 context,但将结果类型 result type \([t_2^\ast]\) 添加到 \(\href{../valid/conventions.html#context}{\mathsf{labels}}\) 向量的前端。

  • 在上下文 \(C'\) 下,指令序列 \(\href{../syntax/instructions.html#syntax-instr}{\mathit{instr}}_1^\ast\) 必须 有效,其类型为 \([t_1^\ast] \href{../syntax/types.html#syntax-functype}{\rightarrow} [t_2^\ast]\)

  • 在上下文 \(C'\) 下,指令序列 \(\href{../syntax/instructions.html#syntax-instr}{\mathit{instr}}_2^\ast\) 必须 有效,其类型为 \([t_1^\ast] \href{../syntax/types.html#syntax-functype}{\rightarrow} [t_2^\ast]\)

  • 然后,复合指令的类型有效,为 \([t_1^\ast~\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}] \href{../syntax/types.html#syntax-functype}{\rightarrow} [t_2^\ast]\)

\[\frac{ C \href{../valid/types.html#valid-blocktype}{\vdash} \href{../syntax/instructions.html#syntax-blocktype}{\mathit{blocktype}} : [t_1^\ast] \href{../syntax/types.html#syntax-functype}{\rightarrow} [t_2^\ast] \qquad C,\href{../valid/conventions.html#context}{\mathsf{labels}}\,[t_2^\ast] \href{../valid/instructions.html#valid-instr-seq}{\vdash} \href{../syntax/instructions.html#syntax-instr}{\mathit{instr}}_1^\ast : [t_1^\ast] \href{../syntax/types.html#syntax-functype}{\rightarrow} [t_2^\ast] \qquad C,\href{../valid/conventions.html#context}{\mathsf{labels}}\,[t_2^\ast] \href{../valid/instructions.html#valid-instr-seq}{\vdash} \href{../syntax/instructions.html#syntax-instr}{\mathit{instr}}_2^\ast : [t_1^\ast] \href{../syntax/types.html#syntax-functype}{\rightarrow} [t_2^\ast] }{ C \href{../valid/instructions.html#valid-instr}{\vdash} \href{../syntax/instructions.html#syntax-instr-control}{\mathsf{if}}~\href{../syntax/instructions.html#syntax-blocktype}{\mathit{blocktype}}~\href{../syntax/instructions.html#syntax-instr}{\mathit{instr}}_1^\ast~\href{../syntax/instructions.html#syntax-instr-control}{\mathsf{else}}~\href{../syntax/instructions.html#syntax-instr}{\mathit{instr}}_2^\ast~\href{../syntax/instructions.html#syntax-instr-control}{\mathsf{end}} : [t_1^\ast~\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}] \href{../syntax/types.html#syntax-functype}{\rightarrow} [t_2^\ast] }\]

注意

符号 \(C,\href{../valid/conventions.html#context}{\mathsf{labels}}\,[t^\ast]\) 将新的标签类型插入索引 \(0\) 处,并将所有其他标签类型向后移动。notation

\(\href{../syntax/instructions.html#syntax-instr-control}{\mathsf{br}}~l\)

  • 标签 \(C.\href{../valid/conventions.html#context}{\mathsf{labels}}[l]\) 必须在上下文中定义。

  • \([t^\ast]\)结果类型 \(C.\href{../valid/conventions.html#context}{\mathsf{labels}}[l]\)

  • 则该指令对于任何操作数类型序列 \(t_1^\ast\)\(t_2^\ast\),其类型有效,为 \([t_1^\ast~t^\ast] \href{../syntax/types.html#syntax-functype}{\rightarrow} [t_2^\ast]\)

\[\frac{ C.\href{../valid/conventions.html#context}{\mathsf{labels}}[l] = [t^\ast] }{ C \href{../valid/instructions.html#valid-instr}{\vdash} \href{../syntax/instructions.html#syntax-instr-control}{\mathsf{br}}~l : [t_1^\ast~t^\ast] \href{../syntax/types.html#syntax-functype}{\rightarrow} [t_2^\ast] }\]

注意

上下文 \(C\) 中的 标签索引 空间将最新的标签放在最前面,以便 \(C.\href{../valid/conventions.html#context}{\mathsf{labels}}[l]\) 按预期执行相对查找。

\(\href{../syntax/instructions.html#syntax-instr-control}{\mathsf{br}}\) 指令是 栈多态的

\(\href{../syntax/instructions.html#syntax-instr-control}{\mathsf{br\_if}}~l\)

  • 标签 \(C.\href{../valid/conventions.html#context}{\mathsf{labels}}[l]\) 必须在上下文中定义。

  • \([t^\ast]\)结果类型 \(C.\href{../valid/conventions.html#context}{\mathsf{labels}}[l]\)

  • 则该指令类型有效,为 \([t^\ast~\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}] \href{../syntax/types.html#syntax-functype}{\rightarrow} [t^\ast]\)

\[\frac{ C.\href{../valid/conventions.html#context}{\mathsf{labels}}[l] = [t^\ast] }{ C \href{../valid/instructions.html#valid-instr}{\vdash} \href{../syntax/instructions.html#syntax-instr-control}{\mathsf{br\_if}}~l : [t^\ast~\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}] \href{../syntax/types.html#syntax-functype}{\rightarrow} [t^\ast] }\]

注意

上下文 \(C\) 中的 标签索引 空间将最新的标签放在最前面,以便 \(C.\href{../valid/conventions.html#context}{\mathsf{labels}}[l]\) 按预期执行相对查找。

\(\href{../syntax/instructions.html#syntax-instr-control}{\mathsf{br\_table}}~l^\ast~l_N\)

  • 标签 \(C.\href{../valid/conventions.html#context}{\mathsf{labels}}[l_N]\) 必须在上下文中定义。

  • 对于 \(l^\ast\) 中的每个标签 \(l_i\),标签 \(C.\href{../valid/conventions.html#context}{\mathsf{labels}}[l_i]\) 必须在上下文中定义。

  • 必须存在一个 操作数类型 序列 \(t^\ast\),使得

    • 序列 \(t^\ast\) 的长度与序列 \(C.\href{../valid/conventions.html#context}{\mathsf{labels}}[l_N]\) 的长度相同。

    • 对于 \(t^\ast\) 中的每个 操作数类型 \(t_j\)\(C.\href{../valid/conventions.html#context}{\mathsf{labels}}[l_N]\) 中对应的类型 \(t'_{Nj}\)\(t_j\) 匹配 \(t'_{Nj}\)

    • 对于 \(l^\ast\) 中的每个标签 \(l_i\)

      • 序列 \(t^\ast\) 的长度与序列 \(C.\href{../valid/conventions.html#context}{\mathsf{labels}}[l_i]\) 的长度相同。

      • 对于 \(t^\ast\) 中的每个 操作数类型 \(t_j\)\(C.\href{../valid/conventions.html#context}{\mathsf{labels}}[l_i]\) 中对应的类型 \(t'_{ij}\)\(t_j\) 匹配 \(t'_{ij}\)

  • 则该指令对于任何操作数类型序列 \(t_1^\ast\)\(t_2^\ast\),其类型有效,为 \([t_1^\ast~t^\ast~\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}] \href{../syntax/types.html#syntax-functype}{\rightarrow} [t_2^\ast]\)

\[\frac{ (\vdash [t^\ast] \leq C.\href{../valid/conventions.html#context}{\mathsf{labels}}[l])^\ast \qquad \vdash [t^\ast] \leq C.\href{../valid/conventions.html#context}{\mathsf{labels}}[l_N] }{ C \href{../valid/instructions.html#valid-instr}{\vdash} \href{../syntax/instructions.html#syntax-instr-control}{\mathsf{br\_table}}~l^\ast~l_N : [t_1^\ast~t^\ast~\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}] \href{../syntax/types.html#syntax-functype}{\rightarrow} [t_2^\ast] }\]

注意

上下文 \(C\) 中的 标签索引 空间将最新的标签放在最前面,以便 \(C.\href{../valid/conventions.html#context}{\mathsf{labels}}[l_i]\) 按预期执行相对查找。

\(\href{../syntax/instructions.html#syntax-instr-control}{\mathsf{br\_table}}\) 指令是 栈多态的

\(\href{../syntax/instructions.html#syntax-instr-control}{\mathsf{return}}\)

  • 返回类型 \(C.\href{../valid/conventions.html#context}{\mathsf{return}}\) 在上下文中不能缺失。

  • \([t^\ast]\)\(C.\href{../valid/conventions.html#context}{\mathsf{return}}\)结果类型

  • 则该指令对于任何操作数类型序列 \(t_1^\ast\)\(t_2^\ast\),其类型有效,为 \([t_1^\ast~t^\ast] \href{../syntax/types.html#syntax-functype}{\rightarrow} [t_2^\ast]\)

\[\frac{ C.\href{../valid/conventions.html#context}{\mathsf{return}} = [t^\ast] }{ C \href{../valid/instructions.html#valid-instr}{\vdash} \href{../syntax/instructions.html#syntax-instr-control}{\mathsf{return}} : [t_1^\ast~t^\ast] \href{../syntax/types.html#syntax-functype}{\rightarrow} [t_2^\ast] }\]

注意

\(\href{../syntax/instructions.html#syntax-instr-control}{\mathsf{return}}\) 指令是 栈多态的

在验证不是函数体的 表达式 时,\(C.\href{../valid/conventions.html#context}{\mathsf{return}}\) 缺失(设置为 \(\epsilon\))。这与将其设置为空结果类型 (\([\epsilon]\)) 不同,后者是对于不返回任何内容的函数的情况。

\(\href{../syntax/instructions.html#syntax-instr-control}{\mathsf{call}}~x\)

  • 上下文必须定义函数 \(C.\href{../valid/conventions.html#context}{\mathsf{funcs}}[x]\)

  • 则该指令类型有效,为 \(C.\href{../valid/conventions.html#context}{\mathsf{funcs}}[x]\)

\[\frac{ C.\href{../valid/conventions.html#context}{\mathsf{funcs}}[x] = [t_1^\ast] \href{../syntax/types.html#syntax-functype}{\rightarrow} [t_2^\ast] }{ C \href{../valid/instructions.html#valid-instr}{\vdash} \href{../syntax/instructions.html#syntax-instr-control}{\mathsf{call}}~x : [t_1^\ast] \href{../syntax/types.html#syntax-functype}{\rightarrow} [t_2^\ast] }\]

\(\href{../syntax/instructions.html#syntax-instr-control}{\mathsf{call\_indirect}}~x~y\)

  • \(C.\href{../valid/conventions.html#context}{\mathsf{tables}}[x]\) 必须在上下文中定义。

  • \(\href{../syntax/types.html#syntax-limits}{\mathit{limits}}~t\)表类型 \(C.\href{../valid/conventions.html#context}{\mathsf{tables}}[x]\)

  • 引用类型 \(t\) 必须为 \(\href{../syntax/types.html#syntax-reftype}{\mathsf{funcref}}\)

  • 类型 \(C.\href{../valid/conventions.html#context}{\mathsf{types}}[y]\) 必须在上下文中定义。

  • \([t_1^\ast] \href{../syntax/types.html#syntax-functype}{\rightarrow} [t_2^\ast]\)函数类型 \(C.\href{../valid/conventions.html#context}{\mathsf{types}}[y]\)

  • 则该指令类型有效,为 \([t_1^\ast~\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}] \href{../syntax/types.html#syntax-functype}{\rightarrow} [t_2^\ast]\)

\[\frac{ C.\href{../valid/conventions.html#context}{\mathsf{tables}}[x] = \href{../syntax/types.html#syntax-limits}{\mathit{limits}}~\href{../syntax/types.html#syntax-reftype}{\mathsf{funcref}} \qquad C.\href{../valid/conventions.html#context}{\mathsf{types}}[y] = [t_1^\ast] \href{../syntax/types.html#syntax-functype}{\rightarrow} [t_2^\ast] }{ C \href{../valid/instructions.html#valid-instr}{\vdash} \href{../syntax/instructions.html#syntax-instr-control}{\mathsf{call\_indirect}}~x~y : [t_1^\ast~\href{../syntax/types.html#syntax-valtype}{\mathsf{i32}}] \href{../syntax/types.html#syntax-functype}{\rightarrow} [t_2^\ast] }\]

指令序列

指令序列的类型化是递归定义的。

空指令序列:\(\epsilon\)

  • 空指令序列对于任何 操作数类型 序列 \(t^\ast\),其类型有效,为 \([t^\ast] \href{../syntax/types.html#syntax-functype}{\rightarrow} [t^\ast]\)

\[\frac{ }{ C \href{../valid/instructions.html#valid-instr-seq}{\vdash} \epsilon : [t^\ast] \href{../syntax/types.html#syntax-functype}{\rightarrow} [t^\ast] }\]

非空指令序列:\(\href{../syntax/instructions.html#syntax-instr}{\mathit{instr}}^\ast~\href{../syntax/instructions.html#syntax-instr}{\mathit{instr}}_N\)

  • 指令序列 \(\href{../syntax/instructions.html#syntax-instr}{\mathit{instr}}^\ast\) 必须对于某些 操作数类型 序列 \(t_1^\ast\)\(t_2^\ast\),其类型有效,为 \([t_1^\ast] \href{../syntax/types.html#syntax-functype}{\rightarrow} [t_2^\ast]\)

  • 指令 \(\href{../syntax/instructions.html#syntax-instr}{\mathit{instr}}_N\) 必须对于某些 操作数类型 序列 \(t^\ast\)\(t_3^\ast\),其类型有效,为 \([t^\ast] \href{../syntax/types.html#syntax-functype}{\rightarrow} [t_3^\ast]\)

  • 必须存在一个 操作数类型 序列 \(t_0^\ast\),使得 \(t_2^\ast = t_0^\ast~{t'}^\ast\),其中类型序列 \({t'}^\ast\)\(t^\ast\) 一样长。

  • 对于 \({t'}^\ast\) 中的每个 操作数类型 \(t'_i\)\(t^\ast\) 中对应的类型 \(t_i\)\(t'_i\) 匹配 \(t_i\)

  • 则组合后的指令序列类型有效,为 \([t_1^\ast] \href{../syntax/types.html#syntax-functype}{\rightarrow} [t_0^\ast~t_3^\ast]\)

\[\frac{ C \href{../valid/instructions.html#valid-instr-seq}{\vdash} \href{../syntax/instructions.html#syntax-instr}{\mathit{instr}}^\ast : [t_1^\ast] \href{../syntax/types.html#syntax-functype}{\rightarrow} [t_0^\ast~{t'}^\ast] \qquad \vdash [{t'}^\ast] \leq [t^\ast] \qquad C \href{../valid/instructions.html#valid-instr}{\vdash} \href{../syntax/instructions.html#syntax-instr}{\mathit{instr}}_N : [t^\ast] \href{../syntax/types.html#syntax-functype}{\rightarrow} [t_3^\ast] }{ C \href{../valid/instructions.html#valid-instr-seq}{\vdash} \href{../syntax/instructions.html#syntax-instr}{\mathit{instr}}^\ast~\href{../syntax/instructions.html#syntax-instr}{\mathit{instr}}_N : [t_1^\ast] \href{../syntax/types.html#syntax-functype}{\rightarrow} [t_0^\ast~t_3^\ast] }\]

表达式

表达式 \(\href{../syntax/instructions.html#syntax-expr}{\mathit{expr}}\)结果类型 分类,结果类型的形式为 \([t^\ast]\)

\(\href{../syntax/instructions.html#syntax-instr}{\mathit{instr}}^\ast~\href{../syntax/instructions.html#syntax-instr-control}{\mathsf{end}}\)

  • 指令序列 \(\href{../syntax/instructions.html#syntax-instr}{\mathit{instr}}^\ast\) 必须是 有效的,并具有某种 栈类型 \([] \href{../syntax/types.html#syntax-functype}{\rightarrow} [{t'}^\ast]\)

  • 对于 \({t'}^\ast\) 中的每个 操作数类型 \(t'_i\) 以及 \(t^\ast\) 中对应的 值类型 \(t_i\)\(t'_i\) 匹配 \(t_i\)

  • 然后,表达式对于 结果类型 \([t^\ast]\) 是有效的。

\[\frac{ C \href{../valid/instructions.html#valid-instr-seq}{\vdash} \href{../syntax/instructions.html#syntax-instr}{\mathit{instr}}^\ast : [] \href{../syntax/types.html#syntax-functype}{\rightarrow} [{t'}^\ast] \qquad \vdash [{t'}^\ast] \leq [t^\ast] }{ C \href{../valid/instructions.html#valid-expr}{\vdash} \href{../syntax/instructions.html#syntax-instr}{\mathit{instr}}^\ast~\href{../syntax/instructions.html#syntax-instr-control}{\mathsf{end}} : [t^\ast] }\]

常量表达式

  • 常量表达式 \(\href{../syntax/instructions.html#syntax-instr}{\mathit{instr}}^\ast~\href{../syntax/instructions.html#syntax-instr-control}{\mathsf{end}}\) 中,\(\href{../syntax/instructions.html#syntax-instr}{\mathit{instr}}^\ast\) 中的所有指令都必须是常量。

  • 常量指令 \(\href{../syntax/instructions.html#syntax-instr}{\mathit{instr}}\) 必须是

    • 形式为 \(t.\href{../syntax/instructions.html#syntax-instr-numeric}{\mathsf{const}}~c\)

    • 或形式为 \(\href{../syntax/instructions.html#syntax-instr-ref}{\mathsf{ref{.}null}}\)

    • 或形式为 \(\href{../syntax/instructions.html#syntax-instr-ref}{\mathsf{ref{.}func}}~x\)

    • 或形式为 \(\href{../syntax/instructions.html#syntax-instr-variable}{\mathsf{global.get}}~x\),在这种情况下,\(C.\href{../valid/conventions.html#context}{\mathsf{globals}}[x]\) 必须是形式为 \(\href{../syntax/instructions.html#syntax-instr-numeric}{\mathsf{const}}~t\)全局类型

\[\frac{ (C \href{../valid/instructions.html#valid-constant}{\vdash} \href{../syntax/instructions.html#syntax-instr}{\mathit{instr}} \href{../valid/instructions.html#valid-constant}{\mathrel{\mbox{const}}})^\ast }{ C \href{../valid/instructions.html#valid-constant}{\vdash} \href{../syntax/instructions.html#syntax-instr}{\mathit{instr}}^\ast~\href{../syntax/instructions.html#syntax-instr-control}{\mathsf{end}} \href{../valid/instructions.html#valid-constant}{\mathrel{\mbox{const}}} }\]
\[\frac{ }{ C \href{../valid/instructions.html#valid-constant}{\vdash} t.\href{../syntax/instructions.html#syntax-instr-numeric}{\mathsf{const}}~c \href{../valid/instructions.html#valid-constant}{\mathrel{\mbox{const}}} } \qquad \frac{ }{ C \href{../valid/instructions.html#valid-constant}{\vdash} \href{../syntax/instructions.html#syntax-instr-ref}{\mathsf{ref{.}null}}~t \href{../valid/instructions.html#valid-constant}{\mathrel{\mbox{const}}} } \qquad \frac{ }{ C \href{../valid/instructions.html#valid-constant}{\vdash} \href{../syntax/instructions.html#syntax-instr-ref}{\mathsf{ref{.}func}}~x \href{../valid/instructions.html#valid-constant}{\mathrel{\mbox{const}}} }\]
\[\frac{ C.\href{../valid/conventions.html#context}{\mathsf{globals}}[x] = \href{../syntax/instructions.html#syntax-instr-numeric}{\mathsf{const}}~t }{ C \href{../valid/instructions.html#valid-constant}{\vdash} \href{../syntax/instructions.html#syntax-instr-variable}{\mathsf{global.get}}~x \href{../valid/instructions.html#valid-constant}{\mathrel{\mbox{const}}} }\]

注意

目前,出现在 全局变量元素数据 段中的常量表达式受到进一步的约束,其中包含的 \(\href{../syntax/instructions.html#syntax-instr-variable}{\mathsf{global.get}}\) 指令仅允许引用导入的全局变量。这在 模块验证规则 中通过相应地约束上下文 \(C\) 来执行。

常量表达式的定义可能会在 WebAssembly 的未来版本中扩展。