git ssb

0+

wanderer🌟 / js-primea-hypervisor



Commit 7465ee54b512e6772d88465794c551333e42ecfe

added interfaceAPI

wanderer committed on 11/5/2016, 11:32:23 AM
Parent: c326c8af2a729760e833b861163acade71770ff5

Files changed

interfaceAPI.jsadded
interfaceAPI.jsView
@@ -1,0 +1,47 @@
1+module.exports = class interfaceAPI {
2+ /**
3+ * The interface API is the api the exposed to interfaces. All queries about
4+ * the enviroment and call to the kernel go through this API
5+ */
6+ constructor (code) {
7+ this._module = WebAssembly.Module(code)
8+ }
9+
10+ run (environment, imports) {
11+ this._environment = environment
12+ // TODO, delete the instance once done.
13+ const instance = this._instance = WebAssembly.Instance(this._module, imports)
14+ if (instance.exports.main) {
15+ instance.exports.main()
16+ }
17+ return this.onDone()
18+ }
19+
20+ // returns a promise that resolves when the wasm instance is done running
21+ async onDone () {
22+ let prevOps
23+ while (prevOps !== this._opsQueue) {
24+ prevOps = this._opsQueue
25+ await this._opsQueue
26+ }
27+ }
28+
29+ pushOpsQueue (promise, callbackIndex, intefaceCallback) {
30+ this._opsQueue = Promise.all([this._opsQueue, promise]).then(values => {
31+ intefaceCallback(values.pop())
32+ this._instance.exports[callbackIndex.toString()]()
33+ })
34+ }
35+
36+ sendMessage (message) {
37+
38+ }
39+
40+ get environment () {
41+ return this._environment
42+ }
43+
44+ get memory () {
45+ return this._instance.exports.memory
46+ }
47+}

Built with git-ssb-web