Author: Alex Gaynor <[email protected]>
Branch:
Changeset: r45336:6d1937f2d0a9
Date: 2011-07-04 07:51 -0700
http://bitbucket.org/pypy/pypy/changeset/6d1937f2d0a9/
Log: Merged upstream.
diff --git a/pypy/jit/metainterp/optimizeopt/fficall.py
b/pypy/jit/metainterp/optimizeopt/fficall.py
--- a/pypy/jit/metainterp/optimizeopt/fficall.py
+++ b/pypy/jit/metainterp/optimizeopt/fficall.py
@@ -4,7 +4,7 @@
from pypy.rlib.debug import debug_start, debug_stop, debug_print,
have_debug_prints
from pypy.jit.codewriter.effectinfo import EffectInfo
from pypy.jit.metainterp.resoperation import rop, ResOperation
-from pypy.jit.metainterp.optimizeopt.util import _findall
+from pypy.jit.metainterp.optimizeopt.util import make_dispatcher_method
from pypy.jit.metainterp.optimizeopt.optimizer import Optimization
from pypy.jit.backend.llsupport.ffisupport import UnsupportedKind
@@ -203,13 +203,7 @@
def propagate_forward(self, op):
if self.logops is not None:
debug_print(self.logops.repr_of_resop(op))
- opnum = op.getopnum()
- for value, func in optimize_ops:
- if opnum == value:
- func(self, op)
- break
- else:
- self.emit_operation(op)
+ dispatch_opt(self, op)
def _get_oopspec(self, op):
effectinfo = op.getdescr().get_extra_info()
@@ -220,4 +214,5 @@
def _get_funcval(self, op):
return self.getvalue(op.getarg(1))
-optimize_ops = _findall(OptFfiCall, 'optimize_')
+dispatch_opt = make_dispatcher_method(OptFfiCall, 'optimize_',
+ default=OptFfiCall.emit_operation)
diff --git a/pypy/jit/metainterp/optimizeopt/heap.py
b/pypy/jit/metainterp/optimizeopt/heap.py
--- a/pypy/jit/metainterp/optimizeopt/heap.py
+++ b/pypy/jit/metainterp/optimizeopt/heap.py
@@ -1,5 +1,5 @@
import os
-from pypy.jit.metainterp.optimizeopt.util import _findall
+from pypy.jit.metainterp.optimizeopt.util import make_dispatcher_method
from pypy.jit.metainterp.resoperation import rop, ResOperation
from pypy.rlib.objectmodel import we_are_translated
from pypy.jit.metainterp.jitexc import JitException
@@ -431,13 +431,7 @@
self._seen_guard_not_invalidated = True
self.emit_operation(op)
- def propagate_forward(self, op):
- opnum = op.getopnum()
- for value, func in optimize_ops:
- if opnum == value:
- func(self, op)
- break
- else:
- self.emit_operation(op)
-optimize_ops = _findall(OptHeap, 'optimize_')
+dispatch_opt = make_dispatcher_method(OptHeap, 'optimize_',
+ default=OptHeap.emit_operation)
+OptHeap.propagate_forward = dispatch_opt
diff --git a/pypy/jit/metainterp/optimizeopt/intbounds.py
b/pypy/jit/metainterp/optimizeopt/intbounds.py
--- a/pypy/jit/metainterp/optimizeopt/intbounds.py
+++ b/pypy/jit/metainterp/optimizeopt/intbounds.py
@@ -1,5 +1,5 @@
from pypy.jit.metainterp.optimizeopt.optimizer import Optimization, CONST_1,
CONST_0
-from pypy.jit.metainterp.optimizeopt.util import _findall
+from pypy.jit.metainterp.optimizeopt.util import make_dispatcher_method
from pypy.jit.metainterp.optimizeopt.intutils import (IntBound, IntUnbounded,
IntLowerBound, IntUpperBound)
from pypy.jit.metainterp.history import Const, ConstInt
@@ -34,14 +34,11 @@
op = self.posponedop
self.posponedop = None
- opnum = op.getopnum()
- for value, func in optimize_ops:
- if opnum == value:
- func(self, op)
- break
- else:
- assert not op.is_ovf()
- self.emit_operation(op)
+ dispatch_opt(self, op)
+
+ def opt_default(self, op):
+ assert not op.is_ovf()
+ self.emit_operation(op)
def propagate_bounds_backward(self, box):
@@ -57,11 +54,7 @@
op = self.optimizer.producer[box]
except KeyError:
return
- opnum = op.getopnum()
- for value, func in propagate_bounds_ops:
- if opnum == value:
- func(self, op)
- break
+ dispatch_bounds_ops(self, op)
def optimize_GUARD_TRUE(self, op):
self.emit_operation(op)
@@ -440,5 +433,6 @@
propagate_bounds_INT_MUL_OVF = propagate_bounds_INT_MUL
-optimize_ops = _findall(OptIntBounds, 'optimize_')
-propagate_bounds_ops = _findall(OptIntBounds, 'propagate_bounds_')
+dispatch_opt = make_dispatcher_method(OptIntBounds, 'optimize_',
+ default=OptIntBounds.opt_default)
+dispatch_bounds_ops = make_dispatcher_method(OptIntBounds, 'propagate_bounds_')
diff --git a/pypy/jit/metainterp/optimizeopt/optimizer.py
b/pypy/jit/metainterp/optimizeopt/optimizer.py
--- a/pypy/jit/metainterp/optimizeopt/optimizer.py
+++ b/pypy/jit/metainterp/optimizeopt/optimizer.py
@@ -4,7 +4,7 @@
from pypy.jit.metainterp.resoperation import rop, ResOperation
from pypy.jit.metainterp import jitprof
from pypy.jit.metainterp.executor import execute_nonspec
-from pypy.jit.metainterp.optimizeopt.util import _findall, sort_descrs
+from pypy.jit.metainterp.optimizeopt.util import make_dispatcher_method,
sort_descrs
from pypy.jit.metainterp.optimizeopt.util import descrlist_dict, args_dict
from pypy.jit.metainterp.optimize import InvalidLoop
from pypy.jit.metainterp import resume, compile
@@ -434,14 +434,7 @@
def propagate_forward(self, op):
self.producer[op.result] = op
- opnum = op.getopnum()
- for value, func in optimize_ops:
- if opnum == value:
- func(self, op)
- break
- else:
- self.optimize_default(op)
- #print '\n'.join([str(o) for o in self.newoperations]) + '\n---\n'
+ dispatch_opt(self, op)
def test_emittable(self, op):
return True
@@ -569,7 +562,8 @@
def optimize_DEBUG_MERGE_POINT(self, op):
self.emit_operation(op)
-optimize_ops = _findall(Optimizer, 'optimize_')
+dispatch_opt = make_dispatcher_method(Optimizer, 'optimize_',
+ default=Optimizer.optimize_default)
diff --git a/pypy/jit/metainterp/optimizeopt/rewrite.py
b/pypy/jit/metainterp/optimizeopt/rewrite.py
--- a/pypy/jit/metainterp/optimizeopt/rewrite.py
+++ b/pypy/jit/metainterp/optimizeopt/rewrite.py
@@ -1,7 +1,7 @@
from pypy.jit.metainterp.optimizeopt.optimizer import *
from pypy.jit.metainterp.resoperation import opboolinvers, opboolreflex
from pypy.jit.metainterp.history import ConstInt
-from pypy.jit.metainterp.optimizeopt.util import _findall
+from pypy.jit.metainterp.optimizeopt.util import _findall,
make_dispatcher_method
from pypy.jit.metainterp.resoperation import rop, ResOperation
from pypy.jit.codewriter.effectinfo import EffectInfo
from pypy.jit.metainterp.optimizeopt.intutils import IntBound
@@ -21,18 +21,13 @@
if self.find_rewritable_bool(op, args):
return
- opnum = op.getopnum()
- for value, func in optimize_ops:
- if opnum == value:
- func(self, op)
- break
- else:
- self.emit_operation(op)
+ dispatch_opt(self, op)
def test_emittable(self, op):
opnum = op.getopnum()
- for value, func in optimize_guards:
+ for value, cls, func in optimize_guards:
if opnum == value:
+ assert isinstance(op, cls)
try:
func(self, op, dryrun=True)
return self.is_emittable(op)
@@ -477,5 +472,6 @@
self.emit_operation(op)
-optimize_ops = _findall(OptRewrite, 'optimize_')
+dispatch_opt = make_dispatcher_method(OptRewrite, 'optimize_',
+ default=OptRewrite.emit_operation)
optimize_guards = _findall(OptRewrite, 'optimize_', 'GUARD')
diff --git a/pypy/jit/metainterp/optimizeopt/simplify.py
b/pypy/jit/metainterp/optimizeopt/simplify.py
--- a/pypy/jit/metainterp/optimizeopt/simplify.py
+++ b/pypy/jit/metainterp/optimizeopt/simplify.py
@@ -1,7 +1,7 @@
from pypy.jit.metainterp.resoperation import ResOperation, rop
from pypy.jit.metainterp.optimizeopt.optimizer import Optimization
-from pypy.jit.metainterp.optimizeopt.util import _findall
+from pypy.jit.metainterp.optimizeopt.util import make_dispatcher_method
class OptSimplify(Optimization):
def optimize_CALL_PURE(self, op):
@@ -25,13 +25,7 @@
# but it's a bit hard to implement robustly if heap.py is also run
pass
- def propagate_forward(self, op):
- opnum = op.getopnum()
- for value, func in optimize_ops:
- if opnum == value:
- func(self, op)
- break
- else:
- self.emit_operation(op)
-optimize_ops = _findall(OptSimplify, 'optimize_')
+dispatch_opt = make_dispatcher_method(OptSimplify, 'optimize_',
+ default=OptSimplify.emit_operation)
+OptSimplify.propagate_forward = dispatch_opt
diff --git a/pypy/jit/metainterp/optimizeopt/util.py
b/pypy/jit/metainterp/optimizeopt/util.py
--- a/pypy/jit/metainterp/optimizeopt/util.py
+++ b/pypy/jit/metainterp/optimizeopt/util.py
@@ -20,9 +20,25 @@
if op_prefix and not name.startswith(op_prefix):
continue
if hasattr(Class, name_prefix + name):
- result.append((value, getattr(Class, name_prefix + name)))
+ opclass = resoperation.opclasses[getattr(rop, name)]
+ print value, name, opclass
+ result.append((value, opclass, getattr(Class, name_prefix + name)))
return unrolling_iterable(result)
+def make_dispatcher_method(Class, name_prefix, op_prefix=None, default=None):
+ ops = _findall(Class, name_prefix, op_prefix)
+ def dispatch(self, op, *args):
+ opnum = op.getopnum()
+ for value, cls, func in ops:
+ if opnum == value:
+ assert isinstance(op, cls)
+ return func(self, op, *args)
+ if default:
+ return default(self, op, *args)
+ dispatch.func_name = "dispatch_" + name_prefix
+ return dispatch
+
+
def partition(array, left, right):
last_item = array[right]
pivot = last_item.sort_key()
diff --git a/pypy/jit/metainterp/optimizeopt/virtualize.py
b/pypy/jit/metainterp/optimizeopt/virtualize.py
--- a/pypy/jit/metainterp/optimizeopt/virtualize.py
+++ b/pypy/jit/metainterp/optimizeopt/virtualize.py
@@ -1,7 +1,7 @@
from pypy.jit.metainterp.history import Const, ConstInt, BoxInt
from pypy.jit.metainterp.resoperation import rop, ResOperation
-from pypy.jit.metainterp.optimizeopt.util import _findall, sort_descrs
-from pypy.jit.metainterp.optimizeopt.util import descrlist_dict
+from pypy.jit.metainterp.optimizeopt.util import make_dispatcher_method
+from pypy.jit.metainterp.optimizeopt.util import descrlist_dict, sort_descrs
from pypy.rlib.objectmodel import we_are_translated
from pypy.jit.metainterp.optimizeopt import optimizer
from pypy.jit.metainterp.executor import execute
@@ -456,13 +456,8 @@
###self.heap_op_optimizer.optimize_SETARRAYITEM_GC(op, value,
fieldvalue)
self.emit_operation(op)
- def propagate_forward(self, op):
- opnum = op.getopnum()
- for value, func in optimize_ops:
- if opnum == value:
- func(self, op)
- break
- else:
- self.emit_operation(op)
-optimize_ops = _findall(OptVirtualize, 'optimize_')
+dispatch_opt = make_dispatcher_method(OptVirtualize, 'optimize_',
+ default=OptVirtualize.emit_operation)
+
+OptVirtualize.propagate_forward = dispatch_opt
diff --git a/pypy/jit/metainterp/optimizeopt/vstring.py
b/pypy/jit/metainterp/optimizeopt/vstring.py
--- a/pypy/jit/metainterp/optimizeopt/vstring.py
+++ b/pypy/jit/metainterp/optimizeopt/vstring.py
@@ -8,7 +8,7 @@
from pypy.jit.metainterp.optimizeopt import optimizer, virtualize
from pypy.jit.metainterp.optimizeopt.optimizer import CONST_0, CONST_1
from pypy.jit.metainterp.optimizeopt.optimizer import llhelper
-from pypy.jit.metainterp.optimizeopt.util import _findall
+from pypy.jit.metainterp.optimizeopt.util import make_dispatcher_method
from pypy.jit.codewriter.effectinfo import EffectInfo
from pypy.jit.codewriter import heaptracker
from pypy.rlib.unroll import unrolling_iterable
@@ -649,16 +649,11 @@
self.emit_operation(op)
return
- opnum = op.getopnum()
- for value, func in optimize_ops:
- if opnum == value:
- func(self, op)
- break
- else:
- self.emit_operation(op)
+ dispatch_opt(self, op)
-optimize_ops = _findall(OptString, 'optimize_')
+dispatch_opt = make_dispatcher_method(OptString, 'optimize_',
+ default=OptString.emit_operation)
def _findall_call_oopspec():
prefix = 'opt_call_stroruni_'
diff --git a/pypy/translator/jvm/src/pypy/PyPy.java
b/pypy/translator/jvm/src/pypy/PyPy.java
--- a/pypy/translator/jvm/src/pypy/PyPy.java
+++ b/pypy/translator/jvm/src/pypy/PyPy.java
@@ -969,7 +969,10 @@
// XXX: this is really a quick hack to make things work.
// it should disappear, because this function is not
// supported by ootypesystem.
- return Double.toString(d); // XXX: we are ignoring "format"
+ DecimalFormat format = new DecimalFormat("0.###");
+ format.setMinimumFractionDigits(precision);
+ format.setMaximumFractionDigits(precision);
+ return format.format(d);
}
// ----------------------------------------------------------------------
diff --git a/pypy/translator/jvm/test/test_float.py
b/pypy/translator/jvm/test/test_float.py
--- a/pypy/translator/jvm/test/test_float.py
+++ b/pypy/translator/jvm/test/test_float.py
@@ -22,3 +22,14 @@
def test_r_singlefloat(self):
py.test.skip("not implemented: single-precision floats")
+
+ def test_format_float(self):
+ from pypy.rlib.rfloat import _formatd
+ def fn(precision):
+ return _formatd(10.01, 'd', precision, 0)
+
+ res = self.interpret(fn, [2])
+ assert res == "10.01"
+
+ res = self.interpret(fn, [1])
+ assert res == "10.0"
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit