[pypy-svn] r23050 - in pypy/dist/pypy/rpython: . test
pedronis at codespeak.net
pedronis at codespeak.net
Sun Feb 5 21:19:31 CET 2006
Author: pedronis
Date: Sun Feb 5 21:19:30 2006
New Revision: 23050
Modified:
pypy/dist/pypy/rpython/rgenop.py
pypy/dist/pypy/rpython/test/test_rgenop.py
Log:
(start of) simple rtyping of rgenop operations, for now rtyped as direct_calls without graphs.
This works with llinterp.
Modified: pypy/dist/pypy/rpython/rgenop.py
==============================================================================
--- pypy/dist/pypy/rpython/rgenop.py (original)
+++ pypy/dist/pypy/rpython/rgenop.py Sun Feb 5 21:19:30 2006
@@ -9,6 +9,8 @@
from pypy.translator.simplify import eliminate_empty_blocks, join_blocks
from pypy.rpython.module.support import init_opaque_object
from pypy.rpython.module.support import to_opaque_object, from_opaque_object
+from pypy.rpython.module.support import from_rstr
+
# for debugging, sanity checks in non-RPython code
reveal = from_opaque_object
@@ -37,8 +39,11 @@
assert isinstance(v, (flowmodel.Constant, flowmodel.Variable))
res.append(v)
return res
-
+
+# is opname a runtime value?
def genop(blockcontainer, opname, vars, RESULT_TYPE):
+ if not isinstance(opname, str):
+ opname = from_rstr(opname)
block = from_opaque_object(blockcontainer.obj)
opvars = _inputvars(vars)
v = flowmodel.Variable()
@@ -188,6 +193,7 @@
consttypeinfo.set_lltype(vartypeinfo.get_lltype()) # force same lltype
linktypeinfo = declareptrtype(flowmodel.Link, "Link")
+CONSTORVAR = consttypeinfo.get_lltype()
BLOCKCONTAINERTYPE = blocktypeinfo.get_lltype()
LINKTYPE = linktypeinfo.get_lltype()
@@ -196,3 +202,43 @@
fields = tuple(zip(fieldnames, lltypes))
LINKPAIR = lltype.GcStruct('tuple2', *fields)
+# helpers
+def setannotation(func, TYPE):
+ func.compute_result_annotation = lambda *args_s: TYPE
+
+def setspecialize(func):
+ # for now
+ def specialize_as_direct_call(hop):
+ FUNCTYPE = lltype.FuncType([r.lowleveltype for r in hop.args_r], hop.r_result.lowleveltype)
+ args_v = hop.inputargs(*hop.args_r)
+ funcptr = lltype.functionptr(FUNCTYPE, func.__name__, _callable=func)
+ cfunc = hop.inputconst(lltype.Ptr(FUNCTYPE), funcptr)
+ return hop.genop('direct_call', [cfunc] + args_v, hop.r_result)
+ func.specialize = specialize_as_direct_call
+
+# annotations
+from pypy.annotation import model as annmodel
+setannotation(initblock, None)
+setannotation(geninputarg, annmodel.SomeExternalObject(flowmodel.Variable))
+setannotation(genop, annmodel.SomeExternalObject(flowmodel.Variable))
+setannotation(genconst, annmodel.SomeExternalObject(flowmodel.Variable))
+setannotation(closeblock1, annmodel.SomeExternalObject(flowmodel.Link))
+setannotation(closeblock2, annmodel.SomePtr(lltype.Ptr(LINKPAIR)))
+setannotation(closelink, None)
+setannotation(closereturnlink, None)
+
+# specialize
+setspecialize(initblock)
+setspecialize(geninputarg)
+setspecialize(genop)
+setspecialize(genconst)
+setspecialize(closeblock1)
+setspecialize(closeblock2)
+setspecialize(closelink)
+setspecialize(closereturnlink)
+
+
+
+
+
+
Modified: pypy/dist/pypy/rpython/test/test_rgenop.py
==============================================================================
--- pypy/dist/pypy/rpython/test/test_rgenop.py (original)
+++ pypy/dist/pypy/rpython/test/test_rgenop.py Sun Feb 5 21:19:30 2006
@@ -19,14 +19,14 @@
res = runblock(block, [17])
assert res == 289
-def NO_test_rtype_newblock():
+def test_rtype_newblock():
def emptyblock():
return newblock()
blockcontainer = interpret(emptyblock, [])
block = from_opaque_object(blockcontainer.obj)
assert isinstance(block, flowmodel.Block)
-def NO_test_rtype_geninputarg():
+def test_rtype_geninputarg():
def onearg():
block = newblock()
v0 = geninputarg(block, Signed)
@@ -35,11 +35,9 @@
v = from_opaque_object(opaquev)
assert isinstance(v, flowmodel.Variable)
-
-def NO_test_rtype_build_square():
+def test_rtype_build_square():
blockcontainer = interpret(build_square, [])
- block = from_opaque_object(blockcontainer.obj)
- res = runblock(block, [17])
+ res = runblock(blockcontainer, [17])
assert res == 289
def test_if():
More information about the Pypy-commit
mailing list