[pypy-svn] r32866 - in pypy/dist/pypy/objspace/cclp: . constraint

auc at codespeak.net auc at codespeak.net
Wed Oct 4 13:40:51 CEST 2006


Author: auc
Date: Wed Oct  4 13:40:48 2006
New Revision: 32866

Modified:
   pypy/dist/pypy/objspace/cclp/constraint/distributor.py
   pypy/dist/pypy/objspace/cclp/space.py
   pypy/dist/pypy/objspace/cclp/thunk.py
Log:
translatable again


Modified: pypy/dist/pypy/objspace/cclp/constraint/distributor.py
==============================================================================
--- pypy/dist/pypy/objspace/cclp/constraint/distributor.py	(original)
+++ pypy/dist/pypy/objspace/cclp/constraint/distributor.py	Wed Oct  4 13:40:48 2006
@@ -27,17 +27,10 @@
 
     dist = cspace.distributor
     # constraint distributor thread main loop
-    try:
-        while dist.distributable():
-            choice = cspace.choose(dist.fanout())
-            dist.w_distribute(choice)
-    except ConsistencyError, e:
-        w("-- DISTRIBUTOR thunk exited because", str(e))
-        cspace.fail()
-    except Exception, eek:
-        if not we_are_translated():
-            import traceback
-            traceback.print_exc()
+    while dist.distributable():
+        choice = cspace.choose(dist.fanout())
+        dist.w_distribute(choice)
+            
 app_distribute = interp2app(distribute)
 
 

Modified: pypy/dist/pypy/objspace/cclp/space.py
==============================================================================
--- pypy/dist/pypy/objspace/cclp/space.py	(original)
+++ pypy/dist/pypy/objspace/cclp/space.py	Wed Oct  4 13:40:48 2006
@@ -3,6 +3,7 @@
 from pypy.interpreter.error import OperationError
 
 from pypy.objspace.std.intobject import W_IntObject
+from pypy.objspace.std.listobject import W_ListObject, W_TupleObject
 
 from pypy.objspace.cclp.misc import ClonableCoroutine, get_current_cspace, w
 from pypy.objspace.cclp.thunk import CSpaceThunk, PropagatorThunk
@@ -85,8 +86,6 @@
         self._store = {} # name -> var
         if not we_are_translated():
             self._constraints = []
-            self._choose_count = 0
-            self._commit_count = 0
         
     def register_var(self, cvar):
         self._store[cvar.name] = cvar
@@ -148,14 +147,9 @@
         return committed
 
     def w_commit(self, w_n):
-        self._commit_count += 1
-        #scheduler[0].wait_stable(self)
-        self._commit_count += 1
         assert isinstance(w_n, W_IntObject)
         n = w_n.intval
-        if not interp_free(self._committed):
-            import pdb
-            pdb.set_trace()
+        assert interp_free(self._committed)
         assert n > 0
         assert n <= self._last_choice
         interp_bind(self._committed, w_n)
@@ -182,13 +176,10 @@
         self._store = {}
         # let's bind the solution variables
         sol = self._solution.w_bound_to
-        if contains_cvar(sol.wrappeditems):
-            for var in sol.wrappeditems:
-                assert isinstance(var, W_CVar)
-                dom = var.w_dom
-                assert isinstance(dom, W_AbstractDomain)
-                assert dom.size() == 1
-                interp_bind(var, dom.get_values()[0])
+        if isinstance(sol, W_ListObject):
+            bind_solution_variables(sol.wrappeditems)
+        elif isinstance(sol, W_TupleObject):
+            bind_solution_variables(sol.wrappeditems)
         return self._solution
 
     def __ne__(self, other):
@@ -197,6 +188,16 @@
         return True
 
 
+def bind_solution_variables(solution):
+    if contains_cvar(solution): # was a constraint script
+        for var in solution:
+            assert isinstance(var, W_CVar)
+            dom = var.w_dom
+            assert isinstance(dom, W_AbstractDomain)
+            assert dom.size() == 1
+            interp_bind(var, dom.get_values()[0])
+
+
 def contains_cvar(lst):
     for elt in lst:
         if isinstance(elt, W_CVar):

Modified: pypy/dist/pypy/objspace/cclp/thunk.py
==============================================================================
--- pypy/dist/pypy/objspace/cclp/thunk.py	(original)
+++ pypy/dist/pypy/objspace/cclp/thunk.py	Wed Oct  4 13:40:48 2006
@@ -40,7 +40,6 @@
             except Exception, exc:
                 w(".! exceptional EXIT of procedure", str(id(self._coro)), "with", str(exc))
                 scheduler[0].dirty_traced_vars(self._coro, W_FailedValue(exc))
-                self._coro._dead = True
             else:
                 w(".! clean EXIT of procedure", str(id(self._coro)))
         finally:
@@ -65,7 +64,6 @@
                 failed_val = W_FailedValue(exc)
                 self.space.bind(self.w_Result, failed_val)
                 scheduler[0].dirty_traced_vars(self._coro, failed_val)
-                self._coro._dead = True
             else:
                 w(".! clean EXIT of future", str(id(self._coro)),
                   "-- setting future result", str(self.w_Result), "to",
@@ -92,29 +90,24 @@
                 _AppThunk.call(self)
             except Exception, exc:
                 # maybe app_level let something buble up ...
-                w("-- exceptional EXIT of cspace DISTRIBUTOR", str(id(self._coro)), "with", str(exc))
+                w("-- exceptional EXIT of DISTRIBUTOR", str(id(self._coro)), "with", str(exc))
                 failed_value = W_FailedValue(exc)
                 scheduler[0].dirty_traced_vars(self._coro, failed_value)
                 interp_bind(cspace._solution, failed_value)
                 cspace.fail()
             else:
                 w("-- clean EXIT of DISTRIBUTOR (success)", str(id(self._coro)))
-                try:
-                    sol = cspace._solution
-                    assert isinstance(sol, W_Var)
-                    interp_bind(sol, self.costate.w_tempval)
-                    outcome = sol.w_bound_to
-                    if not (isinstance(outcome, W_ListObject) or \
-                            isinstance(outcome, W_TupleObject)):
-                        w("WARINING: return value type of the script was not a list or tuple, we do nothing ...")
-                        return
-                    assert interp_free(cspace._choice)
-                    interp_bind(cspace._choice, self.space.newint(1))
-                except Exception, foo:
-                    print "WE DIED BECAUSE", str(foo)
-                    import pdb
-                    pdb.set_trace()
-                
+                sol = cspace._solution
+                assert isinstance(sol, W_Var)
+                interp_bind(sol, self.costate.w_tempval)
+                outcome = sol.w_bound_to
+                if not (isinstance(outcome, W_ListObject) or \
+                        isinstance(outcome, W_TupleObject)):
+                    w("WARNING: return value type of the script was not a list or tuple, we fail ...")
+                    cspace.fail()
+                    return
+                assert interp_free(cspace._choice)
+                interp_bind(cspace._choice, self.space.newint(1))
         finally:
             interp_bind(cspace._finished, self.space.w_True)
             scheduler[0].remove_thread(self._coro)
@@ -156,7 +149,6 @@
                     import traceback
                     traceback.print_exc()
         finally:
-            self.coro._dead = True
             scheduler[0].remove_thread(self.coro)
             scheduler[0].schedule()
 



More information about the Pypy-commit mailing list