Copyright | Justin Ethier |
---|---|
License | MIT (see LICENSE in the distribution) |
Maintainer | github.com/justinethier |
Stability | experimental |
Portability | portable |
Safe Haskell | None |
Language | Haskell98 |
This module contains a Scheme to Haskell compiler which performs the following transformations:
Scheme AST (LispVal) => Haskell AST (HaskAST) => Compiled Code (String)
The GHC compiler is then used to create a native executable. At present, the focus has just been on creating a compiler that will generate correct, working code. Many optimizations could and need to be made for time and space...
Note the following type is used for all functions generated by the compiler:
compiledFunc :: Env -> -- Runtime Environment LispVal -> -- Continuation LispVal -> -- Value Maybe [LispVal] -> -- Additional arguments IOThrowsError LispVal -- Result
- compile :: Env -> LispVal -> CompOpts -> IOThrowsError [HaskAST]
- compileApply :: Env -> LispVal -> CompOpts -> IOThrowsError [HaskAST]
- compileBlock :: String -> Maybe String -> Env -> [HaskAST] -> [LispVal] -> IOThrowsError [HaskAST]
- compileDivertedVars :: String -> Env -> [LispVal] -> CompOpts -> IOThrowsError HaskAST
- compileExpr :: Env -> LispVal -> String -> Maybe String -> IOThrowsError [HaskAST]
- compileLambdaList :: [LispVal] -> IOThrowsError String
- compileLisp :: Env -> String -> String -> Maybe String -> IOThrowsError [HaskAST]
- compileScalar :: String -> CompOpts -> IOThrowsError [HaskAST]
- compileSpecialForm :: String -> String -> CompOpts -> IOThrowsError HaskAST
- compileSpecialFormBody :: Env -> LispVal -> CompOpts -> (Maybe String -> ErrorT LispError IO [HaskAST]) -> ErrorT LispError IO [HaskAST]
- compileSpecialFormEntryPoint :: String -> String -> CompOpts -> IOThrowsError HaskAST
- defineLambdaVars :: Env -> [LispVal] -> IOThrowsError LispVal
- defineTopLevelVars :: Env -> [LispVal] -> IOThrowsError LispVal
- divertVars :: Env -> LispVal -> CompOpts -> (Env -> LispVal -> CompOpts -> IOThrowsError [HaskAST]) -> IOThrowsError [HaskAST]
- initializeCompiler :: Env -> IOThrowsError [HaskAST]
- isPrim :: Env -> LispVal -> IOThrowsError (Maybe LispVal)
- mcompile :: Env -> LispVal -> CompOpts -> IOThrowsError [HaskAST]
- mfunc :: Env -> LispVal -> (Env -> LispVal -> CompOpts -> IOThrowsError [HaskAST]) -> CompOpts -> IOThrowsError [HaskAST]
Documentation
compile :: Env -> LispVal -> CompOpts -> IOThrowsError [HaskAST] Source #
Compile a Lisp expression to Haskell. Note this function does not expand macros; mcompile should be used instead if macros may appear in the expression.
compileApply :: Env -> LispVal -> CompOpts -> IOThrowsError [HaskAST] Source #
Compile a function call
compileBlock :: String -> Maybe String -> Env -> [HaskAST] -> [LispVal] -> IOThrowsError [HaskAST] Source #
Compile a list (block) of Scheme code
compileDivertedVars :: String -> Env -> [LispVal] -> CompOpts -> IOThrowsError HaskAST Source #
Take a list of variables diverted into env at compile time, and divert them into the env at runtime
compileExpr :: Env -> LispVal -> String -> Maybe String -> IOThrowsError [HaskAST] Source #
Compile an intermediate expression (such as an arg to if) and call into the next continuation with it's value
compileLambdaList :: [LispVal] -> IOThrowsError String Source #
Compile the list of arguments for a function
:: Env | Compiler environment |
-> String | Filename |
-> String | Function entry point (code calls into this function) |
-> Maybe String | Function exit point, if any |
-> IOThrowsError [HaskAST] |
Compile a file containing scheme code
compileScalar :: String -> CompOpts -> IOThrowsError [HaskAST] Source #
Helper function to compile expressions consisting of a scalar
compileSpecialForm :: String -> String -> CompOpts -> IOThrowsError HaskAST Source #
Helper function for compiling a special form
compileSpecialFormBody :: Env -> LispVal -> CompOpts -> (Maybe String -> ErrorT LispError IO [HaskAST]) -> ErrorT LispError IO [HaskAST] Source #
A wrapper for each special form that allows the form variable (EG: "if") to be redefined at compile time
compileSpecialFormEntryPoint :: String -> String -> CompOpts -> IOThrowsError HaskAST Source #
Create the function entry point for a special form
defineLambdaVars :: Env -> [LispVal] -> IOThrowsError LispVal Source #
Add lambda variables to the compiler's environment
defineTopLevelVars :: Env -> [LispVal] -> IOThrowsError LispVal Source #
Find all variables defined at "this" level and load their symbols into the environment. This allows the compiler validation to work even though a variable is used in a sub-form before it is defined further on down in the program
:: Env | Current compile Environment |
-> LispVal | Lisp code after macro expansion |
-> CompOpts | Compiler options |
-> (Env -> LispVal -> CompOpts -> IOThrowsError [HaskAST]) | Continuation to call into after vars are diverted |
-> IOThrowsError [HaskAST] | Code generated by the continuation, along with the code added to divert vars to the compiled program |
Do the actual insertion of diverted variables back to the compiled program.
initializeCompiler :: Env -> IOThrowsError [HaskAST] Source #
Perform one-time initialization of the compiler's environment
isPrim :: Env -> LispVal -> IOThrowsError (Maybe LispVal) Source #
Determines if the given lispval is a primitive function