[pypy-svn] r30962 - in pypy/dist/pypy: annotation rpython rpython/test

fijal at codespeak.net fijal at codespeak.net
Thu Aug 3 19:19:39 CEST 2006


Author: fijal
Date: Thu Aug  3 19:19:14 2006
New Revision: 30962

Added:
   pypy/dist/pypy/rpython/nonconst.py   (contents, props changed)
   pypy/dist/pypy/rpython/test/test_nonconst.py   (contents, props changed)
Modified:
   pypy/dist/pypy/annotation/annrpython.py
Log:
Added non-constant constant. It means that when you write down NonConst(42) it gets annotated as SomeInteger(knowntype=int). Cool for testing without one() magic.


Modified: pypy/dist/pypy/annotation/annrpython.py
==============================================================================
--- pypy/dist/pypy/annotation/annrpython.py	(original)
+++ pypy/dist/pypy/annotation/annrpython.py	Thu Aug  3 19:19:14 2006
@@ -23,6 +23,7 @@
     def __init__(self, translator=None, policy=None, bookkeeper=None):
         import pypy.rpython.ootypesystem.ooregistry # has side effects
         import pypy.rpython.ootypesystem.bltregistry # has side effects
+        import pypy.rpython.nonconst # has side effects
         
         if translator is None:
             # interface for tests

Added: pypy/dist/pypy/rpython/nonconst.py
==============================================================================
--- (empty file)
+++ pypy/dist/pypy/rpython/nonconst.py	Thu Aug  3 19:19:14 2006
@@ -0,0 +1,16 @@
+
+""" simple non-constant constant. Ie constant which does not get annotated as constant
+"""
+
+from pypy.rpython.extregistry import ExtRegistryEntry
+from pypy.annotation.bookkeeper import getbookkeeper
+
+class NonConstant(object):
+    def __init__(self, _constant):
+        self.constant = _constant
+
+class EntryNonConstant(ExtRegistryEntry):
+    _about_ = NonConstant
+    
+    def compute_result_annotation(self, arg):
+        return getbookkeeper().annotation_from_example(arg.const)

Added: pypy/dist/pypy/rpython/test/test_nonconst.py
==============================================================================
--- (empty file)
+++ pypy/dist/pypy/rpython/test/test_nonconst.py	Thu Aug  3 19:19:14 2006
@@ -0,0 +1,18 @@
+
+""" Test of non-constant constant.
+"""
+
+from pypy.rpython.nonconst import NonConstant
+
+from pypy.objspace.flow import FlowObjSpace
+from pypy.annotation.annrpython import RPythonAnnotator
+
+def test_nonconst():
+    def nonconst_f():
+        a = NonConstant(3)
+        return a
+    
+    a = RPythonAnnotator()
+    s = a.build_types(nonconst_f, [])
+    assert s.knowntype is int
+    assert not hasattr(s, 'const')



More information about the Pypy-commit mailing list