Commit 0c67dbd7d1ebd5df858985a411d801af32110ab8
Merge pull request #10 from ewasm/constants
Rename constants for readabilitywanderer authored on 8/3/2016, 11:46:05 PM
GitHub committed on 8/3/2016, 11:46:05 PM
Parent: b1c93edeea0cf16136ca43f608f4e121f45f84c3
Parent: e5d3fb4071df5c5f17107e5b9632880c93790361
Files changed
constants.js | changed |
environment.js | changed |
interface.js | changed |
constants.js | ||
---|---|---|
@@ -1,4 +1,4 @@ | ||
1 | 1 | module.exports = { |
2 | - MAX_BAL_BYTES: 16, // Max balance size in bytes | |
3 | - ADD_SIZE_BYTES: 20 // Address size in bytes | |
2 | + BALANCE_SIZE_BYTES: 16, // Max balance size in bytes | |
3 | + ADDRESS_SIZE_BYTES: 20 // Address size in bytes | |
4 | 4 | } |
environment.js | ||
---|---|---|
@@ -8,14 +8,14 @@ | ||
8 | 8 | gasPrice: 0, |
9 | 9 | gasLimit: 0, // The gas limit for the block |
10 | 10 | gasRefund: 0, |
11 | 11 | // call infromation |
12 | - address: new Uint8Array(constants.ADD_SIZE_BYTES), | |
13 | - origin: new Uint8Array(constants.ADD_SIZE_BYTES), | |
14 | - coinbase: new Uint8Array(constants.ADD_SIZE_BYTES), | |
12 | + address: new Uint8Array(constants.ADDRESS_SIZE_BYTES), | |
13 | + origin: new Uint8Array(constants.ADDRESS_SIZE_BYTES), | |
14 | + coinbase: new Uint8Array(constants.ADDRESS_SIZE_BYTES), | |
15 | 15 | difficulty: new Uint8Array(20), |
16 | - caller: new Uint8Array(constants.ADD_SIZE_BYTES), | |
17 | - callValue: new Uint8Array(constants.MAX_BAL_BYTES), | |
16 | + caller: new Uint8Array(constants.ADDRESS_SIZE_BYTES), | |
17 | + callValue: new Uint8Array(constants.BALANCE_SIZE_BYTES), | |
18 | 18 | callData: new ArrayBuffer(), |
19 | 19 | // the ROM |
20 | 20 | code: new ArrayBuffer(), // the current running code |
21 | 21 | // output calls |
interface.js | ||
---|---|---|
@@ -90,9 +90,9 @@ | ||
90 | 90 | * the given offset. |
91 | 91 | * @param {integer} offset |
92 | 92 | */ |
93 | 93 | address (offset) { |
94 | - this.setMemory(offset, constants.ADD_SIZE_BYTES, this.environment.address) | |
94 | + this.setMemory(offset, constants.ADDRESS_SIZE_BYTES, this.environment.address) | |
95 | 95 | } |
96 | 96 | |
97 | 97 | /** |
98 | 98 | * Gets balance of the given account and loads it into memory at the given |
@@ -100,12 +100,12 @@ | ||
100 | 100 | * @param {integer} addressOffset the memory offset to laod the address |
101 | 101 | * @param {integer} resultOffset |
102 | 102 | */ |
103 | 103 | balance (addressOffset, offset) { |
104 | - const address = this.getMemory(addressOffset, constants.ADD_SIZE_BYTES) | |
104 | + const address = this.getMemory(addressOffset, constants.ADDRESS_SIZE_BYTES) | |
105 | 105 | // call the parent contract and ask for the balance of one of its child contracts |
106 | 106 | const balance = this.environment.parent.environment.getBalance(address) |
107 | - this.setMemory(offset, constants.MAX_BAL_BYTES, balance) | |
107 | + this.setMemory(offset, constants.BALANCE_SIZE_BYTES, balance) | |
108 | 108 | } |
109 | 109 | |
110 | 110 | /** |
111 | 111 | * Gets the execution's origination address and loads it into memory at the |
@@ -113,27 +113,27 @@ | ||
113 | 113 | * account with non-empty associated code. |
114 | 114 | * @param {integer} offset |
115 | 115 | */ |
116 | 116 | origin (offset) { |
117 | - this.setMemory(offset, constants.ADD_SIZE_BYTES, this.environment.origin) | |
117 | + this.setMemory(offset, constants.ADDRESS_SIZE_BYTES, this.environment.origin) | |
118 | 118 | } |
119 | 119 | |
120 | 120 | /** |
121 | 121 | * Gets caller address and loads it into memory at the given offset. This is |
122 | 122 | * the address of the account that is directly responsible for this execution. |
123 | 123 | * @param {integer} offset |
124 | 124 | */ |
125 | 125 | caller (offset) { |
126 | - this.setMemory(offset, constants.ADD_SIZE_BYTES, this.environment.caller) | |
126 | + this.setMemory(offset, constants.ADDRESS_SIZE_BYTES, this.environment.caller) | |
127 | 127 | } |
128 | 128 | |
129 | 129 | /** |
130 | 130 | * Gets the deposited value by the instruction/transaction responsible for |
131 | 131 | * this execution and loads it into memory at the given location. |
132 | 132 | * @param {integer} offset |
133 | 133 | */ |
134 | 134 | callValue (offset) { |
135 | - this.setMemory(offset, constants.MAX_BAL_BYTES, this.environment.callValue) | |
135 | + this.setMemory(offset, constants.BALANCE_SIZE_BYTES, this.environment.callValue) | |
136 | 136 | } |
137 | 137 | |
138 | 138 | /** |
139 | 139 | * Get size of input data in current environment. This pertains to the input |
@@ -180,9 +180,9 @@ | ||
180 | 180 | * @param {integer} addressOffset the offset in memory to load the address from |
181 | 181 | * @return {integer} |
182 | 182 | */ |
183 | 183 | extCodeSize (addressOffset) { |
184 | - const address = this.getMemory(addressOffset, constants.ADD_SIZE_BYTES) | |
184 | + const address = this.getMemory(addressOffset, constants.ADDRESS_SIZE_BYTES) | |
185 | 185 | const code = this.environment.getCode(address) |
186 | 186 | return code.byteLength |
187 | 187 | } |
188 | 188 | |
@@ -193,9 +193,9 @@ | ||
193 | 193 | * @param {integer} codeOffset the code offset |
194 | 194 | * @param {integer} length the length of code to copy |
195 | 195 | */ |
196 | 196 | extCodeCopy (addressOffset, offset, codeOffset, length) { |
197 | - const address = this.getMemory(addressOffset, constants.ADD_SIZE_BYTES) | |
197 | + const address = this.getMemory(addressOffset, constants.ADDRESS_SIZE_BYTES) | |
198 | 198 | let code = this.environment.getCode(address) |
199 | 199 | code = new Uint8Array(code, codeOffset, length) |
200 | 200 | this.setMemory(offset, length, code) |
201 | 201 | } |
@@ -222,9 +222,9 @@ | ||
222 | 222 | * Gets the block’s beneficiary address and loads into memory. |
223 | 223 | * @param offset |
224 | 224 | */ |
225 | 225 | coinbase (offset) { |
226 | - this.setMemory(offset, constants.ADD_SIZE_BYTES, this.environment.coinbase) | |
226 | + this.setMemory(offset, constants.ADDRESS_SIZE_BYTES, this.environment.coinbase) | |
227 | 227 | } |
228 | 228 | |
229 | 229 | /** |
230 | 230 | * Get the block’s timestamp. |
@@ -278,9 +278,9 @@ | ||
278 | 278 | * @param {integer} dataOffset the offset to load the code for the new contract from |
279 | 279 | * @param {integer} length the data length |
280 | 280 | */ |
281 | 281 | create (valueOffset, dataOffset, length) { |
282 | - const value = this.getMemory(valueOffset, constants.MAX_BAL_BYTES) | |
282 | + const value = this.getMemory(valueOffset, constants.BALANCE_SIZE_BYTES) | |
283 | 283 | const data = this.getMemory(dataOffset, length) |
284 | 284 | const result = this.environment.create(value, data) |
285 | 285 | return result |
286 | 286 | } |
@@ -301,10 +301,10 @@ | ||
301 | 301 | if (gas === undefined) { |
302 | 302 | gas = this.gasLeft() |
303 | 303 | } |
304 | 304 | // Load the params from mem |
305 | - const address = this.getMemory(addressOffset, constants.ADD_SIZE_BYTES) | |
306 | - const value = this.getMemory(valueOffset, constants.MAX_BAL_BYTES) | |
305 | + const address = this.getMemory(addressOffset, constants.ADDRESS_SIZE_BYTES) | |
306 | + const value = this.getMemory(valueOffset, constants.BALANCE_SIZE_BYTES) | |
307 | 307 | const data = this.getMemory(dataOffset, dataLength) |
308 | 308 | // Run the call |
309 | 309 | const [result, errorCode] = this.environment.call(gas, address, value, data) |
310 | 310 | this.setMemory(resultOffset, resultLength, result) |
@@ -325,9 +325,9 @@ | ||
325 | 325 | * @return {integer} Returns 1 or 0 depending on if the VM trapped on the message or not |
326 | 326 | */ |
327 | 327 | callDelegate (gas, addressOffset, dataOffset, dataLength, resultOffset, resultLength) { |
328 | 328 | const data = this.getMemory(dataOffset, dataLength) |
329 | - const address = this.getMemory(addressOffset, constants.ADD_SIZE_BYTES) | |
329 | + const address = this.getMemory(addressOffset, constants.ADDRESS_SIZE_BYTES) | |
330 | 330 | const [result, errorCode] = this.environment.callDelegate(gas, address, data) |
331 | 331 | this.setMemory(resultOffset, resultLength, result) |
332 | 332 | |
333 | 333 | return errorCode |
@@ -384,9 +384,9 @@ | ||
384 | 384 | * balance to an address path |
385 | 385 | * @param {integer} offset the offset to load the address from |
386 | 386 | */ |
387 | 387 | suicide (addressOffset) { |
388 | - this.environment.suicideAddress = this.getMemory(addressOffset, constants.ADD_SIZE_BYTES) | |
388 | + this.environment.suicideAddress = this.getMemory(addressOffset, constants.ADDRESS_SIZE_BYTES) | |
389 | 389 | } |
390 | 390 | |
391 | 391 | getMemory (offset, length) { |
392 | 392 | return new Uint8Array(this.module.exports.memory, offset, length) |
Built with git-ssb-web