piet-0.1: A Piet interpreter

Language.Piet.Commands

Contents

Description

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.

Synopsis

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.

piet_pop :: PietMonad ()Source

Pops the top value off the stack and discards it.

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.