Copyright | (c) Eric Mertens 2019 |
---|---|
License | ISC |
Maintainer | emertens@gmail.com |
Safe Haskell | Trustworthy |
Language | Haskell2010 |
The module implements the representation of the intcode machine state.
The Machine
type stores the initial memory image in an array and
only stores changes to that initial image. This allows for more efficient
comparisons of machine states for equality when there are few changes to
memory.
This implementation of the machine supports negative memory addresses. These are defined not to be used in the Advent of Code problems.
This implementation stores machine-sized Int
values in memory.
Synopsis
Machine state
Machine state is comprised of the program counter, relative base pointer, and memory.
- Interact with registers using:
jmp
,addRelBase
- Interact with memory using: (
!
),set
- Build new machines with:
new
Updates to memory are stored separately from the initial values
which can enable equality comparisons to be relatively efficient.
This efficiency comes from being able to compare the inital memory
using only pointer equality when two machines are created by the
same call to new
.
Machine | |
|
Construct machine from a list of initial values starting at address 0. Program counter and relative base start at 0.
Register operations
Memory operations
Generate a list representation of memory starting from zero. This can get big for sparsely filled memory using large addresses. Returned values start at position 0.
>>>
memoryList (set 8 10 (new [1,2,3]))
[1,2,3,0,0,0,0,0,10]