Copyright | Edwin Brady |
---|---|
License | BSD-style (see LICENSE in the distribution) |
Maintainer | eb@cs.st-andrews.ac.uk |
Stability | experimental |
Portability | non-portable |
Safe Haskell | None |
Language | Haskell98 |
Epic.Epic
Contents
Description
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_ :: EpicExpr e => Type -> String -> [(e, Type)] -> Term
- foreignL_ :: EpicExpr e => Type -> String -> [(e, Type)] -> Term
- foreignConst_ :: Type -> String -> Term
- 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
- bigint :: Integer -> 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
- mallocTrace_ :: EpicExpr a => a -> Term
- data Type
- tyInt :: Type
- tyBigInt :: Type
- tyChar :: Type
- tyBool :: Type
- tyFloat :: Type
- tyString :: Type
- tyPtr :: Type
- tyUnit :: Type
- tyAny :: Type
- tyC :: String -> Type
- data Op
- plus_ :: Op
- minus_ :: Op
- times_ :: Op
- divide_ :: Op
- plusF_ :: Op
- minusF_ :: Op
- timesF_ :: Op
- divideF_ :: Op
- eq_ :: Op
- lt_ :: Op
- lte_ :: Op
- gt_ :: Op
- gte_ :: Op
- eqF_ :: Op
- ltF_ :: Op
- lteF_ :: Op
- gtF_ :: Op
- gteF_ :: Op
- shiftl_ :: Op
- shiftr_ :: 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
- basic_defs :: [EpicDecl]
Expressions
class EpicExpr e where
Build expressions, with a name supply
class Alternative e
Build a case alternative, with a name supply
Minimal complete definition
mkAlt
Instances
Alternative Expr | |
Alternative Term | |
Alternative e => Alternative (Expr -> e) | |
Alternative e => Alternative ([Name], e) |
data Expr
data Name
case_ :: EpicExpr e => e -> [State Int CaseAlt] -> Term
Build a case expression with a list of alternatives
Arguments
:: Alternative e | |
=> Int | the tag |
-> e | RHS of alternative |
-> State Int CaseAlt |
Case alternative for constructor with the given tag
Arguments
:: 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 CaseAlt
Default case if no other branches apply
While loops (primitive, for efficiency).
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
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.
foreignConst_ :: Type -> String -> Term
foreignConstL_ :: Type -> String -> Term
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
.
(!.) infixl 5
Project an argument from an expression which evaluates to constructor form.
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.
Evaluate an expression under garbage collected memory, and output how much was allocated during evaluation.
Types
Operators
Declarations and programs
data EpicDecl
Top level declarations
data Program
Compiling and execution
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
.
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