@@ -21,7 +21,7 @@ module Language.PureScript.CodeGen.Cpp.Optimizer.Blocks
23import Prelude.Compat
23import Prelude.Compat
24−import Data.Either
24+import Data.Maybe
26import Language.PureScript.CodeGen.Cpp.AST
26import Language.PureScript.CodeGen.Cpp.AST
27import Language.PureScript.CodeGen.Cpp.Types
27import Language.PureScript.CodeGen.Cpp.Types
@@ -94,16 +94,16 @@ collapseCtorChecksToSwitch = everywhereOnCpp collapse
94 collapse (CppBlock cpps@(_:_:_)) = CppBlock (go cpps)
94 collapse (CppBlock cpps@(_:_:_)) = CppBlock (go cpps)
96 go cpps'@(cpp:_)
96 go cpps'@(cpp:_)
97− | Right (lhs, _, _) <- fromif Nothing cpp
97+ | Just (lhs, _, _) <- fromif Nothing cpp
98− , (otherCpps, ifs@(_:_:_)) <- partitionEithers $ fromif (Just lhs) <$> cpps'
98+ , ifs@(_:_:_) <- catMaybes . takeWhile (isJust) $ fromif (Just lhs) <$> cpps'
99− = CppSwitch lhs ((\(_,b,c) -> (b,c)) <$> ifs) Nothing : otherCpps
99+ = CppSwitch lhs ((\(_,b,c) -> (b,c)) <$> ifs) Nothing : drop (length ifs) cpps'
100 go (cpp':cpps') = cpp' : go cpps'
100 go (cpp':cpps') = cpp' : go cpps'
101 go cpp' = cpp'
101 go cpp' = cpp'
102− fromif :: Maybe Cpp -> Cpp -> Either Cpp (Cpp, Cpp, Cpp)
102+ fromif :: Maybe Cpp -> Cpp -> Maybe (Cpp, Cpp, Cpp)
103 fromif cond (CppIfElse (CppBinary EqualTo lhs rhs) stmt Nothing)
103 fromif cond (CppIfElse (CppBinary EqualTo lhs rhs) stmt Nothing)
104 | CppApp (CppVar f) _ <- lhs
104 | CppApp (CppVar f) _ <- lhs
105 , f == getCtor
105 , f == getCtor
106 , maybe True (lhs==) cond
106 , maybe True (lhs==) cond
107− = Right (lhs, rhs, stmt)
107+ = Just (lhs, rhs, stmt)
108− fromif _ cpp = Left cpp
108+ fromif _ _ = Nothing
109 collapse cpp = cpp
109 collapse cpp = cpp