diff options
author | jm <jm.huang@cobinhood.com> | 2019-01-15 00:48:13 +0800 |
---|---|---|
committer | Jhih-Ming Huang <jm.huang@cobinhood.com> | 2019-05-06 10:44:03 +0800 |
commit | 266068a53cdf9e06acacf982d63653c03133a634 (patch) | |
tree | af2d74e6adb309adfe39bafaa2f540fe0bcd1a31 /core/vm/memory.go | |
parent | d41cb421d755b8f0bca87b7476f26aa4b879b9d9 (diff) | |
download | dexon-266068a53cdf9e06acacf982d63653c03133a634.tar dexon-266068a53cdf9e06acacf982d63653c03133a634.tar.gz dexon-266068a53cdf9e06acacf982d63653c03133a634.tar.bz2 dexon-266068a53cdf9e06acacf982d63653c03133a634.tar.lz dexon-266068a53cdf9e06acacf982d63653c03133a634.tar.xz dexon-266068a53cdf9e06acacf982d63653c03133a634.tar.zst dexon-266068a53cdf9e06acacf982d63653c03133a634.zip |
core: vm: refactor file structure
For support other vm types, this pr modified the core/vm file
structures.
Diffstat (limited to 'core/vm/memory.go')
-rw-r--r-- | core/vm/memory.go | 48 |
1 files changed, 24 insertions, 24 deletions
diff --git a/core/vm/memory.go b/core/vm/memory.go index 65ffe26c7..bbfa4cc2a 100644 --- a/core/vm/memory.go +++ b/core/vm/memory.go @@ -25,8 +25,8 @@ import ( // Memory implements a simple memory model for the ethereum virtual machine. type Memory struct { - store []byte - lastGasCost uint64 + Store []byte + LastGasCost uint64 } // NewMemory returns a new memory model. @@ -39,33 +39,33 @@ func (m *Memory) Set(offset, size uint64, value []byte) { // It's possible the offset is greater than 0 and size equals 0. This is because // the calcMemSize (common.go) could potentially return 0 when size is zero (NO-OP) if size > 0 { - // length of store may never be less than offset + size. - // The store should be resized PRIOR to setting the memory - if offset+size > uint64(len(m.store)) { - panic("invalid memory: store empty") + // length of.Store may never be less than offset + size. + // The.Store should be resized PRIOR to setting the memory + if offset+size > uint64(len(m.Store)) { + panic("invalid memory:.Store empty") } - copy(m.store[offset:offset+size], value) + copy(m.Store[offset:offset+size], value) } } // Set32 sets the 32 bytes starting at offset to the value of val, left-padded with zeroes to // 32 bytes. func (m *Memory) Set32(offset uint64, val *big.Int) { - // length of store may never be less than offset + size. - // The store should be resized PRIOR to setting the memory - if offset+32 > uint64(len(m.store)) { - panic("invalid memory: store empty") + // length of.Store may never be less than offset + size. + // The.Store should be resized PRIOR to setting the memory + if offset+32 > uint64(len(m.Store)) { + panic("invalid memory:.Store empty") } // Zero the memory area - copy(m.store[offset:offset+32], []byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}) + copy(m.Store[offset:offset+32], []byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}) // Fill in relevant bits - math.ReadBits(val, m.store[offset:offset+32]) + math.ReadBits(val, m.Store[offset:offset+32]) } // Resize resizes the memory to size func (m *Memory) Resize(size uint64) { if uint64(m.Len()) < size { - m.store = append(m.store, make([]byte, size-uint64(m.Len()))...) + m.Store = append(m.Store, make([]byte, size-uint64(m.Len()))...) } } @@ -75,9 +75,9 @@ func (m *Memory) Get(offset, size int64) (cpy []byte) { return nil } - if len(m.store) > int(offset) { + if len(m.Store) > int(offset) { cpy = make([]byte, size) - copy(cpy, m.store[offset:offset+size]) + copy(cpy, m.Store[offset:offset+size]) return } @@ -91,8 +91,8 @@ func (m *Memory) GetPtr(offset, size int64) []byte { return nil } - if len(m.store) > int(offset) { - return m.store[offset : offset+size] + if len(m.Store) > int(offset) { + return m.Store[offset : offset+size] } return nil @@ -100,21 +100,21 @@ func (m *Memory) GetPtr(offset, size int64) []byte { // Len returns the length of the backing slice func (m *Memory) Len() int { - return len(m.store) + return len(m.Store) } // Data returns the backing slice func (m *Memory) Data() []byte { - return m.store + return m.Store } // Print dumps the content of the memory. func (m *Memory) Print() { - fmt.Printf("### mem %d bytes ###\n", len(m.store)) - if len(m.store) > 0 { + fmt.Printf("### mem %d bytes ###\n", len(m.Store)) + if len(m.Store) > 0 { addr := 0 - for i := 0; i+32 <= len(m.store); i += 32 { - fmt.Printf("%03d: % x\n", addr, m.store[i:i+32]) + for i := 0; i+32 <= len(m.Store); i += 32 { + fmt.Printf("%03d: % x\n", addr, m.Store[i:i+32]) addr++ } } else { |