Created
July 12, 2019 09:42
-
-
Save martijnbastiaan/3f2eca0616cf203750f4c8d1342190c7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[..] | |
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 n, r) _ | n == maxBound = ((Idle, 0), (Just r, Ready)) | |
| otherwise = ((Waiting (succ 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