[pypy-commit] pypy default: Might go away again, but: attempting to give app-level code direct
arigo
noreply at buildbot.pypy.org
Wed Jul 17 13:51:07 CEST 2013
Author: Armin Rigo <arigo at tunes.org>
Branch:
Changeset: r65425:b91fe2eeb20d
Date: 2013-07-17 12:19 +0200
http://bitbucket.org/pypy/pypy/changeset/b91fe2eeb20d/
Log: Might go away again, but: attempting to give app-level code direct
access to the wrap-around C-ish versions of some arithmetic
operations.
diff --git a/pypy/module/__pypy__/__init__.py b/pypy/module/__pypy__/__init__.py
--- a/pypy/module/__pypy__/__init__.py
+++ b/pypy/module/__pypy__/__init__.py
@@ -36,6 +36,20 @@
}
+class IntOpModule(MixedModule):
+ appleveldefs = {}
+ interpleveldefs = {
+ 'int_add': 'interp_intop.int_add',
+ 'int_sub': 'interp_intop.int_sub',
+ 'int_mul': 'interp_intop.int_mul',
+ 'int_floordiv': 'interp_intop.int_floordiv',
+ 'uint_floordiv': 'interp_intop.uint_floordiv',
+ 'int_mod': 'interp_intop.int_mod',
+ 'int_lshift': 'interp_intop.int_lshift',
+ 'uint_rshift': 'interp_intop.uint_rshift',
+ }
+
+
class Module(MixedModule):
appleveldefs = {
}
@@ -67,6 +81,7 @@
"builders": BuildersModule,
"time": TimeModule,
"thread": ThreadModule,
+ "intop": IntOpModule,
}
def setup_after_space_initialization(self):
diff --git a/pypy/module/__pypy__/interp_intop.py b/pypy/module/__pypy__/interp_intop.py
new file mode 100644
--- /dev/null
+++ b/pypy/module/__pypy__/interp_intop.py
@@ -0,0 +1,7 @@
+from pypy.interpreter.gateway import unwrap_spec
+from rpython.rlib.rarithmetic import intmask
+
+
+ at unwrap_spec(n=int, m=int)
+def int_add(space, n, m):
+ return space.wrap(intmask(n + m))
diff --git a/pypy/module/__pypy__/test/test_intop.py b/pypy/module/__pypy__/test/test_intop.py
new file mode 100644
--- /dev/null
+++ b/pypy/module/__pypy__/test/test_intop.py
@@ -0,0 +1,11 @@
+
+
+class AppTestIntOp:
+ spaceconfig = dict(usemodules=['__pypy__'])
+
+ def test_int_add(self):
+ import sys
+ from __pypy__ import intop
+ assert intop.int_add(40, 2) == 42
+ assert intop.int_add(sys.maxint, 1) == -sys.maxint-1
+ assert intop.int_add(-2, -sys.maxint) == sys.maxint
More information about the pypy-commit
mailing list