[pypy-svn] r14267 - in pypy/branch/dist-2.4.1/pypy: annotation interpreter translator/llvm2/test translator/test

arigo at codespeak.net arigo at codespeak.net
Tue Jul 5 12:35:34 CEST 2005


Author: arigo
Date: Tue Jul  5 12:35:33 2005
New Revision: 14267

Modified:
   pypy/branch/dist-2.4.1/pypy/annotation/builtin.py
   pypy/branch/dist-2.4.1/pypy/interpreter/pycompiler.py
   pypy/branch/dist-2.4.1/pypy/translator/llvm2/test/test_genllvm.py
   pypy/branch/dist-2.4.1/pypy/translator/test/test_annrpython.py
Log:
svn merge -r14261:14266 http://codespeak.net/svn/pypy/dist



Modified: pypy/branch/dist-2.4.1/pypy/annotation/builtin.py
==============================================================================
--- pypy/branch/dist-2.4.1/pypy/annotation/builtin.py	(original)
+++ pypy/branch/dist-2.4.1/pypy/annotation/builtin.py	Tue Jul  5 12:35:33 2005
@@ -66,8 +66,15 @@
 def builtin_bool(s_obj):
     return constpropagate(bool, [s_obj], SomeBool())
 
-def builtin_int(s_obj):
-    return constpropagate(int, [s_obj], SomeInteger())
+def builtin_int(s_obj, s_base=None):
+    assert (s_base is None or s_base.is_constant() 
+            and s_base.const == 16
+            and s_obj.knowntype == str), "only int(v|string) or int(string,16) expected"
+    if s_base is not None:
+        args_s = [s_obj, s_base]
+    else:
+        args_s = [s_obj]
+    return constpropagate(int, args_s, SomeInteger())
 
 def restricted_uint(s_obj):    # for r_uint
     return constpropagate(pypy.rpython.rarithmetic.r_uint, [s_obj],

Modified: pypy/branch/dist-2.4.1/pypy/interpreter/pycompiler.py
==============================================================================
--- pypy/branch/dist-2.4.1/pypy/interpreter/pycompiler.py	(original)
+++ pypy/branch/dist-2.4.1/pypy/interpreter/pycompiler.py	Tue Jul  5 12:35:33 2005
@@ -169,13 +169,6 @@
 
 
 ########
-from pypy.interpreter import stablecompiler
-from pypy.interpreter.stablecompiler.pycodegen import ModuleCodeGenerator
-from pypy.interpreter.stablecompiler.pycodegen import InteractiveCodeGenerator
-from pypy.interpreter.stablecompiler.pycodegen import ExpressionCodeGenerator
-from pypy.interpreter.stablecompiler.transformer import Transformer
-from pyparser.pythonutil import ast_from_input
-
 class PythonCompiler(CPythonCompiler):
     """Uses the stdlib's python implementation of compiler
 
@@ -185,6 +178,13 @@
          the whole source after having only added a new '\n')
     """
     def compile(self, source, filename, mode, flags):
+        from pypy.interpreter import stablecompiler
+        from pypy.interpreter.stablecompiler.pycodegen import ModuleCodeGenerator
+        from pypy.interpreter.stablecompiler.pycodegen import InteractiveCodeGenerator
+        from pypy.interpreter.stablecompiler.pycodegen import ExpressionCodeGenerator
+        from pypy.interpreter.stablecompiler.transformer import Transformer
+        from pyparser.pythonutil import ast_from_input
+
         flags |= __future__.generators.compiler_flag   # always on (2.2 compat)
         space = self.space
         try:

Modified: pypy/branch/dist-2.4.1/pypy/translator/llvm2/test/test_genllvm.py
==============================================================================
--- pypy/branch/dist-2.4.1/pypy/translator/llvm2/test/test_genllvm.py	(original)
+++ pypy/branch/dist-2.4.1/pypy/translator/llvm2/test/test_genllvm.py	Tue Jul  5 12:35:33 2005
@@ -227,6 +227,20 @@
     f = compile_function(nested_tuple, [int])
     assert f(4) == 4
 
+def test_prebuilt_tuples():
+    t1 = (1,2,3,4)
+    t2 = (5,6,7,8)
+    def callee_tuple(t):
+        return t[0]
+    def caller_tuple(i):
+        if i:
+            return callee_tuple(t1) + i
+        else:
+            return callee_tuple(t2) + i
+    f = compile_function(caller_tuple, [int])
+    assert f(0) == 5
+    assert f(1) == 2
+
 def test_pbc_fns(): 
     def f2(x):
          return x+1

Modified: pypy/branch/dist-2.4.1/pypy/translator/test/test_annrpython.py
==============================================================================
--- pypy/branch/dist-2.4.1/pypy/translator/test/test_annrpython.py	(original)
+++ pypy/branch/dist-2.4.1/pypy/translator/test/test_annrpython.py	Tue Jul  5 12:35:33 2005
@@ -1380,6 +1380,13 @@
         s = a.build_types(f, [int])
         assert s == a.bookkeeper.immutablevalue(12)
 
+    def test_int(self):
+        def f(x, s):
+            return int(x) + int(s) + int(s, 16)
+        a = self.RPythonAnnotator()
+        s = a.build_types(f, [int, str])
+        assert s.knowntype == int
+
 
 def g(n):
     return [0,1,2,n]



More information about the Pypy-commit mailing list