fay-0.12.0.1: A compiler for Fay, a Haskell subset that compiles to JavaScript.

Safe HaskellNone

Language.Fay.Compiler.Optimizer

Synopsis

Documentation

type FuncArity = (QName, Int)Source

The arity of a function. Arity here is defined to be the number of arguments that can be directly uncurried from a curried lambda abstraction. So x y z -> if x then (a -> a) else (a -> a) has an arity of 3, not 4.

type Optimize = State OptStateSource

Optimize monad.

data OptState Source

State.

Constructors

OptState 

Fields

optStmts :: [JsStmt]
 
optUncurry :: [QName]
 

runOptimizer :: ([JsStmt] -> Optimize [JsStmt]) -> [JsStmt] -> [JsStmt]Source

Run an optimizer, which may output additional statements.

optimizeToplevel :: [JsStmt] -> Optimize [JsStmt]Source

Perform any top-level cross-module optimizations and GO DEEP to optimize further.

tco :: [JsStmt] -> [JsStmt]Source

Perform tail-call optimization.

stripAndUncurry :: [JsStmt] -> Optimize [JsStmt]Source

Strip redundant forcing from the whole generated code.

walkAndStripForces :: [FuncArity] -> JsExp -> Optimize (Maybe JsExp)Source

Strip redundant forcing from an application if possible.

applyToExpsInStmts :: ([FuncArity] -> JsExp -> Optimize JsExp) -> [JsStmt] -> Optimize [JsStmt]Source

Apply the given function to the top-level expressions in the given statements.

applyToExpsInStmt :: [FuncArity] -> ([FuncArity] -> JsExp -> Optimize JsExp) -> JsStmt -> Optimize JsStmtSource

Apply the given function to the top-level expressions in the given statement.

collectFuncs :: [JsStmt] -> [FuncArity]Source

Collect functions and their arity from the whole codeset.

expArity :: JsExp -> IntSource

Get the arity of an expression.

renameUncurried :: QName -> QNameSource

Rename an uncurried copy of a curried function.