[pypy-svn] r39888 - pypy/branch/pypy-2.5/pypy/module/operator
asigfrid at codespeak.net
asigfrid at codespeak.net
Sun Mar 4 15:38:22 CET 2007
Author: asigfrid
Date: Sun Mar 4 15:38:20 2007
New Revision: 39888
Modified:
pypy/branch/pypy-2.5/pypy/module/operator/__init__.py
pypy/branch/pypy-2.5/pypy/module/operator/app_operator.py
pypy/branch/pypy-2.5/pypy/module/operator/interp_operator.py
Log:
Moved the directly translatable functions in operator from app to interpreter level.
Modified: pypy/branch/pypy-2.5/pypy/module/operator/__init__.py
==============================================================================
--- pypy/branch/pypy-2.5/pypy/module/operator/__init__.py (original)
+++ pypy/branch/pypy-2.5/pypy/module/operator/__init__.py Sun Mar 4 15:38:20 2007
@@ -6,27 +6,33 @@
appleveldefs = {}
- names = ['__abs__', '__add__', '__and__',
- '__concat__', '__contains__', '__delitem__', '__delslice__',
- '__div__', '__doc__', '__eq__', '__floordiv__',
- '__ge__', '__getitem__', '__getslice__', '__gt__', '__inv__',
- '__invert__', '__le__', '__lshift__', '__lt__', '__mod__',
- '__mul__', '__name__', '__ne__', '__neg__', '__not__', '__or__',
- '__pos__', '__pow__', '__repeat__', '__rshift__', '__setitem__',
- '__setslice__', '__sub__', '__truediv__', '__xor__', 'abs', 'add',
- 'and_', 'attrgetter', 'concat', 'contains', 'countOf', 'delitem',
- 'delslice', 'div', 'division', 'eq', 'floordiv', 'ge', 'getitem',
- 'getslice', 'gt', 'indexOf', 'inv', 'invert', 'isCallable',
- 'isMappingType', 'isNumberType', 'isSequenceType', 'is_',
- 'is_not', 'itemgetter', 'le', 'lshift', 'lt', 'mod', 'mul',
- 'ne', 'neg', 'not_', 'or_', 'pos', 'pow', 'repeat', 'rshift',
- 'sequenceIncludes', 'setitem', 'setslice', 'sub', 'truediv',
- 'truth', 'xor']
+ app_names = ['__delslice__', '__doc__','__getslice__', '__name__',
+ '__repeat__', '__setslice__', '__truediv__','attrgetter',
+ 'concat', 'contains', 'countOf', 'delitem',
+ 'delslice', 'division', 'getslice', 'indexOf',
+ 'isCallable','isMappingType', 'isNumberType', 'isSequenceType',
+ 'itemgetter','repeat', 'sequenceIncludes', 'setslice',
+ 'truediv']
- for name in names:
+ for name in app_names:
appleveldefs[name] = 'app_operator.%s' % name
-
-
- interpleveldefs = {
- 'index': 'interp_operator.index'
- }
+
+ interp_names = ['index', '__abs__', '__add__', '__and__',
+ '__concat__', '__contains__', '__delitem__','__div__',
+ '__eq__', '__floordiv__', '__ge__', '__getitem__',
+ '__gt__', '__inv__', '__invert__', '__le__',
+ '__lshift__', '__lt__', '__mod__', '__mul__',
+ '__ne__', '__neg__', '__not__', '__or__',
+ '__pos__', '__pow__', '__rshift__', '__setitem__',
+ '__sub__', '__xor__', 'abs', 'add',
+ 'and_', 'div', 'eq', 'floordiv',
+ 'ge', 'getitem', 'gt', 'inv',
+ 'invert', 'is_', 'is_not', 'le',
+ 'lshift', 'lt', 'mod', 'mul',
+ 'ne', 'neg', 'not_', 'or_',
+ 'pos', 'pow', 'rshift', 'setitem',
+ 'sub', 'truth', 'xor']
+ interpleveldefs = {}
+
+ for name in interp_names:
+ interpleveldefs[name] = 'interp_operator.%s' % name
Modified: pypy/branch/pypy-2.5/pypy/module/operator/app_operator.py
==============================================================================
--- pypy/branch/pypy-2.5/pypy/module/operator/app_operator.py (original)
+++ pypy/branch/pypy-2.5/pypy/module/operator/app_operator.py Sun Mar 4 15:38:20 2007
@@ -5,32 +5,11 @@
'''
import __builtin__
-def abs(obj,):
- 'abs(a) -- Same as abs(a).'
- return __builtin__.abs(obj)
-__abs__ = abs
-def add(obj1, obj2):
- 'add(a, b) -- Same as a + b.'
- return obj1 + obj2
-__add__ = add
-def and_(obj1,obj2):
- 'and_(a, b) -- Same as a & b.'
- return obj1 & obj2
-__and__ = and_
def attrgetter(attr):
def f(obj):
return getattr(obj, attr)
return f
-def concat(obj1, obj2):
- 'concat(a, b) -- Same as a + b, for a and b sequences.'
- return obj1 + obj2 # XXX cPython only works on types with sequence api
- # we support any with __add__
-__concat__ = concat
-
-def contains(obj1,obj2):
- 'contains(a, b) -- Same as b in a (note reversed operands).'
- return obj2 in obj1
-__contains__ = contains
+
def countOf(a,b):
'countOf(a, b) -- Return the number of times b occurs in a.'
count = 0
@@ -38,46 +17,21 @@
if x == b:
count += 1
return count
-def delitem(obj, key):
- 'delitem(a, b) -- Same as del a[b].'
- del obj[key]
-__delitem__ = delitem
+
def delslice(obj, start, end):
'delslice(a, b, c) -- Same as del a[b:c].'
if not isinstance(start, int) or not isinstance(end, int):
raise TypeError("an integer is expected")
del obj[start:end]
__delslice__ = delslice
-def div(a,b):
- 'div(a, b) -- Same as a / b when __future__.division is not in effect.'
- return a / b
-__div__ = div
-def eq(a, b):
- 'eq(a, b) -- Same as a==b.'
- return a == b
-__eq__ = eq
-def floordiv(a, b):
- 'floordiv(a, b) -- Same as a // b.'
- return a // b
-__floordiv__ = floordiv
-def ge(a, b):
- 'ge(a, b) -- Same as a>=b.'
- return a >= b
-__ge__ = ge
-def getitem(a, b):
- 'getitem(a, b) -- Same as a[b].'
- return a[b]
-__getitem__ = getitem
+
def getslice(a, start, end):
'getslice(a, b, c) -- Same as a[b:c].'
if not isinstance(start, int) or not isinstance(end, int):
raise TypeError("an integer is expected")
return a[start:end]
__getslice__ = getslice
-def gt(a,b):
- 'gt(a, b) -- Same as a>b.'
- return a > b
-__gt__ = gt
+
def indexOf(a, b):
'indexOf(a, b) -- Return the first index of b in a.'
index = 0
@@ -86,14 +40,7 @@
return index
index += 1
raise ValueError, 'sequence.index(x): x not in sequence'
-def inv(obj,):
- 'inv(a) -- Same as ~a.'
- return ~obj
-__inv__ = inv
-def invert(obj,):
- 'invert(a) -- Same as ~a.'
- return ~obj
-__invert__ = invert
+
def isCallable(obj,):
'isCallable(a) -- Same as callable(a).'
return callable(obj)
@@ -103,68 +50,20 @@
'isMappingType(a) -- Return True if a has a mapping type, False otherwise.'
# XXX this is fragile and approximative anyway
return hasattr(obj, '__getitem__') and hasattr(obj, 'keys')
+
def isNumberType(obj,):
'isNumberType(a) -- Return True if a has a numeric type, False otherwise.'
- return hasattr(obj, '__int__') or hasattr(obj, '__float__')
+ return hasattr(obj, '__int__') or hasattr(obj, '__float__')
+
def isSequenceType(obj,):
'isSequenceType(a) -- Return True if a has a sequence type, False otherwise.'
return hasattr(obj, '__getitem__')
-def is_(a, b):
- 'is_(a, b) -- Same as a is b.'
- return a is b
-def is_not(a, b):
- 'is_not(a, b) -- Same as a is not b.'
- return a is not b
def itemgetter(idx):
def f(obj):
return obj[idx]
return f
-def le(a, b):
- 'le(a, b) -- Same as a<=b.'
- return a <= b
-__le__ = le
-def lshift(a, b):
- 'lshift(a, b) -- Same as a << b.'
- return a << b
-__lshift__ = lshift
-def lt(a, b):
- 'lt(a, b) -- Same as a<b.'
- return a < b
-__lt__ = lt
-def mod(a, b):
- 'mod(a, b) -- Same as a % b.'
- return a % b
-__mod__ = mod
-def mul(a, b):
- 'mul(a, b) -- Same as a * b.'
- return a * b
-__mul__ = mul
-def ne(a, b):
- 'ne(a, b) -- Same as a!=b.'
- return a != b
-__ne__ = ne
-def neg(obj,):
- 'neg(a) -- Same as -a.'
- return -obj
-__neg__ = neg
-def not_(obj,):
- 'not_(a) -- Same as not a.'
- return not obj
-__not__ = not_
-
-def or_(a, b):
- 'or_(a, b) -- Same as a | b.'
- return a | b
-__or__ = or_
-def pos(obj,):
- 'pos(a) -- Same as +a.'
- return +obj
-__pos__ = pos
-def pow(a, b):
- 'pow(a, b) -- Same as a**b.'
- return a ** b
-__pow__ = pow
+
def repeat(obj, num):
'repeat(a, b) -- Return a * b, where a is a sequence, and b is an integer.'
if not isinstance(num, (int, long)):
@@ -173,28 +72,17 @@
# protocol. We support any with a __mul__
__repeat__ = repeat
-def rshift(a, b):
- 'rshift(a, b) -- Same as a >> b.'
- return a >> b
-__rshift__ = rshift
def sequenceIncludes(a, b):
'sequenceIncludes(a, b) -- Same as b in a (note reversed operands; deprecated).'
for x in a:
if x == b:
return True
return False
-def setitem(obj, key, value):
- 'setitem(a, b, c) -- Same as a[b] = c.'
- obj[key] = value
-__setitem__ = setitem
+
def setslice(a, b, c, d):
'setslice(a, b, c, d) -- Same as a[b:c] = d.'
a[b:c] = d
__setslice__ = setslice
-def sub(a, b):
- 'sub(a, b) -- Same as a - b.'
- return a - b
-__sub__ = sub
exec """from __future__ import division
def truediv(a, b):
@@ -202,10 +90,3 @@
return a / b
"""
__truediv__ = truediv
-def truth(a,):
- 'truth(a) -- Return True if a is true, False otherwise.'
- return not not a
-def xor(a, b):
- 'xor(a, b) -- Same as a ^ b.'
- return a ^ b
-__xor__ = xor
Modified: pypy/branch/pypy-2.5/pypy/module/operator/interp_operator.py
==============================================================================
--- pypy/branch/pypy-2.5/pypy/module/operator/interp_operator.py (original)
+++ pypy/branch/pypy-2.5/pypy/module/operator/interp_operator.py Sun Mar 4 15:38:20 2007
@@ -1,4 +1,3 @@
-
def index(space, w_a):
return space.index(w_a)
@@ -7,3 +6,183 @@
return space.abs(w_obj)
__abs__ = abs
+
+def add(space, w_obj1, w_obj2):
+ 'add(a, b) -- Same as a a + b'
+ return space.add(w_obj1, w_obj2)
+__add__ = add
+
+def and_(space, w_obj1, w_obj2):
+ 'and_(a, b) -- Same as a a & b'
+ return space.and_(w_obj1, w_obj2)
+__and__ = and_
+
+# attrgetter
+
+def concat(space, w_obj1, w_obj2):
+ 'concat(a, b) -- Same as a a + b, for a and b sequences.'
+ return space.add(w_obj1, w_obj2) # XXX cPython only works on types with sequence api
+ # we support any with __add__
+__concat__ = concat
+
+def contains(space, w_obj1, w_obj2):
+ 'contains(a, b) -- Same as b in a (note reversed operands).'
+ return space.contains(w_obj1, w_obj2)
+__contains__ = contains
+
+# countOf
+
+def delitem(space, w_obj, w_key):
+ 'delitem(a,b) -- Same as del a[b]'
+ space.delete(w_obj, w_key)
+
+__delitem__ = delitem
+
+# delslice
+
+def div(space, w_a, w_b):
+ 'div(a, b) -- Same as a / b when __future__.division is no in effect'
+ return space.div(w_a, w_b)
+__div__ = div
+
+def eq(space, w_a, w_b):
+ 'eq(a, b) -- Same as a==b'
+ return space.eq(w_a, w_b)
+__eq__ = eq
+
+def floordiv(space, w_a, w_b):
+ 'floordiv(a, b) -- Same as a // b.'
+ return space.floordiv(w_a, w_b)
+__floordiv__ = floordiv
+
+def ge(space, w_a, w_b):
+ 'ge(a, b) -- Same as a>=b.'
+ return space.ge(w_a, w_b)
+__ge__ = ge
+
+def getitem(space, w_a, w_b):
+ 'getitem(a, b) -- Same as a[b].'
+ return space.getitem(w_a, w_b)
+__getitem__ = getitem
+
+# getslice
+
+def gt(space, w_a, w_b):
+ 'gt(a, b) -- Same as a>b.'
+ return space.gt(w_a, w_b)
+__gt__ = gt
+
+# indexOf
+
+def inv(space, w_obj,):
+ 'inv(a) -- Same as ~a.'
+ return space.invert(w_obj)
+__inv__ = inv
+
+def invert(space, w_obj,):
+ 'invert(a) -- Same as ~a.'
+ return space.invert(w_obj)
+__invert__ = invert
+
+# isCallable
+
+# isMappingType
+
+# isNumberType
+
+# isSequenceType
+
+def _is(space, w_a, w_b):
+ 'is_(a,b) -- Same as a is b'
+ return space.is_(w_a, w_b)
+
+def is_not(space, w_a, w_b):
+ 'is_not(a, b) -- Same as a is not b'
+ return space.not_(space.is_(w_a, w_b))
+
+# itemgetter
+
+def le(space, w_a, w_b):
+ 'le(a, b) -- Same as a<=b.'
+ return space.le(w_a, w_b)
+__le__ = le
+
+def lshift(space, w_a, w_b):
+ 'lshift(a, b) -- Same as a << b.'
+ return space.lshift(w_a, w_b)
+__lshift__ = lshift
+
+def lt(space, w_a, w_b):
+ 'lt(a, b) -- Same as a<b.'
+ return space.lt(w_a, w_b)
+__lt__ = lt
+
+def mod(space, w_a, w_b):
+ 'mod(a, b) -- Same as a % b.'
+ return space.mod(w_a, w_b)
+__mod__ = mod
+
+def mul(space, w_a, w_b):
+ 'mul(a, b) -- Same as a * b.'
+ return space.mul(w_a, w_b)
+__mul__ = mul
+
+def ne(space, w_a, w_b):
+ 'ne(a, b) -- Same as a!=b.'
+ return space.ne(w_a, w_b)
+__ne__ = ne
+
+def neg(space, w_obj,):
+ 'neg(a) -- Same as -a.'
+ return space.neg(w_obj)
+__neg__ = neg
+
+def not_(space, w_obj,):
+ 'not_(a) -- Same as not a.'
+ return space.not_(w_obj)
+__not__ = not_
+
+def or_(space, w_a, w_b):
+ 'or_(a, b) -- Same as a | b.'
+ return space.or_(w_a, w_b)
+__or__ = or_
+
+def pos(space, w_obj,):
+ 'pos(a) -- Same as +a.'
+ return space.pos(w_obj)
+__pos__ = pos
+
+def pow(space, w_a, w_b):
+ 'pow(a, b) -- Same as a**b.'
+ return space.pow(w_a, w_b)
+__pow__ = pow
+
+# reapeat
+
+def rshift(space, w_a, w_b):
+ 'rshift(a, b) -- Same as a >> b.'
+ return space.rshift(w_a, w_b)
+__rshift__ = rshift
+
+# sequenceIncludes
+
+def setitem(space, w_obj, w_key, w_value):
+ 'setitem(a, b, c) -- Same as a[b] = c.'
+ space.setitem(w_obj, w_key, w_value)
+__setitem__ = setitem
+
+# setslice
+
+def sub(space, w_a, w_b):
+ 'sub(a, b) -- Same as a - b.'
+ return space.sub(w_a, w_b)
+__sub__ = sub
+
+def truth(space, w_a,):
+ 'truth(a) -- Return True if a is true, False otherwise.'
+ return space.is_true(w_a)
+
+def xor(space, w_a, w_b):
+ 'xor(a, b) -- Same as a ^ b.'
+ return space.xor(w_a, w_b)
+__xor__ = xor
More information about the Pypy-commit
mailing list