Skip to content

Commit

Permalink
Merge pull request #69 from ewasm/0x0d
Browse files Browse the repository at this point in the history
upgrade to 0x0d
  • Loading branch information
wanderer committed Dec 28, 2016
2 parents 4a746dd + 7be79ad commit 26787af
Show file tree
Hide file tree
Showing 32 changed files with 114 additions and 103 deletions.
6 changes: 3 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[submodule "sexpr-wasm-prototype"]
path = tools/sexpr-wasm-prototype
url = https://github.com/WebAssembly/sexpr-wasm-prototype.git
[submodule "tools/wabt"]
path = tools/wabt
url = https://github.com/WebAssembly/wabt.git
17 changes: 16 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
language: node_js
node_js:
- "7"
before_install:
- npm install .
- cd tools
- wget https://storage.googleapis.com/chromium-v8/node-linux-rel/node-linux-rel-41967-121bf38bc0a2973476ba378ddd3ff3b5f97ae494.zip -O nodejs.zip
- unzip nodejs.zip
- cd bin

env:
- CXX=g++-4.8
Expand All @@ -14,4 +19,14 @@ addons:
- wget
- unzip

script: npm run lint
matrix:
fast_finish: true
include:
- os: linux
node_js: "7"
env: TEST_SUITE=test
- os: linux
node_js: "7"
env: TEST_SUITE=lint
script: ./npm run $TEST_SUITE

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"scripts": {
"lint": "standard",
"test": "node --harmony --expose-wasm ./tests/interfaceRunner.js",
"build": "node ./tests/buildTests.js"
"build": "node ./tests/buildTests.js && ./tools/wabt/out/wast2wasm ./wasm/interface.wast -o ./wasm/interface.wasm"
},
"repository": {
"type": "git",
Expand All @@ -30,7 +30,7 @@
},
"standard": {
"ignore": [
"/tools/sexpr-wasm-prototype/"
"/tools/"
],
"globals": [
"WebAssembly"
Expand Down
2 changes: 1 addition & 1 deletion tests/buildTests.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ let tests = fs.readdirSync(dir).filter((file) => file.endsWith('.wast'))
for (let testName of tests) {
testName = testName.split('.')[0]
// Compile Command
cp.execSync(`${__dirname}/../tools/sexpr-wasm-prototype/out/sexpr-wasm ${dir}/${testName}.wast -o ${dir}/${testName}.wasm`)
cp.execSync(`${__dirname}/../tools/wabt/out/wast2wasm ${dir}/${testName}.wast -o ${dir}/${testName}.wasm`)
}
Binary file modified tests/interface/address.wasm
Binary file not shown.
10 changes: 5 additions & 5 deletions tests/interface/address.wast
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
;; starts with an address of 5d48c1018904a172886829bbbd9c6f4a2d06c47b
(module
(import "ethereum" "getAddress" (func $address (param i32)))

(memory 1)

(import $address "ethereum" "getAddress" (param i32))
(export "main" 0)
(export "a" memory)
(export "main" (func 0))
(export "memory" (memory 0))
(func
(block
;; loads the address into memory
(call_import $address (i32.const 0))
(call $address (i32.const 0))
(if (i64.eq (i64.load (i32.const 0)) (i64.const 0x72a1048901c1485d))
(return)
)
Expand Down
Binary file modified tests/interface/balance.wasm
Binary file not shown.
20 changes: 11 additions & 9 deletions tests/interface/balance.wast
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
;; address of 5d48c1018904a172886829bbbd9c6f4a2d06c47b has a balance of 0x056bc75e2d63100000 (100 ETH)
(module
(memory 1 (segment 0 "\5d\48\c1\01\89\04\a1\72\88\68\29\bb\bd\9c\6f\4a\2d\06\c4\7b"))
(import $balance "ethereum" "getBalance" (param i32 i32 i32))
(export "a" memory)
(export "main" 0)
(func
(call_import $balance (i32.const 0) (i32.const 0) (i32.const 1))
)
(import "ethereum" "getBalance" (func $balance (param i32 i32 i32)))
(memory 1 )
(data (i32.const 0) "\5d\48\c1\01\89\04\a1\72\88\68\29\bb\bd\9c\6f\4a\2d\06\c4\7b")
(export "memory" (memory 0))
(export "main" (func $main))
(export "1" (func $callback))

(export "1" 1)
(func
(func $main
(call $balance (i32.const 0) (i32.const 0) (i32.const 1))
)

(func $callback
(block
(if (i64.eq (i64.load (i32.const 0)) (i64.const 0x0500000000000000))
(return)
Expand Down
Binary file modified tests/interface/basic_gas_ops.wasm
Binary file not shown.
16 changes: 8 additions & 8 deletions tests/interface/basic_gas_ops.wast
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
;; starts with 1000 gas
(module
(import $useGas "ethereum" "useGas" (param i32))
(import $gas "ethereum" "getGasLeft" (result i32))
(import "ethereum" "useGas" (func $useGas (param i64)))
(import "ethereum" "getGasLeft" (func $gas (result i64)))

(export "test" 0)
(func
(export "test" (func $main))
(func $main
;; test adding gas
(block
(call_import $useGas (i32.const 1))
(if (i32.eq (call_import $gas) (i32.const 997))
(call $useGas (i64.const 1))
(if (i64.eq (call $gas) (i64.const 997))
(return)
)
(unreachable)
)
(block
(call_import $useGas (i32.const 1))
(if (i32.eq (call_import $gas) (i32.const 996))
(call $useGas (i64.const 1))
(if (i64.eq (call $gas) (i64.const 996))
(return)
)
(unreachable)
Expand Down
Binary file modified tests/interface/call.wasm
Binary file not shown.
18 changes: 9 additions & 9 deletions tests/interface/call.wast
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
;; starts with an address of 5d48c1018904a172886829bbbd9c6f4a2d06c47b
(module
(memory 1)

(import $call "ethereum" "call" (param i32 i32 i32 i32 i32 i32 i32 i32) (result i32))
(export "a" memory)
(export "main" 0)
(func
(import "ethereum" "call" (func $call (param i64 i32 i32 i32 i32 i32 i32 i32) (result i32)))
(memory 1)
(export "memory" (memory 0))
(export "main" (func $main))
(func $main
(block
;; Memory layout:
;; 0 - 20 bytes: address (4)
Expand All @@ -14,12 +13,13 @@
;; 56 - 60 bytes: result
(i32.store (i32.const 0) (i32.const 0x4))
(i32.store (i32.const 52) (i32.const 0x42004200))
(call_import $call (i32.const 2000) (i32.const 0) (i32.const 20) (i32.const 52) (i32.const 4) (i32.const 56) (i32.const 4) (i32.const 1))
(call $call (i64.const 2000) (i32.const 0) (i32.const 20) (i32.const 52) (i32.const 4) (i32.const 56) (i32.const 4) (i32.const 1))
drop
)
)

(export "1" 1)
(func (param $result i32)
(export "1" (func $callback))
(func $callback (param $result i32)
(if (i32.eq (i32.const 1) (get_local $result))
(return)
)
Expand Down
Binary file modified tests/interface/callDataCopy.wasm
Binary file not shown.
11 changes: 5 additions & 6 deletions tests/interface/callDataCopy.wast
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
;; calldata is "596f75206172652077616974...", but i64.load works in LSB mode
(module
(import "ethereum" "callDataCopy" (func $callDataCopy (param i32 i32 i32)))
(memory 1)
(import $callDataCopy "ethereum" "callDataCopy" (param i32 i32 i32))

(export "memory" memory)
(export "main" 0)
(func
(export "memory" (memory 0))
(export "main" (func $main))
(func $main
(block
(call_import $callDataCopy (i32.const 0) (i32.const 0) (i32.const 8))
(call $callDataCopy (i32.const 0) (i32.const 0) (i32.const 8))
(if (i64.eq (i64.load (i32.const 0)) (i64.const 0x2065726120756f59))
(return)
)
Expand Down
Binary file modified tests/interface/callDataSize.wasm
Binary file not shown.
9 changes: 4 additions & 5 deletions tests/interface/callDataSize.wast
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
(module
(import"ethereum" "getCallDataSize" (func $callDataSize (result i32)))
(memory 1)
(import $callDataSize "ethereum" "getCallDataSize" (result i64))

(export "main" 0)
(func
(export "main" (func $main))
(func $main
(block
(if (i64.eq (call_import $callDataSize) (i64.const 277))
(if (i32.eq (call $callDataSize) (i32.const 277))
(return)
)
(unreachable)
Expand Down
Binary file modified tests/interface/callValue.wasm
Binary file not shown.
11 changes: 5 additions & 6 deletions tests/interface/callValue.wast
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
;; call value of 0x056bc75e2d63100000 (100 ETH)
(module
(import "ethereum" "getCallValue" (func $callValue (param i32)))
(memory 1)
(import $callValue "ethereum" "getCallValue" (param i32))

(export "a" memory)
(export "main" 0)
(func
(export "memory" (memory 0))
(export "main" (func $main))
(func $main
(block
(call_import $callValue (i32.const 0))
(call $callValue (i32.const 0))
(if (i64.eq (i64.load (i32.const 0)) (i64.const 0x0500000000000000))
(return)
)
Expand Down
Binary file modified tests/interface/caller.wasm
Binary file not shown.
11 changes: 5 additions & 6 deletions tests/interface/caller.wast
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
;; starts with an caller of 5d48c1018904a172886829bbbd9c6f4a2d06c47b
(module
(import "ethereum" "getCaller" (func $caller (param i32)))
(memory 1)
(import $caller "ethereum" "getCaller" (param i32))

(export "main" 0)
(export "a" memory)
(func
(export "main" (func $main))
(export "memory" (memory 0))
(func $main
(block
;; loads the caller into memory
(call_import $caller (i32.const 0))
(call $caller (i32.const 0))
(if (i64.eq (i64.load (i32.const 0)) (i64.const 0x72a1048901c1485d))
(return)
)
Expand Down
Binary file modified tests/interface/coinbase.wasm
Binary file not shown.
11 changes: 5 additions & 6 deletions tests/interface/coinbase.wast
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
;; starts with a coinbase of 5d48c1018904a172886829bbbd9c6f4a2d06c47b
(module
(import "ethereum" "getBlockCoinbase" (func $coinbase (param i32)))
(memory 1)

(import $coinbase "ethereum" "getBlockCoinbase" (param i32))
(export "main" 0)
(export "a" memory)
(func
(export "main" (func $main))
(export "memory" (memory 0))
(func $main
(block
;; loads the coinbase into memory
(call_import $coinbase (i32.const 0))
(call $coinbase (i32.const 0))
(if (i64.eq (i64.load (i32.const 0)) (i64.const 0x72a1048901c1485d))
(return)
)
Expand Down
Binary file modified tests/interface/origin.wasm
Binary file not shown.
10 changes: 5 additions & 5 deletions tests/interface/origin.wast
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
;; starts with an origin of 5d48c1018904a172886829bbbd9c6f4a2d06c47b
(module
(import "ethereum" "getTxOrigin" (func $origin (param i32)))
(memory 1)
(import $origin "ethereum" "getTxOrigin" (param i32))

(export "main" 0)
(export "a" memory)
(func
(export "main" (func $main))
(export "memory" (memory 0))
(func $main
(block
;; loads the address into memory
(call_import $origin (i32.const 0))
(call $origin (i32.const 0))
(if (i64.eq (i64.load (i32.const 0)) (i64.const 0x72a1048901c1485d))
(return)
)
Expand Down
Binary file modified tests/interface/sstore.wasm
Binary file not shown.
24 changes: 12 additions & 12 deletions tests/interface/sstore.wast
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
;; starts with an caller of 5d48c1018904a172886829bbbd9c6f4a2d06c47b
(module
(memory 1)
(import $sstore "ethereum" "storageStore" (param i32 i32 i32))
(import $sload "ethereum" "storageLoad" (param i32 i32 i32))
(import "ethereum" "storageStore" (func $sstore (param i32 i32 i32)))
(import "ethereum" "storageLoad" (func $sload (param i32 i32 i32)))

(export "main" 0)
(export "a" memory)
(func
(memory 1)
(export "main" (func $main))
(export "memory" (memory 0))
(func $main
(local $temp i64)
(block
;; should roundtrip store and load a value from storage
(i64.store (i32.const 0) (i64.const 173553719826446289))
(call_import $sstore (i32.const 64) (i32.const 0) (i32.const 1))
(call $sstore (i32.const 64) (i32.const 0) (i32.const 1))
)
)

(export "1" 1)
(func
(export "1" (func $callback))
(func $callback
(block
(call_import $sload (i32.const 64) (i32.const 64) (i32.const 2))
(call $sload (i32.const 64) (i32.const 64) (i32.const 2))
)
)

(export "2" 2)
(func
(export "2" (func $callback2))
(func $callback2
(block
(if (i64.ne (i64.load (i32.const 64)) (i64.const 173553719826446289))
(unreachable))
Expand Down
3 changes: 1 addition & 2 deletions tests/interfaceRunner.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const Environment = require('../testEnvironment.js')
const dir = path.join(__dirname, '/interface')
// get the test names
let tests = fs.readdirSync(dir).filter((file) => file.endsWith('.wast'))
// tests = ['callDataCopy.wast']
// tests = ['callDataSize.wast']

runTests(tests)

Expand All @@ -20,7 +20,6 @@ function runTests (tests) {
testName = testName.split('.')[0]
tape(testName, async (t) => {
// Compile Command

const rootVertex = new Vertex()
const code = fs.readFileSync(`${dir}/${testName}.wasm`)
const envData = JSON.parse(fs.readFileSync(`${dir}/${testName}.json`).toString())
Expand Down
1 change: 0 additions & 1 deletion tools/sexpr-wasm-prototype
Submodule sexpr-wasm-prototype deleted from b48757
1 change: 1 addition & 0 deletions tools/wabt
Submodule wabt added at 2177e7
2 changes: 1 addition & 1 deletion vm.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,6 @@ module.exports = class VM {
}

get memory () {
return this._instance.exports.memory
return this._instance.exports.memory.buffer
}
}
Binary file modified wasm/interface.wasm
Binary file not shown.
Loading

0 comments on commit 26787af

Please sign in to comment.