[pypy-svn] r18430 - in pypy/branch/hl-backend/pypy: rpython rpython/ootype rpython/ootype/test translator
boria at codespeak.net
boria at codespeak.net
Tue Oct 11 20:01:13 CEST 2005
Author: boria
Date: Tue Oct 11 20:01:08 2005
New Revision: 18430
Modified:
pypy/branch/hl-backend/pypy/rpython/ootype/ootype.py
pypy/branch/hl-backend/pypy/rpython/ootype/test/test_ooclean.py
pypy/branch/hl-backend/pypy/rpython/ootype/test/test_ootype.py
pypy/branch/hl-backend/pypy/rpython/rmodel.py
pypy/branch/hl-backend/pypy/rpython/rpbc.py
pypy/branch/hl-backend/pypy/rpython/rtyper.py
pypy/branch/hl-backend/pypy/translator/translator.py
Log:
(Samuele, Aurelien, Boris)
* Start of work on integrating ootype with r{typer, model, pbc}.py
Modified: pypy/branch/hl-backend/pypy/rpython/ootype/ootype.py
==============================================================================
--- pypy/branch/hl-backend/pypy/rpython/ootype/ootype.py (original)
+++ pypy/branch/hl-backend/pypy/rpython/ootype/ootype.py Tue Oct 11 20:01:08 2005
@@ -197,8 +197,8 @@
def new(CLASS):
return _instance(CLASS)
-def static_meth(FUNCTION, **attrs):
- return _static_meth(FUNCTION, **attrs)
+def static_meth(FUNCTION, name, **attrs):
+ return _static_meth(FUNCTION, _name=name, **attrs)
def meth(METHOD, **attrs):
return _meth(METHOD, **attrs)
Modified: pypy/branch/hl-backend/pypy/rpython/ootype/test/test_ooclean.py
==============================================================================
--- pypy/branch/hl-backend/pypy/rpython/ootype/test/test_ooclean.py (original)
+++ pypy/branch/hl-backend/pypy/rpython/ootype/test/test_ooclean.py Tue Oct 11 20:01:08 2005
@@ -18,7 +18,7 @@
return a + b
t = Translator(f)
t.annotate([int, int])
- t.specialize()
+ t.specialize(type_system="ootype")
graph = t.flowgraphs[f]
check_only_ootype(graph)
@@ -32,7 +32,8 @@
t = Translator(g)
t.annotate([])
- t.specialize()
+
+ t.specialize(type_system="ootype")
graph = t.flowgraphs[g]
check_only_ootype(graph)
Modified: pypy/branch/hl-backend/pypy/rpython/ootype/test/test_ootype.py
==============================================================================
--- pypy/branch/hl-backend/pypy/rpython/ootype/test/test_ootype.py (original)
+++ pypy/branch/hl-backend/pypy/rpython/ootype/test/test_ootype.py Tue Oct 11 20:01:08 2005
@@ -74,7 +74,7 @@
F = StaticMethod([Signed, Signed], Signed)
def f_(a, b):
return a+b
- f = static_meth(F, _name="f", _callable=f_)
+ f = static_meth(F, "f", _callable=f_)
assert typeOf(f) == F
result = f(2, 3)
@@ -85,7 +85,7 @@
F = StaticMethod([Signed, Signed], Signed)
def f_(a, b):
return a+b
- f = static_meth(F, _name="f", _callable=f_)
+ f = static_meth(F, "f", _callable=f_)
py.test.raises(TypeError, "f(2.0, 3.0)")
py.test.raises(TypeError, "f()")
Modified: pypy/branch/hl-backend/pypy/rpython/rmodel.py
==============================================================================
--- pypy/branch/hl-backend/pypy/rpython/rmodel.py (original)
+++ pypy/branch/hl-backend/pypy/rpython/rmodel.py Tue Oct 11 20:01:08 2005
@@ -4,6 +4,7 @@
from pypy.rpython.lltype import Void, Bool, Float, Signed, Char, UniChar
from pypy.rpython.lltype import typeOf, LowLevelType, Ptr, PyObject
from pypy.rpython.lltype import FuncType, functionptr, cast_ptr_to_int
+from pypy.rpython.ootype import ootype
from pypy.rpython.error import TyperError, MissingRTypeOperation
# initialization states for Repr instances
@@ -313,13 +314,19 @@
return getattr(v, 'concretetype', PyObjPtr)
def getfunctionptr(translator, graphfunc, getconcretetype=getconcretetype):
+ return getcallable(translator, graphfunc, getconcretetype, FuncType, functionptr)
+
+def getstaticmeth(translator, graphfunc, getconcretetype=getconcretetype):
+ return getcallable(translator, graphfunc, getconcretetype, ootype.StaticMethod, ootype.static_meth)
+
+def getcallable(translator, graphfunc, getconcretetype, typ, constr):
"""Make a functionptr from the given Python function."""
graph = translator.getflowgraph(graphfunc)
llinputs = [getconcretetype(v) for v in graph.getargs()]
lloutput = getconcretetype(graph.getreturnvar())
- FT = FuncType(llinputs, lloutput)
+ FT = typ(llinputs, lloutput)
_callable = getattr(graphfunc, '_specializedversionof_', graphfunc)
- return functionptr(FT, graphfunc.func_name, graph = graph, _callable = _callable)
+ return constr(FT, graphfunc.func_name, graph = graph, _callable = _callable)
def needsgc(classdef, nogc=False):
if classdef is None:
Modified: pypy/branch/hl-backend/pypy/rpython/rpbc.py
==============================================================================
--- pypy/branch/hl-backend/pypy/rpython/rpbc.py (original)
+++ pypy/branch/hl-backend/pypy/rpython/rpbc.py Tue Oct 11 20:01:08 2005
@@ -344,9 +344,8 @@
def getsignature(rtyper, func):
- f = rtyper.getfunctionptr(func)
+ f = rtyper.getcallable(func)
graph = f._obj.graph
- FUNCPTR = typeOf(f)
rinputs = [rtyper.bindingrepr(v) for v in graph.getargs()]
if graph.getreturnvar() in rtyper.annotator.bindings:
rresult = rtyper.bindingrepr(graph.getreturnvar())
Modified: pypy/branch/hl-backend/pypy/rpython/rtyper.py
==============================================================================
--- pypy/branch/hl-backend/pypy/rpython/rtyper.py (original)
+++ pypy/branch/hl-backend/pypy/rpython/rtyper.py Tue Oct 11 20:01:08 2005
@@ -26,7 +26,7 @@
from pypy.translator.unsimplify import insert_empty_block
from pypy.rpython.rmodel import Repr, inputconst
from pypy.rpython.rmodel import TyperError, BrokenReprTyperError
-from pypy.rpython.rmodel import getfunctionptr, warning
+from pypy.rpython.rmodel import getfunctionptr, getstaticmeth, warning
from pypy.rpython.normalizecalls import perform_normalizations
from pypy.rpython.annlowlevel import annotate_lowlevel_helper
from pypy.rpython.exceptiondata import ExceptionData
@@ -36,8 +36,9 @@
class RPythonTyper:
- def __init__(self, annotator):
+ def __init__(self, annotator, type_system="lltype"):
self.annotator = annotator
+ self.type_system = type_system
self.reprs = {}
self._reprs_must_call_setup = []
self._seen_reprs_must_call_setup = {}
@@ -496,6 +497,18 @@
def needs_hash_support(self, cls):
return cls in self.annotator.bookkeeper.needs_hash_support
+ def getcallable(self, graphfunc):
+ if self.type_system == "lltype":
+ return self.getfunctionptr(graphfunc)
+
+ elif self.type_system == "ootype":
+ return self.getstaticmeth(graphfunc)
+
+ def getstaticmeth(self, graphfunc):
+ def getconcretetype(v):
+ return self.bindingrepr(v).lowleveltype
+ return getstaticmeth(self.annotator.translator, graphfunc, getconcretetype)
+
def getfunctionptr(self, graphfunc):
def getconcretetype(v):
return self.bindingrepr(v).lowleveltype
Modified: pypy/branch/hl-backend/pypy/translator/translator.py
==============================================================================
--- pypy/branch/hl-backend/pypy/translator/translator.py (original)
+++ pypy/branch/hl-backend/pypy/translator/translator.py Tue Oct 11 20:01:08 2005
@@ -169,7 +169,9 @@
if self.rtyper is not None:
raise ValueError("cannot specialize() several times")
from pypy.rpython.rtyper import RPythonTyper
- self.rtyper = RPythonTyper(self.annotator)
+
+ self.rtyper = RPythonTyper(self.annotator,
+ type_system=flags.pop("type_system", "lltype"))
self.rtyper.specialize(**flags)
def backend_optimizations(self, **kwds):
More information about the Pypy-commit
mailing list