[pypy-svn] r23388 - in pypy/dist/pypy: annotation annotation/test interpreter module/math objspace/std rpython rpython/l3interp rpython/test translator/c/test
pedronis at codespeak.net
pedronis at codespeak.net
Thu Feb 16 04:26:06 CET 2006
Author: pedronis
Date: Thu Feb 16 04:25:57 2006
New Revision: 23388
Modified:
pypy/dist/pypy/annotation/description.py
pypy/dist/pypy/annotation/policy.py
pypy/dist/pypy/annotation/specialize.py
pypy/dist/pypy/annotation/test/test_annrpython.py
pypy/dist/pypy/interpreter/baseobjspace.py
pypy/dist/pypy/interpreter/pyopcode.py
pypy/dist/pypy/module/math/interp_math.py
pypy/dist/pypy/objspace/std/listsort.py
pypy/dist/pypy/objspace/std/longobject.py
pypy/dist/pypy/objspace/std/objspace.py
pypy/dist/pypy/objspace/std/stringobject.py
pypy/dist/pypy/rpython/annlowlevel.py
pypy/dist/pypy/rpython/l3interp/l3interp.py
pypy/dist/pypy/rpython/test/test_rint.py
pypy/dist/pypy/rpython/test/test_rpbc.py
pypy/dist/pypy/translator/c/test/test_annotated.py
Log:
sanitize a bit parametrised specialisation
now specialize__* methods can take further parameters in the signature:
(funcdecs, args_s, *rest)
they are passed in with function call like syntax: "specialize:name[(arguments...)]"
(this is parsed to a tuple using eval)
use this style instead of the explicit instantiation for various params done before.
now "specialize:arg0" is "specialize:arg(0)" etc...
the no parameter case still works without (): "specialize:memo"
Modified: pypy/dist/pypy/annotation/description.py
==============================================================================
--- pypy/dist/pypy/annotation/description.py (original)
+++ pypy/dist/pypy/annotation/description.py Thu Feb 16 04:25:57 2006
@@ -354,9 +354,11 @@
if self.specialize:
# make a custom funcdesc that specializes on its first
# argument (i.e. 'self').
- from pypy.annotation.specialize import argtype
+ from pypy.annotation.specialize import specialize_argtype
+ def argtype0(funcdesc, args_s):
+ return specialize_argtype(funcdesc, args_s, 0)
funcdesc = FunctionDesc(self.bookkeeper, value,
- specializer=argtype(0))
+ specializer=argtype0)
self.classdict[name] = funcdesc
continue
# NB. if value is, say, AssertionError.__init__, then we
Modified: pypy/dist/pypy/annotation/policy.py
==============================================================================
--- pypy/dist/pypy/annotation/policy.py (original)
+++ pypy/dist/pypy/annotation/policy.py Thu Feb 16 04:25:57 2006
@@ -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, arglistitemtype
+from pypy.annotation.specialize import specialize_argvalue, specialize_argtype, specialize_arglistitemtype
from pypy.annotation.specialize import memo
# for some reason, model must be imported first,
# or we create a cycle.
@@ -36,43 +36,48 @@
if directive is None:
return pol.default_specialize
- name = directive.replace(':', '__')
+ # specialize|override:name[(args)]
+ directive_parts = directive.split('(', 1)
+ if len(directive_parts) == 1:
+ [name] = directive_parts
+ parms = ()
+ else:
+ name, parms = directive_parts
+ try:
+ parms = eval("(lambda *parms: parms)(%s" % parms)
+ except KeyboardInterrupt, SystemExit:
+ raise
+ except:
+ raise Exception, "broken specialize directive parms: %s" % directive
+ name = name.replace(':', '__')
try:
specializer = getattr(pol, name)
except AttributeError:
raise AttributeError("%r specialize tag not defined in annotation"
- "policy %s" % (directive, pol))
+ "policy %s" % (name, pol))
if directive.startswith('override:'):
# different signature: override__xyz(*args_s)
+ if parms:
+ raise Exception, "override:* specialisations don't support parameters"
def specialize_override(funcdesc, args_s):
funcdesc.overridden = True
return specializer(*args_s)
return specialize_override
else:
- return specializer
+ if not parms:
+ return specializer
+ else:
+ def specialize_with_parms(funcdesc, args_s):
+ return specializer(funcdesc, args_s, *parms)
+ return specialize_with_parms
# common specializations
default_specialize = staticmethod(default)
specialize__memo = staticmethod(memo)
- 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))
+ specialize__arg = staticmethod(specialize_argvalue) # specialize:arg(N)
+ specialize__argtype = staticmethod(specialize_argtype) # specialize:argtype(N)
+ specialize__arglistitemtype = staticmethod(specialize_arglistitemtype)
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 Thu Feb 16 04:25:57 2006
@@ -375,25 +375,18 @@
## return funcdesc.cachedgraph(s1_type, alt_name='memo_%s' % funcdesc.name,
## builder=builder)
+def specialize_argvalue(funcdesc, args_s, i):
+ key = args_s[i].const
+ return funcdesc.cachedgraph(key)
-def argvalue(i):
- def specialize_argvalue(funcdesc, args_s):
- key = args_s[i].const
- return funcdesc.cachedgraph(key)
- return specialize_argvalue
+def specialize_argtype(funcdesc, args_s, i):
+ key = args_s[i].knowntype
+ return funcdesc.cachedgraph(key)
-def argtype(i):
- def specialize_argtype(funcdesc, args_s):
- 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
+def specialize_arglistitemtype(funcdesc, args_s, i):
+ s = args_s[i]
+ if s.knowntype is not list:
+ key = None
+ else:
+ key = s.listdef.listitem.s_value.knowntype
+ return funcdesc.cachedgraph(key)
Modified: pypy/dist/pypy/annotation/test/test_annrpython.py
==============================================================================
--- pypy/dist/pypy/annotation/test/test_annrpython.py (original)
+++ pypy/dist/pypy/annotation/test/test_annrpython.py Thu Feb 16 04:25:57 2006
@@ -954,7 +954,7 @@
i = inst(cls)
assert isinstance(i, cls)
return i
- alloc._annspecialcase_ = "specialize:arg0"
+ alloc._annspecialcase_ = "specialize:arg(0)"
def f():
c1 = alloc(C1)
Modified: pypy/dist/pypy/interpreter/baseobjspace.py
==============================================================================
--- pypy/dist/pypy/interpreter/baseobjspace.py (original)
+++ pypy/dist/pypy/interpreter/baseobjspace.py Thu Feb 16 04:25:57 2006
@@ -411,7 +411,7 @@
w_obj.getclass(self).getname(self, '?'))
raise OperationError(self.w_TypeError, self.wrap(msg))
return obj
- interp_w._annspecialcase_ = 'specialize:arg1'
+ interp_w._annspecialcase_ = 'specialize:arg(1)'
def unpackiterable(self, w_iterable, expected_length=-1):
"""Unpack an iterable object into a real (interpreter-level) list.
Modified: pypy/dist/pypy/interpreter/pyopcode.py
==============================================================================
--- pypy/dist/pypy/interpreter/pyopcode.py (original)
+++ pypy/dist/pypy/interpreter/pyopcode.py Thu Feb 16 04:25:57 2006
@@ -874,7 +874,7 @@
return
# XXX add unicode handling
file_softspace(stream, True)
- print_item_to._annspecialcase_ = "specialize:argtype0"
+ print_item_to._annspecialcase_ = "specialize:argtype(0)"
def print_newline_to(stream):
stream.write("\n")
Modified: pypy/dist/pypy/module/math/interp_math.py
==============================================================================
--- pypy/dist/pypy/module/math/interp_math.py (original)
+++ pypy/dist/pypy/module/math/interp_math.py Thu Feb 16 04:25:57 2006
@@ -20,7 +20,7 @@
raise OperationError(space.w_ValueError,
space.wrap("math domain error"))
return space.wrap(y)
-math1._annspecialcase_ = 'specialize:arg1'
+math1._annspecialcase_ = 'specialize:arg(1)'
def math1_w(space, f, x):
try:
@@ -32,7 +32,7 @@
raise OperationError(space.w_ValueError,
space.wrap("math domain error"))
return r
-math1_w._annspecialcase_ = 'specialize:arg1'
+math1_w._annspecialcase_ = 'specialize:arg(1)'
def math2(space, f, x, snd):
try:
@@ -44,7 +44,7 @@
raise OperationError(space.w_ValueError,
space.wrap("math domain error"))
return space.wrap(r)
-math2._annspecialcase_ = 'specialize:arg1'
+math2._annspecialcase_ = 'specialize:arg(1)'
def pow(space, x, y):
"""pow(x,y)
Modified: pypy/dist/pypy/objspace/std/listsort.py
==============================================================================
--- pypy/dist/pypy/objspace/std/listsort.py (original)
+++ pypy/dist/pypy/objspace/std/listsort.py Thu Feb 16 04:25:57 2006
@@ -190,7 +190,7 @@
# the two cases. (This is actually needed for technical reasons: the
# variable 'lower' must contain a known method, which is the case in each
# specialized version but not in the unspecialized one.)
- gallop._annspecialcase_ = "specialize:arg4"
+ gallop._annspecialcase_ = "specialize:arg(4)"
# ____________________________________________________________
Modified: pypy/dist/pypy/objspace/std/longobject.py
==============================================================================
--- pypy/dist/pypy/objspace/std/longobject.py (original)
+++ pypy/dist/pypy/objspace/std/longobject.py Thu Feb 16 04:25:57 2006
@@ -1300,7 +1300,7 @@
# CAUTION: e*SHIFT may overflow using int arithmetic,
# so force use of double. */
return func(x) + (e * float(SHIFT) * func(2.0))
-_loghelper._annspecialcase_ = 'specialize:arg0'
+_loghelper._annspecialcase_ = 'specialize:arg(0)'
def _long_true_divide(a, b):
try:
Modified: pypy/dist/pypy/objspace/std/objspace.py
==============================================================================
--- pypy/dist/pypy/objspace/std/objspace.py (original)
+++ pypy/dist/pypy/objspace/std/objspace.py Thu Feb 16 04:25:57 2006
@@ -402,7 +402,7 @@
instance.user_setup(self, w_subtype, w_subtype.nslots)
assert isinstance(instance, cls)
return instance
- allocate_instance._annspecialcase_ = "specialize:arg1"
+ allocate_instance._annspecialcase_ = "specialize:arg(1)"
def unpacktuple(self, w_tuple, expected_length=-1):
assert isinstance(w_tuple, W_TupleObject)
Modified: pypy/dist/pypy/objspace/std/stringobject.py
==============================================================================
--- pypy/dist/pypy/objspace/std/stringobject.py (original)
+++ pypy/dist/pypy/objspace/std/stringobject.py Thu Feb 16 04:25:57 2006
@@ -46,7 +46,7 @@
if not fun(v[idx]):
return space.w_False
return space.w_True
-_is_generic._annspecialcase_ = "specialize:arg1"
+_is_generic._annspecialcase_ = "specialize:arg(1)"
def _upper(ch):
if ch.islower():
Modified: pypy/dist/pypy/rpython/annlowlevel.py
==============================================================================
--- pypy/dist/pypy/rpython/annlowlevel.py (original)
+++ pypy/dist/pypy/rpython/annlowlevel.py Thu Feb 16 04:25:57 2006
@@ -106,18 +106,10 @@
else:
return funcdesc.cachedgraph(None)
- def arglltype(i):
- def specialize_arglltype(pol, funcdesc, args_s):
- key = pol.rtyper.getrepr(args_s[i]).lowleveltype
- alt_name = funcdesc.name+"__for_%sLlT" % key._short_name()
- return funcdesc.cachedgraph(key, alt_name=valid_identifier(alt_name))
- return specialize_arglltype
-
- specialize__arglltype0 = arglltype(0)
- specialize__arglltype1 = arglltype(1)
- specialize__arglltype2 = arglltype(2)
-
- del arglltype
+ def specialize__arglltype(pol, funcdesc, args_s, i):
+ key = pol.rtyper.getrepr(args_s[i]).lowleveltype
+ alt_name = funcdesc.name+"__for_%sLlT" % key._short_name()
+ return funcdesc.cachedgraph(key, alt_name=valid_identifier(alt_name))
def annotate_mixlevel_helper(rtyper, ll_function, args_s):
Modified: pypy/dist/pypy/rpython/l3interp/l3interp.py
==============================================================================
--- pypy/dist/pypy/rpython/l3interp/l3interp.py (original)
+++ pypy/dist/pypy/rpython/l3interp/l3interp.py Thu Feb 16 04:25:57 2006
@@ -270,7 +270,7 @@
for i in range(targetlen):
stack[stackbase + i] = stack[top + i]
del stack[stackbase + targetlen:]
-followlink1._annspecialcase_ = 'specialize:arglistitemtype0'
+followlink1._annspecialcase_ = 'specialize:arglistitemtype(0)'
def directcall1(stack, nargs, constants, nextop):
if nargs > 0:
@@ -280,4 +280,4 @@
if op >= 0: newval = constants[op]
else: newval = stack[top + op]
stack.append(newval)
-directcall1._annspecialcase_ = 'specialize:arglistitemtype0'
+directcall1._annspecialcase_ = 'specialize:arglistitemtype(0)'
Modified: pypy/dist/pypy/rpython/test/test_rint.py
==============================================================================
--- pypy/dist/pypy/rpython/test/test_rint.py (original)
+++ pypy/dist/pypy/rpython/test/test_rint.py Thu Feb 16 04:25:57 2006
@@ -104,7 +104,7 @@
def test_specializing_int_functions():
def f(i):
return i + 1
- f._annspecialcase_ = "specialize:argtype0"
+ f._annspecialcase_ = "specialize:argtype(0)"
def g(n):
if n > 0:
return f(r_longlong(0))
@@ -132,7 +132,7 @@
if isinstance(x, r_longlong):
return int(x)
return "XXX"
- wrap._annspecialcase_ = 'specialize:argtype0'
+ wrap._annspecialcase_ = 'specialize:argtype(0)'
space = FakeSpace()
def wrap(x):
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 Thu Feb 16 04:25:57 2006
@@ -1203,9 +1203,9 @@
return x
def mysecond(x, y): # int,int->int or str,str->str
return y
- myadder._annspecialcase_ = 'specialize:argtype0'
- myfirst._annspecialcase_ = 'specialize:argtype0'
- mysecond._annspecialcase_ = 'specialize:argtype0'
+ myadder._annspecialcase_ = 'specialize:argtype(0)'
+ myfirst._annspecialcase_ = 'specialize:argtype(0)'
+ mysecond._annspecialcase_ = 'specialize:argtype(0)'
def f(i):
if i == 0:
g = myfirst
@@ -1229,7 +1229,7 @@
return self.tag + '< %d >' % x
else:
return self.tag + x
- wrap._annspecialcase_ = 'specialize:argtype1'
+ wrap._annspecialcase_ = 'specialize:argtype(1)'
space1 = space("tag1:")
space2 = space("tag2:")
def f(i):
Modified: pypy/dist/pypy/translator/c/test/test_annotated.py
==============================================================================
--- pypy/dist/pypy/translator/c/test/test_annotated.py (original)
+++ pypy/dist/pypy/translator/c/test/test_annotated.py Thu Feb 16 04:25:57 2006
@@ -252,7 +252,7 @@
def test_specializing_int_functions(self):
def f(i):
return i + 1
- f._annspecialcase_ = "specialize:argtype0"
+ f._annspecialcase_ = "specialize:argtype(0)"
def g(n=int):
if n > 0:
return f(r_longlong(0))
More information about the Pypy-commit
mailing list