From 6c3d521988cef72cab99cb800e75134193ac4afb Mon Sep 17 00:00:00 2001 From: Joe Crayne Date: Sat, 23 Mar 2019 18:39:08 -0400 Subject: Handle void return. --- monkeypatch.hs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/monkeypatch.hs b/monkeypatch.hs index e47cb37..e58cc2e 100644 --- a/monkeypatch.hs +++ b/monkeypatch.hs @@ -508,12 +508,15 @@ grokStatement fe (CBlockStmt (CReturn (Just exp) _)) = do let k = uniqIdentifier "go" (compFree x `Map.union` compIntro x) x' = fmap (\y -> App () (hsvar "return") $ promote (fnArgs fe) y) x return $ fmap (\y -> Lambda () [hspvar k] y) $ foldr applyComputation x' xs +grokStatement fe (CBlockStmt (CReturn Nothing _)) = + Just $ Computation Map.empty Map.empty $ Lambda () [hspvar "go"] retUnit grokStatement fe (CBlockStmt (CIf exp thn els _)) = do (xs,x) <- grokExpression fe exp let mkif0 = If () (comp x) (mkif,stmts) <- case (thn,els) of (CCompound [] stmts _, Nothing ) -> Just (mkif0, stmts) + (stmt , Nothing ) -> Just (mkif0, [CBlockStmt stmt]) (CCompound [] stmts _, Just (CExpr Nothing _) ) -> Just (mkif0, stmts) (CCompound [] stmts _, Just (CCompound [] [ CBlockStmt (CExpr Nothing _) ] _)) -> Just (mkif0, stmts) @@ -522,15 +525,15 @@ grokStatement fe (CBlockStmt (CIf exp thn els _)) = do (CExpr Nothing _ ,Just e@(CExpr (Just _) _)) -> Just (flip mkif0, [CBlockStmt e]) (CCompound [] [CBlockStmt (CExpr Nothing _)] _,Just e@(CExpr (Just _) _)) -> Just (flip mkif0, [CBlockStmt e]) - _ -> Nothing -- TODO + _ -> trace ("Unhandled if: "++show (fmap (const LT) thn)) $ Nothing -- TODO ss <- sequence $ map (grokStatement fe) stmts let s = foldr applyComputation (Computation Map.empty Map.empty (hsvar k)) ss k = uniqIdentifier "go" (Map.union (compFree x) (compFree s)) - return $ flip (foldr applyComputation) xs Computation + return $ fmap (Lambda () [hspvar k]) $ flip (foldr applyComputation) xs Computation { compFree = compFree x `Map.union` compFree s , compIntro = compIntro s - , comp = Lambda () [hspvar k] $ mkif (comp s) (hsvar k) + , comp = mkif (comp s) (hsvar k) } grokStatement fe (CBlockStmt (CExpr (Just (C.CCall (CVar (C.Ident "__assert_fail" _ _) _) xs _)) _)) = do x <- case xs of -- cgit v1.2.3