Commit 918662450986924c9a68f772d475dc794e4d7127
add function encoding
Signed-off-by: wanderer <mjbecze@gmail.com>wanderer committed on 2/26/2018, 11:51:20 PM
Parent: e6bb7dfe86f19f0188e093e016c11a70df79bf72
Files changed
wasmContainer.js | changed |
wasmContainer.js | ||
---|---|---|
@@ -37,39 +37,50 @@ | ||
37 | 37 | |
38 | 38 | class FunctionRef { |
39 | 39 | constructor (location, identifier, params, id) { |
40 | 40 | this.location = location |
41 | + this.identifier = identifier | |
41 | 42 | this.destId = id |
42 | 43 | this.params = params |
43 | - this.identifier = identifier | |
44 | 44 | |
45 | - const wrapper = typeCheckWrapper(params) | |
45 | + } | |
46 | + | |
47 | + generateWrapper (container) { | |
48 | + let wrapper = typeCheckWrapper(this.params) | |
46 | 49 | const wasm = json2wasm(wrapper) |
47 | 50 | const mod = WebAssembly.Module(wasm) |
48 | 51 | const self = this |
49 | - this.wrapper = WebAssembly.Instance(mod, { | |
52 | + wrapper = WebAssembly.Instance(mod, { | |
50 | 53 | 'env': { |
51 | 54 | 'checkTypes': function () { |
52 | 55 | const args = [...arguments] |
53 | 56 | const checkedArgs = [] |
54 | 57 | while (args.length) { |
55 | 58 | const type = LANGUAGE_TYPES[args.shift()] |
56 | 59 | let arg = args.shift() |
57 | 60 | if (!nativeTypes.has(type)) { |
58 | - arg = self._container.refs.get(arg, type) | |
61 | + arg = container.refs.get(arg, type) | |
59 | 62 | } |
60 | 63 | checkedArgs.push(arg) |
61 | 64 | } |
62 | 65 | const message = new Message({ |
63 | 66 | funcRef: self, |
64 | 67 | funcArguments: checkedArgs |
65 | 68 | }) |
66 | - self._container.actor.send(message) | |
69 | + container.actor.send(message) | |
67 | 70 | } |
68 | 71 | } |
69 | 72 | }) |
70 | - this.wrapper.exports.check.object = this | |
73 | + wrapper.exports.check.object = this | |
74 | + return wrapper | |
71 | 75 | } |
76 | + | |
77 | + encodeCBOR (gen) { | |
78 | + return gen.write({ | |
79 | + '>': {} | |
80 | + }) | |
81 | + } | |
82 | + | |
72 | 83 | set container (container) { |
73 | 84 | this._container = container |
74 | 85 | } |
75 | 86 | } |
@@ -87,10 +98,10 @@ | ||
87 | 98 | encodeCBOR (gen) { |
88 | 99 | return gen.write({ |
89 | 100 | '#': { |
90 | 101 | exports: this.exports, |
91 | - '@': { | |
92 | - id: this.id | |
102 | + id: { | |
103 | + '@': this.id | |
93 | 104 | } |
94 | 105 | } |
95 | 106 | }) |
96 | 107 | } |
@@ -152,10 +163,10 @@ | ||
152 | 163 | } |
153 | 164 | }, |
154 | 165 | internalize: (ref, index) => { |
155 | 166 | const funcRef = self.refs.get(ref, 'func') |
156 | - funcRef.container = self | |
157 | - this.instance.exports.table.set(index, funcRef.wrapper.exports.check) | |
167 | + const wrapper = funcRef.generateWrapper(self) | |
168 | + this.instance.exports.table.set(index, wrapper.exports.check) | |
158 | 169 | }, |
159 | 170 | catch: (ref, catchRef) => { |
160 | 171 | const {funcRef} = self.refs.get(ref, FunctionRef) |
161 | 172 | const {funcRef: catchFunc} = self.refs.get(ref, FunctionRef) |
Built with git-ssb-web