aoc2017-0.1.0.0: Advent of Code 2017 - my answers

Safe HaskellSafe
LanguageHaskell2010

Day18

Description

 

Synopsis

Documentation

data Ins reg val Source #

A single instruction.

Either represents either a register reference or an immediate value.

Constructors

Rcv reg 
Snd (Either reg val) 
Op (val -> val -> val) reg (Either reg val) 
Jgz (Either reg val) (Either reg val) 

data MachineSpec m pc reg val Source #

A specification for how to run a machine.

Constructors

MachineSpec 

Fields

data MachineState pc reg val Source #

The current state of a machine.

Constructors

MachineState

The machine is running.

Fields

  • pc :: pc

    The program counter.

  • regs :: Map reg val

    The registers.

MachineTerminated

The machine is stopped.

parse :: (Integral a, Read a) => String -> [Ins String a] Source #

Parse an assembly listing to instructions.

step :: (Monad m, Ix pc, Num pc, Ord reg, Integral val, Ord val) => MachineSpec m pc reg val -> MachineState pc reg val -> m (MachineState pc reg val) Source #

Evaluate a single instruction.

loop :: (Monad m, Ix pc, Num pc, Ord reg, Integral val, Ord val) => MachineSpec m pc reg val -> MachineState pc reg val -> m () Source #

Run a machine until its state reaches MachineTerminated.