Author: Alex Gaynor <alex.gay...@gmail.com> Branch: Changeset: r64944:34b8e7d584a8 Date: 2013-06-19 21:46 -0700 http://bitbucket.org/pypy/pypy/changeset/34b8e7d584a8/
Log: random pep8 cleanups diff --git a/rpython/jit/metainterp/compile.py b/rpython/jit/metainterp/compile.py --- a/rpython/jit/metainterp/compile.py +++ b/rpython/jit/metainterp/compile.py @@ -9,19 +9,20 @@ from rpython.tool.sourcetools import func_with_new_name from rpython.jit.metainterp.resoperation import ResOperation, rop, get_deep_immutable_oplist -from rpython.jit.metainterp.history import TreeLoop, Box, JitCellToken, TargetToken -from rpython.jit.metainterp.history import AbstractFailDescr, BoxInt -from rpython.jit.metainterp.history import BoxPtr, BoxFloat, ConstInt -from rpython.jit.metainterp import history, resume, jitexc +from rpython.jit.metainterp.history import (TreeLoop, Box, JitCellToken, + TargetToken, AbstractFailDescr, BoxInt, BoxPtr, BoxFloat, ConstInt) +from rpython.jit.metainterp import history, jitexc from rpython.jit.metainterp.optimize import InvalidLoop from rpython.jit.metainterp.inliner import Inliner from rpython.jit.metainterp.resume import NUMBERING, PENDINGFIELDSP, ResumeDataDirectReader from rpython.jit.codewriter import heaptracker, longlong + def giveup(): from rpython.jit.metainterp.pyjitpl import SwitchToBlackhole raise SwitchToBlackhole(Counters.ABORT_BRIDGE) + def show_procedures(metainterp_sd, procedure=None, error=None): # debugging if option and (option.view or option.viewloops): @@ -657,17 +658,21 @@ class AllVirtuals: llopaque = True cache = None + def __init__(self, cache): self.cache = cache + def hide(self, cpu): ptr = cpu.ts.cast_instance_to_base_ref(self) return cpu.ts.cast_to_ref(ptr) + @staticmethod def show(cpu, gcref): from rpython.rtyper.annlowlevel import cast_base_ptr_to_instance ptr = cpu.ts.cast_to_baseclass(gcref) return cast_base_ptr_to_instance(AllVirtuals, ptr) + class ResumeGuardForcedDescr(ResumeGuardDescr): def __init__(self, metainterp_sd, jitdriver_sd): @@ -762,9 +767,12 @@ b = c = -1 for i in range(1, 5): if self.counters[i] > self.counters[a]: - c = b; b = a; a = i + c = b + b = a + a = i elif b < 0 or self.counters[i] > self.counters[b]: - c = b; b = i + c = b + b = i elif c < 0 or self.counters[i] > self.counters[c]: c = i self.counters[c] = 1 @@ -878,10 +886,14 @@ assert len(redargtypes) == nb_red_args inputargs = [] for kind in redargtypes: - if kind == history.INT: box = BoxInt() - elif kind == history.REF: box = BoxPtr() - elif kind == history.FLOAT: box = BoxFloat() - else: raise AssertionError + if kind == history.INT: + box = BoxInt() + elif kind == history.REF: + box = BoxPtr() + elif kind == history.FLOAT: + box = BoxFloat() + else: + raise AssertionError inputargs.append(box) k = jitdriver_sd.portal_runner_adr funcbox = history.ConstInt(heaptracker.adr2int(k)) @@ -909,7 +921,7 @@ ResOperation(rop.CALL, callargs, result, descr=jd.portal_calldescr), ResOperation(rop.GUARD_NO_EXCEPTION, [], None, descr=faildescr), ResOperation(rop.FINISH, finishargs, None, descr=jd.portal_finishtoken) - ] + ] operations[1].setfailargs([]) operations = get_deep_immutable_oplist(operations) cpu.compile_loop(inputargs, operations, jitcell_token, log=False) diff --git a/rpython/jit/metainterp/inliner.py b/rpython/jit/metainterp/inliner.py --- a/rpython/jit/metainterp/inliner.py +++ b/rpython/jit/metainterp/inliner.py @@ -1,6 +1,7 @@ from rpython.jit.metainterp.history import Const from rpython.jit.metainterp.resume import Snapshot + class Inliner(object): def __init__(self, inputargs, jump_args): assert len(inputargs) == len(jump_args) @@ -54,4 +55,3 @@ new_snapshot = Snapshot(self.inline_snapshot(snapshot.prev), boxes) self.snapshot_map[snapshot] = new_snapshot return new_snapshot - diff --git a/rpython/jit/metainterp/jitprof.py b/rpython/jit/metainterp/jitprof.py --- a/rpython/jit/metainterp/jitprof.py +++ b/rpython/jit/metainterp/jitprof.py @@ -18,7 +18,7 @@ class EmptyProfiler(BaseProfiler): initialized = True - + def start(self): pass @@ -96,7 +96,7 @@ def end_backend(self): self._end (Counters.BACKEND) def count(self, kind, inc=1): - self.counters[kind] += inc + self.counters[kind] += inc def get_counter(self, num): if num == Counters.TOTAL_COMPILED_LOOPS: diff --git a/rpython/jit/metainterp/logger.py b/rpython/jit/metainterp/logger.py --- a/rpython/jit/metainterp/logger.py +++ b/rpython/jit/metainterp/logger.py @@ -1,14 +1,13 @@ - -from rpython.rlib.debug import have_debug_prints -from rpython.rlib.debug import debug_start, debug_stop, debug_print +from rpython.jit.metainterp.history import (ConstInt, BoxInt, ConstFloat, + BoxFloat, TargetToken) +from rpython.jit.metainterp.resoperation import rop +from rpython.rlib.debug import (have_debug_prints, debug_start, debug_stop, + debug_print) from rpython.rlib.objectmodel import we_are_translated, compute_unique_id from rpython.rtyper.lltypesystem import lltype, llmemory, rffi -from rpython.jit.metainterp.resoperation import rop -from rpython.jit.metainterp.history import ConstInt, \ - BoxInt, ConstFloat, BoxFloat, TargetToken + class Logger(object): - def __init__(self, metainterp_sd, guard_number=False): self.metainterp_sd = metainterp_sd self.guard_number = guard_number @@ -24,7 +23,7 @@ debug_stop("jit-log-compiling-loop") else: debug_start("jit-log-opt-loop") - debug_print("# Loop", number, '(%s)' % name , ":", type, + debug_print("# Loop", number, '(%s)' % name, ":", type, "with", len(operations), "ops") logops = self._log_operations(inputargs, operations, ops_offset) debug_stop("jit-log-opt-loop") @@ -138,7 +137,7 @@ else: r = self.repr_of_descr(descr) if args: - args += ', descr=' + r + args += ', descr=' + r else: args = "descr=" + r if is_guard and op.getfailargs() is not None: diff --git a/rpython/jit/metainterp/optimize.py b/rpython/jit/metainterp/optimize.py --- a/rpython/jit/metainterp/optimize.py +++ b/rpython/jit/metainterp/optimize.py @@ -1,6 +1,7 @@ from rpython.rlib.debug import debug_start, debug_stop, debug_print from rpython.jit.metainterp.jitexc import JitException + class InvalidLoop(JitException): """Raised when the optimize*.py detect that the loop that we are trying to build cannot possibly make sense as a diff --git a/rpython/jit/metainterp/optimizeopt/earlyforce.py b/rpython/jit/metainterp/optimizeopt/earlyforce.py --- a/rpython/jit/metainterp/optimizeopt/earlyforce.py +++ b/rpython/jit/metainterp/optimizeopt/earlyforce.py @@ -1,7 +1,7 @@ from rpython.jit.codewriter.effectinfo import EffectInfo from rpython.jit.metainterp.optimizeopt.optimizer import Optimization -from rpython.jit.metainterp.optimizeopt.vstring import VAbstractStringValue -from rpython.jit.metainterp.resoperation import rop, ResOperation +from rpython.jit.metainterp.resoperation import rop + def is_raw_free(op, opnum): if opnum != rop.CALL: @@ -14,14 +14,14 @@ def propagate_forward(self, op): opnum = op.getopnum() - if (opnum != rop.SETFIELD_GC and + if (opnum != rop.SETFIELD_GC and opnum != rop.SETARRAYITEM_GC and opnum != rop.SETARRAYITEM_RAW and opnum != rop.QUASIIMMUT_FIELD and opnum != rop.SAME_AS and opnum != rop.MARK_OPAQUE_PTR and not is_raw_free(op, opnum)): - + for arg in op.getarglist(): if arg in self.optimizer.values: value = self.getvalue(arg) @@ -33,5 +33,3 @@ def setup(self): self.optimizer.optearlyforce = self - - diff --git a/rpython/jit/metainterp/optimizeopt/test/test_multilabel.py b/rpython/jit/metainterp/optimizeopt/test/test_multilabel.py --- a/rpython/jit/metainterp/optimizeopt/test/test_multilabel.py +++ b/rpython/jit/metainterp/optimizeopt/test/test_multilabel.py @@ -9,6 +9,7 @@ from rpython.jit.metainterp.optimizeopt.optimizer import Optimization from rpython.jit.metainterp.optimizeopt.util import make_dispatcher_method + class BaseTestMultiLabel(BaseTest): enable_opts = "intbounds:rewrite:virtualize:string:earlyforce:pure:heap:unroll" @@ -25,7 +26,7 @@ optimized = TreeLoop('optimized') optimized.inputargs = loop.inputargs optimized.operations = [] - + labels = [i for i, op in enumerate(loop.operations) \ if op.getopnum()==rop.LABEL] prv = 0 @@ -46,10 +47,10 @@ last_label = [part.operations.pop()] else: last_label = [] - + optimized.operations.extend(part.operations) prv = nxt + 1 - + # print print "Optimized:" @@ -84,7 +85,7 @@ self.assert_equal(short_preamble, expected_short, text_right='expected short preamble') - + return optimized class OptimizeoptTestMultiLabel(BaseTestMultiLabel): @@ -138,12 +139,12 @@ [p1] p2 = new_array(3, descr=arraydescr) label(p2) - p4 = new_array(2, descr=arraydescr) + p4 = new_array(2, descr=arraydescr) jump(p4) """ with raises(InvalidLoop): self.optimize_loop(ops, ops) - + def test_nonmatching_arraystruct_1(self): ops = """ [p1, f0] @@ -156,7 +157,7 @@ """ with raises(InvalidLoop): self.optimize_loop(ops, ops) - + def test_nonmatching_arraystruct_2(self): ops = """ [p1, f0] @@ -164,7 +165,7 @@ setinteriorfield_gc(p2, 2, f0, descr=complexrealdescr) label(p2, f0) p4 = new_array(2, descr=complexarraydescr) - setinteriorfield_gc(p4, 0, f0, descr=complexrealdescr) + setinteriorfield_gc(p4, 0, f0, descr=complexrealdescr) jump(p4, f0) """ with raises(InvalidLoop): @@ -213,7 +214,7 @@ """ with raises(InvalidLoop): self.optimize_loop(ops, ops) - + def test_virtuals_turns_not_equal(self): ops = """ [p1, p2] @@ -317,7 +318,7 @@ short = """ [p1, i1] label(p1, i1) - i2 = getfield_gc(p1, descr=valuedescr) + i2 = getfield_gc(p1, descr=valuedescr) jump(p1, i1, i2) """ self.optimize_loop(ops, expected, expected_shorts=[short, short]) @@ -360,7 +361,7 @@ jump(p1, i5) """ self.optimize_loop(ops, exported) - + def test_import_virtual_across_multiple_labels(self): ops = """ [p0, i1] @@ -435,25 +436,25 @@ def test_boxed_opaque_unknown_class(self): ops = """ [p1] - p2 = getfield_gc(p1, descr=nextdescr) - mark_opaque_ptr(p2) + p2 = getfield_gc(p1, descr=nextdescr) + mark_opaque_ptr(p2) i3 = getfield_gc(p2, descr=otherdescr) label(p1) i4 = getfield_gc(p1, descr=otherdescr) label(p1) - p5 = getfield_gc(p1, descr=nextdescr) - mark_opaque_ptr(p5) + p5 = getfield_gc(p1, descr=nextdescr) + mark_opaque_ptr(p5) i6 = getfield_gc(p5, descr=otherdescr) i7 = call(i6, descr=nonwritedescr) """ expected = """ [p1] - p2 = getfield_gc(p1, descr=nextdescr) + p2 = getfield_gc(p1, descr=nextdescr) i3 = getfield_gc(p2, descr=otherdescr) label(p1) i4 = getfield_gc(p1, descr=otherdescr) label(p1) - p5 = getfield_gc(p1, descr=nextdescr) + p5 = getfield_gc(p1, descr=nextdescr) i6 = getfield_gc(p5, descr=otherdescr) i7 = call(i6, descr=nonwritedescr) """ @@ -462,20 +463,20 @@ def test_opaque_pointer_fails_to_close_loop(self): ops = """ [p1, p11] - p2 = getfield_gc(p1, descr=nextdescr) + p2 = getfield_gc(p1, descr=nextdescr) guard_class(p2, ConstClass(node_vtable)) [] - mark_opaque_ptr(p2) + mark_opaque_ptr(p2) i3 = getfield_gc(p2, descr=otherdescr) label(p1, p11) - p12 = getfield_gc(p1, descr=nextdescr) + p12 = getfield_gc(p1, descr=nextdescr) i13 = getfield_gc(p2, descr=otherdescr) - i14 = call(i13, descr=nonwritedescr) + i14 = call(i13, descr=nonwritedescr) jump(p11, p1) """ with raises(InvalidLoop): self.optimize_loop(ops, ops) - + class OptRenameStrlen(Optimization): @@ -487,7 +488,7 @@ newop.result = op.result.clonebox() self.emit_operation(newop) self.make_equal_to(op.result, self.getvalue(newop.result)) - + dispatch_opt = make_dispatcher_method(OptRenameStrlen, 'optimize_', default=OptRenameStrlen.emit_operation) @@ -537,7 +538,7 @@ jump(p1, i11) """ self.optimize_loop(ops, expected) - + class TestLLtype(OptimizeoptTestMultiLabel, LLtypeMixin): pass diff --git a/rpython/jit/metainterp/quasiimmut.py b/rpython/jit/metainterp/quasiimmut.py --- a/rpython/jit/metainterp/quasiimmut.py +++ b/rpython/jit/metainterp/quasiimmut.py @@ -51,7 +51,7 @@ class QuasiImmut(object): llopaque = True compress_limit = 30 - + def __init__(self, cpu): self.cpu = cpu # list of weakrefs to the LoopTokens that must be invalidated if diff --git a/rpython/jit/metainterp/resoperation.py b/rpython/jit/metainterp/resoperation.py --- a/rpython/jit/metainterp/resoperation.py +++ b/rpython/jit/metainterp/resoperation.py @@ -1,5 +1,6 @@ from rpython.rlib.objectmodel import we_are_translated + def ResOperation(opnum, args, result, descr=None): cls = opclasses[opnum] op = cls(result) @@ -50,7 +51,6 @@ def numargs(self): raise NotImplementedError - # methods implemented by GuardResOp # --------------------------------- @@ -183,6 +183,7 @@ class PlainResOp(AbstractResOp): pass + class ResOpWithDescr(AbstractResOp): _descr = None @@ -347,6 +348,7 @@ else: raise IndexError + class N_aryOp(object): _mixin_ = True _args = None @@ -577,7 +579,7 @@ opclasses.append(cls) oparity.append(arity) opwithdescr.append(withdescr) - assert len(opclasses)==len(oparity)==len(opwithdescr)==len(_oplist) + assert len(opclasses) == len(oparity) == len(opwithdescr) == len(_oplist) def get_base_class(mixin, base): try: @@ -597,7 +599,7 @@ 1: UnaryOp, 2: BinaryOp, 3: TernaryOp - } + } is_guard = name.startswith('GUARD') if is_guard: @@ -639,7 +641,7 @@ rop.PTR_EQ: rop.PTR_NE, rop.PTR_NE: rop.PTR_EQ, - } +} opboolreflex = { rop.INT_EQ: rop.INT_EQ, @@ -663,7 +665,7 @@ rop.PTR_EQ: rop.PTR_EQ, rop.PTR_NE: rop.PTR_NE, - } +} def get_deep_immutable_oplist(operations): diff --git a/rpython/jit/metainterp/warmspot.py b/rpython/jit/metainterp/warmspot.py --- a/rpython/jit/metainterp/warmspot.py +++ b/rpython/jit/metainterp/warmspot.py @@ -1,8 +1,11 @@ -import sys, py +import sys + +import py + from rpython.tool.sourcetools import func_with_new_name from rpython.rtyper.lltypesystem import lltype, llmemory -from rpython.rtyper.annlowlevel import llhelper, MixLevelHelperAnnotator,\ - cast_base_ptr_to_instance, hlstr +from rpython.rtyper.annlowlevel import (llhelper, MixLevelHelperAnnotator, + cast_base_ptr_to_instance, hlstr) from rpython.annotator import model as annmodel from rpython.rtyper.llinterp import LLException from rpython.rtyper.test.test_llinterp import get_interpreter, clear_tcache @@ -20,11 +23,12 @@ from rpython.jit.metainterp.pyjitpl import MetaInterpStaticData from rpython.jit.metainterp.jitprof import Profiler, EmptyProfiler from rpython.jit.metainterp.jitdriver import JitDriverStaticData -from rpython.jit.codewriter import support, codewriter, longlong +from rpython.jit.codewriter import support, codewriter from rpython.jit.codewriter.policy import JitPolicy from rpython.jit.codewriter.effectinfo import EffectInfo from rpython.jit.metainterp.optimizeopt import ALL_OPTS_NAMES + # ____________________________________________________________ # Bootstrapping @@ -39,8 +43,8 @@ warmrunnerdesc = WarmRunnerDesc(translator, translate_support_code=True, listops=True, - no_stats = True, - ProfilerClass = ProfilerClass, + no_stats=True, + ProfilerClass=ProfilerClass, **kwds) for jd in warmrunnerdesc.jitdrivers_sd: jd.warmstate.set_param_inlining(inline) @@ -336,7 +340,6 @@ c_new_driver = Constant(new_driver, v_driver.concretetype) op.args[1] = c_new_driver - def find_portals(self): self.jitdrivers_sd = [] graphs = self.translator.graphs @@ -419,9 +422,12 @@ self.annhelper = MixLevelHelperAnnotator(self.translator.rtyper) cpu = CPUClass(self.translator.rtyper, self.stats, self.opt, translate_support_code, gcdescr=self.gcdescr) - if not supports_floats: cpu.supports_floats = False - if not supports_longlong: cpu.supports_longlong = False - if not supports_singlefloats: cpu.supports_singlefloats = False + if not supports_floats: + cpu.supports_floats = False + if not supports_longlong: + cpu.supports_longlong = False + if not supports_singlefloats: + cpu.supports_singlefloats = False self.cpu = cpu def build_meta_interp(self, ProfilerClass): @@ -677,6 +683,7 @@ # get special treatment since we rewrite it to a call that accepts # jit driver func = func_with_new_name(func, func.func_name + '_compiled') + def new_func(ignored, *args): return func(self, *args) ARGS = [lltype.Void] + [arg.concretetype for arg in op.args[3:]] @@ -734,7 +741,7 @@ from rpython.jit.metainterp.warmstate import specialize_value from rpython.jit.metainterp.warmstate import unspecialize_value portal_ptr = self.cpu.ts.functionptr(PORTALFUNC, 'portal', - graph = portalgraph) + graph=portalgraph) jd._portal_ptr = portal_ptr # portalfunc_ARGS = [] @@ -758,7 +765,6 @@ ts = self.cpu.ts state = jd.warmstate maybe_compile_and_run = jd._maybe_compile_and_run_fn - cpu = jd.warmstate.cpu def ll_portal_runner(*args): start = True @@ -920,7 +926,7 @@ if self.cpu.translate_support_code: call_final_function(self.translator, finish, - annhelper = self.annhelper) + annhelper=self.annhelper) def rewrite_set_param_and_get_stats(self): from rpython.rtyper.lltypesystem.rstr import STR @@ -952,7 +958,7 @@ return Constant(funcptr, TP) # for graph, block, i in find_set_param(graphs): - + op = block.operations[i] if op.args[1].value is not None: for jd in self.jitdrivers_sd: diff --git a/rpython/jit/metainterp/warmstate.py b/rpython/jit/metainterp/warmstate.py --- a/rpython/jit/metainterp/warmstate.py +++ b/rpython/jit/metainterp/warmstate.py @@ -1,17 +1,18 @@ -import sys, weakref +import sys +import weakref + +from rpython.jit.codewriter import support, heaptracker, longlong +from rpython.jit.metainterp import history +from rpython.rlib.debug import debug_start, debug_stop, debug_print +from rpython.rlib.jit import PARAMETERS, BaseJitCell +from rpython.rlib.nonconst import NonConstant +from rpython.rlib.objectmodel import specialize, we_are_translated, r_dict +from rpython.rlib.rarithmetic import intmask +from rpython.rlib.unroll import unrolling_iterable +from rpython.rtyper.annlowlevel import (hlstr, cast_base_ptr_to_instance, + cast_object_to_ptr) from rpython.rtyper.lltypesystem import lltype, llmemory, rstr, rffi from rpython.rtyper.ootypesystem import ootype -from rpython.rtyper.annlowlevel import hlstr, cast_base_ptr_to_instance -from rpython.rtyper.annlowlevel import cast_object_to_ptr -from rpython.rlib.objectmodel import specialize, we_are_translated, r_dict -from rpython.rlib.rarithmetic import intmask -from rpython.rlib.nonconst import NonConstant -from rpython.rlib.unroll import unrolling_iterable -from rpython.rlib.jit import PARAMETERS -from rpython.rlib.jit import BaseJitCell -from rpython.rlib.debug import debug_start, debug_stop, debug_print -from rpython.jit.metainterp import history -from rpython.jit.codewriter import support, heaptracker, longlong # ____________________________________________________________ @@ -601,7 +602,7 @@ fn = support.maybe_on_top_of_llinterp(rtyper, inline_ptr) return fn(*greenargs) self.should_unroll_one_iteration = should_unroll_one_iteration - + redargtypes = ''.join([kind[0] for kind in jd.red_args_types]) def get_assembler_token(greenkey): _______________________________________________ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit