[pypy-svn] r47879 - in pypy/dist/pypy/lang/smalltalk: . test
akuhn at codespeak.net
akuhn at codespeak.net
Thu Oct 25 01:47:33 CEST 2007
Author: akuhn
Date: Thu Oct 25 01:47:32 2007
New Revision: 47879
Modified:
pypy/dist/pypy/lang/smalltalk/constants.py
pypy/dist/pypy/lang/smalltalk/mirror.py
pypy/dist/pypy/lang/smalltalk/model.py
pypy/dist/pypy/lang/smalltalk/squeakimage.py
pypy/dist/pypy/lang/smalltalk/test/test_classtable.py
pypy/dist/pypy/lang/smalltalk/test/test_miniimage.py
Log:
nice __str__ for W_AbstractObjectWithClassReference that prints 'a Object' for instances and 'Object class' for classes.
Modified: pypy/dist/pypy/lang/smalltalk/constants.py
==============================================================================
--- pypy/dist/pypy/lang/smalltalk/constants.py (original)
+++ pypy/dist/pypy/lang/smalltalk/constants.py Thu Oct 25 01:47:32 2007
@@ -12,6 +12,7 @@
CLASS_SUPERCLASS_INDEX = 0
CLASS_METHODDICT_INDEX = 1
CLASS_FORMAT_INDEX = 2
+CLASS_NAME_INDEX = 6
METHODDICT_VALUES_INDEX = 1
METHODDICT_NAMES_INDEX = 2
Modified: pypy/dist/pypy/lang/smalltalk/mirror.py
==============================================================================
--- pypy/dist/pypy/lang/smalltalk/mirror.py (original)
+++ pypy/dist/pypy/lang/smalltalk/mirror.py Thu Oct 25 01:47:32 2007
@@ -25,7 +25,7 @@
self.methoddict = {}
self.m_superclass = None
self.m_metaclass = None
- self.name = '?'
+ self.name = '?' # take care when initing this, metaclasses do not have a name!
self.invalid = True
def check(self):
Modified: pypy/dist/pypy/lang/smalltalk/model.py
==============================================================================
--- pypy/dist/pypy/lang/smalltalk/model.py (original)
+++ pypy/dist/pypy/lang/smalltalk/model.py Thu Oct 25 01:47:32 2007
@@ -79,6 +79,17 @@
def getclassmirror(self):
return self.m_class
+ def __str__(self):
+ self.getclassmirror().check()
+ if self.size() >= 9:
+ return ''.join(self.fetch(sqc.CLASS_NAME_INDEX).bytes) + " class"
+ else:
+ return "a " + ''.join(self.getclass().fetch(sqc.CLASS_NAME_INDEX).bytes)
+
+ def getclass(self):
+ self.getclassmirror().check()
+ return self.getclassmirror().w_self
+
def invariant(self):
from pypy.lang.smalltalk.mirror import ClassMirror
return (W_AbstractObjectWithIdentityHash.invariant(self) and
Modified: pypy/dist/pypy/lang/smalltalk/squeakimage.py
==============================================================================
--- pypy/dist/pypy/lang/smalltalk/squeakimage.py (original)
+++ pypy/dist/pypy/lang/smalltalk/squeakimage.py Thu Oct 25 01:47:32 2007
@@ -333,16 +333,18 @@
literals = [self.decode_pointer(pointer).w_object
for pointer in self.chunk.data[:literalsize+1]]
# --------------------
- l = []
- for each in self.chunk.data[literalsize+1:]:
- l.append(int2str(each))
- bytes = "".join(l)
- bytes = bytes[:-(self.format & 3)]
+ bbytes = []
+ for each in self.chunk.data:
+ bbytes.append(chr((each >> 24) & 0xff))
+ bbytes.append(chr((each >> 16) & 0xff))
+ bbytes.append(chr((each >> 8) & 0xff))
+ bbytes.append(chr((each >> 0) & 0xff))
+ bbytes = bbytes[(literalsize + 1)*4:-(self.format & 3)] # omit literals & odd bytes
# XXX assert mirrorcache.get_or_build(self.g_class.w_object) is
# ct.m_CompiledMethod
w_compiledmethod.__init__(
literalsize = literalsize,
- bytes = bytes,
+ bytes = ''.join(bbytes),
argsize = numargs,
tempsize = tempsize,
primitive = primitive)
Modified: pypy/dist/pypy/lang/smalltalk/test/test_classtable.py
==============================================================================
--- pypy/dist/pypy/lang/smalltalk/test/test_classtable.py (original)
+++ pypy/dist/pypy/lang/smalltalk/test/test_classtable.py Thu Oct 25 01:47:32 2007
@@ -20,3 +20,4 @@
def test_metaclass_of_metaclass_is_an_instance_of_metaclass():
assert ct.m_Metaclass.m_metaclass.m_metaclass is ct.m_Metaclass
+
Modified: pypy/dist/pypy/lang/smalltalk/test/test_miniimage.py
==============================================================================
--- pypy/dist/pypy/lang/smalltalk/test/test_miniimage.py (original)
+++ pypy/dist/pypy/lang/smalltalk/test/test_miniimage.py Thu Oct 25 01:47:32 2007
@@ -80,6 +80,13 @@
assert isinstance(w_float_class_name, sqm.W_BytesObject)
assert w_float_class_name.bytes == list("Float")
+
+ assert str(w_float_class) == "Float class"
+
+ assert str(w_float_class.getclass()) == "a Metaclass" # yes, with article here.
+
+ assert str(w_float_class.getclass().getclass()) == "Metaclass class"
+
def test_lookup_abs_in_integer():
image = create_squeakimage()
@@ -103,3 +110,4 @@
print interp.activeContext.stack
except sqi.ReturnFromTopLevel, e:
return e.object
+
More information about the Pypy-commit
mailing list