git ssb

0+

wanderer🌟 / js-primea-hypervisor



Commit 74db0581899799b168cd273b45f5e767bd0982a1

Merge pull request #20 from ewasm/primitives

Use primitive types in environment
wanderer 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.jschanged
environment.jschanged
interface.jschanged
address.jsView
@@ -22,8 +22,12 @@
2222 throw new Error('Invalid address length')
2323 }
2424 }
2525
26+ toBuffer () {
27+ return this._value
28+ }
29+
2630 toString () {
2731 return '0x' + this._value.toString('hex')
2832 }
2933
environment.jsView
@@ -1,5 +1,6 @@
11 const constants = require('./constants.js')
2+const U256 = require('./u256.js')
23
34 module.exports = class Environment {
45 constructor (data) {
56 const defaults = {
@@ -10,19 +11,19 @@
1011 // call infromation
1112 address: new Uint8Array(constants.ADDRESS_SIZE_BYTES),
1213 origin: new Uint8Array(constants.ADDRESS_SIZE_BYTES),
1314 coinbase: new Uint8Array(constants.ADDRESS_SIZE_BYTES),
14- difficulty: new Uint8Array(20),
15+ difficulty: 0,
1516 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(),
1819 // the ROM
19- code: new ArrayBuffer(), // the current running code
20+ code: new Uint8Array(), // the current running code
2021 // output calls
2122 logs: [],
22- selfDestructAddress: new ArrayBuffer(),
23+ selfDestructAddress: new Uint8Array(constants.ADDRESS_SIZE_BYTES),
2324 // more output calls
24- returnValue: new ArrayBuffer()
25+ returnValue: new Uint8Array()
2526 }
2627
2728 const self = this
2829 this.state = new Map()
interface.jsView
@@ -126,18 +126,18 @@
126126 * this execution and loads it into memory at the given location.
127127 * @param {integer} offset
128128 */
129129 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())
131131 }
132132
133133 /**
134134 * Get size of input data in current environment. This pertains to the input
135135 * data passed with the message call instruction or transaction.
136136 * @return {integer}
137137 */
138138 callDataSize () {
139- return this.environment.callData.byteLength
139+ return this.environment.callData.length
140140 }
141141
142142 /**
143143 * Copys the input data in current environment to memory. This pertains to
@@ -155,9 +155,9 @@
155155 * Gets the size of code running in current environment.
156156 * @return {interger}
157157 */
158158 codeSize () {
159- return this.environment.code.byteLength
159+ return this.environment.code.length
160160 }
161161
162162 /**
163163 * Copys the code running in current environment to memory.
@@ -177,9 +177,9 @@
177177 */
178178 extCodeSize (addressOffset) {
179179 const address = this.getMemory(addressOffset, constants.ADDRESS_SIZE_BYTES)
180180 const code = this.environment.getCode(address)
181- return code.byteLength
181+ return code.length
182182 }
183183
184184 /**
185185 * Copys the code of an account to memory.

Built with git-ssb-web