git ssb

0+

wanderer🌟 / js-primea-hypervisor



Commit 49051b3e16dc9927b3bbcfe2f7a8af88ccc8a232

docs and small fixes

Norton Wang committed on 3/5/2018, 3:45:29 AM
Parent: 21960d62467278cd5659e2eb5f80cc6ddd87e663

Files changed

.gitignorechanged
customTypes.jschanged
docs/actor.mdchanged
docs/hypervisor.mdchanged
docs/index.mdchanged
docs/scheduler.mdchanged
package.jsonchanged
tests/wasmContainer.jschanged
wasmContainer.jschanged
.gitignoreView
@@ -1,2 +1,3 @@
11 node_modules/
2-testdb/
2+testdb/
3+*.sublime-*
customTypes.jsView
@@ -193,19 +193,21 @@
193193
194194 const {value: type} = iterator.next()
195195 const {value: imports = {entries: []}} = iterator.next()
196196 const {value: functions} = iterator.next()
197- functions.entries.forEach((typeIndex, funcIndex) => {
198- let customIndex = mappedFuncs.get(funcIndex)
199- if (customIndex === undefined) {
200- customIndex = mappedTypes.get(typeIndex)
201- }
202- if (customIndex === undefined) {
203- customIndex = result.types.push(type.entries[typeIndex]) - 1
204- mappedTypes.set(typeIndex, customIndex)
205- }
206- result.indexes[funcIndex + imports.entries.length] = customIndex
207- })
197+ if (functions) {
198+ functions.entries.forEach((typeIndex, funcIndex) => {
199+ let customIndex = mappedFuncs.get(funcIndex)
200+ if (customIndex === undefined) {
201+ customIndex = mappedTypes.get(typeIndex)
202+ }
203+ if (customIndex === undefined) {
204+ customIndex = result.types.push(type.entries[typeIndex]) - 1
205+ mappedTypes.set(typeIndex, customIndex)
206+ }
207+ result.indexes[funcIndex + imports.entries.length] = customIndex
208+ })
209+ }
208210
209211 const {value: exports = {entries: []}} = iterator.next()
210212 exports.entries.forEach(entry => {
211213 if (entry.kind === 'function') {
docs/actor.mdView
@@ -2,9 +2,8 @@
22
33 ### Table of Contents
44
55 - [constructor](#constructor)
6-- [queue](#queue)
76 - [shutdown](#shutdown)
87 - [startup](#startup)
98 - [runMessage](#runmessage)
109 - [incrementTicks](#incrementticks)
@@ -12,9 +11,9 @@
1211 - [send](#send)
1312
1413 ## constructor
1514
16-[actor.js:15-25](https://github.com/dfinity/js-primea/blob/3d3fc0d82dd65f14b8533dcd2fb881c9fbbb1bd3/actor.js#L15-L25 "Source code on GitHub")
15+[actor.js:11-18](https://github.com/dfinity/js-primea/blob/21960d62467278cd5659e2eb5f80cc6ddd87e663/actor.js#L11-L18 "Source code on GitHub")
1716
1817 the Actor manages the varous message passing functions and provides
1918 an interface for the containers to use
2019
@@ -25,34 +24,23 @@
2524 - `opts.state` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** the state of the container
2625 - `opts.hypervisor` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** the instance of the hypervisor
2726 - `opts.container` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** the container constuctor and argments
2827
29-## queue
30-
31-[actor.js:32-39](https://github.com/dfinity/js-primea/blob/3d3fc0d82dd65f14b8533dcd2fb881c9fbbb1bd3/actor.js#L32-L39 "Source code on GitHub")
32-
33-adds a message to this actor's message queue
34-
35-**Parameters**
36-
37-- `message` **[object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)**
38-- `portName` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)**
39-
4028 ## shutdown
4129
42-[actor.js:89-92](https://github.com/dfinity/js-primea/blob/3d3fc0d82dd65f14b8533dcd2fb881c9fbbb1bd3/actor.js#L89-L92 "Source code on GitHub")
30+[actor.js:23-29](https://github.com/dfinity/js-primea/blob/21960d62467278cd5659e2eb5f80cc6ddd87e663/actor.js#L23-L29 "Source code on GitHub")
4331
4432 Runs the shutdown routine for the actor
4533
4634 ## startup
4735
48-[actor.js:97-99](https://github.com/dfinity/js-primea/blob/3d3fc0d82dd65f14b8533dcd2fb881c9fbbb1bd3/actor.js#L97-L99 "Source code on GitHub")
36+[actor.js:34-36](https://github.com/dfinity/js-primea/blob/21960d62467278cd5659e2eb5f80cc6ddd87e663/actor.js#L34-L36 "Source code on GitHub")
4937
5038 Runs the startup routine for the actor
5139
5240 ## runMessage
5341
54-[actor.js:107-114](https://github.com/dfinity/js-primea/blob/3d3fc0d82dd65f14b8533dcd2fb881c9fbbb1bd3/actor.js#L107-L114 "Source code on GitHub")
42+[actor.js:44-56](https://github.com/dfinity/js-primea/blob/21960d62467278cd5659e2eb5f80cc6ddd87e663/actor.js#L44-L56 "Source code on GitHub")
5543
5644 run the Actor with a given message
5745
5846 **Parameters**
@@ -63,9 +51,9 @@
6351 Returns **[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)**
6452
6553 ## incrementTicks
6654
67-[actor.js:120-123](https://github.com/dfinity/js-primea/blob/3d3fc0d82dd65f14b8533dcd2fb881c9fbbb1bd3/actor.js#L120-L123 "Source code on GitHub")
55+[actor.js:62-64](https://github.com/dfinity/js-primea/blob/21960d62467278cd5659e2eb5f80cc6ddd87e663/actor.js#L62-L64 "Source code on GitHub")
6856
6957 updates the number of ticks that the actor has run
7058
7159 **Parameters**
@@ -73,9 +61,9 @@
7361 - `count` **[Number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** the number of ticks to add
7462
7563 ## createActor
7664
77-[actor.js:130-133](https://github.com/dfinity/js-primea/blob/3d3fc0d82dd65f14b8533dcd2fb881c9fbbb1bd3/actor.js#L130-L133 "Source code on GitHub")
65+[actor.js:71-74](https://github.com/dfinity/js-primea/blob/21960d62467278cd5659e2eb5f80cc6ddd87e663/actor.js#L71-L74 "Source code on GitHub")
7866
7967 creates an actor
8068
8169 **Parameters**
@@ -85,9 +73,9 @@
8573 - `message` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** an intial [message](https://github.com/primea/js-primea-message) to send newly created actor
8674
8775 ## send
8876
89-[actor.js:150-155](https://github.com/dfinity/js-primea/blob/3d3fc0d82dd65f14b8533dcd2fb881c9fbbb1bd3/actor.js#L150-L155 "Source code on GitHub")
77+[actor.js:91-96](https://github.com/dfinity/js-primea/blob/21960d62467278cd5659e2eb5f80cc6ddd87e663/actor.js#L91-L96 "Source code on GitHub")
9078
9179 sends a message to a given port
9280
9381 **Parameters**
docs/hypervisor.mdView
@@ -3,16 +3,15 @@
33 ### Table of Contents
44
55 - [constructor](#constructor)
66 - [send](#send)
7-- [getActor](#getactor)
87 - [createActor](#createactor)
98 - [createStateRoot](#createstateroot)
109 - [registerContainer](#registercontainer)
1110
1211 ## constructor
1312
14-[index.js:10-15](https://github.com/dfinity/js-primea/blob/3d3fc0d82dd65f14b8533dcd2fb881c9fbbb1bd3/index.js#L10-L15 "Source code on GitHub")
13+[index.js:12-17](https://github.com/dfinity/js-primea/blob/21960d62467278cd5659e2eb5f80cc6ddd87e663/index.js#L12-L17 "Source code on GitHub")
1514
1615 The Hypervisor manages the container instances by instantiating them and
1716 destorying them when possible. It also facilitates localating Containers
1817
@@ -22,34 +21,23 @@
2221 - `nonce` (optional, default `0`)
2322
2423 ## send
2524
26-[index.js:23-27](https://github.com/dfinity/js-primea/blob/3d3fc0d82dd65f14b8533dcd2fb881c9fbbb1bd3/index.js#L23-L27 "Source code on GitHub")
25+[index.js:25-30](https://github.com/dfinity/js-primea/blob/21960d62467278cd5659e2eb5f80cc6ddd87e663/index.js#L25-L30 "Source code on GitHub")
2726
2827 sends a message
2928
3029 **Parameters**
3130
31+- `messages`
32+- `cap` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** the capabilitly used to send the message
3233 - `message` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** the [message](https://github.com/primea/js-primea-message) to send
33-- `cap` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** the capabilitly used to send the message
3434
3535 Returns **[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)** a promise that resolves once the receiving container is loaded
3636
37-## getActor
38-
39-[index.js:55-63](https://github.com/dfinity/js-primea/blob/3d3fc0d82dd65f14b8533dcd2fb881c9fbbb1bd3/index.js#L55-L63 "Source code on GitHub")
40-
41-gets an existsing actor
42-
43-**Parameters**
44-
45-- `id` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** the actor's ID
46-
47-Returns **[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)**
48-
4937 ## createActor
5038
51-[index.js:71-85](https://github.com/dfinity/js-primea/blob/3d3fc0d82dd65f14b8533dcd2fb881c9fbbb1bd3/index.js#L71-L85 "Source code on GitHub")
39+[index.js:65-83](https://github.com/dfinity/js-primea/blob/21960d62467278cd5659e2eb5f80cc6ddd87e663/index.js#L65-L83 "Source code on GitHub")
5240
5341 creates an instance of an Actor
5442
5543 **Parameters**
@@ -60,22 +48,22 @@
6048 - `message` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** an intial [message](https://github.com/primea/js-primea-message) to send newly created actor
6149
6250 ## createStateRoot
6351
64-[index.js:98-101](https://github.com/dfinity/js-primea/blob/3d3fc0d82dd65f14b8533dcd2fb881c9fbbb1bd3/index.js#L98-L101 "Source code on GitHub")
52+[index.js:98-104](https://github.com/dfinity/js-primea/blob/21960d62467278cd5659e2eb5f80cc6ddd87e663/index.js#L98-L104 "Source code on GitHub")
6553
6654 creates a state root starting from a given container and a given number of
6755 ticks
6856
6957 **Parameters**
7058
71-- `ticks` **[Number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** the number of ticks at which to create the state root (optional, default `Infinity`)
59+- `ticks` **[Number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** the number of ticks at which to create the state root
7260
7361 Returns **[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)**
7462
7563 ## registerContainer
7664
77-[index.js:109-111](https://github.com/dfinity/js-primea/blob/3d3fc0d82dd65f14b8533dcd2fb881c9fbbb1bd3/index.js#L109-L111 "Source code on GitHub")
65+[index.js:112-114](https://github.com/dfinity/js-primea/blob/21960d62467278cd5659e2eb5f80cc6ddd87e663/index.js#L112-L114 "Source code on GitHub")
7866
7967 regirsters a container with the hypervisor
8068
8169 **Parameters**
docs/index.mdView
@@ -1,7 +1,6 @@
11 # API
22 - [Hypervisor](./hypervisor.md)
3-- [Kernel](./kernel.md)
4-- [PortManager](./portManager.md)
3+- [Actor](./actor.md)
54
6-## internal API's
5+## Internal APIs
76 - [Scheduler](./scheduler.md)
docs/scheduler.mdView
@@ -2,87 +2,15 @@
22
33 ### Table of Contents
44
55 - [constructor](#constructor)
6-- [lock](#lock)
7-- [update](#update)
8-- [getInstance](#getinstance)
9-- [done](#done)
10-- [wait](#wait)
11-- [leastNumberOfTicks](#leastnumberofticks)
126
137 ## constructor
148
15-[scheduler.js:13-17](https://github.com/dfinity/js-primea/blob/3d3fc0d82dd65f14b8533dcd2fb881c9fbbb1bd3/scheduler.js#L13-L17 "Source code on GitHub")
9+[scheduler.js:19-26](https://github.com/dfinity/js-primea/blob/21960d62467278cd5659e2eb5f80cc6ddd87e663/scheduler.js#L19-L26 "Source code on GitHub")
1610
1711 The Scheduler manages the actor instances and tracks how many "ticks" they
1812 have ran.
1913
20-## lock
21-
22-[scheduler.js:24-34](https://github.com/dfinity/js-primea/blob/3d3fc0d82dd65f14b8533dcd2fb881c9fbbb1bd3/scheduler.js#L24-L34 "Source code on GitHub")
23-
24-locks the scheduler from clearing waits untill the lock is resolved
25-
2614 **Parameters**
2715
28-- `id` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)**
29-
30-Returns **[function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function)** the resolve function to call once it to unlock
31-
32-## update
33-
34-[scheduler.js:40-44](https://github.com/dfinity/js-primea/blob/3d3fc0d82dd65f14b8533dcd2fb881c9fbbb1bd3/scheduler.js#L40-L44 "Source code on GitHub")
35-
36-updates an instance with a new tick count
37-
38-**Parameters**
39-
40-- `instance` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** an actor instance
41-
42-## getInstance
43-
44-[scheduler.js:56-59](https://github.com/dfinity/js-primea/blob/3d3fc0d82dd65f14b8533dcd2fb881c9fbbb1bd3/scheduler.js#L56-L59 "Source code on GitHub")
45-
46-returns an Actor instance
47-
48-**Parameters**
49-
50-- `id` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)**
51-
52-Returns **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)**
53-
54-## done
55-
56-[scheduler.js:65-70](https://github.com/dfinity/js-primea/blob/3d3fc0d82dd65f14b8533dcd2fb881c9fbbb1bd3/scheduler.js#L65-L70 "Source code on GitHub")
57-
58-deletes an instance from the scheduler
59-
60-**Parameters**
61-
62-- `id` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** the containers id
63-
64-## wait
65-
66-[scheduler.js:79-93](https://github.com/dfinity/js-primea/blob/3d3fc0d82dd65f14b8533dcd2fb881c9fbbb1bd3/scheduler.js#L79-L93 "Source code on GitHub")
67-
68-returns a promise that resolves once all containers have reached the given
69-number of ticks
70-
71-**Parameters**
72-
73-- `ticks` **interger** the number of ticks to wait
74-- `id` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** optional id of the container that is waiting
75-
76-Returns **[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)**
77-
78-## leastNumberOfTicks
79-
80-[scheduler.js:99-109](https://github.com/dfinity/js-primea/blob/3d3fc0d82dd65f14b8533dcd2fb881c9fbbb1bd3/scheduler.js#L99-L109 "Source code on GitHub")
81-
82-returns the oldest container's ticks
83-
84-**Parameters**
85-
86-- `exclude`
87-
88-Returns **integer**
16+- `hypervisor`
package.jsonView
@@ -5,13 +5,14 @@
55 "scripts": {
66 "coveralls": "npm run coverage && nyc report --reporter=text-lcov | coveralls",
77 "coverage": "nyc npm test",
88 "lint": "standard",
9- "build:docs": "npm run build:docs:hypervisor && npm run build:docs:actor && npm run build:docs:scheduler && npm run build:docs:capsStore && npm run build:docs:inbox",
9+ "build:docs": "npm run build:docs:hypervisor && npm run build:docs:actor && npm run build:docs:scheduler",
1010 "build:docs:hypervisor": "documentation build ./index.js --github --shallow --sort-order source -f md > ./docs/hypervisor.md",
1111 "build:docs:actor": "documentation build ./actor.js --github --shallow --sort-order source -f md > ./docs/actor.md",
12- "build:docs:capsStore": "documentation build ./capsStore.js --github --shallow --sort-order source -f md > ./docs/capsStore.md",
13- "test": "node ./tests/index.js"
12+ "build:docs:scheduler": "documentation build ./scheduler.js --github --shallow --sort-order source -f md > ./docs/scheduler.md",
13+ "test": "node ./tests/index.js",
14+ "test:wasm": "node ./tests/wasmContainer.js"
1415 },
1516 "repository": {
1617 "type": "git",
1718 "url": "git+https://github.com/primea/js-primea-hypervisor.git"
tests/wasmContainer.jsView
@@ -1,14 +1,17 @@
11 const tape = require('tape')
22 const fs = require('fs')
3+const path = require('path')
34 const Message = require('../message.js')
45 const Hypervisor = require('../')
56 const WasmContainer = require('../wasmContainer.js')
67
78 const level = require('level-browserify')
89 const RadixTree = require('dfinity-radix-tree')
910 const db = level('./testdb')
1011
12+const WASM_PATH = path.join(__dirname, 'wasm')
13+
1114 let tester
1215
1316 class TestWasmContainer extends WasmContainer {
1417 constructor (actor) {
@@ -41,9 +44,9 @@
4144 const tree = new RadixTree({
4245 db
4346 })
4447
45- const wasm = fs.readFileSync('./wasm/reciever.wasm')
48+ const wasm = fs.readFileSync(WASM_PATH + '/reciever.wasm')
4649
4750 const hypervisor = new Hypervisor(tree)
4851 hypervisor.registerContainer(TestWasmContainer)
4952
@@ -68,10 +71,10 @@
6871 }
6972
7073 const tree = new RadixTree({db})
7174
72- const recieverWasm = fs.readFileSync('./wasm/reciever.wasm')
73- const callerWasm = fs.readFileSync('./wasm/caller.wasm')
75+ const recieverWasm = fs.readFileSync(WASM_PATH + '/reciever.wasm')
76+ const callerWasm = fs.readFileSync(WASM_PATH + '/caller.wasm')
7477
7578 const hypervisor = new Hypervisor(tree)
7679 hypervisor.registerContainer(TestWasmContainer)
7780
@@ -101,10 +104,10 @@
101104 const tree = new RadixTree({
102105 db
103106 })
104107
105- const recieverWasm = fs.readFileSync('./wasm/funcRef_reciever.wasm')
106- const callerWasm = fs.readFileSync('./wasm/funcRef_caller.wasm')
108+ const recieverWasm = fs.readFileSync(WASM_PATH + '/funcRef_reciever.wasm')
109+ const callerWasm = fs.readFileSync(WASM_PATH + '/funcRef_caller.wasm')
107110
108111 const hypervisor = new Hypervisor(tree)
109112 hypervisor.registerContainer(TestWasmContainer)
110113
@@ -136,10 +139,10 @@
136139 const tree = new RadixTree({
137140 db
138141 })
139142
140- const recieverWasm = fs.readFileSync('./wasm/funcRef_reciever.wasm')
141- const callerWasm = fs.readFileSync('./wasm/private_caller.wasm')
143+ const recieverWasm = fs.readFileSync(WASM_PATH + '/funcRef_reciever.wasm')
144+ const callerWasm = fs.readFileSync(WASM_PATH + '/private_caller.wasm')
142145
143146 const hypervisor = new Hypervisor(tree)
144147 hypervisor.registerContainer(TestWasmContainer)
145148
@@ -167,9 +170,9 @@
167170 const tree = new RadixTree({
168171 db
169172 })
170173
171- const wasm = fs.readFileSync('./wasm/memory.wasm')
174+ const wasm = fs.readFileSync(WASM_PATH + '/memory.wasm')
172175
173176 const hypervisor = new Hypervisor(tree)
174177 hypervisor.registerContainer(TestWasmContainer)
175178
@@ -191,9 +194,9 @@
191194 const tree = new RadixTree({
192195 db
193196 })
194197
195- const wasm = fs.readFileSync('./wasm/table.wasm')
198+ const wasm = fs.readFileSync(WASM_PATH + '/table.wasm')
196199 const hypervisor = new Hypervisor(tree)
197200 hypervisor.registerContainer(TestWasmContainer)
198201
199202 const {module} = await hypervisor.createActor(TestWasmContainer.typeId, wasm)
@@ -215,9 +218,9 @@
215218 const tree = new RadixTree({
216219 db
217220 })
218221
219- const wasm = fs.readFileSync('./wasm/globals.wasm')
222+ const wasm = fs.readFileSync(WASM_PATH + '/globals.wasm')
220223
221224 const hypervisor = new Hypervisor(tree)
222225 hypervisor.registerContainer(TestWasmContainer)
223226
@@ -255,9 +258,9 @@
255258 const tree = new RadixTree({
256259 db
257260 })
258261
259- const wasm = fs.readFileSync('./hi.wasm')
262+ const wasm = fs.readFileSync(WASM_PATH + '.wasm')
260263 const hypervisor = new Hypervisor(tree)
261264 hypervisor.registerContainer(TestWasmContainer)
262265
263266 const {module} = await hypervisor.createActor(TestWasmContainer.typeId, wasm)
wasmContainer.jsView
@@ -191,9 +191,9 @@
191191 },
192192 internalize: (elemRef, srcOffset, sinkOffset, length) => {
193193 let table = this.refs.get(elemRef, 'elem')
194194 const buf = table.slice(srcOffset, srcOffset + length).map(obj => this.refs.add(obj))
195- const mem = new Uint32Array(this.instance.exports.memory.buffer, sinkOffset, length)
195+ const mem = this.getMemory(sinkOffset, length)
196196 mem.set(buf)
197197 },
198198 length (elemRef) {
199199 let elem = this.refs.get(elemRef, 'elem')
@@ -260,9 +260,9 @@
260260 numOfGlobals = this.json.globals.length
261261 if (numOfGlobals) {
262262 this.actor.storage = []
263263 this.instance.exports.getter_globals()
264- const mem = new Uint32Array(this.instance.exports.memory.buffer, 0, numOfGlobals)
264+ const mem = this.getMemory(0, numOfGlobals)
265265 while (numOfGlobals--) {
266266 const ref = mem[numOfGlobals]
267267 this.actor.storage.push(this.refs.get(ref, this.json.globals[numOfGlobals].type))
268268 }

Built with git-ssb-web