]> hydra-www.ietfng.org Git - dyna2/commitdiff
Tweaks:
authorTim Vieira <tim.f.vieira@gmail.com>
Wed, 31 Jul 2013 12:40:05 +0000 (08:40 -0400)
committerTim Vieira <tim.f.vieira@gmail.com>
Wed, 31 Jul 2013 12:40:05 +0000 (08:40 -0400)
 - color REPL prompt leads to strange behavior because the width of the prompt
   appears to be miscalculated by readline.

 - tiny improvement to trace's output format

 - tiny tweak to codegen

 - doctest shows diff along with what was expected and what it got.

src/Dyna/Backend/Python/Backend.hs
src/Dyna/Backend/Python/dyna_doctest.py
src/Dyna/Backend/Python/interpreter.py
src/Dyna/Backend/Python/post/trace.py
src/Dyna/Backend/Python/repl.py
test/repl/trace.dynadoc

index 44c1fd952b9a7dcafa49142a67e46a32b687f03b..43a8afe5ff012b94e91a8c022a056394cfd7e2bc 100644 (file)
@@ -234,10 +234,7 @@ ground2underscore x = if isGround x then "_" else pretty (x^.mv_var)
 
 piterate :: [ModedVar] -> Doc e
 piterate vs = if length vs == 0 then "_"
-              else parens $
-       sepBy "," (map ground2underscore vs)
-       <> "," -- add a comma to ensure tuple.
-
+              else "[" <> sepBy "," (map ground2underscore vs) <> "]"
 
 -- filterGround :: [ModedVar] -> [DVar]
 -- filterGround = map (^.mv_var) . filter (not.nGround.(^.mv_mi))
@@ -260,7 +257,7 @@ pdope_ _ (OPWrap v vs f) = return $ pretty v
                            <+> equals
                            <+> "build"
                            <> (parens $ pfas f vs <> comma
-                                <> (sepBy "," $ map pretty vs))
+                                <> (sepBy "," $ map pretty vs)) 
 
 pdope_ _ (OPIter v vs _ Det (Just (PDBS c))) = return $ pretty (v^.mv_var)
                                      <+> equals
@@ -292,8 +289,8 @@ pdope_ bc (OPIter o m f DetSemi Nothing) | (f,length m) `S.member` bc = do
    vcat
    [     pretty (o^.mv_var)
      <+> equals
-     <+> "gbc"
-     <> tupled (pfas f m : map (pretty . _mv_var) m)
+     <+> "gbc(" <> pfas f m <> ",[" <> sepBy "," (map (pretty . _mv_var) m) <> "])"
+
 
 --- needs an opbuild
    , ("d" <> pretty dookie)
index ee89f938bb467649c630a508128cdb59b8613ffa..b7a44e736e5037cf8458a6c97db3e2b54ada7580 100644 (file)
@@ -3,7 +3,17 @@ import re, sys, traceback
 from interpreter import Interpreter
 from repl import REPL
 from cStringIO import StringIO
-from utils import red, green, yellow, strip_comments
+from utils import bold, red, green, yellow, strip_comments
+
+
+def diff(expect, got):
+    with file('/tmp/expect','wb') as A:
+        A.write(expect)
+    with file('/tmp/got','wb') as B:
+        B.write(got)
+    from subprocess import Popen, PIPE
+    p = Popen(['colordiff', A.name, B.name], stdout=PIPE, stderr=PIPE)
+    return p.communicate()[0]
 
 
 def extract(code):
@@ -51,10 +61,12 @@ def run(code, out=None):
             repl.cmdloop()
             continue
 
+        exception = False
         sys.stdout = x = StringIO()
         try:
             repl.onecmd(cmd)
         except:
+            exception = True
             print >> out, red % traceback.format_exc()
         finally:
             sys.stdout = sys.__stdout__
@@ -62,13 +74,17 @@ def run(code, out=None):
         got = clean(x.getvalue())
         expect = clean(expect)
 
-        if expect == '*ignore*':
+        if expect == '*ignore*' and not exception:
             continue
 
-        if expect != got:
+        if expect != got or exception:
             print >> out, green % expect
             print >> out, red % got
+            print >> out, bold % yellow % '=== diff ======'
+            print >> out, diff(expect, got).strip()
+            print >> out, bold % yellow % '==============='
             errors += 1
+
         else:
             print >> out
             print >> out, got
index 97c7703b745b9be8ceb72f0f6ef32a66be0460ba..211636abe990e4399e7f3863b193f9b085562e8d 100644 (file)
@@ -276,7 +276,7 @@ class Interpreter(object):
             # is not possible.
             self.emit(*e)
 
-    def gbc(self, fn, *args):
+    def gbc(self, fn, args):
 
         item = self.build(fn, *args)
 
index 166a0904e33e2e7c43643325f822d1ea7cc99c6c..046135cc92bb90031eebadecdcdadc64e1443d7e 100644 (file)
@@ -172,9 +172,10 @@ class Crux(object):
         this expresion graph.
         """
 
-        if x not in ('true', 'false'):
-            if x in self.visited:
-                return red % '*cycle@%s*' % x
+        #if x not in ('true', 'false'):
+        #    if x in self.visited:
+        #        #return red % '*cycle@%s*' % x
+        #        return x
         self.visited.add(x)
 
         g = self.graph
index 2fa33a6ba1344a0c98388fa55c1bbc4541398dbb..3ee0e63b877adf6bef25baae98923efc25902a3a 100644 (file)
@@ -43,7 +43,7 @@ class REPL(cmd.Cmd, object):
 
     @property
     def prompt(self):
-        return bold % green % '> '
+        return '> '
 
     def do_rules(self, _):
         """
index 1c6345e2e4fae437eb8e2dd5e4abe4d402f7d3d1..047d24eebcdcdf6e1beb0f8adfb1fd797e75614e 100644 (file)
@@ -44,7 +44,7 @@ b = 3
       |
       └─ := 3
 
-         f(X=3) := (f((X=3 - 1)=2)=2 + f((X=3 - 2)=1)=1)=3,
+         f(X=3) := (f((X=3 - 1)=2)=2 + f((X=3 - 2)=1)=1)=3
              for ((X=3 > 1)=true) = (true=true).
          |
          ├─ f(1) = 1
@@ -57,7 +57,7 @@ b = 3
             |
             └─ := 2
 
-               f(X=2) := (f((X=2 - 1)=1)=1 + f((X=2 - 2)=0)=1)=2,
+               f(X=2) := (f((X=2 - 1)=1)=1 + f((X=2 - 2)=0)=1)=2
                    for ((X=2 > 1)=true) = (true=true).
                |
                ├─ f(0) = 1