Author: Alex Gaynor <[email protected]>
Branch: python-loop-unroll
Changeset: r64648:978ab2b048ae
Date: 2013-05-28 15:16 -0700
http://bitbucket.org/pypy/pypy/changeset/978ab2b048ae/
Log: Expose a class whose job is to explicitly indicate that a loop
should be unrolled.
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
@@ -3,6 +3,7 @@
from pypy.interpreter.mixedmodule import MixedModule
from pypy.module.imp.importing import get_pyc_magic
+
class BuildersModule(MixedModule):
appleveldefs = {}
@@ -11,6 +12,7 @@
"UnicodeBuilder": "interp_builders.W_UnicodeBuilder",
}
+
class TimeModule(MixedModule):
appleveldefs = {}
interpleveldefs = {}
@@ -41,23 +43,30 @@
}
interpleveldefs = {
- 'internal_repr' : 'interp_magic.internal_repr',
- 'bytebuffer' : 'bytebuffer.bytebuffer',
- 'identity_dict' : 'interp_identitydict.W_IdentityDict',
- 'debug_start' : 'interp_debug.debug_start',
- 'debug_print' : 'interp_debug.debug_print',
- 'debug_stop' : 'interp_debug.debug_stop',
- 'debug_print_once' : 'interp_debug.debug_print_once',
- 'builtinify' : 'interp_magic.builtinify',
- 'lookup_special' : 'interp_magic.lookup_special',
- 'do_what_I_mean' : 'interp_magic.do_what_I_mean',
- 'list_strategy' : 'interp_magic.list_strategy',
- 'validate_fd' : 'interp_magic.validate_fd',
- 'resizelist_hint' : 'interp_magic.resizelist_hint',
- 'newlist_hint' : 'interp_magic.newlist_hint',
- 'add_memory_pressure' : 'interp_magic.add_memory_pressure',
- 'newdict' : 'interp_dict.newdict',
- 'dictstrategy' : 'interp_dict.dictstrategy',
+ 'lookup_special': 'interp_magic.lookup_special',
+ 'builtinify': 'interp_magic.builtinify',
+ 'internal_repr': 'interp_magic.internal_repr',
+
+ 'bytebuffer': 'bytebuffer.bytebuffer',
+ 'identity_dict': 'interp_identitydict.W_IdentityDict',
+
+ 'debug_start': 'interp_debug.debug_start',
+ 'debug_print': 'interp_debug.debug_print',
+ 'debug_stop': 'interp_debug.debug_stop',
+ 'debug_print_once': 'interp_debug.debug_print_once',
+
+ 'add_memory_pressure': 'interp_magic.add_memory_pressure',
+ 'validate_fd': 'interp_magic.validate_fd',
+
+ 'newlist_hint': 'interp_magic.newlist_hint',
+ 'resizelist_hint': 'interp_magic.resizelist_hint',
+ 'list_strategy': 'interp_magic.list_strategy',
+ 'newdict': 'interp_dict.newdict',
+ 'dictstrategy': 'interp_dict.dictstrategy',
+
+ 'unroll_loop': 'interp_unroll.W_LoopUnroller',
+
+ 'do_what_I_mean': 'interp_magic.do_what_I_mean',
}
if sys.platform == 'win32':
interpleveldefs['get_console_cp'] = 'interp_magic.get_console_cp'
diff --git a/pypy/module/__pypy__/interp_unroll.py
b/pypy/module/__pypy__/interp_unroll.py
new file mode 100644
--- /dev/null
+++ b/pypy/module/__pypy__/interp_unroll.py
@@ -0,0 +1,24 @@
+from pypy.interpreter.baseobjspace import W_Root
+from pypy.interpreter.gateway import interp2app
+from pypy.interpreter.typedef import TypeDef
+
+
+class W_LoopUnroller(W_Root):
+ def __init__(self, w_obj):
+ self.w_obj = w_obj
+
+ def descr__new__(space, w_subtype, w_obj):
+ return W_LoopUnroller(w_obj)
+
+ def descr__repr__(self, space):
+ return space.wrap("LoopUnroller(%s)" %
space.str_w(space.repr(self.w_obj)))
+
+ def descr__iter__(self, space):
+ return space.iter(self.w_obj)
+
+
+W_LoopUnroller.typedef = TypeDef("LoopUnroller",
+ __new__=interp2app(W_LoopUnroller.descr__new__.im_func),
+ __repr__=interp2app(W_LoopUnroller.descr__repr__),
+ __iter__=interp2app(W_LoopUnroller.descr__iter__),
+)
diff --git a/pypy/module/__pypy__/test/test_unroller.py
b/pypy/module/__pypy__/test/test_unroller.py
new file mode 100644
--- /dev/null
+++ b/pypy/module/__pypy__/test/test_unroller.py
@@ -0,0 +1,15 @@
+class AppTestUnroller(object):
+ spaceconfig = {"usemodules": ["__pypy__"]}
+
+ def test_iter(self):
+ from __pypy__ import unroll_loop
+
+ res = []
+ for i in unroll_loop(xrange(3)):
+ res.append(i)
+ assert res == [0, 1, 2]
+
+ def test_repr(self):
+ from __pypy__ import unroll_loop
+
+ assert repr(unroll_loop([1, 2, 3])) == "LoopUnroller(%r)" % [1, 2, 3]
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit