Franck Pommereau

started debugging CoffeeScript

......@@ -25,7 +25,10 @@ statespace = (init, addsucc, print_states, print_succs, print_dead) ->
if print_succs
console.log ">", s.toString()
return [seen.len(), dead]
dumpobj = (obj) ->
return "{" + ("#{ k }: #{ v }" for k, v of obj).join(", ") + "}"
lts = (init, itersucc) ->
i = init()
i.id = 0
......@@ -37,12 +40,12 @@ lts = (init, itersucc) ->
for [trans, mode, sub, add] from itersucc(state)
succ = state.copy().sub(sub).add(add)
if seen.has(succ)
succ = seen.get(s)
succ = seen.get(succ)
else
succ.id = seen.len()
seen.add(succ)
todo.put(succ)
console.log "@ #{ trans } = #{ mode }"
console.log "@ #{ trans } = #{ dumpobj(mode) }"
console.log " - #{ sub.toString() }"
console.log " + #{ add.toString() }"
console.log " > #{ succ.toString() }"
......
// Generated by CoffeeScript 2.0.2
(function() {
var dicts, lts, main, sets, statespace;
var dicts, dumpobj, lts, main, sets, statespace;
sets = require("./sets");
......@@ -38,6 +38,19 @@
return [seen.len(), dead];
};
dumpobj = function(obj) {
var k, v;
return "{" + ((function() {
var results;
results = [];
for (k in obj) {
v = obj[k];
results.push(`${k}: ${v}`);
}
return results;
})()).join(", ") + "}";
};
lts = function(init, itersucc) {
var add, i, mode, results, seen, state, sub, succ, todo, trans;
i = init();
......@@ -56,13 +69,13 @@
[trans, mode, sub, add] = x;
succ = state.copy().sub(sub).add(add);
if (seen.has(succ)) {
succ = seen.get(s);
succ = seen.get(succ);
} else {
succ.id = seen.len();
seen.add(succ);
todo.put(succ);
}
console.log(`@ ${trans} = ${mode}`);
console.log(`@ ${trans} = ${dumpobj(mode)}`);
console.log(` - ${sub.toString()}`);
console.log(` + ${add.toString()}`);
results1.push(console.log(` > ${succ.toString()}`));
......
This diff is collapsed. Click to expand it.
......@@ -3,6 +3,8 @@ msets = require "./multisets"
class BlackToken
toString: -> "dot"
hash: -> 2881495479
eq: (other) -> other is this
dot = new BlackToken()
......@@ -57,7 +59,7 @@ class Marking
"""
copy = new Marking(id)
for [p, m] from @iter()
copy.set(p, m.copy())
copy.d.set(p, m)
return copy
has: (place) ->
"""
......
......@@ -11,6 +11,14 @@
return "dot";
}
hash() {
return 2881495479;
}
eq(other) {
return other === this;
}
};
dot = new BlackToken();
......@@ -53,7 +61,7 @@
ref = this.iter();
for (x of ref) {
[p, m] = x;
copy.set(p, m.copy());
copy.d.set(p, m);
}
return copy;
}
......
This diff is collapsed. Click to expand it.
......@@ -72,7 +72,7 @@ class CodeGenerator (ast.CodeGenerator) :
def visit_IfAllType (self, node) :
if node.place.type :
var = node.CTX.names.fresh()
self.fill("if (%s instanceof %s for %s from %s.iter())"
self.fill("if (typeof(%s) == %r for %s from %s.iter())"
% (var, node.place.type, var, node.variable))
self.write(".reduce((a, b) -> a and b)")
self.children_visit(node.body, True)
......@@ -119,7 +119,7 @@ class CodeGenerator (ast.CodeGenerator) :
elif typ.endswith("()") :
yield False, "%s(%s)" % (typ[:-2], var)
else :
yield False, "%s instanceof %s" % (var, typ)
yield False, "typeof(%s) == %r" % (var, typ)
def visit_IfType (self, node) :
match = list(c[1] for c in self._matchtype(node.token, node.place.type))
if not match :
......@@ -142,7 +142,6 @@ class CodeGenerator (ast.CodeGenerator) :
self.fill("%s = new Marking()" % var)
whole = []
for i, (place, tokens) in enumerate(marking.items()) :
self.fill("%s.set(%r, " % (var, place))
first = True
for tok in tokens :
if isinstance(tok, tuple) :
......@@ -152,16 +151,19 @@ class CodeGenerator (ast.CodeGenerator) :
raise CompilationError("unsupported type '%s(%s)'" % tok,
blame)
else :
if not first :
if first :
self.fill("%s.set(%r, " % (var, place))
first = False
else :
self.write(", ")
first = False
if isinstance(tok, ast.Pattern) :
self.write(self._pattern(tok.matcher))
else :
self.write(tok)
self.write(")")
if not first :
self.write(")")
for place, tokens in whole :
self.fill("%s.get(%r).update(%s)" % (var, place, tokens))
self.fill("%s.get(%r).add(%s)" % (var, place, tokens))
def visit_IfEnoughTokens (self, node) :
if not hasattr(node.CTX, "subvar") :
node.CTX.subvar = node.NAMES.fresh(base="sub")
......
......@@ -10,9 +10,9 @@ max = Math.max
net "test net" :
place p0 = dot # ensure finite execution
place p1 Number = 0, 1, 2
place p2 Number = 1, 2, 3
place p3 Number = MAX, {MAX+1}
place p1 number = 0, 1, 2
place p2 number = 1, 2, 3
place p3 number = MAX, {MAX+1}
# values
trans t01 :
< p0 val = dot
......@@ -90,7 +90,7 @@ net "test net" :
< p0 val = dot
< p1 flush = m
> p1 fill = m
> p1 fill = (x+1 for x in m)
> p1 fill = new Mset(x+1 for x in m)
# inhibitor value
trans t14 :
< p0 val = dot
......@@ -109,8 +109,8 @@ net "test net" :
< p2 !expr = x+1
> p3 val = 2
# tuples
place p5 (Number, Number)
place p6 (String, (Number, Number), Boolean)
place p5 (number, number)
place p6 (string, (number, number), boolean)
# input/output and nested
trans t17 :
< p0 val = dot
......