[pypy-svn] r26896 - in pypy/dist/pypy: rpython translator/stackless

arigo at codespeak.net arigo at codespeak.net
Sat May 6 21:23:53 CEST 2006


Author: arigo
Date: Sat May  6 21:23:51 2006
New Revision: 26896

Modified:
   pypy/dist/pypy/rpython/annlowlevel.py
   pypy/dist/pypy/translator/stackless/transform.py
Log:
(pedronis, arigo)
Delayed Pointer Technology.


Modified: pypy/dist/pypy/rpython/annlowlevel.py
==============================================================================
--- pypy/dist/pypy/rpython/annlowlevel.py	(original)
+++ pypy/dist/pypy/rpython/annlowlevel.py	Sat May  6 21:23:51 2006
@@ -8,6 +8,7 @@
 from pypy.annotation.policy import AnnotatorPolicy
 from pypy.rpython.lltypesystem import lltype
 from pypy.rpython import extfunctable
+from pypy.objspace.flow.model import Constant
 
 def not_const(s_obj): # xxx move it somewhere else
     if s_obj.is_constant():
@@ -117,7 +118,8 @@
         self.policy = MixLevelAnnotatorPolicy(rtyper)
         self.pending = []     # list of (graph, args_s, s_result)
         self.delayedreprs = []
-        self.delayedconsts = [] 
+        self.delayedconsts = []
+        self.delayedfuncs = []
 
     def getgraph(self, ll_function, args_s, s_result):
         # get the graph of the mix-level helper ll_function and prepare it for
@@ -132,6 +134,19 @@
         self.pending.append((graph, args_s, s_result))
         return graph
 
+    def delayedfunction(self, ll_function, args_s, s_result):
+        # get a delayed pointer to the low-level function, annotated as
+        # specified.  The pointer is only valid after finish() was called.
+        graph = self.getgraph(ll_function, args_s, s_result)
+        FUNCTYPE = lltype.ForwardReference()
+        delayedptr = lltype._ptr(lltype.Ptr(FUNCTYPE), "delayed!", solid=True)
+        self.delayedfuncs.append((delayedptr, graph))
+        return delayedptr
+
+    def constfunc(self, ll_function, args_s, s_result):
+        p = self.delayedfunction(ll_function, args_s, s_result)
+        return Constant(p, lltype.typeOf(p))
+
     def getdelayedrepr(self, s_value):
         """Like rtyper.getrepr(), but the resulting repr will not be setup() at
         all before finish() is called.
@@ -180,6 +195,10 @@
             r.set_setup_delayed(False)
         for p, repr, obj in self.delayedconsts:
             p._become(repr.convert_const(obj))
+        for p, graph in self.delayedfuncs:
+            real_p = rtyper.getcallable(graph)
+            lltype.typeOf(p).TO.become(lltype.typeOf(real_p).TO)
+            p._become(real_p)
         rtyper.specialize_more_blocks()
         del self.pending[:]
         del self.delayedreprs[:]

Modified: pypy/dist/pypy/translator/stackless/transform.py
==============================================================================
--- pypy/dist/pypy/translator/stackless/transform.py	(original)
+++ pypy/dist/pypy/translator/stackless/transform.py	Sat May  6 21:23:51 2006
@@ -8,7 +8,6 @@
 from pypy.rpython.annlowlevel import MixLevelHelperAnnotator
 from pypy.translator.stackless import code 
 from pypy.rpython.rclass import getinstancerepr
-from pypy.rpython.typesystem import getfunctionptr
 from pypy.rpython.rbuiltin import gen_cast
 from pypy.rpython.rtyper import LowLevelOpList
 
@@ -98,44 +97,28 @@
         l2a = annmodel.lltype_to_annotation
 
         unwinddef = bk.getuniqueclassdef(code.UnwindException)
-        add_frame_state_graph = mixlevelannotator.getgraph(
+        self.add_frame_state_ptr = mixlevelannotator.constfunc(
             code.add_frame_state,
             [annmodel.SomeInstance(unwinddef),
              annmodel.SomePtr(lltype.Ptr(STATE_HEADER))],
             l2a(lltype.Void))
 
-        resume_state_graph = mixlevelannotator.getgraph(
+        self.resume_state_ptr = mixlevelannotator.constfunc(
             code.resume_state, [], annmodel.SomeInteger())
 
-        fetch_retval_void_graph = mixlevelannotator.getgraph(
+        self.fetch_retval_void_ptr = mixlevelannotator.constfunc(
             code.fetch_retval_void, [], annmodel.s_None)
-        fetch_retval_long_graph = mixlevelannotator.getgraph(
+        self.fetch_retval_long_ptr = mixlevelannotator.constfunc(
             code.fetch_retval_long, [], annmodel.SomeInteger())
-        fetch_retval_longlong_graph = mixlevelannotator.getgraph( # WAA!
+        self.fetch_retval_longlong_ptr = mixlevelannotator.constfunc(
             code.fetch_retval_longlong, [], annmodel.SomeInteger(size=2))
-        fetch_retval_float_graph = mixlevelannotator.getgraph(
+        self.fetch_retval_float_ptr = mixlevelannotator.constfunc(
             code.fetch_retval_float, [], annmodel.SomeFloat())
-        fetch_retval_void_p_graph = mixlevelannotator.getgraph(
+        self.fetch_retval_void_p_ptr = mixlevelannotator.constfunc(
             code.fetch_retval_void_p, [], annmodel.SomeAddress())
 
         mixlevelannotator.finish()
 
-        def fptr(graph):
-            FTYPE = lltype.FuncType(
-                [v.concretetype for v in graph.startblock.inputargs],
-                graph.returnblock.inputargs[0].concretetype)
-            return model.Constant(getfunctionptr(graph), lltype.Ptr(FTYPE))
-
-        self.add_frame_state_ptr = fptr(add_frame_state_graph)
-
-        self.resume_state_ptr = fptr(resume_state_graph)
-
-        self.fetch_retval_void_ptr = fptr(fetch_retval_void_graph)
-        self.fetch_retval_long_ptr = fptr(fetch_retval_long_graph)
-        self.fetch_retval_longlong_ptr = fptr(fetch_retval_longlong_graph)
-        self.fetch_retval_float_ptr = fptr(fetch_retval_float_graph)
-        self.fetch_retval_void_p_ptr = fptr(fetch_retval_void_p_graph)
-
         s_global_state = bk.immutablevalue(code.global_state)
         r_global_state = translator.rtyper.getrepr(s_global_state)
         self.ll_global_state = model.Constant(



More information about the Pypy-commit mailing list