piet-0.1: A Piet interpreter

Language.Piet.Interpreter

Contents

Description

This module implements an interpreter for the Piet programming language.

Synopsis

Interpreter implementation

interpret :: Program -> PietMonad ()Source

Interpret a Piet Program.

Helper functions

Movement

interpretWhite :: Program -> PietMonad ()Source

Find a way out of the current White block. terminate if there is no way out.

nonBlackSuccSource

Arguments

:: Program

Program

-> LabelInfo

Current block

-> DirectionPointer

DP

-> CodelChooser

CC

-> Maybe (Int, Int, DirectionPointer, CodelChooser)

Next coordinates, DP and CC (if available)

Find coordinates and resulting DP/CC of the successing non-black block, if it exists, Nothing otherwise.

succCoordinatesSource

Arguments

:: LabelInfo

Current label

-> DirectionPointer

DP

-> CodelChooser

CC

-> (Int, Int)

Where to enter the next block

Given a label, a DirectionPointer and a CodelChooser, this function finds the coordinates of the next block to enter. These coordinates are not guaranteed to be valid, they might be out of range or point to a Black or White block.

Colour difference handling

colours2CommandSource

Arguments

:: Lightness

Lightness of the "from"-block

-> HueColour

HueColour of the "from"-block

-> Lightness

Lightness of the "to"-block

-> HueColour

HueColour of the "to"-block

-> Int

The size of the "from"-block

-> PietMonad ()

Resulting Piet operation

Piet's commands are issued by a colour change, see http://www.dangermouse.net/esoteric/piet.html. This function takes two neighbouring colours and returns the resulting Piet command, which is a function consuming (or more likely, ignoring) an Int (the size of the colour block that is being left) and returning a PietMonad ().

colourDiff2Command :: Lightness -> HueColour -> Int -> PietMonad ()Source

Converts a colour difference calculated by Language.Piet.Types.colourChange and lightnessChange to a PietMonad (), compare colours2Command.