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