Skip to content
Snippets Groups Projects
Commit b135f8a8 authored by chrg's avatar chrg
Browse files

Quickfix

parent 9a263465
No related branches found
No related tags found
No related merge requests found
......@@ -5,25 +5,18 @@
{-# LANGUAGE ImportQualifiedPost #-}
{-# LANGUAGE OverloadedStrings #-}
import Control.RTree
import Data.Valuation qualified as Val
import Control.Monad.IRTree qualified as IRTree
import ReduceC
import Colog
import Control.Applicative
import Control.Monad
import Control.Monad.State
import Control.Monad.Trans
import Data.Bool (bool)
import Data.Foldable
import Data.Functor
import Data.List (intercalate)
import Data.Map.Strict qualified as Map
import Data.Text qualified as Text
import Data.Time (getCurrentTime)
import Data.Time qualified as Time
import Data.Vector qualified as V
import GHC.Stack
import Language.C qualified as C
import Options.Applicative
......@@ -41,7 +34,7 @@ main =
join
. execParser
$ info (run <**> helper)
. fold
. fold
$ []
process :: (WithLog env (Msg sev) m, MonadIO m) => sev -> Text.Text -> m a -> m a
......@@ -57,39 +50,39 @@ process sev p ma = do
run :: (HasCallStack) => Parser (IO ())
run = do
expmode <-
flag False True
$ fold
flag False True $
fold
[ long "exp"
, help "run in exponential mode"
]
checkmode <-
flag False True
$ fold
flag False True $
fold
[ long "dry-run"
, short 'n'
, help "don't do any reduction"
]
validity <-
optional
$ strOption
$ fold
[ long "validity"
, short 'v'
, help "check every output for validity"
]
optional $
strOption $
fold
[ long "validity"
, short 'v'
, help "check every output for validity"
]
pedandic <-
flag False True
$ fold
flag False True $
fold
[ long "pedandic"
, short 'P'
, help "when checking for validity, throw error if command fails"
]
debug <-
flag False True
$ fold
flag False True $
fold
[ long "debug"
, help "enable debugging"
]
......@@ -99,7 +92,7 @@ run = do
file <- strArgument $ fold [metavar "FILE"]
pure do
t <- getCurrentTime
time <- getCurrentTime
let
fmt m = do
t' <- getCurrentTime
......@@ -108,7 +101,7 @@ run = do
( Time.formatTime
Time.defaultTimeLocale
"%_3m:%04ES "
(t' `Time.diffUTCTime` t)
(t' `Time.diffUTCTime` time)
)
<> fmtMessage m
)
......@@ -138,37 +131,21 @@ run = do
removeFile (f <.> "bak")
liftIO exitFailure
check' f (ReState ch i val) mc = process I "Checking predictate" do
logDebug . Text.pack $ map (\j -> maybe '*' (bool '0' '1') (ch V.!? j)) [0 .. i]
logDebug
. Text.pack
$ intercalate
", "
[C.identToString k | (k, v) <- Val.toPairs val, v]
logDebug
. Text.pack
$ intercalate
", "
["!" <> C.identToString k | (k, v) <- Val.toPairs val, not v]
case mc of
Nothing -> do
logDebug "Empty input"
pure False
Just c -> do
when debug do
pPrint (void c)
check' f _ c = process I "Checking predictate" do
when debug do
pPrint (void c)
when pedandic do
liftIO $ copyFile f (f <.> "last")
output f c
v <- validiate f
if v
then test f
else do
logWarning "Produced invalid code"
when pedandic do
liftIO $ copyFile f (f <.> "last")
output f c
v <- validiate f
if v
then test f
else do
logWarning "Produced invalid code"
when pedandic do
liftIO $ copyFile f (f <.> "fail")
cleanup f
pure False
liftIO $ copyFile f (f <.> "fail")
cleanup f
pure False
let bak = file <.> "bak"
......@@ -213,10 +190,9 @@ run = do
liftIO exitSuccess
l <-
(if expmode then ireduceExpT (`evalStateT` Map.empty) else ireduceT (`evalStateT` Map.empty))
(if expmode then IRTree.reduceExpT id else IRTree.reduceT id)
(check' file)
(Val.singleton (Val.is $ C.internalIdent "main"))
(ReduceC.reduceC c)
(ReduceC.defaultReduceC c)
when pedandic do
liftIO $ copyFile file (file <.> "last")
......
......@@ -12,7 +12,6 @@ import Data.List.NonEmpty (nonEmpty)
import qualified Data.List.NonEmpty as NE
import qualified Data.Map.Strict as Map
import Test.Hspec
import Test.Hspec.Glitter
spec :: Spec
spec = describe "examples" do
......@@ -36,27 +35,27 @@ spec = describe "examples" do
let re = runReaderT (Expr.rExpr e) Map.empty
let
predicate :: Expr -> IO Bool
predicate = pure . contains isOpr
-- let
-- predicate :: Expr -> IO Bool
-- predicate = pure . contains isOpr
rex <- runIO $ RTree.reduce predicate re
-- rex <- runIO $ RTree.reduce predicate re
onGlitterWith
("test/expected/" <> str <> "-red")
( \fp () -> do
(mex, result) <- runWriterT (IRTree.reduce (debugPredicate showString (prettyExprS 0) predicate) me)
writeFile fp (appEndo result "")
pure mex
)
do
it "should produce the same results as the RTree" \mex -> do
rex `shouldBe` mex
-- onGlitterWith
-- ("test/expected/" <> str <> "-red")
-- ( \fp () -> do
-- (mex, result) <- runWriterT (IRTree.reduce (debugPredicate showString (prettyExprS 0) predicate) me)
-- writeFile fp (appEndo result "")
-- pure mex
-- )
-- do
-- it "should produce the same results as the RTree" \mex -> do
-- rex `shouldBe` mex
it "should find an opr exponentially" do
(mex, result) <- runWriterT (IRTree.reduceExp (debugPredicate showString (prettyExprS 0) predicate) me)
rex `shouldBe` mex
pure $ glitter ("test/expected/" <> str <> "-red-exp") (appEndo result "")
-- it "should find an opr exponentially" do
-- (mex, result) <- runWriterT (IRTree.reduceExp (debugPredicate showString (prettyExprS 0) predicate) me)
-- rex `shouldBe` mex
-- pure $ glitter ("test/expected/" <> str <> "-red-exp") (appEndo result "")
it "should reduce like iinputs" do
forM_ (RTree.iinputs re) \(ii, e') -> do
......
......@@ -80,10 +80,10 @@ rtreeSpec = describe "RTree" do
]
describe "drawRTree" do
it "should pretty print it's tree" do
glitter
"test/expected/rlist-drawrtree"
(drawRTree (\() -> id) shows (rList [1, 2, 3 :: Int]))
onGlitterWith
"test/expected/rlist-drawrtree"
(\fp () -> writeFile fp (drawRTree (\() -> id) shows (rList [1, 2, 3 :: Int])))
(pure ())
examplesSpec :: Spec
examplesSpec = describe "example" do
......@@ -107,10 +107,10 @@ examplesSpec = describe "example" do
let re = runReaderT me Map.empty
it "should draw the same" do
glitter
("test/expected/" <> str)
(drawRTree showString (prettyExprS 0) re)
onGlitterWith
("test/expected/" <> str)
(\fp () -> writeFile fp (drawRTree showString (prettyExprS 0) re))
(pure ())
it "should reduce like iinputs" do
forM_ (iinputs re) \(ii, e') -> do
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment