diff options
author | Alex Gaynor <alex.gaynor@gmail.com> | 2013-07-10 09:20:40 +1000 |
---|---|---|
committer | Alex Gaynor <alex.gaynor@gmail.com> | 2013-07-10 09:20:40 +1000 |
commit | 7b6b73a5dc87da3c5837e5e683a08024aa2c6cea (patch) | |
tree | f9cdbcf8df84b466cf72d8dc40cc4700821f0617 | |
parent | A failing test for a dict where a key is a PBC. (diff) | |
download | pypy-7b6b73a5dc87da3c5837e5e683a08024aa2c6cea.tar.gz pypy-7b6b73a5dc87da3c5837e5e683a08024aa2c6cea.tar.bz2 pypy-7b6b73a5dc87da3c5837e5e683a08024aa2c6cea.zip |
Corrected a bunch of code that wasn't using 4-space indents.
36 files changed, 453 insertions, 453 deletions
diff --git a/pypy/interpreter/astcompiler/test/test_compiler.py b/pypy/interpreter/astcompiler/test/test_compiler.py index 73c5a8cb99..9d9fc835f9 100644 --- a/pypy/interpreter/astcompiler/test/test_compiler.py +++ b/pypy/interpreter/astcompiler/test/test_compiler.py @@ -881,15 +881,15 @@ class AppTestCompiler: assert "0 ('hi')" not in output.getvalue() def test_print_to(self): - exec """if 1: - from StringIO import StringIO - s = StringIO() - print >> s, "hi", "lovely!" - assert s.getvalue() == "hi lovely!\\n" - s = StringIO() - print >> s, "hi", "lovely!", - assert s.getvalue() == "hi lovely!" - """ in {} + exec """if 1: + from StringIO import StringIO + s = StringIO() + print >> s, "hi", "lovely!" + assert s.getvalue() == "hi lovely!\\n" + s = StringIO() + print >> s, "hi", "lovely!", + assert s.getvalue() == "hi lovely!" + """ in {} def test_assert_with_tuple_arg(self): try: diff --git a/pypy/interpreter/pyparser/parsestring.py b/pypy/interpreter/pyparser/parsestring.py index f92be71e5f..fd14fa5f52 100644 --- a/pypy/interpreter/pyparser/parsestring.py +++ b/pypy/interpreter/pyparser/parsestring.py @@ -111,7 +111,7 @@ def parsestr(space, encoding, s, unicode_literal=False): enc = None if need_encoding: - enc = encoding + enc = encoding v = PyString_DecodeEscape(space, substr, enc) return space.wrap(v) diff --git a/pypy/interpreter/test/test_function.py b/pypy/interpreter/test/test_function.py index a8e811a95c..d536139977 100644 --- a/pypy/interpreter/test/test_function.py +++ b/pypy/interpreter/test/test_function.py @@ -636,11 +636,11 @@ def f%s: assert fn.code.fast_natural_arity == i|PyCode.FLATPYCALL if i < 5: - def bomb(*args): - assert False, "shortcutting should have avoided this" + def bomb(*args): + assert False, "shortcutting should have avoided this" - code.funcrun = bomb - code.funcrun_obj = bomb + code.funcrun = bomb + code.funcrun_obj = bomb args_w = map(space.wrap, range(i)) w_res = space.call_function(fn, *args_w) diff --git a/pypy/module/__builtin__/__init__.py b/pypy/module/__builtin__/__init__.py index 3a1bcacfc1..c9ca6a7576 100644 --- a/pypy/module/__builtin__/__init__.py +++ b/pypy/module/__builtin__/__init__.py @@ -102,26 +102,26 @@ class Module(MixedModule): } def pick_builtin(self, w_globals): - "Look up the builtin module to use from the __builtins__ global" - # pick the __builtins__ roughly in the same way CPython does it - # this is obscure and slow - space = self.space - try: - w_builtin = space.getitem(w_globals, space.wrap('__builtins__')) - except OperationError, e: - if not e.match(space, space.w_KeyError): - raise - else: - if w_builtin is space.builtin: # common case - return space.builtin - if space.isinstance_w(w_builtin, space.w_dict): + "Look up the builtin module to use from the __builtins__ global" + # pick the __builtins__ roughly in the same way CPython does it + # this is obscure and slow + space = self.space + try: + w_builtin = space.getitem(w_globals, space.wrap('__builtins__')) + except OperationError, e: + if not e.match(space, space.w_KeyError): + raise + else: + if w_builtin is space.builtin: # common case + return space.builtin + if space.isinstance_w(w_builtin, space.w_dict): return module.Module(space, None, w_builtin) - if isinstance(w_builtin, module.Module): - return w_builtin - # no builtin! make a default one. Give them None, at least. - builtin = module.Module(space, None) - space.setitem(builtin.w_dict, space.wrap('None'), space.w_None) - return builtin + if isinstance(w_builtin, module.Module): + return w_builtin + # no builtin! make a default one. Give them None, at least. + builtin = module.Module(space, None) + space.setitem(builtin.w_dict, space.wrap('None'), space.w_None) + return builtin def setup_after_space_initialization(self): """NOT_RPYTHON""" diff --git a/pypy/module/_rawffi/structure.py b/pypy/module/_rawffi/structure.py index 50208de44a..6865b41ed1 100644 --- a/pypy/module/_rawffi/structure.py +++ b/pypy/module/_rawffi/structure.py @@ -86,20 +86,20 @@ def size_alignment_pos(fields, is_union=False, pack=0): (not _MS_WINDOWS or fieldsize * 8 == last_size) and fieldsize * 8 <= last_size and bitoffset + bitsize <= last_size): - # continue bit field - field_type = CONT_BITFIELD + # continue bit field + field_type = CONT_BITFIELD elif (not _MS_WINDOWS and last_size and # we have a bitfield open fieldsize * 8 >= last_size and bitoffset + bitsize <= fieldsize * 8): - # expand bit field - field_type = EXPAND_BITFIELD + # expand bit field + field_type = EXPAND_BITFIELD else: - # start new bitfield - field_type = NEW_BITFIELD - has_bitfield = True - bitoffset = 0 - last_size = fieldsize * 8 + # start new bitfield + field_type = NEW_BITFIELD + has_bitfield = True + bitoffset = 0 + last_size = fieldsize * 8 if is_union: pos.append(0) diff --git a/pypy/module/cppyy/bench/hsimple.py b/pypy/module/cppyy/bench/hsimple.py index f6294c70bb..cd304ead11 100755 --- a/pypy/module/cppyy/bench/hsimple.py +++ b/pypy/module/cppyy/bench/hsimple.py @@ -37,7 +37,7 @@ except ImportError: import random if _reflex: - gROOT.SetBatch(True) + gROOT.SetBatch(True) # Create a new ROOT binary machine independent file. # Note that this file may contain any kind of ROOT objects, histograms, diff --git a/pypy/module/cppyy/bench/hsimple_rflx.py b/pypy/module/cppyy/bench/hsimple_rflx.py index 706dfe9747..6e9a4feb93 100755 --- a/pypy/module/cppyy/bench/hsimple_rflx.py +++ b/pypy/module/cppyy/bench/hsimple_rflx.py @@ -80,14 +80,14 @@ kUPDATE = 1000 for i in xrange(2500000): # Generate random values. # px, py = random.gauss(0, 1), random.gauss(0, 1) - px, py = random.Gaus(0, 1), random.Gaus(0, 1) + px, py = random.Gaus(0, 1), random.Gaus(0, 1) # pt = (px*px + py*py)**0.5 - pt = math.sqrt(px*px + py*py) + pt = math.sqrt(px*px + py*py) # pt = (px*px + py*py) # random = rndm(1) # Fill histograms. - hpx.Fill(pt) + hpx.Fill(pt) # hpxpyFill( px, py ) # hprofFill( px, pz ) # ntupleFill( px, py, pz, random, i ) @@ -105,7 +105,7 @@ for i in xrange(2500000): #gBenchmark.Show( 'hsimple' ) -hpx.Print() +hpx.Print() # Save all objects in this file. #hpx.SetFillColor( 0 ) diff --git a/pypy/module/cpyext/stringobject.py b/pypy/module/cpyext/stringobject.py index 7f2983894c..9bf68ed05a 100644 --- a/pypy/module/cpyext/stringobject.py +++ b/pypy/module/cpyext/stringobject.py @@ -225,9 +225,9 @@ def PyString_Concat(space, ref, w_newpart): if w_newpart is None or not PyString_Check(space, ref[0]) or \ not PyString_Check(space, w_newpart): - Py_DecRef(space, ref[0]) - ref[0] = lltype.nullptr(PyObject.TO) - return + Py_DecRef(space, ref[0]) + ref[0] = lltype.nullptr(PyObject.TO) + return w_str = from_ref(space, ref[0]) w_newstr = space.add(w_str, w_newpart) Py_DecRef(space, ref[0]) diff --git a/pypy/module/parser/__init__.py b/pypy/module/parser/__init__.py index a00ac45642..fec2322bcb 100644 --- a/pypy/module/parser/__init__.py +++ b/pypy/module/parser/__init__.py @@ -2,28 +2,27 @@ from pypy.interpreter.mixedmodule import MixedModule class Module(MixedModule): - """The builtin parser module.""" + """The builtin parser module.""" - applevel_name = 'parser' + applevel_name = 'parser' - appleveldefs = { - } + appleveldefs = { + } - interpleveldefs = { - '__name__' : '(space.wrap("parser"))', - '__doc__' : '(space.wrap("parser module"))', - - 'suite' : 'pyparser.suite', - 'expr' : 'pyparser.expr', - 'issuite' : 'pyparser.issuite', - 'isexpr' : 'pyparser.isexpr', - 'STType' : 'pyparser.W_STType', - 'ast2tuple' : 'pyparser.st2tuple', - 'st2tuple' : 'pyparser.st2tuple', - 'ast2list' : 'pyparser.st2list', - 'ast2tuple' : 'pyparser.st2tuple', - 'ASTType' : 'pyparser.W_STType', - 'compilest' : 'pyparser.compilest', - 'compileast' : 'pyparser.compilest', - 'ParserError' : 'space.new_exception_class("parser.ParserError")', - } + interpleveldefs = { + '__name__' : '(space.wrap("parser"))', + '__doc__' : '(space.wrap("parser module"))', + 'suite' : 'pyparser.suite', + 'expr' : 'pyparser.expr', + 'issuite' : 'pyparser.issuite', + 'isexpr' : 'pyparser.isexpr', + 'STType' : 'pyparser.W_STType', + 'ast2tuple' : 'pyparser.st2tuple', + 'st2tuple' : 'pyparser.st2tuple', + 'ast2list' : 'pyparser.st2list', + 'ast2tuple' : 'pyparser.st2tuple', + 'ASTType' : 'pyparser.W_STType', + 'compilest' : 'pyparser.compilest', + 'compileast' : 'pyparser.compilest', + 'ParserError' : 'space.new_exception_class("parser.ParserError")', + } diff --git a/pypy/module/pypyjit/test_pypy_c/model.py b/pypy/module/pypyjit/test_pypy_c/model.py index b6e8f0eba0..9ef5ddaf1e 100644 --- a/pypy/module/pypyjit/test_pypy_c/model.py +++ b/pypy/module/pypyjit/test_pypy_c/model.py @@ -146,9 +146,9 @@ class TraceWithIds(Function): for op in self._ops_for_chunk(chunk, include_guard_not_invalidated): yield op else: - for op in chunk.operations: - if op.name == 'label': - yield op + for op in chunk.operations: + if op.name == 'label': + yield op def allops(self, *args, **kwds): return list(self._allops(*args, **kwds)) diff --git a/pypy/module/rctime/interp_time.py b/pypy/module/rctime/interp_time.py index 82cf7d62c7..1f38b7dd27 100644 --- a/pypy/module/rctime/interp_time.py +++ b/pypy/module/rctime/interp_time.py @@ -209,12 +209,12 @@ def _init_timezone(space): tzname = ["", ""] if _WIN: - c_tzset() - timezone = c_get_timezone() - altzone = timezone - 3600 - daylight = c_get_daylight() - tzname_ptr = c_get_tzname() - tzname = rffi.charp2str(tzname_ptr[0]), rffi.charp2str(tzname_ptr[1]) + c_tzset() + timezone = c_get_timezone() + altzone = timezone - 3600 + daylight = c_get_daylight() + tzname_ptr = c_get_tzname() + tzname = rffi.charp2str(tzname_ptr[0]), rffi.charp2str(tzname_ptr[1]) if _POSIX: if _CYGWIN: diff --git a/pypy/objspace/descroperation.py b/pypy/objspace/descroperation.py index 2f7bd75e9f..c6f5a02108 100644 --- a/pypy/objspace/descroperation.py +++ b/pypy/objspace/descroperation.py @@ -379,13 +379,13 @@ class DescrOperation(object): if _check_notimplemented(space, w_res): return w_res if w_right_impl is not None: - if space.is_w(w_obj3, space.w_None): - w_res = space.get_and_call_function(w_right_impl, w_obj2, w_obj1) - else: - w_res = space.get_and_call_function(w_right_impl, w_obj2, w_obj1, + if space.is_w(w_obj3, space.w_None): + w_res = space.get_and_call_function(w_right_impl, w_obj2, w_obj1) + else: + w_res = space.get_and_call_function(w_right_impl, w_obj2, w_obj1, w_obj3) - if _check_notimplemented(space, w_res): - return w_res + if _check_notimplemented(space, w_res): + return w_res raise OperationError(space.w_TypeError, space.wrap("operands do not support **")) diff --git a/pypy/objspace/std/stringobject.py b/pypy/objspace/std/stringobject.py index e5e60278ca..f40a3966b0 100644 --- a/pypy/objspace/std/stringobject.py +++ b/pypy/objspace/std/stringobject.py @@ -539,11 +539,11 @@ def _strip_none(space, w_self, left, right): if left: #print "while %d < %d and -%s- in -%s-:"%(lpos, rpos, u_self[lpos],w_chars) while lpos < rpos and u_self[lpos].isspace(): - lpos += 1 + lpos += 1 if right: while rpos > lpos and u_self[rpos - 1].isspace(): - rpos -= 1 + rpos -= 1 assert rpos >= lpos # annotator hint, don't remove return sliced(space, u_self, lpos, rpos, w_self) diff --git a/pypy/objspace/std/unicodeobject.py b/pypy/objspace/std/unicodeobject.py index c85ed27b34..b0e8e445e4 100644 --- a/pypy/objspace/std/unicodeobject.py +++ b/pypy/objspace/std/unicodeobject.py @@ -359,11 +359,11 @@ def _strip(space, w_self, w_chars, left, right): if left: while lpos < rpos and u_self[lpos] in u_chars: - lpos += 1 + lpos += 1 if right: while rpos > lpos and u_self[rpos - 1] in u_chars: - rpos -= 1 + rpos -= 1 assert rpos >= 0 result = u_self[lpos: rpos] diff --git a/rpython/annotator/builtin.py b/rpython/annotator/builtin.py index 48bd79cc99..049667a379 100644 --- a/rpython/annotator/builtin.py +++ b/rpython/annotator/builtin.py @@ -177,8 +177,8 @@ def builtin_isinstance(s_obj, s_type, variables=None): r.const = isinstance(s_obj.const, typ) elif our_issubclass(s_obj.knowntype, typ): if not s_obj.can_be_none(): - r.const = True - elif not our_issubclass(typ, s_obj.knowntype): + r.const = True + elif not our_issubclass(typ, s_obj.knowntype): r.const = False elif s_obj.knowntype == int and typ == bool: # xxx this will explode in case of generalisation # from bool to int, notice that isinstance( , bool|int) @@ -207,12 +207,12 @@ def builtin_hasattr(s_obj, s_attr): r.const = hasattr(s_obj.const, s_attr.const) elif (isinstance(s_obj, SomePBC) and s_obj.getKind() is description.FrozenDesc): - answers = {} - for d in s_obj.descriptions: - answer = (d.s_read_attribute(s_attr.const) != s_ImpossibleValue) - answers[answer] = True - if len(answers) == 1: - r.const, = answers + answers = {} + for d in s_obj.descriptions: + answer = (d.s_read_attribute(s_attr.const) != s_ImpossibleValue) + answers[answer] = True + if len(answers) == 1: + r.const, = answers return r ##def builtin_callable(s_obj): @@ -344,7 +344,7 @@ def llmemory_cast_int_to_adr(s): return SomeAddress() def unicodedata_decimal(s_uchr): - raise TypeError, "unicodedate.decimal() calls should not happen at interp-level" + raise TypeError, "unicodedate.decimal() calls should not happen at interp-level" def test(*args): return s_Bool @@ -395,7 +395,7 @@ else: if hasattr(object.__init__, 'im_func'): BUILTIN_ANALYZERS[object.__init__.im_func] = object_init else: - BUILTIN_ANALYZERS[object.__init__] = object_init + BUILTIN_ANALYZERS[object.__init__] = object_init # import BUILTIN_ANALYZERS[__import__] = import_func @@ -549,12 +549,12 @@ def instanceof(i, I): return s_Bool def classof(i): - assert isinstance(i, SomeOOInstance) + assert isinstance(i, SomeOOInstance) return SomeOOClass(i.ootype) def subclassof(class1, class2): - assert isinstance(class1, SomeOOClass) - assert isinstance(class2, SomeOOClass) + assert isinstance(class1, SomeOOClass) + assert isinstance(class2, SomeOOClass) return s_Bool def runtimenew(c): diff --git a/rpython/annotator/unaryop.py b/rpython/annotator/unaryop.py index 68b6b3966e..26c1229a33 100644 --- a/rpython/annotator/unaryop.py +++ b/rpython/annotator/unaryop.py @@ -5,14 +5,12 @@ Unary operations on SomeValues. from __future__ import absolute_import from types import MethodType -from rpython.annotator.model import \ - SomeObject, SomeInteger, SomeBool, SomeString, SomeChar, SomeList, \ - SomeDict, SomeTuple, SomeImpossibleValue, SomeUnicodeCodePoint, \ - SomeInstance, SomeBuiltin, SomeFloat, SomeIterator, SomePBC, \ - SomeTypedAddressAccess, SomeAddress, SomeType, \ - s_ImpossibleValue, s_Bool, s_None, \ - unionof, missing_operation, add_knowntypedata, HarmlesslyBlocked, \ - SomeWeakRef, SomeUnicodeString +from rpython.annotator.model import (SomeObject, SomeInteger, SomeBool, + SomeString, SomeChar, SomeList, SomeDict, SomeTuple, SomeImpossibleValue, + SomeUnicodeCodePoint, SomeInstance, SomeBuiltin, SomeFloat, SomeIterator, + SomePBC, SomeTypedAddressAccess, SomeAddress, SomeType, s_ImpossibleValue, + s_Bool, s_None, unionof, missing_operation, add_knowntypedata, + HarmlesslyBlocked, SomeWeakRef, SomeUnicodeString) from rpython.annotator.bookkeeper import getbookkeeper from rpython.annotator import builtin from rpython.annotator.binaryop import _clone ## XXX where to put this? @@ -39,7 +37,7 @@ class __extend__(SomeObject): def type(obj, *moreargs): if moreargs: - raise Exception, 'type() called with more than one argument' + raise Exception('type() called with more than one argument') r = SomeType() bk = getbookkeeper() op = bk._find_current_op(opname="type", arity=1, pos=0, s_type=obj) diff --git a/rpython/jit/backend/arm/test/test_instr_codebuilder.py b/rpython/jit/backend/arm/test/test_instr_codebuilder.py index 13f89bbca5..2c0234d733 100644 --- a/rpython/jit/backend/arm/test/test_instr_codebuilder.py +++ b/rpython/jit/backend/arm/test/test_instr_codebuilder.py @@ -76,16 +76,16 @@ class TestInstrCodeBuilder(ASMTest): self.assert_equal('ASR r7, r5, #24') def test_orr_rr_no_shift(self): - self.cb.ORR_rr(r.r0.value, r.r7.value,r.r12.value) + self.cb.ORR_rr(r.r0.value, r.r7.value, r.r12.value) self.assert_equal('ORR r0, r7, r12') def test_orr_rr_lsl_8(self): - self.cb.ORR_rr(r.r0.value, r.r7.value,r.r12.value, 8) + self.cb.ORR_rr(r.r0.value, r.r7.value, r.r12.value, 8) self.assert_equal('ORR r0, r7, r12, lsl #8') def test_push_one_reg(self): if get_as_version() < (2, 23): - py.test.xfail("GNU as before version 2.23 generates encoding A1 for " + py.test.xfail("GNU as before version 2.23 generates encoding A1 for " "pushing only one register") self.cb.PUSH([r.r1.value]) self.assert_equal('PUSH {r1}') diff --git a/rpython/jit/metainterp/history.py b/rpython/jit/metainterp/history.py index 2596ea54ce..f467b2e5f7 100644 --- a/rpython/jit/metainterp/history.py +++ b/rpython/jit/metainterp/history.py @@ -374,7 +374,7 @@ class ConstObj(Const): nonconstbox = clonebox def getref_base(self): - return self.value + return self.value def getref(self, OBJ): return ootype.cast_from_object(OBJ, self.getref_base()) diff --git a/rpython/jit/metainterp/resume.py b/rpython/jit/metainterp/resume.py index e1524b65ab..378601a143 100644 --- a/rpython/jit/metainterp/resume.py +++ b/rpython/jit/metainterp/resume.py @@ -183,8 +183,8 @@ class ResumeDataLoopMemo(object): if snapshot is None: return lltype.nullptr(NUMBERING), {}, 0 if snapshot in self.numberings: - numb, liveboxes, v = self.numberings[snapshot] - return numb, liveboxes.copy(), v + numb, liveboxes, v = self.numberings[snapshot] + return numb, liveboxes.copy(), v numb1, liveboxes, v = self.number(optimizer, snapshot.prev) n = len(liveboxes) - v diff --git a/rpython/jit/metainterp/test/test_greenfield.py b/rpython/jit/metainterp/test/test_greenfield.py index 07185bd138..fc7bd39f4b 100644 --- a/rpython/jit/metainterp/test/test_greenfield.py +++ b/rpython/jit/metainterp/test/test_greenfield.py @@ -56,5 +56,6 @@ class GreenFieldsTests: class TestLLtypeGreenFieldsTests(GreenFieldsTests, LLJitMixin): pass + class TestOOtypeGreenFieldsTests(GreenFieldsTests, OOJitMixin): - pass + pass diff --git a/rpython/jit/metainterp/test/test_immutable.py b/rpython/jit/metainterp/test/test_immutable.py index 4be1dd1138..5363ddf692 100644 --- a/rpython/jit/metainterp/test/test_immutable.py +++ b/rpython/jit/metainterp/test/test_immutable.py @@ -178,5 +178,6 @@ class ImmutableFieldsTests: class TestLLtypeImmutableFieldsTests(ImmutableFieldsTests, LLJitMixin): pass + class TestOOtypeImmutableFieldsTests(ImmutableFieldsTests, OOJitMixin): - pass + pass diff --git a/rpython/jit/tl/test/test_tl.py b/rpython/jit/tl/test/test_tl.py index 8cff208725..9fd2d5477a 100644 --- a/rpython/jit/tl/test/test_tl.py +++ b/rpython/jit/tl/test/test_tl.py @@ -79,10 +79,10 @@ class TestTL(test_boehm.AbstractGCTestClass): ] def test_ops(self): - for insn, pyop, values in self.ops: - for first, second in values: - code = [PUSH, first, PUSH, second, insn] - assert self.interp(list2bytecode(code)) == pyop(first, second) + for insn, pyop, values in self.ops: + for first, second in values: + code = [PUSH, first, PUSH, second, insn] + assert self.interp(list2bytecode(code)) == pyop(first, second) def test_branch_forward(self): diff --git a/rpython/memory/gc/generation.py b/rpython/memory/gc/generation.py index 60664f4f3d..f13a943499 100644 --- a/rpython/memory/gc/generation.py +++ b/rpython/memory/gc/generation.py @@ -468,7 +468,7 @@ class GenerationGC(SemiSpaceGC): JIT_WB_IF_FLAG = GCFLAG_NO_YOUNG_PTRS def write_barrier(self, newvalue, addr_struct): - if self.header(addr_struct).tid & GCFLAG_NO_YOUNG_PTRS: + if self.header(addr_struct).tid & GCFLAG_NO_YOUNG_PTRS: self.remember_young_pointer(addr_struct, newvalue) def _setup_wb(self): diff --git a/rpython/rlib/parsing/lexer.py b/rpython/rlib/parsing/lexer.py index a628cbd647..dc5d48cb04 100644 --- a/rpython/rlib/parsing/lexer.py +++ b/rpython/rlib/parsing/lexer.py @@ -80,10 +80,11 @@ class Lexer(object): self.ignore) def __getstate__(self): - return (self.token_regexs, self.names, self.ignore) + return (self.token_regexs, self.names, self.ignore) def __setstate__(self, args): - self.__init__(*args) + self.__init__(*args) + class DummyLexer(Lexer): def __init__(self, matcher, automaton, ignore): diff --git a/rpython/rlib/rope.py b/rpython/rlib/rope.py index c04ee87b94..e836a3839a 100644 --- a/rpython/rlib/rope.py +++ b/rpython/rlib/rope.py @@ -79,7 +79,7 @@ class StringNode(object): def is_ascii(self): raise NotImplementedError("base class") - + def is_bytestring(self): raise NotImplementedError("base class") @@ -144,7 +144,7 @@ class LiteralStringNode(LiteralNode): def __init__(self, s): assert isinstance(s, str) self.s = s - + def length(self): return len(self.s) @@ -245,7 +245,7 @@ class LiteralUnicodeNode(LiteralNode): def __init__(self, u): assert isinstance(u, unicode) self.u = u - + def length(self): return len(self.u) @@ -254,7 +254,7 @@ class LiteralUnicodeNode(LiteralNode): def is_ascii(self): return False # usually not - + def is_bytestring(self): return False @@ -415,7 +415,7 @@ class BinaryConcatNode(StringNode): def flatten_unicode(self): f = fringe(self) return u"".join([node.flatten_unicode() for node in f]) - + def hash_part(self): return self.additional_info().hash @@ -435,7 +435,7 @@ class BinaryConcatNode(StringNode): return self return rebalance([self], self.len) - + def _concat(self, other): if isinstance(other, LiteralNode): r = self.right @@ -946,7 +946,7 @@ class ItemIterator(object): self.index = 0 if start: self._advance_to(start) - + def _advance_to(self, index): self.index = self.iter._seekforward(index) self.node = self.iter.next() @@ -1106,7 +1106,7 @@ class SeekableItemIterator(object): self.stack.pop() raise StopIteration - + def seekback(self, numchars): if numchars <= self.index: self.index -= numchars @@ -1148,7 +1148,7 @@ class FindIterator(object): self.stop = self.start else: self.restart_positions = construct_restart_positions_node(sub) - + def next(self): if self.search_length == 0: if (self.stop - self.start) < 0: @@ -1257,20 +1257,20 @@ def endswith(self, suffix, start, end): def strip(node, left=True, right=True, predicate=lambda i: chr(i).isspace(), *extraargs): length = node.length() - + lpos = 0 rpos = length - + if left: iter = ItemIterator(node) while lpos < rpos and predicate(iter.nextint(), *extraargs): - lpos += 1 - + lpos += 1 + if right: iter = ReverseItemIterator(node) while rpos > lpos and predicate(iter.nextint(), *extraargs): - rpos -= 1 - + rpos -= 1 + assert rpos >= lpos return getslice_one(node, lpos, rpos) strip._annspecialcase_ = "specialize:arg(3)" @@ -1501,10 +1501,10 @@ def _str_encode_utf_8(s): ch = ord(s[i]) i += 1 if (ch < 0x80): - # Encode ASCII + # Encode ASCII result.append(chr(ch)) continue - # Encode Latin-1 + # Encode Latin-1 result.append(chr((0xc0 | (ch >> 6)))) result.append(chr((0x80 | (ch & 0x3f)))) return "".join(result) diff --git a/rpython/rlib/rstruct/ieee.py b/rpython/rlib/rstruct/ieee.py index 1a9f2c7134..e2f5ac989b 100644 --- a/rpython/rlib/rstruct/ieee.py +++ b/rpython/rlib/rstruct/ieee.py @@ -163,7 +163,7 @@ def float_pack(x, size): # Raise on overflow (in some circumstances, may want to return # infinity instead). if exp >= MAX_EXP - MIN_EXP + 2: - raise OverflowError("float too large to pack in this format") + raise OverflowError("float too large to pack in this format") # check constraints if not objectmodel.we_are_translated(): @@ -219,7 +219,7 @@ def float_pack80(x, size): # Raise on overflow (in some circumstances, may want to return # infinity instead). if exp >= MAX_EXP - MIN_EXP + 2: - raise OverflowError("float too large to pack in this format") + raise OverflowError("float too large to pack in this format") # check constraints if not objectmodel.we_are_translated(): diff --git a/rpython/rlib/test/test_rcomplex.py b/rpython/rlib/test/test_rcomplex.py index f7cb518dd1..4c5c9c5666 100644 --- a/rpython/rlib/test/test_rcomplex.py +++ b/rpython/rlib/test/test_rcomplex.py @@ -22,15 +22,15 @@ def test_sub(): ((10, -3), (-5, 7), (15, -10)), ((42, 0.3), (42, 0.3), (0, 0)) ]: - assert c.c_sub(c1, c2) == result + assert c.c_sub(c1, c2) == result def test_mul(): - for c1, c2, result in [ + for c1, c2, result in [ ((0, 0), (0, 0), (0, 0)), ((1, 0), (2, 0), (2, 0)), ((0, 3), (0, 2), (-6, 0)), ((0, -3), (-5, 0), (0, 15)), - ]: + ]: assert c.c_mul(c1, c2) == result def test_div(): @@ -65,7 +65,7 @@ def parse_testfile2(fname): struct.pack('l',int(rhs_pieces[i]))) else: rhs_pieces[i] = float(rhs_pieces[i]) - #id, fn, arg1_real, arg1_imag arg2_real, arg2_imag = + #id, fn, arg1_real, arg1_imag arg2_real, arg2_imag = #exp_real, exp_imag = rhs_pieces[0], rhs_pieces[1] flags = rhs_pieces[2:] id_f, fn = lhs_pieces[:2] @@ -108,7 +108,7 @@ def args_to_str(args): (args[0][0], args[0][1], args[1][0], args[1][1]) else: return '(complex(%r, %r))' % (args[0], args[1]) - + def rAssertAlmostEqual(a, b, rel_err = 2e-15, abs_err = 5e-323, msg=''): """Fail if the two floating-point numbers are not almost equal. diff --git a/rpython/rtyper/extfuncregistry.py b/rpython/rtyper/extfuncregistry.py index cfbbf76474..bb201dc7d4 100644 --- a/rpython/rtyper/extfuncregistry.py +++ b/rpython/rtyper/extfuncregistry.py @@ -61,7 +61,7 @@ for module, methods in _register: # Things with a tuple return type have a fake impl for RPython, check # to see if the method has one. if hasattr(oo_math, method_name): - oofake = getattr(oo_math, method_name) + oofake = getattr(oo_math, method_name) register_external(getattr(module, name), arg_types, return_type, export_name='ll_math.%s' % method_name, sandboxsafe=True, diff --git a/rpython/rtyper/lltypesystem/ll2ctypes.py b/rpython/rtyper/lltypesystem/ll2ctypes.py index a44ab997ed..f66428c0ff 100644 --- a/rpython/rtyper/lltypesystem/ll2ctypes.py +++ b/rpython/rtyper/lltypesystem/ll2ctypes.py @@ -718,186 +718,186 @@ def get_rtyper(): return None def lltype2ctypes(llobj, normalize=True): - """Convert the lltype object 'llobj' to its ctypes equivalent. - 'normalize' should only be False in tests, where we want to - inspect the resulting ctypes object manually. - """ - with rlock: - if isinstance(llobj, lltype._uninitialized): - return uninitialized2ctypes(llobj.TYPE) - if isinstance(llobj, llmemory.AddressAsInt): - cobj = ctypes.cast(lltype2ctypes(llobj.adr), ctypes.c_void_p) - res = intmask(cobj.value) - _int2obj[res] = llobj.adr.ptr._obj - return res - if isinstance(llobj, llmemory.fakeaddress): - llobj = llobj.ptr or 0 + """Convert the lltype object 'llobj' to its ctypes equivalent. + 'normalize' should only be False in tests, where we want to + inspect the resulting ctypes object manually. + """ + with rlock: + if isinstance(llobj, lltype._uninitialized): + return uninitialized2ctypes(llobj.TYPE) + if isinstance(llobj, llmemory.AddressAsInt): + cobj = ctypes.cast(lltype2ctypes(llobj.adr), ctypes.c_void_p) + res = intmask(cobj.value) + _int2obj[res] = llobj.adr.ptr._obj + return res + if isinstance(llobj, llmemory.fakeaddress): + llobj = llobj.ptr or 0 - T = lltype.typeOf(llobj) + T = lltype.typeOf(llobj) + + if isinstance(T, lltype.Ptr): + if not llobj: # NULL pointer + if T == llmemory.GCREF: + return ctypes.c_void_p(0) + return get_ctypes_type(T)() - if isinstance(T, lltype.Ptr): - if not llobj: # NULL pointer if T == llmemory.GCREF: - return ctypes.c_void_p(0) - return get_ctypes_type(T)() - - if T == llmemory.GCREF: - if isinstance(llobj._obj, _llgcopaque): - return ctypes.c_void_p(llobj._obj.intval) - if isinstance(llobj._obj, int): # tagged pointer - return ctypes.c_void_p(llobj._obj) - container = llobj._obj.container - T = lltype.Ptr(lltype.typeOf(container)) - # otherwise it came from integer and we want a c_void_p with - # the same value - if getattr(container, 'llopaque', None): - try: - no = _opaque_objs_seen[container] - except KeyError: - no = len(_opaque_objs) - _opaque_objs.append(container) - _opaque_objs_seen[container] = no - return no * 2 + 1 - else: - container = llobj._obj - if isinstance(T.TO, lltype.FuncType): - # XXX a temporary workaround for comparison of lltype.FuncType - key = llobj._obj.__dict__.copy() - key['_TYPE'] = repr(key['_TYPE']) - items = key.items() - items.sort() - key = tuple(items) - if key in _all_callbacks: - return _all_callbacks[key] - v1voidlist = [(i, getattr(container, '_void' + str(i), None)) - for i in range(len(T.TO.ARGS)) - if T.TO.ARGS[i] is lltype.Void] - def callback_internal(*cargs): - cargs = list(cargs) - for v1 in v1voidlist: - cargs.insert(v1[0], v1[1]) - assert len(cargs) == len(T.TO.ARGS) - llargs = [] - for ARG, carg in zip(T.TO.ARGS, cargs): - if ARG is lltype.Void: - llargs.append(carg) - else: - llargs.append(ctypes2lltype(ARG, carg)) - if hasattr(container, 'graph'): - if LLInterpreter.current_interpreter is None: - raise AssertionError - llinterp = LLInterpreter.current_interpreter + if isinstance(llobj._obj, _llgcopaque): + return ctypes.c_void_p(llobj._obj.intval) + if isinstance(llobj._obj, int): # tagged pointer + return ctypes.c_void_p(llobj._obj) + container = llobj._obj.container + T = lltype.Ptr(lltype.typeOf(container)) + # otherwise it came from integer and we want a c_void_p with + # the same value + if getattr(container, 'llopaque', None): try: - llres = llinterp.eval_graph(container.graph, llargs) - except LLException, lle: - llinterp._store_exception(lle) - return 0 - #except: - # import pdb - # pdb.set_trace() - else: - try: - llres = container._callable(*llargs) - except LLException, lle: + no = _opaque_objs_seen[container] + except KeyError: + no = len(_opaque_objs) + _opaque_objs.append(container) + _opaque_objs_seen[container] = no + return no * 2 + 1 + else: + container = llobj._obj + if isinstance(T.TO, lltype.FuncType): + # XXX a temporary workaround for comparison of lltype.FuncType + key = llobj._obj.__dict__.copy() + key['_TYPE'] = repr(key['_TYPE']) + items = key.items() + items.sort() + key = tuple(items) + if key in _all_callbacks: + return _all_callbacks[key] + v1voidlist = [(i, getattr(container, '_void' + str(i), None)) + for i in range(len(T.TO.ARGS)) + if T.TO.ARGS[i] is lltype.Void] + def callback_internal(*cargs): + cargs = list(cargs) + for v1 in v1voidlist: + cargs.insert(v1[0], v1[1]) + assert len(cargs) == len(T.TO.ARGS) + llargs = [] + for ARG, carg in zip(T.TO.ARGS, cargs): + if ARG is lltype.Void: + llargs.append(carg) + else: + llargs.append(ctypes2lltype(ARG, carg)) + if hasattr(container, 'graph'): + if LLInterpreter.current_interpreter is None: + raise AssertionError llinterp = LLInterpreter.current_interpreter - llinterp._store_exception(lle) - return 0 - assert lltype.typeOf(llres) == T.TO.RESULT - if T.TO.RESULT is lltype.Void: - return None - res = lltype2ctypes(llres) + try: + llres = llinterp.eval_graph(container.graph, llargs) + except LLException, lle: + llinterp._store_exception(lle) + return 0 + #except: + # import pdb + # pdb.set_trace() + else: + try: + llres = container._callable(*llargs) + except LLException, lle: + llinterp = LLInterpreter.current_interpreter + llinterp._store_exception(lle) + return 0 + assert lltype.typeOf(llres) == T.TO.RESULT + if T.TO.RESULT is lltype.Void: + return None + res = lltype2ctypes(llres) + if isinstance(T.TO.RESULT, lltype.Ptr): + _all_callbacks_results.append(res) + res = ctypes.cast(res, ctypes.c_void_p).value + if res is None: + return 0 + if T.TO.RESULT == lltype.SingleFloat: + res = res.value # baaaah, cannot return a c_float() + return res + + def callback(*cargs): + try: + return callback_internal(*cargs) + except: + import sys + #if option.usepdb: + # import pdb; pdb.post_mortem(sys.exc_traceback) + global _callback_exc_info + _callback_exc_info = sys.exc_info() + raise + if isinstance(T.TO.RESULT, lltype.Ptr): - _all_callbacks_results.append(res) - res = ctypes.cast(res, ctypes.c_void_p).value - if res is None: - return 0 - if T.TO.RESULT == lltype.SingleFloat: - res = res.value # baaaah, cannot return a c_float() + TMod = lltype.Ptr(lltype.FuncType(T.TO.ARGS, + lltype.Signed)) + ctypes_func_type = get_ctypes_type(TMod) + res = ctypes_func_type(callback) + ctypes_func_type = get_ctypes_type(T) + res = ctypes.cast(res, ctypes_func_type) + else: + ctypes_func_type = get_ctypes_type(T) + res = ctypes_func_type(callback) + _all_callbacks[key] = res + key2 = intmask(ctypes.cast(res, ctypes.c_void_p).value) + _int2obj[key2] = container return res - def callback(*cargs): - try: - return callback_internal(*cargs) - except: - import sys - #if option.usepdb: - # import pdb; pdb.post_mortem(sys.exc_traceback) - global _callback_exc_info - _callback_exc_info = sys.exc_info() - raise - - if isinstance(T.TO.RESULT, lltype.Ptr): - TMod = lltype.Ptr(lltype.FuncType(T.TO.ARGS, - lltype.Signed)) - ctypes_func_type = get_ctypes_type(TMod) - res = ctypes_func_type(callback) - ctypes_func_type = get_ctypes_type(T) - res = ctypes.cast(res, ctypes_func_type) - else: - ctypes_func_type = get_ctypes_type(T) - res = ctypes_func_type(callback) - _all_callbacks[key] = res - key2 = intmask(ctypes.cast(res, ctypes.c_void_p).value) - _int2obj[key2] = container - return res - - index = 0 - if isinstance(container, lltype._subarray): - topmost, index = _find_parent(container) - container = topmost - T = lltype.Ptr(lltype.typeOf(container)) - - if container._storage is None: - raise RuntimeError("attempting to pass a freed structure to C") - if container._storage is True: - # container has regular lltype storage, convert it to ctypes - if isinstance(T.TO, lltype.Struct): - convert_struct(container) - elif isinstance(T.TO, lltype.Array): - convert_array(container) - elif isinstance(T.TO, lltype.OpaqueType): - if T.TO != lltype.RuntimeTypeInfo: - cbuf = ctypes.create_string_buffer(T.TO.hints['getsize']()) + index = 0 + if isinstance(container, lltype._subarray): + topmost, index = _find_parent(container) + container = topmost + T = lltype.Ptr(lltype.typeOf(container)) + + if container._storage is None: + raise RuntimeError("attempting to pass a freed structure to C") + if container._storage is True: + # container has regular lltype storage, convert it to ctypes + if isinstance(T.TO, lltype.Struct): + convert_struct(container) + elif isinstance(T.TO, lltype.Array): + convert_array(container) + elif isinstance(T.TO, lltype.OpaqueType): + if T.TO != lltype.RuntimeTypeInfo: + cbuf = ctypes.create_string_buffer(T.TO.hints['getsize']()) + else: + cbuf = ctypes.create_string_buffer("\x00") + cbuf = ctypes.cast(cbuf, ctypes.c_void_p) + add_storage(container, _parentable_mixin, cbuf) else: - cbuf = ctypes.create_string_buffer("\x00") - cbuf = ctypes.cast(cbuf, ctypes.c_void_p) - add_storage(container, _parentable_mixin, cbuf) + raise NotImplementedError(T) + container._ctypes_storage_was_allocated() + + if isinstance(T.TO, lltype.OpaqueType): + return container._storage.value + + storage = container._storage + p = storage + if index: + p = ctypes.cast(p, ctypes.c_void_p) + p = ctypes.c_void_p(p.value + index) + c_tp = get_ctypes_type(T.TO) + storage.contents._normalized_ctype = c_tp + if normalize and hasattr(storage.contents, '_normalized_ctype'): + normalized_ctype = storage.contents._normalized_ctype + p = ctypes.cast(p, ctypes.POINTER(normalized_ctype)) + if lltype.typeOf(llobj) == llmemory.GCREF: + p = ctypes.cast(p, ctypes.c_void_p) + return p + + if isinstance(llobj, Symbolic): + if isinstance(llobj, llmemory.ItemOffset): + llobj = ctypes.sizeof(get_ctypes_type(llobj.TYPE)) * llobj.repeat + elif isinstance(llobj, ComputedIntSymbolic): + llobj = llobj.compute_fn() else: - raise NotImplementedError(T) - container._ctypes_storage_was_allocated() - - if isinstance(T.TO, lltype.OpaqueType): - return container._storage.value - - storage = container._storage - p = storage - if index: - p = ctypes.cast(p, ctypes.c_void_p) - p = ctypes.c_void_p(p.value + index) - c_tp = get_ctypes_type(T.TO) - storage.contents._normalized_ctype = c_tp - if normalize and hasattr(storage.contents, '_normalized_ctype'): - normalized_ctype = storage.contents._normalized_ctype - p = ctypes.cast(p, ctypes.POINTER(normalized_ctype)) - if lltype.typeOf(llobj) == llmemory.GCREF: - p = ctypes.cast(p, ctypes.c_void_p) - return p - - if isinstance(llobj, Symbolic): - if isinstance(llobj, llmemory.ItemOffset): - llobj = ctypes.sizeof(get_ctypes_type(llobj.TYPE)) * llobj.repeat - elif isinstance(llobj, ComputedIntSymbolic): - llobj = llobj.compute_fn() - else: - raise NotImplementedError(llobj) # don't know about symbolic value + raise NotImplementedError(llobj) # don't know about symbolic value - if T is lltype.Char or T is lltype.UniChar: - return ord(llobj) + if T is lltype.Char or T is lltype.UniChar: + return ord(llobj) - if T is lltype.SingleFloat: - return ctypes.c_float(float(llobj)) + if T is lltype.SingleFloat: + return ctypes.c_float(float(llobj)) - return llobj + return llobj def ctypes2lltype(T, cobj): """Convert the ctypes object 'cobj' to its lltype equivalent. diff --git a/rpython/rtyper/lltypesystem/test/test_lltype.py b/rpython/rtyper/lltypesystem/test/test_lltype.py index d699134301..dbf8b67208 100644 --- a/rpython/rtyper/lltypesystem/test/test_lltype.py +++ b/rpython/rtyper/lltypesystem/test/test_lltype.py @@ -53,9 +53,9 @@ def test_basics(): length = len(l.items) newitems = malloc(List_typ.items.TO, length+1) i = 0 - while i<length: - newitems[i].item = l.items[i].item - i += 1 + while i < length: + newitems[i].item = l.items[i].item + i += 1 newitems[length].item = newitem l.items = newitems diff --git a/rpython/translator/backendopt/raisingop2direct_call.py b/rpython/translator/backendopt/raisingop2direct_call.py index 82d93d58e4..673ae6715c 100644 --- a/rpython/translator/backendopt/raisingop2direct_call.py +++ b/rpython/translator/backendopt/raisingop2direct_call.py @@ -8,9 +8,9 @@ def is_raisingop(op): s = op.opname if (not s.startswith('int_') and not s.startswith('uint_') and not s.startswith('float_') and not s.startswith('llong_')): - return False + return False if not s.endswith('_zer') and not s.endswith('_ovf') and not s.endswith('_val'): #not s in special_operations: - return False + return False return True def raisingop2direct_call(translator, graphs=None): diff --git a/rpython/translator/driver.py b/rpython/translator/driver.py index b3d16bc55a..410f313e2f 100644 --- a/rpython/translator/driver.py +++ b/rpython/translator/driver.py @@ -60,7 +60,7 @@ class ProfInstrument(object): env = os.environ.copy() env['PYPY_INSTRUMENT_COUNTERS'] = str(self.datafile) self.compiler.platform.execute(exe, args, env=env) - + def after(self): # xxx os._exit(0) @@ -99,7 +99,7 @@ class TranslationDriver(SimpleTaskEngine): default_goal, = self.backend_select_goals([default_goal]) if default_goal in self._maybe_skip(): default_goal = None - + self.default_goal = default_goal self.extra_goals = [] self.exposed = [] @@ -142,7 +142,7 @@ class TranslationDriver(SimpleTaskEngine): def set_backend_extra_options(self, extra_options): self._backend_extra_options = extra_options - + def get_info(self): # XXX more? d = {'backend': self.config.translation.backend} return d @@ -163,7 +163,7 @@ class TranslationDriver(SimpleTaskEngine): new_goal = cand break else: - raise Exception, "cannot infer complete goal from: %r" % goal + raise Exception("cannot infer complete goal from: %r" % goal) l.append(new_goal) return l @@ -173,11 +173,10 @@ class TranslationDriver(SimpleTaskEngine): def _maybe_skip(self): maybe_skip = [] if self._disabled: - for goal in self.backend_select_goals(self._disabled): - maybe_skip.extend(self._depending_on_closure(goal)) + for goal in self.backend_select_goals(self._disabled): + maybe_skip.extend(self._depending_on_closure(goal)) return dict.fromkeys(maybe_skip).keys() - def setup(self, entry_point, inputtypes, policy=None, extra={}, empty_translator=None): standalone = inputtypes is None self.standalone = standalone @@ -423,7 +422,7 @@ class TranslationDriver(SimpleTaskEngine): from rpython.translator.transform import insert_ll_stackcheck count = insert_ll_stackcheck(self.translator) self.log.info("inserted %d stack checks." % (count,)) - + def possibly_check_for_boehm(self): if self.config.translation.gc == "boehm": @@ -537,7 +536,7 @@ class TranslationDriver(SimpleTaskEngine): def task_llinterpret_lltype(self): from rpython.rtyper.llinterp import LLInterpreter py.log.setconsumer("llinterp operation", None) - + translator = self.translator interp = LLInterpreter(translator.rtyper) bk = translator.annotator.bookkeeper @@ -575,7 +574,7 @@ class TranslationDriver(SimpleTaskEngine): # restore original os values if hasattr(self, 'old_cli_defs'): unpatch_os(self.old_cli_defs) - + self.log.info("Compiled %s" % filename) if self.standalone and self.exe_name: self.copy_cli_exe() @@ -607,9 +606,9 @@ then EXE=$0 fi if uname -s | grep -iq Cygwin -then +then MONO= -else +else MONO=mono # workaround for known mono buggy versions VER=`mono -V | head -1 | sed s/'Mono JIT compiler version \(.*\) (.*'/'\1/'` @@ -629,7 +628,7 @@ $LEDIT $MONO "$(dirname $EXE)/$(basename $EXE)-data/%s" "$@" # XXX doesn't work pypylib_dll = os.path.join(usession_path, 'pypylib.dll') shutil.copy(dllname, '.') shutil.copy(pypylib_dll, '.') - + # main.exe is a stub but is needed right now because it's # referenced by pypylib.dll. Will be removed in the future translator_path, _ = os.path.split(__file__) @@ -747,7 +746,7 @@ $LEDIT java -Xmx256m -jar $EXE.jar "$@" if backend in ('cli', 'jvm'): from rpython.translator.oosupport.support import patch_os driver.old_cli_defs = patch_os() - + target = targetspec_dic['target'] spec = target(driver, args) @@ -757,8 +756,8 @@ $LEDIT java -Xmx256m -jar $EXE.jar "$@" entry_point, inputtypes = spec policy = None - driver.setup(entry_point, inputtypes, - policy=policy, + driver.setup(entry_point, inputtypes, + policy=policy, extra=targetspec_dic, empty_translator=empty_translator) @@ -770,7 +769,7 @@ $LEDIT java -Xmx256m -jar $EXE.jar "$@" assert 'rpython.rtyper.rmodel' not in sys.modules, ( "cannot fork because the rtyper has already been imported") prereq_checkpt_rtype_lltype = prereq_checkpt_rtype - prereq_checkpt_rtype_ootype = prereq_checkpt_rtype + prereq_checkpt_rtype_ootype = prereq_checkpt_rtype # checkpointing support def _event(self, kind, goal, func): diff --git a/rpython/translator/goal/order.py b/rpython/translator/goal/order.py index e655d03df0..a1adfe7f46 100644 --- a/rpython/translator/goal/order.py +++ b/rpython/translator/goal/order.py @@ -3,9 +3,9 @@ import os RTYPERORDER = os.getenv('RTYPERORDER').split(',') if len(RTYPERORDER) == 2: - module_list = RTYPERORDER[1] + module_list = RTYPERORDER[1] else: - module_list = 'module-list' + module_list = 'module-list' lst = open(module_list, 'r') try: @@ -20,38 +20,37 @@ prefixes = [line for line in prefixes if line and not line.startswith('#')] NOMATCH = sys.maxint def order(annotator, pending): - cache = {} - annotated = annotator.annotated - def indx(block): - func = annotated[block] - module = func.__module__ - if module is None: - module = 'None' - tag = "%s:%s" % (module, func.__name__) - try: - return cache[tag] - except KeyError: - match = NOMATCH - i = 0 - for pfx in prefixes: - if tag.startswith(pfx): - if match == NOMATCH: - match = i - else: - if len(pfx) > len(prefixes[match]): - match = i - i += 1 - cache[tag] = match, module - return match - - pending.sort(lambda blk1, blk2: cmp(indx(blk1), indx(blk2))) - - cur_module = ['$'] - def track(block): - module = annotated[block].__module__ - if module != cur_module[0]: - print "--- Specializing blocks in module: %s" % module - cur_module[0] = module - return track - - + cache = {} + annotated = annotator.annotated + def indx(block): + func = annotated[block] + module = func.__module__ + if module is None: + module = 'None' + tag = "%s:%s" % (module, func.__name__) + try: + return cache[tag] + except KeyError: + match = NOMATCH + i = 0 + for pfx in prefixes: + if tag.startswith(pfx): + if match == NOMATCH: + match = i + else: + if len(pfx) > len(prefixes[match]): + match = i + i += 1 + cache[tag] = match, module + return match + + pending.sort(lambda blk1, blk2: cmp(indx(blk1), indx(blk2))) + + cur_module = ['$'] + + def track(block): + module = annotated[block].__module__ + if module != cur_module[0]: + print "--- Specializing blocks in module: %s" % module + cur_module[0] = module + return track diff --git a/rpython/translator/test/snippet.py b/rpython/translator/test/snippet.py index 481b77a189..fb565ff6d9 100644 --- a/rpython/translator/test/snippet.py +++ b/rpython/translator/test/snippet.py @@ -62,7 +62,7 @@ def get_set_del_slice(l=list): def sieve_of_eratosthenes(): """Sieve of Eratosthenes - + This one is from an infamous benchmark, "The Great Computer Language Shootout". @@ -103,7 +103,7 @@ def nested_whiles(i=int, j=int): s = s + '!' return s -def poor_man_range(i=int): +def poor_man_range(i=int): lst = [] while i > 0: i = i - 1 @@ -111,14 +111,14 @@ def poor_man_range(i=int): lst.reverse() return lst -def poor_man_rev_range(i=int): +def poor_man_rev_range(i=int): lst = [] while i > 0: i = i - 1 lst += [i] return lst -def simple_id(x=anytype): +def simple_id(x=anytype): return x def branch_id(cond=anytype, a=anytype, b=anytype): @@ -257,7 +257,7 @@ def factorial2(n=int): # analysed in a different order else: return 1 -def _append_five(lst): +def _append_five(lst): lst += [5] def call_five(): @@ -265,7 +265,7 @@ def call_five(): _append_five(a) return a -def _append_six(lst): +def _append_six(lst): lst += [6] def call_five_six(): @@ -333,7 +333,7 @@ def do_try_raise_choose(): return r -# INHERITANCE / CLASS TESTS +# INHERITANCE / CLASS TESTS class C(object): pass def build_instance(): @@ -565,7 +565,7 @@ def call_star_args1def(z): b = star_args1def(5) c = star_args1def() return a+b+c - + def star_args(x, y, *args): return x + args[0] @@ -605,10 +605,10 @@ def powerset(setsize=int): This one is from a Philippine Pythonista Hangout, an modified version of Andy Sy's code. - + list.append is modified to list concatenation, and powerset is pre-allocated and stored, instead of printed. - + URL is: http://lists.free.net.ph/pipermail/python/2002-November/ """ set = range(setsize) @@ -643,8 +643,8 @@ def _somebug1(n=int): l = [] v = l.append while n: - l[7] = 5 # raises an exception - break + l[7] = 5 # raises an exception + break return v def _getstuff(x): @@ -686,7 +686,7 @@ def func2(): pass def mergefunctions(cond): - if cond: + if cond: x = func1 else: x = func2 @@ -703,48 +703,48 @@ def func_arg_unpack(): a,b = 3, "hello" return a -class APBC: - def __init__(self): +class APBC: + def __init__(self): self.answer = 42 apbc = APBC() apbc.answer = 7 def preserve_pbc_attr_on_instance(cond): - if cond: + if cond: x = APBC() - else: - x = apbc - return x.answer + else: + x = apbc + return x.answer class APBCS(object): __slots__ = ['answer'] - def __init__(self): + def __init__(self): self.answer = 42 apbcs = APBCS() apbcs.answer = 7 def preserve_pbc_attr_on_instance_with_slots(cond): - if cond: + if cond: x = APBCS() - else: + else: x = apbcs - return x.answer + return x.answer -def is_and_knowntype(x): - if x is None: - return x - else: - return None +def is_and_knowntype(x): + if x is None: + return x + else: + return None -def isinstance_and_knowntype(x): - if isinstance(x, APBC): +def isinstance_and_knowntype(x): + if isinstance(x, APBC): return x - else: - return apbc + else: + return apbc def simple_slice(x): return x[:10] @@ -836,7 +836,7 @@ def exception_deduction_with_raise3(x): witness(e) return e return Exc() - + def slice_union(x): if x: return slice(1) @@ -938,8 +938,8 @@ def one_thing1(): class Thing2(long): - def __new__(t,v): - return long.__new__(t,v*2) + def __new__(t, v): + return long.__new__(t, v * 2) thing2 = Thing2(2) @@ -971,16 +971,16 @@ def propagation_of_fresh_instances_through_attrs(x): class R: - def __init__(self, n): - if n>0: - self.r = R(n-1) - else: - self.r = None - self.n = n - if self.r: - self.m = self.r.n - else: - self.m = -1 + def __init__(self, n): + if n > 0: + self.r = R(n-1) + else: + self.r = None + self.n = n + if self.r: + self.m = self.r.n + else: + self.m = -1 def make_r(n): return R(n) @@ -989,7 +989,7 @@ class B: pass class Even(B): - def __init__(self,n): + def __init__(self, n): if n > 0: self.x = [Odd(n-1)] self.y = self.x[0].x @@ -998,12 +998,12 @@ class Even(B): self.y = [] class Odd(B): - def __init__(self,n): + def __init__(self, n): self.x = [Even(n-1)] self.y = self.x[0].x def make_eo(n): - if n%2 == 0: + if n % 2 == 0: return Even(n) else: return Odd(n) @@ -1013,26 +1013,26 @@ def make_eo(n): # instances rev numbers class Box: - pass + pass class Box2: - pass + pass class Box3(Box2): - pass + pass def flow_rev_numbers(n): - bx3 = Box3() - bx3.x = 1 - bx = Box() - bx.bx3 = bx3 - if n >0: - z = bx.bx3.x - if n >0: - bx2 = Box2() - bx2.x = 3 - return z - raise Exception + bx3 = Box3() + bx3.x = 1 + bx = Box() + bx.bx3 = bx3 + if n > 0: + z = bx.bx3.x + if n > 0: + bx2 = Box2() + bx2.x = 3 + return z + raise Exception # class specialization @@ -1077,13 +1077,13 @@ def div_func(i=numtype): return ovfcheck((-maxint-1) // i) except (OverflowError, ZeroDivisionError): raise - + def mul_func(x=numtype, y=numtype): try: return ovfcheck(x * y) except OverflowError: raise - + def mod_func(i=numtype): try: return ovfcheck((-maxint-1) % i) @@ -1098,7 +1098,8 @@ def rshift_func(i=numtype): except ValueError: raise -class hugelmugel(OverflowError):pass +class hugelmugel(OverflowError): + pass def hugo(a, b, c):pass @@ -1112,6 +1113,7 @@ def lshift_func(i=numtype): def unary_func(i=numtype): try: return ovfcheck(-i), ovfcheck(abs(i-1)) - except: raise + except: + raise # XXX it would be nice to get it right without an exception # handler at all, but then we need to do much harder parsing diff --git a/rpython/translator/test/test_simplify.py b/rpython/translator/test/test_simplify.py index b5a5e738b6..9955c5dcc6 100644 --- a/rpython/translator/test/test_simplify.py +++ b/rpython/translator/test/test_simplify.py @@ -445,4 +445,4 @@ class TestLLSpecializeListComprehension: class TestOOSpecializeListComprehension(TestLLSpecializeListComprehension): - typesystem = 'ootype' + typesystem = 'ootype' diff --git a/rpython/translator/tool/make_dot.py b/rpython/translator/tool/make_dot.py index 1ead71de00..a3e07e7407 100644 --- a/rpython/translator/tool/make_dot.py +++ b/rpython/translator/tool/make_dot.py @@ -143,13 +143,13 @@ class FlowGraphDotGen(DotGen): color = "black" fillcolor = getattr(block, "blockcolor", "white") if not numblocks: - shape = "box" - if len(block.inputargs) == 1: - lines[-1] += 'return %s' % tuple(block.inputargs) - fillcolor= RETURN_COLOR - elif len(block.inputargs) == 2: - lines[-1] += 'raise %s, %s' % tuple(block.inputargs) - fillcolor= EXCEPT_COLOR + shape = "box" + if len(block.inputargs) == 1: + lines[-1] += 'return %s' % tuple(block.inputargs) + fillcolor = RETURN_COLOR + elif len(block.inputargs) == 2: + lines[-1] += 'raise %s, %s' % tuple(block.inputargs) + fillcolor = EXCEPT_COLOR elif numblocks == 1: shape = "box" else: |