]> hydra-www.ietfng.org Git - dyna2/commitdiff
fixed test/repl test cases.
authortimv <tim.f.vieira@gmail.com>
Wed, 12 Jun 2013 17:31:03 +0000 (13:31 -0400)
committertimv <tim.f.vieira@gmail.com>
Wed, 12 Jun 2013 17:31:03 +0000 (13:31 -0400)
 - repl no longer overwrites `~/.dyna/tmp.dyna` and `~/.dyna/tmp.dyna.plan.py`
   Now uses a file in `~/dyna/tmp/` with file name based on sha1 hash of
   necessary code (which includes parser_state pragmas, of course)

src/Dyna/Backend/Python/interpreter.py
src/Dyna/Backend/Python/repl.py
test/repl/aggregator-conflict.expect
test/repl/retract-rule.expect

index 0cab7ae7f7813d571809dda112ff7eff06da5922..fabd396c7c0dc4cfc0f570194817a5fc79d98644 100644 (file)
@@ -197,6 +197,8 @@ import os, sys
 from collections import defaultdict
 from argparse import ArgumentParser
 
+from hashlib import sha1
+
 import debug
 from chart import Chart, Term, _repr
 from defn import aggregator
@@ -525,8 +527,15 @@ class Interpreter(object):
 
         raises ``DynaCompilerError``
         """
+        x = sha1()
+        x.update(self.parser_state)
+        x.update(code)
+
+        dyna = dotdynadir / 'tmp' / ('%s.dyna' % x.hexdigest())
+
+        # make necessary directories
+        dyna.dirname().mkdir_p()
 
-        dyna = dotdynadir / 'tmp.dyna'
         out = '%s.plan.py' % dyna
 
         with file(dyna, 'wb') as f:
index 046adc765af9999c16a5ce696fa4d1192e433a1a..1de1e455fdc0f17a1088dd564e75e81fd301e744 100644 (file)
@@ -18,7 +18,6 @@ class REPL(cmd.Cmd, object):
             with file(hist, 'wb') as f:
                 f.write('')
         readline.read_history_file(hist)
-        self.do_trace('off')
         self.lineno = 0
 
     @property
@@ -65,16 +64,8 @@ class REPL(cmd.Cmd, object):
     def do_ip(self, _):
         ip()
 
-    def do_trace(self, args):
-        if args == 'on':
-            self.interp.trace = sys.stdout
-        elif args == 'off':
-            self.interp.trace = file(os.devnull, 'w')
-        else:
-            print 'Did not understand argument %r please use (on or off).' % args
-
     def do_debug(self, line):
-        with file(dotdynadir / 'tmp.dyna', 'wb') as f:
+        with file(dotdynadir / 'repl-debug-line.dyna', 'wb') as f:
             f.write(line)
         debug.main(f.name)
 
index 3238426141d36e1e49530c732adf445c610d3402..34bdc95b0c8e80eed97eceab3b45d7f0b25aefca 100644 (file)
@@ -1,6 +1,10 @@
 :- :- =============
 a := 1
 
-:- AggregatorConflict: Aggregator conflict 'a/0' was '+=' trying to set to '|='.
+:- DynaCompilerError:
+FATAL: Encountered error in input program:
+ Conflicting aggregators; rule /home/timv/.dyna/tmp/966093dc38b755a6f17b02774b5c656931163a3a.dyna:5:1-/home/timv/.dyna/tmp/966093dc38b755a6f17b02774b5c656931163a3a.dyna:5:3
+ uses '|=' for a/0 but I had been lead to expect '+='.
+
 > new rule(s) were not added to program.
 :- exit
index 155280757a0609913379e3feb9462fcd83bfd989..c4c5012036a72535a80d8f1c1abeb62ff71ff9f6 100644 (file)
@@ -7,8 +7,8 @@ b := 1
 :- =============
 a := 2
 
-:-   0: 
-  1: a += 1.
+:-   0: a += 1.
+  1: b += 1.
   2: a += 1.
 :- 
 Charts