[pypy-svn] r14498 - in pypy/dist/pypy/rpython: . test
arigo at codespeak.net
arigo at codespeak.net
Mon Jul 11 14:06:41 CEST 2005
Author: arigo
Date: Mon Jul 11 14:06:39 2005
New Revision: 14498
Modified:
pypy/dist/pypy/rpython/rpbc.py
pypy/dist/pypy/rpython/test/test_rpbc.py
Log:
Generally allow None in PBC sets in rpbc.py.
Support for None in FunctionsPBCRepr.
Modified: pypy/dist/pypy/rpython/rpbc.py
==============================================================================
--- pypy/dist/pypy/rpython/rpbc.py (original)
+++ pypy/dist/pypy/rpython/rpbc.py Mon Jul 11 14:06:39 2005
@@ -35,6 +35,9 @@
x, classdef))
choice = MethodsPBCRepr
+ elif x is None:
+ continue # skipped, a None is allowed implicitely anywhere
+
elif isinstance(x, (type, types.ClassType)):
# classes
if x in userclasses:
@@ -66,6 +69,8 @@
if len(choices) > 1:
raise TyperError("mixed kinds of PBC in the set %r" % (
self.prebuiltinstances,))
+ if len(choices) < 1:
+ return none_frozen_pbc_repr # prebuiltinstances == {None: True}
reprcls, = choices
return reprcls(rtyper, self)
@@ -82,8 +87,8 @@
def getFrozenPBCRepr(rtyper, s_pbc):
if len(s_pbc.prebuiltinstances) <= 1:
- if s_pbc.const is None:
- return none_frozen_pbc_repr
+ #if s_pbc.const is None: -- take care of by rtyper_makerepr() above
+ # return none_frozen_pbc_repr
return single_frozen_pbc_repr
else:
pbcs = [pbc for pbc in s_pbc.prebuiltinstances.keys()
@@ -195,7 +200,7 @@
try:
thisattrvalue = getattr(pbc, attr)
except AttributeError:
- warning("PBC %r has no attribute %r" % (pbc, attr))
+ warning("PBC %r has no attribute %r" % (pbc, name))
continue
llvalue = r_value.convert_const(thisattrvalue)
setattr(result, mangled_name, llvalue)
@@ -298,10 +303,15 @@
if self._function_signatures is None:
self._function_signatures = {}
for func in self.s_pbc.prebuiltinstances:
- self._function_signatures[func] = getsignature(self.rtyper,func)
+ if func is not None:
+ self._function_signatures[func] = getsignature(self.rtyper,
+ func)
+ assert self._function_signatures
return self._function_signatures
def convert_const(self, value):
+ if value is None:
+ return nullptr(self.lowleveltype.TO)
if isinstance(value, types.MethodType) and value.im_self is None:
value = value.im_func # unbound method -> bare function
if value not in self.function_signatures():
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 Mon Jul 11 14:06:39 2005
@@ -291,3 +291,22 @@
assert res == 123
res = interpret(f, [1])
assert res == 456
+
+def test_function_or_None():
+ def g1():
+ return 42
+ def f(i):
+ g = None
+ if i > 5:
+ g = g1
+ if i > 6:
+ return g()
+ else:
+ return 12
+
+ res = interpret(f, [0])
+ assert res == 12
+ res = interpret(f, [6])
+ assert res == 12
+ res = interpret(f, [7])
+ assert res == 42
More information about the Pypy-commit
mailing list