forked from tetratelabs/wazero
/
vm_call.go
34 lines (28 loc) · 837 Bytes
/
vm_call.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package wasm
func call(vm *VirtualMachine) {
vm.ActiveContext.PC++
index := vm.FetchUint32()
vm.Functions[index].Call(vm)
}
func callIndirect(vm *VirtualMachine) {
vm.ActiveContext.PC++
index := vm.FetchUint32()
expType := vm.InnerModule.SecTypes[index]
tableIndex := vm.OperandStack.Pop()
// note: mvp limits the size of table index space to 1
if tableIndex >= uint64(len(vm.InnerModule.IndexSpace.Table[0])) {
panic("table index out of range")
}
te := vm.InnerModule.IndexSpace.Table[0][tableIndex]
if te == nil {
panic("table entry not initialized")
}
f := vm.Functions[*te]
ft := f.FunctionType()
if !hasSameSignature(ft.InputTypes, expType.InputTypes) ||
!hasSameSignature(ft.ReturnTypes, expType.ReturnTypes) {
panic("function signature mismatch")
}
f.Call(vm)
vm.ActiveContext.PC++ // skip 0x00
}