[pypy-svn] r14167 - in pypy/dist/pypy/rpython: . test
arigo at codespeak.net
arigo at codespeak.net
Sun Jul 3 18:43:59 CEST 2005
Author: arigo
Date: Sun Jul 3 18:43:56 2005
New Revision: 14167
Added:
pypy/dist/pypy/rpython/remptydict.py (contents, props changed)
pypy/dist/pypy/rpython/test/test_remptydict.py (contents, props changed)
Modified:
pypy/dist/pypy/rpython/rdict.py
Log:
We need to support empty dictionaries for PyPy :-)
Modified: pypy/dist/pypy/rpython/rdict.py
==============================================================================
--- pypy/dist/pypy/rpython/rdict.py (original)
+++ pypy/dist/pypy/rpython/rdict.py Sun Jul 3 18:43:56 2005
@@ -3,7 +3,7 @@
from pypy.objspace.flow.model import Constant
from pypy.rpython import rmodel, lltype, rstr
from pypy.rpython.rarithmetic import r_uint
-from pypy.rpython import rlist, rconstantdict
+from pypy.rpython import rlist, rconstantdict, remptydict
# ____________________________________________________________
#
@@ -39,6 +39,8 @@
return rconstantdict.ConstantDictRepr(
rtyper.getrepr(dictkey.s_value),
rtyper.getrepr(dictvalue.s_value))
+ elif isinstance(s_key, annmodel.SomeImpossibleValue):
+ return remptydict.EmptyDictRepr()
else:
raise rmodel.TyperError("cannot make repr of %r" %(self.dictdef,))
Added: pypy/dist/pypy/rpython/remptydict.py
==============================================================================
--- (empty file)
+++ pypy/dist/pypy/rpython/remptydict.py Sun Jul 3 18:43:56 2005
@@ -0,0 +1,14 @@
+from pypy.annotation.pairtype import pairtype
+from pypy.annotation import model as annmodel
+from pypy.rpython import rmodel, lltype
+
+# ____________________________________________________________
+#
+# PyPy uses dictionaries that are known to be empty at run-time!
+# look for 'lazyloaders'.
+
+class EmptyDictRepr(rmodel.Repr):
+ lowleveltype = lltype.Void
+
+ def rtype_len(self, hop):
+ return hop.inputconst(lltype.Signed, 0)
Added: pypy/dist/pypy/rpython/test/test_remptydict.py
==============================================================================
--- (empty file)
+++ pypy/dist/pypy/rpython/test/test_remptydict.py Sun Jul 3 18:43:56 2005
@@ -0,0 +1,12 @@
+import py
+from pypy.rpython.test.test_llinterp import interpret
+
+def test_empty_dict():
+ class A:
+ pass
+ a = A()
+ a.d = {}
+ def func():
+ return bool(a.d)
+ res = interpret(func, [])
+ assert res is False
More information about the Pypy-commit
mailing list