[pypy-commit] pypy default: move FloatRepr and IntegerRepr to rfloat and rint respectively
rlamy
noreply at buildbot.pypy.org
Tue May 13 22:07:56 CEST 2014
Author: Ronan Lamy <ronan.lamy at gmail.com>
Branch:
Changeset: r71496:ea4a7d70ec57
Date: 2014-05-13 21:06 +0100
http://bitbucket.org/pypy/pypy/changeset/ea4a7d70ec57/
Log: move FloatRepr and IntegerRepr to rfloat and rint respectively
diff --git a/rpython/rtyper/lltypesystem/rffi.py b/rpython/rtyper/lltypesystem/rffi.py
--- a/rpython/rtyper/lltypesystem/rffi.py
+++ b/rpython/rtyper/lltypesystem/rffi.py
@@ -1,7 +1,7 @@
import py
from rpython.annotator import model as annmodel
from rpython.rtyper.llannotation import SomePtr
-from rpython.rtyper.lltypesystem import lltype, rstr
+from rpython.rtyper.lltypesystem import lltype
from rpython.rtyper.lltypesystem import ll2ctypes
from rpython.rtyper.lltypesystem.llmemory import cast_ptr_to_adr
from rpython.rtyper.lltypesystem.llmemory import itemoffsetof
diff --git a/rpython/rtyper/lltypesystem/rstr.py b/rpython/rtyper/lltypesystem/rstr.py
--- a/rpython/rtyper/lltypesystem/rstr.py
+++ b/rpython/rtyper/lltypesystem/rstr.py
@@ -9,11 +9,11 @@
from rpython.rlib.rarithmetic import ovfcheck
from rpython.rtyper.error import TyperError
from rpython.rtyper.lltypesystem import ll_str, llmemory
-from rpython.rtyper.lltypesystem.lloperation import llop
from rpython.rtyper.lltypesystem.lltype import (GcStruct, Signed, Array, Char,
UniChar, Ptr, malloc, Bool, Void, GcArray, nullptr, cast_primitive,
typeOf, staticAdtMethod, GcForwardReference)
-from rpython.rtyper.rmodel import inputconst, Repr, IntegerRepr
+from rpython.rtyper.rmodel import inputconst, Repr
+from rpython.rtyper.rint import IntegerRepr
from rpython.rtyper.rstr import (AbstractStringRepr, AbstractCharRepr,
AbstractUniCharRepr, AbstractStringIteratorRepr, AbstractLLHelpers,
AbstractUnicodeRepr)
diff --git a/rpython/rtyper/module/r_os_stat.py b/rpython/rtyper/module/r_os_stat.py
--- a/rpython/rtyper/module/r_os_stat.py
+++ b/rpython/rtyper/module/r_os_stat.py
@@ -11,7 +11,8 @@
from rpython.rtyper.llannotation import lltype_to_annotation
from rpython.flowspace.model import Constant
from rpython.tool.pairtype import pairtype
-from rpython.rtyper.rmodel import Repr, IntegerRepr
+from rpython.rtyper.rmodel import Repr
+from rpython.rtyper.rint import IntegerRepr
from rpython.rtyper.error import TyperError
from rpython.rtyper.module import ll_os_stat
diff --git a/rpython/rtyper/raddress.py b/rpython/rtyper/raddress.py
--- a/rpython/rtyper/raddress.py
+++ b/rpython/rtyper/raddress.py
@@ -4,7 +4,8 @@
from rpython.rtyper.lltypesystem import lltype
from rpython.rtyper.lltypesystem.llmemory import (NULL, Address,
cast_adr_to_int, fakeaddress, sizeof)
-from rpython.rtyper.rmodel import Repr, IntegerRepr
+from rpython.rtyper.rmodel import Repr
+from rpython.rtyper.rint import IntegerRepr
from rpython.rtyper.rptr import PtrRepr
from rpython.tool.pairtype import pairtype
diff --git a/rpython/rtyper/rbool.py b/rpython/rtyper/rbool.py
--- a/rpython/rtyper/rbool.py
+++ b/rpython/rtyper/rbool.py
@@ -1,7 +1,9 @@
from rpython.annotator import model as annmodel
from rpython.rtyper.error import TyperError
from rpython.rtyper.lltypesystem.lltype import Signed, Unsigned, Bool, Float
-from rpython.rtyper.rmodel import IntegerRepr, log
+from rpython.rtyper.rmodel import log
+from rpython.rtyper.rint import IntegerRepr
+from rpython.rtyper.rfloat import FloatRepr
from rpython.tool.pairtype import pairtype
@@ -44,6 +46,20 @@
#
# _________________________ Conversions _________________________
+class __extend__(pairtype(BoolRepr, FloatRepr)):
+ def convert_from_to((r_from, r_to), v, llops):
+ if r_from.lowleveltype == Bool and r_to.lowleveltype == Float:
+ log.debug('explicit cast_bool_to_float')
+ return llops.genop('cast_bool_to_float', [v], resulttype=Float)
+ return NotImplemented
+
+class __extend__(pairtype(FloatRepr, BoolRepr)):
+ def convert_from_to((r_from, r_to), v, llops):
+ if r_from.lowleveltype == Float and r_to.lowleveltype == Bool:
+ log.debug('explicit cast_float_to_bool')
+ return llops.genop('float_is_true', [v], resulttype=Bool)
+ return NotImplemented
+
class __extend__(pairtype(BoolRepr, IntegerRepr)):
def convert_from_to((r_from, r_to), v, llops):
if r_from.lowleveltype == Bool and r_to.lowleveltype == Unsigned:
diff --git a/rpython/rtyper/rbytearray.py b/rpython/rtyper/rbytearray.py
--- a/rpython/rtyper/rbytearray.py
+++ b/rpython/rtyper/rbytearray.py
@@ -1,6 +1,6 @@
from rpython.annotator import model as annmodel
from rpython.rtyper.lltypesystem import lltype
-from rpython.rtyper.rmodel import IntegerRepr
+from rpython.rtyper.rint import IntegerRepr
from rpython.rtyper.rstr import AbstractStringRepr
from rpython.tool.pairtype import pairtype
diff --git a/rpython/rtyper/rfloat.py b/rpython/rtyper/rfloat.py
--- a/rpython/rtyper/rfloat.py
+++ b/rpython/rtyper/rfloat.py
@@ -1,17 +1,65 @@
from rpython.annotator import model as annmodel
from rpython.rlib.objectmodel import _hash_float
from rpython.rlib.rarithmetic import base_int
-from rpython.rlib.rfloat import formatd
from rpython.rlib import jit
from rpython.rtyper.annlowlevel import llstr
from rpython.rtyper.error import TyperError
-from rpython.rtyper.lltypesystem.lltype import (Signed, Unsigned,
- SignedLongLong, UnsignedLongLong, Bool, Float)
-from rpython.rtyper.rmodel import FloatRepr, IntegerRepr, log
-from rpython.rtyper.rbool import BoolRepr
-from rpython.rtyper.rstr import AbstractStringRepr
+from rpython.rtyper.lltypesystem.lltype import (Signed, Bool, Float)
+from rpython.rtyper.rmodel import Repr
from rpython.tool.pairtype import pairtype
+class FloatRepr(Repr):
+ lowleveltype = Float
+
+ def convert_const(self, value):
+ if not isinstance(value, (int, base_int, float)): # can be bool too
+ raise TyperError("not a float: %r" % (value,))
+ return float(value)
+
+ def get_ll_eq_function(self):
+ return None
+ get_ll_gt_function = get_ll_eq_function
+ get_ll_lt_function = get_ll_eq_function
+ get_ll_ge_function = get_ll_eq_function
+ get_ll_le_function = get_ll_eq_function
+
+ def get_ll_hash_function(self):
+ return _hash_float
+
+ def rtype_bool(_, hop):
+ vlist = hop.inputargs(Float)
+ return hop.genop('float_is_true', vlist, resulttype=Bool)
+
+ def rtype_neg(_, hop):
+ vlist = hop.inputargs(Float)
+ return hop.genop('float_neg', vlist, resulttype=Float)
+
+ def rtype_pos(_, hop):
+ vlist = hop.inputargs(Float)
+ return vlist[0]
+
+ def rtype_abs(_, hop):
+ vlist = hop.inputargs(Float)
+ return hop.genop('float_abs', vlist, resulttype=Float)
+
+ def rtype_int(_, hop):
+ vlist = hop.inputargs(Float)
+ # int(x) never raises in RPython, you need to use
+ # rarithmetic.ovfcheck_float_to_int() if you want this
+ hop.exception_cannot_occur()
+ return hop.genop('cast_float_to_int', vlist, resulttype=Signed)
+
+ def rtype_float(_, hop):
+ vlist = hop.inputargs(Float)
+ hop.exception_cannot_occur()
+ return vlist[0]
+
+ @jit.elidable
+ def ll_str(self, f):
+ from rpython.rlib.rfloat import formatd
+ return llstr(formatd(f, 'f', 6))
+
+float_repr = FloatRepr()
class __extend__(annmodel.SomeFloat):
def rtyper_makerepr(self, rtyper):
@@ -21,9 +69,6 @@
return self.__class__,
-float_repr = FloatRepr()
-
-
class __extend__(pairtype(FloatRepr, FloatRepr)):
#Arithmetic
@@ -76,11 +121,6 @@
def rtype_ge(_, hop):
return _rtype_compare_template(hop, 'ge')
-class __extend__(pairtype(AbstractStringRepr, FloatRepr)):
- def rtype_mod(_, hop):
- from rpython.rtyper.lltypesystem.rstr import do_stringformat
- return do_stringformat(hop, [(hop.args_v[1], hop.args_r[1])])
-
#Helpers FloatRepr,FloatRepr
def _rtype_template(hop, func):
@@ -92,104 +132,6 @@
return hop.genop('float_'+func, vlist, resulttype=Bool)
-class __extend__(FloatRepr):
-
- def convert_const(self, value):
- if not isinstance(value, (int, base_int, float)): # can be bool too
- raise TyperError("not a float: %r" % (value,))
- return float(value)
-
- def get_ll_eq_function(self):
- return None
- get_ll_gt_function = get_ll_eq_function
- get_ll_lt_function = get_ll_eq_function
- get_ll_ge_function = get_ll_eq_function
- get_ll_le_function = get_ll_eq_function
-
- def get_ll_hash_function(self):
- return _hash_float
-
- def rtype_bool(_, hop):
- vlist = hop.inputargs(Float)
- return hop.genop('float_is_true', vlist, resulttype=Bool)
-
- def rtype_neg(_, hop):
- vlist = hop.inputargs(Float)
- return hop.genop('float_neg', vlist, resulttype=Float)
-
- def rtype_pos(_, hop):
- vlist = hop.inputargs(Float)
- return vlist[0]
-
- def rtype_abs(_, hop):
- vlist = hop.inputargs(Float)
- return hop.genop('float_abs', vlist, resulttype=Float)
-
- def rtype_int(_, hop):
- vlist = hop.inputargs(Float)
- # int(x) never raises in RPython, you need to use
- # rarithmetic.ovfcheck_float_to_int() if you want this
- hop.exception_cannot_occur()
- return hop.genop('cast_float_to_int', vlist, resulttype=Signed)
-
- def rtype_float(_, hop):
- vlist = hop.inputargs(Float)
- hop.exception_cannot_occur()
- return vlist[0]
-
- @jit.elidable
- def ll_str(self, f):
- return llstr(formatd(f, 'f', 6))
-
-#
-# _________________________ Conversions _________________________
-
-class __extend__(pairtype(IntegerRepr, FloatRepr)):
- def convert_from_to((r_from, r_to), v, llops):
- if r_from.lowleveltype == Unsigned and r_to.lowleveltype == Float:
- log.debug('explicit cast_uint_to_float')
- return llops.genop('cast_uint_to_float', [v], resulttype=Float)
- if r_from.lowleveltype == Signed and r_to.lowleveltype == Float:
- log.debug('explicit cast_int_to_float')
- return llops.genop('cast_int_to_float', [v], resulttype=Float)
- if r_from.lowleveltype == SignedLongLong and r_to.lowleveltype == Float:
- log.debug('explicit cast_longlong_to_float')
- return llops.genop('cast_longlong_to_float', [v], resulttype=Float)
- if r_from.lowleveltype == UnsignedLongLong and r_to.lowleveltype == Float:
- log.debug('explicit cast_ulonglong_to_float')
- return llops.genop('cast_ulonglong_to_float', [v], resulttype=Float)
- return NotImplemented
-
-class __extend__(pairtype(FloatRepr, IntegerRepr)):
- def convert_from_to((r_from, r_to), v, llops):
- if r_from.lowleveltype == Float and r_to.lowleveltype == Unsigned:
- log.debug('explicit cast_float_to_uint')
- return llops.genop('cast_float_to_uint', [v], resulttype=Unsigned)
- if r_from.lowleveltype == Float and r_to.lowleveltype == Signed:
- log.debug('explicit cast_float_to_int')
- return llops.genop('cast_float_to_int', [v], resulttype=Signed)
- if r_from.lowleveltype == Float and r_to.lowleveltype == SignedLongLong:
- log.debug('explicit cast_float_to_longlong')
- return llops.genop('cast_float_to_longlong', [v], resulttype=SignedLongLong)
- if r_from.lowleveltype == Float and r_to.lowleveltype == UnsignedLongLong:
- log.debug('explicit cast_float_to_ulonglong')
- return llops.genop('cast_float_to_ulonglong', [v], resulttype=UnsignedLongLong)
- return NotImplemented
-
-class __extend__(pairtype(BoolRepr, FloatRepr)):
- def convert_from_to((r_from, r_to), v, llops):
- if r_from.lowleveltype == Bool and r_to.lowleveltype == Float:
- log.debug('explicit cast_bool_to_float')
- return llops.genop('cast_bool_to_float', [v], resulttype=Float)
- return NotImplemented
-
-class __extend__(pairtype(FloatRepr, BoolRepr)):
- def convert_from_to((r_from, r_to), v, llops):
- if r_from.lowleveltype == Float and r_to.lowleveltype == Bool:
- log.debug('explicit cast_float_to_bool')
- return llops.genop('float_is_true', [v], resulttype=Bool)
- return NotImplemented
-
# ______________________________________________________________________
# Support for r_singlefloat and r_longfloat from rpython.rlib.rarithmetic
diff --git a/rpython/rtyper/rint.py b/rpython/rtyper/rint.py
--- a/rpython/rtyper/rint.py
+++ b/rpython/rtyper/rint.py
@@ -8,9 +8,166 @@
from rpython.rtyper.lltypesystem.lltype import (Signed, Unsigned, Bool, Float,
Char, UniChar, UnsignedLongLong, SignedLongLong, build_number, Number,
cast_primitive, typeOf, SignedLongLongLong)
-from rpython.rtyper.rmodel import IntegerRepr, inputconst, log
+from rpython.rtyper.rfloat import FloatRepr
+from rpython.rtyper.rmodel import inputconst, log
from rpython.tool.pairtype import pairtype
+class IntegerRepr(FloatRepr):
+ def __init__(self, lowleveltype, opprefix):
+ self.lowleveltype = lowleveltype
+ self._opprefix = opprefix
+ self.as_int = self
+
+ @property
+ def opprefix(self):
+ if self._opprefix is None:
+ raise TyperError("arithmetic not supported on %r, its size is too small" %
+ self.lowleveltype)
+ return self._opprefix
+
+ def convert_const(self, value):
+ if isinstance(value, objectmodel.Symbolic):
+ return value
+ T = typeOf(value)
+ if isinstance(T, Number) or T is Bool:
+ return cast_primitive(self.lowleveltype, value)
+ raise TyperError("not an integer: %r" % (value,))
+
+ def get_ll_eq_function(self):
+ if getattr(self, '_opprefix', '?') is None:
+ return ll_eq_shortint
+ return None
+
+ def get_ll_ge_function(self):
+ return None
+ get_ll_gt_function = get_ll_ge_function
+ get_ll_lt_function = get_ll_ge_function
+ get_ll_le_function = get_ll_ge_function
+
+ def get_ll_hash_function(self):
+ if (sys.maxint == 2147483647 and
+ self.lowleveltype in (SignedLongLong, UnsignedLongLong)):
+ return ll_hash_long_long
+ return ll_hash_int
+
+ get_ll_fasthash_function = get_ll_hash_function
+
+ def get_ll_dummyval_obj(self, rtyper, s_value):
+ # if >= 0, then all negative values are special
+ if s_value.nonneg and self.lowleveltype is Signed:
+ return signed_repr # whose ll_dummy_value is -1
+ else:
+ return None
+
+ ll_dummy_value = -1
+
+ def rtype_chr(_, hop):
+ vlist = hop.inputargs(Signed)
+ if hop.has_implicit_exception(ValueError):
+ hop.exception_is_here()
+ hop.gendirectcall(ll_check_chr, vlist[0])
+ else:
+ hop.exception_cannot_occur()
+ return hop.genop('cast_int_to_char', vlist, resulttype=Char)
+
+ def rtype_unichr(_, hop):
+ vlist = hop.inputargs(Signed)
+ if hop.has_implicit_exception(ValueError):
+ hop.exception_is_here()
+ hop.gendirectcall(ll_check_unichr, vlist[0])
+ else:
+ hop.exception_cannot_occur()
+ return hop.genop('cast_int_to_unichar', vlist, resulttype=UniChar)
+
+ def rtype_bool(self, hop):
+ assert self is self.as_int # rtype_is_true() is overridden in BoolRepr
+ vlist = hop.inputargs(self)
+ return hop.genop(self.opprefix + 'is_true', vlist, resulttype=Bool)
+
+ #Unary arithmetic operations
+
+ def rtype_abs(self, hop):
+ self = self.as_int
+ vlist = hop.inputargs(self)
+ if hop.s_result.unsigned:
+ return vlist[0]
+ else:
+ return hop.genop(self.opprefix + 'abs', vlist, resulttype=self)
+
+ def rtype_abs_ovf(self, hop):
+ self = self.as_int
+ if hop.s_result.unsigned:
+ raise TyperError("forbidden uint_abs_ovf")
+ else:
+ vlist = hop.inputargs(self)
+ hop.has_implicit_exception(OverflowError) # record we know about it
+ hop.exception_is_here()
+ return hop.genop(self.opprefix + 'abs_ovf', vlist, resulttype=self)
+
+ def rtype_invert(self, hop):
+ self = self.as_int
+ vlist = hop.inputargs(self)
+ return hop.genop(self.opprefix + 'invert', vlist, resulttype=self)
+
+ def rtype_neg(self, hop):
+ self = self.as_int
+ vlist = hop.inputargs(self)
+ if hop.s_result.unsigned:
+ # implement '-r_uint(x)' with unsigned subtraction '0 - x'
+ zero = self.lowleveltype._defl()
+ vlist.insert(0, hop.inputconst(self.lowleveltype, zero))
+ return hop.genop(self.opprefix + 'sub', vlist, resulttype=self)
+ else:
+ return hop.genop(self.opprefix + 'neg', vlist, resulttype=self)
+
+ def rtype_neg_ovf(self, hop):
+ self = self.as_int
+ if hop.s_result.unsigned:
+ # this is supported (and turns into just 0-x) for rbigint.py
+ hop.exception_cannot_occur()
+ return self.rtype_neg(hop)
+ else:
+ vlist = hop.inputargs(self)
+ hop.has_implicit_exception(OverflowError) # record we know about it
+ hop.exception_is_here()
+ return hop.genop(self.opprefix + 'neg_ovf', vlist, resulttype=self)
+
+ def rtype_pos(self, hop):
+ self = self.as_int
+ vlist = hop.inputargs(self)
+ return vlist[0]
+
+ def rtype_int(self, hop):
+ if self.lowleveltype in (Unsigned, UnsignedLongLong):
+ raise TyperError("use intmask() instead of int(r_uint(...))")
+ vlist = hop.inputargs(Signed)
+ hop.exception_cannot_occur()
+ return vlist[0]
+
+ def rtype_float(_, hop):
+ vlist = hop.inputargs(Float)
+ hop.exception_cannot_occur()
+ return vlist[0]
+
+ @jit.elidable
+ def ll_str(self, i):
+ from rpython.rtyper.lltypesystem.ll_str import ll_int2dec
+ return ll_int2dec(i)
+
+ def rtype_hex(self, hop):
+ from rpython.rtyper.lltypesystem.ll_str import ll_int2hex
+ self = self.as_int
+ varg = hop.inputarg(self, 0)
+ true = inputconst(Bool, True)
+ return hop.gendirectcall(ll_int2hex, varg, true)
+
+ def rtype_oct(self, hop):
+ from rpython.rtyper.lltypesystem.ll_str import ll_int2oct
+ self = self.as_int
+ varg = hop.inputarg(self, 0)
+ true = inputconst(Bool, True)
+ return hop.gendirectcall(ll_int2oct, varg, true)
+
_integer_reprs = {}
def getintegerrepr(lltype, prefix=None):
@@ -235,156 +392,11 @@
repr = hop.rtyper.getrepr(annmodel.unionof(s_int1, s_int2)).as_int
vlist = hop.inputargs(repr, repr)
hop.exception_is_here()
- return hop.genop(repr.opprefix+func, vlist, resulttype=Bool)
+ return hop.genop(repr.opprefix + func, vlist, resulttype=Bool)
#
-class __extend__(IntegerRepr):
-
- def convert_const(self, value):
- if isinstance(value, objectmodel.Symbolic):
- return value
- T = typeOf(value)
- if isinstance(T, Number) or T is Bool:
- return cast_primitive(self.lowleveltype, value)
- raise TyperError("not an integer: %r" % (value,))
-
- def get_ll_eq_function(self):
- if getattr(self, '_opprefix', '?') is None:
- return ll_eq_shortint
- return None
-
- def get_ll_ge_function(self):
- return None
- get_ll_gt_function = get_ll_ge_function
- get_ll_lt_function = get_ll_ge_function
- get_ll_le_function = get_ll_ge_function
-
- def get_ll_hash_function(self):
- if (sys.maxint == 2147483647 and
- self.lowleveltype in (SignedLongLong, UnsignedLongLong)):
- return ll_hash_long_long
- return ll_hash_int
-
- get_ll_fasthash_function = get_ll_hash_function
-
- def get_ll_dummyval_obj(self, rtyper, s_value):
- # if >= 0, then all negative values are special
- if s_value.nonneg and self.lowleveltype is Signed:
- return signed_repr # whose ll_dummy_value is -1
- else:
- return None
-
- ll_dummy_value = -1
-
- def rtype_chr(_, hop):
- vlist = hop.inputargs(Signed)
- if hop.has_implicit_exception(ValueError):
- hop.exception_is_here()
- hop.gendirectcall(ll_check_chr, vlist[0])
- else:
- hop.exception_cannot_occur()
- return hop.genop('cast_int_to_char', vlist, resulttype=Char)
-
- def rtype_unichr(_, hop):
- vlist = hop.inputargs(Signed)
- if hop.has_implicit_exception(ValueError):
- hop.exception_is_here()
- hop.gendirectcall(ll_check_unichr, vlist[0])
- else:
- hop.exception_cannot_occur()
- return hop.genop('cast_int_to_unichar', vlist, resulttype=UniChar)
-
- def rtype_bool(self, hop):
- assert self is self.as_int # rtype_is_true() is overridden in BoolRepr
- vlist = hop.inputargs(self)
- return hop.genop(self.opprefix + 'is_true', vlist, resulttype=Bool)
-
- #Unary arithmetic operations
-
- def rtype_abs(self, hop):
- self = self.as_int
- vlist = hop.inputargs(self)
- if hop.s_result.unsigned:
- return vlist[0]
- else:
- return hop.genop(self.opprefix + 'abs', vlist, resulttype=self)
-
- def rtype_abs_ovf(self, hop):
- self = self.as_int
- if hop.s_result.unsigned:
- raise TyperError("forbidden uint_abs_ovf")
- else:
- vlist = hop.inputargs(self)
- hop.has_implicit_exception(OverflowError) # record we know about it
- hop.exception_is_here()
- return hop.genop(self.opprefix + 'abs_ovf', vlist, resulttype=self)
-
- def rtype_invert(self, hop):
- self = self.as_int
- vlist = hop.inputargs(self)
- return hop.genop(self.opprefix + 'invert', vlist, resulttype=self)
-
- def rtype_neg(self, hop):
- self = self.as_int
- vlist = hop.inputargs(self)
- if hop.s_result.unsigned:
- # implement '-r_uint(x)' with unsigned subtraction '0 - x'
- zero = self.lowleveltype._defl()
- vlist.insert(0, hop.inputconst(self.lowleveltype, zero))
- return hop.genop(self.opprefix + 'sub', vlist, resulttype=self)
- else:
- return hop.genop(self.opprefix + 'neg', vlist, resulttype=self)
-
- def rtype_neg_ovf(self, hop):
- self = self.as_int
- if hop.s_result.unsigned:
- # this is supported (and turns into just 0-x) for rbigint.py
- hop.exception_cannot_occur()
- return self.rtype_neg(hop)
- else:
- vlist = hop.inputargs(self)
- hop.has_implicit_exception(OverflowError) # record we know about it
- hop.exception_is_here()
- return hop.genop(self.opprefix + 'neg_ovf', vlist, resulttype=self)
-
- def rtype_pos(self, hop):
- self = self.as_int
- vlist = hop.inputargs(self)
- return vlist[0]
-
- def rtype_int(self, hop):
- if self.lowleveltype in (Unsigned, UnsignedLongLong):
- raise TyperError("use intmask() instead of int(r_uint(...))")
- vlist = hop.inputargs(Signed)
- hop.exception_cannot_occur()
- return vlist[0]
-
- def rtype_float(_, hop):
- vlist = hop.inputargs(Float)
- hop.exception_cannot_occur()
- return vlist[0]
-
- @jit.elidable
- def ll_str(self, i):
- from rpython.rtyper.lltypesystem.ll_str import ll_int2dec
- return ll_int2dec(i)
-
- def rtype_hex(self, hop):
- from rpython.rtyper.lltypesystem.ll_str import ll_int2hex
- self = self.as_int
- varg = hop.inputarg(self, 0)
- true = inputconst(Bool, True)
- return hop.gendirectcall(ll_int2hex, varg, true)
-
- def rtype_oct(self, hop):
- from rpython.rtyper.lltypesystem.ll_str import ll_int2oct
- self = self.as_int
- varg = hop.inputarg(self, 0)
- true = inputconst(Bool, True)
- return hop.gendirectcall(ll_int2oct, varg, true)
-
def ll_hash_int(n):
return intmask(n)
@@ -407,3 +419,38 @@
return
else:
raise ValueError
+
+#
+# _________________________ Conversions _________________________
+
+class __extend__(pairtype(IntegerRepr, FloatRepr)):
+ def convert_from_to((r_from, r_to), v, llops):
+ if r_from.lowleveltype == Unsigned and r_to.lowleveltype == Float:
+ log.debug('explicit cast_uint_to_float')
+ return llops.genop('cast_uint_to_float', [v], resulttype=Float)
+ if r_from.lowleveltype == Signed and r_to.lowleveltype == Float:
+ log.debug('explicit cast_int_to_float')
+ return llops.genop('cast_int_to_float', [v], resulttype=Float)
+ if r_from.lowleveltype == SignedLongLong and r_to.lowleveltype == Float:
+ log.debug('explicit cast_longlong_to_float')
+ return llops.genop('cast_longlong_to_float', [v], resulttype=Float)
+ if r_from.lowleveltype == UnsignedLongLong and r_to.lowleveltype == Float:
+ log.debug('explicit cast_ulonglong_to_float')
+ return llops.genop('cast_ulonglong_to_float', [v], resulttype=Float)
+ return NotImplemented
+
+class __extend__(pairtype(FloatRepr, IntegerRepr)):
+ def convert_from_to((r_from, r_to), v, llops):
+ if r_from.lowleveltype == Float and r_to.lowleveltype == Unsigned:
+ log.debug('explicit cast_float_to_uint')
+ return llops.genop('cast_float_to_uint', [v], resulttype=Unsigned)
+ if r_from.lowleveltype == Float and r_to.lowleveltype == Signed:
+ log.debug('explicit cast_float_to_int')
+ return llops.genop('cast_float_to_int', [v], resulttype=Signed)
+ if r_from.lowleveltype == Float and r_to.lowleveltype == SignedLongLong:
+ log.debug('explicit cast_float_to_longlong')
+ return llops.genop('cast_float_to_longlong', [v], resulttype=SignedLongLong)
+ if r_from.lowleveltype == Float and r_to.lowleveltype == UnsignedLongLong:
+ log.debug('explicit cast_float_to_ulonglong')
+ return llops.genop('cast_float_to_ulonglong', [v], resulttype=UnsignedLongLong)
+ return NotImplemented
diff --git a/rpython/rtyper/rlist.py b/rpython/rtyper/rlist.py
--- a/rpython/rtyper/rlist.py
+++ b/rpython/rtyper/rlist.py
@@ -9,7 +9,8 @@
from rpython.rtyper.error import TyperError
from rpython.rtyper.lltypesystem.lltype import typeOf, Ptr, Void, Signed, Bool
from rpython.rtyper.lltypesystem.lltype import nullptr, Char, UniChar, Number
-from rpython.rtyper.rmodel import Repr, IteratorRepr, IntegerRepr
+from rpython.rtyper.rmodel import Repr, IteratorRepr
+from rpython.rtyper.rint import IntegerRepr
from rpython.rtyper.rstr import AbstractStringRepr, AbstractCharRepr
from rpython.tool.pairtype import pairtype, pair
diff --git a/rpython/rtyper/rmodel.py b/rpython/rtyper/rmodel.py
--- a/rpython/rtyper/rmodel.py
+++ b/rpython/rtyper/rmodel.py
@@ -2,7 +2,7 @@
from rpython.flowspace.model import Constant
from rpython.rtyper.error import TyperError, MissingRTypeOperation
from rpython.rtyper.lltypesystem import lltype
-from rpython.rtyper.lltypesystem.lltype import (Void, Bool, Float, typeOf,
+from rpython.rtyper.lltypesystem.lltype import (Void, Bool, typeOf,
LowLevelType, isCompatibleType)
from rpython.tool.pairtype import pairtype, extendabletype, pair
@@ -322,25 +322,6 @@
return NotImplemented
# ____________________________________________________________
-# Primitive Repr classes, in the same hierarchical order as
-# the corresponding SomeObjects
-
-class FloatRepr(Repr):
- lowleveltype = Float
-
-class IntegerRepr(FloatRepr):
- def __init__(self, lowleveltype, opprefix):
- self.lowleveltype = lowleveltype
- self._opprefix = opprefix
- self.as_int = self
-
- def _get_opprefix(self):
- if self._opprefix is None:
- raise TyperError("arithmetic not supported on %r, its size is too small" %
- self.lowleveltype)
- return self._opprefix
-
- opprefix = property(_get_opprefix)
class VoidRepr(Repr):
lowleveltype = Void
diff --git a/rpython/rtyper/rptr.py b/rpython/rtyper/rptr.py
--- a/rpython/rtyper/rptr.py
+++ b/rpython/rtyper/rptr.py
@@ -5,7 +5,8 @@
from rpython.rlib.rarithmetic import r_uint
from rpython.rtyper.error import TyperError
from rpython.rtyper.lltypesystem import lltype
-from rpython.rtyper.rmodel import Repr, IntegerRepr
+from rpython.rtyper.rmodel import Repr
+from rpython.rtyper.rint import IntegerRepr
from rpython.tool.pairtype import pairtype
diff --git a/rpython/rtyper/rrange.py b/rpython/rtyper/rrange.py
--- a/rpython/rtyper/rrange.py
+++ b/rpython/rtyper/rrange.py
@@ -2,7 +2,8 @@
from rpython.rtyper.error import TyperError
from rpython.rtyper.lltypesystem.lltype import Signed, Void, Ptr
from rpython.rtyper.rlist import dum_nocheck, dum_checkidx
-from rpython.rtyper.rmodel import Repr, IntegerRepr, IteratorRepr
+from rpython.rtyper.rmodel import Repr, IteratorRepr
+from rpython.rtyper.rint import IntegerRepr
from rpython.tool.pairtype import pairtype
diff --git a/rpython/rtyper/rstr.py b/rpython/rtyper/rstr.py
--- a/rpython/rtyper/rstr.py
+++ b/rpython/rtyper/rstr.py
@@ -3,7 +3,9 @@
from rpython.rtyper import rint
from rpython.rtyper.error import TyperError
from rpython.rtyper.lltypesystem.lltype import Signed, Bool, Void, UniChar
-from rpython.rtyper.rmodel import IntegerRepr, IteratorRepr, inputconst, Repr
+from rpython.rtyper.rmodel import IteratorRepr, inputconst, Repr
+from rpython.rtyper.rint import IntegerRepr
+from rpython.rtyper.rfloat import FloatRepr
from rpython.tool.pairtype import pairtype, pair
from rpython.tool.sourcetools import func_with_new_name
from rpython.tool.staticmethods import StaticMethods
@@ -473,6 +475,11 @@
# overriding rtype_mod() below
return r_str.ll.do_stringformat(hop, [(hop.args_v[1], hop.args_r[1])])
+class __extend__(pairtype(AbstractStringRepr, FloatRepr)):
+ def rtype_mod(_, hop):
+ from rpython.rtyper.lltypesystem.rstr import do_stringformat
+ return do_stringformat(hop, [(hop.args_v[1], hop.args_r[1])])
+
class __extend__(pairtype(AbstractStringRepr, IntegerRepr)):
def rtype_getitem((r_str, r_int), hop, checkidx=False):
diff --git a/rpython/rtyper/rtuple.py b/rpython/rtyper/rtuple.py
--- a/rpython/rtyper/rtuple.py
+++ b/rpython/rtyper/rtuple.py
@@ -9,8 +9,9 @@
Void, Signed, Bool, Ptr, GcStruct, malloc, typeOf, nullptr)
from rpython.rtyper.lltypesystem.rstr import LLHelpers
from rpython.rtyper.rstr import AbstractStringRepr
-from rpython.rtyper.rmodel import (Repr, IntegerRepr, inputconst, IteratorRepr,
+from rpython.rtyper.rmodel import (Repr, inputconst, IteratorRepr,
externalvsinternal)
+from rpython.rtyper.rint import IntegerRepr
from rpython.tool.pairtype import pairtype
More information about the pypy-commit
mailing list