[pypy-svn] r57736 - in pypy/branch/oo-jit/pypy/rpython/ootypesystem: . test
antocuni at codespeak.net
antocuni at codespeak.net
Mon Sep 1 20:31:26 CEST 2008
Author: antocuni
Date: Mon Sep 1 20:31:24 2008
New Revision: 57736
Modified:
pypy/branch/oo-jit/pypy/rpython/ootypesystem/ootype.py
pypy/branch/oo-jit/pypy/rpython/ootypesystem/test/test_oortype.py
pypy/branch/oo-jit/pypy/rpython/ootypesystem/test/test_ootype.py
Log:
attach a Class to *all* OOTypes, including Class itself, and all
StaticMethods.
Not sure if this is the right way to do or just a temporary hack, probably we
need to think more about how the various OOTypes are related each other.
Modified: pypy/branch/oo-jit/pypy/rpython/ootypesystem/ootype.py
==============================================================================
--- pypy/branch/oo-jit/pypy/rpython/ootypesystem/ootype.py (original)
+++ pypy/branch/oo-jit/pypy/rpython/ootypesystem/ootype.py Mon Sep 1 20:31:24 2008
@@ -15,6 +15,18 @@
oopspec_name = None
+ _classes = {}
+
+ @property
+ def _class(self):
+ try:
+ return self._classes[self]
+ except KeyError:
+ cls = _class(self)
+ self._classes[self] = cls
+ return cls
+
+
def _is_compatible(TYPE1, TYPE2):
if TYPE1 == TYPE2:
return True
@@ -87,7 +99,7 @@
self._add_methods(methods)
self._null = make_null_instance(self)
- self._class = _class(self)
+ self.__dict__['_class'] = _class(self)
def __eq__(self, other):
return self is other
@@ -294,17 +306,6 @@
class BuiltinType(SpecializableType):
- _classes = {}
-
- @property
- def _class(self):
- try:
- return self._classes[self]
- except KeyError:
- cls = _class(self)
- self._classes[self] = cls
- return cls
-
def _example(self):
return new(self)
@@ -1826,9 +1827,9 @@
def overrideDefaultForFields(INSTANCE, fields):
INSTANCE._override_default_for_fields(fields)
-def runtimeClass(INSTANCE):
- assert isinstance(INSTANCE, (Instance, BuiltinType))
- return INSTANCE._class
+def runtimeClass(TYPE):
+ assert isinstance(TYPE, OOType)
+ return TYPE._class
def isSubclass(C1, C2):
c = C1
Modified: pypy/branch/oo-jit/pypy/rpython/ootypesystem/test/test_oortype.py
==============================================================================
--- pypy/branch/oo-jit/pypy/rpython/ootypesystem/test/test_oortype.py (original)
+++ pypy/branch/oo-jit/pypy/rpython/ootypesystem/test/test_oortype.py Mon Sep 1 20:31:24 2008
@@ -372,13 +372,16 @@
c1 = runtimeClass(I)
c2 = runtimeClass(R)
c3 = runtimeClass(L)
+ c4 = runtimeClass(Class)
def fn(flag):
if flag == 0:
return c1
elif flag == 1:
return c2
- else:
+ elif flag == 2:
return c3
+ else:
+ return c4
res = interpret(fn, [0], type_system='ootype')
assert res is c1
@@ -386,3 +389,5 @@
assert res is c2
res = interpret(fn, [2], type_system='ootype')
assert res is c3
+ res = interpret(fn, [3], type_system='ootype')
+ assert res is c4
Modified: pypy/branch/oo-jit/pypy/rpython/ootypesystem/test/test_ootype.py
==============================================================================
--- pypy/branch/oo-jit/pypy/rpython/ootypesystem/test/test_ootype.py (original)
+++ pypy/branch/oo-jit/pypy/rpython/ootypesystem/test/test_ootype.py Mon Sep 1 20:31:24 2008
@@ -59,7 +59,16 @@
L2 = List(Signed)
assert L1 == L2
assert runtimeClass(L1) is runtimeClass(L2)
-
+
+def test_class_class():
+ L = List(Signed)
+ R = Record({"a": Signed})
+ c1 = runtimeClass(L)
+ c2 = runtimeClass(R)
+ C1 = typeOf(c1)
+ C2 = typeOf(c2)
+ assert runtimeClass(C1) is runtimeClass(C2)
+
def test_classof():
I = Instance("test", ROOT, {"a": Signed})
c = runtimeClass(I)
More information about the Pypy-commit
mailing list