git ssb

0+

wanderer🌟 / js-primea-hypervisor



Commit 08886ada2409d7516bf4a5654c170fa62fe5e439

move symbols to common

wanderer committed on 1/24/2017, 11:34:01 PM
Parent: 7a180f8331c532b243f6fda8a92ea00c741b4aaa

Files changed

EVMinterface.jschanged
index.jschanged
tests/interfaceRunner.jschanged
common.jsadded
EVMinterface.jsView
@@ -7,8 +7,9 @@
77 const ethUtil = require('ethereumjs-util')
88 const Vertex = require('merkle-trie')
99 const U256 = require('./deps/u256.js')
1010 const Message = require('./message.js')
11+const common = require('./common.js')
1112
1213 const U128_SIZE_BYTES = 16
1314 const ADDRESS_SIZE_BYTES = 20
1415 const U256_SIZE_BYTES = 32
@@ -33,16 +34,16 @@
3334 })
3435 }
3536
3637 async initialize () {
37- this.block = await this.kernel.send(this.kernel.ROOT, new Message({
38+ this.block = await this.kernel.send(common.ROOT, new Message({
3839 data: {
3940 getValue: 'block'
4041 },
4142 sync: true
4243 }))
4344
44- this.blockchain = await this.kernel.send(this.kernel.ROOT, new Message({
45+ this.blockchain = await this.kernel.send(common.ROOT, new Message({
4546 data: {
4647 getValue: 'blockchain'
4748 },
4849 sync: true
@@ -149,10 +150,10 @@
149150 */
150151 getBalance (addressOffset, offset, cbIndex) {
151152 this.takeGas(20)
152153
153- const path = [this.kernel.PARENT, '0x' + new Buffer(this.getMemory(addressOffset, ADDRESS_SIZE_BYTES)).toString('hex')]
154- const opPromise = this.kernel.send(this.kernel.PARENT, new Message({
154+ const path = [common.PARENT, '0x' + new Buffer(this.getMemory(addressOffset, ADDRESS_SIZE_BYTES)).toString('hex')]
155+ const opPromise = this.kernel.send(common.PARENT, new Message({
155156 to: path,
156157 data: {
157158 getValue: 'balance'
158159 },
@@ -497,9 +498,9 @@
497498 this.takeGas(40)
498499
499500 const gas = from64bit(gasHigh, gasLow)
500501 // Load the params from mem
501- const address = [this.kernel.PARENT, ...this.getMemory(addressOffset, ADDRESS_SIZE_BYTES)]
502+ const address = [common.PARENT, ...this.getMemory(addressOffset, ADDRESS_SIZE_BYTES)]
502503 const value = new U256(this.getMemory(valueOffset, U128_SIZE_BYTES))
503504
504505 // Special case for non-zero value; why does this exist?
505506 if (!value.isZero()) {
index.jsView
@@ -2,12 +2,10 @@
22 const Cache = require('imperative-trie')
33 const imports = require('./EVMinterface.js')
44 const codeHandler = require('./codeHandler.js')
55 const MessageQueue = require('./messageQueue')
6+const common = require('./common.js')
67
7-const PARENT_SYMBOL = Symbol('parent')
8-const ROOT_SYMBOL = Symbol('root')
9-
108 module.exports = class Kernel {
119 constructor (opts = {}) {
1210 const state = this.state = opts.state || new Vertex()
1311 state.value = opts.code || state.value
@@ -17,24 +15,8 @@
1715 this._messageQueue = new MessageQueue(this)
1816 this._instanceCache = new Cache()
1917 }
2018
21- static get PARENT () {
22- return PARENT_SYMBOL
23- }
24-
25- static get ROOT () {
26- return ROOT_SYMBOL
27- }
28-
29- get PARENT () {
30- return PARENT_SYMBOL
31- }
32-
33- get ROOT () {
34- return ROOT_SYMBOL
35- }
36-
3719 /**
3820 * run the kernels code with a given enviroment
3921 * The Kernel Stores all of its state in the Environment. The Interface is used
4022 * to by the VM to retrive infromation from the Environment.
@@ -61,17 +43,17 @@
6143
6244 async send (port, message) {
6345 message.sending(this, this._messageQueue.currentMessage)
6446 // replace root with parent path to root
65- if (port === ROOT_SYMBOL) {
66- port = PARENT_SYMBOL
67- message.to = new Array(this.state.path.length - 1).fill(PARENT_SYMBOL).concat(message.to)
47+ if (port === common.ROOT) {
48+ port = common.PARENT
49+ message.to = new Array(this.state.path.length - 1).fill(common.PARENT).concat(message.to)
6850 }
6951
70- if (port === PARENT_SYMBOL) {
52+ if (port === common.PARENT) {
7153 message.from.push(this.state.name)
7254 } else {
73- message.from.push(this.PARENT)
55+ message.from.push(common.PARENT)
7456 }
7557
7658 const dest = await this.getPort(port)
7759 return dest.recieve(message)
@@ -86,9 +68,9 @@
8668 }
8769
8870 async getPort (name) {
8971 let kernel
90- if (name === this.PARENT) {
72+ if (name === common.PARENT) {
9173 kernel = this.parent
9274 } else {
9375 kernel = this._instanceCache.get(name)
9476 }
@@ -96,9 +78,9 @@
9678 if (kernel) {
9779 return kernel
9880 } else {
9981 const destState = await (
100- name === this.PARENT
82+ name === common.PARENT
10183 ? this.state.getParent()
10284 : this.state.get([name]))
10385
10486 const kernel = new Kernel({
tests/interfaceRunner.jsView
@@ -8,8 +8,9 @@
88 // TODO remove fakeblockchain
99 const fakeBlockChain = require('../fakeBlockChain.js')
1010 const Kernel = require('../index.js')
1111 const Message = require('../message.js')
12+const common = require('../common.js')
1213
1314 const dir = path.join(__dirname, '/interface')
1415 // get the test names
1516 let tests = fs.readdirSync(dir).filter((file) => file.endsWith('.wast'))
@@ -69,9 +70,9 @@
6970
7071 const callerState = await rootVertex.get(['accounts', envData.caller, 'code'])
7172 const caller = new Kernel({state: callerState})
7273 try {
73- await caller.send(Kernel.ROOT, message)
74+ await caller.send(common.ROOT, message)
7475 } catch (e) {
7576 t.fail('Exception: ' + e)
7677 console.error('FAIL')
7778 console.error(e)
common.jsView
@@ -1,0 +1,2 @@
1+exports.PARENT = Symbol('parent')
2+exports.ROOT = Symbol('root')

Built with git-ssb-web