[pypy-svn] r47864 - in pypy/dist/pypy/lang/smalltalk: . test tool
tverwaes at codespeak.net
tverwaes at codespeak.net
Wed Oct 24 22:46:21 CEST 2007
Author: tverwaes
Date: Wed Oct 24 22:46:20 2007
New Revision: 47864
Modified:
pypy/dist/pypy/lang/smalltalk/interpreter.py
pypy/dist/pypy/lang/smalltalk/model.py
pypy/dist/pypy/lang/smalltalk/test/test_miniimage.py
pypy/dist/pypy/lang/smalltalk/tool/analyseimage.py
Log:
a starting point for method lookup in the analysis tool
Modified: pypy/dist/pypy/lang/smalltalk/interpreter.py
==============================================================================
--- pypy/dist/pypy/lang/smalltalk/interpreter.py (original)
+++ pypy/dist/pypy/lang/smalltalk/interpreter.py Wed Oct 24 22:46:20 2007
@@ -514,3 +514,17 @@
return result
BYTECODE_TABLE = initialize_bytecode_table()
+
+def initialize_readable_bytecode_table():
+ result = [None] * 256
+ for entry in BYTECODE_RANGES:
+ if len(entry) == 2:
+ positions = [entry[0]]
+ else:
+ positions = range(entry[0], entry[1]+1)
+ for pos in positions:
+ result[pos] = "%s(%d)" % (entry[-1],pos)
+ assert None not in result
+ return result
+
+READABLE_BYTECODE_TABLE = initialize_readable_bytecode_table()
Modified: pypy/dist/pypy/lang/smalltalk/model.py
==============================================================================
--- pypy/dist/pypy/lang/smalltalk/model.py (original)
+++ pypy/dist/pypy/lang/smalltalk/model.py Wed Oct 24 22:46:20 2007
@@ -27,6 +27,9 @@
def invariant(self):
return isinstance(self.value, int)
+ def __str__(self):
+ return "SmallInt(%d)" % self.value
+
class W_Float(W_Object):
def __init__(self, value):
self.value = value
@@ -41,6 +44,8 @@
def invariant(self):
return self.value is not None # XXX but later:
#return isinstance(self.value, float)
+ def __str__(self):
+ return "Float(%f)" % self.value
class W_ObjectWithStoredClass(W_Object):
""" The base class of objects that store 'm_class' explicitly. """
@@ -92,6 +97,9 @@
def size(self):
return len(self.bytes)
+ def __str__(self):
+ return repr("".join(self.bytes))
+
def invariant(self):
if not W_ObjectWithStoredClass.invariant(self):
return False
@@ -161,6 +169,12 @@
assert len(arguments) == self.argsize
return W_MethodContext(self, receiver, arguments, sender)
+ def __str__(self):
+ from pypy.lang.smalltalk.interpreter import BYTECODE_TABLE
+ return ("\n\nBytecode:\n---------------------\n" +
+ "\n".join([BYTECODE_TABLE[ord(i)].__name__ + " " + str(ord(i)) for i in self.bytes]) +
+ "\n---------------------\n")
+
def invariant(self):
return (W_Object.invariant(self) and
hasattr(self, 'literals') and
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 Wed Oct 24 22:46:20 2007
@@ -70,4 +70,3 @@
assert isinstance(w_float_class_name, sqm.W_BytesObject)
assert w_float_class_name.bytes == list("Float")
-
Modified: pypy/dist/pypy/lang/smalltalk/tool/analyseimage.py
==============================================================================
--- pypy/dist/pypy/lang/smalltalk/tool/analyseimage.py (original)
+++ pypy/dist/pypy/lang/smalltalk/tool/analyseimage.py Wed Oct 24 22:46:20 2007
@@ -21,48 +21,34 @@
image = create_squeakimage()
for each in image.objects:
if isinstance(each,sqm.W_BytesObject):
- print repr(''.join(each.bytes))
+ print each.bytes
def printReadableBytecode(bytecode):
print "\n\nBytecode:\n---------------------"
print "\n".join([sqi.BYTECODE_TABLE[ord(i)].__name__ for i in bytecode])
print "---------------------\n"
+def getMethodFromClass(w_class,methodname):
+ w_methoddict = w_class.fetch(1)
+ for var in w_methoddict.vars:
+ if isinstance(var,sqm.W_BytesObject):
+ if str(var) == repr(methodname):
+ return w_methoddict.vars[1].vars[w_methoddict.vars.index(var)-2]
def testCompiledMethods():
image = create_squeakimage()
amethod = None
- skip = 0
- for each in image.objects:
- if isinstance(each,sqm.W_CompiledMethod):
- if (each.argsize == 0 and amethod == None and
- each.tempsize == 0 and
- each.primitive == 0):
-
- if len(each.bytes) == 0:
- pass
- else:
- if skip >= SKIPMETHODS:
- amethod = each
- else:
- skip += 1
- #print "%d %d %d" % (each.argsize, each.tempsize, each.primitive)
-
- # receiver, arguments
- interp = sqi.Interpreter()
-
- anObject = sqm.W_PointersObject(sqm.W_Class(None,None,100),0)
- for i in range(0,99):
- anObject.store(i, interp.ONE)
+ w_float_class = image.special(sq.FLOAT_CLASS)
+ interp = sqi.Interpreter()
+ anObject = sqm.W_Float(1.5)
+ amethod = getMethodFromClass(w_float_class,"abs")
+ # receiver, arguments
w_frame = amethod.createFrame(anObject, [])
interp.activeContext = w_frame
- #w_frame.push(interp.TRUE)
- #w_frame.push(interp.ONE)
- #w_frame.push(interp.TWO)
- printReadableBytecode(amethod.bytes)
+ print amethod
while True:
try:
@@ -75,8 +61,8 @@
SKIPMETHODS=42 #X
def test_do():
- #testCompiledMethods()
- printStringsInImage()
+ testCompiledMethods()
+ #printStringsInImage()
if __name__ == '__main__':
test_do()
More information about the Pypy-commit
mailing list