Commit fc3efb6d1a8e5ef2e4cbd0017fa9649b221b8793
added system objects
Signed-off-by: wanderer <mjbecze@gmail.com>wanderer committed on 2/28/2018, 9:04:23 PM
Parent: 7c6e94b073aaac86243093e7d533ecd1cbdb587d
Files changed
wasmContainer.js | changed |
systemObjects.js | added |
wasmContainer.js | ||
---|---|---|
@@ -4,27 +4,10 @@ | ||
4 | 4 | const Message = require('./message.js') |
5 | 5 | const customTypes = require('./customTypes.js') |
6 | 6 | const injectGlobals = require('./injectGlobals.js') |
7 | 7 | const typeCheckWrapper = require('./typeCheckWrapper.js') |
8 | -const {FunctionRef} = require('./systemObjects.js') | |
9 | -const cbor = require('borc') | |
8 | +const {FunctionRef, ModuleRef, DEFAULTS} = require('./systemObjects.js') | |
10 | 9 | |
11 | -const TAGS = { | |
12 | - link: 42, | |
13 | - id: 43, | |
14 | - func: 43, | |
15 | - mod: 44 | |
16 | -} | |
17 | - | |
18 | -const DEFAULTS = { | |
19 | - elem: [], | |
20 | - buf: Buffer.from([]), | |
21 | - id: new cbor.Tagged(TAGS.id, 0), | |
22 | - mod: new cbor.Tagged(TAGS.mod, [{}, new cbor.Tagged(TAGS.id, 0)]), | |
23 | - link: {'/': null}, | |
24 | - func: new cbor.Tagged(TAGS.func, 0) | |
25 | -} | |
26 | - | |
27 | 10 | const nativeTypes = new Set(['i32', 'i64', 'f32', 'f64']) |
28 | 11 | const LANGUAGE_TYPES = { |
29 | 12 | 'actor': 0x0, |
30 | 13 | 'buf': 0x1, |
@@ -82,34 +65,8 @@ | ||
82 | 65 | wrapper.exports.check.object = funcRef |
83 | 66 | return wrapper |
84 | 67 | } |
85 | 68 | |
86 | -class ModuleRef { | |
87 | - constructor (ex, id) { | |
88 | - this.exports = ex | |
89 | - this.id = id | |
90 | - } | |
91 | - | |
92 | - getFuncRef (name) { | |
93 | - return new FunctionRef(false, name, this.exports[name], this.id) | |
94 | - } | |
95 | - | |
96 | - encodeCBOR (gen) { | |
97 | - return gen.write(new cbor.Tagged(TAGS.mod, [this.exports, new cbor.Tagged(TAGS.id, this.id)])) | |
98 | - } | |
99 | - | |
100 | - static fromMetaJSON (json, id) { | |
101 | - const exports = {} | |
102 | - for (const ex in json.exports) { | |
103 | - const type = json.types[json.indexes[json.exports[ex].toString()]].params | |
104 | - exports[ex] = type | |
105 | - } | |
106 | - return new ModuleRef(exports, id) | |
107 | - } | |
108 | - | |
109 | - static deserialize (serialized) {} | |
110 | -} | |
111 | - | |
112 | 69 | module.exports = class WasmContainer { |
113 | 70 | constructor (actor) { |
114 | 71 | this.actor = actor |
115 | 72 | this.refs = new ReferanceMap() |
systemObjects.js | ||
---|---|---|
@@ -1,0 +1,82 @@ | ||
1 | +const cbor = require('borc') | |
2 | + | |
3 | +const TAGS = { | |
4 | + link: 42, | |
5 | + id: 43, | |
6 | + func: 43, | |
7 | + mod: 44 | |
8 | +} | |
9 | + | |
10 | +const DEFAULTS = { | |
11 | + elem: [], | |
12 | + buf: Buffer.from([]), | |
13 | + id: new cbor.Tagged(TAGS.id, 0), | |
14 | + mod: new cbor.Tagged(TAGS.mod, [{}, new cbor.Tagged(TAGS.id, 0)]), | |
15 | + link: {'/': null}, | |
16 | + func: new cbor.Tagged(TAGS.func, 0) | |
17 | +} | |
18 | + | |
19 | +class FunctionRef { | |
20 | + constructor (privateFunc, identifier, params, id) { | |
21 | + this.private = privateFunc | |
22 | + this.identifier = identifier | |
23 | + this.destId = id | |
24 | + this.params = params | |
25 | + } | |
26 | + | |
27 | + encodeCBOR (gen) { | |
28 | + return gen.write(new cbor.Tagged(TAGS.func, [ | |
29 | + this.private, | |
30 | + this.identifier, | |
31 | + this.destId, | |
32 | + this.params | |
33 | + ])) | |
34 | + } | |
35 | + | |
36 | + set container (container) { | |
37 | + this._container = container | |
38 | + } | |
39 | +} | |
40 | + | |
41 | +class ModuleRef { | |
42 | + constructor (ex, id) { | |
43 | + this.exports = ex | |
44 | + this.id = id | |
45 | + } | |
46 | + | |
47 | + getFuncRef (name) { | |
48 | + return new FunctionRef(false, name, this.exports[name], this.id) | |
49 | + } | |
50 | + | |
51 | + encodeCBOR (gen) { | |
52 | + return gen.write(new cbor.Tagged(TAGS.mod, [this.exports, this.id])) | |
53 | + } | |
54 | + | |
55 | + static fromMetaJSON (json, id) { | |
56 | + const exports = {} | |
57 | + for (const ex in json.exports) { | |
58 | + const type = json.types[json.indexes[json.exports[ex].toString()]].params | |
59 | + exports[ex] = type | |
60 | + } | |
61 | + return new ModuleRef(exports, id) | |
62 | + } | |
63 | + | |
64 | + static deserialize (serialized) {} | |
65 | +} | |
66 | + | |
67 | +class ID { | |
68 | + constructor (id) { | |
69 | + this.id = id | |
70 | + } | |
71 | + | |
72 | + encodeCBOR (gen) { | |
73 | + return gen.write(cbor.Tagged(TAGS.id, this.id)) | |
74 | + } | |
75 | +} | |
76 | + | |
77 | +module.exports = { | |
78 | + ID, | |
79 | + FunctionRef, | |
80 | + ModuleRef, | |
81 | + DEFAULTS | |
82 | +} |
Built with git-ssb-web