git ssb

0+

wanderer🌟 / js-primea-hypervisor



Tree: 19b980f7bfa315ae01afacb96f1bb76873270b53

Files: 19b980f7bfa315ae01afacb96f1bb76873270b53 / systemObjects.js

1523 bytesRaw
1const cbor = require('borc')
2
3const TAGS = {
4 link: 42,
5 id: 43,
6 func: 43,
7 mod: 44
8}
9
10const 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
19class FunctionRef {
20 constructor (privateFunc, identifier, params, id) {
21 this.private = privateFunc
22 this.identifier = identifier
23 this.destId = id
24 this.params = params
25 this.gas = 0
26 }
27
28 encodeCBOR (gen) {
29 return gen.write(new cbor.Tagged(TAGS.func, [
30 this.private,
31 this.identifier,
32 this.destId,
33 this.params
34 ]))
35 }
36
37 set container (container) {
38 this._container = container
39 }
40}
41
42class ModuleRef {
43 constructor (ex, id) {
44 this.exports = ex
45 this.id = id
46 }
47
48 getFuncRef (name) {
49 return new FunctionRef(false, name, this.exports[name], this.id)
50 }
51
52 encodeCBOR (gen) {
53 return gen.write(new cbor.Tagged(TAGS.mod, [this.exports, this.id]))
54 }
55
56 static fromMetaJSON (json, id) {
57 const exports = {}
58 for (const ex in json.exports) {
59 const type = json.types[json.indexes[json.exports[ex].toString()]].params
60 exports[ex] = type
61 }
62 return new ModuleRef(exports, id)
63 }
64
65 static deserialize (serialized) {}
66}
67
68class ID {
69 constructor (id) {
70 this.id = id
71 }
72
73 encodeCBOR (gen) {
74 return gen.write(cbor.Tagged(TAGS.id, this.id))
75 }
76}
77
78module.exports = {
79 ID,
80 FunctionRef,
81 ModuleRef,
82 DEFAULTS
83}
84

Built with git-ssb-web