[pypy-svn] r20641 - in pypy/dist/pypy: annotation rpython/l3interp rpython/test
arigo at codespeak.net
arigo at codespeak.net
Sun Dec 4 14:11:55 CET 2005
Author: arigo
Date: Sun Dec 4 14:11:53 2005
New Revision: 20641
Modified:
pypy/dist/pypy/annotation/policy.py
pypy/dist/pypy/annotation/specialize.py
pypy/dist/pypy/rpython/l3interp/l3interp.py
pypy/dist/pypy/rpython/test/test_rpbc.py
Log:
Make and use a more appropriate specialization tag.
Modified: pypy/dist/pypy/annotation/policy.py
==============================================================================
--- pypy/dist/pypy/annotation/policy.py (original)
+++ pypy/dist/pypy/annotation/policy.py Sun Dec 4 14:11:53 2005
@@ -1,6 +1,6 @@
# base annotation policy for overrides and specialization
from pypy.annotation.specialize import default_specialize as default
-from pypy.annotation.specialize import argtype, argvalue
+from pypy.annotation.specialize import argtype, argvalue, arglistitemtype
from pypy.annotation.specialize import memo, methodmemo
# for some reason, model must be imported first,
# or we create a cycle.
@@ -55,16 +55,22 @@
specialize__methodmemo = staticmethod(methodmemo)
specialize__arg0 = staticmethod(argvalue(0))
specialize__argtype0 = staticmethod(argtype(0))
+ specialize__arglistitemtype0 = staticmethod(arglistitemtype(0))
specialize__arg1 = staticmethod(argvalue(1))
specialize__argtype1 = staticmethod(argtype(1))
+ specialize__arglistitemtype1 = staticmethod(arglistitemtype(1))
specialize__arg2 = staticmethod(argvalue(2))
specialize__argtype2 = staticmethod(argtype(2))
+ specialize__arglistitemtype2 = staticmethod(arglistitemtype(2))
specialize__arg3 = staticmethod(argvalue(3))
specialize__argtype3 = staticmethod(argtype(3))
+ specialize__arglistitemtype3 = staticmethod(arglistitemtype(3))
specialize__arg4 = staticmethod(argvalue(4))
specialize__argtype4 = staticmethod(argtype(4))
+ specialize__arglistitemtype4 = staticmethod(arglistitemtype(4))
specialize__arg5 = staticmethod(argvalue(5))
specialize__argtype5 = staticmethod(argtype(5))
+ specialize__arglistitemtype5 = staticmethod(arglistitemtype(5))
def override__ignore(pol, *args):
bk = getbookkeeper()
Modified: pypy/dist/pypy/annotation/specialize.py
==============================================================================
--- pypy/dist/pypy/annotation/specialize.py (original)
+++ pypy/dist/pypy/annotation/specialize.py Sun Dec 4 14:11:53 2005
@@ -186,3 +186,13 @@
key = args_s[i].knowntype
return funcdesc.cachedgraph(key)
return specialize_argtype
+
+def arglistitemtype(i):
+ def specialize_arglistitemtype(funcdesc, args_s):
+ s = args_s[i]
+ if s.knowntype is not list:
+ key = None
+ else:
+ key = s.listdef.listitem.s_value.knowntype
+ return funcdesc.cachedgraph(key)
+ return specialize_arglistitemtype
Modified: pypy/dist/pypy/rpython/l3interp/l3interp.py
==============================================================================
--- pypy/dist/pypy/rpython/l3interp/l3interp.py (original)
+++ pypy/dist/pypy/rpython/l3interp/l3interp.py Sun Dec 4 14:11:53 2005
@@ -73,12 +73,12 @@
def followlink(self, link):
assert isinstance(link, model.Link)
block = self.block
- followlink1(L3Integer, self.stack_int, self.base_int,
- link.targetregs_int, block.constants_int)
- followlink1(L3Double, self.stack_dbl, self.base_dbl,
- link.targetregs_dbl, block.constants_dbl)
- followlink1(L3Pointer, self.stack_ptr, self.base_ptr,
- link.targetregs_ptr, block.constants_ptr)
+ followlink1(self.stack_int, self.base_int,
+ link.targetregs_int, block.constants_int)
+ followlink1(self.stack_dbl, self.base_dbl,
+ link.targetregs_dbl, block.constants_dbl)
+ followlink1(self.stack_ptr, self.base_ptr,
+ link.targetregs_ptr, block.constants_ptr)
self.block = link.target
self.i = 0
@@ -161,12 +161,12 @@
block = self.block
assert block.called_graphs is not None
graph = block.called_graphs[self.nextuop()]
- directcall1(L3Integer, graph.nargs_int, self.stack_int,
- block.constants_int, self.nextop)
- directcall1(L3Double, graph.nargs_dbl, self.stack_dbl,
- block.constants_dbl, self.nextop)
- directcall1(L3Pointer, graph.nargs_ptr, self.stack_ptr,
- block.constants_ptr, self.nextop)
+ directcall1(self.stack_int, graph.nargs_int,
+ block.constants_int, self.nextop)
+ directcall1(self.stack_dbl, graph.nargs_dbl,
+ block.constants_dbl, self.nextop)
+ directcall1(self.stack_ptr, graph.nargs_ptr,
+ block.constants_ptr, self.nextop)
frame = L3Frame(graph, self.stack_int, self.stack_dbl, self.stack_ptr)
frame.execute()
@@ -175,7 +175,7 @@
class L3Return(Exception):
pass
-def followlink1(marker, stack, stackbase, targetregs, constants):
+def followlink1(stack, stackbase, targetregs, constants):
if targetregs is None:
del stack[stackbase:]
else:
@@ -188,9 +188,9 @@
for i in range(targetlen):
stack[stackbase + i] = stack[top + i]
del stack[stackbase + targetlen:]
-followlink1._annspecialcase_ = 'specialize:arg0'
+followlink1._annspecialcase_ = 'specialize:arglistitemtype0'
-def directcall1(marker, nargs, stack, constants, nextop):
+def directcall1(stack, nargs, constants, nextop):
if nargs > 0:
top = r_uint(len(stack))
for i in range(nargs):
@@ -198,4 +198,4 @@
if op >= 0: newval = constants[op]
else: newval = stack[top + op]
stack.append(newval)
-directcall1._annspecialcase_ = 'specialize:arg0'
+directcall1._annspecialcase_ = 'specialize:arglistitemtype0'
Modified: pypy/dist/pypy/rpython/test/test_rpbc.py
==============================================================================
--- pypy/dist/pypy/rpython/test/test_rpbc.py (original)
+++ pypy/dist/pypy/rpython/test/test_rpbc.py Sun Dec 4 14:11:53 2005
@@ -1218,3 +1218,16 @@
assert ''.join(res.chars) == 'tag1:hellotag1:< 42 >'
res = interpret(f, [0])
assert ''.join(res.chars) == 'tag2:hellotag2:< 42 >'
+
+def test_call_from_list():
+ def f0(n): return n+200
+ def f1(n): return n+192
+ def f2(n): return n+46
+ def f3(n): return n+2987
+ def f4(n): return n+217
+ lst = [f0, f1, f2, f3, f4]
+ def f(i, n):
+ return lst[i](n)
+ for i in range(5):
+ res = interpret(f, [i, 1000])
+ assert res == f(i, 1000)
More information about the Pypy-commit
mailing list