[pypy-svn] r39815 - in pypy/dist/pypy/rpython: . ootypesystem/test
fijal at codespeak.net
fijal at codespeak.net
Sat Mar 3 16:25:19 CET 2007
Author: fijal
Date: Sat Mar 3 16:25:18 2007
New Revision: 39815
Modified:
pypy/dist/pypy/rpython/ootypesystem/test/test_bltann.py
pypy/dist/pypy/rpython/rexternalobj.py
Log:
convert_from_to for BasicExternal and a test
Modified: pypy/dist/pypy/rpython/ootypesystem/test/test_bltann.py
==============================================================================
--- pypy/dist/pypy/rpython/ootypesystem/test/test_bltann.py (original)
+++ pypy/dist/pypy/rpython/ootypesystem/test/test_bltann.py Sat Mar 3 16:25:18 2007
@@ -7,10 +7,11 @@
from pypy.objspace.flow import FlowObjSpace
from pypy.annotation.annrpython import RPythonAnnotator
import exceptions
-from pypy.rpython.ootypesystem.bltregistry import BasicExternal, ExternalType, MethodDesc
+from pypy.rpython.ootypesystem.bltregistry import BasicExternal, ExternalType, MethodDesc, described
from pypy.rpython.ootypesystem.ootype import Signed, _static_meth, StaticMethod, Void
from pypy.rpython.test.test_llinterp import interpret
from pypy.annotation.signature import annotation
+from pypy.translator.translator import TranslationContext
class C(BasicExternal):
pass
@@ -166,3 +167,28 @@
assert isinstance(res, float)
res = interpret(callback_field, [0], type_system="ootype")
assert res == 8.3
+
+def test_mixed_classes():
+ from pypy.rpython.extfunc import register_external
+ class One(BasicExternal):
+ pass
+
+ class Two(One):
+ pass
+
+ def g(one):
+ return 3
+ register_external(g, args=[One], result=int)
+
+ def f(x):
+ if x:
+ return g(One())
+ return g(Two())
+
+ t = TranslationContext()
+ a = t.buildannotator()
+ s = a.build_types(f, [bool])
+ a.simplify()
+ typer = t.buildrtyper(type_system="ootype")
+ typer.specialize()
+ #res = interpret(f, [True], type_system="ootype")
Modified: pypy/dist/pypy/rpython/rexternalobj.py
==============================================================================
--- pypy/dist/pypy/rpython/rexternalobj.py (original)
+++ pypy/dist/pypy/rpython/rexternalobj.py Sat Mar 3 16:25:18 2007
@@ -5,9 +5,10 @@
from pypy.rpython.extfunctable import typetable
from pypy.rpython import rbuiltin
from pypy.rpython.module.support import init_opaque_object
-from pypy.objspace.flow.model import Constant
+from pypy.objspace.flow.model import Constant, Variable
from pypy.rpython import extregistry
from pypy.annotation.signature import annotation
+from pypy.annotation.pairtype import pairtype
class __extend__(annmodel.SomeExternalObject):
@@ -136,3 +137,14 @@
def rtype_is_true(self, hop):
vlist = hop.inputargs(self)
return hop.genop('ptr_nonzero', vlist, resulttype=lltype.Bool)
+
+class __extend__(pairtype(ExternalBuiltinRepr, ExternalBuiltinRepr)):
+ def convert_from_to((from_, to), v, llops):
+ type_from = from_.knowntype._class_
+ type_to = to.knowntype._class_
+ if issubclass(type_from, type_to):
+ v.concretetype=to.knowntype
+ return v
+ return NotImplemented
+
+
More information about the Pypy-commit
mailing list