]> hydra-www.ietfng.org Git - dyna2/commitdiff
Improve ./debug
authorNathaniel Wesley Filardo <nwf@cs.jhu.edu>
Wed, 15 May 2013 04:40:35 +0000 (00:40 -0400)
committerNathaniel Wesley Filardo <nwf@cs.jhu.edu>
Wed, 15 May 2013 04:40:35 +0000 (00:40 -0400)
.gitignore
external/prototype-1.6.0.3.js [moved from bin/prototype.js with 100% similarity, mode: 0644]
src/Dyna/Analysis/ANFPretty.hs
src/Dyna/Analysis/DOpAMine.hs
src/Dyna/Analysis/Mode/Execution/NamedInst.hs
src/Dyna/Backend/Python/debug-pygments.css [moved from bin/style.css with 100% similarity]
src/Dyna/Backend/Python/debug.py
src/Dyna/Main/Driver.hs

index d0cef4988c0d143c3f02810a7fff7463bf6b8688..a17f27d781e34dc223b2aacc35ea3e607550e4ae 100644 (file)
@@ -3,3 +3,6 @@
 *.pyc
 
 dist/
+examples/*.d
+examples/*.out
+examples/*.plan
old mode 100755 (executable)
new mode 100644 (file)
similarity index 100%
rename from bin/prototype.js
rename to external/prototype-1.6.0.3.js
index 2d88e0081c5214b85d79a9890a62c9dfc0a5ee29..7a54bbe74621a96d6c3bb1410c8b48ccdc2313af 100644 (file)
@@ -40,7 +40,7 @@ printANF (Rule rix h a result sp _ cruxes) =
     pev (CEval n o i)    = parens (pretty o <+> pretty i <> char '@' <> pretty n)
     pev (CCall n o is f) = parens (pretty o <+> pnft (n,(f,is)))
 
-    pun (CStruct o is f) = parens (pretty o  <+> parens (pft (f,is)))
+    pun (CStruct o is f) = parens (pretty o  <+> parens (char '&' <+> pft (f,is)))
     pun (CAssign o v   ) = parens (pretty o  <+> parens (equals   <+> pretty v))
     pun (CEquals v1 v2 ) = parens (pretty v1 <+> parens (equals   <+> pretty v2))
     pun (CNotEqu v1 v2 ) = parens (pretty v1 <+> parens (char '!' <+> pretty v2))
index 31e018a84d07d2b9c546f7248246c647d06959a6..10007717a49e03625a019c004a43cba53ca0e304 100644 (file)
@@ -115,19 +115,23 @@ type BackendRenderDopIter bs e =
 -- | Given a mechanism for rendering backend-specific information,
 -- pretty-print a 'DOpAMine' opcode.
 renderDOpAMine :: BackendRenderDopIter bs e -> DOpAMine bs -> Doc e
-renderDOpAMine _ (OPAsgn v n)    = text "OPAsgn" <+> pretty v  <+> pretty n
-renderDOpAMine _ (OPCheq a b)    = text "OPCheq" <+> pretty a  <+> pretty b
-renderDOpAMine _ (OPCkne a b)    = text "OPCkne" <+> pretty a  <+> pretty b
-renderDOpAMine _ (OPIndr a b)    = text "OPIndr" <+> pretty a  <+> pretty b
-renderDOpAMine _ (OPPeel vs v f) = text "OPPeel" <+> pretty vs
-                                               <+> pretty v  <+> pretty f
-renderDOpAMine _ (OPWrap v vs f) = text "OPWrap" <+> pretty v
-                                               <+> pretty vs <+> pretty f
-renderDOpAMine e (OPIter v vs f d b) =     text "OPIter"
-                                <+> pretty v
-                                <+> list (map pretty vs)
-                                <+> squotes (pretty f)
-                                <+> text (show d)
-                                <> maybe empty ((space <>) . braces . e v vs f d) b
+renderDOpAMine = r
+ where
+  r _ (OPAsgn v n)        = text "OPAsgn" <+> pretty v  <+> pretty n
+  r _ (OPCheq a b)        = text "OPCheq" <+> pretty a  <+> pretty b
+  r _ (OPCkne a b)        = text "OPCkne" <+> pretty a  <+> pretty b
+  r _ (OPIndr a b)        = text "OPIndr" <+> pretty a  <+> pretty b
+  r _ (OPPeel vs v f)     = text "OPPeel" <+> pretty vs
+                                          <+> pretty v  <+> pretty f
+  r _ (OPWrap v vs f)     = text "OPWrap" <+> pretty v
+                                          <+> pretty vs <+> pretty f
+  r e (OPIter v vs f d b) = text "OPIter"
+                            <+> pretty v
+                            <+> list (map pretty vs)
+                            <+> squotes (pretty f)
+                            <+> text (show d)
+                            <> maybe empty
+                                     ((space <>) . braces . e v vs f d)
+                                     b
 
 ------------------------------------------------------------------------}}}
index f2819c4d8eebbc5b72e75e5cc4b25c276bcd9595..157fe470901ac25a717f70db3d089b6226b9bc55 100644 (file)
@@ -108,11 +108,11 @@ instance (Pretty f) => Pretty (NIX f) where
                    UClobbered       -> "cl"
 
    -- render inst
-   ri IFree          = text "$f"
-   ri (IAny u)       = text "$a@" <> ru u
-   ri (IUniv u)      = text "$u@" <> ru u
-   ri (IBound u bm b) = ru u
-                     <> (semiBraces $ if b then (text "$b"):rm else rm)
+   ri IFree          = text "F"
+   ri (IAny u)       = text "A@" <> ru u
+   ri (IUniv u)      = text "U@" <> ru u
+   ri (IBound u bm b) = (semiBraces $ if b then (text "B"):rm else rm)
+                        <> char '@' <> ru u
     where
      rm = map (\(k,vs) -> pretty k <> tupled (map rix vs)) (M.toList bm)
                     
@@ -290,7 +290,7 @@ nExpose :: NIX f -> InstF f (NIX f)
 nExpose n@(NIX r m) = fmap (\a -> either id (\i -> NIX i m) (ml n m a)) r
 {-# INLINABLE nExpose #-}
 
--- | An inefficient \"inverse\" of nExpose.
+-- | An inefficient \"inverse\" (up to isomorphism) of nExpose.
 nHide :: InstF f (NIX f) -> NIX f
 nHide i = uncurry NIX $ runState (T.mapM next i) M.empty
  where
index b1bd02562ac4ded3b68c58153eb5e1937ad36c9f..4585a3b8de7fd44d77f6d8dae7a23c0a763c10ec 100644 (file)
@@ -4,7 +4,7 @@ Generates a visual representation of a Dyna program rules after the
 normalization process.
 """
 
-import re, os
+import re, os, shutil
 from collections import defaultdict, namedtuple
 from utils import magenta, red, green, yellow, white, read_anf
 
@@ -12,6 +12,8 @@ from pygments import highlight
 from pygments.lexers import get_lexer_by_name
 from pygments.formatters import HtmlFormatter
 
+cssfile="src/Dyna/Backend/Python/debug-pygments.css"
+jsfile="external/prototype-1.6.0.3.js"
 
 Edge = namedtuple('Edge', 'head label body')  # "body" is sometimes called the "tail"
 
@@ -161,7 +163,10 @@ def circuit(anf):
         g.edge(head=var, label=op, body=args)
 
     for var, op, val in unifs:
-        g.edge(head=var, label='& %s' % op, body=val)
+        if op == '&' :
+            op = '%s %s' % (op,val[0])
+            val = val[1:]
+        g.edge(head=var, label='%s' % op, body=val)
 
     g.head = head
     g.result = result
@@ -179,7 +184,9 @@ def graph_styles(g):
 
     # edge styles
     for e in g.edges:
-        if e.label.startswith('&'):  # distiguish unif edges
+        if    e.label.startswith('&') \
+           or e.label.startswith('!') \
+           or e.label.startswith('=') :  # distiguish unif edges
             sty[e].update({'style': 'filled', 'fillcolor': 'grey'})
 
     # node styles
@@ -200,9 +207,16 @@ def graph_styles(g):
 
 def main(dynafile):
 
+    if not os.path.exists(cssfile) or not os.path.exists(jsfile):
+        print("Debug must be run from the root of the Dyna source tree")
+        return
+
     d = dynafile + '.d'
     os.system('mkdir -p %s' % d)
 
+    shutil.copyfile(cssfile,d+"/debug-pygments.css")
+    shutil.copyfile(jsfile,d+"/prototype.js")
+
     with file(d + '/index.html', 'wb') as html:
 
         print >> html, """\
@@ -213,9 +227,10 @@ html, body {margin:0; padding:0;}
 
 #dyna-source { position:absolute; height: 95%; width: 42%; top: 10px; left: 0%; padding-left: 10px;  }
 #circuit-pane { position:absolute; width: 50%; top: 10px; left: 42%; padding-left: 5%; }
-#update-handler-pane { position: absolute; top: 10px; left: 100%; width: 45%; padding-right: 5%; }
+#dopamine-pane { position: absolute; top: 10px; left: 100%; width: 42%; padding-right: 5%; }
+#update-handler-pane { position: absolute; top: 10px; left: 150%; width: 45%; padding-right: 5%; }
 
-#dyna-source, #circuit-pane {
+#dyna-source, #circuit-pane, #dopamine-pane {
   border-right: 1px solid #666
 }
 
@@ -226,9 +241,9 @@ body { background: black; color: white; }
 
 </style>
 
-<link rel="stylesheet" href="../../bin/style.css">
+<link rel="stylesheet" href="debug-pygments.css">
 
-<script type="text/javascript" language="javascript" src="../../bin/prototype.js"></script>
+<script type="text/javascript" language="javascript" src="prototype.js"></script>
 
 <script type="text/javascript" language="javascript">
 
@@ -236,6 +251,9 @@ function selectline(lineno) {
   $("update-handler-pane").innerHTML = "";
   $$(".handler-" + lineno).each(function (e) { $("update-handler-pane").innerHTML += e.innerHTML; });
 
+  $("dopamine-pane").innerHTML = "";
+  $$(".dopamine-" + lineno).each(function (e) { $("dopamine-pane").innerHTML += e.innerHTML; });
+
   $("circuit-pane").innerHTML = "";
   $$(".circuit-" + lineno).each(function (e) { $("circuit-pane").innerHTML += e.innerHTML; });
 
@@ -265,6 +283,7 @@ function selectline(lineno) {
         print >> html, '</div>'
 
         print >> html, '<div id="circuit-pane" style=""></div>'
+        print >> html, '<div id="dopamine-pane" style=""></div>'
         print >> html, '<div id="update-handler-pane" style=""></div>'
 
         # XXX We do not yet render the dumped dopamine, but it's there...
@@ -278,13 +297,14 @@ function selectline(lineno) {
             os.system('gnome-open %s 2>/dev/null >/dev/null' % html.name)
             return
 
+        print >> html, '<div style="display:none;">'
+
         with file(d + '/anf') as f:
             anf = f.read()
 
-            print >> html, '<div style="display:none;">'
-
-            print >> html, '<h2>ANF</h2>'
-            print >> html, '<pre>\n%s\n</pre>' % anf.strip()
+            # Suppress this since we display ANF graphically instead.
+            # print >> html, '<h2>ANF</h2>'
+            # print >> html, '<pre>\n%s\n</pre>' % anf.strip()
 
             print >> html, '<h2>Hyperedge templates</h2>'
 
@@ -302,13 +322,50 @@ function selectline(lineno) {
         # find "update plans" -- every term (edge) in a rule must have code to
         # handle an update to it's value.
 
-        print >> html, '<h2>Update plans</h2>'
+        with file(d + '/dopupd') as f:
+            code = f.read()
+
+            print >> html, '<h2>Update plans</h2>'
 
-#        print >> html, '<pre>'
+            for (f,bline,bcol,eline,ecol,kv,block) in \
+                re.findall(';; (.*?):(\d+):(\d+)-.*?:(\d+):(\d+) (.*)\n((?: [^\n]*\n)*)'
+                          , code) :
+
+                # [fa] = re.findall('fa=([^ ]*)', kv)
+
+                print >> html, """\
+<div class="dopamine-%s">
+<pre>
+Update %s
+%s
+</pre>
+</div>
+""" % (bline, kv, block)
+
+
+        with file(d + '/dopini') as f:
+            code = f.read()
+
+            print >> html, '<h2>Initialization plans</h2>'
+
+            for (f,bline,bcol,eline,ecol,kv,block) in \
+                re.findall(';; (.*?):(\d+):(\d+)-.*?:(\d+):(\d+) (.*)\n((?: [^\n]*\n)*)'
+                          , code) :
+
+                print >> html, """\
+<div class="dopamine-%s">
+<pre>
+Initializer:
+%s
+</pre>
+</div>
+""" % (bline, block)
 
         with file(d + '/plan') as f:
             code = f.read()
-            print >> html, code
+            # print >> html, code
+
+            print >> html, '<h2>Update code</h2>'
 
             for block in re.split('# --\n', code)[1:]:  # drop the begining bit.
                 [(f, bline, bcol, eline, ecol, code)] = \
@@ -334,7 +391,6 @@ function selectline(lineno) {
 
         print >> html, '</div>'
 
-
     if argv.browser:
         os.system('gnome-open %s 2>/dev/null >/dev/null' % html.name)
 
index 9847436c5c47a340e1b42df5dcc1ea66a0795c6d..f0537031eb858d277e98486fb2a1902615128feb 100644 (file)
@@ -9,6 +9,7 @@
                                 -- rip out.
 {-# LANGUAGE OverloadedStrings #-}
 {-# LANGUAGE Rank2Types #-}
+{-# LANGUAGE ScopedTypeVariables #-}
 
 module Dyna.Main.Driver where
 
@@ -28,7 +29,7 @@ import           Dyna.Backend.BackendDefn
 import           Dyna.Backend.Backends
 import           Dyna.Main.Exception
 import qualified Dyna.ParserHS.Parser         as P
--- import           Dyna.Term.TTerm
+import           Dyna.Term.TTerm
 import           Dyna.XXX.Trifecta (prettySpanLoc)
 import           System.Console.GetOpt
 import           System.Environment
@@ -200,11 +201,15 @@ renderDop ddi dop = vsep $ map (renderDOpAMine ddi) dop
 
 renderDopUpds :: BackendRenderDopIter bs e -> UpdateEvalMap bs -> Doc e
 renderDopUpds ddi um = vsep $ flip map (M.toList um) $ \(fa,ps) ->
-    pretty fa `above` indent 2 (vsep $ flip map ps $ \(r,n,c,vi,vo,act) ->
-        planHeader r n c (vi,vo) `above` indent 2 (renderDop ddi act))
+    vsep $ flip map ps $ \(r,n,c,vi,vo,act) ->
+        planHeader r fa n c (vi,vo) `above` indent 2 (renderDop ddi act)
  where
-  planHeader r n c (vi,vo) =
-        (prettySpanLoc $ r_span r)
+  planHeader r (fa :: Maybe DFunctAr) n c (vi,vo) =
+        text ";;"
+    <+> (prettySpanLoc $ r_span r)
+    <+> text "fa="     <> maybe empty
+                                (\(f,a) -> pretty f <> text "/" <> pretty a)
+                                fa
     <+> text "evalix=" <> pretty n
     <+> text "cost="   <> pretty c
     <+> text "in="     <> pretty vi
@@ -217,10 +222,11 @@ renderDopInis ddi im = vsep $ flip map im $ \(r,c,ps) ->
   iniHeader r c `above` indent 2 (renderDop ddi ps)
  where
   iniHeader r c = 
-       ((prettySpanLoc $ r_span r)
-   <+> text "cost=" <> pretty c
-   <+> text "head=" <> pretty (r_head r)
-   <+> text "res=" <> pretty (r_result r))
+        text ";;"
+    <+> (prettySpanLoc $ r_span r)
+    <+> text "cost=" <> pretty c
+    <+> text "head=" <> pretty (r_head r)
+    <+> text "res=" <> pretty (r_result r)
 
 ------------------------------------------------------------------------}}}
 -- Warnings                                                             {{{