Commit fe2d3d73d28c55f28860b137e3990bae31fbd26b
fix in defualtAgent
wanderer committed on 1/21/2017, 1:04:37 AMParent: 05c4e2d027ee79f709d87c92e48f83e9cb3489ad
Files changed
EVMinterface.js | changed |
defaultAgent.js | changed |
index.js | changed |
message.js | changed |
EVMinterface.js | ||
---|---|---|
@@ -14,9 +14,9 @@ | ||
14 | 14 | const U256_SIZE_BYTES = 32 |
15 | 15 | |
16 | 16 | // The interface exposed to the WebAessembly VM |
17 | 17 | module.exports = class Interface { |
18 | - constructor (api, message, state) { | |
18 | + constructor (api, message) { | |
19 | 19 | this.message = message |
20 | 20 | this.kernel = api.kernel |
21 | 21 | this.state = api.kernel.state |
22 | 22 | this.api = api |
defaultAgent.js | ||
---|---|---|
@@ -1,7 +1,7 @@ | ||
1 | 1 | exports.run = async (message, kernel) => { |
2 | 2 | const to = message.nextPort() |
3 | - if (message.toPort) { | |
3 | + if (to) { | |
4 | 4 | return kernel.send(to, message) |
5 | 5 | } else if (message.data.getValue) { |
6 | 6 | return (await kernel.state.get(message.data.getValue)).value |
7 | 7 | } |
index.js | ||
---|---|---|
@@ -10,13 +10,15 @@ | ||
10 | 10 | constructor (opts = {}) { |
11 | 11 | const state = this.state = opts.state || new Vertex() |
12 | 12 | state.value = opts.code || state.value |
13 | 13 | this.imports = opts.imports || [imports] |
14 | - this.parent = opts.parent | |
15 | 14 | // RENAME agent |
16 | 15 | this._vm = (opts.codeHandler || codeHandler).init(state.value) |
17 | 16 | this._messageQueue = new MessageQueue(this) |
18 | 17 | this._instanceCache = new Map() |
18 | + if (opts.parent) { | |
19 | + this._instanceCache.set(opts.parent) | |
20 | + } | |
19 | 21 | } |
20 | 22 | |
21 | 23 | static get PARENT () { |
22 | 24 | return PARENT_SYMBOL |
@@ -40,14 +42,12 @@ | ||
40 | 42 | * to by the VM to retrive infromation from the Environment. |
41 | 43 | */ |
42 | 44 | async run (message, imports = this.imports) { |
43 | 45 | const state = this.state.copy() |
44 | - | |
45 | - // const stateInterface = new StateInterface(state) | |
46 | 46 | const result = await this._vm.run(message, this, imports) |
47 | 47 | if (!result.execption) { |
48 | 48 | // update the state |
49 | - await this.state.set([], state) | |
49 | + this.state.set([], state) | |
50 | 50 | } |
51 | 51 | return result |
52 | 52 | } |
53 | 53 | |
@@ -82,9 +82,10 @@ | ||
82 | 82 | async getPort (port) { |
83 | 83 | if (this._instanceCache.has(port)) { |
84 | 84 | return this._instanceCache.get(port) |
85 | 85 | } else { |
86 | - const destState = await (port === this.PARENT | |
86 | + const destState = await ( | |
87 | + port === this.PARENT | |
87 | 88 | ? this.state.getParent() |
88 | 89 | : this.state.get([port])) |
89 | 90 | |
90 | 91 | const kernel = new Kernel({ |
message.js | ||
---|---|---|
@@ -1,13 +1,11 @@ | ||
1 | 1 | const U256 = require('./deps/u256.js') |
2 | -const Address = require('./deps/address.js') | |
3 | 2 | |
4 | 3 | module.exports = class Message { |
5 | 4 | constructor (opts = {}) { |
6 | 5 | const defaults = { |
7 | 6 | // call infromation |
8 | 7 | to: [], |
9 | - origin: new Address('0x0000000000000000000000000000000000000000'), | |
10 | 8 | from: [], |
11 | 9 | data: new Uint8Array(), |
12 | 10 | sync: true, |
13 | 11 | // resource info |
Built with git-ssb-web