brainfuck-0.1.0.3: Brainfuck interpreter

Safe Haskell | None
Language | Haskell98

Language.Brainfuck

Synopsis

- data Command
  - = IncPtr
  - | IncPtrBy !Int
  - | DecPtr
  - | IncByte
  - | IncByteBy !Int
  - | DecByte
  - | OutputByte
  - | JmpForward !Int
  - | JmpBackward !Int
  - | SetIpTo !Int
  - | Halt
  - | Ignored
- type Core = IOUArray Int Word8
- type InstPtr = Int
- type CorePtr = Int
- data BF = BF !Core !CorePtr !InstPtr
- coreSize :: Int
- core :: IO Core
- decode :: Char -> State Int Command
- debug :: Bool
- incIP :: InstPtr -> InstPtr
- incCP :: CorePtr -> CorePtr
- decCP :: CorePtr -> CorePtr
- doCommand :: Array Int Command -> BF -> IO BF
- nextJmp :: Array Int Command -> InstPtr -> (InstPtr -> InstPtr) -> Command -> InstPtr
- chrToWord8 :: Char -> Word8
- word8ToChr :: Word8 -> Char
- updateByte :: MArray IOUArray Word8 m => BF -> (Word8 -> Word8) -> m BF
- loadProgram :: String -> Array Int Command
- optimize :: [Command] -> Array Int Command
- execute :: Array Int Command -> Int -> BF -> IO ()
- halt :: IO ()

# Documentation

data Command Source #

The complete BF language:

- > Increment the pointer.
- < Decrement the pointer.
- + Increment the byte at the pointer.
- - Decrement the byte at the pointer.
- . Output the byte at the pointer.
- , Input a byte and store it in the byte at the pointer.
- [ Jump forward past the matching ] if the byte at the pointer is zero.
- ] Jump backward to the matching [ unless the byte at the pointer is zero.

Constructors

IncPtr |
IncPtrBy !Int | Increment pointer by set amount
DecPtr |
IncByte |
IncByteBy !Int | Increment by a set amount
DecByte |
OutputByte |
JmpForward !Int | nesting level
JmpBackward !Int | nesting level
SetIpTo !Int | Sets the instruction ptr to a specific value
Halt |
Ignored |

#### Instances

Instances details

Eq Command Source # |
Instance details Defined in Language.Brainfuck Methods (==) :: Command -> Command -> Bool Source # (/=) :: Command -> Command -> Bool Source #
Show Command Source # |
Instance details Defined in Language.Brainfuck Methods showsPrec :: Int -> Command -> ShowS Source # show :: Command -> String Source # showList :: [Command] -> ShowS Source #

type Core = IOUArray Int Word8 Source #

type InstPtr = Int Source #

type CorePtr = Int Source #

data BF Source #

Constructors

BF !Core !CorePtr !InstPtr |

#### Instances

Instances details

Show BF Source # |
Instance details Defined in Language.Brainfuck Methods showsPrec :: Int -> BF -> ShowS Source # show :: BF -> String Source # showList :: [BF] -> ShowS Source #

coreSize :: Int Source #

core :: IO Core Source #

decode :: Char -> State Int Command Source #

debug :: Bool Source #

incIP :: InstPtr -> InstPtr Source #

incCP :: CorePtr -> CorePtr Source #

decCP :: CorePtr -> CorePtr Source #

doCommand :: Array Int Command -> BF -> IO BF Source #

nextJmp :: Array Int Command -> InstPtr -> (InstPtr -> InstPtr) -> Command -> InstPtr Source #

chrToWord8 :: Char -> Word8 Source #

word8ToChr :: Word8 -> Char Source #

updateByte :: MArray IOUArray Word8 m => BF -> (Word8 -> Word8) -> m BF Source #

loadProgram :: String -> Array Int Command Source #

optimize :: [Command] -> Array Int Command Source #

execute :: Array Int Command -> Int -> BF -> IO () Source #

halt :: IO () Source #