Module FlatCurry.CaseLifting

This module contains an implementation of a case lifter, i.e., an operation which lifts all nested cases (and also nested lets) in a FlatCurry program into new operations.

NOTE: the new operations contain nonsense types, i.e., this transformation should only be used if the actual function types are irrelevant!

Author: Michael Hanus

Version: June 2020

Summary of exported operations:

defaultLiftOpts :: LiftOptions   
Default options for lifting all nested case/let/free expressions.
defaultNoLiftOpts :: LiftOptions   
Default options for lifting no nested case/let/free expression.
getOpts :: StateT LiftState Identity LiftOptions   
genFuncName :: String -> StateT LiftState Identity (String,String)   
addFun2State :: FuncDecl -> LiftState -> LiftState   
liftProg :: LiftOptions -> Prog -> Prog   
Lift nested cases/lets/free in a FlatCurry program (w.r.t.
liftTopFun :: FuncDecl -> StateT LiftState Identity [FuncDecl]   
liftNewFun :: FuncDecl -> StateT LiftState Identity FuncDecl   
liftRule :: Rule -> StateT LiftState Identity Rule   
liftExp :: Bool -> Expr -> StateT LiftState Identity Expr   
unboundVars :: Expr -> [Int]   
Find all variables which are not bound in an expression.
unboundVarsInBranch :: BranchExpr -> [Int]   
unionMap :: Eq a => (b -> [a]) -> [b] -> [a]   

Exported datatypes:


LiftOptions

Options for case/let/free lifting.

Constructors:

  • LiftOptions :: Bool -> Bool -> LiftOptions

    Fields:

    • liftCase :: Bool
    • liftCArg :: Bool

LiftState

Options for case/let/free lifting.

Constructors:

  • LiftState :: LiftOptions -> String -> [String] -> [FuncDecl] -> String -> Int -> LiftState

    Fields:

    • liftOpts :: LiftOptions
    • currMod :: String
    • topFuncs :: [String]
    • liftFuncs :: [FuncDecl]
    • currFunc :: String
    • currIndex :: Int

LiftingState

Type synonym: LiftingState a = State LiftState a


Exported operations:

defaultLiftOpts :: LiftOptions   

Default options for lifting all nested case/let/free expressions.

Further infos:
  • solution complete, i.e., able to compute all solutions

defaultNoLiftOpts :: LiftOptions   

Default options for lifting no nested case/let/free expression.

Further infos:
  • solution complete, i.e., able to compute all solutions

genFuncName :: String -> StateT LiftState Identity (String,String)   

addFun2State :: FuncDecl -> LiftState -> LiftState   

Further infos:
  • solution complete, i.e., able to compute all solutions

liftProg :: LiftOptions -> Prog -> Prog   

Lift nested cases/lets/free in a FlatCurry program (w.r.t. options).

liftExp :: Bool -> Expr -> StateT LiftState Identity Expr   

unboundVars :: Expr -> [Int]   

Find all variables which are not bound in an expression.

unboundVarsInBranch :: BranchExpr -> [Int]   

unionMap :: Eq a => (b -> [a]) -> [b] -> [a]