Epic

Epic is a simple functional language which compiles to reasonably efficient C code. The primary aim is to develop a back end for Epigram, but it will (I hope, eventually) be useful to anyone looking for a back end for a functional language. It is currently used as a back end for Idris.

Programs consist of a number of supercombinator definitions, e.g. the canonical factorial example or this list program. The main function is evaluated when the program is run. Some important language features to note:

  • Strict semantics by default, with lazy annotation if that’s what you need.
  • No semantic checking, other than to see if names are in scope — it is assumed that the higher level language will have performed typechecking, and in any case Epic should make no assumptions about the higher level type system or any transformations you’ve applied.
  • Further to the above, if you get a segmentation fault, it might be an error in my code, but it might also be a type error. I may add a debug mode with dynamic checking to help here.
  • Data types are introduced with an explicit constructor tag; e.g. Con 2 (x,y,z) is a constructor taking three arguments, with tag 2.
  • There is a rudimentary foreign function interface, allowing calls to external C functions. Foreign functions can have side effects, and it is assumed that you’ve set things up so that they evaluate in the right order… see this program for a simple example.
  • ';' is a sequencing operator, for sequencing side effecting expressions.
  • Primitive types Int, Float, BigInt,BigFloat, Char and String, although only Int, BigInt and String work so far; comparison operators
    work on Int.

Where to get it

Epic is available either through the repository on github, or from hackage with the usual warnings about research quality code, etc:

You’ll need an up to date GHC, happy, the Boehm garbage collector library and the GNU MP arithmetic library. You’ll also need gcc, since the compiler outputs C code.

Documentation

There is a paper describing the language and its Haskell API.

The command line tool, epic takes a source file and produces executable code, via C. Separate compilation is supported, in a fairly simple way, e.g. to compile a main program main.e which includes some functions defined in lib.e:

  • Build lib.o with the command epic -c lib.e.
  • Import functions in main.e with the line include "lib.ei" in the source.
  • Build the executable with epic main.e lib.o -o main