-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | An intermediate representation for Copilot. -- -- Intermediate representation for Copilot. -- -- Copilot is a stream (i.e., infinite lists) domain-specific language -- (DSL) in Haskell that compiles into embedded C. Copilot contains an -- interpreter, multiple back-end compilers, and other verification -- tools. -- -- A tutorial, examples, and other information are available at -- https://copilot-language.github.io. @package copilot-core @version 3.20 -- | Implementation of an array that uses type literals to store length. No -- explicit indexing is used for the input data. Supports arbitrary -- nesting of arrays. module Copilot.Core.Type.Array -- | Implementation of an array that uses type literals to store length. data Array (n :: Nat) t -- | Smart array constructor that only type checks if the length of the -- given list matches the length of the array at type level. array :: forall n t. KnownNat n => [t] -> Array n t -- | Return the elements of an array. arrayElems :: Array n a -> [a] instance GHC.Show.Show t => GHC.Show.Show (Copilot.Core.Type.Array.Array n t) -- | All expressions and streams in Core are accompanied by a -- representation of the types of the underlying expressions used or -- carried by the streams. This information is needed by the compiler to -- generate code, since it must initialize variables and equivalent -- representations for those types in the target languages. module Copilot.Core.Type -- | A Type representing the types of expressions or values handled by -- Copilot Core. -- -- Note that both arrays and structs use dependently typed features. In -- the former, the length of the array is part of the type. In the -- latter, the names of the fields are part of the type. data Type :: * -> * [Bool] :: Type Bool [Int8] :: Type Int8 [Int16] :: Type Int16 [Int32] :: Type Int32 [Int64] :: Type Int64 [Word8] :: Type Word8 [Word16] :: Type Word16 [Word32] :: Type Word32 [Word64] :: Type Word64 [Float] :: Type Float [Double] :: Type Double [Array] :: forall n t. (KnownNat n, Typed t) => Type t -> Type (Array n t) [Struct] :: (Typed a, Struct a) => a -> Type a -- | A typed expression, from which we can obtain the two type -- representations used by Copilot: Type and SimpleType. class (Show a, Typeable a) => Typed a typeOf :: Typed a => Type a simpleType :: Typed a => Type a -> SimpleType -- | A untyped type (no phantom type). data UType UType :: Type a -> UType [uTypeType] :: UType -> Type a -- | A simple, monomorphic representation of types that facilitates putting -- variables in heterogeneous lists and environments in spite of their -- types being different. data SimpleType [SBool] :: SimpleType [SInt8] :: SimpleType [SInt16] :: SimpleType [SInt32] :: SimpleType [SInt64] :: SimpleType [SWord8] :: SimpleType [SWord16] :: SimpleType [SWord32] :: SimpleType [SWord64] :: SimpleType [SFloat] :: SimpleType [SDouble] :: SimpleType [SArray] :: Type t -> SimpleType [SStruct] :: SimpleType -- | Return the total (nested) size of an array from its type typeSize :: forall n t. KnownNat n => Type (Array n t) -> Int -- | Return the length of an array from its type typeLength :: forall n t. KnownNat n => Type (Array n t) -> Int -- | The field of a struct, together with a representation of its type. data Value a Value :: Type t -> Field s t -> Value a -- | Transforms all the struct's fields into a list of values. toValues :: Struct a => a -> [Value a] -- | A field in a struct. The name of the field is a literal at the type -- level. data Field (s :: Symbol) t Field :: t -> Field (s :: Symbol) t -- | Returns the name of struct in the target language. typeName :: Struct a => a -> String -- | The value of that is a product or struct, defined as a constructor -- with several fields. class Struct a -- | Extract the name of a field. fieldName :: forall s t. KnownSymbol s => Field s t -> String -- | Extract the name of an accessor (a function that returns a field of a -- struct). accessorName :: forall a s t. (Struct a, KnownSymbol s) => (a -> Field s t) -> String updateField :: Struct a => a -> Value t -> a instance GHC.Classes.Eq Copilot.Core.Type.UType instance (Copilot.Core.Type.Typed t, Copilot.Core.Type.Struct t) => GHC.Show.Show t instance Data.Type.Equality.TestEquality Copilot.Core.Type.Type instance GHC.Classes.Eq Copilot.Core.Type.SimpleType instance Copilot.Core.Type.Typed GHC.Types.Bool instance Copilot.Core.Type.Typed GHC.Int.Int8 instance Copilot.Core.Type.Typed GHC.Int.Int16 instance Copilot.Core.Type.Typed GHC.Int.Int32 instance Copilot.Core.Type.Typed GHC.Int.Int64 instance Copilot.Core.Type.Typed GHC.Word.Word8 instance Copilot.Core.Type.Typed GHC.Word.Word16 instance Copilot.Core.Type.Typed GHC.Word.Word32 instance Copilot.Core.Type.Typed GHC.Word.Word64 instance Copilot.Core.Type.Typed GHC.Types.Float instance Copilot.Core.Type.Typed GHC.Types.Double instance (Data.Typeable.Internal.Typeable t, Copilot.Core.Type.Typed t, GHC.TypeNats.KnownNat n) => Copilot.Core.Type.Typed (Copilot.Core.Type.Array.Array n t) instance (GHC.TypeLits.KnownSymbol s, GHC.Show.Show t) => GHC.Show.Show (Copilot.Core.Type.Field s t) module Copilot.Core.Operators -- | Unary operators. data Op1 a b [Not] :: Op1 Bool Bool [Abs] :: Num a => Type a -> Op1 a a [Sign] :: Num a => Type a -> Op1 a a [Recip] :: Fractional a => Type a -> Op1 a a [Exp] :: Floating a => Type a -> Op1 a a [Sqrt] :: Floating a => Type a -> Op1 a a [Log] :: Floating a => Type a -> Op1 a a [Sin] :: Floating a => Type a -> Op1 a a [Tan] :: Floating a => Type a -> Op1 a a [Cos] :: Floating a => Type a -> Op1 a a [Asin] :: Floating a => Type a -> Op1 a a [Atan] :: Floating a => Type a -> Op1 a a [Acos] :: Floating a => Type a -> Op1 a a [Sinh] :: Floating a => Type a -> Op1 a a [Tanh] :: Floating a => Type a -> Op1 a a [Cosh] :: Floating a => Type a -> Op1 a a [Asinh] :: Floating a => Type a -> Op1 a a [Atanh] :: Floating a => Type a -> Op1 a a [Acosh] :: Floating a => Type a -> Op1 a a [Ceiling] :: RealFrac a => Type a -> Op1 a a [Floor] :: RealFrac a => Type a -> Op1 a a [BwNot] :: Bits a => Type a -> Op1 a a [Cast] :: (Integral a, Num b) => Type a -> Type b -> Op1 a b [GetField] :: KnownSymbol s => Type a -> Type b -> (a -> Field s b) -> Op1 a b -- | Binary operators. data Op2 a b c [And] :: Op2 Bool Bool Bool [Or] :: Op2 Bool Bool Bool [Add] :: Num a => Type a -> Op2 a a a [Sub] :: Num a => Type a -> Op2 a a a [Mul] :: Num a => Type a -> Op2 a a a [Mod] :: Integral a => Type a -> Op2 a a a [Div] :: Integral a => Type a -> Op2 a a a [Fdiv] :: Fractional a => Type a -> Op2 a a a [Pow] :: Floating a => Type a -> Op2 a a a [Logb] :: Floating a => Type a -> Op2 a a a [Atan2] :: RealFloat a => Type a -> Op2 a a a [Eq] :: Eq a => Type a -> Op2 a a Bool [Ne] :: Eq a => Type a -> Op2 a a Bool [Le] :: Ord a => Type a -> Op2 a a Bool [Ge] :: Ord a => Type a -> Op2 a a Bool [Lt] :: Ord a => Type a -> Op2 a a Bool [Gt] :: Ord a => Type a -> Op2 a a Bool [BwAnd] :: Bits a => Type a -> Op2 a a a [BwOr] :: Bits a => Type a -> Op2 a a a [BwXor] :: Bits a => Type a -> Op2 a a a [BwShiftL] :: (Bits a, Integral b) => Type a -> Type b -> Op2 a b a [BwShiftR] :: (Bits a, Integral b) => Type a -> Type b -> Op2 a b a [Index] :: Type (Array n t) -> Op2 (Array n t) Word32 t [UpdateField] :: (Typeable b, KnownSymbol s, Show b) => Type a -> Type b -> (a -> Field s b) -> Op2 a b a -- | Ternary operators. data Op3 a b c d [Mux] :: Type a -> Op3 Bool a a a module Copilot.Core.Expr -- | A stream identifier. type Id = Int -- | A name of a trigger, an external variable, or an external function. type Name = String -- | Internal representation of Copilot stream expressions. -- -- The Core representation mimics the high-level Copilot stream, but the -- Core representation contains information about the types of elements -- in the stream. data Expr a [Const] :: Typeable a => Type a -> a -> Expr a [Drop] :: Typeable a => Type a -> DropIdx -> Id -> Expr a [Local] :: Typeable a => Type a -> Type b -> Name -> Expr a -> Expr b -> Expr b [Var] :: Typeable a => Type a -> Name -> Expr a [ExternVar] :: Typeable a => Type a -> Name -> Maybe [a] -> Expr a [Op1] :: Typeable a => Op1 a b -> Expr a -> Expr b [Op2] :: (Typeable a, Typeable b) => Op2 a b c -> Expr a -> Expr b -> Expr c [Op3] :: (Typeable a, Typeable b, Typeable c) => Op3 a b c d -> Expr a -> Expr b -> Expr c -> Expr d [Label] :: Typeable a => Type a -> String -> Expr a -> Expr a -- | A untyped expression that carries the information about the type of -- the expression as a value, as opposed to exposing it at type level -- (using an existential). data UExpr UExpr :: Type a -> Expr a -> UExpr [uExprType] :: UExpr -> Type a [uExprExpr] :: UExpr -> Expr a -- | An index for the drop operator. type DropIdx = Word32 -- | Copilot specifications constitute the main declaration of Copilot -- modules. -- -- A specification normally contains the association between streams to -- monitor and their handling functions, or streams to observe, or a -- theorem that must be proved. -- -- In order to be executed, high-level Copilot Language Spec must be -- turned into Copilot Core's Spec. This module defines the -- low-level Copilot Core representations for Specs and the main types of -- element in a spec.. module Copilot.Core.Spec -- | A stream in an infinite succession of values of the same type. -- -- Stream can carry different types of data. Boolean streams play a -- special role: they are used by other parts (e.g., Trigger) to -- detect when the properties being monitored are violated. data Stream Stream :: Id -> [a] -> Expr a -> Type a -> Stream [streamId] :: Stream -> Id [streamBuffer] :: Stream -> [a] [streamExpr] :: Stream -> Expr a [streamExprType] :: Stream -> Type a -- | An observer, representing a stream that we observe during -- interpretation at every sample. data Observer Observer :: Name -> Expr a -> Type a -> Observer [observerName] :: Observer -> Name [observerExpr] :: Observer -> Expr a [observerExprType] :: Observer -> Type a -- | A trigger, representing a function we execute when a boolean stream -- becomes true at a sample. data Trigger Trigger :: Name -> Expr Bool -> [UExpr] -> Trigger [triggerName] :: Trigger -> Name [triggerGuard] :: Trigger -> Expr Bool [triggerArgs] :: Trigger -> [UExpr] -- | A Copilot specification is a list of streams, together with monitors -- on these streams implemented as observers, triggers or properties. data Spec Spec :: [Stream] -> [Observer] -> [Trigger] -> [Property] -> Spec [specStreams] :: Spec -> [Stream] [specObservers] :: Spec -> [Observer] [specTriggers] :: Spec -> [Trigger] [specProperties] :: Spec -> [Property] -- | A property, representing a boolean stream that is existentially or -- universally quantified over time. data Property Property :: Name -> Expr Bool -> Property [propertyName] :: Property -> Name [propertyExpr] :: Property -> Expr Bool -- | The following articles might also be useful: -- -- -- -- For examples of how to traverse a Copilot specification see the source -- code of the interpreter (copilot-interpreter) and the -- pretty-printer (copilot-prettyprinter). module Copilot.Core