Showing
1 changed file
with
8 additions
and
5 deletions
... | @@ -229,6 +229,7 @@ class PidEnv (dict) : | ... | @@ -229,6 +229,7 @@ class PidEnv (dict) : |
229 | dict.__init__(self) | 229 | dict.__init__(self) |
230 | self.killed = set() | 230 | self.killed = set() |
231 | self.spawned = defaultdict(list) | 231 | self.spawned = defaultdict(list) |
232 | + self.next = {} | ||
232 | self._vars = set() | 233 | self._vars = set() |
233 | self(prog) | 234 | self(prog) |
234 | def __call__ (self, prog) : | 235 | def __call__ (self, prog) : |
... | @@ -256,11 +257,15 @@ def extend (module) : | ... | @@ -256,11 +257,15 @@ def extend (module) : |
256 | class Transition (snk.Transition) : | 257 | class Transition (snk.Transition) : |
257 | def __init__ (self, name, guard=None, **args) : | 258 | def __init__ (self, name, guard=None, **args) : |
258 | self.pids = PidEnv(args.pop("pids", "")) | 259 | self.pids = PidEnv(args.pop("pids", "")) |
260 | + vars = WordSet(self.pids.vars()) | ||
259 | if self.pids.spawned : | 261 | if self.pids.spawned : |
260 | assign = [] | 262 | assign = [] |
261 | for parent, children in self.pids.spawned.items() : | 263 | for parent, children in self.pids.spawned.items() : |
264 | + pidcount = vars.fresh(add=True, base="next_%s" % parent) | ||
265 | + self.pids.next[parent] = pidcount | ||
262 | for n, child in enumerate(children) : | 266 | for n, child in enumerate(children) : |
263 | - assign.append("%s=%s.next(%s)" % (child, parent, n)) | 267 | + assign.append("%s=%s.next(%s+%s)" |
268 | + % (child, parent, n, pidcount)) | ||
264 | if guard is None : | 269 | if guard is None : |
265 | guard = snk.Expression("newpids(%s)" % ", ".join(assign)) | 270 | guard = snk.Expression("newpids(%s)" % ", ".join(assign)) |
266 | else : | 271 | else : |
... | @@ -272,7 +277,6 @@ def extend (module) : | ... | @@ -272,7 +277,6 @@ def extend (module) : |
272 | class PetriNet (snk.PetriNet) : | 277 | class PetriNet (snk.PetriNet) : |
273 | def __init__ (self, name, **args) : | 278 | def __init__ (self, name, **args) : |
274 | snk.PetriNet.__init__(self, name, **args) | 279 | snk.PetriNet.__init__(self, name, **args) |
275 | - self.globals["newpids"] = snk.let | ||
276 | self.nextpids, nextpids = None, args.pop("nextpids", "nextpids") | 280 | self.nextpids, nextpids = None, args.pop("nextpids", "nextpids") |
277 | self.add_place(snk.Place(nextpids, [], tNextPid)) | 281 | self.add_place(snk.Place(nextpids, [], tNextPid)) |
278 | self.nextpids = nextpids | 282 | self.nextpids = nextpids |
... | @@ -284,9 +288,8 @@ def extend (module) : | ... | @@ -284,9 +288,8 @@ def extend (module) : |
284 | def add_transition (self, trans, **args) : | 288 | def add_transition (self, trans, **args) : |
285 | snk.PetriNet.add_transition(self, trans, **args) | 289 | snk.PetriNet.add_transition(self, trans, **args) |
286 | cons, prod = {}, {} | 290 | cons, prod = {}, {} |
287 | - vars = WordSet(trans.vars()) | ||
288 | for parent, children in trans.pids.spawned.items() : | 291 | for parent, children in trans.pids.spawned.items() : |
289 | - pidcount = vars.fresh(add=True, base="next_%s" % parent) | 292 | + pidcount = trans.pids.next[parent] |
290 | cons[parent] = snk.Tuple([snk.Variable(parent), | 293 | cons[parent] = snk.Tuple([snk.Variable(parent), |
291 | snk.Variable(pidcount)]) | 294 | snk.Variable(pidcount)]) |
292 | prod[parent] = snk.Tuple([snk.Variable(parent), | 295 | prod[parent] = snk.Tuple([snk.Variable(parent), |
... | @@ -310,4 +313,4 @@ def extend (module) : | ... | @@ -310,4 +313,4 @@ def extend (module) : |
310 | elif len(cons) == 1 : | 313 | elif len(cons) == 1 : |
311 | self.add_output(self.nextpids, trans.name, | 314 | self.add_output(self.nextpids, trans.name, |
312 | iter(prod.values()).next()) | 315 | iter(prod.values()).next()) |
313 | - return PetriNet, Transition, Pid | 316 | + return PetriNet, Transition, Pid, ("tPid", tPid), ("tNextPid", tNextPid) | ... | ... |
-
Please register or login to post a comment