2018-01-16 17:05:20 +00:00
|
|
|
import
|
2018-01-22 22:23:07 +00:00
|
|
|
sequtils, bigints,
|
2018-01-16 17:05:20 +00:00
|
|
|
../constants, ../errors, ../logging, ../validation, ../utils_numeric
|
|
|
|
|
|
|
|
type
|
|
|
|
Memory* = ref object
|
|
|
|
logger*: Logger
|
|
|
|
bytes*: seq[byte]
|
|
|
|
|
|
|
|
proc newMemory*: Memory =
|
|
|
|
new(result)
|
|
|
|
result.bytes = @[]
|
|
|
|
result.logger = logging.getLogger("evm.vm.memory.Memory")
|
|
|
|
|
|
|
|
proc len*(memory: Memory): int =
|
|
|
|
result = len(memory.bytes)
|
|
|
|
|
|
|
|
proc extend*(memory: var Memory; startPosition: Int256; size: Int256) =
|
|
|
|
if size == 0:
|
|
|
|
return
|
|
|
|
var newSize = ceil32(startPosition + size)
|
2018-01-22 22:23:07 +00:00
|
|
|
if newSize <= len(memory).int256:
|
2018-01-16 17:05:20 +00:00
|
|
|
return
|
2018-01-22 22:23:07 +00:00
|
|
|
var sizeToExtend = newSize - len(memory).int256
|
|
|
|
memory.bytes = memory.bytes.concat(repeat(0.byte, sizeToExtend.getInt))
|
2018-01-16 17:05:20 +00:00
|
|
|
|
2018-01-24 13:31:24 +00:00
|
|
|
proc newMemory*(size: Int256): Memory =
|
|
|
|
result = newMemory()
|
|
|
|
result.extend(0.int256, size)
|
|
|
|
|
2018-01-16 17:05:20 +00:00
|
|
|
proc read*(self: var Memory; startPosition: Int256; size: Int256): cstring =
|
|
|
|
return cstring""
|
2018-01-22 22:23:07 +00:00
|
|
|
|
|
|
|
proc write*(self: var Memory, startPosition: Int256, size: Int256, value: cstring) =
|
|
|
|
echo value
|