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