[pypy-svn] r77787 - in pypy/branch/32ptr-on-64bit/pypy/rpython: . lltypesystem test
arigo at codespeak.net
arigo at codespeak.net
Mon Oct 11 14:37:19 CEST 2010
Author: arigo
Date: Mon Oct 11 14:37:17 2010
New Revision: 77787
Modified:
pypy/branch/32ptr-on-64bit/pypy/rpython/llinterp.py
pypy/branch/32ptr-on-64bit/pypy/rpython/lltypesystem/lltype.py
pypy/branch/32ptr-on-64bit/pypy/rpython/lltypesystem/rcompressed.py
pypy/branch/32ptr-on-64bit/pypy/rpython/lltypesystem/rdict.py
pypy/branch/32ptr-on-64bit/pypy/rpython/lltypesystem/rlist.py
pypy/branch/32ptr-on-64bit/pypy/rpython/lltypesystem/rstr.py
pypy/branch/32ptr-on-64bit/pypy/rpython/rmodel.py
pypy/branch/32ptr-on-64bit/pypy/rpython/rtuple.py
pypy/branch/32ptr-on-64bit/pypy/rpython/test/test_rcompressed.py
pypy/branch/32ptr-on-64bit/pypy/rpython/test/test_rdict.py
Log:
Tests and fixes.
Modified: pypy/branch/32ptr-on-64bit/pypy/rpython/llinterp.py
==============================================================================
--- pypy/branch/32ptr-on-64bit/pypy/rpython/llinterp.py (original)
+++ pypy/branch/32ptr-on-64bit/pypy/rpython/llinterp.py Mon Oct 11 14:37:17 2010
@@ -1445,7 +1445,7 @@
from pypy.rpython.lltypesystem import llarena
try:
result = llarena.getfakearenaaddress(result)
- except RuntimeError:
+ except (RuntimeError, AttributeError): # xxx bad style
pass
# the GC should never see instances of _gctransformed_wref
result = self.unwrap_possible_weakref(result)
Modified: pypy/branch/32ptr-on-64bit/pypy/rpython/lltypesystem/lltype.py
==============================================================================
--- pypy/branch/32ptr-on-64bit/pypy/rpython/lltypesystem/lltype.py (original)
+++ pypy/branch/32ptr-on-64bit/pypy/rpython/lltypesystem/lltype.py Mon Oct 11 14:37:17 2010
@@ -542,6 +542,9 @@
class ForwardReference(ContainerType):
_gckind = 'raw'
+ def __init__(self, will_be_varsize=False):
+ self._will_be_varsize = will_be_varsize
+
def become(self, realcontainertype):
if not isinstance(realcontainertype, ContainerType):
raise TypeError("ForwardReference can only be to a container, "
@@ -549,12 +552,22 @@
if realcontainertype._gckind != self._gckind:
raise TypeError("become() gives conflicting gckind, use the "
"correct XxForwardReference")
+ if realcontainertype._is_varsize() != self._will_be_varsize:
+ raise TypeError("become() between non-varsize and varsize "
+ "containers -- initialize the ForwardReference "
+ "correctly")
self.__class__ = realcontainertype.__class__
self.__dict__ = realcontainertype.__dict__
def __hash__(self):
raise TypeError("%r object is not hashable" % self.__class__.__name__)
+ def _inline_is_varsize(self, last):
+ raise TypeError("%s._inline_is_varsize()" % self.__class__.__name__)
+
+ def _is_varsize(self):
+ return self._will_be_varsize
+
class GcForwardReference(ForwardReference):
_gckind = 'gc'
Modified: pypy/branch/32ptr-on-64bit/pypy/rpython/lltypesystem/rcompressed.py
==============================================================================
--- pypy/branch/32ptr-on-64bit/pypy/rpython/lltypesystem/rcompressed.py (original)
+++ pypy/branch/32ptr-on-64bit/pypy/rpython/lltypesystem/rcompressed.py Mon Oct 11 14:37:17 2010
@@ -38,6 +38,7 @@
class CompressedGcRefRepr(Repr):
lowleveltype = llmemory.HiddenGcRef32
+ ll_eq_function = None
ll_hash_function = None
ll_fasthash_function = None
@@ -53,9 +54,19 @@
return llop.hide_into_ptr32(self.lowleveltype, ptr)
def get_ll_eq_function(self):
- if self.baserepr.get_ll_eq_function() is not None:
- raise TyperError("%r has an eq function" % (self.baserepr,))
- return None
+ if self.ll_eq_function is None:
+ basefunc = self.baserepr.get_ll_eq_function()
+ if basefunc is None:
+ return None
+ BASETYPE = self.BASETYPE
+ #
+ def ll_eq_function(x, y):
+ x = llop.show_from_ptr32(BASETYPE, x)
+ y = llop.show_from_ptr32(BASETYPE, y)
+ return basefunc(x, y)
+ #
+ self.ll_eq_function = ll_eq_function
+ return self.ll_eq_function
def get_ll_hash_function(self):
if self.ll_hash_function is None:
Modified: pypy/branch/32ptr-on-64bit/pypy/rpython/lltypesystem/rdict.py
==============================================================================
--- pypy/branch/32ptr-on-64bit/pypy/rpython/lltypesystem/rdict.py (original)
+++ pypy/branch/32ptr-on-64bit/pypy/rpython/lltypesystem/rdict.py Mon Oct 11 14:37:17 2010
@@ -275,10 +275,14 @@
def _rtype_method_kvi(self, hop, ll_func):
v_dic, = hop.inputargs(self)
+ s_list = hop.s_result
+ s_value = s_list.listdef.listitem.s_value
+ r_value = hop.rtyper.getrepr(s_value)
+ cLISTITEM = hop.inputconst(lltype.Void, r_value.lowleveltype)
r_list = hop.r_result
cLIST = hop.inputconst(lltype.Void, r_list.lowleveltype.TO)
hop.exception_cannot_occur()
- return hop.gendirectcall(ll_func, cLIST, v_dic)
+ return hop.gendirectcall(ll_func, cLIST, cLISTITEM, v_dic)
def rtype_method_keys(self, hop):
return self._rtype_method_kvi(hop, ll_dict_keys)
@@ -778,7 +782,7 @@
return v
def _make_ll_keys_values_items(kind):
- def ll_kvi(LIST, dic):
+ def ll_kvi(LIST, LISTITEM, dic):
res = LIST.ll_newlist(dic.num_items)
entries = dic.entries
dlen = len(entries)
@@ -787,18 +791,18 @@
p = 0
while i < dlen:
if entries.valid(i):
- ELEM = lltype.typeOf(items).TO.OF
- if ELEM is not lltype.Void:
+ if LISTITEM is not lltype.Void:
entry = entries[i]
if kind == 'items':
- r = lltype.malloc(ELEM.TO)
- r.item0 = recast(ELEM.TO.item0, entry.key)
- r.item1 = recast(ELEM.TO.item1, entry.value)
- items[p] = r
+ r = lltype.malloc(LISTITEM.TO)
+ r.item0 = recast(LISTITEM.TO.item0, entry.key)
+ r.item1 = recast(LISTITEM.TO.item1, entry.value)
elif kind == 'keys':
- items[p] = recast(ELEM, entry.key)
+ r = entry.key
elif kind == 'values':
- items[p] = recast(ELEM, entry.value)
+ r = entry.value
+ ELEM = lltype.typeOf(items).TO.OF
+ items[p] = recast(ELEM, r)
p += 1
i += 1
assert p == res.ll_length()
Modified: pypy/branch/32ptr-on-64bit/pypy/rpython/lltypesystem/rlist.py
==============================================================================
--- pypy/branch/32ptr-on-64bit/pypy/rpython/lltypesystem/rlist.py (original)
+++ pypy/branch/32ptr-on-64bit/pypy/rpython/lltypesystem/rlist.py Mon Oct 11 14:37:17 2010
@@ -44,7 +44,8 @@
# known_maxlength is ignored by lltype but used by ootype
def __init__(self, rtyper, item_repr, listitem=None, known_maxlength=False):
self.rtyper = rtyper
- self.LIST = GcForwardReference()
+ will_be_varsize = isinstance(self, FixedSizeListRepr)
+ self.LIST = GcForwardReference(will_be_varsize=will_be_varsize)
self.lowleveltype = Ptr(self.LIST)
if not isinstance(item_repr, Repr): # not computed yet, done by setup()
assert callable(item_repr)
Modified: pypy/branch/32ptr-on-64bit/pypy/rpython/lltypesystem/rstr.py
==============================================================================
--- pypy/branch/32ptr-on-64bit/pypy/rpython/lltypesystem/rstr.py (original)
+++ pypy/branch/32ptr-on-64bit/pypy/rpython/lltypesystem/rstr.py Mon Oct 11 14:37:17 2010
@@ -28,8 +28,8 @@
# chars: array of Char
# }
-STR = GcForwardReference()
-UNICODE = GcForwardReference()
+STR = GcForwardReference(will_be_varsize=True)
+UNICODE = GcForwardReference(will_be_varsize=True)
def new_malloc(TP, name):
def mallocstr(length):
Modified: pypy/branch/32ptr-on-64bit/pypy/rpython/rmodel.py
==============================================================================
--- pypy/branch/32ptr-on-64bit/pypy/rpython/rmodel.py (original)
+++ pypy/branch/32ptr-on-64bit/pypy/rpython/rmodel.py Mon Oct 11 14:37:17 2010
@@ -435,14 +435,16 @@
return alloc_flavor
def externalvsinternal(rtyper, item_repr): # -> external_item_repr, (internal_)item_repr
+ if (rtyper is not None and rtyper.annotator is not None and # in tests
+ rtyper.annotator.translator.config.translation.compressptr):
+ item_repr, internal_item_repr = externalvsinternalfield(rtyper,
+ item_repr)
+ if internal_item_repr is not item_repr:
+ return item_repr, internal_item_repr
+ #
from pypy.rpython import rclass
if (isinstance(item_repr, rclass.AbstractInstanceRepr) and
getattr(item_repr, 'gcflavor', 'gc') == 'gc'):
- if rtyper.annotator.translator.config.translation.compressptr:
- item_repr, internal_item_repr = externalvsinternalfield(rtyper,
- item_repr)
- if internal_item_repr is not item_repr:
- return item_repr, internal_item_repr
return item_repr, rclass.getinstancerepr(rtyper, None)
return item_repr, item_repr
Modified: pypy/branch/32ptr-on-64bit/pypy/rpython/rtuple.py
==============================================================================
--- pypy/branch/32ptr-on-64bit/pypy/rpython/rtuple.py (original)
+++ pypy/branch/32ptr-on-64bit/pypy/rpython/rtuple.py Mon Oct 11 14:37:17 2010
@@ -46,7 +46,7 @@
_gen_eq_function_cache[key] = ll_eq
return ll_eq
-import os
+
def gen_cmp_function(items_r, op_funcs, eq_funcs, strict):
"""generates <= and >= comparison ll_op for tuples
cmp_funcs is a tuple of (strict_comp, equality) functions
Modified: pypy/branch/32ptr-on-64bit/pypy/rpython/test/test_rcompressed.py
==============================================================================
--- pypy/branch/32ptr-on-64bit/pypy/rpython/test/test_rcompressed.py (original)
+++ pypy/branch/32ptr-on-64bit/pypy/rpython/test/test_rcompressed.py Mon Oct 11 14:37:17 2010
@@ -1,6 +1,8 @@
import py
from pypy.config.translationoption import IS_64_BITS
from pypy.rpython.test import test_rclass
+from pypy.rpython import rmodel, rint, rclass
+from pypy.rpython.lltypesystem import llmemory
def setup_module(mod):
@@ -24,6 +26,148 @@
return super(MixinCompressed64, self).interpret_raises(*args, **kwds)
+class TestExternalVsInternal(MixinCompressed64):
+ def setup_method(self, _):
+ class FakeRTyper(object):
+ class annotator:
+ class translator:
+ config = self._get_config()
+ class type_system:
+ from pypy.rpython.lltypesystem import rclass
+ def add_pendingsetup(self, r):
+ pass
+ self.rtyper = FakeRTyper()
+ self.rtyper.instance_reprs = {}
+
+ def get_r_A(self):
+ class FakeClassDesc:
+ pyobj = None
+ def read_attribute(self, name, default):
+ return default
+ class FakeClassDef(object):
+ classdesc = FakeClassDesc()
+ def getallsubdefs(self):
+ return [self]
+ classdef = FakeClassDef()
+ return rclass.getinstancerepr(self.rtyper, classdef)
+
+ def get_r_L(self, itemrepr, fixed=True):
+ from pypy.rpython.lltypesystem import rlist
+ class FakeListItem(object):
+ pass
+ if fixed:
+ cls = rlist.FixedSizeListRepr
+ else:
+ cls = rlist.ListRepr
+ return cls(self.rtyper, itemrepr, FakeListItem())
+
+ def test_simple(self):
+ er, ir = rmodel.externalvsinternal(self.rtyper, rint.signed_repr)
+ assert er is ir is rint.signed_repr
+ er, ir = rmodel.externalvsinternalfield(self.rtyper, rint.signed_repr)
+ assert er is ir is rint.signed_repr
+
+ def test_instance(self):
+ r_A = self.get_r_A()
+ er, ir = rmodel.externalvsinternal(self.rtyper, r_A)
+ assert er is r_A
+ assert ir.lowleveltype == llmemory.HiddenGcRef32
+ er, ir = rmodel.externalvsinternalfield(self.rtyper, r_A)
+ assert er is r_A
+ assert ir.lowleveltype == llmemory.HiddenGcRef32
+
+ def test_fixedlist_of_ints(self):
+ r_L = self.get_r_L(rint.signed_repr)
+ assert r_L.lowleveltype.TO._is_varsize()
+ assert r_L.external_item_repr is rint.signed_repr
+ assert r_L.item_repr is rint.signed_repr
+ er, ir = rmodel.externalvsinternal(self.rtyper, r_L)
+ assert er is ir is r_L
+ er, ir = rmodel.externalvsinternalfield(self.rtyper, r_L)
+ assert er is ir is r_L
+
+ def test_varlist_of_ints(self):
+ r_L = self.get_r_L(rint.signed_repr, fixed=False)
+ assert r_L.external_item_repr is rint.signed_repr
+ assert r_L.item_repr is rint.signed_repr
+ er, ir = rmodel.externalvsinternal(self.rtyper, r_L)
+ assert er is r_L
+ assert ir.lowleveltype == llmemory.HiddenGcRef32
+ er, ir = rmodel.externalvsinternalfield(self.rtyper, r_L)
+ assert er is r_L
+ assert ir.lowleveltype == llmemory.HiddenGcRef32
+
+ def test_fixedlist_of_instance(self):
+ r_A = self.get_r_A()
+ r_L = self.get_r_L(r_A)
+ assert r_L.external_item_repr is r_A
+ assert r_L.item_repr.lowleveltype == llmemory.HiddenGcRef32
+ er, ir = rmodel.externalvsinternal(self.rtyper, r_L)
+ assert er is ir is r_L
+ er, ir = rmodel.externalvsinternalfield(self.rtyper, r_L)
+ assert er is ir is r_L
+
+ def test_varlist_of_instance(self):
+ r_A = self.get_r_A()
+ r_L = self.get_r_L(r_A, fixed=False)
+ assert r_L.external_item_repr is r_A
+ assert r_L.item_repr.lowleveltype == llmemory.HiddenGcRef32
+ er, ir = rmodel.externalvsinternal(self.rtyper, r_L)
+ assert er is r_L
+ assert ir.lowleveltype == llmemory.HiddenGcRef32
+ er, ir = rmodel.externalvsinternalfield(self.rtyper, r_L)
+ assert er is r_L
+ assert ir.lowleveltype == llmemory.HiddenGcRef32
+
+ def test_fixedlist_of_fixedlist_of_instance(self):
+ r_A = self.get_r_A()
+ r_L1 = self.get_r_L(r_A)
+ r_L = self.get_r_L(r_L1)
+ assert r_L.external_item_repr is r_L1
+ assert r_L.item_repr is r_L1
+ er, ir = rmodel.externalvsinternal(self.rtyper, r_L)
+ assert er is ir is r_L
+ er, ir = rmodel.externalvsinternalfield(self.rtyper, r_L)
+ assert er is ir is r_L
+
+ def test_fixedlist_of_varlist_of_instance(self):
+ r_A = self.get_r_A()
+ r_L1 = self.get_r_L(r_A, fixed=False)
+ r_L = self.get_r_L(r_L1)
+ assert r_L.external_item_repr is r_L1
+ assert r_L.item_repr.lowleveltype == llmemory.HiddenGcRef32
+ er, ir = rmodel.externalvsinternal(self.rtyper, r_L)
+ assert er is ir is r_L
+ er, ir = rmodel.externalvsinternalfield(self.rtyper, r_L)
+ assert er is ir is r_L
+
+ def test_varlist_of_fixedlist_of_instance(self):
+ r_A = self.get_r_A()
+ r_L1 = self.get_r_L(r_A)
+ r_L = self.get_r_L(r_L1, fixed=False)
+ assert r_L.external_item_repr is r_L1
+ assert r_L.item_repr is r_L1
+ er, ir = rmodel.externalvsinternal(self.rtyper, r_L)
+ assert er is r_L
+ assert ir.lowleveltype == llmemory.HiddenGcRef32
+ er, ir = rmodel.externalvsinternalfield(self.rtyper, r_L)
+ assert er is r_L
+ assert ir.lowleveltype == llmemory.HiddenGcRef32
+
+ def test_varlist_of_varlist_of_instance(self):
+ r_A = self.get_r_A()
+ r_L1 = self.get_r_L(r_A, fixed=False)
+ r_L = self.get_r_L(r_L1, fixed=False)
+ assert r_L.external_item_repr is r_L1
+ assert r_L.item_repr.lowleveltype == llmemory.HiddenGcRef32
+ er, ir = rmodel.externalvsinternal(self.rtyper, r_L)
+ assert er is r_L
+ assert ir.lowleveltype == llmemory.HiddenGcRef32
+ er, ir = rmodel.externalvsinternalfield(self.rtyper, r_L)
+ assert er is r_L
+ assert ir.lowleveltype == llmemory.HiddenGcRef32
+
+
class TestLLtype64(MixinCompressed64, test_rclass.TestLLtype):
def test_casts_1(self):
@@ -56,3 +200,20 @@
a = d.values()[0]
a.x = 5
self.interpret(fn, [])
+
+ def test_dict_recast_2(self):
+ from pypy.rlib.objectmodel import r_dict
+ def fn():
+ d = {4: 5}
+ return d.items()[0][1]
+ res = self.interpret(fn, [])
+ assert res == 5
+
+ def test_tuple_eq(self):
+ base = (5, (6, (7,)))
+ def fn(i, j, k):
+ return (i, (j, (k,))) == base
+ res = self.interpret(fn, [5, 6, 7])
+ assert res == True
+ res = self.interpret(fn, [5, 6, 8])
+ assert res == False
Modified: pypy/branch/32ptr-on-64bit/pypy/rpython/test/test_rdict.py
==============================================================================
--- pypy/branch/32ptr-on-64bit/pypy/rpython/test/test_rdict.py (original)
+++ pypy/branch/32ptr-on-64bit/pypy/rpython/test/test_rdict.py Mon Oct 11 14:37:17 2010
@@ -936,6 +936,7 @@
class PseudoRTyper:
cache_dummy_values = {}
+ annotator = None
dictrepr = rdict.DictRepr(PseudoRTyper(), string_repr, string_repr,
DictKey(None, annmodel.SomeString(key_can_be_none)),
DictValue(None, annmodel.SomeString(value_can_be_none)))
More information about the Pypy-commit
mailing list