git ssb

0+

wanderer🌟 / js-primea-hypervisor



Commit 9614aca7d0fa9c4a2fa282568f2a104e73a2fff1

let the kenerel call ewasm callbacks

wanderer committed on 10/31/2016, 6:00:02 PM
Parent: 94e70479466583e8f96e3641f443293d8f7d77e3

Files changed

index.jschanged
interface.jschanged
index.jsView
@@ -84,11 +84,13 @@
8484 await this._runningOps
8585 }
8686 }
8787
88- _addOperation (op) {
89- this._runningOps = Promise.all([this._runningOps, op])
90- return this._runningOps
88+ _addOperation (promise, callbackIndex, intefaceCallback) {
89+ this._runningOps = Promise.all([this._runningOps, promise]).then(values => {
90+ intefaceCallback(values.pop())
91+ this.instance.exports[callbackIndex.toString()]()
92+ })
9193 }
9294
9395 // loads code from the merkle trie and delegates the message
9496 // Detects if code is EVM or WASM
interface.jsView
@@ -276,13 +276,10 @@
276276 opPromise = this.environment.getBlockHash(number)
277277 }
278278
279279 // wait for all the prevouse async ops to finish before running the callback
280- this.kernel._addOperation(opPromise)
281- .then(values => {
282- const hash = values.pop()
280+ this.kernel._addOperation(opPromise, cbOffset, hash => {
283281 this.setMemory(offset, U256_SIZE_BYTES, hash.toMemory())
284- this.module.exports[cbOffset.toString()]()
285282 })
286283 }
287284
288285 /**
@@ -518,11 +515,9 @@
518515 // the value was not found
519516 return null
520517 })
521518
522- this.kernel._addOperation(opPromise)
523- .then(values => {
524- const oldValue = values.pop()
519+ this.kernel._addOperation(opPromise, cbDest, oldValue => {
525520 if (valIsZero && oldValue) {
526521 // delete a value
527522 this.environment.gasRefund += 15000
528523 this.environment.state.del(path)
@@ -533,10 +528,8 @@
533528 }
534529 // update
535530 this.environment.state.set(path, value)
536531 }
537-
538- this.module.exports[cbDest.toString()]()
539532 })
540533 }
541534
542535 /**
@@ -555,13 +548,10 @@
555548 // if the value was not found return a empty array
556549 return new Uint8Array(32)
557550 })
558551
559- this.kernel._addOperation(opPromise)
560- .then(values => {
561- const result = values.pop()
552+ this.kernel._addOperation(opPromise, cbDest, result => {
562553 this.setMemory(resultOffset, U256_SIZE_BYTES, result)
563- this.module.exports[cbDest.toString()]()
564554 })
565555 }
566556
567557 /**

Built with git-ssb-web