[pypy-svn] r31234 - in pypy/dist/pypy/objspace: cclp cclp/constraint test

auc at codespeak.net auc at codespeak.net
Thu Aug 10 17:41:01 CEST 2006


Author: auc
Date: Thu Aug 10 17:40:58 2006
New Revision: 31234

Modified:
   pypy/dist/pypy/objspace/cclp/constraint/constraint.py
   pypy/dist/pypy/objspace/cclp/space.py
   pypy/dist/pypy/objspace/cclp/thunk.py
   pypy/dist/pypy/objspace/cclp/types.py
   pypy/dist/pypy/objspace/cclp/variable.py
   pypy/dist/pypy/objspace/test/test_logicobjspace.py
Log:
merge -- we can solve what does not need cloning


Modified: pypy/dist/pypy/objspace/cclp/constraint/constraint.py
==============================================================================
--- pypy/dist/pypy/objspace/cclp/constraint/constraint.py	(original)
+++ pypy/dist/pypy/objspace/cclp/constraint/constraint.py	Thu Aug 10 17:40:58 2006
@@ -16,7 +16,6 @@
 from pypy.objspace.constraint.btree import BTree
 from pypy.objspace.constraint.util import sort, reverse
 
-
 all_mms = {}
 
 
@@ -127,7 +126,7 @@
             domain = variable.w_dom
             values = domain.get_values()
             variables.append((domain.size(), [variable.w_name(), values, 0, len(values)]))
-            #kwargs.content[variable.w_name()] = values[0]
+            kwargs.content[variable.w_name()] = values[0]
         # sort variables to instanciate those with fewer possible values first
         sort(variables)
         self._assign_values_state = variables

Modified: pypy/dist/pypy/objspace/cclp/space.py
==============================================================================
--- pypy/dist/pypy/objspace/cclp/space.py	(original)
+++ pypy/dist/pypy/objspace/cclp/space.py	Thu Aug 10 17:40:58 2006
@@ -62,7 +62,9 @@
         self._choice = newvar(space)
         self._committed = newvar(space)
         # merging
+        self._solution = newvar(space)
         self._merged = newvar(space)
+        
 
     def w_ask(self):
         scheduler[0].wait_stable(self)
@@ -101,7 +103,7 @@
 
     def w_merge(self):
         self.space.bind(self._merged, self.space.w_True)
-
+        return self._solution
 
 
 

Modified: pypy/dist/pypy/objspace/cclp/thunk.py
==============================================================================
--- pypy/dist/pypy/objspace/cclp/thunk.py	(original)
+++ pypy/dist/pypy/objspace/cclp/thunk.py	Thu Aug 10 17:40:58 2006
@@ -4,7 +4,7 @@
 from pypy.objspace.cclp.misc import w
 from pypy.objspace.cclp.global_state import scheduler
 from pypy.objspace.cclp.types import W_Var, W_Future, W_FailedValue
-from pypy.objspace.cclp.interp_var import interp_wait, interp_entail
+from pypy.objspace.cclp.interp_var import interp_wait, interp_entail, interp_bind
 
 
 def logic_args(args):
@@ -92,6 +92,7 @@
                 self.space.bind(cspace._choice, self.space.wrap(SPACE_FAILURE))
             else:
                 w(".% clean (valueless) EXIT of", str(id(self._coro)))
+                self.space.bind(cspace._solution, self.costate.w_tempval)
                 self.space.bind(cspace._choice, self.space.wrap(SPACE_SOLUTION))
         finally:
             scheduler[0].remove_thread(self._coro)
@@ -107,17 +108,25 @@
 
     def call(self):
         try:
-            while 1:
-                entailed = self.const.revise()
-                if entailed:
-                    break
-                Obs = W_Var(self.space)
-                interp_entail(self.space, self.Merged, Obs)
-                for Sync in [var.w_dom.give_synchronizer()
-                             for var in self.const._variables]:
-                    interp_entail(self.space, Sync, Obs)
-                interp_wait(self.space, Obs)
+            try:
+                while 1:
+                    entailed = self.const.revise()
+                    if entailed:
+                        break
+                    Obs = W_Var(self.space)
+                    interp_entail(self.space, self.Merged, Obs)
+                    for Sync in [var.w_dom.give_synchronizer()
+                                 for var in self.const._variables]:
+                        interp_entail(self.space, Sync, Obs)
+                    interp_wait(self.space, Obs)
+            except:
+                import traceback
+                traceback.print_exc()
         finally:
+            # all values of dom size 1 are bound
+            for var in self.const._variables:
+                if var.w_dom.size() == 1:
+                    interp_bind(self.space, var, var.w_dom.get_values()[0])
             self.coro._dead = True
             scheduler[0].remove_thread(self.coro)
             scheduler[0].schedule()

Modified: pypy/dist/pypy/objspace/cclp/types.py
==============================================================================
--- pypy/dist/pypy/objspace/cclp/types.py	(original)
+++ pypy/dist/pypy/objspace/cclp/types.py	Thu Aug 10 17:40:58 2006
@@ -69,8 +69,7 @@
     def __init__(self, object_space):
         self._space = object_space
 
-W_Constraint.typedef = typedef.TypeDef(
-    "W_Constraint")
+W_Constraint.typedef = typedef.TypeDef("W_Constraint")
 
 class W_AbstractDomain(baseobjspace.Wrappable):
     """Implements the functionnality related to the changed flag.

Modified: pypy/dist/pypy/objspace/cclp/variable.py
==============================================================================
--- pypy/dist/pypy/objspace/cclp/variable.py	(original)
+++ pypy/dist/pypy/objspace/cclp/variable.py	Thu Aug 10 17:40:58 2006
@@ -26,7 +26,7 @@
     return w_obj
 
 def wait__Var(space, w_var):
-    w(":wait", str(id(ClonableCoroutine.w_getcurrent(space))))
+    #w(":wait", str(id(ClonableCoroutine.w_getcurrent(space))))
     if space.is_true(space.is_free(w_var)):
         scheduler[0].unblock_byneed_on(w_var)
         scheduler[0].add_to_blocked_on(w_var, ClonableCoroutine.w_getcurrent(space))
@@ -51,7 +51,7 @@
 #-- Wait_needed --------------------------------------------
 
 def wait_needed__Var(space, w_var):
-    w(":wait_needed", str(id(ClonableCoroutine.w_getcurrent(space))))
+    #w(":wait_needed", str(id(ClonableCoroutine.w_getcurrent(space))))
     if space.is_true(space.is_free(w_var)):
         if w_var.needed:
             return

Modified: pypy/dist/pypy/objspace/test/test_logicobjspace.py
==============================================================================
--- pypy/dist/pypy/objspace/test/test_logicobjspace.py	(original)
+++ pypy/dist/pypy/objspace/test/test_logicobjspace.py	Thu Aug 10 17:40:58 2006
@@ -781,19 +781,21 @@
         def problem():
             X, Y = domain([1, 2], 'X'), domain([1, 2, 3], 'Y')
             tell(make_expression([X, Y], 'X + Y > 4'))
+            return (X, Y)
 
         def solve(spc, X):
             while 1:
                 status = spc.ask()
                 if status == 1:
-                    unify(X, status)
                     break
-            spc.merge()
+            unify(spc.merge(), X)
 
         s = newspace(problem)
-        Finished = newvar()
-        stacklet(solve, s, Finished)
-        wait(Finished)
+        Solution = newvar()
+        stacklet(solve, s, Solution)
 
         schedule()
+
+        assert Solution == (2, 3)
+
         assert len(sched_all()['threads']) == 1



More information about the Pypy-commit mailing list