[pypy-svn] r13400 - pypy/dist/pypy/rpython
arigo at codespeak.net
arigo at codespeak.net
Tue Jun 14 19:59:45 CEST 2005
Author: arigo
Date: Tue Jun 14 19:59:43 2005
New Revision: 13400
Modified:
pypy/dist/pypy/rpython/rint.py
pypy/dist/pypy/rpython/rtyper.py
Log:
Completed rint.py with all _ovf version of the operations and with the
exceptional low-level operations (xxx_zer, xxx_val) that are used if we see
the corresponding ZeroDivisionError or ValueError caught.
Modified: pypy/dist/pypy/rpython/rint.py
==============================================================================
--- pypy/dist/pypy/rpython/rint.py (original)
+++ pypy/dist/pypy/rpython/rint.py Tue Jun 14 19:59:43 2005
@@ -54,18 +54,42 @@
return _rtype_template(hop, 'mul')
rtype_inplace_mul = rtype_mul
+ def rtype_mul_ovf(_, hop):
+ return _rtype_template(hop, 'mul_ovf')
+ rtype_inplace_mul_ovf = rtype_mul_ovf
+
def rtype_div(_, hop):
- return _rtype_template(hop, 'div')
+ return _rtype_template(hop, 'div', [ZeroDivisionError])
rtype_inplace_div = rtype_div
+ def rtype_div_ovf(_, hop):
+ return _rtype_template(hop, 'div_ovf', [ZeroDivisionError])
+ rtype_inplace_div_ovf = rtype_div_ovf
+
def rtype_floordiv(_, hop):
- return _rtype_template(hop, 'floordiv')
+ return _rtype_template(hop, 'floordiv', [ZeroDivisionError])
rtype_inplace_floordiv = rtype_floordiv
+ def rtype_floordiv_ovf(_, hop):
+ return _rtype_template(hop, 'floordiv_ovf', [ZeroDivisionError])
+ rtype_inplace_floordiv_ovf = rtype_floordiv_ovf
+
+ def rtype_truediv(_, hop):
+ return _rtype_template(hop, 'truediv', [ZeroDivisionError])
+ rtype_inplace_truediv = rtype_truediv
+
+ def rtype_truediv_ovf(_, hop):
+ return _rtype_template(hop, 'truediv_ovf', [ZeroDivisionError])
+ rtype_inplace_truediv_ovf = rtype_truediv_ovf
+
def rtype_mod(_, hop):
- return _rtype_template(hop, 'mod')
+ return _rtype_template(hop, 'mod', [ZeroDivisionError])
rtype_inplace_mod = rtype_mod
+ def rtype_mod_ovf(_, hop):
+ return _rtype_template(hop, 'mod_ovf', [ZeroDivisionError])
+ rtype_inplace_mod_ovf = rtype_mod_ovf
+
def rtype_xor(_, hop):
return _rtype_template(hop, 'xor')
rtype_inplace_xor = rtype_xor
@@ -79,38 +103,44 @@
rtype_inplace_or = rtype_or_
def rtype_lshift(_, hop):
- return _rtype_template(hop, 'lshift')
+ return _rtype_template(hop, 'lshift', [ValueError])
rtype_inplace_lshift = rtype_lshift
def rtype_lshift_ovf(_, hop):
- return _rtype_template(hop, 'lshift_ovf')
+ return _rtype_template(hop, 'lshift_ovf', [ValueError])
rtype_inplace_lshift_ovf = rtype_lshift_ovf
def rtype_rshift(_, hop):
- return _rtype_template(hop, 'rshift')
+ return _rtype_template(hop, 'rshift', [ValueError])
rtype_inplace_rshift = rtype_rshift
- def rtype_rshift_ovf(_, hop):
- return _rtype_template(hop, 'rshift_ovf')
- rtype_inplace_rshift_ovf = rtype_rshift_ovf
-
- def rtype_pow(_, hop):
+ def rtype_pow(_, hop, suffix=''):
+ if hop.has_implicit_exception(ZeroDivisionError):
+ suffix += '_zer'
s_int3 = hop.args_s[2]
if hop.s_result.unsigned:
if s_int3.is_constant() and s_int3.const is None:
vlist = hop.inputargs(Unsigned, Unsigned, Void)[:2]
else:
vlist = hop.inputargs(Unsigned, Unsigned, Unsigned)
- return hop.genop('uint_pow', vlist, resulttype=Unsigned)
+ return hop.genop('uint_pow' + suffix, vlist, resulttype=Unsigned)
else:
if s_int3.is_constant() and s_int3.const is None:
vlist = hop.inputargs(Signed, Signed, Void)[:2]
else:
vlist = hop.inputargs(Signed, Signed, Signed)
- return hop.genop('int_pow', vlist, resulttype=Signed)
+ return hop.genop('int_pow' + suffix, vlist, resulttype=Signed)
+
+ def rtype_pow_ovf(_, hop):
+ if hop.s_result.unsigned:
+ raise TyperError("forbidden uint_pow_ovf")
+ return self.rtype_pow(_, hop, suffix='_ovf')
def rtype_inplace_pow(_, hop):
- return _rtype_template(hop, 'pow')
+ return _rtype_template(hop, 'pow', [ZeroDivisionError])
+
+ def rtype_inplace_pow_ovf(_, hop):
+ return _rtype_template(hop, 'pow_ovf', [ZeroDivisionError])
#comparisons: eq is_ ne lt le gt ge
@@ -136,8 +166,14 @@
#Helper functions
-def _rtype_template(hop, func):
+def _rtype_template(hop, func, implicit_excs=[]):
+ func1 = func
+ for implicit_exc in implicit_excs:
+ if hop.has_implicit_exception(implicit_exc):
+ func += '_' + implicit_exc.__name__[:3].lower()
if hop.s_result.unsigned:
+ if func1.endswith('_ovf'):
+ raise TyperError("forbidden uint_" + func)
vlist = hop.inputargs(Unsigned, Unsigned)
return hop.genop('uint_'+func, vlist, resulttype=Unsigned)
else:
@@ -191,8 +227,7 @@
def rtype_abs_ovf(_, hop):
if hop.s_result.unsigned:
- vlist = hop.inputargs(Unsigned)
- return vlist[0]
+ raise TyperError("forbidden uint_abs_ovf")
else:
vlist = hop.inputargs(Signed)
return hop.genop('int_abs_ovf', vlist, resulttype=Signed)
@@ -213,6 +248,13 @@
vlist = hop.inputargs(Signed)
return hop.genop('int_neg', vlist, resulttype=Signed)
+ def rtype_neg_ovf(_, hop):
+ if hop.s_result.unsigned:
+ raise TyperError("forbidden uint_neg_ovf")
+ else:
+ vlist = hop.inputargs(Signed)
+ return hop.genop('int_neg_ovf', vlist, resulttype=Signed)
+
def rtype_pos(_, hop):
if hop.s_result.unsigned:
vlist = hop.inputargs(Unsigned)
Modified: pypy/dist/pypy/rpython/rtyper.py
==============================================================================
--- pypy/dist/pypy/rpython/rtyper.py (original)
+++ pypy/dist/pypy/rpython/rtyper.py Tue Jun 14 19:59:43 2005
@@ -1,3 +1,4 @@
+from __future__ import generators
import sys
from pypy.annotation.pairtype import pair
from pypy.annotation import model as annmodel
@@ -154,12 +155,11 @@
for v in block.getvariables():
varmapping[v] = v # records existing Variables
- for op in block.operations:
+ for hop in self.highlevelops(block, newops):
try:
- hop = HighLevelOp(self, op, newops)
self.translate_hl_to_ll(hop, varmapping)
except TyperError, e:
- self.gottypererror(e, block, op, newops)
+ self.gottypererror(e, block, hop.spaceop, newops)
return # cannot continue this block: no op.result.concretetype
block.operations[:] = newops
@@ -214,6 +214,18 @@
block.operations.extend(newops)
link.args[i] = a1
+ def highlevelops(self, block, llops):
+ # enumerate the HighLevelOps in a block.
+ if block.operations:
+ for op in block.operations[:-1]:
+ yield HighLevelOp(self, op, [], llops)
+ # look for exception links for the last operation
+ if block.exitswitch == Constant(last_exception):
+ exclinks = block.exits[1:]
+ else:
+ exclinks = []
+ yield HighLevelOp(self, block.operations[-1], exclinks, llops)
+
def translate_hl_to_ll(self, hop, varmapping):
if debug:
print hop.spaceop.opname, hop.args_s
@@ -327,7 +339,7 @@
class HighLevelOp:
nb_popped = 0
- def __init__(self, rtyper, spaceop, llops):
+ def __init__(self, rtyper, spaceop, exceptionlinks, llops):
self.rtyper = rtyper
self.spaceop = spaceop
self.nb_args = len(spaceop.args)
@@ -337,6 +349,7 @@
self.args_r = [rtyper.getrepr(s_a) for s_a in self.args_s]
self.r_result = rtyper.getrepr(self.s_result)
rtyper.call_all_setups() # compute ForwardReferences now
+ self.exceptionlinks = exceptionlinks
def inputarg(self, converted_to, arg):
"""Returns the arg'th input argument of the current operation,
@@ -381,6 +394,12 @@
self.nb_args -= 1
return self.args_r.pop(0), self.args_s.pop(0)
+ def has_implicit_exception(self, exc_cls):
+ for link in self.exceptionlinks:
+ if issubclass(exc_cls, link.exitcase):
+ return True
+ return False
+
# ____________________________________________________________
class LowLevelOpList(list):
More information about the Pypy-commit
mailing list