git ssb

0+

wanderer🌟 / js-primea-hypervisor



Commit 6c97c88b95f43dea4cf265dbbc93e6e3cc5cba97

remove Kernal referance from the envorment

wanderer committed on 7/22/2016, 5:15:03 PM
Parent: c65080ed891e4874c7962a92eb7e6e331964adb3

Files changed

index.jschanged
interface.jschanged
tests/interfaceRunner.jschanged
index.jsView
@@ -1,6 +1,7 @@
11 /**
22 * This implements the Ethereum Kernel
3+ * Kernels must implement two methods `codeHandler` and `callHandler` (and `linkHandler` for sharding)
34 * The Kernel Contract handles the following
45 * - Interprocess communications
56 * - Intializing the VM and exposes ROM to it (codeHandler)
67 * - Expose namespace which VM instance exists and Intializes the Environment (callHandler)
@@ -9,10 +10,9 @@
910 *
1011 * All State should be stored in the Environment.
1112 *
1213 */
13-// const Environment = require('./environment.js')
14-//
14+
1515 // The Kernel Exposes this Interface to VM instances it makes
1616 const Interface = require('./interface.js')
1717 // The Kernel Stores all of its state in the Environment. The Interface is used
1818 // to by the VM to retrive infromation from the Environment.
@@ -41,9 +41,9 @@
4141 // Detects if code is EVM or WASM
4242 // Detects if the code injection is needed
4343 // Detects if transcompilation is needed
4444 static callHandler (path, data) {
45- // creats a new Kernal
45+ // creats a new Kernel
4646 // const environment = new Environment(data)
4747 // environment.parent = this
4848 // const kernel = new Kernel(this, environment)
4949 // kernel.codeHandler(code)
interface.jsView
@@ -1,17 +1,15 @@
11 /**
22 * This is the Ethereum interface that is exposed to the WASM instance which
33 * enables to interact with the Ethereum Environment
44 */
5-const Environment = require('./environment.js')
65 const constants = require('./constants.js')
76 // const Graph = require('generic-digraph')
87
98 // function.bind is not working corretly whith Wasm imports. So instead create
109 // a global for now. TODO REMOVE
1110 let ENV
1211 let MOD
13-let self
1412 // The interface exposed to the WebAessembly Core
1513 module.exports = class Interface {
1614
1715 debugPrint (a) {
@@ -21,11 +19,10 @@
2119 memPrint () {
2220 console.log((new Uint8Array(MOD.exports.memory)).toString())
2321 }
2422
25- constructor (environment, kernal) {
23+ constructor (environment) {
2624 ENV = this.environment = environment
27- self = this
2825 }
2926
3027 setModule (mod) {
3128 this.module = MOD = mod
@@ -68,9 +65,10 @@
6865 */
6966 balance (addressOffset, offset) {
7067 const address = new Uint8Array(MOD.exports.memory, addressOffset, constants.ADD_SIZE_BYTES)
7168 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)
7371 memory.set(balance)
7472 }
7573
7674 /**
tests/interfaceRunner.jsView
@@ -17,18 +17,19 @@
1717 // Compile Command
1818 cp.execSync(`${__dirname}/../../evm-wasm-transcompiler/deps/sexpr-wasm-prototype/out/sexpr-wasm ${dir}/${testName}.wast -o ${dir}/${testName}.wasm`)
1919 const buffer = fs.readFileSync(`${dir}/${testName}.wasm`)
2020 const envData = fs.readFileSync(`${dir}/${testName}.json`)
21+ const ethereum = new Kernel(new Environment(envData))
2122
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)
2528
2629 try {
2730 const mod = Wasm.instantiateModule(buffer, {'ethereum': ethInterface})
2831 ethInterface.setModule(mod)
29- // ethInterface.address(0)
30- // console.log(ethInterface.environment);
3132 mod.exports.test()
3233 } catch (e) {
3334 t.fail()
3435 console.error('FAIL')

Built with git-ssb-web