[pypy-svn] r34195 - in pypy/branch/transparent-proxy/pypy/rpython: . test
fijal at codespeak.net
fijal at codespeak.net
Sat Nov 4 17:24:02 CET 2006
Author: fijal
Date: Sat Nov 4 17:24:01 2006
New Revision: 34195
Modified:
pypy/branch/transparent-proxy/pypy/rpython/rpbc.py
pypy/branch/transparent-proxy/pypy/rpython/test/test_rpbc.py
Log:
Merge back from dist.
Modified: pypy/branch/transparent-proxy/pypy/rpython/rpbc.py
==============================================================================
--- pypy/branch/transparent-proxy/pypy/rpython/rpbc.py (original)
+++ pypy/branch/transparent-proxy/pypy/rpython/rpbc.py Sat Nov 4 17:24:01 2006
@@ -595,9 +595,9 @@
def __init__(self, rtyper, s_pbc):
self.rtyper = rtyper
self.s_pbc = s_pbc
- if s_pbc.can_be_None:
- raise TyperError("unsupported: variable of type "
- "class-pointer or None")
+ #if s_pbc.can_be_None:
+ # raise TyperError("unsupported: variable of type "
+ # "class-pointer or None")
if s_pbc.is_constant():
self.lowleveltype = Void
else:
@@ -627,6 +627,12 @@
return rclass.get_type_repr(self.rtyper).convert_desc(desc)
def convert_const(self, cls):
+ if cls is None:
+ if self.lowleveltype is Void:
+ return None
+ else:
+ T = self.lowleveltype
+ return self.rtyper.type_system.null_callable(T)
bk = self.rtyper.annotator.bookkeeper
classdesc = bk.getdesc(cls)
return self.convert_desc(classdesc)
@@ -664,8 +670,10 @@
s_instance = hop.s_result
r_instance = hop.r_result
- if self.lowleveltype is Void:
+ if len(self.s_pbc.descriptions) == 1:
# instantiating a single class
+ if self.lowleveltype is not Void:
+ assert 0, "XXX None-or-1-class instantation not implemented"
assert isinstance(s_instance, annmodel.SomeInstance)
classdef = hop.s_result.classdef
s_init = classdef.classdesc.s_read_attribute('__init__')
@@ -693,13 +701,13 @@
vtypeptr = hop.inputarg(self, arg=0)
try:
access_set, r_class = self.get_access_set('__init__')
- except MissingRTypeAttribute:
+ except rclass.MissingRTypeAttribute:
s_init = annmodel.s_ImpossibleValue
else:
s_init = access_set.s_value
v_init = r_class.getpbcfield(vtypeptr, access_set, '__init__',
hop.llops)
- v_instance = self._instantiate_runtime_class(hop, vtypeptr, r_instance)
+ v_instance = self._instantiate_runtime_class(hop, vtypeptr, r_instance)
if isinstance(s_init, annmodel.SomeImpossibleValue):
assert hop.nb_args == 1, ("arguments passed to __init__, "
Modified: pypy/branch/transparent-proxy/pypy/rpython/test/test_rpbc.py
==============================================================================
--- pypy/branch/transparent-proxy/pypy/rpython/test/test_rpbc.py (original)
+++ pypy/branch/transparent-proxy/pypy/rpython/test/test_rpbc.py Sat Nov 4 17:24:01 2006
@@ -568,6 +568,31 @@
res = self.interpret(f, [1])
assert self.class_name(res) == 'B'
+ def test_call_classes_or_None(self):
+ class A: pass
+ class B(A): pass
+ def f(i):
+ if i == -1:
+ cls = None
+ elif i == 1:
+ cls = B
+ else:
+ cls = A
+ return cls()
+ res = self.interpret(f, [0])
+ assert self.class_name(res) == 'A'
+ res = self.interpret(f, [1])
+ assert self.class_name(res) == 'B'
+
+ #def f(i):
+ # if i == -1:
+ # cls = None
+ # else:
+ # cls = A
+ # return cls()
+ #res = self.interpret(f, [0])
+ #assert self.class_name(res) == 'A'
+
def test_call_classes_with_init2(self):
class A:
def __init__(self, z):
More information about the Pypy-commit
mailing list