From 3cb552371037dee8e75ef1b05e39e7b3c9ed5f92 Mon Sep 17 00:00:00 2001 From: Edwin Brady Date: Thu, 13 Jan 2011 14:46:06 +0000 Subject: [PATCH] Add malloc_ to Epic interface --- Epic/Epic.lhs | 10 ++++++++++ Papers/Epic/implementation.tex | 16 ++++++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 Papers/Epic/implementation.tex diff --git a/Epic/Epic.lhs b/Epic/Epic.lhs index 15a8e73..e377981 100644 --- a/Epic/Epic.lhs +++ b/Epic/Epic.lhs @@ -21,6 +21,7 @@ > foreign_, foreignL_, foreignConst_, foreignConstL_, > let_, letN_, update_, op_, > str, int, float, char, bool, unit_, (!.), fn, ref, (+>), +> malloc_, > -- * Types > Type, tyInt, tyChar, tyBool, tyFloat, tyString, > tyPtr, tyUnit, tyAny, tyC, @@ -262,6 +263,15 @@ Remaining expression constructs > foreignConst_ t str = term $ ForeignCall t str [] > foreignConstL_ t str = term $ LazyForeignCall t str [] +> -- | 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. +> malloc_ :: (EpicExpr a, EpicExpr b) => +> a -- ^ Size of block to allocate +> -> b -- ^ Expression to evaluate +> -> Term +> malloc_ = exp2 (WithMem FixedPool) + mkCon :: Int -> [Term] -> Term mkCon tag args = do args' <- mapM expr args return (Con tag args') diff --git a/Papers/Epic/implementation.tex b/Papers/Epic/implementation.tex new file mode 100644 index 0000000..c857c4d --- /dev/null +++ b/Papers/Epic/implementation.tex @@ -0,0 +1,16 @@ +\section{Implementation} + +How it's implemented is not really important to the user --- a +compiler can target Epic without knowing, and we could drop in a new +back end at any time in principle. + +There is currently one back end, but more are planned. Compiled via +C. Garbage collection with Boehm~\cite{boehm-gc}, +\texttt{\%memory}. (Note that a non-moving collector makes things +easier for foreign functions, but may not be the best choice in the +long run). + +Later plans: compile via LLVM, allow plug in garbage collectors +(important for embedded systems, device drivers, operating system +services, for example). +