Difference between revisions of "WebAssembly/Instructions"

From Free Pascal wiki
Jump to navigationJump to search
Line 99: Line 99:
 
|'''call_indirect'''  '''typeuse'''
 
|'''call_indirect'''  '''typeuse'''
 
|$11
 
|$11
 +
|
 +
|
 +
|-
 +
|'''drop'''
 +
|$1A
 +
|[t]→[]
 +
|
 +
|-
 +
|'''select'''
 +
|$1B
 +
|[t t i32]→[t]
 +
|
 +
|-
 +
|(reserved)
 +
|$1C..$1F
 
|
 
|
 
|
 
|

Revision as of 16:48, 11 September 2019

This page is created because it's annoying to constantly jump around the official WebAssembly documentation.

The page requires careful review as official specs are updated

Instructions

Instruction Byte Code Execution Notes
unreachable $00
1. Trap
nop $01
1. Do nothing
block $02 blocktype
1. Let n be the arity |t?| of the result type t?.
2. Let L be the label whose arity is n and whose continuation is the end of the block.
3. Enter the block instr∗ with label L.
block must always be closed with end
loop $03
if $04
else $05 can only be used with if. Only single else is allowed per if
end $0B end can only close block or loop clocks
br labelidx $0C labelidx
1. Assert: due to validation, the stack contains at least l+1 labels.
2. Let L be the l-th label appearing on the stack, starting from the top and counting from zero.
3. Let n be the arity of L.
4. Assert: due to validation, there are at least n values on the top of the stack.
5. Pop the values valn from the stack.
6. Repeat l+1 times:
a. While the top of the stack is a value, do:
i. Pop the value from the stack.
b. Assert: due to validation, the top of the stack now is a label.
c. Pop the label from the stack.
7. Push the values valn to the stack.
8. Jump to the continuation of L.
Branching - Unconditional

Branching is possible only within a block. The block itself defines labels where the branching can go to.

br_if labelidx $0D labelidx
1. Assert: due to validation, a value of value type i32 is on the top of the stack.
2. Pop the value i32.const c from the stack.
3. If c is non-zero, then:
a. Execute the instruction (br l).
4. Else:
b. Do nothing.
Branching - Conditional

Branching is possible only within a block. The block itself defines labels where the branching can go to.

br_table vec(labelidxI) labelidx $0E
return $0F
call funcidx $10
call_indirect typeuse $11
drop $1A [t]→[]
select $1B [t t i32]→[t]
(reserved) $1C..$1F

See Also