[pypy-svn] r7477 - in pypy/trunk/src/pypy: annotation interpreter objspace/std translator
hpk at codespeak.net
hpk at codespeak.net
Sat Nov 20 09:20:25 CET 2004
Author: hpk
Date: Sat Nov 20 09:20:22 2004
New Revision: 7477
Modified:
pypy/trunk/src/pypy/annotation/binaryop.py
pypy/trunk/src/pypy/annotation/factory.py
pypy/trunk/src/pypy/interpreter/argument.py
pypy/trunk/src/pypy/interpreter/eval.py
pypy/trunk/src/pypy/objspace/std/objspace.py
pypy/trunk/src/pypy/translator/annrpython.py
Log:
use newstyleclasses (the annotator is happier in its "commonbase"
hack then)
Modified: pypy/trunk/src/pypy/annotation/binaryop.py
==============================================================================
--- pypy/trunk/src/pypy/annotation/binaryop.py (original)
+++ pypy/trunk/src/pypy/annotation/binaryop.py Sat Nov 20 09:20:22 2004
@@ -7,7 +7,7 @@
from pypy.annotation.model import SomeString, SomeChar, SomeList, SomeDict
from pypy.annotation.model import SomeTuple, SomeImpossibleValue
from pypy.annotation.model import SomeInstance, SomeCallable
-from pypy.annotation.model import SomeBuiltin, SomeIterator
+from pypy.annotation.model import SomeBuiltin, SomeIterator, SomeNone
from pypy.annotation.model import SomePrebuiltConstant, immutablevalue
from pypy.annotation.model import unionof, set, setunion, missing_operation
from pypy.annotation.factory import generalize, isclassdef, getbookkeeper
@@ -288,6 +288,24 @@
d[cal] = classdef
return SomeCallable(d)
+# XXX experimental hack: union of more complex objects with
+# SomeNone (aka "NULL"-pointer) doesn't destroy
+# type inference (keeps the type of the more complex object)
+
+#for _X in SomeCallable, SomeInstance, SomePrebuiltConstant:
+# class __extend__(pairtype(_X, SomeNone)):
+# def union((obj1, obj2)):
+# return obj1
+# class __extend__(pairtype(SomeNone, _X)):
+# def union((obj1, obj2)):
+# return obj2
+
+#class __extend__(pairtype(SomePrebuiltConstant, SomeNone)):
+# def union((pbc, non)):
+# if
+
+# XXX experimental hack finish ... kind of
+
class __extend__(pairtype(SomeImpossibleValue, SomeObject)):
def union((imp1, obj2)):
return obj2
Modified: pypy/trunk/src/pypy/annotation/factory.py
==============================================================================
--- pypy/trunk/src/pypy/annotation/factory.py (original)
+++ pypy/trunk/src/pypy/annotation/factory.py Sat Nov 20 09:20:22 2004
@@ -177,11 +177,27 @@
assert isinstance(func, FunctionType), "expected function, got %r"%func
# do we need to specialize this function in several versions?
x = getattr(func, '_specialize_', False)
+ #if not x:
+ # x = 'argtypesdeep'
if x:
if x == 'argtypes':
key = "_".join([arg.__class__.__name__ for arg in args])
name = func.__name__+'_'+key
func = self.specialize_by_key(func, key, name)
+ elif x == 'argtypesdeep':
+ l = []
+ for arg in args:
+ if isinstance(arg, SomeInstance):
+ if hasattr(arg, 'knowntype'):
+ x = arg.knowntype.__name__
+ else:
+ x = 'unknown'
+ l.append('SI_%s' % x)
+ else:
+ l.append(arg.__class__.__name__)
+ key = "_".join(l)
+ name = func.__name__ + '_' + key
+ func = self.specialize_by_key(func, key, name)
elif x == "location":
# fully specialize: create one version per call position
func = self.specialize_by_key(func, self.position_key)
Modified: pypy/trunk/src/pypy/interpreter/argument.py
==============================================================================
--- pypy/trunk/src/pypy/interpreter/argument.py (original)
+++ pypy/trunk/src/pypy/interpreter/argument.py Sat Nov 20 09:20:22 2004
@@ -84,7 +84,9 @@
space = self.space
args_w = self.args_w
kwds_w = self.kwds_w
- argnames, varargname, kwargname = signature
+ argnames = signature[0]
+ varargname = signature[1]
+ kwargname = signature[2]
#
# args_w = list of the normal actual parameters, wrapped
# kwds_w = real dictionary {'keyword': wrapped parameter}
Modified: pypy/trunk/src/pypy/interpreter/eval.py
==============================================================================
--- pypy/trunk/src/pypy/interpreter/eval.py (original)
+++ pypy/trunk/src/pypy/interpreter/eval.py Sat Nov 20 09:20:22 2004
@@ -49,7 +49,7 @@
def getdocstring(self):
return None
-class UndefinedClass:
+class UndefinedClass:
pass
UNDEFINED = UndefinedClass() # marker for undefined local variables
Modified: pypy/trunk/src/pypy/objspace/std/objspace.py
==============================================================================
--- pypy/trunk/src/pypy/objspace/std/objspace.py (original)
+++ pypy/trunk/src/pypy/objspace/std/objspace.py Sat Nov 20 09:20:22 2004
@@ -303,6 +303,7 @@
def lookup(self, w_obj, name):
w_type = w_obj.getclass(self)
return w_type.lookup(name)
+ lookup._specialize_ = "argtypesdeep"
def allocate_instance(self, cls, w_subtype):
"""Allocate the memory needed for an instance of an internal or
@@ -349,6 +350,7 @@
if w_one is w_two:
return self.w_True
return self.w_False
+ is_._specialize_ = "argtypesdeep"
def is_true(self, w_obj):
# XXX don't look!
@@ -356,6 +358,7 @@
return not not w_obj.used
else:
return DescrOperation.is_true(self, w_obj)
+ is_true._specialize_ = "argtypesdeep"
def hash(space, w_obj):
w = space.wrap
Modified: pypy/trunk/src/pypy/translator/annrpython.py
==============================================================================
--- pypy/trunk/src/pypy/translator/annrpython.py (original)
+++ pypy/trunk/src/pypy/translator/annrpython.py Sat Nov 20 09:20:22 2004
@@ -187,16 +187,17 @@
missingargs = expectedargs - len(inputcells)
nbdefaults = len(func.func_defaults or ())
if not (0 <= missingargs <= nbdefaults):
- # XXX hack to avoid "*args" related processing
- # to bail out
- #v = graph.getreturnvar()
- #return self.bindings.get(v, annmodel.SomeImpossibleValue())
- # XXX end hack
if nbdefaults:
msg = "%d to %d" % (expectedargs-nbdefaults,
expectedargs)
else:
msg = "%d" % expectedargs
+ # XXX hack to avoid "*args" related processing
+ # to bail out
+ print "ANNOTATION WARNING: got %d inputcells in call to %r; expected %s" % (len(inputcells), func, msg)
+ v = graph.getreturnvar()
+ return self.bindings.get(v, annmodel.SomeImpossibleValue())
+ # XXX end hack
raise AnnotatorError, (
"got %d inputcells in call to %r; expected %s" % (
len(inputcells), func, msg))
More information about the Pypy-commit
mailing list