]> hydra-www.ietfng.org Git - dyna2/commitdiff
Chart does not need update method thanks to the new Term objects.
authortimv <tim.f.vieira@gmail.com>
Mon, 3 Jun 2013 02:23:32 +0000 (22:23 -0400)
committertimv <tim.f.vieira@gmail.com>
Mon, 3 Jun 2013 02:23:32 +0000 (22:23 -0400)
src/Dyna/Backend/Python/interpreter.py
src/Dyna/Backend/Python/utils.py

index 50049a96e628cb6a383af301fbf1b1abf04059ac..06aff799f52ac5106d334d05b655413991a16e8e 100644 (file)
@@ -123,13 +123,14 @@ import os, sys
 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):
@@ -174,10 +175,6 @@ def dump_charts(out=sys.stdout):
         print >> out
 
 
-def notimplemented(*_,**__):
-    raise NotImplementedError
-
-
 # TODO: codegen should output a derive Term instance for each functor
 class Term(namedtuple('Term', 'fn args'), object):
 
@@ -261,32 +258,17 @@ class Chart(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)
 
@@ -294,13 +276,13 @@ class Chart(object):
         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
index 91a3f8e631293620515eb0df147878131328bc5d..c6313b52c5f0cf2bd9366c7d27817a2b9db9da50 100644 (file)
@@ -6,8 +6,10 @@ ip = InteractiveShellEmbed(banner1 = 'Dropping into IPython\n')
 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.
@@ -58,3 +60,8 @@ def read_anf(e):
                g(evals[1:]),
                g(unifs[1:]),
                result)
+
+
+def notimplemented(*_,**__):
+    raise NotImplementedError
+