Algorithms.hs

module Algorithms where
import Memories(Addr,Word)
import MemMonads
import qualified FunFM as FM
import Nat

type Reg = Nat
type RegFile = FM.FM Word

data Code
  = Done RegFile
  | Read Addr (Word->Code)
  | Write Addr Word Code

type Alg = Addr -> RegFile -> Code

runAlg (Done r) = return r
runAlg (Read a c) = rd a >>= runAlg . c
runAlg (Write a w c) = wr a w >> runAlg c


---

initRegFile :: RegFile
initRegFile = FM.empty 0

r0,r1,r2::Reg
r0=O
r1=S r0
r2=S r1

Plain-text version of Algorithms.hs | Valid HTML?