Commit 88d61c8591d4cdf5ba2022f4eeaa1af8e06891a5
remove EVMinterface dep
wanderer committed on 3/1/2017, 4:28:44 PMParent: 841228acfa1dad00f990ebe18290a46130f85d5d
Files changed
hypervisor.js | changed |
index.js | changed |
portManager.js | changed |
runTx.js | changed |
tests/interfaceRunner.js | changed |
hypervisor.js | ||
---|---|---|
@@ -4,19 +4,12 @@ | ||
4 | 4 | // const blockchain = require('./fakeBlockChain.js') |
5 | 5 | const codeHandlers = require('./codeHandler.js') |
6 | 6 | |
7 | 7 | module.exports = class Hypervisor { |
8 | - constructor (state = new Vertex()) { | |
8 | + constructor (state = new Vertex(), imports = []) { | |
9 | 9 | this.state = state |
10 | - // if (state.isEmpty) { | |
11 | - // state.set('block', new Vertex({ | |
12 | - // value: new Block() | |
13 | - // })) | |
14 | - // state.set('blockchain', new Vertex({ | |
15 | - // value: blockchain | |
16 | - // })) | |
17 | - // } | |
18 | 10 | this.root = new Kernel({ |
11 | + imports: imports, | |
19 | 12 | state: state |
20 | 13 | }) |
21 | 14 | } |
22 | 15 |
index.js | ||
---|---|---|
@@ -1,8 +1,7 @@ | ||
1 | 1 | const EventEmitter = require('events') |
2 | 2 | const Vertex = require('merkle-trie') |
3 | 3 | const PortManager = require('./portManager.js') |
4 | -const imports = require('./EVMinterface.js') | |
5 | 4 | const codeHandler = require('./codeHandler.js') |
6 | 5 | |
7 | 6 | module.exports = class Kernel extends EventEmitter { |
8 | 7 | constructor (opts = {}) { |
@@ -11,29 +10,29 @@ | ||
11 | 10 | const state = this.state = opts.state || new Vertex() |
12 | 11 | this.path = state.path |
13 | 12 | |
14 | 13 | // set up the vm |
15 | - this.imports = opts.imports || [imports] | |
14 | + this.imports = opts.imports | |
16 | 15 | this._vm = (opts.codeHandler || codeHandler).init(opts.code || state.value) |
17 | - this._state = 'idle' | |
16 | + this._vmstate = 'idle' | |
18 | 17 | |
19 | 18 | // set up ports |
20 | - this.ports = new PortManager(state, opts.parentPort, Kernel) | |
21 | - this._sentAtomicMessages = [] | |
19 | + this.ports = new PortManager(state, opts.parentPort, Kernel, this.imports) | |
22 | 20 | this.ports.on('message', index => { |
23 | 21 | this.runNextMessage(index) |
24 | 22 | }) |
23 | + this._sentAtomicMessages = [] | |
25 | 24 | } |
26 | 25 | |
27 | 26 | runNextMessage (index = 0) { |
28 | 27 | // load the next message from port space |
29 | 28 | return this.ports.peek(index).then(message => { |
30 | - if (message && (message._isCyclic(this) || this._state === 'idle')) { | |
29 | + if (message && (message._isCyclic(this) || this._vmstate === 'idle')) { | |
31 | 30 | this._currentMessage = message |
32 | 31 | this.ports.remove(index) |
33 | 32 | return this.run(message) |
34 | 33 | } else { |
35 | - this._state = 'idle' | |
34 | + this._vmstate = 'idle' | |
36 | 35 | this.emit('idle') |
37 | 36 | } |
38 | 37 | }) |
39 | 38 | } |
@@ -54,9 +53,9 @@ | ||
54 | 53 | } |
55 | 54 | |
56 | 55 | const oldState = this.state.copy() |
57 | 56 | let result |
58 | - this._state = 'running' | |
57 | + this._vmstate = 'running' | |
59 | 58 | try { |
60 | 59 | result = await this._vm.run(message, this, imports) || {} |
61 | 60 | } catch (e) { |
62 | 61 | result = { |
portManager.js | ||
---|---|---|
@@ -2,12 +2,13 @@ | ||
2 | 2 | const Port = require('./port.js') |
3 | 3 | const common = require('./common.js') |
4 | 4 | |
5 | 5 | module.exports = class PortManager extends EventEmitter { |
6 | - constructor (state, destParentPort, KernelContructor) { | |
6 | + constructor (state, destParentPort, KernelContructor, imports) { | |
7 | 7 | super() |
8 | 8 | this._queue = [] |
9 | 9 | this.state = state |
10 | + this.imports = imports | |
10 | 11 | this.Kernel = KernelContructor |
11 | 12 | // set up the parent port |
12 | 13 | const parentPort = new Port(common.PARENT) |
13 | 14 | parentPort.on('message', message => { |
@@ -34,9 +35,10 @@ | ||
34 | 35 | // create destination kernel |
35 | 36 | const state = await this.state.get(name) |
36 | 37 | const destKernel = new this.Kernel({ |
37 | 38 | state: state, |
38 | - parentPort: port | |
39 | + parentPort: port, | |
40 | + imports: this.imports | |
39 | 41 | }) |
40 | 42 | |
41 | 43 | // shutdown the kernel when it is done doing it work |
42 | 44 | destKernel.on('idle', () => { |
runTx.js | ||
---|---|---|
@@ -1,10 +1,10 @@ | ||
1 | -class runtx extends Kernel { | |
2 | - run (tx) { | |
1 | +// class runtx extends Kernel { | |
2 | +// run (tx) { | |
3 | 3 | |
4 | 4 | |
5 | - } | |
6 | -} | |
5 | +// } | |
6 | +// } | |
7 | 7 | |
8 | 8 | |
9 | 9 | // run tx; the tx message handler |
10 | 10 | // runTx (tx, environment = new Environment()) { |
tests/interfaceRunner.js | ||
---|---|---|
@@ -9,10 +9,10 @@ | ||
9 | 9 | const fakeBlockChain = require('../fakeBlockChain.js') |
10 | 10 | const Hypervisor = require('../hypervisor.js') |
11 | 11 | const Message = require('../message.js') |
12 | 12 | const common = require('../common') |
13 | - | |
14 | 13 | const dir = path.join(__dirname, '/interface') |
14 | +const EVMinterface = require('../EVMinterface.js') | |
15 | 15 | // get the test names |
16 | 16 | let tests = fs.readdirSync(dir).filter((file) => file.endsWith('.wast')) |
17 | 17 | // tests = ['sstore.wast'] |
18 | 18 | |
@@ -21,9 +21,9 @@ | ||
21 | 21 | function runTests (tests) { |
22 | 22 | for (let testName of tests) { |
23 | 23 | testName = testName.split('.')[0] |
24 | 24 | tape(testName, async (t) => { |
25 | - const hypervisor = new Hypervisor() | |
25 | + const hypervisor = new Hypervisor(new Vertex(), [EVMinterface]) | |
26 | 26 | const rootVertex = hypervisor.state |
27 | 27 | const code = fs.readFileSync(`${dir}/${testName}.wasm`) |
28 | 28 | const envData = JSON.parse(fs.readFileSync(`${dir}/${testName}.json`).toString()) |
29 | 29 |
Built with git-ssb-web