-- | 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
------------------------------------------------------------------------}}}
normalization process.
"""
-import re, os
+import re, os, shutil
from collections import defaultdict, namedtuple
from utils import magenta, red, green, yellow, white, read_anf
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"
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
# 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
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, """\
#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
}
</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">
$("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; });
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...
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>'
# 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)] = \
print >> html, '</div>'
-
if argv.browser:
os.system('gnome-open %s 2>/dev/null >/dev/null' % html.name)
-- rip out.
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE Rank2Types #-}
+{-# LANGUAGE ScopedTypeVariables #-}
module Dyna.Main.Driver where
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
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
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 {{{