from collections import defaultdict, namedtuple
from argparse import ArgumentParser
-from utils import ip, red, green, blue, magenta, yellow, dynahome
+from utils import ip, red, green, blue, magenta, yellow, dynahome, notimplemented
from defn import aggregator
class AggregatorConflict(Exception):
pass
+
# TODO: as soon as we have safe names for these things we can get rid of this.
class chart_indirect(dict):
def __missing__(self, key):
print >> out
-def notimplemented(*_,**__):
- raise NotImplementedError
-
-
# TODO: codegen should output a derive Term instance for each functor
class Term(namedtuple('Term', 'fn args'), object):
if term.value == val:
yield term.args + (term.value,)
-
def lookup(self, args):
"find index for these args"
- assert len(args) == self.ncols - 1 # XXX: lookup doesn't want val?
-
- assert isinstance(args, tuple) and not isinstance(args, Term)
+ assert len(args) == self.ncols - 1
try:
return self.intern[args]
except KeyError:
return None
- def update(self, ix, args, val):
- "Update chart"
-
- assert len(args) == self.ncols - 1
- assert isinstance(args, tuple) and not isinstance(args, Term)
-
- term = self.intern[args]
- term.value = val
- return term
-
def insert(self, args, val):
- assert isinstance(args, tuple) and not isinstance(args, Term)
-
# debugging check: row is not already in chart.
assert self.lookup(args) is None, '%r already in chart with value %r' % (args, val)
term.value = val
term.aggregator = aggregator(agg_decl[self.name])
+ # indexes new term
for i, x in enumerate(args):
self.ix[i][x].add(term)
return term
-
def build(fn, *args):
if fn == "true/0": # TODO: I'd rather have the codegen ensure true/0 is True and false/0 is False
return True
black, red, green, yellow, blue, magenta, cyan, white = \
map('\033[3%sm%%s\033[0m'.__mod__, range(8))
+
dynahome = os.getenv('DYNAHOME', '.')
+
def parse_sexpr(e):
"""
Parse a string representing an s-expressions into lists-of-lists.
g(evals[1:]),
g(unifs[1:]),
result)
+
+
+def notimplemented(*_,**__):
+ raise NotImplementedError
+