[pypy-commit] lang-smalltalk default: (lwassermann, timfel) refactor expose_primitive, split it into an

timfel noreply at buildbot.pypy.org
Tue Apr 23 18:14:18 CEST 2013


Author: Tim Felgentreff <timfelgentreff at gmail.com>
Branch: 
Changeset: r321:7a5037c77a3d
Date: 2013-04-23 16:14 +0200
http://bitbucket.org/pypy/lang-smalltalk/changeset/7a5037c77a3d/

Log:	(lwassermann, timfel) refactor expose_primitive, split it into an
	unwrapping+stack-mgmt decorator and a decorator that adds the func
	to the prim table (so we can re-use the former to implement plugin
	prims)

diff --git a/spyvm/primitives.py b/spyvm/primitives.py
--- a/spyvm/primitives.py
+++ b/spyvm/primitives.py
@@ -52,8 +52,6 @@
 
 def expose_primitive(code, unwrap_spec=None, no_result=False,
                     result_is_new_frame=False, clean_stack=True, compiled_method=False):
-    # some serious magic, don't look
-    from rpython.rlib.unroll import unrolling_iterable
     # heuristics to give it a nice name
     name = None
     for key, value in globals().iteritems():
@@ -64,13 +62,33 @@
             else:
                 name = key
 
+    def decorator(func):
+        assert code not in prim_table
+        func.func_name = "prim_" + name
+
+        wrapped = wrap_primitive(
+            unwrap_spec=unwrap_spec, no_result=no_result,
+            result_is_new_frame=result_is_new_frame,
+            clean_stack=clean_stack, compiled_method=compiled_method
+        )(func)
+        wrapped.func_name = "wrap_prim_" + name
+        prim_table[code] = wrapped
+        prim_table_implemented_only.append((code, wrapped))
+        return func
+    return decorator
+
+
+def wrap_primitive(unwrap_spec=None, no_result=False,
+                   result_is_new_frame=False, clean_stack=True,
+                   compiled_method=False):
+    # some serious magic, don't look
+    from rpython.rlib.unroll import unrolling_iterable
+
     assert not (no_result and result_is_new_frame)
     # Because methods always have a receiver, an unwrap_spec of [] is a bug
     assert unwrap_spec is None or unwrap_spec
 
     def decorator(func):
-        assert code not in prim_table
-        func.func_name = "prim_" + name
         if unwrap_spec is None:
             def wrapped(interp, s_frame, argument_count_m1, s_method=None):
                 if compiled_method:
@@ -138,10 +156,7 @@
                         assert w_result is not None
                         assert isinstance(w_result, model.W_Object)
                         s_frame.push(w_result)
-        wrapped.func_name = "wrap_prim_" + name
-        prim_table[code] = wrapped
-        prim_table_implemented_only.append((code, wrapped))
-        return func
+        return wrapped
     return decorator
 
 # ___________________________________________________________________________


More information about the pypy-commit mailing list