[pypy-svn] r63906 - in pypy/branch/pyjitpl5-simplify/pypy: annotation rpython/lltypesystem rpython/ootypesystem rpython/ootypesystem/test rpython/test
antocuni at codespeak.net
antocuni at codespeak.net
Thu Apr 9 17:26:38 CEST 2009
Author: antocuni
Date: Thu Apr 9 17:26:35 2009
New Revision: 63906
Modified:
pypy/branch/pyjitpl5-simplify/pypy/annotation/builtin.py
pypy/branch/pyjitpl5-simplify/pypy/annotation/model.py
pypy/branch/pyjitpl5-simplify/pypy/rpython/lltypesystem/lloperation.py
pypy/branch/pyjitpl5-simplify/pypy/rpython/ootypesystem/ooopimpl.py
pypy/branch/pyjitpl5-simplify/pypy/rpython/ootypesystem/rbuiltin.py
pypy/branch/pyjitpl5-simplify/pypy/rpython/ootypesystem/rootype.py
pypy/branch/pyjitpl5-simplify/pypy/rpython/ootypesystem/test/test_oortype.py
pypy/branch/pyjitpl5-simplify/pypy/rpython/test/test_rclass.py
Log:
replay r53057
annotation & rtyping of the new type ootype.Object and the two operations
cast_to_object and cast_from_object.
Modified: pypy/branch/pyjitpl5-simplify/pypy/annotation/builtin.py
==============================================================================
--- pypy/branch/pyjitpl5-simplify/pypy/annotation/builtin.py (original)
+++ pypy/branch/pyjitpl5-simplify/pypy/annotation/builtin.py Thu Apr 9 17:26:35 2009
@@ -9,6 +9,7 @@
from pypy.annotation.model import SomeFloat, unionof, SomeUnicodeString
from pypy.annotation.model import SomePBC, SomeInstance, SomeDict
from pypy.annotation.model import SomeWeakRef
+from pypy.annotation.model import SomeOOObject
from pypy.annotation.model import annotation_to_lltype, lltype_to_annotation, ll_to_annotation
from pypy.annotation.model import add_knowntypedata
from pypy.annotation.model import s_ImpossibleValue
@@ -548,7 +549,7 @@
return SomeOOInstance(c.ootype)
def ooidentityhash(i):
- assert isinstance(i, SomeOOInstance)
+ assert isinstance(i, (SomeOOInstance, SomeOOObject))
return SomeInteger()
def ooupcast(I, i):
@@ -565,6 +566,21 @@
else:
raise AnnotatorError, 'Cannot cast %s to %s' % (i.ootype, I.const)
+def cast_to_object(obj):
+ assert isinstance(obj.ootype, ootype.OOType)
+ return SomeOOObject()
+
+def cast_from_object(T, obj):
+ TYPE = T.const
+ if isinstance(TYPE, ootype.Instance):
+ return SomeOOInstance(TYPE)
+ elif isinstance(TYPE, ootype.Record):
+ return SomeOOInstance(TYPE) # XXX: SomeOORecord?
+ elif isinstance(TYPE, ootype.StaticMethod):
+ return SomeOOStaticMeth(TYPE)
+ else:
+ raise AnnotatorError, 'Cannot cast Object to %s' % TYPE
+
BUILTIN_ANALYZERS[ootype.instanceof] = instanceof
BUILTIN_ANALYZERS[ootype.new] = new
BUILTIN_ANALYZERS[ootype.oonewarray] = oonewarray
@@ -575,6 +591,8 @@
BUILTIN_ANALYZERS[ootype.ooidentityhash] = ooidentityhash
BUILTIN_ANALYZERS[ootype.ooupcast] = ooupcast
BUILTIN_ANALYZERS[ootype.oodowncast] = oodowncast
+BUILTIN_ANALYZERS[ootype.cast_to_object] = cast_to_object
+BUILTIN_ANALYZERS[ootype.cast_from_object] = cast_from_object
#________________________________
# weakrefs
Modified: pypy/branch/pyjitpl5-simplify/pypy/annotation/model.py
==============================================================================
--- pypy/branch/pyjitpl5-simplify/pypy/annotation/model.py (original)
+++ pypy/branch/pyjitpl5-simplify/pypy/annotation/model.py Thu Apr 9 17:26:35 2009
@@ -541,6 +541,10 @@
def can_be_none(self):
return False
+class SomeOOObject(SomeObject):
+ def __init__(self):
+ self.ootype = ootype.Object
+
class SomeOOClass(SomeObject):
def __init__(self, ootype):
self.ootype = ootype
Modified: pypy/branch/pyjitpl5-simplify/pypy/rpython/lltypesystem/lloperation.py
==============================================================================
--- pypy/branch/pyjitpl5-simplify/pypy/rpython/lltypesystem/lloperation.py (original)
+++ pypy/branch/pyjitpl5-simplify/pypy/rpython/lltypesystem/lloperation.py Thu Apr 9 17:26:35 2009
@@ -480,15 +480,17 @@
'instrument_count': LLOp(),
# __________ ootype operations __________
- 'new': LLOp(oo=True, canraise=(Exception,)),
- 'runtimenew': LLOp(oo=True, canraise=(Exception,)),
- 'oonewcustomdict': LLOp(oo=True, canraise=(Exception,)),
- 'oonewarray': LLOp(oo=True, canraise=(Exception,)),
+ 'new': LLOp(oo=True, canraise=(MemoryError,)),
+ 'runtimenew': LLOp(oo=True, canraise=(MemoryError,)),
+ 'oonewcustomdict': LLOp(oo=True, canraise=(MemoryError,)),
+ 'oonewarray': LLOp(oo=True, canraise=(MemoryError,)),
'oosetfield': LLOp(oo=True),
'oogetfield': LLOp(oo=True, sideeffects=False),
'oosend': LLOp(oo=True, canraise=(Exception,)),
'ooupcast': LLOp(oo=True, canfold=True),
'oodowncast': LLOp(oo=True, canfold=True),
+ 'cast_to_object': LLOp(oo=True, canfold=True),
+ 'cast_from_object': LLOp(oo=True, canfold=True),
'oononnull': LLOp(oo=True, canfold=True),
'ooisnot': LLOp(oo=True, canfold=True),
'ooisnull': LLOp(oo=True, canfold=True),
Modified: pypy/branch/pyjitpl5-simplify/pypy/rpython/ootypesystem/ooopimpl.py
==============================================================================
--- pypy/branch/pyjitpl5-simplify/pypy/rpython/ootypesystem/ooopimpl.py (original)
+++ pypy/branch/pyjitpl5-simplify/pypy/rpython/ootypesystem/ooopimpl.py Thu Apr 9 17:26:35 2009
@@ -12,6 +12,13 @@
return ootype.oodowncast(INST, inst)
op_oodowncast.need_result_type = True
+def op_cast_to_object(inst):
+ return ootype.cast_to_object(inst)
+
+def op_cast_from_object(TYPE, obj):
+ return ootype.cast_from_object(TYPE, obj)
+op_cast_from_object.need_result_type = True
+
def op_oononnull(inst):
checkinst(inst)
return bool(inst)
@@ -26,6 +33,9 @@
elif isinstance(obj1, ootype._class):
assert isinstance(obj2, ootype._class)
return obj1 is obj2
+ elif isinstance(obj1, ootype._object):
+ assert isinstance(obj2, ootype._object)
+ return obj1 == obj2
else:
assert False, "oois on something silly"
Modified: pypy/branch/pyjitpl5-simplify/pypy/rpython/ootypesystem/rbuiltin.py
==============================================================================
--- pypy/branch/pyjitpl5-simplify/pypy/rpython/ootypesystem/rbuiltin.py (original)
+++ pypy/branch/pyjitpl5-simplify/pypy/rpython/ootypesystem/rbuiltin.py Thu Apr 9 17:26:35 2009
@@ -42,7 +42,7 @@
resulttype = hop.r_result.lowleveltype)
def rtype_ooidentityhash(hop):
- assert isinstance(hop.args_s[0], annmodel.SomeOOInstance)
+ assert isinstance(hop.args_s[0], (annmodel.SomeOOInstance, annmodel.SomeOOObject))
vlist = hop.inputargs(hop.args_r[0])
return hop.genop('ooidentityhash', vlist,
resulttype = ootype.Signed)
@@ -59,6 +59,17 @@
v_inst = hop.inputarg(hop.args_r[1], arg=1)
return hop.genop('oodowncast', [v_inst], resulttype = hop.r_result.lowleveltype)
+def rtype_cast_to_object(hop):
+ assert isinstance(hop.args_s[0].ootype, ootype.OOType)
+ v_inst = hop.inputarg(hop.args_r[0], arg=0)
+ return hop.genop('cast_to_object', [v_inst], resulttype = hop.r_result.lowleveltype)
+
+def rtype_cast_from_object(hop):
+ assert isinstance(hop.args_s[0].const, ootype.OOType)
+ assert isinstance(hop.args_s[1], annmodel.SomeOOObject)
+ v_inst = hop.inputarg(hop.args_r[1], arg=1)
+ return hop.genop('cast_from_object', [v_inst], resulttype = hop.r_result.lowleveltype)
+
def rtype_builtin_isinstance(hop):
if hop.s_result.is_constant():
return hop.inputconst(ootype.Bool, hop.s_result.const)
@@ -114,6 +125,8 @@
BUILTIN_TYPER[ootype.ooidentityhash] = rtype_ooidentityhash
BUILTIN_TYPER[ootype.ooupcast] = rtype_ooupcast
BUILTIN_TYPER[ootype.oodowncast] = rtype_oodowncast
+BUILTIN_TYPER[ootype.cast_from_object] = rtype_cast_from_object
+BUILTIN_TYPER[ootype.cast_to_object] = rtype_cast_to_object
BUILTIN_TYPER[isinstance] = rtype_builtin_isinstance
BUILTIN_TYPER[objectmodel.r_dict] = rtype_r_dict
BUILTIN_TYPER[objectmodel.instantiate] = rtype_instantiate
Modified: pypy/branch/pyjitpl5-simplify/pypy/rpython/ootypesystem/rootype.py
==============================================================================
--- pypy/branch/pyjitpl5-simplify/pypy/rpython/ootypesystem/rootype.py (original)
+++ pypy/branch/pyjitpl5-simplify/pypy/rpython/ootypesystem/rootype.py Thu Apr 9 17:26:35 2009
@@ -1,9 +1,15 @@
from pypy.annotation import model as annmodel
from pypy.rpython.rmodel import Repr
from pypy.rpython.ootypesystem import ootype
-from pypy.rpython.ootypesystem.ootype import Void, Class
+from pypy.rpython.ootypesystem.ootype import Void, Class, Object
from pypy.tool.pairtype import pairtype
+class __extend__(annmodel.SomeOOObject):
+ def rtyper_makerepr(self, rtyper):
+ return ooobject_repr
+ def rtyper_makekey(self):
+ return self.__class__,
+
class __extend__(annmodel.SomeOOClass):
def rtyper_makerepr(self, rtyper):
return ooclass_repr
@@ -29,6 +35,10 @@
return self.__class__, self.method
+class OOObjectRepr(Repr):
+ lowleveltype = Object
+
+ooobject_repr = OOObjectRepr()
class OOClassRepr(Repr):
lowleveltype = Class
@@ -86,6 +96,18 @@
v = rpair.rtype_eq(hop)
return hop.genop("bool_not", [v], resulttype=ootype.Bool)
+
+class __extend__(pairtype(OOObjectRepr, OOObjectRepr)):
+ def rtype_is_((r_obj1, r_obj2), hop):
+ vlist = hop.inputargs(r_obj1, r_obj2)
+ return hop.genop('oois', vlist, resulttype=ootype.Bool)
+
+ rtype_eq = rtype_is_
+
+ def rtype_ne(rpair, hop):
+ v = rpair.rtype_eq(hop)
+ return hop.genop("bool_not", [v], resulttype=ootype.Bool)
+
class OOBoundMethRepr(Repr):
def __init__(self, ootype, name):
self.lowleveltype = ootype
Modified: pypy/branch/pyjitpl5-simplify/pypy/rpython/ootypesystem/test/test_oortype.py
==============================================================================
--- pypy/branch/pyjitpl5-simplify/pypy/rpython/ootypesystem/test/test_oortype.py (original)
+++ pypy/branch/pyjitpl5-simplify/pypy/rpython/ootypesystem/test/test_oortype.py Thu Apr 9 17:26:35 2009
@@ -352,7 +352,6 @@
assert res == 42
def test_ooidentityhash():
- py.test.skip('fixme!')
L = List(Signed)
def fn():
Modified: pypy/branch/pyjitpl5-simplify/pypy/rpython/test/test_rclass.py
==============================================================================
--- pypy/branch/pyjitpl5-simplify/pypy/rpython/test/test_rclass.py (original)
+++ pypy/branch/pyjitpl5-simplify/pypy/rpython/test/test_rclass.py Thu Apr 9 17:26:35 2009
@@ -838,3 +838,35 @@
assert destra == destrc
assert destrb is not None
assert destra is not None
+
+ def test_cast_object(self):
+ A = ootype.Instance("Foo", ootype.ROOT)
+ B = ootype.Record({'x': ootype.Signed})
+
+ def fn_instance():
+ a = ootype.new(A)
+ obj = ootype.cast_to_object(a)
+ a2 = ootype.cast_from_object(A, obj)
+ a3 = ootype.cast_from_object(ootype.ROOT, obj)
+ assert a is a2
+ assert a is a3
+ self.interpret(fn_instance, [])
+
+ def fn_record():
+ b = ootype.new(B)
+ b.x = 42
+ obj = ootype.cast_to_object(b)
+ b2 = ootype.cast_from_object(B, obj)
+ assert b2.x == 42
+ assert b is b2
+ self.interpret(fn_record, [])
+
+ def fn_null():
+ a = ootype.null(A)
+ b = ootype.null(B)
+ obj1 = ootype.cast_to_object(a)
+ obj2 = ootype.cast_to_object(b)
+ assert obj1 == obj2
+ assert ootype.cast_from_object(A, obj1) == a
+ assert ootype.cast_from_object(B, obj2) == b
+ self.interpret(fn_null, [])
More information about the Pypy-commit
mailing list