Showing
2 changed files
with
26 additions
and
12 deletions
... | @@ -5,7 +5,7 @@ from snakes.utils.abcd.build import Builder | ... | @@ -5,7 +5,7 @@ from snakes.utils.abcd.build import Builder |
5 | from snakes.lang.abcd.parser import parse | 5 | from snakes.lang.abcd.parser import parse |
6 | from snakes.lang.pgen import ParseError | 6 | from snakes.lang.pgen import ParseError |
7 | from snakes.utils.abcd import CompilationError, DeclarationError | 7 | from snakes.utils.abcd import CompilationError, DeclarationError |
8 | -from snakes.utils.abcd.simul import Simulator | 8 | +from snakes.utils.abcd.simul import Simulator, ABCDSimulator |
9 | from snakes.utils.abcd.checker import Checker | 9 | from snakes.utils.abcd.checker import Checker |
10 | from snakes.utils.abcd.html import build as html | 10 | from snakes.utils.abcd.html import build as html |
11 | from snakes.utils.simul.html import json | 11 | from snakes.utils.simul.html import json |
... | @@ -213,6 +213,20 @@ def save_pnml (net, target) : | ... | @@ -213,6 +213,20 @@ def save_pnml (net, target) : |
213 | die(ERR_OUTPUT, str(sys.exc_info()[1])) | 213 | die(ERR_OUTPUT, str(sys.exc_info()[1])) |
214 | 214 | ||
215 | ## | 215 | ## |
216 | +## simulator (not standalone) | ||
217 | +## | ||
218 | + | ||
219 | +def simulate (source, filename="<string>") : | ||
220 | + global options, snk | ||
221 | + getopts(["--simul", filename]) | ||
222 | + node = parse(source, filename=filename) | ||
223 | + snk = snakes.plugins.load(options.plugins, "snakes.nets", "snk") | ||
224 | + build = Builder(snk) | ||
225 | + net = build.build(node) | ||
226 | + net.label(srcfile=filename, snakes=snk) | ||
227 | + return ABCDSimulator(node, net, draw(net, None)) | ||
228 | + | ||
229 | +## | ||
216 | ## main | 230 | ## main |
217 | ## | 231 | ## |
218 | 232 | ||
... | @@ -278,7 +292,7 @@ def main (args=sys.argv[1:], src=None) : | ... | @@ -278,7 +292,7 @@ def main (args=sys.argv[1:], src=None) : |
278 | lineno, trace = Checker(net).run() | 292 | lineno, trace = Checker(net).run() |
279 | if options.simul : | 293 | if options.simul : |
280 | try : | 294 | try : |
281 | - simul = Simulator(abcd, node, net, draw(net, None)) | 295 | + simul = Simulator(node, net, draw(net, None)) |
282 | except : | 296 | except : |
283 | bug() | 297 | bug() |
284 | simul.start() | 298 | simul.start() | ... | ... |
... | @@ -3,8 +3,14 @@ from snakes.utils.simul import * | ... | @@ -3,8 +3,14 @@ from snakes.utils.simul import * |
3 | import snakes.utils.abcd.html as html | 3 | import snakes.utils.abcd.html as html |
4 | 4 | ||
5 | class ABCDSimulator (BaseSimulator) : | 5 | class ABCDSimulator (BaseSimulator) : |
6 | - def __init__ (self, net, a2html, n2html, gv) : | 6 | + def __init__ (self, node, net, gv) : |
7 | BaseSimulator.__init__(self, net) | 7 | BaseSimulator.__init__(self, net) |
8 | + a2html = html.ABCD2HTML(node) | ||
9 | + n2html = html.Net2HTML(net, gv, a2html) | ||
10 | + self.info = {"filename" : node.st.filename, | ||
11 | + "abcd" : a2html.html(), | ||
12 | + "tree" : n2html.html(), | ||
13 | + "net" : n2html.svg()} | ||
8 | self.tree = {} | 14 | self.tree = {} |
9 | for node in net.node() : | 15 | for node in net.node() : |
10 | nid = gv.nodemap[node.name] | 16 | nid = gv.nodemap[node.name] |
... | @@ -52,17 +58,11 @@ class ABCDSimulator (BaseSimulator) : | ... | @@ -52,17 +58,11 @@ class ABCDSimulator (BaseSimulator) : |
52 | } | 58 | } |
53 | 59 | ||
54 | class Simulator (BaseHTTPSimulator) : | 60 | class Simulator (BaseHTTPSimulator) : |
55 | - def __init__ (self, abcd, node, net, gv) : | 61 | + def __init__ (self, node, net, gv) : |
56 | - a2html = html.ABCD2HTML(node) | 62 | + simul = ABCDSimulator(node, net, gv) |
57 | - n2html = html.Net2HTML(net, gv, a2html) | ||
58 | - simul = ABCDSimulator(net, a2html, n2html, gv) | ||
59 | BaseHTTPSimulator.__init__(self, net, simulator=simul) | 63 | BaseHTTPSimulator.__init__(self, net, simulator=simul) |
60 | - self.info = {"filename" : node.st.filename, | ||
61 | - "abcd" : a2html.html(), | ||
62 | - "tree" : n2html.html(), | ||
63 | - "net" : n2html.svg()} | ||
64 | def init_model (self) : | 64 | def init_model (self) : |
65 | - return self.res["model.html"] % self.info | 65 | + return self.res["model.html"] % self.simul.info |
66 | def init_ui (self) : | 66 | def init_ui (self) : |
67 | return BaseHTTPSimulator.init_ui(self)[:-1] + [{ | 67 | return BaseHTTPSimulator.init_ui(self)[:-1] + [{ |
68 | "label" : "Show net", | 68 | "label" : "Show net", | ... | ... |
-
Please register or login to post a comment