|
|
|
|
| Synopsis |
|
| type Var = CoreVarName | | | data CState = CState {} | | | | | | | type Compiler a = State CState a | | | bcCompile :: Flags -> IntState -> [CoreImport] -> Core -> BCModule | | | coreToImports :: Core -> [CoreImport] | | | cCore :: Core -> Compiler [BCDecl] | | | cData :: CoreData -> Compiler [BCDecl] | | | cCtor :: CoreCtor -> Int -> Compiler BCDecl | | | cFunc :: CoreFunc -> Compiler [BCDecl] | | | cBody :: CoreExpr -> [Var] -> Compiler [UseIns] | | | cBody' :: CoreExpr -> [Var] -> Compiler [UseIns] | | | cPrim :: CoreFunc -> Compiler [BCDecl] | | | isOnlyCon :: CoreCtorName -> Compiler Bool | | | cExpr :: CMode -> CoreExpr -> Compiler () | | | cArgs :: CMode -> [CoreExpr] -> Compiler () | | | cCallGlobal :: CMode -> Var -> Int -> Int -> Compiler () | | | cIfBranch :: CoreExpr -> Bool -> Label -> Label -> Compiler Bool | | | type Alt = (Label, CorePat, CoreExpr) | | | cAlt :: Label -> Alt -> Compiler Bool | | | cBinding :: Bool -> (CoreVarName, CoreExpr) -> Int -> Compiler () | | | cFail :: Compiler Bool | | | primForFunc :: CoreFuncName -> Maybe Ins | | | flattenCoreApp :: CoreExpr -> (CoreExpr, [CoreExpr]) | | | decomposeAlts :: [Alt] -> Compiler (Bool, Bool, [Tag], Maybe Label) | | | altsAsIf :: [(CorePat, CoreExpr)] -> Maybe (CoreExpr, CoreExpr) | | | pushConst :: ConstItem -> Compiler () | | | pushVar :: Var -> Compiler () | | | getIns :: Compiler [UseIns] | | | getDepth :: Compiler Int | | | emit :: Ins -> Compiler () | | | emitUse :: Ins -> [Var] -> Set Var -> Compiler () | | | shiftStack :: Int -> Compiler () | | | evalVar :: CMode -> Var -> Compiler () | | | eval :: CMode -> Compiler () | | | makePure :: Compiler a -> Compiler (a, CState) | | | asNewFunc :: Compiler a -> Compiler a | | | branchs :: Label -> String -> [Compiler Bool] -> Compiler () | | | bind :: Var -> Where -> Compiler () | | | addConst :: ConstItem -> Compiler CRef | | | newLabel :: Compiler Label | | | newLabels :: Int -> Compiler [Label] | | | withFailure :: Label -> Compiler a -> Compiler a | | | getFailure :: Compiler (Label, Int) | | | whereIsVar :: Var -> Compiler Where | | | lookupImport :: String -> Compiler CoreImport | | | lookupImportData :: String -> Compiler CoreData | | | lookupImportArity :: String -> Compiler Int | | | isFailure :: Var -> Bool | | | intersectManySets :: Ord a => [Set a] -> Set a |
|
|
| Documentation |
|
| type Var = CoreVarName |
| a variable, just to save typing space
|
|
| data CState |
| The state of the compilation process
| | Constructors | | CState | | | csFlags :: Flags | the overal compilation flags
| | csImports :: (Map String CoreImport) | import definitions
| | csConsts :: (Map ConstItem CRef) | the current constant table items
| | csThisFunc :: String | the name of the current func (for debugging the compiler)
| | csNextConst :: CRef | the next available constant reference
| | csNextLabel :: Label | the next available label
| | csMaxDepth :: Int | the maximum stack depth encountered
| | csIns :: [UseIns] | the outputted instructions
| | csEnv :: (Map Var Where) | a mapping from variables to arg/stack locations
| | csDepth :: Int | the current stack depth
| | csEvals :: (Set Var) | the set of already evaluated variables
| | csFails :: [(Label, Int)] | the stack of failure labels and stack depths
|
|
|
|
|
| data CMode |
| compiler mode (strict or lazy)
| | Constructors | | Instances | |
|
|
| data Where |
| where a variable is stored
| | Constructors | | Stack Int | on the stack
| | Arg Int | as an argument
|
| Instances | |
|
|
| type Compiler a = State CState a |
A case pattern
A monad for compiling
|
|
| bcCompile |
| :: Flags | compiler flags
| | -> IntState | internal state
| | -> [CoreImport] | items imported into core
| | -> Core | core to compile
| | -> BCModule | compiled bytecode
| | Compile Yhc.Core into bytecode, top-level function
|
|
|
| coreToImports :: Core -> [CoreImport] |
| convert a core to a list of imports of the items within that core
|
|
| cCore :: Core -> Compiler [BCDecl] |
| Compile the complete Yhc.Core into bytecode declarations
|
|
| cData :: CoreData -> Compiler [BCDecl] |
| Compile a Data declaration into bytecode declarations
|
|
| cCtor |
| :: CoreCtor | the constructor to compile
| | -> Int | the tag of the constructor
| | -> Compiler BCDecl | the geenrated declaration
| | Compile a single constructor into a declaration
|
|
|
| cFunc :: CoreFunc -> Compiler [BCDecl] |
| Compile a function declaration into a bytecode declaration
|
|
| cBody :: CoreExpr -> [Var] -> Compiler [UseIns] |
| compile the body of the a function and its arguments to bytecode instructions
|
|
| cBody' :: CoreExpr -> [Var] -> Compiler [UseIns] |
| compile the body of a function that is definitely not a selector
|
|
| cPrim :: CoreFunc -> Compiler [BCDecl] |
| compile a primitive function
|
|
| isOnlyCon :: CoreCtorName -> Compiler Bool |
| decide whether a constructor is the only constructor in the datatype
|
|
| cExpr :: CMode -> CoreExpr -> Compiler () |
| compile an expression (either strictly or lazily)
|
|
| cArgs :: CMode -> [CoreExpr] -> Compiler () |
| compile the arguments to a function
|
|
| cCallGlobal |
| :: CMode | mode to compile in (strict or lazy)
| | -> Var | the name of the function to call
| | -> Int | the number of arguments given
| | -> Int | the number of arguments expected
| | -> Compiler () | | | emit instructions to call a global function
|
|
|
| cIfBranch :: CoreExpr -> Bool -> Label -> Label -> Compiler Bool |
| compile an if branch
|
|
| type Alt = (Label, CorePat, CoreExpr) |
| an internal alternative
|
|
| cAlt :: Label -> Alt -> Compiler Bool |
| compile an alternative
|
|
| cBinding :: Bool -> (CoreVarName, CoreExpr) -> Int -> Compiler () |
| compile a let binding (either for recursive or non-recursive let)
|
|
| cFail :: Compiler Bool |
| compile a failure
|
|
| primForFunc :: CoreFuncName -> Maybe Ins |
| return the special primitive instruction associated with a function, or Nothing
|
|
| flattenCoreApp :: CoreExpr -> (CoreExpr, [CoreExpr]) |
| turn a nested application of CoreApp into a function and list of arguments
|
|
| decomposeAlts :: [Alt] -> Compiler (Bool, Bool, [Tag], Maybe Label) |
| decompose a list of alternatives into (int-case,complete,tags,default)
where int-case is true if this is an int-case, complete is true if the case is complete,
tags is the list of constructor tag numbers and default is the default case (if there is one)
|
|
| altsAsIf :: [(CorePat, CoreExpr)] -> Maybe (CoreExpr, CoreExpr) |
| decides whether a list of core alternatives are really an if
|
|
| pushConst :: ConstItem -> Compiler () |
| introduce instructions to push a constant
|
|
| pushVar :: Var -> Compiler () |
| push a variable on the stack
|
|
| getIns :: Compiler [UseIns] |
| get the instructions
|
|
| getDepth :: Compiler Int |
| get the current depth
|
|
| emit :: Ins -> Compiler () |
| emit an instruction
|
|
| emitUse :: Ins -> [Var] -> Set Var -> Compiler () |
| emit an instruction, with usage information
|
|
| shiftStack :: Int -> Compiler () |
| shift all the (Stack n) variables on the stack, also update the depth
|
|
| evalVar :: CMode -> Var -> Compiler () |
| evaluate a variable if it hasn't been evaluated already
|
|
| eval :: CMode -> Compiler () |
| emit an EVAL instruction, if the mode is strict
|
|
| makePure :: Compiler a -> Compiler (a, CState) |
| takes a compiler function and changes it so that it doesn't actually modify the state
|
|
| asNewFunc :: Compiler a -> Compiler a |
| takes a compiler and executes it as a new function body
|
|
| branchs :: Label -> String -> [Compiler Bool] -> Compiler () |
| take a list of compilers for different branches, run them all and then merge the results
the compiler returns a bool indicating whether it returns normally, if it doesn't return normally
then it doesn't need to have a depth matching the other branchs.
|
|
| bind :: Var -> Where -> Compiler () |
| bind a variable to a location
|
|
| addConst :: ConstItem -> Compiler CRef |
| add a constant to the constant table (if not present) and return its reference
|
|
| newLabel :: Compiler Label |
| allocate a new label
|
|
| newLabels :: Int -> Compiler [Label] |
| allocate several new labels
|
|
| withFailure :: Label -> Compiler a -> Compiler a |
| run a compiler in a new failure block
|
|
| getFailure :: Compiler (Label, Int) |
| get the most current failure
|
|
| whereIsVar :: Var -> Compiler Where |
| return where a variable can be found
|
|
| lookupImport :: String -> Compiler CoreImport |
| lookup an import
|
|
| lookupImportData :: String -> Compiler CoreData |
| lookup a data constructor
|
|
| lookupImportArity :: String -> Compiler Int |
| lookup the arity of a name
|
|
| isFailure :: Var -> Bool |
| test whether an expression a failure variable
|
|
| intersectManySets :: Ord a => [Set a] -> Set a |
| calculate the intersection of many sets (analogous to unionManySets)
|
|
| Produced by Haddock version 0.8 |