[pypy-svn] r46045 - in pypy/branch/pypy-more-rtti-inprogress/translator: cli jvm/test oosupport/test_template
antocuni at codespeak.net
antocuni at codespeak.net
Mon Aug 27 17:55:41 CEST 2007
Author: antocuni
Date: Mon Aug 27 17:55:41 2007
New Revision: 46045
Modified:
pypy/branch/pypy-more-rtti-inprogress/translator/cli/metavm.py
pypy/branch/pypy-more-rtti-inprogress/translator/cli/opcodes.py
pypy/branch/pypy-more-rtti-inprogress/translator/jvm/test/test_cast.py
pypy/branch/pypy-more-rtti-inprogress/translator/oosupport/test_template/cast.py
Log:
implement cast_primitive and ullong_lshift for gencli
Modified: pypy/branch/pypy-more-rtti-inprogress/translator/cli/metavm.py
==============================================================================
--- pypy/branch/pypy-more-rtti-inprogress/translator/cli/metavm.py (original)
+++ pypy/branch/pypy-more-rtti-inprogress/translator/cli/metavm.py Mon Aug 27 17:55:41 2007
@@ -231,6 +231,18 @@
generator.ilasm.opcode('ldtoken', fullname)
generator.ilasm.call('class [mscorlib]System.Type class [mscorlib]System.Type::GetTypeFromHandle(valuetype [mscorlib]System.RuntimeTypeHandle)')
+OOTYPE_TO_MNEMONIC = {
+ ootype.Signed: 'i4',
+ ootype.SignedLongLong: 'i8',
+ ootype.Unsigned: 'u4',
+ ootype.UnsignedLongLong: 'u8',
+ }
+
+class _CastPrimitive(MicroInstruction):
+ def render(self, generator, op):
+ TO = op.result.concretetype
+ mnemonic = OOTYPE_TO_MNEMONIC[TO]
+ generator.ilasm.opcode('conv.%s' % mnemonic)
Call = _Call()
CallMethod = _CallMethod()
@@ -245,3 +257,4 @@
GetArrayElem = _GetArrayElem()
SetArrayElem = _SetArrayElem()
TypeOf = _TypeOf()
+CastPrimitive = _CastPrimitive()
Modified: pypy/branch/pypy-more-rtti-inprogress/translator/cli/opcodes.py
==============================================================================
--- pypy/branch/pypy-more-rtti-inprogress/translator/cli/opcodes.py (original)
+++ pypy/branch/pypy-more-rtti-inprogress/translator/cli/opcodes.py Mon Aug 27 17:55:41 2007
@@ -1,7 +1,7 @@
from pypy.translator.cli.metavm import Call, CallMethod, \
IndirectCall, GetField, SetField, OOString, DownCast, NewCustomDict,\
CastWeakAdrToPtr, MapException, Box, Unbox, NewArray, GetArrayElem, SetArrayElem,\
- TypeOf
+ TypeOf, CastPrimitive
from pypy.translator.oosupport.metavm import PushArg, PushAllArgs, StoreResult, InstructionList,\
New, RuntimeNew, CastTo, PushPrimitive
from pypy.translator.cli.cts import WEAKREF
@@ -210,6 +210,7 @@
'ullong_ne': _not('ceq'),
'ullong_gt': 'cgt.un',
'ullong_ge': _not('clt.un'),
+ 'ullong_lshift': [PushAllArgs, 'conv.u4', 'shl', 'conv.u8'],
# when casting from bool we want that every truth value is casted
# to 1: we can't simply DoNothing, because the CLI stack could
@@ -231,6 +232,7 @@
'cast_float_to_uint': 'conv.u4',
'cast_longlong_to_float': 'conv.r8',
'cast_float_to_longlong': 'conv.i8',
+ 'cast_primitive': [PushAllArgs, CastPrimitive],
'truncate_longlong_to_int': 'conv.i4',
'is_early_constant': [PushPrimitive(ootype.Bool, False)]
}
Modified: pypy/branch/pypy-more-rtti-inprogress/translator/jvm/test/test_cast.py
==============================================================================
--- pypy/branch/pypy-more-rtti-inprogress/translator/jvm/test/test_cast.py (original)
+++ pypy/branch/pypy-more-rtti-inprogress/translator/jvm/test/test_cast.py Mon Aug 27 17:55:41 2007
@@ -7,3 +7,6 @@
def test_uint_to_float(self):
# This is most likely with how we render uints when we print them, and they get parsed.
py.test.skip('Same issue seen in other tests with uints... 2147450880.0 == 2147483648.0')
+
+ def test_cast_primitive(self):
+ py.test.skip('fixme!')
Modified: pypy/branch/pypy-more-rtti-inprogress/translator/oosupport/test_template/cast.py
==============================================================================
--- pypy/branch/pypy-more-rtti-inprogress/translator/oosupport/test_template/cast.py (original)
+++ pypy/branch/pypy-more-rtti-inprogress/translator/oosupport/test_template/cast.py Mon Aug 27 17:55:41 2007
@@ -52,3 +52,17 @@
def test_uint_to_float(self):
self.check(to_float, [r_uint(sys.maxint+1)])
+
+ def test_cast_primitive(self):
+ from pypy.rpython.lltypesystem.lltype import cast_primitive, \
+ UnsignedLongLong, SignedLongLong, Signed
+ def f(x):
+ x = cast_primitive(UnsignedLongLong, x)
+ x <<= 60
+ x /= 3
+ x <<= 1
+ x = cast_primitive(SignedLongLong, x)
+ x >>= 32
+ return cast_primitive(Signed, x)
+ res = self.interpret(f, [14])
+ assert res == -1789569707
More information about the pypy-svn
mailing list