git ssb

0+

wanderer🌟 / js-primea-hypervisor



Commit d291bade737857a6cb2a21c8505c308c7a61a90e

write code directly to tree

Signed-off-by: wanderer <mjbecze@gmail.com>
wanderer committed on 2/28/2018, 11:06:13 PM
Parent: fc3efb6d1a8e5ef2e4cbd0017fa9649b221b8793

Files changed

index.jschanged
wasmContainer.jschanged
index.jsView
@@ -1,5 +1,6 @@
11 const Actor = require('./actor.js')
2+const RadixTree = require('dfinity-radix-tree')
23 const Scheduler = require('./scheduler.js')
34 const {ID} = require('./systemObjects.js')
45
56 module.exports = class Hypervisor {
@@ -29,10 +30,11 @@
2930 }
3031
3132 async loadActor (id) {
3233 const state = await this.tree.getSubTree(id.id)
33- const code = state.get(Buffer.from([0]))
34- const {type, nonce} = Actor.deserializeMetaData(state.root['/'][3])
34+ const state2 = await this.tree.get(id.id, true)
35+ let code = await this.tree.graph.get(state2.root, '1')
36+ const {type, nonce} = Actor.deserializeMetaData(state2.value)
3537 const Container = this._containerTypes[type]
3638
3739 // create a new actor instance
3840 const actor = new Actor({
@@ -66,9 +68,10 @@
6668
6769 // save the container in the state
6870 this.tree.set(idHash.id, metaData)
6971 if (code) {
70- this.tree.set(Buffer.concat([idHash.id, Buffer.from([0])]), code)
72+ const node = await this.tree.get(idHash.id)
73+ await this.tree.graph.set(node.root, '1', code)
7174 }
7275 return {
7376 id: idHash,
7477 module: module
wasmContainer.jsView
@@ -8,21 +8,8 @@
88 const {FunctionRef, ModuleRef, DEFAULTS} = require('./systemObjects.js')
99
1010 const nativeTypes = new Set(['i32', 'i64', 'f32', 'f64'])
1111 const LANGUAGE_TYPES = {
12- 'actor': 0x0,
13- 'buf': 0x1,
14- 'elem': 0x2,
15- 'link': 0x3,
16- 'id': 0x4,
17- 'i32': 0x7f,
18- 'i64': 0x7e,
19- 'f32': 0x7d,
20- 'f64': 0x7c,
21- 'anyFunc': 0x70,
22- 'func': 0x60,
23- 'block_type': 0x40,
24-
2512 0x0: 'actor',
2613 0x1: 'buf',
2714 0x02: 'elem',
2815 0x03: 'link',
@@ -257,9 +244,8 @@
257244 while (numOfGlobals--) {
258245 const ref = mem[numOfGlobals]
259246 this.storage.push(this.refs.get(ref, this.json.globals[numOfGlobals].type))
260247 }
261-
262248 this.actor.state.set(Buffer.from([1]), this.storage)
263249 }
264250
265251 this.refs.clear()
@@ -308,9 +294,9 @@
308294 })
309295 }),
310296 this.actor.state.get(Buffer.from([1]))
311297 ])
312- this.storage = storage
298+ this.storage = storage.value
313299 wasm = Buffer.from(wasm, 'hex')
314300 json = JSON.parse(json)
315301 this.mod = WebAssembly.Module(wasm)
316302 this.json = json

Built with git-ssb-web