retroforth/vm/nga-python/Memory.py
crc 1b0fa54eef nga-python: commit updates to class-based vm implementation
FossilOrigin-Name: f6f51a35193443a3fb5735b5cf742b82bafd9810aab098fe9376847ac948b4b1
2020-12-02 20:18:58 +00:00

24 lines
560 B
Python

import os
import struct
class Memory:
def __init__(self, source, size):
self.memory = [0] * size
cells = int(os.path.getsize(source) / 4)
f = open(source, "rb")
i = 0
for cell in list(struct.unpack(cells * "i", f.read())):
self.memory[i] = cell
i = i + 1
f.close()
self.length = size
def store(self, value, address):
self.memory[address] = value
def fetch(self, address):
return self.memory[address]
def size(self):
return self.length