Commits

Maciej Fijalkowski committed a43ff04

kill last mentions of pypy.interpreter from flow objspace, great job ronan!

Comments (0)

Files changed (5)

pypy/objspace/flow/bytecode.py

 """
 Bytecode handling classes and functions for use by the flow space.
 """
-from pypy.interpreter.pycode import BytecodeCorruption
 from pypy.tool.stdlib_opcode import (host_bytecode_spec, EXTENDED_ARG,
         HAVE_ARGUMENT)
-from pypy.interpreter.astcompiler.consts import (CO_GENERATOR, CO_VARARGS,
-        CO_VARKEYWORDS)
 from pypy.objspace.flow.argument import Signature
+from pypy.objspace.flow.flowcontext import BytecodeCorruption
+
+CO_GENERATOR = 0x0020
+CO_VARARGS = 0x0004
+CO_VARKEYWORDS = 0x0008
 
 def cpython_code_signature(code):
     "([list-of-arg-names], vararg-name-or-None, kwarg-name-or-None)."

pypy/objspace/flow/flowcontext.py

 
 from pypy.tool.error import source_lines
 from pypy.tool.stdlib_opcode import host_bytecode_spec
-from pypy.interpreter import pyframe
 from pypy.objspace.flow.argument import ArgumentsForTranslation
-from pypy.interpreter.pyopcode import BytecodeCorruption
 from pypy.objspace.flow.model import (Constant, Variable, Block, Link,
     UnwrapException, c_last_exception)
 from pypy.objspace.flow.framestate import (FrameState, recursively_unflatten,
 class ImplicitOperationError(FSException):
     pass
 
+class BytecodeCorruption(Exception):
+    pass
+
 class SpamBlock(Block):
     # make slots optional, for debugging
     if hasattr(Block, '__slots__'):

pypy/objspace/flow/objspace.py

 import types
 from inspect import CO_NEWLOCALS
 
-from pypy.interpreter.baseobjspace import ObjSpace
 from pypy.objspace.flow.argument import ArgumentsForTranslation
 from pypy.objspace.flow.model import (Constant, Variable, WrapException,
     UnwrapException, checkgraph, SpaceOperation)
     setattr(FlowObjSpace, name, generic_operator)
 
 
-for (name, symbol, arity, specialnames) in ObjSpace.MethodTable:
+for (name, symbol, arity, specialnames) in operation.MethodTable:
     make_op(name, arity)

pypy/objspace/flow/operation.py

 import __builtin__
 import __future__
 import operator
-from pypy.interpreter.baseobjspace import ObjSpace
 from pypy.tool.sourcetools import compile2
 from pypy.rlib.rarithmetic import ovfcheck
 
+# this is a copy that should be shared with standard objspace
+
+MethodTable = [
+# method name # symbol # number of arguments # special method name(s)
+    ('is_',             'is',        2, []),
+    ('id',              'id',        1, []),
+    ('type',            'type',      1, []),
+    ('isinstance',      'isinstance', 2, ['__instancecheck__']),
+    ('issubtype',       'issubtype', 2, ['__subclasscheck__']),  # not for old-style classes
+    ('repr',            'repr',      1, ['__repr__']),
+    ('str',             'str',       1, ['__str__']),
+    ('format',          'format',    2, ['__format__']),
+    ('len',             'len',       1, ['__len__']),
+    ('hash',            'hash',      1, ['__hash__']),
+    ('getattr',         'getattr',   2, ['__getattribute__']),
+    ('setattr',         'setattr',   3, ['__setattr__']),
+    ('delattr',         'delattr',   2, ['__delattr__']),
+    ('getitem',         'getitem',   2, ['__getitem__']),
+    ('setitem',         'setitem',   3, ['__setitem__']),
+    ('delitem',         'delitem',   2, ['__delitem__']),
+    ('getslice',        'getslice',  3, ['__getslice__']),
+    ('setslice',        'setslice',  4, ['__setslice__']),
+    ('delslice',        'delslice',  3, ['__delslice__']),
+    ('trunc',           'trunc',     1, ['__trunc__']),
+    ('pos',             'pos',       1, ['__pos__']),
+    ('neg',             'neg',       1, ['__neg__']),
+    ('nonzero',         'truth',     1, ['__nonzero__']),
+    ('abs' ,            'abs',       1, ['__abs__']),
+    ('hex',             'hex',       1, ['__hex__']),
+    ('oct',             'oct',       1, ['__oct__']),
+    ('ord',             'ord',       1, []),
+    ('invert',          '~',         1, ['__invert__']),
+    ('add',             '+',         2, ['__add__', '__radd__']),
+    ('sub',             '-',         2, ['__sub__', '__rsub__']),
+    ('mul',             '*',         2, ['__mul__', '__rmul__']),
+    ('truediv',         '/',         2, ['__truediv__', '__rtruediv__']),
+    ('floordiv',        '//',        2, ['__floordiv__', '__rfloordiv__']),
+    ('div',             'div',       2, ['__div__', '__rdiv__']),
+    ('mod',             '%',         2, ['__mod__', '__rmod__']),
+    ('divmod',          'divmod',    2, ['__divmod__', '__rdivmod__']),
+    ('pow',             '**',        3, ['__pow__', '__rpow__']),
+    ('lshift',          '<<',        2, ['__lshift__', '__rlshift__']),
+    ('rshift',          '>>',        2, ['__rshift__', '__rrshift__']),
+    ('and_',            '&',         2, ['__and__', '__rand__']),
+    ('or_',             '|',         2, ['__or__', '__ror__']),
+    ('xor',             '^',         2, ['__xor__', '__rxor__']),
+    ('int',             'int',       1, ['__int__']),
+    ('index',           'index',     1, ['__index__']),
+    ('float',           'float',     1, ['__float__']),
+    ('long',            'long',      1, ['__long__']),
+    ('inplace_add',     '+=',        2, ['__iadd__']),
+    ('inplace_sub',     '-=',        2, ['__isub__']),
+    ('inplace_mul',     '*=',        2, ['__imul__']),
+    ('inplace_truediv', '/=',        2, ['__itruediv__']),
+    ('inplace_floordiv','//=',       2, ['__ifloordiv__']),
+    ('inplace_div',     'div=',      2, ['__idiv__']),
+    ('inplace_mod',     '%=',        2, ['__imod__']),
+    ('inplace_pow',     '**=',       2, ['__ipow__']),
+    ('inplace_lshift',  '<<=',       2, ['__ilshift__']),
+    ('inplace_rshift',  '>>=',       2, ['__irshift__']),
+    ('inplace_and',     '&=',        2, ['__iand__']),
+    ('inplace_or',      '|=',        2, ['__ior__']),
+    ('inplace_xor',     '^=',        2, ['__ixor__']),
+    ('lt',              '<',         2, ['__lt__', '__gt__']),
+    ('le',              '<=',        2, ['__le__', '__ge__']),
+    ('eq',              '==',        2, ['__eq__', '__eq__']),
+    ('ne',              '!=',        2, ['__ne__', '__ne__']),
+    ('gt',              '>',         2, ['__gt__', '__lt__']),
+    ('ge',              '>=',        2, ['__ge__', '__le__']),
+    ('cmp',             'cmp',       2, ['__cmp__']),   # rich cmps preferred
+    ('coerce',          'coerce',    2, ['__coerce__', '__coerce__']),
+    ('contains',        'contains',  2, ['__contains__']),
+    ('iter',            'iter',      1, ['__iter__']),
+    ('next',            'next',      1, ['next']),
+#    ('call',            'call',      3, ['__call__']),
+    ('get',             'get',       3, ['__get__']),
+    ('set',             'set',       3, ['__set__']),
+    ('delete',          'delete',    2, ['__delete__']),
+    ('userdel',         'del',       1, ['__del__']),
+    ('buffer',          'buffer',    1, ['__buffer__']),   # see buffer.py
+    ]
+
 
 FunctionByName = {}   # dict {"operation_name": <built-in function>}
 OperationName  = {}   # dict {<built-in function>: "operation_name"}
 
 def setup():
     # insert all operators
-    for line in ObjSpace.MethodTable:
+    for line in MethodTable:
         name = line[0]
         if hasattr(operator, name):
             Table.append((name, getattr(operator, name)))
         if func not in OperationName:
             OperationName[func] = name
     # check that the result is complete
-    for line in ObjSpace.MethodTable:
+    for line in MethodTable:
         name = line[0]
         Arity[name] = line[2]
         assert name in FunctionByName

pypy/objspace/flow/test/test_objspace.py

     def test_mergeable(self):
         def myfunc(x):
             if x:
-                from pypy.interpreter.error import OperationError
+                from pypy.objspace.flow.flowcontext import BytecodeCorruption
                 s = 12
             else:
                 s = x.abc