copilot-0.28: 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 a

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

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 a

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

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 Bool

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

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

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

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

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

Boolean constants

data Bool

Constructors

False 
True 

Instances

Bounded Bool 
Enum Bool 
Eq Bool 
Ord Bool 
Show Bool 
EqE Bool 
Expr Bool 
Assign Bool 
Streamable Bool 
Random Bool 
Castable Bool 

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.

Instances

Num Double 
Num Float 
Num Int 
Num Int8 
Num Int16 
Num Int32 
Num Int64 
Num Integer 
Num Word 
Num Word8 
Num Word16 
Num Word32 
Num Word64 
Integral a => Num (Ratio a) 
(Num a, NumE a, OrdE a) => Num (E a) 
(Streamable a, NumE a) => Num (Spec 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

Instances

Fractional Double 
Fractional Float 
Integral a => Fractional (Ratio a) 
(OrdE a, NumE a, Num a, Fractional a) => Fractional (E a) 
(Streamable a, NumE a, Fractional a) => Fractional (Spec a) 

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

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

Copilot variable declarations.

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

Useful for writing libraries.

The next functions provide easier access to typed external variables.

The next functions provide easier access to typed external arrays.

extArrB :: (Streamable a, IntegralE a) => Var -> Spec a -> Phase -> Spec Bool

extArrI8 :: (Streamable a, IntegralE a) => Var -> Spec a -> Phase -> Spec Int8

extArrI16 :: (Streamable a, IntegralE a) => Var -> Spec a -> Phase -> Spec Int16

extArrI32 :: (Streamable a, IntegralE a) => Var -> Spec a -> Phase -> Spec Int32

extArrI64 :: (Streamable a, IntegralE a) => Var -> Spec a -> Phase -> Spec Int64

extArrW8 :: (Streamable a, IntegralE a) => Var -> Spec a -> Phase -> Spec Word8

extArrW16 :: (Streamable a, IntegralE a) => Var -> Spec a -> Phase -> Spec Word16

extArrW32 :: (Streamable a, IntegralE a) => Var -> Spec a -> Phase -> Spec Word32

extArrW64 :: (Streamable a, IntegralE a) => Var -> Spec a -> Phase -> Spec Word64

extArrF :: (Streamable a, IntegralE a) => Var -> Spec a -> Phase -> Spec Float

extArrD :: (Streamable a, IntegralE a) => Var -> Spec a -> Phase -> Spec Double

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

opsF2 :: Operators

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

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

Drop i elements from a stream.

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

Just a trivial wrapper over the Append constructor

(.=) :: Streamable a => Spec a -> Spec a -> Streams

Define a stream variable.

The next functions help typing the send operations

send :: Streamable a => String -> Port -> Spec a -> Phase -> Streams

Takes a function name, a port number, a Copilot variable v, and a phase ph, 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. The sending of the value on the port occurs at phase ph.

port :: Int -> Port

Triggers

trigger :: Spec Bool -> String -> TriggerLst -> Streams

Takes a Boolean stream,

void :: TriggerLst

No C arguments

(<>) :: Streamable a => Spec a -> TriggerLst -> TriggerLst

Turn a Spec Var into an arguement for a C function.

(<>>) :: (Streamable a, Streamable b) => Spec a -> Spec b -> TriggerLst

Turn a Spec Var into an arguement for a C function.

Safe casting

cast :: (Castable a, Castable b, Streamable b) => Spec b -> Spec a

Boolean stream constants

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

Coerces a type that is Streamable into a Copilot constant.