Permalink
Browse files

Make EpicDecl a bit neater (no need for names on include/link/etc)

  • Loading branch information...
1 parent b39a3f4 commit 0d3f43284ba28006ed1d4b8b3dad9ebaa8f35a41 Edwin Brady committed Jan 13, 2011
Showing with 52 additions and 52 deletions.
  1. +1 −1 Atuin/atuin.cabal
  2. +5 −5 Atuin/src/MkEpic.lhs
  3. +11 −11 Atuin/src/SDLprims.lhs
  4. +14 −13 Epic/Epic.lhs
  5. +2 −1 FL/fl.cabal
  6. +2 −9 FL/src/Lang.lhs
  7. +1 −1 FL/src/Main.lhs
  8. +4 −5 Papers/Epic/example.tex
  9. +11 −5 Papers/Epic/language.tex
  10. +1 −1 epic.cabal
View
@@ -23,4 +23,4 @@ Executable atuin
hs-source-dirs: src
Other-modules: Turtle MkEpic SDLprims Lexer Parser Paths_atuin
Build-depends: base >=4 && <5, haskell98, Cabal, array,
- directory, epic
+ directory, epic >=0.1.10
View
@@ -128,9 +128,9 @@ Convert a function with arguments into an Epic definition. We have the
arguments in the definition, plus an additional state added by the system
which carries the turtle state and SDL surface.
-> mkEpic :: (Id, Function) -> (Name, EpicDecl)
+> mkEpic :: (Id, Function) -> EpicDecl
> mkEpic (i, (args, p))
-> = (epicId i, EpicFn (\ state -> (map epicId args, compile state p)))
+> = EpicFn (epicId i) (\ state -> (map epicId args, compile state p))
Epic main program - initialises SDL, sets up an initial turtle state,
runs the program called "main" and waits for a key press.
@@ -151,9 +151,9 @@ with the primitives (from SDLprims) and the user's program.
> sdlo <- getDataFileName "sdl/sdlrun.o"
> sdlh <- getDataFileName "sdl/sdlrun.h"
> let eprog = map mkEpic prog
-> let incs = [(name "hdr", Include sdlh),
-> (name "hdr", Include "math.h")]
+> let incs = [Include sdlh,
+> Include "math.h"]
> compileObj (incs ++ sdlPrims ++
-> (name "main", EpicFn runMain):eprog)
+> EpicFn (name "main") runMain : eprog)
> (fp++".o")
> linkWith opts [fp++".o", sdlo] fp
View
@@ -186,14 +186,14 @@ the user direct access to this tuple.
Export the primitives as Epic functions.
> sdlPrims = basic_defs ++
-> [(name "initSDL", EpicFn initSDL),
-> (name "pollEvent", EpicFn pollEvent),
-> (name "flipBuffers", EpicFn flipBuffers),
-> (name "drawLine", EpicFn drawLine),
-> (name "forward", EpicFn forward),
-> (name "left", EpicFn left),
-> (name "right", EpicFn right),
-> (name "colour", EpicFn colour),
-> (name "pen", EpicFn pen),
-> (name "repeat", EpicFn primRepeat),
-> (name "pressAnyKey", EpicFn pressAnyKey)]
+> [EpicFn (name "initSDL") initSDL,
+> EpicFn (name "pollEvent") pollEvent,
+> EpicFn (name "flipBuffers") flipBuffers,
+> EpicFn (name "drawLine") drawLine,
+> EpicFn (name "forward") forward,
+> EpicFn (name "left") left,
+> EpicFn (name "right") right,
+> EpicFn (name "colour") colour,
+> EpicFn (name "pen") pen,
+> EpicFn (name "repeat") primRepeat,
+> EpicFn (name "pressAnyKey") pressAnyKey]
View
@@ -410,25 +410,25 @@ Remaining expression constructs
> _ -> return $ App f' [a']
> -- | Top level declarations
-> data EpicDecl = forall e. EpicFn e => EpicFn e -- ^ Normal function
+> data EpicDecl = forall e. EpicFn e => EpicFn Name e -- ^ Normal function
> | Include String -- ^ Include a C header
> | Link String -- ^ Link to a C library
> | CType String -- ^ Export a C type
> instance Show EpicDecl where
-> show (EpicFn e) = show (evalState (func e) 0)
+> show (EpicFn n e) = show (n, evalState (func e) 0)
-> type Program = [(Name, EpicDecl)]
+> type Program = [EpicDecl]
> name :: String -> Name
> name = UN
-> mkDecl :: (Name, EpicDecl) -> Decl
-> mkDecl (n, EpicFn e) = Decl n TyAny (mkFunc e) Nothing []
+> mkDecl :: EpicDecl -> Decl
+> mkDecl (EpicFn n e) = Decl n TyAny (mkFunc e) Nothing []
> -- mkDecl (n, Epic.Epic.Extern nm ty tys) = Epic.Language.Extern nm ty tys
-> mkDecl (n, Epic.Epic.Include f) = Epic.Language.Include f
-> mkDecl (n, Epic.Epic.Link f) = Epic.Language.Link f
-> mkDecl (n, Epic.Epic.CType f) = Epic.Language.CType f
+> mkDecl (Epic.Epic.Include f) = Epic.Language.Include f
+> mkDecl (Epic.Epic.Link f) = Epic.Language.Link f
+> mkDecl (Epic.Epic.CType f) = Epic.Language.CType f
> -- |Compile a program to an executable
> compile :: Program -> FilePath -> IO ()
@@ -484,9 +484,10 @@ Some useful functions
> intToString_ x = foreign_ tyString "intToStr" [(x, tyInt)]
> -- | Some default definitions: putStr, putStrLn, readStr, append, intToString
-> basic_defs = [(name "putStr", EpicFn putStr_),
-> (name "putStrLn", EpicFn putStrLn_),
-> (name "readStr", EpicFn readStr_),
-> (name "append", EpicFn append_),
-> (name "intToString", EpicFn intToString_)]
+> basic_defs :: [EpicDecl]
+> basic_defs = [EpicFn (name "putStr") putStr_,
+> EpicFn (name "putStrLn") putStrLn_,
+> EpicFn (name "readStr") readStr_,
+> EpicFn (name "append") append_,
+> EpicFn (name "intToString") intToString_]
View
@@ -18,4 +18,5 @@ Executable fl
Main-is: Main.lhs
hs-source-dirs: src
Other-modules: Lang
- Build-depends: base >=4 && <5, haskell98, Cabal, directory, epic
+ Build-depends: base >=4 && <5, haskell98, Cabal, directory,
+ epic >=0.1.10
View
@@ -17,10 +17,7 @@
> data Infix = Plus | Minus | Times | Divide | Append
> | Equal | Lt | Gt
-> data Def = LangDef Lang
-> | PrimDef EpicDecl
-
-> type Defs = [(Name, Def)]
+> type Defs = [(Name, Lang)]
> build :: Lang -> Term
> build (Lam f) = term (\x -> build (f (EpicRef x)))
@@ -39,12 +36,8 @@
> buildOp Lt = lt_
> buildOp Gt = gt_
-> mkEpic :: Def -> EpicDecl
-> mkEpic (PrimDef p) = p
-> mkEpic (LangDef l) = EpicFn (build l)
-
> mkProgram :: Defs -> Program
-> mkProgram ds = basic_defs ++ map (\ (n, d) -> (n, mkEpic d)) ds
+> mkProgram ds = basic_defs ++ map (\ (n, d) -> EpicFn n (build d)) ds
> execute :: Defs -> IO ()
> execute p = run (mkProgram p)
View
@@ -13,6 +13,6 @@
> (App (App (Ref (name "add"))
> (Const (CInt 5))) (Const (CInt 6))))
-> testdefs = [(name "add", LangDef add), (name "main", LangDef main_)]
+> testdefs = [(name "add", add), (name "main", main_)]
> main = execute testdefs
View
@@ -93,10 +93,10 @@ \subsubsection{Compilation}
\begin{SaveVerbatim}{eprogs}
-data EpicDecl = forall e. EpicFn e => EpicFn e
+data EpicDecl = forall e. EpicFn e => EpicFn Name e
| ...
-type Program = [(Name, EpicDecl)]
+type Program = [EpicDecl]
\end{SaveVerbatim}
\useverb{eprogs}
@@ -110,7 +110,7 @@ \subsubsection{Compilation}
\begin{SaveVerbatim}{bdefs}
-basic_defs :: [(Name, EpicDecl)]
+basic_defs :: [EpicDecl]
\end{SaveVerbatim}
\useverb{bdefs}
@@ -208,8 +208,7 @@ \subsubsection{Compilation}
mkProgram :: Defs -> Program
mkProgram ds = basic_defs ++
- map (\ (n, d) ->
- (n, EpicFn (build d))) ds
+ map (\ (n, d) -> EpicFn n (build d)) ds
execute :: Defs -> IO ()
execute p = run (mkProgram p)
View
@@ -1,14 +1,17 @@
\section{The Epic Language}
-Epic is an untyped $\lambda$-calculus with algebraic data types.
-There are additional control structures for specifying evaluation
-order, primitive loop constructs, and calling foreign
+Epic is based on the untyped $\lambda$-calculus with some extensions.
+It supports primitives such as strings and integers, as well as tagged
+unions. There are additional control structures for specifying
+evaluation order, primitive loop constructs, and calling foreign
functions. Foreign function calls are annotated with types, to assist
-with marshaling data between Epic and C, but otherwise there are no
+with marshaling values between Epic and C, but otherwise there are no
type annotations and there is no type checking --- as Epic is intended
as an intermediate language, it is assumed that the high level
language has already performed any necessary type checking. The
abstract syntax of the core language is given in Figure \ref{epicsyn}.
+As a shorthand, we use de Bruijn telescope notation, $\tx$, to denote
+a sequence of $\vx$.
\newcommand{\Con}[2]{\DC{Con}\:#1(#2)}
@@ -21,7 +24,7 @@ \section{The Epic Language}
\\
\vt & ::= & \vx & \mbox{(Variable)} \\
& \mid & \vt(\ttt) & \mbox{(Function application)} \\
-& \mid & \lambda\:\vx\SC\vt & \mbox{(Lambda binding)} \\
+& \mid & \lambda\vx\SC\vt & \mbox{(Lambda binding)} \\
& \mid & \RW{let}\:\vx\:=\:\vt\:\RW{in}\:\vt & \mbox{(Let
binding)} \\
& \mid & \Con{\vi}{\ttt} & \mbox{(Constructor application)} \\
@@ -76,6 +79,9 @@ \section{The Epic Language}
\subsection{Definitions}
+An Epic program consists of a sequence of \remph{untyped} function
+definitions, with zero or more arguments,
+
Expressions. \texttt{let}, \texttt{case}, \texttt{lazy}
\subsection{Types}
View
@@ -1,5 +1,5 @@
Name: epic
-Version: 0.1.9
+Version: 0.1.10
Author: Edwin Brady
License: BSD3
License-file: LICENSE

0 comments on commit 0d3f432

Please sign in to comment.