Commit 6c97c88b95f43dea4cf265dbbc93e6e3cc5cba97
remove Kernal referance from the envorment
wanderer committed on 7/22/2016, 5:15:03 PMParent: c65080ed891e4874c7962a92eb7e6e331964adb3
Files changed
index.js | changed |
interface.js | changed |
tests/interfaceRunner.js | changed |
index.js | ||
---|---|---|
@@ -1,6 +1,7 @@ | ||
1 | 1 | /** |
2 | 2 | * This implements the Ethereum Kernel |
3 | + * Kernels must implement two methods `codeHandler` and `callHandler` (and `linkHandler` for sharding) | |
3 | 4 | * The Kernel Contract handles the following |
4 | 5 | * - Interprocess communications |
5 | 6 | * - Intializing the VM and exposes ROM to it (codeHandler) |
6 | 7 | * - Expose namespace which VM instance exists and Intializes the Environment (callHandler) |
@@ -9,10 +10,9 @@ | ||
9 | 10 | * |
10 | 11 | * All State should be stored in the Environment. |
11 | 12 | * |
12 | 13 | */ |
13 | -// const Environment = require('./environment.js') | |
14 | -// | |
14 | + | |
15 | 15 | // The Kernel Exposes this Interface to VM instances it makes |
16 | 16 | const Interface = require('./interface.js') |
17 | 17 | // The Kernel Stores all of its state in the Environment. The Interface is used |
18 | 18 | // to by the VM to retrive infromation from the Environment. |
@@ -41,9 +41,9 @@ | ||
41 | 41 | // Detects if code is EVM or WASM |
42 | 42 | // Detects if the code injection is needed |
43 | 43 | // Detects if transcompilation is needed |
44 | 44 | static callHandler (path, data) { |
45 | - // creats a new Kernal | |
45 | + // creats a new Kernel | |
46 | 46 | // const environment = new Environment(data) |
47 | 47 | // environment.parent = this |
48 | 48 | // const kernel = new Kernel(this, environment) |
49 | 49 | // kernel.codeHandler(code) |
interface.js | ||
---|---|---|
@@ -1,17 +1,15 @@ | ||
1 | 1 | /** |
2 | 2 | * This is the Ethereum interface that is exposed to the WASM instance which |
3 | 3 | * enables to interact with the Ethereum Environment |
4 | 4 | */ |
5 | -const Environment = require('./environment.js') | |
6 | 5 | const constants = require('./constants.js') |
7 | 6 | // const Graph = require('generic-digraph') |
8 | 7 | |
9 | 8 | // function.bind is not working corretly whith Wasm imports. So instead create |
10 | 9 | // a global for now. TODO REMOVE |
11 | 10 | let ENV |
12 | 11 | let MOD |
13 | -let self | |
14 | 12 | // The interface exposed to the WebAessembly Core |
15 | 13 | module.exports = class Interface { |
16 | 14 | |
17 | 15 | debugPrint (a) { |
@@ -21,11 +19,10 @@ | ||
21 | 19 | memPrint () { |
22 | 20 | console.log((new Uint8Array(MOD.exports.memory)).toString()) |
23 | 21 | } |
24 | 22 | |
25 | - constructor (environment, kernal) { | |
23 | + constructor (environment) { | |
26 | 24 | ENV = this.environment = environment |
27 | - self = this | |
28 | 25 | } |
29 | 26 | |
30 | 27 | setModule (mod) { |
31 | 28 | this.module = MOD = mod |
@@ -68,9 +65,10 @@ | ||
68 | 65 | */ |
69 | 66 | balance (addressOffset, offset) { |
70 | 67 | const address = new Uint8Array(MOD.exports.memory, addressOffset, constants.ADD_SIZE_BYTES) |
71 | 68 | const memory = new Uint8Array(MOD.exports.memory, offset, constants.MAX_BAL_BYTES) |
72 | - const balance = ENV.getBalance(address) | |
69 | + // call the parent contract and ask for the balance of one of its child contracts | |
70 | + const balance = ENV.parent.environment.getBalance(address) | |
73 | 71 | memory.set(balance) |
74 | 72 | } |
75 | 73 | |
76 | 74 | /** |
tests/interfaceRunner.js | ||
---|---|---|
@@ -17,18 +17,19 @@ | ||
17 | 17 | // Compile Command |
18 | 18 | cp.execSync(`${__dirname}/../../evm-wasm-transcompiler/deps/sexpr-wasm-prototype/out/sexpr-wasm ${dir}/${testName}.wast -o ${dir}/${testName}.wasm`) |
19 | 19 | const buffer = fs.readFileSync(`${dir}/${testName}.wasm`) |
20 | 20 | const envData = fs.readFileSync(`${dir}/${testName}.json`) |
21 | + const ethereum = new Kernel(new Environment(envData)) | |
21 | 22 | |
22 | - const environment = new Environment(envData) | |
23 | - const kernel = new Kernel() | |
24 | - const ethInterface = new Interface(environment, kernel) | |
23 | + // manually `callHander` | |
24 | + const environment = new Environment(envData) | |
25 | + environment.parent = ethereum | |
26 | + const testContract = new Kernel(environment) | |
27 | + const ethInterface = new Interface(environment, testContract) | |
25 | 28 | |
26 | 29 | try { |
27 | 30 | const mod = Wasm.instantiateModule(buffer, {'ethereum': ethInterface}) |
28 | 31 | ethInterface.setModule(mod) |
29 | - // ethInterface.address(0) | |
30 | - // console.log(ethInterface.environment); | |
31 | 32 | mod.exports.test() |
32 | 33 | } catch (e) { |
33 | 34 | t.fail() |
34 | 35 | console.error('FAIL') |
Built with git-ssb-web