copilot: A stream DSL for writing embedded C programs.

[ bsd3, embedded, language, library ] [ Propose Tags ]

Copilot is a stream-based runtime verification framework implemented as an embedded domain-specific language (EDSL) in Haskell. Programs can be interpreted for testing, or translated into C99 code to be incorporated in a project, or as a standalone application. The C99 backend output is constant in memory and time, making it suitable for systems with hard realtime requirements.

This package is the main entry-point for using Copilot.

A tutorial, examples, and other information are available at https://copilot-language.github.io.


[Skip to Readme]

Flags

Manual Flags

NameDescriptionDefault
examples

Enable examples

Disabled

Use -f <flag> to enable a flag, or -f -<flag> to disable that flag. More info

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

  • No Candidates
Versions [RSS] 0.21, 0.22, 0.23, 0.25, 0.26, 0.27, 0.28, 1.0, 1.0.1, 1.0.2, 2.0, 2.0.1, 2.0.2, 2.0.3, 2.0.4, 2.0.5, 2.0.6, 2.0.7, 2.0.8, 2.0.9, 2.1.0, 2.1.1, 2.1.2, 2.2.0, 2.2.1, 3.0, 3.0.1, 3.1, 3.2, 3.2.1, 3.3, 3.4, 3.5, 3.6, 3.7, 3.8, 3.9, 3.10, 3.11, 3.12, 3.13, 3.14, 3.15, 3.16, 3.16.1, 3.17, 3.18, 3.18.1, 3.19
Change log CHANGELOG
Dependencies base (>=4.9 && <5), copilot, copilot-c99 (>=3.19 && <3.20), copilot-core (>=3.19 && <3.20), copilot-language (>=3.19 && <3.20), copilot-libraries (>=3.19 && <3.20), copilot-prettyprinter (>=3.19 && <3.20), copilot-theorem (>=3.19 && <3.20), directory (>=1.3 && <1.4), filepath (>=1.4 && <1.5), optparse-applicative (>=0.14 && <0.19) [details]
License BSD-3-Clause
Author Frank Dedden, Nis Nordby Wegmann, Lee Pike, Robin Morisset, Sebastian Niller, Alwyn Goodloe, Ivan Perez
Maintainer Ivan Perez <ivan.perezdominguez@nasa.gov>
Category Language, Embedded
Home page https://copilot-language.github.io
Bug tracker https://github.com/Copilot-Language/copilot/issues
Source repo head: git clone https://github.com/Copilot-Language/copilot.git(copilot)
Uploaded by IvanPerez at 2024-03-08T09:07:47Z
Distributions
Reverse Dependencies 6 direct, 0 indirect [details]
Executables voting, structs, heater, engine, counter, clock, cast, array, addmult, wcv, what4-structs, what4-arithmetic, what4-propositional
Downloads 26746 total (106 in the last 30 days)
Rating 2.0 (votes: 1) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs available [build log]
Last success reported on 2024-03-08 [all 1 reports]

Readme for copilot-3.19

[back to package description]

Copilot

Build Status Version on Hackage

Copilot is a runtime verification framework for hard real-time systems. Programs can be interpreted for testing, or translated into C99 code to be incorporated in a project or standalone application. The C99 code generated is constant in memory and time, making it suitable for systems with hard real-time requirements.

InstallationExamplesRelated projectsDocumentationContributionsAcknowledgements

Features

  • Write simple, high-level specifications using a stream-based language.

  • Produce hard real-time C99 runtime monitors that run in constant memory and time.

  • Catch errors in specifications early using expressive static type system.

  • Prove properties about specifications using theorem proving extensions.

  • Interpret specifications for testing and debugging purposes.

  • Obtain proofs of correctness of the generated code.

Table of Contents

Installation

(Back to top)

Linux installation

(Back to top)

Debian Bookworm / Ubuntu 23.04

On Debian Bookworm / Ubuntu 23.04 or newer, Copilot can be installed directly from the package repositories with:

$ sudo apt-get install libghc-copilot-dev

To test that Copilot is available, execute the following:

$ ghci <<< 'import Language.Copilot'

It should end with a line like the following and not print any error messages:

ghci> ghci> Leaving GHCi.

Other Linux distributions

On other Linux distributions or older Debian-based distributions, to use Copilot you must install a Haskell compiler (GHC) and the package manager Cabal. We currently support all versions of GHC from 8.6.5 to modern versions (9.6 as of this writing). You can install the toolchain using ghcup or, if you are on Debian/Ubuntu, directly with apt-get:

$ sudo apt-get install ghc cabal-install

Once the compiler is installed, install Copilot from Hackage with:

cabal v2-install --lib copilot

To test that Copilot is available, execute the following:

$ ghci <<< 'import Language.Copilot'

It should end with a line like the following and not print any error messages:

ghci> ghci> Leaving GHCi.

Mac installation

(Back to top)

To use Copilot you must have a Haskell compiler (GHC) and the package manager Cabal. We currently support all versions of GHC from 8.6.5 to modern versions (9.6 as of this writing). You can install the toolchain using ghcup, as well as with Homebrew:

$ brew install ghc cabal-install

Once the compiler is installed, install Copilot from Hackage with:

$ cabal v2-install --lib copilot

To test that Copilot is available, execute the following:

$ ghci <<< 'import Language.Copilot'

It should end with a line like the following and not print any error messages:

ghci> ghci> Leaving GHCi.

Troubleshooting

(Back to top)

Feel free to open an issue if you are unable to install Copilot following these instructions.

There is a TravisCI file at the root of the repository that may help with troubleshooting the installation. Our issues often include comments with Dockerfiles listing the steps necessary to install Copilot from scratch.

Examples

(Back to top)

Here follows a simple example of a heating system. More examples can be found in the examples directory of the main repository.

-- This example implements a simple home heating system. The system heats
-- when the temperature gets too low, and stops when it is high enough. It read
-- temperature as a byte (range -50C to 100C) and translates this to Celsius.

module Heater where

import Language.Copilot
import Copilot.Compile.C99

import Prelude hiding ((>), (<), div)

-- External temperature as a byte, ranging from -50C to 100C.
temp :: Stream Word8
temp = extern "temperature" Nothing

-- Temperature in Celsius.
--
-- We need to cast the Word8 to a Float. This is an unsafeCast, as there
-- is no direct relation between Word8 and Float.
ctemp :: Stream Float
ctemp = (unsafeCast temp) * (150.0 / 255.0) - 50.0

spec = do
  -- Triggers that fire when the ctemp is too low or too high,
  -- pass the current ctemp as an argument.
  trigger "heaton"  (ctemp < 18.0) [arg ctemp]
  trigger "heatoff" (ctemp > 21.0) [arg ctemp]

-- Compile the spec
main = reify spec >>= compile "heater"

If you save this example in a file Heater.hs and run:

$ runhaskell Heater.hs

it will produce the files heater.c, heater.h and heater_types.h, containing, respectively, the implementation of the monitors, the interface, and a declaration of any types declared in the specification (empty in this case).

If you clone the repository, the examples in the examples/ directory can be run from the root of the project. As a rule of thumb, each example is named after the filename (without extension) in lowercase letters, and directory separators replaced with a '-'. For example:

$ cabal run addmult -f examples
$ cabal run counter -f examples
$ cabal run what4-arithmetic -f examples

Related projects

(Back to top)

Disclaimer: The following projects are not part of Copilot. Their mention here does not constitute any form of endorsement.

  • Ogma is a NASA tool to facilitate the integration of safe runtime monitors into other systems, including those built using NASA's Core Flight System or the Robot Operating System (ROS 2).

  • arduino-copilot facilitates building copilot applications that run on Arduino.

  • sketch-frp-copilot extends Copilot with an FRP-like interface.

  • zephyr-copilot facilitates building copilot applications that run on boards supported by the Zephyr project.

Documentation

(Back to top)

API documentation and tutorials

(Back to top)

A tutorial on Copilot can be found here.

The API is documented throughout the different libraries and published on Hackage:

Publications

(Back to top)

The best introduction to the fundamentals of Copilot apart from the tutorial is:

Other relevant papers include:

Website

(Back to top)

For further information, including links to more documentation and the tutorial, please visit the Copilot website: https://copilot-language.github.io.

Contributions

(Back to top)

Copilot cannot accept pull requests or code contributions from developers outside the development team at this point.

If you have a question, find a bug, or would like to request a change, please file an issue adding as much information as you can to help us reproduce the error or identify the use case. Please file the issue with no labels.

Acknowledgements

(Back to top)

The Copilot team

(Back to top)

Copilot is currently maintained by:

  • Alwyn Goodloe
  • Ivan Perez

Past and current team members also include (in alphabetical order):

  • Macallan Cruff
  • Frank Dedden
  • Chris Hathhorn
  • Georges-Axel Jolayan
  • Jonathan Laurent
  • Eli Mendelson
  • Robin Morisset
  • Sebastian Niller
  • Lauren Pick
  • Lee Pike
  • Will Pogge
  • Ryan Spring
  • Laura Titolo
  • Nis Wegmann

For a complete list of contributors, including external contributors, see: https://github.com/Copilot-Language/copilot/graphs/contributors

Institutional support

(Back to top)

We are grateful for NASA Contract NNL08AD13T to Galois, Inc. and the National Institute of Aerospace, which partially supported this work.

Additionally NASA Langley contracts 80LARC17C0004 and NNL09AA00A supported further development of Copilot.