diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml new file mode 100644 index 0000000..7d700d0 --- /dev/null +++ b/.github/workflows/test.yaml @@ -0,0 +1,14 @@ +name: test +on: [push, pull_request] +jobs: + unit: + name: Unit + runs-on: ubuntu-latest + steps: + - uses: actions/setup-go@v1 + with: + go-version: 1.13 + id: go + - uses: actions/checkout@v1 + - run: make test + diff --git a/.gitignore b/.gitignore index add0837..9074458 100644 --- a/.gitignore +++ b/.gitignore @@ -10,3 +10,6 @@ coverage.txt *.test go.sum +test_runner +tests/generated +target/ diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..1420a04 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "testsuite"] + path = testsuite + url = git@github.com:WebAssembly/testsuite.git diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..52a5546 --- /dev/null +++ b/Makefile @@ -0,0 +1,34 @@ +JSON_DIR:=tests/generated +WAST_DIR:=testsuite +NO_TEST:=tests/skipped/%.no-test +TEST_RUNNER:=target/test_runner + +# Run all test fixtures +.PHONY: test +test: build testsuite test_runner wast $(patsubst ${JSON_DIR}/%.json, ${NO_TEST}, $(wildcard ${JSON_DIR}/*.json)) + +.PHONY: build +build: + go build . + +target/test_runner: + go build -o ${TEST_RUNNER} ./spec/test_runner + +# Pseudo target to run each test fixture +${NO_TEST}: ${JSON_DIR}/%.json + ${TEST_RUNNER} $< + +# Get latest test suite as a git submodule +.PHONY: testsuite +testsuite: + git submodule update --init testsuite + +# Build all JSON specs +.PHONY: wast +wast: $(patsubst ${WAST_DIR}/%.wast, ${JSON_DIR}/%.json, $(wildcard ${WAST_DIR}/*.wast)) + +# Build JSON specs - requires the wast2json binary to be on PATH, from wabt (https://github.com/WebAssembly/wabt) +${JSON_DIR}/%.json: testsuite/%.wast + wast2json $< -o $@ + + diff --git a/compiler/module.go b/compiler/module.go index e85e8d7..040d994 100644 --- a/compiler/module.go +++ b/compiler/module.go @@ -144,7 +144,7 @@ func (m *Module) CompileWithNGen(gp GasPolicy, numGlobals uint64) (out string, r for i, f := range m.Base.FunctionIndexSpace { //fmt.Printf("Compiling function %d (%+v) with %d locals\n", i, f.Sig, len(f.Body.Locals)) - d, err := disasm.Disassemble(f, m.Base) + d, err := disasm.NewDisassembly(f, m.Base) if err != nil { panic(err) } @@ -220,7 +220,7 @@ func (m *Module) CompileForInterpreter(gp GasPolicy) (_retCode []InterpreterCode for i, f := range m.Base.FunctionIndexSpace { //fmt.Printf("Compiling function %d (%+v) with %d locals\n", i, f.Sig, len(f.Body.Locals)) - d, err := disasm.Disassemble(f, m.Base) + d, err := disasm.NewDisassembly(f, m.Base) if err != nil { panic(err) } diff --git a/compiler/serialize.go b/compiler/serialize.go index 3994daa..4408ae7 100644 --- a/compiler/serialize.go +++ b/compiler/serialize.go @@ -722,10 +722,10 @@ func (c *SSAFunctionCompiler) Serialize() []byte { binary.Write(buf, binary.LittleEndian, uint32(v)) } - case "current_memory": + case "memory.size": binary.Write(buf, binary.LittleEndian, opcodes.CurrentMemory) - case "grow_memory": + case "memory.grow": binary.Write(buf, binary.LittleEndian, opcodes.GrowMemory) binary.Write(buf, binary.LittleEndian, uint32(ins.Values[0])) diff --git a/compiler/ssa.go b/compiler/ssa.go index 948df20..ae781d6 100644 --- a/compiler/ssa.go +++ b/compiler/ssa.go @@ -442,12 +442,12 @@ func (c *SSAFunctionCompiler) Compile(importTypeIDs []int) { c.PushStack(targetValueID) } - case "current_memory": + case "memory.size": retID := c.NextValueID() c.Code = append(c.Code, buildInstr(retID, ins.Op.Name, nil, nil)) c.PushStack(retID) - case "grow_memory": + case "memory.grow": retID := c.NextValueID() c.Code = append(c.Code, buildInstr(retID, ins.Op.Name, nil, c.PopStack(1))) c.PushStack(retID) diff --git a/go.mod b/go.mod index f83c738..7596d46 100644 --- a/go.mod +++ b/go.mod @@ -1,9 +1,11 @@ module github.com/perlin-network/life -replace github.com/go-interpreter/wagon v0.0.0 => github.com/perlin-network/wagon v0.3.1-0.20180825141017-f8cb99b55a39 +go 1.13 require ( - github.com/go-interpreter/wagon v0.0.0 + github.com/go-interpreter/wagon v0.6.1-0.20190923081222-01d3d3376951 + github.com/kr/pretty v0.1.0 // indirect github.com/vmihailenco/msgpack v4.0.4+incompatible - golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e // indirect + google.golang.org/appengine v1.6.5 // indirect + gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 // indirect ) diff --git a/tests/skipped/data.no-test b/tests/skipped/data.no-test new file mode 100644 index 0000000..bae880a --- /dev/null +++ b/tests/skipped/data.no-test @@ -0,0 +1 @@ +This file indicates that the corresponding JSON test in tests/generated is not yet passing and will be excluded. Remove this file to include the test. diff --git a/tests/skipped/elem.no-test b/tests/skipped/elem.no-test new file mode 100644 index 0000000..bae880a --- /dev/null +++ b/tests/skipped/elem.no-test @@ -0,0 +1 @@ +This file indicates that the corresponding JSON test in tests/generated is not yet passing and will be excluded. Remove this file to include the test. diff --git a/tests/skipped/imports.no-test b/tests/skipped/imports.no-test new file mode 100644 index 0000000..bae880a --- /dev/null +++ b/tests/skipped/imports.no-test @@ -0,0 +1 @@ +This file indicates that the corresponding JSON test in tests/generated is not yet passing and will be excluded. Remove this file to include the test. diff --git a/tests/skipped/linking.no-test b/tests/skipped/linking.no-test new file mode 100644 index 0000000..bae880a --- /dev/null +++ b/tests/skipped/linking.no-test @@ -0,0 +1 @@ +This file indicates that the corresponding JSON test in tests/generated is not yet passing and will be excluded. Remove this file to include the test. diff --git a/tests/skipped/start.no-test b/tests/skipped/start.no-test new file mode 100644 index 0000000..bae880a --- /dev/null +++ b/tests/skipped/start.no-test @@ -0,0 +1 @@ +This file indicates that the corresponding JSON test in tests/generated is not yet passing and will be excluded. Remove this file to include the test. diff --git a/testsuite b/testsuite new file mode 160000 index 0000000..d072a86 --- /dev/null +++ b/testsuite @@ -0,0 +1 @@ +Subproject commit d072a86948ead9951309ae1892804c71c0ba1cd9