retroforth/vm/nga-python/Memory.py
crc 5efaf73271 nga-python: have Memory class inherit from list (#20)
FossilOrigin-Name: 36c77bdca28143d6a2928f9ea2b9dbb4003ef9e48fd61cddac0897af6f888e74
2020-12-17 13:21:35 +00:00

18 lines
401 B
Python

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