[pypy-svn] r12848 - pypy/dist/pypy/rpython
arigo at codespeak.net
arigo at codespeak.net
Fri May 27 17:38:09 CEST 2005
Author: arigo
Date: Fri May 27 17:38:09 2005
New Revision: 12848
Modified:
pypy/dist/pypy/rpython/rpbc.py
pypy/dist/pypy/rpython/rtyper.py
Log:
Refactor: rtyper.getfunctionptr() returns a low-level
function pointer, typed as found by the annotator,
from a Python function object.
Modified: pypy/dist/pypy/rpython/rpbc.py
==============================================================================
--- pypy/dist/pypy/rpython/rpbc.py (original)
+++ pypy/dist/pypy/rpython/rpbc.py Fri May 27 17:38:09 2005
@@ -1,7 +1,7 @@
import types
from pypy.annotation.pairtype import pair, pairtype
from pypy.annotation.model import SomePBC
-from pypy.rpython.lltype import Void, FuncType, functionptr, NonGcPtr
+from pypy.rpython.lltype import typeOf
from pypy.rpython.rtyper import TLS, receive, receiveconst, direct_op
from pypy.rpython.rtyper import peek_at_result_annotation
@@ -23,16 +23,10 @@
if not isinstance(func, types.FunctionType):
NotImplementedYet
# XXX hackish
- a = TLS.rtyper.annotator
- graph = a.translator.getflowgraph(func)
- llinputs = [a.binding(v).lowleveltype() for v in graph.getargs()]
- s_output = a.binding(graph.getreturnvar(), None)
- if s_output is None:
- lloutput = Void
- else:
- lloutput = s_output.lowleveltype()
- FT = FuncType(llinputs, lloutput)
- f = functionptr(FT, func.func_name, graph = graph, _callable = func)
- args_v = [receive(llinputs[i], arg=i+1) for i in range(len(args_s))]
- c = receiveconst(NonGcPtr(FT), f)
- return direct_op('direct_call', [c] + args_v, resulttype=lloutput)
+ f = TLS.rtyper.getfunctionptr(func)
+ FUNCPTR = typeOf(f)
+ args_v = [receive(FUNCPTR.TO.ARGS[i], arg=i+1)
+ for i in range(len(args_s))]
+ c = receiveconst(FUNCPTR, f)
+ return direct_op('direct_call', [c] + args_v,
+ resulttype = FUNCPTR.TO.RESULT)
Modified: pypy/dist/pypy/rpython/rtyper.py
==============================================================================
--- pypy/dist/pypy/rpython/rtyper.py (original)
+++ pypy/dist/pypy/rpython/rtyper.py Fri May 27 17:38:09 2005
@@ -3,7 +3,7 @@
from pypy.objspace.flow.model import Variable, Constant, Block, Link
from pypy.objspace.flow.model import SpaceOperation
from pypy.rpython.lltype import Void, LowLevelType, NonGcPtr, ContainerType
-from pypy.rpython.lltype import FuncType, functionptr
+from pypy.rpython.lltype import FuncType, functionptr, typeOf
from pypy.tool.tls import tlsobject
from pypy.tool.sourcetools import func_with_new_name, valid_identifier
from pypy.translator.unsimplify import insert_empty_block
@@ -193,6 +193,20 @@
def consider_op_newlist(self, *items_s):
return rlist.rtype_newlist(*items_s)
+ # __________ utilities __________
+
+ def getfunctionptr(self, func):
+ """Make a functionptr from the given Python function."""
+ a = self.annotator
+ graph = a.translator.getflowgraph(func)
+ llinputs = [a.binding(v).lowleveltype() for v in graph.getargs()]
+ s_output = a.binding(graph.getreturnvar(), None)
+ if s_output is None:
+ lloutput = Void
+ else:
+ lloutput = s_output.lowleveltype()
+ FT = FuncType(llinputs, lloutput)
+ return functionptr(FT, func.func_name, graph = graph, _callable = func)
# ____________________________________________________________
#
@@ -275,27 +289,21 @@
spec_name.append(valid_identifier(getattr(key, '__name__', key))+suffix)
spec_key = tuple(spec_key)
try:
- spec_function, spec_graph, resulttype = (
- TLS.rtyper.specialized_ll_functions[spec_key])
+ spec_function = TLS.rtyper.specialized_ll_functions[spec_key]
except KeyError:
name = '_'.join(spec_name)
spec_function = func_with_new_name(ll_function, name)
# flow and annotate (the copy of) the low-level function
spec_graph = annotator.translator.getflowgraph(spec_function)
- s_returnvalue = annotator.build_types(spec_function, args_s)
- resulttype = annmodel.annotation_to_lltype(s_returnvalue,
- "%s: " % ll_function.func_name)
+ annotator.build_types(spec_function, args_s)
# cache the result
- TLS.rtyper.specialized_ll_functions[spec_key] = (
- spec_function, spec_graph, resulttype)
+ TLS.rtyper.specialized_ll_functions[spec_key] = spec_function
# build the 'direct_call' operation
- lltypes = [v.concretetype for v in args_v]
- FT = FuncType(lltypes, resulttype)
- f = functionptr(FT, ll_function.func_name, graph = spec_graph,
- _callable = spec_function)
- c = receiveconst(NonGcPtr(FT), f)
- return direct_op('direct_call', [c]+list(args_v), resulttype=resulttype)
+ f = TLS.rtyper.getfunctionptr(spec_function)
+ c = receiveconst(typeOf(f), f)
+ return direct_op('direct_call', [c]+list(args_v),
+ resulttype = typeOf(f).TO.RESULT)
def direct_op(opname, args, resulttype=None):
More information about the Pypy-commit
mailing list