[pypy-svn] r68230 - in pypy/trunk/pypy: rpython/test translator/cli translator/cli/src translator/cli/test translator/jvm/test translator/oosupport

antocuni at codespeak.net antocuni at codespeak.net
Wed Oct 7 14:25:38 CEST 2009


Author: antocuni
Date: Wed Oct  7 14:25:37 2009
New Revision: 68230

Modified:
   pypy/trunk/pypy/rpython/test/test_rbuiltin.py
   pypy/trunk/pypy/translator/cli/cts.py
   pypy/trunk/pypy/translator/cli/ilgenerator.py
   pypy/trunk/pypy/translator/cli/metavm.py
   pypy/trunk/pypy/translator/cli/src/pypylib.cs
   pypy/trunk/pypy/translator/cli/test/runtest.py
   pypy/trunk/pypy/translator/jvm/test/test_builtin.py
   pypy/trunk/pypy/translator/jvm/test/test_list.py
   pypy/trunk/pypy/translator/oosupport/constant.py
Log:
- move test_cast_primitive to the base class, so it's tested also for ootype

- teach the cli backend about the SHORT type, making test_cast_primitive and test_r_short_list passing

- skip those two tests in the jvm backend



Modified: pypy/trunk/pypy/rpython/test/test_rbuiltin.py
==============================================================================
--- pypy/trunk/pypy/rpython/test/test_rbuiltin.py	(original)
+++ pypy/trunk/pypy/rpython/test/test_rbuiltin.py	Wed Oct  7 14:25:37 2009
@@ -462,32 +462,6 @@
             assert x1 == intmask(x0)
             assert x3 == intmask(x2)
 
-class TestLLtype(BaseTestRbuiltin, LLRtypeMixin):
-
-    def test_isinstance_obj(self):
-        _1 = lltype.pyobjectptr(1)
-        def f(x):
-            return isinstance(x, int)
-        res = self.interpret(f, [_1], someobjects=True)
-        assert res is True
-        _1_0 = lltype.pyobjectptr(1.0)
-        res = self.interpret(f, [_1_0], someobjects=True)
-        assert res is False
-
-    def test_hasattr(self):
-        class A(object):
-            def __init__(self):
-                self.x = 42
-        def f(i):
-            a = A()
-            if i==0: return int(hasattr(A, '__init__'))
-            if i==1: return int(hasattr(A, 'y'))
-            if i==2: return int(hasattr(42, 'x'))
-        for x, y in zip(range(3), (1, 0, 0)):
-            res = self.interpret(f, [x], someobjects=True)
-            assert res._obj.value == y
-        # hmm, would like to test against PyObj, is this the wrong place/way?
-
     def test_cast_primitive(self):
         from pypy.rpython.annlowlevel import LowLevelAnnotatorPolicy
         def llf(u):
@@ -516,6 +490,36 @@
             return lltype.cast_primitive(rffi.SHORT, v)
         res = self.interpret(llf, [123], policy=LowLevelAnnotatorPolicy())
         assert res == 123
+        def llf(v):
+            return lltype.cast_primitive(lltype.Signed, v)
+        res = self.interpret(llf, [rffi.r_short(123)], policy=LowLevelAnnotatorPolicy())
+        assert res == 123
+
+class TestLLtype(BaseTestRbuiltin, LLRtypeMixin):
+
+    def test_isinstance_obj(self):
+        _1 = lltype.pyobjectptr(1)
+        def f(x):
+            return isinstance(x, int)
+        res = self.interpret(f, [_1], someobjects=True)
+        assert res is True
+        _1_0 = lltype.pyobjectptr(1.0)
+        res = self.interpret(f, [_1_0], someobjects=True)
+        assert res is False
+
+    def test_hasattr(self):
+        class A(object):
+            def __init__(self):
+                self.x = 42
+        def f(i):
+            a = A()
+            if i==0: return int(hasattr(A, '__init__'))
+            if i==1: return int(hasattr(A, 'y'))
+            if i==2: return int(hasattr(42, 'x'))
+        for x, y in zip(range(3), (1, 0, 0)):
+            res = self.interpret(f, [x], someobjects=True)
+            assert res._obj.value == y
+        # hmm, would like to test against PyObj, is this the wrong place/way?
 
     def test_cast(self):
         def llfn(v):

Modified: pypy/trunk/pypy/translator/cli/cts.py
==============================================================================
--- pypy/trunk/pypy/translator/cli/cts.py	(original)
+++ pypy/trunk/pypy/translator/cli/cts.py	Wed Oct  7 14:25:37 2009
@@ -6,6 +6,7 @@
 
 from py.builtin import set
 from pypy.rpython.lltypesystem import lltype
+from pypy.rpython.lltypesystem import rffi
 from pypy.rpython.ootypesystem import ootype
 from pypy.translator.cli.option import getoption
 from pypy.translator.cli import oopspec
@@ -107,6 +108,7 @@
 T = CliPrimitiveType
 class types:
     void =    T('void')
+    int16 =   T('int16')
     int32 =   T('int32')
     uint32 =  T('unsigned int32')
     int64 =   T('int64')
@@ -134,6 +136,7 @@
 
 _lltype_to_cts = {
     ootype.Void: types.void,
+    rffi.SHORT: types.int16,
     ootype.Signed: types.int32,    
     ootype.Unsigned: types.uint32,
     ootype.SignedLongLong: types.int64,

Modified: pypy/trunk/pypy/translator/cli/ilgenerator.py
==============================================================================
--- pypy/trunk/pypy/translator/cli/ilgenerator.py	(original)
+++ pypy/trunk/pypy/translator/cli/ilgenerator.py	Wed Oct  7 14:25:37 2009
@@ -1,5 +1,6 @@
 from pypy.rpython.lltypesystem.lltype import Signed, Unsigned, Void, Bool, Float
 from pypy.rpython.lltypesystem.lltype import SignedLongLong, UnsignedLongLong
+from pypy.rpython.lltypesystem import rffi
 from pypy.rlib.objectmodel import CDefinedIntSymbolic
 from pypy.rlib.rarithmetic import isnan, isinf
 from pypy.rpython.ootypesystem import ootype
@@ -406,7 +407,7 @@
                 ilasm.opcode('ldc.r8', repr(value))
         elif isinstance(value, CDefinedIntSymbolic):
             ilasm.opcode('ldc.i4', DEFINED_INT_SYMBOLICS[value.expr])
-        elif TYPE in (ootype.Signed, ootype.Unsigned):
+        elif TYPE in (ootype.Signed, ootype.Unsigned, rffi.SHORT):
             ilasm.opcode('ldc.i4', str(value))
         elif TYPE in (ootype.SignedLongLong, ootype.UnsignedLongLong):
             ilasm.opcode('ldc.i8', str(value))

Modified: pypy/trunk/pypy/translator/cli/metavm.py
==============================================================================
--- pypy/trunk/pypy/translator/cli/metavm.py	(original)
+++ pypy/trunk/pypy/translator/cli/metavm.py	Wed Oct  7 14:25:37 2009
@@ -1,5 +1,6 @@
 from pypy.translator.cli import oopspec
 from pypy.rpython.ootypesystem import ootype
+from pypy.rpython.lltypesystem import rffi
 from pypy.translator.oosupport.metavm import Generator, InstructionList, MicroInstruction,\
      PushAllArgs, StoreResult, GetField, SetField, DownCast
 from pypy.translator.oosupport.metavm import _Call as _OOCall
@@ -274,6 +275,7 @@
     ootype.Bool: 'i1', 
     ootype.Char: 'i2',
     ootype.UniChar: 'i2',
+    rffi.SHORT: 'i2',
     ootype.Signed: 'i4',
     ootype.SignedLongLong: 'i8',
     ootype.Unsigned: 'u4',

Modified: pypy/trunk/pypy/translator/cli/src/pypylib.cs
==============================================================================
--- pypy/trunk/pypy/translator/cli/src/pypylib.cs	(original)
+++ pypy/trunk/pypy/translator/cli/src/pypylib.cs	Wed Oct  7 14:25:37 2009
@@ -18,6 +18,7 @@
         public static string ToPython(uint x)   { return x.ToString(); }
         public static string ToPython(long x)   { return x.ToString(); }
         public static string ToPython(ulong x)  { return x.ToString(); }
+        public static string ToPython(short x)  { return x.ToString(); }
         // XXX: it does not support strings containing "'".
         public static string ToPython(string x) { 
             if (x == null)

Modified: pypy/trunk/pypy/translator/cli/test/runtest.py
==============================================================================
--- pypy/trunk/pypy/translator/cli/test/runtest.py	(original)
+++ pypy/trunk/pypy/translator/cli/test/runtest.py	Wed Oct  7 14:25:37 2009
@@ -126,6 +126,7 @@
 
     def __convert_method(self, arg_type):
         _conv = {
+            CTS.types.int16: 'ToInt16',
             CTS.types.int32: 'ToInt32',
             CTS.types.uint32: 'ToUInt32',
             CTS.types.int64: 'ToInt64',
@@ -285,7 +286,8 @@
         self._ann = None
         self._cli_func = None
 
-    def _compile(self, fn, args, ann=None, backendopt=True, auto_raise_exc=False, exctrans=False):
+    def _compile(self, fn, args, ann=None, backendopt=True,
+                 auto_raise_exc=False, exctrans=False, policy=None):
         if ann is None:
             ann = [get_annotation(x) for x in args]
         if self._func is fn and self._ann == ann:
@@ -293,7 +295,7 @@
         else:
             self._cli_func = compile_function(fn, ann, backendopt=backendopt,
                                               auto_raise_exc=auto_raise_exc,
-                                              exctrans=exctrans)
+                                              exctrans=exctrans, annotatorpolicy=policy)
             self._func = fn
             self._ann = ann
             return self._cli_func
@@ -314,7 +316,7 @@
             backendopt = getattr(self, 'backendopt', True) # enable it by default
         return backendopt
     
-    def interpret(self, fn, args, annotation=None, backendopt=None, exctrans=False):
+    def interpret(self, fn, args, annotation=None, backendopt=None, exctrans=False, policy=None):
         backendopt = self._get_backendopt(backendopt)
         f = self._compile(fn, args, annotation, backendopt=backendopt, exctrans=exctrans)
         res = f(*args)

Modified: pypy/trunk/pypy/translator/jvm/test/test_builtin.py
==============================================================================
--- pypy/trunk/pypy/translator/jvm/test/test_builtin.py	(original)
+++ pypy/trunk/pypy/translator/jvm/test/test_builtin.py	Wed Oct  7 14:25:37 2009
@@ -34,6 +34,10 @@
                          'http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6539705')
         BaseTestBuiltin.test_os_access(self)
 
+    def test_cast_primitive(self):
+        py.test.skip('fixme!')
+
+
 class TestJvmTime(JvmTest, BaseTestTime):
 
     pass

Modified: pypy/trunk/pypy/translator/jvm/test/test_list.py
==============================================================================
--- pypy/trunk/pypy/translator/jvm/test/test_list.py	(original)
+++ pypy/trunk/pypy/translator/jvm/test/test_list.py	Wed Oct  7 14:25:37 2009
@@ -9,6 +9,9 @@
     def test_getitem_exc(self):
         py.test.skip('fixme!')
 
+    def test_r_short_list(self):
+        py.test.skip('fixme!')
+
     def test_zeroed_list(self):
         def fn():
             lst = [0] * 16

Modified: pypy/trunk/pypy/translator/oosupport/constant.py
==============================================================================
--- pypy/trunk/pypy/translator/oosupport/constant.py	(original)
+++ pypy/trunk/pypy/translator/oosupport/constant.py	Wed Oct  7 14:25:37 2009
@@ -26,6 +26,7 @@
 """
 
 from pypy.rpython.ootypesystem import ootype
+from pypy.rpython.lltypesystem import rffi
 import operator
 
 MAX_CONST_PER_STEP = 50
@@ -33,7 +34,7 @@
 PRIMITIVE_TYPES = set([ootype.Void, ootype.Bool, ootype.Char, ootype.UniChar,
                        ootype.Float, ootype.Signed, ootype.Unsigned,
                        ootype.String, ootype.Unicode, ootype.SignedLongLong,
-                       ootype.UnsignedLongLong])
+                       ootype.UnsignedLongLong, rffi.SHORT])
 
 def is_primitive(TYPE):
     return TYPE in PRIMITIVE_TYPES



More information about the Pypy-commit mailing list