Toggle navigation
Toggle navigation
This project
Loading...
Sign in
Franck Pommereau
/
snakes
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Authored by
Franck Pommereau
2016-10-11 10:12:34 +0200
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
c18eb4d35837c4124d9de7897fdbb3e852f77239
c18eb4d3
1 parent
70ce324f
minor improvements to abcd
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
29 additions
and
8 deletions
snakes/plugins/let.py
snakes/utils/abcd/checker.py
snakes/utils/abcd/main.py
snakes/plugins/let.py
View file @
c18eb4d
...
...
@@ -77,13 +77,13 @@ class MakeLet (object) :
exec
(
match
,
env
)
for
name
in
set
(
env
)
-
old
:
binding
[
name
]
=
env
[
name
]
def
__call__
(
self
,
__match__
=
None
,
__raise__
=
False
,
**
args
)
:
def
__call__
(
__self__
,
__match__
=
None
,
__raise__
=
False
,
**
args
)
:
try
:
__binding__
=
inspect
.
stack
()[
1
][
0
]
.
f_locals
[
"__binding__"
]
for
name
,
value
in
args
.
items
()
:
__binding__
[
name
]
=
value
if
__match__
:
self
.
match
(
__match__
,
__binding__
)
__self__
.
match
(
__match__
,
__binding__
)
except
:
if
__raise__
:
raise
...
...
snakes/utils/abcd/checker.py
View file @
c18eb4d
import
heapq
import
heapq
,
time
from
snakes.nets
import
StateGraph
import
snakes.lang
import
snkast
as
ast
class
Checker
(
object
)
:
def
__init__
(
self
,
net
)
:
def
__init__
(
self
,
net
,
progress
)
:
self
.
p
=
progress
self
.
g
=
StateGraph
(
net
)
self
.
f
=
[
self
.
build
(
f
)
for
f
in
net
.
label
(
"asserts"
)]
if
progress
:
if
len
(
self
.
f
)
==
0
:
print
(
"WARNING: no assertion given (computing the state space anyway)"
)
elif
len
(
self
.
f
)
==
1
:
print
(
"checking 1 assertion"
)
else
:
print
(
"checking
%
s assertions"
%
len
(
self
.
f
))
def
build
(
self
,
tree
)
:
src
=
"""
def check (_) :
...
...
@@ -14,25 +22,33 @@ def check (_) :
"""
%
tree
.
st
.
source
()[
7
:]
ctx
=
dict
(
self
.
g
.
net
.
globals
)
ctx
[
"bounded"
]
=
self
.
bounded
ctx
[
"dead"
]
=
self
.
dead
exec
(
src
,
ctx
)
fun
=
ctx
[
"check"
]
fun
.
lineno
=
tree
.
lineno
return
fun
def
bounded
(
self
,
marking
,
max
)
:
return
all
(
len
(
marking
(
p
))
==
1
for
p
in
marking
)
def
dead
(
self
)
:
return
not
bool
(
self
.
g
.
successors
())
def
run
(
self
)
:
start
=
last
=
time
.
time
()
for
state
in
self
.
g
:
marking
=
self
.
g
.
net
.
get_marking
()
for
place
in
marking
:
if
max
(
marking
(
place
)
.
values
())
>
1
:
return
None
,
self
.
trace
(
state
)
return
len
(
self
.
g
),
None
,
self
.
trace
(
state
)
for
check
in
self
.
f
:
try
:
if
not
check
(
marking
)
:
return
check
.
lineno
,
self
.
trace
(
state
)
return
len
(
self
.
g
),
check
.
lineno
,
self
.
trace
(
state
)
except
:
pass
return
None
,
None
if
self
.
p
and
time
.
time
()
-
last
>=
5
:
last
=
time
.
time
()
print
(
" ...
%
s states explored so far in
%.0
f seconds"
%
(
len
(
self
.
g
),
last
-
start
))
return
len
(
self
.
g
),
None
,
None
def
path
(
self
,
tgt
,
src
=
0
)
:
q
=
[(
0
,
src
,
())]
visited
=
set
()
...
...
snakes/utils/abcd/main.py
View file @
c18eb4d
...
...
@@ -87,6 +87,9 @@ opt.add_option("-a", "--all-names",
opt
.
add_option
(
"--debug"
,
dest
=
"debug"
,
action
=
"store_true"
,
default
=
False
,
help
=
"launch debugger on compiler error (default: no)"
)
opt
.
add_option
(
"--progress"
,
dest
=
"progress"
,
action
=
"store_true"
,
default
=
False
,
help
=
"show progression during long operations (default: no)"
)
opt
.
add_option
(
"-s"
,
"--simul"
,
dest
=
"simul"
,
action
=
"store_true"
,
default
=
False
,
help
=
"launch interactive code simulator"
)
...
...
@@ -295,7 +298,9 @@ def main (args=sys.argv[1:], src=None) :
bug
()
trace
,
lineno
=
[],
None
if
options
.
check
:
lineno
,
trace
=
Checker
(
net
)
.
run
()
states
,
lineno
,
trace
=
Checker
(
net
,
options
.
progress
)
.
run
()
if
options
.
progress
:
print
(
"
%
s states explored"
%
states
)
if
options
.
simul
:
engine
=
"dot"
for
eng
in
gv_engines
:
...
...
Please
register
or
login
to post a comment