git ssb

0+

wanderer🌟 / js-primea-hypervisor



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.jschanged
wasmContainer.jsView
@@ -37,39 +37,50 @@
3737
3838 class FunctionRef {
3939 constructor (location, identifier, params, id) {
4040 this.location = location
41+ this.identifier = identifier
4142 this.destId = id
4243 this.params = params
43- this.identifier = identifier
4444
45- const wrapper = typeCheckWrapper(params)
45+ }
46+
47+ generateWrapper (container) {
48+ let wrapper = typeCheckWrapper(this.params)
4649 const wasm = json2wasm(wrapper)
4750 const mod = WebAssembly.Module(wasm)
4851 const self = this
49- this.wrapper = WebAssembly.Instance(mod, {
52+ wrapper = WebAssembly.Instance(mod, {
5053 'env': {
5154 'checkTypes': function () {
5255 const args = [...arguments]
5356 const checkedArgs = []
5457 while (args.length) {
5558 const type = LANGUAGE_TYPES[args.shift()]
5659 let arg = args.shift()
5760 if (!nativeTypes.has(type)) {
58- arg = self._container.refs.get(arg, type)
61+ arg = container.refs.get(arg, type)
5962 }
6063 checkedArgs.push(arg)
6164 }
6265 const message = new Message({
6366 funcRef: self,
6467 funcArguments: checkedArgs
6568 })
66- self._container.actor.send(message)
69+ container.actor.send(message)
6770 }
6871 }
6972 })
70- this.wrapper.exports.check.object = this
73+ wrapper.exports.check.object = this
74+ return wrapper
7175 }
76+
77+ encodeCBOR (gen) {
78+ return gen.write({
79+ '>': {}
80+ })
81+ }
82+
7283 set container (container) {
7384 this._container = container
7485 }
7586 }
@@ -87,10 +98,10 @@
8798 encodeCBOR (gen) {
8899 return gen.write({
89100 '#': {
90101 exports: this.exports,
91- '@': {
92- id: this.id
102+ id: {
103+ '@': this.id
93104 }
94105 }
95106 })
96107 }
@@ -152,10 +163,10 @@
152163 }
153164 },
154165 internalize: (ref, index) => {
155166 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)
158169 },
159170 catch: (ref, catchRef) => {
160171 const {funcRef} = self.refs.get(ref, FunctionRef)
161172 const {funcRef: catchFunc} = self.refs.get(ref, FunctionRef)

Built with git-ssb-web