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.js | changed |
wasmContainer.js | changed |
index.js | ||
---|---|---|
@@ -1,5 +1,6 @@ | ||
1 | 1 | const Actor = require('./actor.js') |
2 | +const RadixTree = require('dfinity-radix-tree') | |
2 | 3 | const Scheduler = require('./scheduler.js') |
3 | 4 | const {ID} = require('./systemObjects.js') |
4 | 5 | |
5 | 6 | module.exports = class Hypervisor { |
@@ -29,10 +30,11 @@ | ||
29 | 30 | } |
30 | 31 | |
31 | 32 | async loadActor (id) { |
32 | 33 | 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) | |
35 | 37 | const Container = this._containerTypes[type] |
36 | 38 | |
37 | 39 | // create a new actor instance |
38 | 40 | const actor = new Actor({ |
@@ -66,9 +68,10 @@ | ||
66 | 68 | |
67 | 69 | // save the container in the state |
68 | 70 | this.tree.set(idHash.id, metaData) |
69 | 71 | 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) | |
71 | 74 | } |
72 | 75 | return { |
73 | 76 | id: idHash, |
74 | 77 | module: module |
wasmContainer.js | ||
---|---|---|
@@ -8,21 +8,8 @@ | ||
8 | 8 | const {FunctionRef, ModuleRef, DEFAULTS} = require('./systemObjects.js') |
9 | 9 | |
10 | 10 | const nativeTypes = new Set(['i32', 'i64', 'f32', 'f64']) |
11 | 11 | 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 | - | |
25 | 12 | 0x0: 'actor', |
26 | 13 | 0x1: 'buf', |
27 | 14 | 0x02: 'elem', |
28 | 15 | 0x03: 'link', |
@@ -257,9 +244,8 @@ | ||
257 | 244 | while (numOfGlobals--) { |
258 | 245 | const ref = mem[numOfGlobals] |
259 | 246 | this.storage.push(this.refs.get(ref, this.json.globals[numOfGlobals].type)) |
260 | 247 | } |
261 | - | |
262 | 248 | this.actor.state.set(Buffer.from([1]), this.storage) |
263 | 249 | } |
264 | 250 | |
265 | 251 | this.refs.clear() |
@@ -308,9 +294,9 @@ | ||
308 | 294 | }) |
309 | 295 | }), |
310 | 296 | this.actor.state.get(Buffer.from([1])) |
311 | 297 | ]) |
312 | - this.storage = storage | |
298 | + this.storage = storage.value | |
313 | 299 | wasm = Buffer.from(wasm, 'hex') |
314 | 300 | json = JSON.parse(json) |
315 | 301 | this.mod = WebAssembly.Module(wasm) |
316 | 302 | this.json = json |
Built with git-ssb-web