copilot-0.21: A lazy-list language for generating constant-time and constant-space C programs. Uses Atom as a backend.

Language.Copilot.Language

Contents

Description

Describes the language Copilot.

If you wish to add a new operator, the only modification needed is adding it in this module. But if you want it to be used in the random generated streams, add it to either opsF, opsF2 or opsF3

Synopsis

Operators and functions

mod :: (Streamable a, IntegralE a) => Spec a -> Spec a -> Spec aSource

div :: (Streamable a, IntegralE a) => Spec a -> Spec a -> Spec aSource

Beware : crash without any possible recovery if a division by 0 happens. Same risk with mod. Use div0 and mod0 if unsure.

mod0 :: (Streamable a, IntegralE a) => a -> Spec a -> Spec a -> Spec aSource

div0 :: (Streamable a, IntegralE a) => a -> Spec a -> Spec a -> Spec aSource

As mod and div, except that if the division would be by 0, it is instead by the first argument.

(<) :: (Streamable a, OrdE a) => Spec a -> Spec a -> Spec BoolSource

(<=) :: (Streamable a, OrdE a) => Spec a -> Spec a -> Spec BoolSource

(==) :: (Streamable a, EqE a) => Spec a -> Spec a -> Spec BoolSource

(/=) :: (Streamable a, EqE a) => Spec a -> Spec a -> Spec BoolSource

(>=) :: (Streamable a, OrdE a) => Spec a -> Spec a -> Spec BoolSource

(>) :: (Streamable a, OrdE a) => Spec a -> Spec a -> Spec BoolSource

Boolean constants

Arithmetic operators (derived)

class (Eq a, Show a) => Num a where

Basic numeric class.

Minimal complete definition: all except negate or (-)

Methods

(+) :: a -> a -> a

(*) :: a -> a -> a

(-) :: a -> a -> a

negate :: a -> a

Unary negation.

abs :: a -> a

Absolute value.

signum :: a -> a

Sign of a number. The functions abs and signum should satisfy the law:

abs x * signum x == x

For real numbers, the signum is either -1 (negative), 0 (zero) or 1 (positive).

fromInteger :: Integer -> a

Conversion from an Integer. An integer literal represents the application of the function fromInteger to the appropriate value of type Integer, so such literals have type (Num a) => a.

Division

class Num a => Fractional a where

Fractional numbers, supporting real division.

Minimal complete definition: fromRational and (recip or (/))

Methods

(/) :: a -> a -> a

fractional division

mux :: Streamable a => Spec Bool -> Spec a -> Spec a -> Spec aSource

Beware : both sides are executed, even if the result of one is later discarded

The next functions are used only to coerce the type of their argument

The next functions provide easier access to typed external variables.

Set of operators from which to choose during the generation of random streams

opsF2 :: OperatorsSource

opsF, opsF2 and opsF3 are feeded to Tests.Random.randomStreams. They allows the random generated streams to include lots of operators. If you add a new operator to Copilot, it would be nice to add it to one of those, that way it could be used in the random streams used for testing. opsF holds all the operators of arity 1, opsF2 of arity 2 and opsF3 of arity3 They are StreamableMaps, because operators are sorted based on their return type.

Constructs of the copilot language

var :: Streamable a => Var -> Spec aSource

Stream variable reference

const :: Streamable a => a -> Spec aSource

A constant stream

drop :: Streamable a => Int -> Spec a -> Spec aSource

Drop i elements from a stream.

(++) :: Streamable a => [a] -> Spec a -> Spec aSource

Just a trivial wrapper over the Append constructor

(.=) :: Streamable a => Var -> Spec a -> StreamsSource

Define a stream variable.

(..|) :: Sendable a => Send a -> Sends -> SendsSource

Allows to build a Sends from specification

The next functions are typed variable declarations to help the type-checker.

The next functions help typing the send operations

Typed constant declarations.