@@ -781,13 +781,14 @@ reduceLoop reduced (cons, program) =
781781 reducable $ last body
782782 | otherwise = False
783783 where reducable :: JS -> Bool
784− reducable (JSReturn js) = reducable js
785− reducable (JSNew _ args) = and $ map reducable args
786− reducable (JSArray fields) = and $ map reducable fields
787− reducable (JSNum _) = True
788− reducable JSNull = True
789− reducable (JSIdent _) = True
790− reducable _ = False
784+ reducable js
785+ | JSReturn ret <- js = reducable ret
786+ | JSNew _ args <- js = and $ map reducable args
787+ | JSArray fields <- js = and $ map reducable fields
788+ | JSNum _ <- js = True
789+ | JSNull <- js = True
790+ | JSIdent _ <- js = True
791+ | otherwise = False
791792
792793
793794 reduce :: JS -> JS
@@ -851,24 +852,26 @@ codegenJavaScript target definitions filename outputType = do
851852
852853
853854 functions :: [String]
854− functions =
855− let translated =
856− concatMap translateDeclaration def ++ [mainLoop, invokeLoop]
857−
858− optimized = map optimizeJS translated
859− idsRemoved = removeIDs optimized
860− reduced = reduceJS idsRemoved
861− constRemoved = map reduceConstants reduced
862− constrInit = initConstructors constRemoved
863− removeAlloc = map removeAllocations constrInit
864− deadElim = elimDeadLoop removeAlloc
865− inlined = inlineFunctions deadElim
866− elimDup = map elimDuplicateEvals inlined
867− evalTC = map (optimizeEvalTailcalls ("__IDR__mEVAL0", "__IDRRT__EVALTC")) elimDup
868− applyTC = map (optimizeEvalTailcalls ("__IDR__mAPPLY0", "__IDRRT__APPLYTC")) evalTC
869− remChecks = map removeInstanceChecks applyTC
870− js = remChecks in
871− map compileJS js
855+ functions = translate >>> optimize >>> compile $ def
856+ where
857+ translate p = concatMap translateDeclaration p ++ [mainLoop, invokeLoop]
858+ optimize p = foldl' (flip ($)) p opt
859+ compile = map compileJS
860+
861+ opt =
862+ [ map optimizeJS
863+ , removeIDs
864+ , reduceJS
865+ , map reduceConstants
866+ , initConstructors
867+ , map removeAllocations
868+ , elimDeadLoop
869+ , inlineFunctions
870+ , map elimDuplicateEvals
871+ , map (optimizeEvalTailcalls ("__IDR__mEVAL0", "__IDRRT__EVALTC"))
872+ , map (optimizeEvalTailcalls ("__IDR__mAPPLY0", "__IDRRT__APPLYTC"))
873+ , map removeInstanceChecks
874+ ]
872875
873876
874877 mainLoop :: JS