copilot-1.0: A stream DSL for writing embedded C monitors.

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, the first argument is used as a default.

(<) :: (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

data Bool

Constructors

False 
True 

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

Copilot variable declarations.

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

Useful for writing libraries.

Copilot constant declarations. For the most part, these are

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

Coerces a type that is Streamable into a Copilot constant.

Boolean stream constants

Constructs of the copilot language

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 => Spec a -> Spec a -> StreamsSource

Define a stream variable.

The next functions help typing the send operations

send :: Streamable a => String -> Port -> Spec a -> StreamsSource

Takes a function name, a port number, and a Copilot variable v and constructs a call to the C function name(x,y) where x is the value of the Copilot stream v and y is the port number.

Triggers

Safe casting

notConstVarErr :: Streamable a => Spec a -> (ArgConstVar -> b) -> bSource

If the Spec isn't a Var or Const, then throw an error; otherwise, apply the function.