Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
R
rtree
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
chrg
rtree
Commits
b135f8a8
Commit
b135f8a8
authored
1 year ago
by
chrg
Browse files
Options
Downloads
Patches
Plain Diff
Quickfix
parent
9a263465
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
rtree-c/bin/Main.hs
+35
-59
35 additions, 59 deletions
rtree-c/bin/Main.hs
rtree/test/src/Control/Monad/IRTreeSpec.hs
+18
-19
18 additions, 19 deletions
rtree/test/src/Control/Monad/IRTreeSpec.hs
rtree/test/src/Control/Monad/RTreeSpec.hs
+8
-8
8 additions, 8 deletions
rtree/test/src/Control/Monad/RTreeSpec.hs
with
61 additions
and
86 deletions
rtree-c/bin/Main.hs
+
35
−
59
View file @
b135f8a8
...
...
@@ -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
t
ime
<-
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
`
t
ime
)
)
<>
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
i
reduceExpT
(`
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"
)
...
...
This diff is collapsed.
Click to expand it.
rtree/test/src/Control/Monad/IRTreeSpec.hs
+
18
−
19
View file @
b135f8a8
...
...
@@ -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
...
...
This diff is collapsed.
Click to expand it.
rtree/test/src/Control/Monad/RTreeSpec.hs
+
8
−
8
View file @
b135f8a8
...
...
@@ -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
(
pre
ttyExprS
0
)
re
)
onGlitterWith
(
"test/expected/"
<>
str
)
(
\
fp
()
->
writeFile
fp
(
drawRTree
showString
(
prettyExprS
0
)
re
)
)
(
p
u
re
()
)
it
"should reduce like iinputs"
do
forM_
(
iinputs
re
)
\
(
ii
,
e'
)
->
do
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment