git ssb

0+

wanderer🌟 / js-primea-hypervisor



Commit fe2d3d73d28c55f28860b137e3990bae31fbd26b

fix in defualtAgent

wanderer committed on 1/21/2017, 1:04:37 AM
Parent: 05c4e2d027ee79f709d87c92e48f83e9cb3489ad

Files changed

EVMinterface.jschanged
defaultAgent.jschanged
index.jschanged
message.jschanged
EVMinterface.jsView
@@ -14,9 +14,9 @@
1414 const U256_SIZE_BYTES = 32
1515
1616 // The interface exposed to the WebAessembly VM
1717 module.exports = class Interface {
18- constructor (api, message, state) {
18+ constructor (api, message) {
1919 this.message = message
2020 this.kernel = api.kernel
2121 this.state = api.kernel.state
2222 this.api = api
defaultAgent.jsView
@@ -1,7 +1,7 @@
11 exports.run = async (message, kernel) => {
22 const to = message.nextPort()
3- if (message.toPort) {
3+ if (to) {
44 return kernel.send(to, message)
55 } else if (message.data.getValue) {
66 return (await kernel.state.get(message.data.getValue)).value
77 }
index.jsView
@@ -10,13 +10,15 @@
1010 constructor (opts = {}) {
1111 const state = this.state = opts.state || new Vertex()
1212 state.value = opts.code || state.value
1313 this.imports = opts.imports || [imports]
14- this.parent = opts.parent
1514 // RENAME agent
1615 this._vm = (opts.codeHandler || codeHandler).init(state.value)
1716 this._messageQueue = new MessageQueue(this)
1817 this._instanceCache = new Map()
18+ if (opts.parent) {
19+ this._instanceCache.set(opts.parent)
20+ }
1921 }
2022
2123 static get PARENT () {
2224 return PARENT_SYMBOL
@@ -40,14 +42,12 @@
4042 * to by the VM to retrive infromation from the Environment.
4143 */
4244 async run (message, imports = this.imports) {
4345 const state = this.state.copy()
44-
45- // const stateInterface = new StateInterface(state)
4646 const result = await this._vm.run(message, this, imports)
4747 if (!result.execption) {
4848 // update the state
49- await this.state.set([], state)
49+ this.state.set([], state)
5050 }
5151 return result
5252 }
5353
@@ -82,9 +82,10 @@
8282 async getPort (port) {
8383 if (this._instanceCache.has(port)) {
8484 return this._instanceCache.get(port)
8585 } else {
86- const destState = await (port === this.PARENT
86+ const destState = await (
87+ port === this.PARENT
8788 ? this.state.getParent()
8889 : this.state.get([port]))
8990
9091 const kernel = new Kernel({
message.jsView
@@ -1,13 +1,11 @@
11 const U256 = require('./deps/u256.js')
2-const Address = require('./deps/address.js')
32
43 module.exports = class Message {
54 constructor (opts = {}) {
65 const defaults = {
76 // call infromation
87 to: [],
9- origin: new Address('0x0000000000000000000000000000000000000000'),
108 from: [],
119 data: new Uint8Array(),
1210 sync: true,
1311 // resource info

Built with git-ssb-web