[pypy-svn] r47870 - in pypy/dist/pypy/lang/smalltalk: . tool

tverwaes at codespeak.net tverwaes at codespeak.net
Wed Oct 24 23:50:48 CEST 2007


Author: tverwaes
Date: Wed Oct 24 23:50:47 2007
New Revision: 47870

Modified:
   pypy/dist/pypy/lang/smalltalk/constants.py
   pypy/dist/pypy/lang/smalltalk/interpreter.py
   pypy/dist/pypy/lang/smalltalk/model.py
   pypy/dist/pypy/lang/smalltalk/squeakimage.py
   pypy/dist/pypy/lang/smalltalk/tool/analyseimage.py
Log:
Added methodlookup and hacky test in tool/analysis



Modified: pypy/dist/pypy/lang/smalltalk/constants.py
==============================================================================
--- pypy/dist/pypy/lang/smalltalk/constants.py	(original)
+++ pypy/dist/pypy/lang/smalltalk/constants.py	Wed Oct 24 23:50:47 2007
@@ -13,6 +13,8 @@
 CLASS_METHODDICT_INDEX = 1
 CLASS_FORMAT_INDEX     = 2
 
+METHODDICT_VALUES_INDEX = 1
+METHODDICT_NAMES_INDEX  = 2
 
 # ----- special objects indices -------
 

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 23:50:47 2007
@@ -139,11 +139,14 @@
         if method.primitive:
             func = primitives.prim_table[method.primitive]
             try:
+                print "Going to send primitive"
                 w_result = func(self)
             except primitives.PrimitiveFailedError:
+                print "Primitive failed"
                 pass # ignore this error and fall back to the Smalltalk version
             else:
                 # the primitive succeeded
+                print "Pushing primitive result on stack"
                 self.push(w_result)
                 return
         arguments = self.stack[len(self.stack)-argcount:]
@@ -296,9 +299,13 @@
     def callPrimitiveAndPush(self, primitive, selector,
                              argcount, interp):
         try:
+            print "Pushing result"
             self.push(primitives.prim_table[primitive](self))
+            print "Pushed result"
         except primitives.PrimitiveFailedError:
+            print "Falling back to smalltalk version"
             self._sendSelfSelector(selector, argcount, interp)
+            print "Fallback succeeded"
 
     def bytecodePrimAdd(self, interp):
         self.callPrimitiveAndPush(primitives.ADD, "+", 1, interp)
@@ -514,17 +521,3 @@
     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 23:50:47 2007
@@ -1,7 +1,10 @@
 import sys
 from pypy.rlib import rrandom
 from pypy.rlib.rarithmetic import intmask
+from pypy.lang.smalltalk import constants as sqc
 
+class MethodNotFound(Exception):
+    pass
 
 class W_Object(object):
 
@@ -101,6 +104,33 @@
         return (W_AbstractObjectWithClassReference.invariant(self) and
                 isinstance(self.vars, list))
 
+    def compiledmethodnamed(self, methodname):
+        w_methoddict = self.fetch(sqc.CLASS_METHODDICT_INDEX).vars
+        names  = w_methoddict[sqc.METHODDICT_NAMES_INDEX:]
+        values = w_methoddict[sqc.METHODDICT_VALUES_INDEX].vars
+        for var in names:
+            if isinstance(var, W_BytesObject):
+                if str(var) == repr(methodname):
+                    return values[names.index(var)]
+        raise MethodNotFound
+
+    def lookup(self, methodname):
+        in_class = self
+        while in_class != None:
+            try:
+                return in_class.compiledmethodnamed(methodname)
+            except MethodNotFound:
+                # Current hack because we don't have a ref to the real
+                # nil yet... XXX XXX XXX
+                try:
+                    new_class = in_class.vars[sqc.CLASS_SUPERCLASS_INDEX]
+                    if in_class == new_class:
+                        raise Exception
+                    else:
+                        in_class = new_class
+                except:
+                    return self.lookup("doesNotUnderstand")
+
 class W_BytesObject(W_AbstractObjectWithClassReference):
     def __init__(self, m_class, size):
         W_AbstractObjectWithClassReference.__init__(self, m_class)

Modified: pypy/dist/pypy/lang/smalltalk/squeakimage.py
==============================================================================
--- pypy/dist/pypy/lang/smalltalk/squeakimage.py	(original)
+++ pypy/dist/pypy/lang/smalltalk/squeakimage.py	Wed Oct 24 23:50:47 2007
@@ -332,7 +332,7 @@
             splitbits(header, [1,9,8,1,6,4,1]))
         primitive = primitive + (highbit << 10) ##XXX todo, check this
         # --------------------
-        literals = [self.decode_pointer(pointer)
+        literals = [self.decode_pointer(pointer).w_object
                     for pointer in self.chunk.data[:literalsize+1]]
         # --------------------
         l = []
@@ -348,6 +348,8 @@
             argsize = numargs,
             tempsize = tempsize,
             primitive = primitive)
+
+        w_compiledmethod.literals = literals
              
     
 

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 23:50:47 2007
@@ -1,6 +1,7 @@
 import autopath
 import py
 from pypy.lang.smalltalk import squeakimage as sq
+from pypy.lang.smalltalk import constants as sqc
 from pypy.lang.smalltalk import model as sqm
 from pypy.lang.smalltalk import interpreter as sqi
 
@@ -23,11 +24,6 @@
         if isinstance(each,sqm.W_BytesObject):
           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:
@@ -39,12 +35,12 @@
     image = create_squeakimage()
     amethod = None
 
-    w_float_class = image.special(sq.FLOAT_CLASS)
+    w_smallint_class = image.special(sqc.SO_SMALLINTEGER_CLASS)
 
     interp = sqi.Interpreter()
-    anObject = sqm.W_Float(1.5)
-    amethod = getMethodFromClass(w_float_class,"abs")
-                                # receiver, arguments
+    anObject = sqm.W_PointersObject(w_smallint_class, 1)
+    anObject.vars[0] = 3
+    amethod = w_smallint_class.lookup("abs")
     w_frame = amethod.createFrame(anObject, [])
     interp.activeContext = w_frame
 



More information about the Pypy-commit mailing list