Portability | non-portable |
---|---|
Stability | experimental |
Maintainer | eb@cs.st-andrews.ac.uk |
Combinators for builing Epic programs
- class EpicExpr e where
- class EpicFn e
- class Alternative e
- data Expr
- type Term = State Int Expr
- data Name
- name :: String -> Name
- (@@) :: (EpicExpr f, EpicExpr a) => f -> a -> Term
- case_ :: EpicExpr e => e -> [State Int CaseAlt] -> Term
- con_ :: Int -> Term
- tuple_ :: Term
- con :: Alternative e => Int -> e -> State Int CaseAlt
- tuple :: Alternative e => e -> State Int CaseAlt
- constcase :: EpicExpr a => Int -> a -> State Int CaseAlt
- defaultcase :: EpicExpr a => a -> State Int CaseAlt
- if_ :: (EpicExpr a, EpicExpr t, EpicExpr e) => a -> t -> e -> Term
- while_ :: (EpicExpr t, EpicExpr b) => t -> b -> Term
- whileAcc_ :: (EpicExpr t, EpicExpr a, EpicExpr b) => t -> a -> b -> Term
- error_ :: String -> Term
- lazy_ :: EpicExpr a => a -> Term
- effect_ :: EpicExpr a => a -> Term
- foreign_, foreignL_ :: EpicExpr e => Type -> String -> [(e, Type)] -> Term
- foreignConst_, foreignConstL_ :: Type -> String -> Term
- let_ :: (LetExpr e, EpicExpr val) => val -> e -> State Int Expr
- letN_ :: (EpicExpr val, EpicExpr scope) => Name -> val -> scope -> Term
- update_ :: (EpicExpr val, EpicExpr scope) => Expr -> val -> scope -> Term
- op_ :: (EpicExpr a, EpicExpr b) => Op -> a -> b -> Term
- str :: String -> Term
- int :: Int -> Term
- float :: Double -> Term
- char :: Char -> Term
- bool :: Bool -> Term
- unit_ :: Term
- (!.) :: EpicExpr t => t -> Int -> Term
- fn :: String -> Term
- ref :: Name -> Term
- (+>) :: EpicExpr c => c -> Term -> Term
- malloc_ :: (EpicExpr a, EpicExpr b) => a -> b -> Term
- data Type
- tyInt, tyAny, tyUnit, tyPtr, tyString, tyFloat, tyBool, tyChar :: Type
- tyC :: String -> Type
- data Op
- plus_, divideF_, timesF_, minusF_, plusF_, divide_, times_, minus_ :: Op
- eq_ :: Op
- lt_, shiftr_, shiftl_, gteF_, gtF_, lteF_, ltF_, gte_, gt_, lte_ :: Op
- eqF_ :: Op
- data EpicDecl
- data Program
- mkProgram :: [EpicDecl] -> Program
- compile :: Program -> FilePath -> IO ()
- compileObj :: Program -> FilePath -> IO ()
- link :: [FilePath] -> FilePath -> IO ()
- compileWith :: [CompileOptions] -> Program -> FilePath -> IO ()
- compileObjWith :: [CompileOptions] -> Program -> FilePath -> IO ()
- linkWith :: [CompileOptions] -> [FilePath] -> FilePath -> IO ()
- run :: Program -> IO ()
- evaluate :: EpicExpr e => Program -> e -> Expr
- data CompileOptions
- = KeepC
- | Trace
- | ShowBytecode
- | ShowParseTree
- | MakeHeader FilePath
- | GCCOpt String
- | Debug
- | Checking Int
- | ExternalMain
- | MainInc FilePath
- | LinkObj FilePath
- basic_defs :: [EpicDecl]
Expressions
Build expressions, with a name supply
Build a function definition, with a name supply
class Alternative e Source
Build a case alternative, with a name supply
Alternative Expr | |
Alternative Term | |
Alternative e => Alternative (Expr -> e) | |
Alternative e => Alternative ([Name], e) |
Eq Expr | |
Show Expr | |
Show Term | |
SubstV Expr | |
Quote Expr | |
RtoV Expr | |
Alternative Expr | |
Alternative Term | |
EpicFn Expr | |
EpicFn Term | |
EpicExpr Expr | |
EpicExpr Term | |
HOAS Func Expr | |
HOAS Expr Expr | |
Eq (Expr -> HRHS) | |
Eq (Expr -> Expr) | |
SubstV (Expr, Type) | |
LetExpr (Expr -> Term) | |
Alternative e => Alternative (Expr -> e) | |
EpicFn e => EpicFn (Expr -> e) | |
EpicExpr e => EpicExpr (Expr -> e) |
case_ :: EpicExpr e => e -> [State Int CaseAlt] -> TermSource
Build a case expression with a list of alternatives
:: Alternative e | |
=> Int | the tag |
-> e | RHS of alternative |
-> State Int CaseAlt |
Case alternative for constructor with the given tag
:: Alternative e | |
=> e | RHS of alternative |
-> State Int CaseAlt |
Case alternative for a tuple with the given tag
Case alternative for a constant
defaultcase :: EpicExpr a => a -> State Int CaseAltSource
Default case if no other branches apply
While loops (primitive, for efficiency).
:: (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
effect_ :: EpicExpr a => a -> TermSource
Evaluate an expression but don't update the closure with the result. | Use this if the expression has a side effect.
foreignConst_, foreignConstL_ :: Type -> String -> TermSource
letN_ :: (EpicExpr val, EpicExpr scope) => Name -> val -> scope -> TermSource
Let bindings with an explicit name
update_ :: (EpicExpr val, EpicExpr scope) => Expr -> val -> scope -> TermSource
Update a local variable (could be an explicit name or bound with
a lambda, so we let it be an Expr
.
Project an argument from an expression which evaluates to constructor form.
(+>) :: EpicExpr c => c -> Term -> TermSource
Constructor for the unit type
Sequence terms --- evaluate the first then second
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.
Types
Operators
Declarations and programs
Top level declarations
Compiling and execution
link :: [FilePath] -> FilePath -> IO ()Source
Link a collection of object files. By convention, the entry point is
the function called main
.
compileWith :: [CompileOptions] -> Program -> FilePath -> IO ()Source
Compile a program to an executable, with options
compileObjWith :: [CompileOptions] -> Program -> FilePath -> IO ()Source
Compile a program to a .o, with options
linkWith :: [CompileOptions] -> [FilePath] -> FilePath -> IO ()Source
Link a collection of object files, with options. By convention,
the entry point is the function called main
.
data CompileOptions Source
(Debugging) options to give to compiler
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 |
Some basic definitions
basic_defs :: [EpicDecl]Source
Some default definitions: putStr, putStrLn, readStr, append, intToString