Franck Pommereau

minor improvements to abcd

......@@ -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
......
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 %.0f seconds"
% (len(self.g), last - start))
return len(self.g), None, None
def path (self, tgt, src=0) :
q = [(0, src, ())]
visited = set()
......
......@@ -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 :
......