Commits

Carl Friedrich Bolz committed 9719792

move graphviz stuff to its own file

Comments (0)

Files changed (3)

prolog/interpreter/continuation.py

 from prolog.interpreter.module import Module, ModuleWrapper
 from prolog.interpreter.helper import unwrap_predicate_indicator
 from prolog.interpreter.stream import StreamWrapper
+from prolog.interpreter.graphviz import _dot, view
 
 Signature.register_extr_attr("function", engine=True)
 
 # ___________________________________________________________________
 # Continuation classes
 
-def _dot(self, seen):
-    if self in seen:
-        return
-    seen.add(self)
-    yield '%s [label="%s", shape=box]' % (id(self), repr(self)[:50])
-    for key, value in self.__dict__.iteritems():
-        if hasattr(value, "_dot"):
-            yield "%s -> %s [label=%s]" % (id(self), id(value), key)
-            for line in value._dot(seen):
-                yield line
-
 
 class Continuation(object):
     """ Represents a continuation of the Prolog computation. This can be seen
         Continuation.__init__(self, engine, nextcont)
         self.module = module
 
-def view(*objects, **names):
-    from dotviewer import graphclient
-    content = ["digraph G{"]
-    seen = set()
-    for obj in list(objects) + names.values():
-        content.extend(obj._dot(seen))
-    for key, value in names.items():
-        content.append("%s -> %s" % (key, id(value)))
-    content.append("}")
-    p = py.test.ensuretemp("prolog").join("temp.dot")
-    p.write("\n".join(content))
-    graphclient.display_dot_file(str(p))
-
 
 class FailureContinuation(object):
     """ A continuation that can represent failures. It has a .fail method that

prolog/interpreter/graphviz.py

+
+def _dot(self, seen):
+    if self in seen:
+        return
+    seen.add(self)
+    yield '%s [label="%s", shape=box]' % (id(self), repr(self)[:50])
+    for key, value in self.__dict__.iteritems():
+        if hasattr(value, "_dot"):
+            yield "%s -> %s [label=%s]" % (id(self), id(value), key)
+            for line in value._dot(seen):
+                yield line
+
+def view(*objects, **names):
+    from dotviewer import graphclient
+    content = ["digraph G{"]
+    seen = set()
+    for obj in list(objects) + names.values():
+        content.extend(obj._dot(seen))
+    for key, value in names.items():
+        content.append("%s -> %s" % (key, id(value)))
+    content.append("}")
+    p = py.test.ensuretemp("prolog").join("temp.dot")
+    p.write("\n".join(content))
+    graphclient.display_dot_file(str(p))
+

prolog/interpreter/shape.py

 from pypy.rlib import jit, objectmodel, debug, unroll
 from prolog.interpreter import term
+from prolog.interpreter.graphviz import _dot, view
 # a Callable implementation that tries to save memory
 
 # XXX tune this
     def __repr__(self):
         return self.str()
 
+    _dot = _dot
+
 INEFFICIENT = Shape()
 SEEN_ONCE = Shape()
 
         assert result.get_shape().num_storage_vars() == result.size_storage()
         return result
 
+    _dot = _dot
+
 for i in range(SHAPED_CALLABLE_SIZE):
     setattr(ShapedCallableMixin, "a%s" % i, None)