diff options
author | Joe Crayne <joe@jerkface.net> | 2019-03-23 18:39:08 -0400 |
---|---|---|
committer | Joe Crayne <joe@jerkface.net> | 2019-03-23 18:39:08 -0400 |
commit | 6c3d521988cef72cab99cb800e75134193ac4afb (patch) | |
tree | 75216a283e4c082ee482e1b1ace98479ede20f42 | |
parent | 86d43ec094cec3a88491258d17434b7e9ee7c1c9 (diff) |
Handle void return.
-rw-r--r-- | monkeypatch.hs | 9 |
1 files 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 | |||
508 | let k = uniqIdentifier "go" (compFree x `Map.union` compIntro x) | 508 | let k = uniqIdentifier "go" (compFree x `Map.union` compIntro x) |
509 | x' = fmap (\y -> App () (hsvar "return") $ promote (fnArgs fe) y) x | 509 | x' = fmap (\y -> App () (hsvar "return") $ promote (fnArgs fe) y) x |
510 | return $ fmap (\y -> Lambda () [hspvar k] y) $ foldr applyComputation x' xs | 510 | return $ fmap (\y -> Lambda () [hspvar k] y) $ foldr applyComputation x' xs |
511 | grokStatement fe (CBlockStmt (CReturn Nothing _)) = | ||
512 | Just $ Computation Map.empty Map.empty $ Lambda () [hspvar "go"] retUnit | ||
511 | grokStatement fe (CBlockStmt (CIf exp thn els _)) = do | 513 | grokStatement fe (CBlockStmt (CIf exp thn els _)) = do |
512 | (xs,x) <- grokExpression fe exp | 514 | (xs,x) <- grokExpression fe exp |
513 | let mkif0 = If () (comp x) | 515 | let mkif0 = If () (comp x) |
514 | (mkif,stmts) <- case (thn,els) of | 516 | (mkif,stmts) <- case (thn,els) of |
515 | 517 | ||
516 | (CCompound [] stmts _, Nothing ) -> Just (mkif0, stmts) | 518 | (CCompound [] stmts _, Nothing ) -> Just (mkif0, stmts) |
519 | (stmt , Nothing ) -> Just (mkif0, [CBlockStmt stmt]) | ||
517 | (CCompound [] stmts _, Just (CExpr Nothing _) ) -> Just (mkif0, stmts) | 520 | (CCompound [] stmts _, Just (CExpr Nothing _) ) -> Just (mkif0, stmts) |
518 | (CCompound [] stmts _, Just (CCompound [] [ CBlockStmt (CExpr Nothing _) ] _)) -> Just (mkif0, stmts) | 521 | (CCompound [] stmts _, Just (CCompound [] [ CBlockStmt (CExpr Nothing _) ] _)) -> Just (mkif0, stmts) |
519 | 522 | ||
@@ -522,15 +525,15 @@ grokStatement fe (CBlockStmt (CIf exp thn els _)) = do | |||
522 | (CExpr Nothing _ ,Just e@(CExpr (Just _) _)) -> Just (flip mkif0, [CBlockStmt e]) | 525 | (CExpr Nothing _ ,Just e@(CExpr (Just _) _)) -> Just (flip mkif0, [CBlockStmt e]) |
523 | (CCompound [] [CBlockStmt (CExpr Nothing _)] _,Just e@(CExpr (Just _) _)) -> Just (flip mkif0, [CBlockStmt e]) | 526 | (CCompound [] [CBlockStmt (CExpr Nothing _)] _,Just e@(CExpr (Just _) _)) -> Just (flip mkif0, [CBlockStmt e]) |
524 | 527 | ||
525 | _ -> Nothing -- TODO | 528 | _ -> trace ("Unhandled if: "++show (fmap (const LT) thn)) $ Nothing -- TODO |
526 | 529 | ||
527 | ss <- sequence $ map (grokStatement fe) stmts | 530 | ss <- sequence $ map (grokStatement fe) stmts |
528 | let s = foldr applyComputation (Computation Map.empty Map.empty (hsvar k)) ss | 531 | let s = foldr applyComputation (Computation Map.empty Map.empty (hsvar k)) ss |
529 | k = uniqIdentifier "go" (Map.union (compFree x) (compFree s)) | 532 | k = uniqIdentifier "go" (Map.union (compFree x) (compFree s)) |
530 | return $ flip (foldr applyComputation) xs Computation | 533 | return $ fmap (Lambda () [hspvar k]) $ flip (foldr applyComputation) xs Computation |
531 | { compFree = compFree x `Map.union` compFree s | 534 | { compFree = compFree x `Map.union` compFree s |
532 | , compIntro = compIntro s | 535 | , compIntro = compIntro s |
533 | , comp = Lambda () [hspvar k] $ mkif (comp s) (hsvar k) | 536 | , comp = mkif (comp s) (hsvar k) |
534 | } | 537 | } |
535 | grokStatement fe (CBlockStmt (CExpr (Just (C.CCall (CVar (C.Ident "__assert_fail" _ _) _) xs _)) _)) = do | 538 | grokStatement fe (CBlockStmt (CExpr (Just (C.CCall (CVar (C.Ident "__assert_fail" _ _) _) xs _)) _)) = do |
536 | x <- case xs of | 539 | x <- case xs of |