Skip to content

Instantly share code, notes, and snippets.

@eklitzke
Created June 26, 2009 20:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eklitzke/136720 to your computer and use it in GitHub Desktop.
Save eklitzke/136720 to your computer and use it in GitHub Desktop.
-- An Addr is really 14 bits, but this should be close enough
type Addr = Word16
-- The status register
type StatusR = On | Off deriving (Show, Eq)
type Imm = LTZ
| LEZ
| EQZ
| GEZ
| GTZ deriving (Show, Eq, Ord, Enum)
data DOper = Add
| Sub
| Mult -- etc.
data DType = DOper Addr Addr
data SType = SOper (Maybe Imm) Addr
-- The program counter
type ProgramCounter = Addr
-- The instruction set is immutable
type Instructions = IArray Addr Word32
-- Memory is mutable
type Memory = IOArray Addr Word64
data World = World ProgramCounter StatusR Instructions Memory
-- Stepping through a single instruction is a function like World -> IO
-- World. The new world has an incremented ProgramCounter, and shares the same
-- reference to an Instruction array and Memory array. Since the memory array is
-- mutable, the old world shouldn't be used anymore (since its memory contents
-- will reflect the new state of the world).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment