From: Tim Vieira Date: Wed, 31 Jul 2013 12:40:05 +0000 (-0400) Subject: Tweaks: X-Git-Url: https://hydra-www.ietfng.org/gitweb/?a=commitdiff_plain;h=784327da0d555c494175770a4992feb21429ad85;p=dyna2 Tweaks: - 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. --- diff --git a/src/Dyna/Backend/Python/Backend.hs b/src/Dyna/Backend/Python/Backend.hs index 44c1fd9..43a8afe 100644 --- a/src/Dyna/Backend/Python/Backend.hs +++ b/src/Dyna/Backend/Python/Backend.hs @@ -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) diff --git a/src/Dyna/Backend/Python/dyna_doctest.py b/src/Dyna/Backend/Python/dyna_doctest.py index ee89f93..b7a44e7 100644 --- a/src/Dyna/Backend/Python/dyna_doctest.py +++ b/src/Dyna/Backend/Python/dyna_doctest.py @@ -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 diff --git a/src/Dyna/Backend/Python/interpreter.py b/src/Dyna/Backend/Python/interpreter.py index 97c7703..211636a 100644 --- a/src/Dyna/Backend/Python/interpreter.py +++ b/src/Dyna/Backend/Python/interpreter.py @@ -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) diff --git a/src/Dyna/Backend/Python/post/trace.py b/src/Dyna/Backend/Python/post/trace.py index 166a090..046135c 100644 --- a/src/Dyna/Backend/Python/post/trace.py +++ b/src/Dyna/Backend/Python/post/trace.py @@ -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 diff --git a/src/Dyna/Backend/Python/repl.py b/src/Dyna/Backend/Python/repl.py index 2fa33a6..3ee0e63 100644 --- a/src/Dyna/Backend/Python/repl.py +++ b/src/Dyna/Backend/Python/repl.py @@ -43,7 +43,7 @@ class REPL(cmd.Cmd, object): @property def prompt(self): - return bold % green % '> ' + return '> ' def do_rules(self, _): """ diff --git a/test/repl/trace.dynadoc b/test/repl/trace.dynadoc index 1c6345e..047d24e 100644 --- a/test/repl/trace.dynadoc +++ b/test/repl/trace.dynadoc @@ -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