[pypy-svn] r51807 - in pypy/branch/smalltalk-shadow-changes/pypy/lang/smalltalk: . test

tverwaes at codespeak.net tverwaes at codespeak.net
Fri Feb 22 19:41:38 CET 2008


Author: tverwaes
Date: Fri Feb 22 19:41:37 2008
New Revision: 51807

Modified:
   pypy/branch/smalltalk-shadow-changes/pypy/lang/smalltalk/model.py
   pypy/branch/smalltalk-shadow-changes/pypy/lang/smalltalk/test/test_model.py
Log:
adding test for at0 atput0 for compiled methods


Modified: pypy/branch/smalltalk-shadow-changes/pypy/lang/smalltalk/model.py
==============================================================================
--- pypy/branch/smalltalk-shadow-changes/pypy/lang/smalltalk/model.py	(original)
+++ pypy/branch/smalltalk-shadow-changes/pypy/lang/smalltalk/model.py	Fri Feb 22 19:41:37 2008
@@ -468,6 +468,8 @@
         
     def atput0(self, index0, w_value):
         from pypy.lang.smalltalk import utility
+        print index0
+        print self.getliteralsize()
         if index0 <= self.getliteralsize():
             self.literalatput0(index0/constants.BYTES_PER_WORD, w_value)
         else:

Modified: pypy/branch/smalltalk-shadow-changes/pypy/lang/smalltalk/test/test_model.py
==============================================================================
--- pypy/branch/smalltalk-shadow-changes/pypy/lang/smalltalk/test/test_model.py	(original)
+++ pypy/branch/smalltalk-shadow-changes/pypy/lang/smalltalk/test/test_model.py	Fri Feb 22 19:41:37 2008
@@ -3,6 +3,13 @@
 from pypy.lang.smalltalk.shadow import MethodNotFound
 from pypy.lang.smalltalk import classtable, utility
 
+def joinbits(values, lengths):
+    result = 0
+    for each, length in reversed(zip(values, lengths)):
+        result = result << length
+        result += each
+    return result   
+
 mockclass = classtable.bootstrap_class
 
 def test_new():
@@ -106,3 +113,21 @@
     assert utility.unwrap_int(w_method.at0(12)) == ord('a')
     assert utility.unwrap_int(w_method.at0(13)) == ord('b')
     assert utility.unwrap_int(w_method.at0(14)) == ord('c')
+
+def test_compiledmethod_atput0():
+    w_method = model.W_CompiledMethod(3)
+    newheader = joinbits([0,2,0,0,0,0],[9,8,1,6,4,1])
+    assert w_method.getliteralsize() == 0
+    w_method.atput0(0, utility.wrap_int(newheader))
+    assert w_method.getliteralsize() == 8 # 2 from new header * BYTES_PER_WORD (= 4)
+    w_method.atput0(4, 'lit1')
+    w_method.atput0(8, 'lit2')
+    w_method.atput0(12, utility.wrap_int(ord('a')))
+    w_method.atput0(13, utility.wrap_int(ord('b')))
+    w_method.atput0(14, utility.wrap_int(ord('c')))
+    assert utility.unwrap_int(w_method.at0(0)) == newheader
+    assert w_method.at0(4) == 'lit1'
+    assert w_method.at0(8) == 'lit2'
+    assert utility.unwrap_int(w_method.at0(12)) == ord('a')
+    assert utility.unwrap_int(w_method.at0(13)) == ord('b')
+    assert utility.unwrap_int(w_method.at0(14)) == ord('c')



More information about the Pypy-commit mailing list