- update ./debug to parse new format.
Updated TODO list.
parse_sexpr handles double quoted strings (at least crudely).
$ go xs
-printPlanHeader :: Handle -> Rule -> Cost -> Maybe Int -> IO ()
-printPlanHeader h r c mn = do
- hPutStrLn h $ "# --"
- -- XXX This "prefixSD" thing is the only real reason we're doing this in
- -- IO; it'd be great if wl-pprint-extras understood how to prefix each
- -- line it was laying out.
- displayIO h $ prefixSD "# " $ renderPretty 1.0 100
- $ (prettySpanLoc $ r_span r) <> line
- hPutStrLn h $ "# EvalIx: " ++ (show mn)
- hPutStrLn h $ "# Cost: " ++ (show c)
-
-printInitializer :: Handle -> Rule -> Actions PyDopeBS -> IO ()
-printInitializer fh rule@(Rule _ h _ r _ _ ucruxes _) dope = do
+printPlanHeader :: Rule -> Cost -> Maybe Int -> Doc e
+printPlanHeader r c mn = do
+ vcat ["'''"
+ , "Span: " <+> (prettySpanLoc $ r_span r)
+ , "RuleIx:" <+> (pretty $ r_index r)
+ , "EvalIx:" <+> (pretty mn)
+ , "Cost: " <+> (pretty c)
+ , "'''"]
+
+printInitializer :: Handle -> Rule -> Cost -> Actions PyDopeBS -> IO ()
+printInitializer fh rule@(Rule _ h _ r _ _ ucruxes _) cost dope = do
displayIO fh $ renderPretty 1.0 100
$ "@initializer" <> parens (uncurry pfa $ MA.fromJust $ findHeadFA h ucruxes)
- `above` "def" <+> char '_' <> tupled ["emit"] <+> colon
+ `above` "def" <+> char '_' <> tupled ["emit"] <> colon
+ `above` (indent 4 $ printPlanHeader rule cost Nothing)
`above` pdope dope
<> line
-- XXX INDIR EVAL
-printUpdate :: Handle -> Rule -> Maybe DFunctAr -> (DVar, DVar) -> Actions PyDopeBS -> IO ()
-printUpdate fh rule@(Rule _ h _ r _ _ _ _) (Just (f,a)) (hv,v) dope = do
+printUpdate :: Handle -> Rule -> Cost -> Int -> Maybe DFunctAr -> (DVar, DVar) -> Actions PyDopeBS -> IO ()
+printUpdate fh rule@(Rule _ h _ r _ _ _ _) cost evalix (Just (f,a)) (hv,v) dope = do
displayIO fh $ renderPretty 1.0 100
$ "@register" <> parens (pfa f a)
- `above` "def" <+> char '_' <> tupled (map pretty [hv,v,"emit"]) <+> colon
+ `above` "def" <+> char '_' <> tupled (map pretty [hv,v,"emit"]) <> colon
+ `above` (indent 4 $ printPlanHeader rule cost (Just evalix))
`above` pdope dope
<> line
hPutStrLn fh ""
hPutStrLn fh $ "# " ++ show fa
forM_ ps $ \(r,n,c,vi,vo,act) -> do
- printPlanHeader fh r c (Just n)
- printUpdate fh r fa (vi,vo) act
+ printUpdate fh r c n fa (vi,vo) act
hPutStrLn fh ""
hPutStrLn fh $ "# ==Initializers=="
forM_ is $ \(r,c,a) -> do
- printPlanHeader fh r c Nothing
- printInitializer fh r a
+ printInitializer fh r c a
{-
hPutStrLn fh $ "# ==Queries=="
print >> f, 'digraph rule {'
print >> f, 'rankdir=LR;' # left-to-right layout
-
print >> f, 'node [style=filled,fillcolor=white];'
print >> f, 'bgcolor="transparent";'
print >> html, '<h2>Update code</h2>'
- for block in re.split('# --\n', code)[1:]: # drop the begining bit.
- [(f, bline, bcol, eline, ecol, code)] = \
- re.findall('# (.*?):(\d+):(\d+)-.*?:(\d+):(\d+)\n#.*\n([\w\W]*)',
+ for block in re.split('\n\s*\n', code):
+
+ x = re.findall('Span:\s*(.*?):(\d+):(\d+)-.*?:(\d+):(\d+)\n',
block)
- code = re.compile('^\s*#.*', re.M).sub('', code.strip())
+ print '-------------------'
+ print block
+ print x
+ if not x:
+ continue
+
+ [(f, bline, bcol, eline, ecol)] = x
+ code = block
lexer = get_lexer_by_name("python", stripall=True)
formatter = HtmlFormatter(linenos=False)
pretty_code = highlight(code, lexer, formatter)
-#
print >> html, """\
<div class="handler-%s">
<pre>
""" % (bline, pretty_code)
print >> html, '</pre>'
-
print >> html, '</div>'
if browser:
- os.system('gnome-open %s 2>/dev/null >/dev/null' % html.name)
+ #os.system('gnome-open %s 2>/dev/null >/dev/null' % html.name)
+ import webbrowser
+ webbrowser.open(html.name)
-import math, operator
-from collections import defaultdict, Counter
+import operator
+from collections import Counter
from utils import red
# remove the 'u' prefix on user variables 'uX'
# Note: We also ignore user variables with an underscore prefix
-
+
return tuple((name[1:], val) for name, val in variables.items() if name.startswith('u') and not name.startswith('u_'))
#!/usr/bin/env python
"""
-
MISC
====
+ - TODO: mode planning failures are slient.
+
- TODO: create an Interpreter object to hold state.
- TODO: deleting a rule: (1) remove update handlers (2) run initializers in
- TODO: transactions for errors.
+ - TODO: Numeric precision is an issue with BAggregators.
+
+ a[0.1] += 1
+ a[0.1 + eps] -= 1
+
+ Approaches:
+ - arbitrary precision arithmetic
-PARSER
-======
+ - approximate deletion ("buckets"), find the nearest neighbor and delete it.
- - TODO: Nested expressions:
+ - hybrid: maintain streaming sum and the bag check periodically for quality
+ and null.
- out(0) dict= _VALUE is (rewrite(X,Y) + rewrite(X,Y,Z)), _VALUE.
+ - numeric approximations, stream folding (fails to get null)
- FATAL: Encountered error in input program:
- Parser error
- /tmp/tmp.dyna:1:14: error: expected: "."
- rewrite(X,Y) + rewrite(X,Y,Z)<EOF>
- ^
+ - delete the hyperedge: not sure this is perfect because hyperedges aren't
+ named with numeric values of variables.
What is null?
- TODO: (Aggregator conflicts)
- The good: we throw and AggregatorConflict exception if newly loaded code
- tries to overwrite an aggregator in `agg_decl`.
+ We throw and AggregatorConflict exception if newly loaded code tries to
+ overwrite an aggregator in `agg_decl`.
However, we need to make sure that we don't load subsequent code pertaining
to this rule that we should reject altogether.
The reason we have to support error is because the system might need to go
through an error state before it can reach it's fixed out. In order to be
- invariant to execution order (preserve our semantice) we to need to have the
+ invariant to execution order (preserve our semantics) we to need to have the
ability fo reach pass thru an error state.
for example:
timv: This isn't sufficiently motivating because we can just leave `a` as
`null` until we pass the divide by zero error.
-
-
-
"""
from __future__ import division
e = re.compile('^\s*;.*?\n', re.M).sub('', e) # remove comments
es, stack = [], []
- for token in re.split(r'([()])|\s+', e):
+ for token in re.split(r'("[^"]*?"|[()])|\s+', e):
if token == '(':
new = []
if stack: