git ssb

0+

wanderer🌟 / js-primea-hypervisor



Commit b4f2286715e5d94ee25ada50027f1690079cca1b

added debuging agent

wanderer committed on 1/26/2017, 2:14:15 AM
Parent: fe338fdb6c586d0d30ccf3d53e445c347b67e8aa

Files changed

codeHandler.jschanged
debugInterface.jschanged
wasmAgent.jschanged
wasmDebugAgent.jsadded
codeHandler.jsView
@@ -18,15 +18,16 @@
1818 return new Wasm(code)
1919 }
2020 }
2121
22-let codeHandlers = exports.codeHandlers = [
23- defaultHandler,
24- wasm
25-]
22+let codeHandlers = exports.handlers = {
23+ default: defaultHandler,
24+ wasm: wasm
25+}
2626
2727 exports.init = (code) => {
28- for (let handler of codeHandlers) {
28+ for (let name in codeHandlers) {
29+ const handler = codeHandlers[name]
2930 if (handler.test(code)) {
3031 return handler.init(code)
3132 }
3233 }
debugInterface.jsView
@@ -3,9 +3,8 @@
33 /**
44 * Debug Interface
55 * This expose some functions that can help with debugging wast
66 */
7-
87 module.exports = class DebugInterface {
98 constructor (kernel) {
109 this.kernel = kernel
1110 }
wasmAgent.jsView
@@ -26,9 +26,9 @@
2626 return importMap
2727 }
2828
2929 let instance
30- const interfaceApi = {
30+ const interfaceApi = this.api = {
3131 /**
3232 * adds an aync operation to the operations queue
3333 */
3434 pushOpsQueue: (promise, callbackIndex, intefaceCallback) => {
wasmDebugAgent.jsView
@@ -1,0 +1,50 @@
1+const Wasm = require('./wasmAgent')
2+
3+module.exports = class Test extends Wasm {
4+ /**
5+ * Runs the core VM with a given environment and imports
6+ */
7+ async run (message, kernel, imports) {
8+ const responses = {}
9+ /**
10+ * Builds a import map with an array of given interfaces
11+ */
12+ async function buildImports (kernelApi, kernel, imports) {
13+ const importMap = {}
14+ for (const Import of imports) {
15+ const response = responses[Import.name] = {}
16+ const newIterface = new Import(kernelApi, message, response)
17+ importMap[Import.name] = newIterface.exports
18+ // initailize the import
19+ await newIterface.initialize()
20+ }
21+ return importMap
22+ }
23+
24+ let instance
25+ const interfaceApi = {
26+ /**
27+ * adds an aync operation to the operations queue
28+ */
29+ pushOpsQueue: (promise, callbackIndex, intefaceCallback) => {
30+ this._opsQueue = Promise.all([this._opsQueue, promise]).then(values => {
31+ const result = intefaceCallback(values.pop())
32+ instance.exports.callback.get(callbackIndex)(result)
33+ })
34+ },
35+ memory: () => {
36+ return instance.exports.memory.buffer
37+ },
38+ kernel: kernel
39+ }
40+
41+ const initializedImports = await buildImports(interfaceApi, kernel, imports)
42+ this.instance = instance = WebAssembly.Instance(this._module, initializedImports)
43+
44+ if (instance.exports.main) {
45+ instance.exports.main()
46+ }
47+ await this.onDone()
48+ return responses
49+ }
50+}

Built with git-ssb-web