32 lines
770 B
Haskell
32 lines
770 B
Haskell
|
module Base where
|
||
|
|
||
|
import qualified Data.HashMap as HM
|
||
|
|
||
|
data BFAction = MoveRight
|
||
|
| MoveLeft
|
||
|
| Increment
|
||
|
| Decrement
|
||
|
| Replace
|
||
|
| Print
|
||
|
| JumpRight
|
||
|
| JumpLeft
|
||
|
|
||
|
type Address = Int
|
||
|
type CodePosition = Int
|
||
|
|
||
|
type Memory = HM.Map Address Int
|
||
|
type JumpTable = HM.Map CodePosition CodePosition
|
||
|
|
||
|
data State = State { memory :: Memory
|
||
|
, pointer :: Int
|
||
|
, codePos :: Int
|
||
|
, jumpTable :: JumpTable
|
||
|
}
|
||
|
deriving (Show, Read, Eq)
|
||
|
|
||
|
initState :: State
|
||
|
initState = State { memory = HM.empty
|
||
|
, pointer = 0
|
||
|
, codePos = 0
|
||
|
, jumpTable = HM.empty
|
||
|
}
|