git ssb

0+

wanderer🌟 / js-primea-hypervisor



Commit 0c67dbd7d1ebd5df858985a411d801af32110ab8

Merge pull request #10 from ewasm/constants

Rename constants for readability
wanderer 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.jschanged
environment.jschanged
interface.jschanged
constants.jsView
@@ -1,4 +1,4 @@
11 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
44 }
environment.jsView
@@ -8,14 +8,14 @@
88 gasPrice: 0,
99 gasLimit: 0, // The gas limit for the block
1010 gasRefund: 0,
1111 // 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),
1515 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),
1818 callData: new ArrayBuffer(),
1919 // the ROM
2020 code: new ArrayBuffer(), // the current running code
2121 // output calls
interface.jsView
@@ -90,9 +90,9 @@
9090 * the given offset.
9191 * @param {integer} offset
9292 */
9393 address (offset) {
94- this.setMemory(offset, constants.ADD_SIZE_BYTES, this.environment.address)
94+ this.setMemory(offset, constants.ADDRESS_SIZE_BYTES, this.environment.address)
9595 }
9696
9797 /**
9898 * Gets balance of the given account and loads it into memory at the given
@@ -100,12 +100,12 @@
100100 * @param {integer} addressOffset the memory offset to laod the address
101101 * @param {integer} resultOffset
102102 */
103103 balance (addressOffset, offset) {
104- const address = this.getMemory(addressOffset, constants.ADD_SIZE_BYTES)
104+ const address = this.getMemory(addressOffset, constants.ADDRESS_SIZE_BYTES)
105105 // call the parent contract and ask for the balance of one of its child contracts
106106 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)
108108 }
109109
110110 /**
111111 * Gets the execution's origination address and loads it into memory at the
@@ -113,27 +113,27 @@
113113 * account with non-empty associated code.
114114 * @param {integer} offset
115115 */
116116 origin (offset) {
117- this.setMemory(offset, constants.ADD_SIZE_BYTES, this.environment.origin)
117+ this.setMemory(offset, constants.ADDRESS_SIZE_BYTES, this.environment.origin)
118118 }
119119
120120 /**
121121 * Gets caller address and loads it into memory at the given offset. This is
122122 * the address of the account that is directly responsible for this execution.
123123 * @param {integer} offset
124124 */
125125 caller (offset) {
126- this.setMemory(offset, constants.ADD_SIZE_BYTES, this.environment.caller)
126+ this.setMemory(offset, constants.ADDRESS_SIZE_BYTES, this.environment.caller)
127127 }
128128
129129 /**
130130 * Gets the deposited value by the instruction/transaction responsible for
131131 * this execution and loads it into memory at the given location.
132132 * @param {integer} offset
133133 */
134134 callValue (offset) {
135- this.setMemory(offset, constants.MAX_BAL_BYTES, this.environment.callValue)
135+ this.setMemory(offset, constants.BALANCE_SIZE_BYTES, this.environment.callValue)
136136 }
137137
138138 /**
139139 * Get size of input data in current environment. This pertains to the input
@@ -180,9 +180,9 @@
180180 * @param {integer} addressOffset the offset in memory to load the address from
181181 * @return {integer}
182182 */
183183 extCodeSize (addressOffset) {
184- const address = this.getMemory(addressOffset, constants.ADD_SIZE_BYTES)
184+ const address = this.getMemory(addressOffset, constants.ADDRESS_SIZE_BYTES)
185185 const code = this.environment.getCode(address)
186186 return code.byteLength
187187 }
188188
@@ -193,9 +193,9 @@
193193 * @param {integer} codeOffset the code offset
194194 * @param {integer} length the length of code to copy
195195 */
196196 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)
198198 let code = this.environment.getCode(address)
199199 code = new Uint8Array(code, codeOffset, length)
200200 this.setMemory(offset, length, code)
201201 }
@@ -222,9 +222,9 @@
222222 * Gets the block’s beneficiary address and loads into memory.
223223 * @param offset
224224 */
225225 coinbase (offset) {
226- this.setMemory(offset, constants.ADD_SIZE_BYTES, this.environment.coinbase)
226+ this.setMemory(offset, constants.ADDRESS_SIZE_BYTES, this.environment.coinbase)
227227 }
228228
229229 /**
230230 * Get the block’s timestamp.
@@ -278,9 +278,9 @@
278278 * @param {integer} dataOffset the offset to load the code for the new contract from
279279 * @param {integer} length the data length
280280 */
281281 create (valueOffset, dataOffset, length) {
282- const value = this.getMemory(valueOffset, constants.MAX_BAL_BYTES)
282+ const value = this.getMemory(valueOffset, constants.BALANCE_SIZE_BYTES)
283283 const data = this.getMemory(dataOffset, length)
284284 const result = this.environment.create(value, data)
285285 return result
286286 }
@@ -301,10 +301,10 @@
301301 if (gas === undefined) {
302302 gas = this.gasLeft()
303303 }
304304 // 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)
307307 const data = this.getMemory(dataOffset, dataLength)
308308 // Run the call
309309 const [result, errorCode] = this.environment.call(gas, address, value, data)
310310 this.setMemory(resultOffset, resultLength, result)
@@ -325,9 +325,9 @@
325325 * @return {integer} Returns 1 or 0 depending on if the VM trapped on the message or not
326326 */
327327 callDelegate (gas, addressOffset, dataOffset, dataLength, resultOffset, resultLength) {
328328 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)
330330 const [result, errorCode] = this.environment.callDelegate(gas, address, data)
331331 this.setMemory(resultOffset, resultLength, result)
332332
333333 return errorCode
@@ -384,9 +384,9 @@
384384 * balance to an address path
385385 * @param {integer} offset the offset to load the address from
386386 */
387387 suicide (addressOffset) {
388- this.environment.suicideAddress = this.getMemory(addressOffset, constants.ADD_SIZE_BYTES)
388+ this.environment.suicideAddress = this.getMemory(addressOffset, constants.ADDRESS_SIZE_BYTES)
389389 }
390390
391391 getMemory (offset, length) {
392392 return new Uint8Array(this.module.exports.memory, offset, length)

Built with git-ssb-web