[pypy-svn] r28096 - in pypy/dist/pypy: rpython rpython/lltypesystem translator/stackless/test

mwh at codespeak.net mwh at codespeak.net
Fri Jun 2 15:05:29 CEST 2006


Author: mwh
Date: Fri Jun  2 15:05:28 2006
New Revision: 28096

Added:
   pypy/dist/pypy/translator/stackless/test/test_resume_point.py
      - copied, changed from r28094, pypy/branch/explicit_resume_pt_experiment/translator/stackless/test/test_resume_point.py
Modified:
   pypy/dist/pypy/rpython/llinterp.py
   pypy/dist/pypy/rpython/lltypesystem/lloperation.py
   pypy/dist/pypy/rpython/rstack.py
Log:
(pedronis, mwh)
begin reimplementing the stuff from samuele's explicit_resume_pt_experiment
branch in a less experimental way :)
only annotation/rtyping stuff so far, no actual implementation


Modified: pypy/dist/pypy/rpython/llinterp.py
==============================================================================
--- pypy/dist/pypy/rpython/llinterp.py	(original)
+++ pypy/dist/pypy/rpython/llinterp.py	Fri Jun  2 15:05:28 2006
@@ -428,6 +428,9 @@
     def op_hint(self, x, hints):
         return x
 
+    def op_resume_point(self, *args):
+        pass
+
     def op_decode_arg(self, fname, i, name, vargs, vkwds):
         raise NotImplementedError("decode_arg")
 

Modified: pypy/dist/pypy/rpython/lltypesystem/lloperation.py
==============================================================================
--- pypy/dist/pypy/rpython/lltypesystem/lloperation.py	(original)
+++ pypy/dist/pypy/rpython/lltypesystem/lloperation.py	Fri Jun  2 15:05:28 2006
@@ -343,6 +343,10 @@
     'yield_current_frame_to_caller': LLOp(canraise=(StackException,)),
     #                               can always unwind, not just if stackless gc
 
+    'resume_point':  LLOp(),
+    'resume_state_create':  LLOp(canraise=(MemoryError,), canunwindgc=True),
+    'resume_state_invoke':  LLOp(canraise=(Exception, StackException)),
+
     # __________ misc operations __________
 
     'keepalive':            LLOp(),

Modified: pypy/dist/pypy/rpython/rstack.py
==============================================================================
--- pypy/dist/pypy/rpython/rstack.py	(original)
+++ pypy/dist/pypy/rpython/rstack.py	Fri Jun  2 15:05:28 2006
@@ -32,3 +32,102 @@
 class frame_stack_top(object):
     def switch(self):
         raise NotImplementedError("only works in translated versions")
+
+
+from pypy.rpython.extregistry import ExtRegistryEntry
+
+def resume_point(label, *args, **kwds):
+    pass
+
+class ResumePointFnEntry(ExtRegistryEntry):
+    _about_ = resume_point
+
+    def compute_result_annotation(self, s_label, *args_s, **kwds_s):
+        from pypy.annotation import model as annmodel
+        return annmodel.s_None
+
+    def specialize_call(self, hop, **kwds_i):
+        from pypy.rpython.lltypesystem import lltype
+
+        assert hop.args_s[0].is_constant()
+        c_label = hop.inputconst(lltype.Void, hop.args_s[0].const)
+        args_v = hop.args_v[1:]
+        if 'i_returns' in kwds_i:
+            assert len(kwds_i) == 1
+            returns_index = kwds_i['i_returns']
+            v_return = args_v.pop(returns_index-1)
+        else:
+            assert not kwds_i
+            v_return = hop.inputconst(lltype.Void, None)
+
+        hop.exception_is_here()
+        return hop.genop('resume_point', [c_label, v_return] + args_v,
+                         hop.r_result)
+
+class ResumeState(object):
+    pass
+
+def resume_state_create(prevstate, label, *args):
+    raise RuntimeError("cannot resume states in non-translated versions")
+
+class ResumeStateCreateFnEntry(ExtRegistryEntry):
+    _about_ = resume_state_create
+
+    def compute_result_annotation(self, s_prevstate, s_label, *args_s):
+        from pypy.annotation import model as annmodel
+        return annmodel.SomeExternalObject(ResumeState)
+
+    def specialize_call(self, hop):
+        from pypy.rpython.lltypesystem import lltype
+        from pypy.rpython.rmodel import SimplePointerRepr
+        from pypy.translator.stackless.frame import STATE_HEADER
+
+        assert hop.args_s[1].is_constant()
+        c_label = hop.inputconst(lltype.Void, hop.args_s[1].const)
+
+        r =  SimplePointerRepr(lltype.Ptr(STATE_HEADER))
+        state_v = hop.inputarg(r, arg=0)
+        
+        args_v = hop.args_v[2:]
+
+        hop.exception_is_here()
+        return hop.genop('resume_state_create', [c_label] + args_v,
+                         hop.r_result)
+
+class ResumeStateEntry(ExtRegistryEntry):
+    _type_ = ResumeState
+
+    def get_repr(self, rtyper, s_state):
+        from pypy.rpython.rmodel import SimplePointerRepr
+        from pypy.translator.stackless.frame import STATE_HEADER
+        from pypy.rpython.lltypesystem import lltype
+        return SimplePointerRepr(lltype.Ptr(STATE_HEADER))
+
+def resume_state_invoke(type, state, **kwds):
+    raise NotImplementedError("only works in translated versions")
+
+class ResumeStateInvokeFnEntry(ExtRegistryEntry):
+    _about_ = resume_state_invoke
+
+    def compute_result_annotation(self, s_type, s_state, **kwds):
+        from pypy.annotation.bookkeeper import getbookkeeper
+        assert s_type.is_constant()
+        return getbookkeeper().valueoftype(s_type.const)
+
+    def specialize_call(self, hop, **kwds_i):
+        from pypy.rpython.lltypesystem import lltype
+        v_state = hop.args_v[0]
+        
+        if 'i_returns' in kwds_i:
+            assert len(kwds_i) == 1
+            returns_index = kwds_i['i_returns']
+            v_return = args_v.pop(returns_index-1)
+        else:
+            assert not kwds_i
+            v_return = hop.inputconst(lltype.Void, None)
+
+        hop.exception_is_here()
+        return hop.genop('resume_state_invoke', [v_state, v_return],
+                         hop.r_result)
+        
+        



More information about the Pypy-commit mailing list