git ssb

0+

wanderer🌟 / js-primea-hypervisor



Commit be42af81974876ce832fa149178075c8fca67321

Merge branch 'shim' into testing

wanderer committed on 9/13/2016, 6:42:03 PM
Parent: faee2f5886f2e3201e3ae568539673700c84ecb3
Parent: 3b07461593e97b8ecb99d055a38948670485d41e

Files changed

index.jschanged
interface.jschanged
wasm/interface.wasmchanged
wasm/interface.wastchanged
index.jsView
@@ -58,8 +58,10 @@
5858 'env': ethInterface.exportTable
5959 }
6060 // add shims
6161 imports.ethereum.useGas = ethInterface.shims.exports.useGas
62+ imports.ethereum.getGasLeft = ethInterface.shims.exports.getGasLeft
63+
6264 const instance = WebAssembly.Instance(module, imports)
6365
6466 ethInterface.setModule(instance)
6567 debugInterface.setModule(instance)
interface.jsView
@@ -18,17 +18,18 @@
1818 const shimBin = fs.readFileSync(path.join(__dirname, '/wasm/interface.wasm'))
1919 const shimMod = WebAssembly.Module(shimBin)
2020 this.shims = WebAssembly.Instance(shimMod, {
2121 'interface': {
22- 'useGas': this._useGas.bind(this)
22+ 'useGas': this._useGas.bind(this),
23+ 'getGasLeftHigh': this._getGasLeftHigh.bind(this),
24+ 'getGasLeftLow': this._getGasLeftLow.bind(this)
2325 }
2426 })
2527 }
2628
2729 get exportTable () {
2830 let exportMethods = [
2931 // include all the public methods according to the Ethereum Environment Interface (EEI) r1
30- 'getGasLeft',
3132 'getAddress',
3233 'getBalance',
3334 'getTxOrigin',
3435 'getCaller',
@@ -91,10 +92,17 @@
9192 /**
9293 * Returns the current amount of gas
9394 * @return {integer}
9495 */
95- getGasLeft () {
96- this.takeGas(2)
96+ _getGasLeftHigh () {
97+ return Math.floor(this.environment.gasLeft / 4294967296)
98+ }
99+
100+ /**
101+ * Returns the current amount of gas
102+ * @return {integer}
103+ */
104+ _getGasLeftLow () {
97105 return this.environment.gasLeft
98106 }
99107
100108 /**
wasm/interface.wasmView
@@ -1,2 +1,2 @@
1-asm type
2-@@import interfaceuseGasfunctionexport useGascode  f��
1+asm type@@@@importF interfaceuseGas interfacegetGasLeftHigh interface getGasLeftLowfunctionexportuseGas
2+getGasLeftcode&  f��� e�[ 
wasm/interface.wastView
@@ -1,11 +1,25 @@
11 (module
2- (import $useGas "interface" "useGas" (param i32 i32))
2+ ;; useGas
3+ (import $useGas "interface" "useGas" (param i32 i32))
34 (func $useGasShim
45 (param $amount i64)
56 (call_import $useGas
67 (i32.wrap/i64
78 (i64.shr_u (get_local $amount) (i64.const 32)))
89 (i32.wrap/i64 (get_local $amount)))
910 )
1011 (export "useGas" $useGasShim)
12+
13+ ;; getGasLeft
14+ (import $getGasLeftHigh "interface" "getGasLeftHigh" (result i32))
15+ (import $getGasLeftLow "interface" "getGasLeftLow" (result i32))
16+ (func $getGasLeft
17+ (result i64)
18+ (call_import $useGas (i32.const 0) (i32.const 2))
19+ (return
20+ (i64.add
21+ (i64.shl (i64.extend_u/i32 (call_import $getGasLeftHigh)) (i64.const 32))
22+ (i64.extend_u/i32 (call_import $getGasLeftLow))))
23+ )
24+ (export "getGasLeft" $getGasLeft)
1125 )

Built with git-ssb-web