Commits

Antonio Cuni committed 0497352

- 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

Comments (0)

Files changed (9)

pypy/rpython/test/test_rbuiltin.py

             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):
             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):

pypy/translator/cli/cts.py

 
 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
 T = CliPrimitiveType
 class types:
     void =    T('void')
+    int16 =   T('int16')
     int32 =   T('int32')
     uint32 =  T('unsigned int32')
     int64 =   T('int64')
 
 _lltype_to_cts = {
     ootype.Void: types.void,
+    rffi.SHORT: types.int16,
     ootype.Signed: types.int32,    
     ootype.Unsigned: types.uint32,
     ootype.SignedLongLong: types.int64,

pypy/translator/cli/ilgenerator.py

 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
                 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))

pypy/translator/cli/metavm.py

 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
     ootype.Bool: 'i1', 
     ootype.Char: 'i2',
     ootype.UniChar: 'i2',
+    rffi.SHORT: 'i2',
     ootype.Signed: 'i4',
     ootype.SignedLongLong: 'i8',
     ootype.Unsigned: 'u4',

pypy/translator/cli/src/pypylib.cs

         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)

pypy/translator/cli/test/runtest.py

 
     def __convert_method(self, arg_type):
         _conv = {
+            CTS.types.int16: 'ToInt16',
             CTS.types.int32: 'ToInt32',
             CTS.types.uint32: 'ToUInt32',
             CTS.types.int64: 'ToInt64',
         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:
         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
             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)

pypy/translator/jvm/test/test_builtin.py

                          '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

pypy/translator/jvm/test/test_list.py

     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

pypy/translator/oosupport/constant.py

 """
 
 from pypy.rpython.ootypesystem import ootype
+from pypy.rpython.lltypesystem import rffi
 import operator
 
 MAX_CONST_PER_STEP = 50
 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