[pypy-svn] r25448 - in pypy/dist/pypy/objspace: . constraint logic
auc at codespeak.net
auc at codespeak.net
Thu Apr 6 15:59:48 CEST 2006
Author: auc
Date: Thu Apr 6 15:59:46 2006
New Revision: 25448
Removed:
pypy/dist/pypy/objspace/logic/
Modified:
pypy/dist/pypy/objspace/constraint/domain.py
pypy/dist/pypy/objspace/logic.py
Log:
domain : set -> dict, intersection as a mm
Modified: pypy/dist/pypy/objspace/constraint/domain.py
==============================================================================
--- pypy/dist/pypy/objspace/constraint/domain.py (original)
+++ pypy/dist/pypy/objspace/constraint/domain.py Thu Apr 6 15:59:46 2006
@@ -1,13 +1,15 @@
from pypy.interpreter.error import OperationError
-from pypy.interpreter import baseobjspace, typedef
+from pypy.interpreter import baseobjspace, typedef, gateway
from pypy.interpreter.baseobjspace import Wrappable
from pypy.interpreter.gateway import interp2app
-from pypy.objspace.std.objspace import W_Object
-
from pypy.objspace.std.listobject import W_ListObject, W_TupleObject
+from pypy.objspace.std.model import StdObjSpaceMultiMethod
+
+
+all_mms = {}
class ConsistencyFailure(Exception):
"""The repository is not in a consistent state"""
@@ -52,14 +54,16 @@
This class uses a dictionnary to make sure that there are
no duplicate values"""
W_AbstractDomain.__init__(self, space)
+ self._values = {}
self.set_values(w_values)
def set_values(self, w_values):
- self._values = set(w_values.wrappeditems)
+ for w_v in w_values.wrappeditems:
+ self._values[w_v] = True
def w_remove_value(self, w_value):
"""Remove value of domain and check for consistency"""
- self._values.remove(w_value)
+ self._values.pop(w_value)
self._value_removed()
def w_remove_values(self, w_values):
@@ -67,7 +71,7 @@
if self._space.is_true(self._space.gt(self._space.len(w_values),
self._space.newint(0))) :
for val in w_values.wrappeditems :
- self._values.remove(val)
+ self._values.pop(val)
self._value_removed()
__delitem__ = w_remove_value
@@ -98,10 +102,19 @@
def __ne__(self, w_other):
return not self == w_other
- # FIXME: this does not work, but we don't need it yet
- def w_intersection(self, w_other):
- assert isinstance(w_other, W_FiniteDomain)
- return self._space.newlist([x for x in (set(self.w_get_values()) & set(w_other.w_get_values()))])
+# function bolted into the space to serve as constructor
+def make_fd(space, w_values):
+ return W_FiniteDomain(space, w_values)
+app_make_fd = gateway.interp2app(make_fd)
+
+
+def intersection__FiniteDomain_FiniteDomain(space, w_fd1, w_fd2):
+ return make_fd(w_fd1.w_get_values() + w_fd2.w_get_values())
+
+intersection_mm = StdObjSpaceMultiMethod('intersection', 2)
+intersection_mm.register(intersection__FiniteDomain_FiniteDomain,
+ W_FiniteDomain, W_FiniteDomain)
+all_mms['intersection'] = intersection_mm
W_FiniteDomain.typedef = typedef.TypeDef("W_FiniteDomain",
W_AbstractDomain.typedef,
@@ -109,5 +122,5 @@
remove_values = interp2app(W_FiniteDomain.w_remove_values),
get_values = interp2app(W_FiniteDomain.w_get_values),
copy = interp2app(W_FiniteDomain.w_copy),
-# intersection = interp2app(W_FiniteDomain.w_intersection),
size = interp2app(W_FiniteDomain.w_size))
+
Modified: pypy/dist/pypy/objspace/logic.py
==============================================================================
--- pypy/dist/pypy/objspace/logic.py (original)
+++ pypy/dist/pypy/objspace/logic.py Thu Apr 6 15:59:46 2006
@@ -551,7 +551,7 @@
def unify__Root_Root(space, w_x, w_y):
if not space.eq_w(w_x, w_y):
- w_d1 = w_x.getdict()
+ w_d1 = w_x.getdict() #returns wrapped dict or unwrapped None ...
w_d2 = w_y.getdict()
if None in [w_d1, w_d2]:
fail(space, w_x, w_y)
@@ -753,15 +753,11 @@
return proxy
-#------ constraints -----------------
+#------ domains -----------------
-## from pypy.objspace.constraint import domain
+from pypy.objspace.constraint import domain
+all_mms.update(domain.all_mms)
-## W_FiniteDomain = domain.W_FiniteDomain
-
-## def make_fd(space, w_values):
-## return domain.W_FiniteDomain(space, w_values)
-## app_make_fd = gateway.interp2app(make_fd)
#-- THE SPACE ---------------------------------------
@@ -813,8 +809,8 @@
space.wrap(app_alias_of))
space.setitem(space.builtin.w_dict, space.wrap('is_aliased'),
space.wrap(app_is_aliased))
-## space.setitem(space.builtin.w_dict, space.wrap('FiniteDomain'),
-## space.wrap(app_make_fd))
+ space.setitem(space.builtin.w_dict, space.wrap('FiniteDomain'),
+ space.wrap(domain.app_make_fd))
space.setitem(space.builtin.w_dict, space.wrap('bind'),
space.wrap(app_bind))
space.setitem(space.builtin.w_dict, space.wrap('unify'),
@@ -844,8 +840,3 @@
return space
-
-
-
-
-
More information about the Pypy-commit
mailing list