Commit 277b81fa0326007d061917f6ea1efa15f8ad5392
docs
wanderer committed on 11/5/2016, 11:07:58 AMParent: 4deaaf0620b832ca0e463a1327d1d7d0ee6c8d6e
Files changed
index.js | changed |
index.js | ||
---|---|---|
@@ -1,25 +1,10 @@ | ||
1 | -/** | |
2 | - * This implements the Kernel | |
3 | - * Kernels must implement two methods `codeHandler` and `callHandler` (and `linkHandler` for sharding) | |
4 | - * The Kernel Contract handles the following | |
5 | - * - Interprocess communications | |
6 | - * - Intializing the VM and exposes ROM to it (codeHandler) | |
7 | - * - Expose namespace which VM instance exists and Intializes the Environment (callHandler) | |
8 | - * - Provides some built in contract (runTx, runBlock) | |
9 | - * - Provides resource sharing and limiting via gas | |
10 | - * | |
11 | - * All State should be stored in the Environment. | |
12 | - */ | |
13 | - | |
14 | 1 | const Vertex = require('./deps/kernelVertex') |
15 | 2 | // The Kernel Exposes this Interface to VM instances it makes |
16 | 3 | const Interface = require('./interface.js') |
17 | 4 | const InterfaceAPI = require('./interfaceAPI.js') |
5 | +const Environment = require('./environment.js') | |
18 | 6 | |
19 | -// The Kernel Stores all of its state in the Environment. The Interface is used | |
20 | -// to by the VM to retrive infromation from the Environment. | |
21 | -const Environment = require('./environment.js') | |
22 | 7 | module.exports = class Kernel { |
23 | 8 | constructor (opts = {}) { |
24 | 9 | this.state = opts.state || new Vertex() |
25 | 10 | this.parent = opts.parent |
@@ -29,16 +14,23 @@ | ||
29 | 14 | } |
30 | 15 | this.imports = this.buildImports(opts.interfaces) |
31 | 16 | } |
32 | 17 | |
18 | + /** | |
19 | + * Builds a import map with an array of given interfaces | |
20 | + */ | |
33 | 21 | buildImports (interfaces = [Interface]) { |
34 | 22 | return interfaces.reduce((obj, Interface) => { |
35 | 23 | obj[Interface.name] = new Interface(this.interfaceAPI).exports |
36 | 24 | return obj |
37 | 25 | }, {}) |
38 | 26 | } |
39 | 27 | |
40 | - // run the kernels code with a given enviroment | |
28 | + /** | |
29 | + * run the kernels code with a given enviroment | |
30 | + * The Kernel Stores all of its state in the Environment. The Interface is used | |
31 | + * to by the VM to retrive infromation from the Environment. | |
32 | + */ | |
41 | 33 | async run (environment = new Environment({state: this.state}), imports = this.imports) { |
42 | 34 | await this.interfaceAPI.run(environment, imports) |
43 | 35 | return environment |
44 | 36 | } |
Built with git-ssb-web