Franck Pommereau

hopefully fixed CoffeeScript

sets = require "./sets"
dicts =
dicts = require "./dicts"
statespace = (init, addsucc, print_states, print_succs, print_dead) ->
i = init()
......@@ -27,13 +27,13 @@ statespace = (init, addsucc, print_states, print_succs, print_dead) ->
return [seen.len(), dead]
dumpobj = (obj) ->
return "{" + ("#{ k }: #{ v }" for k, v of obj).join(", ") + "}"
return "{" + ("'#{ k }': #{ v }" for k, v of obj).join(", ") + "}"
lts = (init, itersucc) ->
i = init()
i.id = 0
todo = new sets.Queue(i)
seen = new sets.Set()
seen = new sets.Set(i)
while not todo.empty()
state = todo.get()
console.log state.toString()
......
......@@ -4,7 +4,9 @@
sets = require("./sets");
dicts = statespace = function(init, addsucc, print_states, print_succs, print_dead) {
dicts = require("./dicts");
statespace = function(init, addsucc, print_states, print_succs, print_dead) {
var dead, i, ref, s, seen, state, succ, todo;
i = init();
i.id = 0;
......@@ -45,7 +47,7 @@
results = [];
for (k in obj) {
v = obj[k];
results.push(`${k}: ${v}`);
results.push(`'${k}': ${v}`);
}
return results;
})()).join(", ") + "}";
......@@ -56,7 +58,7 @@
i = init();
i.id = 0;
todo = new sets.Queue(i);
seen = new sets.Set();
seen = new sets.Set(i);
results = [];
while (!todo.empty()) {
state = todo.get();
......
This diff is collapsed. Click to expand it.
......@@ -59,7 +59,7 @@ class Marking
"""
copy = new Marking(id)
for [p, m] from @iter()
copy.d.set(p, m)
copy.d.set(p, m.copy())
return copy
has: (place) ->
"""
......
......@@ -61,7 +61,7 @@
ref = this.iter();
for (x of ref) {
[p, m] = x;
copy.d.set(p, m);
copy.d.set(p, m.copy());
}
return copy;
}
......
This diff is collapsed. Click to expand it.
......@@ -120,7 +120,7 @@ class Mset
false
"""
for [k, n] from other.d.iter()
if not @d.get(k, 0) >= n
if @d.get(k, 0) < n
return false
return true
empty: ->
......
......@@ -116,7 +116,7 @@
ref = other.d.iter();
for (x of ref) {
[k, n] = x;
if (!this.d.get(k, 0) >= n) {
if (this.d.get(k, 0) < n) {
return false;
}
}
......
This diff is collapsed. Click to expand it.
......@@ -81,7 +81,7 @@ class CodeGenerator (ast.CodeGenerator) :
def visit_GetPlace (self, node) :
self.fill("%s = %s.get(%r)" % (node.variable, node.marking, node.place.name))
def visit_ForeachToken (self, node) :
self.fill("for %s in %s.get(%r).iter()"
self.fill("for %s from %s.get(%r).iter()"
% (node.variable, node.marking, node.place.name))
self.children_visit(node.body, True)
def visit_Break (self, node) :
......@@ -163,7 +163,7 @@ class CodeGenerator (ast.CodeGenerator) :
if not first :
self.write(")")
for place, tokens in whole :
self.fill("%s.get(%r).add(%s)" % (var, place, tokens))
self.fill("%s.update(%r, %s)" % (var, place, tokens))
def visit_IfEnoughTokens (self, node) :
if not hasattr(node.CTX, "subvar") :
node.CTX.subvar = node.NAMES.fresh(base="sub")
......
......@@ -6,8 +6,13 @@ event = collections.namedtuple("event", ["trans", "mode", "state"])
def dumps (obj) :
if isinstance(obj, Marking) :
return "{%s}" % ", ".join("%s: %s" % (p, list(sorted(t)))
for p, t in sorted(obj.items()))
if getattr(obj, "ident", None) is None :
return "{%s}" % ", ".join("%s: %s" % (p, list(sorted(t)))
for p, t in sorted(obj.items()))
else :
return "[%s] {%s}" % (obj.ident,
", ".join("%s: %s" % (p, list(sorted(t)))
for p, t in sorted(obj.items())))
elif isinstance(obj, event) :
return "%s %s => %s" % (obj.trans, dumps(obj.mode), dumps(obj.state))
elif isinstance(obj, dict) :
......
......@@ -90,7 +90,7 @@ net "test net" :
< p0 val = dot
< p1 flush = m
> p1 fill = m
> p1 fill = new Mset(x+1 for x in m)
> p1 fill = m.map((v, c) -> [v+1, c])
# inhibitor value
trans t14 :
< p0 val = dot
......