Supports mix of wasm and go funcs in the same module (#707)

This removes the constraint of a module being exclusively wasm or host
functions. Later pull requests can optimize special imports to be
implemented in wasm, particularly useful for disabled logging callbacks.

Signed-off-by: Adrian Cole <adrian@tetrate.io>
This commit is contained in:
Crypt Keeper
2022-07-19 11:55:37 +08:00
committed by GitHub
parent 0d76b11d66
commit 0da1af2d51
19 changed files with 131 additions and 188 deletions

View File

@@ -1,10 +1,8 @@
package wasm
import (
"reflect"
"testing"
"github.com/tetratelabs/wazero/api"
"github.com/tetratelabs/wazero/internal/testing/require"
)
@@ -202,7 +200,6 @@ func TestModule_SectionElementCount(t *testing.T) {
i32, f32 := ValueTypeI32, ValueTypeF32
zero := uint32(0)
empty := &ConstantExpression{Opcode: OpcodeI32Const, Data: const0}
fn := reflect.ValueOf(func(api.Module) {})
tests := []struct {
name string
@@ -219,16 +216,6 @@ func TestModule_SectionElementCount(t *testing.T) {
input: &Module{NameSection: &NameSection{ModuleName: "simple"}},
expected: map[string]uint32{"custom": 1},
},
{
name: "HostFunctionSection",
input: &Module{HostFunctionSection: []*reflect.Value{&fn}},
expected: map[string]uint32{"host_function": 1},
},
{
name: "NameSection and HostFunctionSection",
input: &Module{NameSection: &NameSection{ModuleName: "simple"}, HostFunctionSection: []*reflect.Value{&fn}},
expected: map[string]uint32{"custom": 1, "host_function": 1},
},
{
name: "TypeSection",
input: &Module{
@@ -312,11 +299,6 @@ func TestModule_SectionElementCount(t *testing.T) {
actual[SectionIDName(i)] = size
}
}
// SectionIDHostFunction is intentionally not after data
if size := tc.input.SectionElementCount(SectionIDHostFunction); size > 0 {
actual[SectionIDName(SectionIDHostFunction)] = size
}
require.Equal(t, tc.expected, actual)
})
}