epic-0.9.3: Compiler for a simple functional language

Portabilitynon-portable
Stabilityexperimental
Maintainereb@cs.st-andrews.ac.uk
Safe HaskellNone

Epic.Epic

Contents

Description

Combinators for builing Epic programs

Synopsis

Expressions

class EpicExpr e where

Build expressions, with a name supply

Methods

term :: e -> State Int Expr

class EpicFn e

Build a function definition, with a name supply

Instances

EpicFn Expr 
EpicFn Term 
EpicFn e => EpicFn (Expr -> e) 
EpicFn e => EpicFn ([Name], e) 

class Alternative e

Build a case alternative, with a name supply

type Term = State Int Expr

A sub-term, with a name supply

data Name

Instances

Eq Name 
Show Name 
Alternative e => Alternative ([Name], e) 
EpicFn e => EpicFn ([Name], e) 
EpicExpr e => EpicExpr ([Name], e) 

(@@)

Arguments

:: (EpicExpr f, EpicExpr a) 
=> f

function

-> a

argument

-> Term 

Application

case_ :: EpicExpr e => e -> [State Int CaseAlt] -> Term

Build a case expression with a list of alternatives

con_

Arguments

:: Int

Tag

-> Term 

Build a constructor with the given tag

tuple_ :: Term

Build a tuple

con

Arguments

:: Alternative e 
=> Int

the tag

-> e

RHS of alternative

-> State Int CaseAlt 

Case alternative for constructor with the given tag

tuple

Arguments

:: Alternative e 
=> e

RHS of alternative

-> State Int CaseAlt 

Case alternative for a tuple with the given tag

constcase

Arguments

:: EpicExpr a 
=> Int

the constant

-> a 
-> State Int CaseAlt 

Case alternative for a constant

defaultcase :: EpicExpr a => a -> State Int CaseAlt

Default case if no other branches apply

if_ :: (EpicExpr a, EpicExpr t, EpicExpr e) => a -> t -> e -> Term

while_

Arguments

:: (EpicExpr t, EpicExpr b) 
=> t

Boolean test (most likely effectful)

-> b

Body

-> Term 

While loops (primitive, for efficiency).

whileAcc_

Arguments

:: (EpicExpr t, EpicExpr a, EpicExpr b) 
=> t

Boolean test (most likely effectful)

-> a

Accumulator (of type a)

-> b

Body (of type a -> a)

-> Term 

While loop, with an accumulator

lazy_ :: EpicExpr a => a -> Term

Evaluate an expression lazily

effect_ :: EpicExpr a => a -> Term

Evaluate an expression but don't update the closure with the result. | Use this if the expression has a side effect.

foreign_ :: EpicExpr e => Type -> String -> [(e, Type)] -> Term

foreignL_ :: EpicExpr e => Type -> String -> [(e, Type)] -> Term

let_ :: (LetExpr e, EpicExpr val) => val -> e -> State Int Expr

letN_ :: (EpicExpr val, EpicExpr scope) => Name -> val -> scope -> Term

Let bindings with an explicit name

update_ :: (EpicExpr val, EpicExpr scope) => Expr -> val -> scope -> Term

Update a local variable (could be an explicit name or bound with a lambda, so we let it be an Expr.

op_ :: (EpicExpr a, EpicExpr b) => Op -> a -> b -> Term

str :: String -> Term

Constant string

int :: Int -> Term

Constant integer

bigint :: Integer -> Term

Constant big integer

float :: Double -> Term

Constant float

char :: Char -> Term

Constant character

bool :: Bool -> Term

Constant bool

unit_ :: Term

Constructor for the unit type

(!.)

Arguments

:: EpicExpr t 
=> t

Expression in constructor form

-> Int

Argument number

-> Term 

Project an argument from an expression which evaluates to constructor form.

fn :: String -> Term

Reference to a function name

ref :: Name -> Term

Reference to a function name

(+>) :: EpicExpr c => c -> Term -> Term

Sequence terms --- evaluate the first then second

malloc_

Arguments

:: (EpicExpr a, EpicExpr b) 
=> a

Size of block to allocate

-> b

Expression to evaluate

-> Term 

Evaluate an expression under manually allocated memory. Creates a pool of memory. All allocation is from this pool, and there is no garbage collection. The pool is freed after evaluation.

mallocTrace_

Arguments

:: EpicExpr a 
=> a

Expression to evaluate

-> Term 

Evaluate an expression under garbage collected memory, and output how much was allocated during evaluation.

Types

data Type

Instances

Operators

data Op

Instances

eq_ :: Op

lt_ :: Op

lte_ :: Op

gt_ :: Op

gte_ :: Op

eqF_ :: Op

ltF_ :: Op

gtF_ :: Op

Declarations and programs

data EpicDecl

Top level declarations

Constructors

forall e . EpicFn e => EpicFn Name e

Normal function

EpicExt Name Int

Epic function defined in a separate .o

Include String

Include a C header

Link String

Link to a C library

CType String

Export a C type

Instances

data Program

Compiling and execution

compile :: Program -> FilePath -> IO ()

Compile a program to an executable

compileObj :: Program -> FilePath -> IO ()

Compile a program to a .o

link :: [FilePath] -> FilePath -> IO ()

Link a collection of object files. By convention, the entry point is the function called main.

compileWith :: [CompileOptions] -> Program -> FilePath -> IO ()

Compile a program to an executable, with options

compileObjWith :: [CompileOptions] -> Program -> FilePath -> IO ()

Compile a program to a .o, with options

linkWith :: [CompileOptions] -> [FilePath] -> FilePath -> IO ()

Link a collection of object files, with options. By convention, the entry point is the function called main.

run :: Program -> IO ()

evaluate :: EpicExpr e => Program -> e -> Expr

data CompileOptions

(Debugging) options to give to compiler

Constructors

KeepC

Keep intermediate C file

Trace

Generate trace at run-time (debug)

ShowBytecode

Show generated code

ShowParseTree

Show parse tree

MakeHeader FilePath

Output a .h file too

GCCOpt String

Extra GCC option

Debug

Generate debug info

Checking Int

Checking level (0 none)

ExternalMain

main is defined externally (in C)

MainInc FilePath

File to #include in main program

LinkObj FilePath

.o file to link with

Instances

Some basic definitions

basic_defs :: [EpicDecl]

Some default definitions: putStr, putStrLn, readStr, append, intToString