Skip to content

Commit

Permalink
js: format code
Browse files Browse the repository at this point in the history
  • Loading branch information
cdump committed Dec 13, 2023
1 parent 4f16820 commit 7a267b1
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 19 deletions.
8 changes: 4 additions & 4 deletions js/src/evm/memory.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ export default class Memory {

const res = new Array(32).fill([-1, 0, undefined])
for (let i = offset; i < offset + 32; i++) {
const idx = i - offset;
const idx = i - offset
for (const [off, seq, val] of this._data) {
if (seq > res[idx][0] && i >= off && i < off + val.length) {
res[idx] = [seq, val[i-off], val]
res[idx] = [seq, val[i - off], val]
}
}
}
const ret = new Uint8Array(res.map((v) => v[1]));
const used = new Set(res.map((v) => v[2]));
const ret = new Uint8Array(res.map((v) => v[1]))
const used = new Set(res.map((v) => v[2]))
return [ret, used]
}
}
2 changes: 1 addition & 1 deletion js/src/evm/stack.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export default class Stack {
}

push_uint(val) {
this.push(bigIntToUint8Array(val));
this.push(bigIntToUint8Array(val))
}

pop_uint() {
Expand Down
4 changes: 2 additions & 2 deletions js/src/evm/vm.js
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,8 @@ export default class Vm {
let s1 = this.stack.pop_uint()

// unsigned to signed
s0 = s0 <= E255M1 ? s0 : (s0 - E256)
s1 = s1 <= E255M1 ? s1 : (s1 - E256)
s0 = s0 <= E255M1 ? s0 : s0 - E256
s1 = s1 <= E255M1 ? s1 : s1 - E256
let res
switch (op) {
case Op.SLT:
Expand Down
4 changes: 2 additions & 2 deletions js/src/index.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export {functionSelectors} from './selectors.js'
export {functionArguments} from './arguments.js'
export { functionSelectors } from './selectors.js'
export { functionArguments } from './arguments.js'
21 changes: 11 additions & 10 deletions js/src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ export function hexToUint8Array(str) {
if (str.startsWith('0x')) {
str = str.slice(2)
if (str.length % 2 !== 0) {
str = '0' + str;
str = '0' + str
}
}
if (typeof Buffer !== 'undefined') { // fast path for nodejs:
return Buffer.from(str, 'hex');
if (typeof Buffer !== 'undefined') {
// fast path for nodejs:
return Buffer.from(str, 'hex')
}
const arr = new Uint8Array(str.length / 2)
for (let i = 0, p = 0; i < str.length; i += 2, p += 1) {
Expand All @@ -16,16 +17,16 @@ export function hexToUint8Array(str) {
}

export function uint8ArrayToBigInt(arr) {
return arr.reduce((acc, b) => acc * 256n + BigInt(b), 0n)
return arr.reduce((acc, b) => acc * 256n + BigInt(b), 0n)
}

export function bigIntToUint8Array(val, n=32) {
const r = new Uint8Array(n);
while(n > 0) {
r[--n] = Number(val & 255n);
val >>= 8n;
export function bigIntToUint8Array(val, n = 32) {
const r = new Uint8Array(n)
while (n > 0) {
r[--n] = Number(val & 255n)
val >>= 8n
}
return r;
return r
}

export function toBigInt(v) {
Expand Down

0 comments on commit 7a267b1

Please sign in to comment.