Commit 74db0581899799b168cd273b45f5e767bd0982a1
Merge pull request #20 from ewasm/primitives
Use primitive types in environmentwanderer authored on 8/16/2016, 5:29:58 PM
GitHub committed on 8/16/2016, 5:29:58 PM
Parent: 32b7b1fd8462def6fab396fe9167b7cdd31fa3fd
Parent: dcaa6556e01ca33ce1e213b861a322b7eb14a723
Files changed
address.js | changed |
environment.js | changed |
interface.js | changed |
address.js | ||
---|---|---|
@@ -22,8 +22,12 @@ | ||
22 | 22 | throw new Error('Invalid address length') |
23 | 23 | } |
24 | 24 | } |
25 | 25 | |
26 | + toBuffer () { | |
27 | + return this._value | |
28 | + } | |
29 | + | |
26 | 30 | toString () { |
27 | 31 | return '0x' + this._value.toString('hex') |
28 | 32 | } |
29 | 33 |
environment.js | ||
---|---|---|
@@ -1,5 +1,6 @@ | ||
1 | 1 | const constants = require('./constants.js') |
2 | +const U256 = require('./u256.js') | |
2 | 3 | |
3 | 4 | module.exports = class Environment { |
4 | 5 | constructor (data) { |
5 | 6 | const defaults = { |
@@ -10,19 +11,19 @@ | ||
10 | 11 | // call infromation |
11 | 12 | address: new Uint8Array(constants.ADDRESS_SIZE_BYTES), |
12 | 13 | origin: new Uint8Array(constants.ADDRESS_SIZE_BYTES), |
13 | 14 | coinbase: new Uint8Array(constants.ADDRESS_SIZE_BYTES), |
14 | - difficulty: new Uint8Array(20), | |
15 | + difficulty: 0, | |
15 | 16 | caller: new Uint8Array(constants.ADDRESS_SIZE_BYTES), |
16 | - callValue: new Uint8Array(constants.BALANCE_SIZE_BYTES), | |
17 | - callData: new ArrayBuffer(), | |
17 | + callValue: new U256(0), | |
18 | + callData: new Uint8Array(), | |
18 | 19 | // the ROM |
19 | - code: new ArrayBuffer(), // the current running code | |
20 | + code: new Uint8Array(), // the current running code | |
20 | 21 | // output calls |
21 | 22 | logs: [], |
22 | - selfDestructAddress: new ArrayBuffer(), | |
23 | + selfDestructAddress: new Uint8Array(constants.ADDRESS_SIZE_BYTES), | |
23 | 24 | // more output calls |
24 | - returnValue: new ArrayBuffer() | |
25 | + returnValue: new Uint8Array() | |
25 | 26 | } |
26 | 27 | |
27 | 28 | const self = this |
28 | 29 | this.state = new Map() |
interface.js | ||
---|---|---|
@@ -126,18 +126,18 @@ | ||
126 | 126 | * this execution and loads it into memory at the given location. |
127 | 127 | * @param {integer} offset |
128 | 128 | */ |
129 | 129 | callValue (offset) { |
130 | - this.setMemory(offset, constants.BALANCE_SIZE_BYTES, this.environment.callValue) | |
130 | + this.setMemory(offset, constants.BALANCE_SIZE_BYTES, this.environment.callValue.toBuffer()) | |
131 | 131 | } |
132 | 132 | |
133 | 133 | /** |
134 | 134 | * Get size of input data in current environment. This pertains to the input |
135 | 135 | * data passed with the message call instruction or transaction. |
136 | 136 | * @return {integer} |
137 | 137 | */ |
138 | 138 | callDataSize () { |
139 | - return this.environment.callData.byteLength | |
139 | + return this.environment.callData.length | |
140 | 140 | } |
141 | 141 | |
142 | 142 | /** |
143 | 143 | * Copys the input data in current environment to memory. This pertains to |
@@ -155,9 +155,9 @@ | ||
155 | 155 | * Gets the size of code running in current environment. |
156 | 156 | * @return {interger} |
157 | 157 | */ |
158 | 158 | codeSize () { |
159 | - return this.environment.code.byteLength | |
159 | + return this.environment.code.length | |
160 | 160 | } |
161 | 161 | |
162 | 162 | /** |
163 | 163 | * Copys the code running in current environment to memory. |
@@ -177,9 +177,9 @@ | ||
177 | 177 | */ |
178 | 178 | extCodeSize (addressOffset) { |
179 | 179 | const address = this.getMemory(addressOffset, constants.ADDRESS_SIZE_BYTES) |
180 | 180 | const code = this.environment.getCode(address) |
181 | - return code.byteLength | |
181 | + return code.length | |
182 | 182 | } |
183 | 183 | |
184 | 184 | /** |
185 | 185 | * Copys the code of an account to memory. |
Built with git-ssb-web