[pypy-svn] r51961 - in pypy/dist/pypy: jit/codegen/llgraph jit/timeshifter jit/timeshifter/test rpython

antocuni at codespeak.net antocuni at codespeak.net
Fri Feb 29 17:52:48 CET 2008


Author: antocuni
Date: Fri Feb 29 17:52:46 2008
New Revision: 51961

Modified:
   pypy/dist/pypy/jit/codegen/llgraph/llimpl.py
   pypy/dist/pypy/jit/timeshifter/hrtyper.py
   pypy/dist/pypy/jit/timeshifter/test/test_timeshift.py
   pypy/dist/pypy/rpython/typesystem.py
Log:
move a bit more the rtyper towards ootype by using staticmethods instead of function pointers



Modified: pypy/dist/pypy/jit/codegen/llgraph/llimpl.py
==============================================================================
--- pypy/dist/pypy/jit/codegen/llgraph/llimpl.py	(original)
+++ pypy/dist/pypy/jit/codegen/llgraph/llimpl.py	Fri Feb 29 17:52:46 2008
@@ -14,6 +14,7 @@
 from pypy.rpython.llinterp import LLInterpreter
 from pypy.rpython.rclass import fishllattr
 from pypy.rpython.lltypesystem.lloperation import llop
+from pypy.translator.simplify import get_funcobj
 
 def _from_opaque(opq):
     return opq._obj.externalobj
@@ -43,6 +44,13 @@
     else:
         return LLSupport.from_rstr(s)
 
+def functionptr_general(TYPE, name, **attrs):
+    if isinstance(TYPE, lltype.FuncType):
+        return functionptr(TYPE, name, **attrs)
+    else:
+        assert isinstance(TYPE, ootype.StaticMethod)
+        return ootype.static_meth(TYPE, name, **attrs)
+
 def newgraph(gv_FUNCTYPE, name):
     FUNCTYPE = _from_opaque(gv_FUNCTYPE).value
     # 'name' is just a way to track things
@@ -74,12 +82,12 @@
     casting_link(graph.prereturnblock, [v1], graph.returnblock)
     substartblock = flowmodel.Block(erasedinputargs)
     casting_link(graph.startblock, inputargs, substartblock)
-    fptr = lltype.functionptr(FUNCTYPE, name,
-                              graph=graph)
+    fptr = functionptr_general(FUNCTYPE, name,
+                               graph=graph)
     return genconst(fptr)
 
 def _getgraph(gv_func):
-     graph = _from_opaque(gv_func).value._obj.graph
+     graph = get_funcobj(_from_opaque(gv_func).value).graph
      return graph
 
 def end(gv_func):

Modified: pypy/dist/pypy/jit/timeshifter/hrtyper.py
==============================================================================
--- pypy/dist/pypy/jit/timeshifter/hrtyper.py	(original)
+++ pypy/dist/pypy/jit/timeshifter/hrtyper.py	Fri Feb 29 17:52:46 2008
@@ -469,7 +469,7 @@
         ARGS = []
         for r_arg in args_r:
             ARGS += r_arg.residual_argtypes()
-        return lltype.FuncType(ARGS, RESTYPE)
+        return self.rtyper.type_system.getcallabletype(ARGS, RESTYPE)
 
     def make_new_lloplist(self, block):
         return HintLowLevelOpList(self)

Modified: pypy/dist/pypy/jit/timeshifter/test/test_timeshift.py
==============================================================================
--- pypy/dist/pypy/jit/timeshifter/test/test_timeshift.py	(original)
+++ pypy/dist/pypy/jit/timeshifter/test/test_timeshift.py	Fri Feb 29 17:52:46 2008
@@ -22,6 +22,7 @@
 from pypy import conftest
 from pypy.jit.conftest import Benchmark
 from pypy.jit.codegen.llgraph.rgenop import RGenOp as LLRGenOp
+from pypy.translator.simplify import get_funcobj
 
 P_NOVIRTUAL = HintAnnotatorPolicy(novirtualcontainer=True)
 
@@ -180,6 +181,7 @@
             + timeshifted_entrypoint_args_s,
             hrtyper.s_JITState)
         FUNC = hrtyper.get_residual_functype(ha.translator.graphs[0])
+        PFUNC = self.Ptr(FUNC)
         argcolors = unrolling_iterable(argcolors)
         self.argcolors = argcolors
 
@@ -220,12 +222,11 @@
                 finish_jitstate(top_jitstate, exceptiondesc, sigtoken)
 
             builder.end()
-            generated = gv_generated.revealconst(lltype.Ptr(FUNC))
+            generated = gv_generated.revealconst(PFUNC)
             return generated
 
         ml_generate_code.args_s = ["XXX rgenop"] + generate_code_args_s
-        ml_generate_code.s_result = annmodel.lltype_to_annotation(
-            lltype.Ptr(FUNC))
+        ml_generate_code.s_result = annmodel.lltype_to_annotation(PFUNC)
 
 ##        def ml_extract_residual_args(*args):
 ##            result = ()
@@ -305,7 +306,7 @@
         ll_generated = llinterp.eval_graph(self.maingraph, mainargs)
 
         # now try to run the residual graph generated by the builder
-        residual_graph = ll_generated._obj.graph
+        residual_graph = get_funcobj(ll_generated).graph
         self.ll_generated = ll_generated
         self.residual_graph = residual_graph
         if conftest.option.view:
@@ -1795,6 +1796,9 @@
 class TestLLType(BaseTestTimeshift):
     type_system = 'lltype'
 
+    def Ptr(self, T):
+        return lltype.Ptr(T)
+
 passing_ootype_tests = set([
     'test_very_simple',
     'test_convert_const_to_redbox',
@@ -1813,6 +1817,9 @@
 class TestOOType(BaseTestTimeshift):
     type_system = 'ootype'
 
+    def Ptr(self, T):
+        return T
+
     def __getattribute__(self, name):
         if name.startswith('test_') and name not in passing_ootype_tests:
             def fn():

Modified: pypy/dist/pypy/rpython/typesystem.py
==============================================================================
--- pypy/dist/pypy/rpython/typesystem.py	(original)
+++ pypy/dist/pypy/rpython/typesystem.py	Fri Feb 29 17:52:46 2008
@@ -45,6 +45,10 @@
     def null_callable(self, T):
         """null callable object of type T"""
         raise NotImplementedError()
+
+    def getcallabletype(self, ARGS, RESTYPE):
+        cls = self.callable_trait[0]
+        return cls(ARGS, RESTYPE)
         
     def getcallable(self, graph, getconcretetype=None):
         """Return callable given a Python function."""



More information about the Pypy-commit mailing list