This module contains the implementation of the Piet language constructs. Most of the documentation is copied from the Piet specification at http://www.dangermouse.net/esoteric/piet.html.
- piet_push :: Int -> PietMonad ()
- piet_pop :: PietMonad ()
- piet_add :: PietMonad ()
- piet_subtract :: PietMonad ()
- piet_multiply :: PietMonad ()
- piet_divide :: PietMonad ()
- piet_mod :: PietMonad ()
- piet_not :: PietMonad ()
- piet_greater :: PietMonad ()
- piet_pointer :: PietMonad ()
- piet_switch :: PietMonad ()
- piet_duplicate :: PietMonad ()
- piet_roll :: PietMonad ()
- piet_in_number :: PietMonad ()
- piet_in_char :: PietMonad ()
- piet_out_number :: PietMonad ()
- piet_out_char :: PietMonad ()
Stack access
piet_push :: Int -> PietMonad ()Source
Pushes the value of the colour block just exited on to the stack. Note that values of colour blocks are not automatically pushed on to the stack - this push operation must be explicitly carried out.
Arithmetic operators
piet_add :: PietMonad ()Source
Pops the top two values off the stack, adds them, and pushes the result back on the stack.
piet_subtract :: PietMonad ()Source
Pops the top two values off the stack, subtracts the top value from the second top value, and pushes the result back on the stack.
piet_multiply :: PietMonad ()Source
Pops the top two values off the stack, multiplies them, and pushes the result back on the stack.
piet_divide :: PietMonad ()Source
Pops the top two values off the stack, calculates the integer division of the second top value by the top value, and pushes the result back on the stack.
piet_mod :: PietMonad ()Source
Pops the top two values off the stack, calculates the second top value modulo the top value, and pushes the result back on the stack.
Boolean operations
piet_not :: PietMonad ()Source
Replaces the top value of the stack with 0 if it is non-zero, and 1 if it is zero.
piet_greater :: PietMonad ()Source
Pops the top two values off the stack, and pushes 1 on to the stack if the second top value is greater than the top value, and pushes 0 if it is not greater.
Movement
piet_pointer :: PietMonad ()Source
Pops the top value off the stack and rotates the DP clockwise that many steps (anticlockwise if negative).
piet_switch :: PietMonad ()Source
Pops the top value off the stack and toggles the CC that many times.
Stack modification
piet_duplicate :: PietMonad ()Source
Pushes a copy of the top value on the stack on to the stack.
piet_roll :: PietMonad ()Source
Pops the top two values off the stack and "rolls" the remaining stack entries to a depth equal to the second value popped, by a number of rolls equal to the first value popped. A single roll to depth n is defined as burying the top value on the stack n deep and bringing all values above it up by 1 place. A negative number of rolls rolls in the opposite direction. A negative depth is an error and the command is ignored.
In this implementation, "ignored" means that the top two values remain pushed off the stack, while the rest of the stack remains unmodified.
I/O
piet_in_number :: PietMonad ()Source
Reads a number from STDIN and pushes it on to the stack.
piet_in_char :: PietMonad ()Source
Reads a char from STDIN and pushes it on to the stack.
piet_out_number :: PietMonad ()Source
Pops the top value off the stack and prints it to STDOUT as a number.
piet_out_char :: PietMonad ()Source
Pops the top value off the stack and prints it to STDOUT as a char.