A module implementing the Piet interpreter as a monad. The monad encapsulates the interpreter's status, i. e. the side-effects of Piet programs.
- data PietMonad a
- data InterpreterStatus
- data LogLevel
- getDP :: PietMonad DirectionPointer
- setDP :: DirectionPointer -> PietMonad ()
- getCC :: PietMonad CodelChooser
- setCC :: CodelChooser -> PietMonad ()
- getPosition :: PietMonad (Int, Int)
- setPosition :: Int -> Int -> PietMonad ()
- stackPush :: Int -> PietMonad ()
- stackPop :: PietMonad (Maybe Int)
- stackRoll :: Int -> Int -> PietMonad ()
- printNumber :: Int -> PietMonad ()
- printChar :: Int -> PietMonad ()
- readNumber :: PietMonad Int
- readChar :: PietMonad Int
- logMessage :: LogLevel -> String -> PietMonad ()
- terminate :: PietMonad ()
- runPietMonad :: (PietType -> IO Int) -> (PietType -> Int -> IO ()) -> (LogLevel -> String -> IO ()) -> PietMonad a -> IO (Either String a)
The Piet interpreter monad
A monad encapsulating the status of a Piet interpreter.
data InterpreterStatus Source
The status of a Piet interpreter.
Describes the importance of a log message.
Status access
Direction Pointer, Codel Chooser and position
getDP :: PietMonad DirectionPointerSource
Returns the current Direction Pointer.
setDP :: DirectionPointer -> PietMonad ()Source
Sets the Direction Pointer.
getCC :: PietMonad CodelChooserSource
Returns the current Codel Chooser.
setCC :: CodelChooser -> PietMonad ()Source
Sets the current Codel Chooser.
getPosition :: PietMonad (Int, Int)Source
Returns the current position.
Stack primitives
Performs the roll
operation on the stack.
I/O
printNumber :: Int -> PietMonad ()Source
Prints a number to STDOUT.
printChar :: Int -> PietMonad ()Source
Converts a given number to a character and prints it to STDOUT.
readNumber :: PietMonad IntSource
Reads a number from STDIN.
Termination
Execution
:: (PietType -> IO Int) | Callback to read from STDIN |
-> (PietType -> Int -> IO ()) | Print callback |
-> (LogLevel -> String -> IO ()) | Logging callback |
-> PietMonad a | The program to be executed |
-> IO (Either String a) | Result of the |
Executes a program represented by a PietMonad
. I/O operations
(reading and writing numbers or characters) is delegated to
callback functions.