Skip to content

Instantly share code, notes, and snippets.

@martijnbastiaan
Created July 12, 2019 09:50
Show Gist options
  • Save martijnbastiaan/604d337c69ee63def34854d420e0e265 to your computer and use it in GitHub Desktop.
Save martijnbastiaan/604d337c69ee63def34854d420e0e265 to your computer and use it in GitHub Desktop.
[..]
data CPUState waitCycles
= Idle
| Waiting (Index waitCycles)
deriving (Generic, NFData, Show)
[..]
cpu
:: forall waitCycles
. (CPUState, Int)
-- ^ State
-> Maybe (Instruction waitCycles)
-- ^ Input
-> ((CPUState, Int), (Maybe Int, Ready))
-- (New state, output)
-- state input new state output
cpu (Idle, _) Nothing = ((Idle, 0), (Nothing, Ready))
cpu (Idle, _) (Just instr) = ((Waiting 0, doInstr instr), (Nothing, Busy))
cpu (Waiting 0, r) _ = ((Idle, 0), (Just r, Ready))
cpu (Waiting n, r) _ = ((Waiting (pred n), r), (Nothing, Busy))
[..]
cpuWaiting5Cycles = cpu @5 (Idle, 0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment