[pypy-svn] r21013 - in pypy/dist/pypy: annotation translator/test
cfbolz at codespeak.net
cfbolz at codespeak.net
Sun Dec 11 00:03:56 CET 2005
Author: cfbolz
Date: Sun Dec 11 00:03:55 2005
New Revision: 21013
Modified:
pypy/dist/pypy/annotation/builtin.py
pypy/dist/pypy/translator/test/test_annrpython.py
Log:
proper annotations for these functions
Modified: pypy/dist/pypy/annotation/builtin.py
==============================================================================
--- pypy/dist/pypy/annotation/builtin.py (original)
+++ pypy/dist/pypy/annotation/builtin.py Sun Dec 11 00:03:55 2005
@@ -247,6 +247,15 @@
def rarith_intmask(s_obj):
return SomeInteger()
+def robjmodel_cast_obj_to_int(s_instance):
+ return SomeInteger()
+
+def robjmodel_cast_int_to_obj(s_int, s_clspbc):
+ assert len(s_clspbc.descriptions) == 1
+ desc = s_clspbc.descriptions.keys()[0]
+ cdef = desc.getuniqueclassdef()
+ return SomeInstance(cdef)
+
def robjmodel_instantiate(s_clspbc):
assert isinstance(s_clspbc, SomePBC)
clsdef = None
@@ -326,6 +335,8 @@
##BUILTIN_ANALYZERS[pypy.rpython.rarithmetic.ovfcheck] = rarith_ovfcheck
##BUILTIN_ANALYZERS[pypy.rpython.rarithmetic.ovfcheck_lshift] = rarith_ovfcheck_lshift
BUILTIN_ANALYZERS[pypy.rpython.rarithmetic.intmask] = rarith_intmask
+BUILTIN_ANALYZERS[pypy.rpython.objectmodel.cast_object_to_int] = robjmodel_cast_obj_to_int
+BUILTIN_ANALYZERS[pypy.rpython.objectmodel.cast_int_to_object] = robjmodel_cast_int_to_obj
BUILTIN_ANALYZERS[pypy.rpython.objectmodel.instantiate] = robjmodel_instantiate
BUILTIN_ANALYZERS[pypy.rpython.objectmodel.we_are_translated] = (
robjmodel_we_are_translated)
Modified: pypy/dist/pypy/translator/test/test_annrpython.py
==============================================================================
--- pypy/dist/pypy/translator/test/test_annrpython.py (original)
+++ pypy/dist/pypy/translator/test/test_annrpython.py Sun Dec 11 00:03:55 2005
@@ -11,6 +11,7 @@
from pypy.annotation.dictdef import DictDef
from pypy.objspace.flow.model import *
from pypy.rpython.rarithmetic import r_uint
+from pypy.rpython import objectmodel
from pypy.objspace.flow import FlowObjSpace
from pypy.translator.test import snippet
@@ -1916,6 +1917,22 @@
assert s.knowntype == int
graph = tgraphof(t, A.__del__.im_func)
assert graph.startblock in a.annotated
+
+ def test_casttoandfromint(self):
+ class A(object):
+ pass
+ def f():
+ a = A()
+ return objectmodel.cast_object_to_int(a)
+ def g(i):
+ return objectmodel.cast_int_to_object(i, A)
+ a = self.RPythonAnnotator()
+ s = a.build_types(f, [])
+ assert isinstance(s, annmodel.SomeInteger)
+ s = a.build_types(g, [annmodel.SomeInteger()])
+ assert isinstance(s, annmodel.SomeInstance)
+ assert s.classdef.classdesc.pyobj is A
+
def g(n):
return [0,1,2,n]
More information about the Pypy-commit
mailing list