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

mwh at codespeak.net mwh at codespeak.net
Thu Dec 8 12:01:22 CET 2005


Author: mwh
Date: Thu Dec  8 12:01:21 2005
New Revision: 20880

Modified:
   pypy/dist/pypy/annotation/model.py
   pypy/dist/pypy/rpython/llinterp.py
   pypy/dist/pypy/rpython/rint.py
   pypy/dist/pypy/rpython/test/test_rint.py
Log:
implement converting Signeds to SignedLongLongs.
be more honest about .knowntype on SomeIntegers.
(no-one else has noticed that we broke translate_pypy yet...)


Modified: pypy/dist/pypy/annotation/model.py
==============================================================================
--- pypy/dist/pypy/annotation/model.py	(original)
+++ pypy/dist/pypy/annotation/model.py	Thu Dec  8 12:01:21 2005
@@ -32,6 +32,7 @@
 import pypy
 from pypy.annotation.pairtype import pair, extendabletype
 from pypy.tool.tls import tlsobject
+from pypy.rpython.rarithmetic import r_uint, r_longlong, r_ulonglong
 import inspect
 
 
@@ -163,6 +164,16 @@
         self.nonneg = unsigned or nonneg
         self.unsigned = unsigned  # pypy.rpython.rarithmetic.r_uint
         self.size = size
+        if self.unsigned:
+            if self.size == 2:
+                self.knowntype = r_ulonglong
+            else:
+                self.knowntype = r_uint
+        else:
+            if self.size == 2:
+                self.knowntype = r_longlong
+            else:
+                self.knowntype = int
 
     def fmt_size(self, s):
         if s != 1:

Modified: pypy/dist/pypy/rpython/llinterp.py
==============================================================================
--- pypy/dist/pypy/rpython/llinterp.py	(original)
+++ pypy/dist/pypy/rpython/llinterp.py	Thu Dec  8 12:01:21 2005
@@ -1,5 +1,5 @@
 from pypy.objspace.flow.model import FunctionGraph, Constant, Variable, last_exception
-from pypy.rpython.rarithmetic import intmask, r_uint, ovfcheck
+from pypy.rpython.rarithmetic import intmask, r_uint, ovfcheck, r_longlong
 from pypy.rpython.lltypesystem import lltype
 from pypy.rpython.memory import lladdress
 from pypy.rpython.ootypesystem import ootype
@@ -436,6 +436,10 @@
         assert type(b) is r_uint
         return intmask(b)
 
+    def op_cast_int_to_longlong(self, b):
+        assert type(b) is int
+        return r_longlong(b)
+
     def op_int_floordiv_ovf_zer(self, a, b):
         assert type(a) is int
         assert type(b) is int
@@ -534,12 +538,14 @@
     # __________________________________________________________
     # primitive operations
 
-    for typ in (float, int, r_uint):
+    for typ in (float, int, r_uint, r_longlong):
         typname = typ.__name__
         optup = ('add', 'sub', 'mul', 'div', 'truediv', 'floordiv',
                  'mod', 'gt', 'lt', 'ge', 'ne', 'le', 'eq',)
         if typ is r_uint:
             opnameprefix = 'uint'
+        elif typ is r_longlong:
+            opnameprefix = 'llong'
         else:
             opnameprefix = typname
         if typ in (int, r_uint):

Modified: pypy/dist/pypy/rpython/rint.py
==============================================================================
--- pypy/dist/pypy/rpython/rint.py	(original)
+++ pypy/dist/pypy/rpython/rint.py	Thu Dec  8 12:01:21 2005
@@ -7,7 +7,7 @@
      UnsignedLongLong, SignedLongLong
 from pypy.rpython.rmodel import IntegerRepr, inputconst
 from pypy.rpython.robject import PyObjRepr, pyobj_repr
-from pypy.rpython.rarithmetic import intmask, r_uint, r_ulonglong, r_longlong
+from pypy.rpython.rarithmetic import intmask, r_int, r_uint, r_ulonglong, r_longlong
 from pypy.rpython.error import TyperError
 from pypy.rpython.rmodel import log
 
@@ -44,6 +44,8 @@
         if r_from.lowleveltype == Unsigned and r_to.lowleveltype == Signed:
             log.debug('explicit cast_uint_to_int')
             return llops.genop('cast_uint_to_int', [v], resulttype=Signed)
+        if r_from.lowleveltype == Signed and r_to.lowleveltype == SignedLongLong:
+            return llops.genop('cast_int_to_longlong', [v], resulttype=SignedLongLong)
         return NotImplemented
 
     #arithmetic
@@ -200,7 +202,7 @@
 class __extend__(IntegerRepr):
 
     def convert_const(self, value):
-        if not isinstance(value, (int, r_uint)):   # can be bool
+        if not isinstance(value, (int, r_uint, r_int, r_longlong, r_ulonglong)):   # can be bool
             raise TyperError("not an integer: %r" % (value,))
         if self.lowleveltype == Signed:
             return intmask(value)

Modified: pypy/dist/pypy/rpython/test/test_rint.py
==============================================================================
--- pypy/dist/pypy/rpython/test/test_rint.py	(original)
+++ pypy/dist/pypy/rpython/test/test_rint.py	Thu Dec  8 12:01:21 2005
@@ -3,7 +3,7 @@
 from pypy.annotation import model as annmodel
 from pypy.rpython.test import snippet
 from pypy.rpython.test.test_llinterp import interpret
-from pypy.rpython.rarithmetic import r_uint
+from pypy.rpython.rarithmetic import r_uint, r_longlong
 
 
 class TestSnippet(object):
@@ -101,3 +101,17 @@
     res = interpret(dummy, [-1])
     assert res is False    # -1 ==> 0xffffffff
 
+def test_specializing_int_functions():
+    def f(i):
+        return i + 1
+    f._annspecialcase_ = "specialize:argtype0"
+    def g(n):
+        if n > 0:
+            return f(r_longlong(0))
+        else:
+            return f(0)
+    res = interpret(g, [0])
+    assert res == 1
+
+    res = interpret(g, [1])
+    assert res == 1



More information about the Pypy-commit mailing list