Commits

Maciej Fijalkowski committed f99fd43 Merge

merge

  • Participants
  • Parent commits 92f0ae3, 8ed0b78

Comments (0)

Files changed (15)

File pypy/interpreter/baseobjspace.py

         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
 
     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__'.
             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,
             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))
              -> (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)
              -> (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,
 
     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)
     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)
         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))
         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
 
     ('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, []),
     ('delete',          'delete',    2, ['__delete__']),
     ('userdel',         'del',       1, ['__del__']),
     ('buffer',          'buffer',    1, ['__buffer__']),   # see buffer.py
-    ]
+]
 
 ObjSpace.BuiltinModuleTable = [
     '__builtin__',
     'sys',
-    ]
+]
 
 ObjSpace.ConstantTable = [
     'None',
     'True',
     'Ellipsis',
     'NotImplemented',
-    ]
+]
 
 ObjSpace.ExceptionTable = [
     'ArithmeticError',
     'ZeroDivisionError',
     'RuntimeWarning',
     'PendingDeprecationWarning',
-    ]
+]
 
 if sys.platform.startswith("win"):
     ObjSpace.ExceptionTable += ['WindowsError']

File pypy/objspace/std/boolobject.py

 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']
         return float(self.boolval)
 
     def int(self, space):
-        return self
+        return space.newint(int(self.boolval))
 
 registerimplementation(W_BoolObject)
 

File pypy/objspace/std/test/test_boolobject.py

     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)
         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

File rpython/jit/backend/conftest.py

 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')

File rpython/jit/codewriter/format.py

 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
             return '%r' % (x,)
         else:
             return '<unknown object: %r>' % (x,)
-    #
+
     seenlabels = {}
     for asm in ssarepr.insns:
         for x in asm:
             labelcount[0] += 1
             seenlabels[lbl.name] = labelcount[0]
         return 'L%d' % seenlabels[lbl.name]
-    #
+
     output = StringIO()
     insns = ssarepr.insns
     if insns and insns[-1] == ('---',):

File rpython/jit/metainterp/blackhole.py

 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

File rpython/jit/metainterp/compile.py

 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
     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 = {}
             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)
         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
     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)
     _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
         # 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,
     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]
     else:
         metainterp.retrace_needed(new_trace)
         return None
-        
 
 # ____________________________________________________________
 

File rpython/jit/metainterp/greenfield.py

-from rpython.jit.metainterp.typesystem import deref
-
-
 class GreenFieldInfo(object):
-
     def __init__(self, cpu, jd):
         self.cpu = cpu
         self.jitdriver_sd = jd

File rpython/jit/metainterp/history.py

-
 from rpython.rtyper.extregistry import ExtRegistryEntry
 from rpython.rtyper.lltypesystem import lltype, llmemory, rffi
 from rpython.rtyper.ootypesystem import ootype
 
 class BasicFinalDescr(AbstractFailDescr):
     final_descr = True
-    
+
     def __init__(self, identifier=None):
         self.identifier = identifier      # for testing
 

File rpython/jit/metainterp/quasiimmut.py

-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

File rpython/jit/metainterp/warmspot.py

 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

File rpython/jit/metainterp/warmstate.py

 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
 
 # ____________________________________________________________
 

File rpython/jit/tool/loopcounter.py

 Parse and display the traces produced by pypy-c-jit when PYPYLOG is set.
 """
 
-import py
 import sys
 import optparse
 import re

File rpython/jit/tool/loopviewer.py

 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:'
     if not options.quiet:
         for loop in loops:
             loop.show()
-            
+
     if options.summary:
         print
         print 'Summary:'

File rpython/jit/tool/showstats.py

 #!/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])
             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:])