Author: Maciej Fijalkowski <fij...@gmail.com> Branch: Changeset: r62718:f99fd433cd40 Date: 2013-03-23 19:47 -0700 http://bitbucket.org/pypy/pypy/changeset/f99fd433cd40/
Log: merge diff --git a/pypy/interpreter/baseobjspace.py b/pypy/interpreter/baseobjspace.py --- a/pypy/interpreter/baseobjspace.py +++ b/pypy/interpreter/baseobjspace.py @@ -913,7 +913,7 @@ if self.is_w(w_exc_type, w_check_class): return True # fast path (also here to handle string exceptions) try: - if self.is_true(self.isinstance(w_check_class, self.w_tuple)): + if self.isinstance_w(w_check_class, self.w_tuple): for w_t in self.fixedview(w_check_class): if self.exception_match(w_exc_type, w_t): return True @@ -1052,11 +1052,11 @@ def abstract_isinstance_w(self, w_obj, w_cls): # Equivalent to 'isinstance(obj, cls)'. - return self.is_true(self.isinstance(w_obj, w_cls)) + return self.isinstance_w(w_obj, w_cls) def abstract_isclass_w(self, w_obj): # Equivalent to 'isinstance(obj, type)'. - return self.is_true(self.isinstance(w_obj, self.w_type)) + return self.isinstance_w(w_obj, self.w_type) def abstract_getclass(self, w_obj): # Equivalent to 'obj.__class__'. @@ -1094,7 +1094,7 @@ expression = compiler.compile(expression, '?', 'eval', 0, hidden_applevel=hidden_applevel) else: - raise TypeError, 'space.eval(): expected a string, code or PyCode object' + raise TypeError('space.eval(): expected a string, code or PyCode object') return expression.exec_code(self, w_globals, w_locals) def exec_(self, statement, w_globals, w_locals, hidden_applevel=False, @@ -1108,7 +1108,7 @@ statement = compiler.compile(statement, filename, 'exec', 0, hidden_applevel=hidden_applevel) if not isinstance(statement, PyCode): - raise TypeError, 'space.exec_(): expected a string, code or PyCode object' + raise TypeError('space.exec_(): expected a string, code or PyCode object') w_key = self.wrap('__builtins__') if not self.is_true(self.contains(w_globals, w_key)): self.setitem(w_globals, w_key, self.wrap(self.builtin)) @@ -1164,7 +1164,7 @@ -> (index, 0, 0) or (start, stop, step) """ - if self.is_true(self.isinstance(w_index_or_slice, self.w_slice)): + if self.isinstance_w(w_index_or_slice, self.w_slice): from pypy.objspace.std.sliceobject import W_SliceObject assert isinstance(w_index_or_slice, W_SliceObject) start, stop, step = w_index_or_slice.indices3(self, seqlength) @@ -1184,7 +1184,7 @@ -> (index, 0, 0, 1) or (start, stop, step, slice_length) """ - if self.is_true(self.isinstance(w_index_or_slice, self.w_slice)): + if self.isinstance_w(w_index_or_slice, self.w_slice): from pypy.objspace.std.sliceobject import W_SliceObject assert isinstance(w_index_or_slice, W_SliceObject) start, stop, step, length = w_index_or_slice.indices4(self, @@ -1326,7 +1326,7 @@ def realstr_w(self, w_obj): # Like str_w, but only works if w_obj is really of type 'str'. - if not self.is_true(self.isinstance(w_obj, self.w_str)): + if not self.isinstance_w(w_obj, self.w_str): raise OperationError(self.w_TypeError, self.wrap('argument must be a string')) return self.str_w(w_obj) @@ -1346,7 +1346,7 @@ def realunicode_w(self, w_obj): # Like unicode_w, but only works if w_obj is really of type # 'unicode'. - if not self.is_true(self.isinstance(w_obj, self.w_unicode)): + if not self.isinstance_w(w_obj, self.w_unicode): raise OperationError(self.w_TypeError, self.wrap('argument must be a unicode')) return self.unicode_w(w_obj) @@ -1367,19 +1367,19 @@ return self.float_w(self.float(w_obj)) def gateway_r_longlong_w(self, w_obj): - if self.is_true(self.isinstance(w_obj, self.w_float)): + if self.isinstance_w(w_obj, self.w_float): raise OperationError(self.w_TypeError, self.wrap("integer argument expected, got float")) return self.r_longlong_w(self.int(w_obj)) def gateway_r_uint_w(self, w_obj): - if self.is_true(self.isinstance(w_obj, self.w_float)): + if self.isinstance_w(w_obj, self.w_float): raise OperationError(self.w_TypeError, self.wrap("integer argument expected, got float")) return self.uint_w(self.int(w_obj)) def gateway_r_ulonglong_w(self, w_obj): - if self.is_true(self.isinstance(w_obj, self.w_float)): + if self.isinstance_w(w_obj, self.w_float): raise OperationError(self.w_TypeError, self.wrap("integer argument expected, got float")) return self.r_ulonglong_w(self.int(w_obj)) @@ -1496,15 +1496,20 @@ space.exec_(str(source), w_glob, w_glob) return space.getitem(w_glob, space.wrap('anonymous')) + class DummyLock(object): def acquire(self, flag): return True + def release(self): pass + def _freeze_(self): return True + def __enter__(self): pass + def __exit__(self, *args): pass @@ -1539,7 +1544,7 @@ ('pos', 'pos', 1, ['__pos__']), ('neg', 'neg', 1, ['__neg__']), ('nonzero', 'truth', 1, ['__nonzero__']), - ('abs' , 'abs', 1, ['__abs__']), + ('abs', 'abs', 1, ['__abs__']), ('hex', 'hex', 1, ['__hex__']), ('oct', 'oct', 1, ['__oct__']), ('ord', 'ord', 1, []), @@ -1592,12 +1597,12 @@ ('delete', 'delete', 2, ['__delete__']), ('userdel', 'del', 1, ['__del__']), ('buffer', 'buffer', 1, ['__buffer__']), # see buffer.py - ] +] ObjSpace.BuiltinModuleTable = [ '__builtin__', 'sys', - ] +] ObjSpace.ConstantTable = [ 'None', @@ -1605,7 +1610,7 @@ 'True', 'Ellipsis', 'NotImplemented', - ] +] ObjSpace.ExceptionTable = [ 'ArithmeticError', @@ -1648,7 +1653,7 @@ 'ZeroDivisionError', 'RuntimeWarning', 'PendingDeprecationWarning', - ] +] if sys.platform.startswith("win"): ObjSpace.ExceptionTable += ['WindowsError'] diff --git a/pypy/objspace/std/boolobject.py b/pypy/objspace/std/boolobject.py --- a/pypy/objspace/std/boolobject.py +++ b/pypy/objspace/std/boolobject.py @@ -6,6 +6,7 @@ from pypy.objspace.std.register_all import register_all from pypy.objspace.std.intobject import W_IntObject + class W_BoolObject(W_Object): from pypy.objspace.std.booltype import bool_typedef as typedef _immutable_fields_ = ['boolval'] @@ -37,7 +38,7 @@ return float(self.boolval) def int(self, space): - return self + return space.newint(int(self.boolval)) registerimplementation(W_BoolObject) diff --git a/pypy/objspace/std/test/test_boolobject.py b/pypy/objspace/std/test/test_boolobject.py --- a/pypy/objspace/std/test/test_boolobject.py +++ b/pypy/objspace/std/test/test_boolobject.py @@ -11,19 +11,24 @@ def test_repr(self): assert self.space.eq_w(self.space.repr(self.true), self.wrap("True")) assert self.space.eq_w(self.space.repr(self.false), self.wrap("False")) - + def test_true(self): assert self.space.is_true(self.true) - + def test_false(self): assert not self.space.is_true(self.false) + def test_int_w(self): + assert self.space.int_w(self.true) is 1 + assert self.space.int_w(self.false) is 0 + def test_uint_w(self): assert self.space.uint_w(self.true) == 1 + assert self.space.uint_w(self.false) == 0 def test_rbigint_w(self): assert self.space.bigint_w(self.true)._digits == [1] - + class AppTestAppBoolTest: def test_bool_callable(self): assert True == bool(1) @@ -36,6 +41,10 @@ assert "True" == repr(True) assert "False" == repr(False) + def test_bool_int(self): + assert int(True) is 1 + assert int(False) is 0 + def test_bool_ops(self): assert True + True == 2 assert False | False is False diff --git a/rpython/jit/backend/conftest.py b/rpython/jit/backend/conftest.py --- a/rpython/jit/backend/conftest.py +++ b/rpython/jit/backend/conftest.py @@ -2,7 +2,7 @@ This conftest adds options used by test/test_random and x86/test/test_zll_random. """ -import py, random +import random def pytest_addoption(parser): group = parser.getgroup('random test options') diff --git a/rpython/jit/codewriter/format.py b/rpython/jit/codewriter/format.py --- a/rpython/jit/codewriter/format.py +++ b/rpython/jit/codewriter/format.py @@ -10,8 +10,7 @@ def format_assembler(ssarepr): """For testing: format a SSARepr as a multiline string.""" from cStringIO import StringIO - seen = {} - # + def repr(x): if isinstance(x, Register): return '%%%s%d' % (x.kind[0], x.index) # e.g. %i1 or %r2 or %f3 @@ -32,7 +31,7 @@ return '%r' % (x,) else: return '<unknown object: %r>' % (x,) - # + seenlabels = {} for asm in ssarepr.insns: for x in asm: @@ -47,7 +46,7 @@ labelcount[0] += 1 seenlabels[lbl.name] = labelcount[0] return 'L%d' % seenlabels[lbl.name] - # + output = StringIO() insns = ssarepr.insns if insns and insns[-1] == ('---',): diff --git a/rpython/jit/metainterp/blackhole.py b/rpython/jit/metainterp/blackhole.py --- a/rpython/jit/metainterp/blackhole.py +++ b/rpython/jit/metainterp/blackhole.py @@ -3,7 +3,7 @@ from rpython.jit.metainterp.compile import ResumeAtPositionDescr from rpython.jit.metainterp.jitexc import JitException, get_llexception, reraise from rpython.rlib import longlong2float -from rpython.rlib.debug import debug_start, debug_stop, ll_assert, make_sure_not_resized +from rpython.rlib.debug import ll_assert, make_sure_not_resized from rpython.rlib.objectmodel import we_are_translated from rpython.rlib.rarithmetic import intmask, LONG_BIT, r_uint, ovfcheck from rpython.rlib.rtimer import read_timestamp 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,11 +9,10 @@ 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, History, JitCellToken, TargetToken +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, BoxObj, BoxFloat, Const, ConstInt +from rpython.jit.metainterp.history import BoxPtr, BoxFloat, ConstInt from rpython.jit.metainterp import history, resume -from rpython.jit.metainterp.typesystem import llhelper, oohelper from rpython.jit.metainterp.optimize import InvalidLoop from rpython.jit.metainterp.inliner import Inliner from rpython.jit.metainterp.resume import NUMBERING, PENDINGFIELDSP @@ -140,7 +139,7 @@ assert isinstance(target_token, TargetToken) all_target_tokens = [target_token] - loop = create_empty_loop(metainterp) + loop = create_empty_loop(metainterp) loop.inputargs = part.inputargs loop.operations = part.operations loop.quasi_immutable_deps = {} @@ -163,7 +162,7 @@ optimize_trace(metainterp_sd, part, enable_opts) except InvalidLoop: return None - + loop.operations = loop.operations[:-1] + part.operations if part.quasi_immutable_deps: loop.quasi_immutable_deps.update(part.quasi_immutable_deps) @@ -224,7 +223,6 @@ try: optimize_trace(metainterp_sd, part, jitdriver_sd.warmstate.enable_opts, inline_short_preamble=False) - except InvalidLoop: return None assert part.operations[-1].getopnum() != rop.LABEL @@ -249,9 +247,9 @@ for box in loop.inputargs: assert isinstance(box, Box) - target_token = loop.operations[-1].getdescr() + target_token = loop.operations[-1].getdescr() resumekey.compile_and_attach(metainterp, loop) - + target_token = label.getdescr() assert isinstance(target_token, TargetToken) record_loop_or_bridge(metainterp_sd, loop) @@ -486,7 +484,7 @@ _counters = None # they get stored in _counters then. # this class also gets the following attributes stored by resume.py code - + # XXX move all of unused stuff to guard_op, now that we can have # a separate class, so it does not survive that long rd_snapshot = None @@ -803,7 +801,6 @@ # with completely unoptimized arguments, as in the interpreter. metainterp_sd = metainterp.staticdata jitdriver_sd = metainterp.jitdriver_sd - redargs = new_loop.inputargs new_loop.original_jitcell_token = jitcell_token = make_jitcell_token(jitdriver_sd) propagate_original_jitcell_token(new_loop) send_loop_to_backend(self.original_greenkey, metainterp.jitdriver_sd, @@ -819,14 +816,14 @@ to some existing place. """ from rpython.jit.metainterp.optimizeopt import optimize_trace - + # The history contains new operations to attach as the code for the # failure of 'resumekey.guard_op'. # # Attempt to use optimize_bridge(). This may return None in case # it does not work -- i.e. none of the existing old_loop_tokens match. new_trace = create_empty_loop(metainterp) - new_trace.inputargs = inputargs = metainterp.history.inputargs[:] + new_trace.inputargs = metainterp.history.inputargs[:] # clone ops, as optimize_bridge can mutate the ops new_trace.operations = [op.clone() for op in metainterp.history.operations] @@ -856,7 +853,6 @@ else: metainterp.retrace_needed(new_trace) return None - # ____________________________________________________________ diff --git a/rpython/jit/metainterp/greenfield.py b/rpython/jit/metainterp/greenfield.py --- a/rpython/jit/metainterp/greenfield.py +++ b/rpython/jit/metainterp/greenfield.py @@ -1,8 +1,4 @@ -from rpython.jit.metainterp.typesystem import deref - - class GreenFieldInfo(object): - def __init__(self, cpu, jd): self.cpu = cpu self.jitdriver_sd = jd diff --git a/rpython/jit/metainterp/history.py b/rpython/jit/metainterp/history.py --- a/rpython/jit/metainterp/history.py +++ b/rpython/jit/metainterp/history.py @@ -1,4 +1,3 @@ - from rpython.rtyper.extregistry import ExtRegistryEntry from rpython.rtyper.lltypesystem import lltype, llmemory, rffi from rpython.rtyper.ootypesystem import ootype @@ -175,7 +174,7 @@ class BasicFinalDescr(AbstractFailDescr): final_descr = True - + def __init__(self, identifier=None): self.identifier = identifier # for testing 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 @@ -1,4 +1,3 @@ -import weakref from rpython.rtyper.lltypesystem import lltype, rclass from rpython.rtyper.annlowlevel import cast_base_ptr_to_instance from rpython.jit.metainterp.history import AbstractDescr 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,12 +1,11 @@ import sys, py from rpython.tool.sourcetools import func_with_new_name -from rpython.rtyper.lltypesystem import lltype, llmemory, rffi +from rpython.rtyper.lltypesystem import lltype, llmemory 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 -from rpython.rtyper.annlowlevel import cast_instance_to_base_ptr from rpython.flowspace.model import SpaceOperation, Variable, Constant from rpython.flowspace.model import checkgraph, Link, copygraph from rpython.rlib.objectmodel import we_are_translated 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 @@ -12,7 +12,6 @@ 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 -from rpython.tool.sourcetools import func_with_new_name # ____________________________________________________________ diff --git a/rpython/jit/tool/loopcounter.py b/rpython/jit/tool/loopcounter.py --- a/rpython/jit/tool/loopcounter.py +++ b/rpython/jit/tool/loopcounter.py @@ -3,7 +3,6 @@ Parse and display the traces produced by pypy-c-jit when PYPYLOG is set. """ -import py import sys import optparse import re diff --git a/rpython/jit/tool/loopviewer.py b/rpython/jit/tool/loopviewer.py --- a/rpython/jit/tool/loopviewer.py +++ b/rpython/jit/tool/loopviewer.py @@ -3,14 +3,10 @@ Parse and display the traces produced by pypy-c-jit when PYPYLOG is set. """ -import py import sys import optparse -from pprint import pprint from rpython.tool import logparser from rpython.jit.tool.oparser import parse -from rpython.jit.metainterp.history import ConstInt -from rpython.rtyper.lltypesystem import llmemory, lltype def main(loopfile, options): print 'Loading file:' @@ -19,7 +15,7 @@ if not options.quiet: for loop in loops: loop.show() - + if options.summary: print print 'Summary:' diff --git a/rpython/jit/tool/showstats.py b/rpython/jit/tool/showstats.py --- a/rpython/jit/tool/showstats.py +++ b/rpython/jit/tool/showstats.py @@ -1,11 +1,10 @@ #!/usr/bin/env python from __future__ import division -import sys, py +import sys from rpython.tool import logparser from rpython.jit.tool.oparser import parse from rpython.jit.metainterp.resoperation import rop -from rpython.rtyper.lltypesystem import lltype, llmemory def main(argv): log = logparser.parse_log_file(argv[0]) @@ -26,6 +25,6 @@ print "Loop #%d, length: %d, opcodes: %d, guards: %d" % (i, num_ops, num_dmp, num_guards) else: print "Loop #%d, length: %d, opcodes: %d, guards: %d, %f" % (i, num_ops, num_dmp, num_guards, num_ops/num_dmp) - + if __name__ == '__main__': main(sys.argv[1:]) _______________________________________________ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit