1-----------------------------------------------------------------------------
3-- Module : Language.PureScript.Optimizer
4-- Copyright : (c) Phil Freeman 2013
7-- Maintainer : Phil Freeman <paf31@cantab.net>
8-- Stability : experimental
12-- This module optimizes code in the simplified-Javascript intermediate representation.
14-- The following optimizations are supported:
16-- * Collapsing nested blocks
18-- * Tail call elimination
20-- * Inlining of (>>=) and ret for the Eff monad
22-- * Removal of unused variables
24-- * Removal of unnecessary thunks
28-- * Inlining variables
30-- * Inline Prelude.($), Prelude.(#), Prelude.(++), Prelude.(!!)
32-- * Inlining primitive Javascript operators
34-----------------------------------------------------------------------------
36module Language.PureScript.Optimizer (
40import Language.PureScript.CodeGen.JS.AST
41import Language.PureScript.Options
43import Language.PureScript.Optimizer.Common
44import Language.PureScript.Optimizer.TCO
45import Language.PureScript.Optimizer.MagicDo
46import Language.PureScript.Optimizer.Inliner
47import Language.PureScript.Optimizer.Unused
48import Language.PureScript.Optimizer.Blocks
51-- Apply a series of optimizer passes to simplified Javascript code
53optimize :: Options -> JS -> JS
54optimize opts | optionsNoOptimizations opts = id
55 | otherwise = untilFixedPoint $ applyAll
56 [ collapseNestedBlocks
59 , removeUnusedVariables
63 , inlineOperator "$" $ \f x -> JSApp f [x]
64 , inlineOperator "#" $ \x f -> JSApp f [x]
65 , inlineOperator "!!" $ flip JSIndexer
66 , inlineOperator "++" $ JSBinary Add
67 , inlineCommonOperators ]
69untilFixedPoint :: (Eq a) => (a -> a) -> a -> a
72 go a = let a' = f a in
73 if a' == a then a' else go a'
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list