git ssb

0+

wanderer🌟 / js-primea-hypervisor



Commit 88d61c8591d4cdf5ba2022f4eeaa1af8e06891a5

remove EVMinterface dep

wanderer committed on 3/1/2017, 4:28:44 PM
Parent: 841228acfa1dad00f990ebe18290a46130f85d5d

Files changed

hypervisor.jschanged
index.jschanged
portManager.jschanged
runTx.jschanged
tests/interfaceRunner.jschanged
hypervisor.jsView
@@ -4,19 +4,12 @@
44 // const blockchain = require('./fakeBlockChain.js')
55 const codeHandlers = require('./codeHandler.js')
66
77 module.exports = class Hypervisor {
8- constructor (state = new Vertex()) {
8+ constructor (state = new Vertex(), imports = []) {
99 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- // }
1810 this.root = new Kernel({
11+ imports: imports,
1912 state: state
2013 })
2114 }
2215
index.jsView
@@ -1,8 +1,7 @@
11 const EventEmitter = require('events')
22 const Vertex = require('merkle-trie')
33 const PortManager = require('./portManager.js')
4-const imports = require('./EVMinterface.js')
54 const codeHandler = require('./codeHandler.js')
65
76 module.exports = class Kernel extends EventEmitter {
87 constructor (opts = {}) {
@@ -11,29 +10,29 @@
1110 const state = this.state = opts.state || new Vertex()
1211 this.path = state.path
1312
1413 // set up the vm
15- this.imports = opts.imports || [imports]
14+ this.imports = opts.imports
1615 this._vm = (opts.codeHandler || codeHandler).init(opts.code || state.value)
17- this._state = 'idle'
16+ this._vmstate = 'idle'
1817
1918 // 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)
2220 this.ports.on('message', index => {
2321 this.runNextMessage(index)
2422 })
23+ this._sentAtomicMessages = []
2524 }
2625
2726 runNextMessage (index = 0) {
2827 // load the next message from port space
2928 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')) {
3130 this._currentMessage = message
3231 this.ports.remove(index)
3332 return this.run(message)
3433 } else {
35- this._state = 'idle'
34+ this._vmstate = 'idle'
3635 this.emit('idle')
3736 }
3837 })
3938 }
@@ -54,9 +53,9 @@
5453 }
5554
5655 const oldState = this.state.copy()
5756 let result
58- this._state = 'running'
57+ this._vmstate = 'running'
5958 try {
6059 result = await this._vm.run(message, this, imports) || {}
6160 } catch (e) {
6261 result = {
portManager.jsView
@@ -2,12 +2,13 @@
22 const Port = require('./port.js')
33 const common = require('./common.js')
44
55 module.exports = class PortManager extends EventEmitter {
6- constructor (state, destParentPort, KernelContructor) {
6+ constructor (state, destParentPort, KernelContructor, imports) {
77 super()
88 this._queue = []
99 this.state = state
10+ this.imports = imports
1011 this.Kernel = KernelContructor
1112 // set up the parent port
1213 const parentPort = new Port(common.PARENT)
1314 parentPort.on('message', message => {
@@ -34,9 +35,10 @@
3435 // create destination kernel
3536 const state = await this.state.get(name)
3637 const destKernel = new this.Kernel({
3738 state: state,
38- parentPort: port
39+ parentPort: port,
40+ imports: this.imports
3941 })
4042
4143 // shutdown the kernel when it is done doing it work
4244 destKernel.on('idle', () => {
runTx.jsView
@@ -1,10 +1,10 @@
1-class runtx extends Kernel {
2- run (tx) {
1+// class runtx extends Kernel {
2+// run (tx) {
33
44
5- }
6-}
5+// }
6+// }
77
88
99 // run tx; the tx message handler
1010 // runTx (tx, environment = new Environment()) {
tests/interfaceRunner.jsView
@@ -9,10 +9,10 @@
99 const fakeBlockChain = require('../fakeBlockChain.js')
1010 const Hypervisor = require('../hypervisor.js')
1111 const Message = require('../message.js')
1212 const common = require('../common')
13-
1413 const dir = path.join(__dirname, '/interface')
14+const EVMinterface = require('../EVMinterface.js')
1515 // get the test names
1616 let tests = fs.readdirSync(dir).filter((file) => file.endsWith('.wast'))
1717 // tests = ['sstore.wast']
1818
@@ -21,9 +21,9 @@
2121 function runTests (tests) {
2222 for (let testName of tests) {
2323 testName = testName.split('.')[0]
2424 tape(testName, async (t) => {
25- const hypervisor = new Hypervisor()
25+ const hypervisor = new Hypervisor(new Vertex(), [EVMinterface])
2626 const rootVertex = hypervisor.state
2727 const code = fs.readFileSync(`${dir}/${testName}.wasm`)
2828 const envData = JSON.parse(fs.readFileSync(`${dir}/${testName}.json`).toString())
2929

Built with git-ssb-web