Portability | portable |
---|---|
Stability | experimental |
Maintainer | github.com/justinethier |
Safe Haskell | Safe-Inferred |
This module contains an experimental Scheme to Haskell compiler.
The compiler 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...
- data CompOpts = CompileOptions {}
- defaultCompileOptions :: String -> CompOpts
- createAstFunc :: CompOpts -> [HaskAST] -> HaskAST
- createAstCont :: CompOpts -> String -> String -> HaskAST
- data HaskAST
- showValAST :: HaskAST -> String
- joinL :: forall a. [[a]] -> [a] -> [a]
- ast2Str :: LispVal -> String
- asts2Str :: [LispVal] -> String
- headerComment :: [String]
- headerImports :: [String]
- headerModule :: [String]
- header :: String -> Bool -> [String]
- initializeCompiler :: Env -> IOThrowsError [HaskAST]
- compileLisp :: Env -> String -> String -> Maybe String -> IOThrowsError [HaskAST]
- compileBlock :: String -> Maybe String -> Env -> [HaskAST] -> [LispVal] -> IOThrowsError [HaskAST]
- compileScalar :: String -> CompOpts -> IOThrowsError [HaskAST]
- compileLambdaList :: [LispVal] -> IOThrowsError String
- defineLambdaVars :: Env -> [LispVal] -> IOThrowsError LispVal
- compile :: Env -> LispVal -> CompOpts -> IOThrowsError [HaskAST]
- mcompile :: Env -> LispVal -> CompOpts -> IOThrowsError [HaskAST]
- mfunc :: Env -> LispVal -> (Env -> LispVal -> CompOpts -> IOThrowsError [HaskAST]) -> CompOpts -> IOThrowsError [HaskAST]
- divertVars :: Env -> LispVal -> CompOpts -> (Env -> LispVal -> CompOpts -> IOThrowsError [HaskAST]) -> IOThrowsError [HaskAST]
- compileDivertedVars :: String -> Env -> [LispVal] -> CompOpts -> IOThrowsError HaskAST
- compileSpecialFormEntryPoint :: String -> String -> CompOpts -> IOThrowsError HaskAST
- compileSpecialForm :: String -> String -> CompOpts -> IOThrowsError HaskAST
- compileSpecialFormBody :: Env -> LispVal -> CompOpts -> (Maybe String -> ErrorT LispError IO [HaskAST]) -> ErrorT LispError IO [HaskAST]
- compileExpr :: Env -> LispVal -> String -> Maybe String -> IOThrowsError [HaskAST]
- compileApply :: Env -> LispVal -> CompOpts -> IOThrowsError [HaskAST]
- isPrim :: Env -> LispVal -> IOThrowsError (Maybe LispVal)
- _collectLiterals :: [LispVal] -> [LispVal] -> Bool -> Maybe [LispVal]
- collectLiterals :: [LispVal] -> Maybe [LispVal]
- collectLiteralsAndVars :: [LispVal] -> Maybe [LispVal]
Documentation
A type to store options passed to compile eventually all of this might be able to be integrated into a Compile monad
Create code for a function
:: CompOpts | Compilation options |
-> String | Value to send to the continuation |
-> String | Extra leading indentation (or blank string if none) |
-> HaskAST | Generated code |
Create code for a continutation
A very basic type to store a Haskell AST. FUTURE: is this even necessary? Would just a string be good enough?
showValAST :: HaskAST -> StringSource
:: forall a . | |
=> [[a]] | Original list-of-lists |
-> [a] | Separator |
-> [a] | Joined list |
A utility function to join list members together
headerModule :: [String]Source
compileLisp :: Env -> String -> String -> Maybe String -> IOThrowsError [HaskAST]Source
compileBlock :: String -> Maybe String -> Env -> [HaskAST] -> [LispVal] -> IOThrowsError [HaskAST]Source
compileScalar :: String -> CompOpts -> IOThrowsError [HaskAST]Source
defineLambdaVars :: Env -> [LispVal] -> IOThrowsError LispValSource
Add lambda variables to the compiler's environment
mfunc :: Env -> LispVal -> (Env -> LispVal -> CompOpts -> IOThrowsError [HaskAST]) -> CompOpts -> IOThrowsError [HaskAST]Source
:: 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.
compileDivertedVars :: String -> Env -> [LispVal] -> CompOpts -> IOThrowsError HaskASTSource
Take a list of variables diverted into env at compile time, and divert them into the env at runtime
compileSpecialForm :: String -> String -> CompOpts -> IOThrowsError HaskASTSource
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
compileExpr :: Env -> LispVal -> String -> Maybe String -> IOThrowsError [HaskAST]Source
compileApply :: Env -> LispVal -> CompOpts -> IOThrowsError [HaskAST]Source
Compile a function call
isPrim :: Env -> LispVal -> IOThrowsError (Maybe LispVal)Source
Determines if the given lispval is a primitive function
_collectLiterals :: [LispVal] -> [LispVal] -> Bool -> Maybe [LispVal]Source
Determine if the given list of expressions contains only literal identifiers EG: 1, 2, etc. And return them if that is all that is found.
Atoms are a special case since they denote variables that will only be available at runtime, so a flag is used to selectively include them.
collectLiterals :: [LispVal] -> Maybe [LispVal]Source
collectLiteralsAndVars :: [LispVal] -> Maybe [LispVal]Source