[pypy-svn] r13196 - pypy/dist/pypy/rpython
arigo at codespeak.net
arigo at codespeak.net
Wed Jun 8 19:47:19 CEST 2005
Author: arigo
Date: Wed Jun 8 19:47:19 2005
New Revision: 13196
Modified:
pypy/dist/pypy/rpython/rmodel.py
pypy/dist/pypy/rpython/robject.py
pypy/dist/pypy/rpython/rtyper.py
Log:
Small reorganizations needed by an ongoing far-fetched attempt of having
translator.ccompile() use the new C compiler.
Modified: pypy/dist/pypy/rpython/rmodel.py
==============================================================================
--- pypy/dist/pypy/rpython/rmodel.py (original)
+++ pypy/dist/pypy/rpython/rmodel.py Wed Jun 8 19:47:19 2005
@@ -2,7 +2,8 @@
from pypy.annotation import model as annmodel
from pypy.objspace.flow.model import Constant
from pypy.rpython.lltype import Void, Bool, Float, Signed, Char
-from pypy.rpython.lltype import typeOf, LowLevelType
+from pypy.rpython.lltype import typeOf, LowLevelType, Ptr, PyObject
+from pypy.rpython.lltype import FuncType, functionptr
class Repr:
@@ -168,3 +169,18 @@
c = Constant(value)
c.concretetype = lltype
return c
+
+# __________ utilities __________
+
+PyObjPtr = Ptr(PyObject)
+
+def getconcretetype(v):
+ return getattr(v, 'concretetype', PyObjPtr)
+
+def getfunctionptr(translator, func, getconcretetype=getconcretetype):
+ """Make a functionptr from the given Python function."""
+ graph = translator.getflowgraph(func)
+ llinputs = [getconcretetype(v) for v in graph.getargs()]
+ lloutput = getconcretetype(graph.getreturnvar())
+ FT = FuncType(llinputs, lloutput)
+ return functionptr(FT, func.func_name, graph = graph, _callable = func)
Modified: pypy/dist/pypy/rpython/robject.py
==============================================================================
--- pypy/dist/pypy/rpython/robject.py (original)
+++ pypy/dist/pypy/rpython/robject.py Wed Jun 8 19:47:19 2005
@@ -1,6 +1,6 @@
from pypy.annotation.pairtype import pair, pairtype
from pypy.annotation import model as annmodel
-from pypy.rpython.lltype import PyObject, Ptr, Void, Bool
+from pypy.rpython.lltype import PyObject, Ptr, Void, Bool, pyobjectptr
from pypy.rpython.rmodel import Repr, TyperError
from pypy.rpython import rclass
@@ -18,6 +18,9 @@
class PyObjRepr(Repr):
lowleveltype = Ptr(PyObject)
+ def convert_const(self, value):
+ return pyobjectptr(value)
+
pyobj_repr = PyObjRepr()
Modified: pypy/dist/pypy/rpython/rtyper.py
==============================================================================
--- pypy/dist/pypy/rpython/rtyper.py (original)
+++ pypy/dist/pypy/rpython/rtyper.py Wed Jun 8 19:47:19 2005
@@ -8,7 +8,7 @@
from pypy.rpython.lltype import FuncType, functionptr, typeOf
from pypy.tool.sourcetools import func_with_new_name, valid_identifier
from pypy.translator.unsimplify import insert_empty_block
-from pypy.rpython.rmodel import Repr, inputconst, TyperError
+from pypy.rpython.rmodel import Repr, inputconst, TyperError, getfunctionptr
from pypy.rpython.normalizecalls import perform_normalizations
from pypy.rpython.annlowlevel import annotate_lowlevel_helper
@@ -95,6 +95,10 @@
self.typererror = None
#self.annotator.translator.view()
raise exc, value, tb
+ # make sure that the return variables of all graphs are concretetype'd
+ for graph in self.annotator.translator.flowgraphs.values():
+ v = graph.getreturnvar()
+ self.setconcretetype(v)
def call_all_setups(self):
# make sure all reprs so far have had their setup() called
@@ -257,17 +261,9 @@
# __________ utilities __________
def getfunctionptr(self, func):
- """Make a functionptr from the given Python function."""
- a = self.annotator
- graph = a.translator.getflowgraph(func)
- llinputs = [self.bindingrepr(v).lowleveltype for v in graph.getargs()]
- s_output = a.binding(graph.getreturnvar(), None)
- if s_output is None:
- lloutput = Void
- else:
- lloutput = self.getrepr(s_output).lowleveltype
- FT = FuncType(llinputs, lloutput)
- return functionptr(FT, func.func_name, graph = graph, _callable = func)
+ def getconcretetype(v):
+ return self.bindingrepr(v).lowleveltype
+ return getfunctionptr(self.annotator.translator, func, getconcretetype)
# ____________________________________________________________
More information about the Pypy-commit
mailing list