[pypy-svn] r51806 - in pypy/branch/smalltalk-shadow-changes/pypy/lang/smalltalk: . test
tverwaes at codespeak.net
tverwaes at codespeak.net
Fri Feb 22 19:24:50 CET 2008
Author: tverwaes
Date: Fri Feb 22 19:24:49 2008
New Revision: 51806
Modified:
pypy/branch/smalltalk-shadow-changes/pypy/lang/smalltalk/model.py
pypy/branch/smalltalk-shadow-changes/pypy/lang/smalltalk/shadow.py
pypy/branch/smalltalk-shadow-changes/pypy/lang/smalltalk/test/test_miniimage.py
pypy/branch/smalltalk-shadow-changes/pypy/lang/smalltalk/test/test_model.py
Log:
fixing literalat0 literalatput0, at0 and atput0 for compiledmethods.
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:24:49 2008
@@ -454,24 +454,26 @@
def at0(self, index0):
from pypy.lang.smalltalk import utility
- # XXX Not tested
- index0 -= self.headersize()
- if index0 < self.getliteralsize():
- self.literalat0(index0)
+ if index0 <= self.getliteralsize():
+ return self.literalat0(index0/constants.BYTES_PER_WORD)
else:
- index0 = index0 - self.getliteralsize()
+ # From blue book:
+ # The literal count indicates the size of the
+ # CompiledMethod's literal frame.
+ # This, in turn, indicates where the
+ # CompiledMethod's bytecodes start.
+ index0 = index0 - self.getliteralsize() - self.headersize()
assert index0 < len(self.bytes)
return utility.wrap_int(ord(self.bytes[index0]))
def atput0(self, index0, w_value):
from pypy.lang.smalltalk import utility
- # XXX Not tested
- index0 -= self.headersize()
- if index0 < self.getliteralsize():
- self.literalatput0(index0, w_value)
+ if index0 <= self.getliteralsize():
+ self.literalatput0(index0/constants.BYTES_PER_WORD, w_value)
else:
# XXX use to-be-written unwrap_char
- index0 = index0 - self.getliteralsize()
+ index0 = index0 - self.getliteralsize() - self.headersize()
+ assert index0 < len(self.bytes)
self.setchar(index0, chr(utility.unwrap_int(w_value)))
def setchar(self, index0, character):
Modified: pypy/branch/smalltalk-shadow-changes/pypy/lang/smalltalk/shadow.py
==============================================================================
--- pypy/branch/smalltalk-shadow-changes/pypy/lang/smalltalk/shadow.py (original)
+++ pypy/branch/smalltalk-shadow-changes/pypy/lang/smalltalk/shadow.py Fri Feb 22 19:24:49 2008
@@ -351,7 +351,9 @@
self.w_self().store(constants.PROCESS_MY_LIST_INDEX, w_object)
def s_suspended_context(self):
- return self.w_self().fetch(constants.PROCESS_SUSPENDED_CONTEXT_INDEX).as_context_get_shadow()
+ # XXX Can currently only restart context if it is a method context...
+ # XXX Depends on typechecking ...
+ return self.w_self().fetch(constants.PROCESS_SUSPENDED_CONTEXT_INDEX).as_methodcontext_get_shadow()
def store_w_suspended_context(self, w_object):
self.w_self().store(constants.PROCESS_SUSPENDED_CONTEXT_INDEX, w_object)
Modified: pypy/branch/smalltalk-shadow-changes/pypy/lang/smalltalk/test/test_miniimage.py
==============================================================================
--- pypy/branch/smalltalk-shadow-changes/pypy/lang/smalltalk/test/test_miniimage.py (original)
+++ pypy/branch/smalltalk-shadow-changes/pypy/lang/smalltalk/test/test_miniimage.py Fri Feb 22 19:24:49 2008
@@ -91,6 +91,7 @@
def test_str_w_object():
w_float_class = get_float_class()
+ w_float_class.as_class_get_shadow()
assert str(w_float_class) == "Float class"
assert str(w_float_class.getclass()) == "a Metaclass" #yes, with article
assert str(w_float_class.getclass().getclass()) == "Metaclass class"
@@ -227,7 +228,7 @@
assert w_false is objtable.w_false
def test_runimage():
- #py.test.skip("This method actually runs an image. Fails since no graphical primitives yet")
+ py.test.skip("This method actually runs an image. Fails since no graphical primitives yet")
from pypy.lang.smalltalk.shadow import SemaphoreShadow
s_semaphore = SemaphoreShadow(None)
s_scheduler = s_semaphore.s_scheduler()
@@ -239,7 +240,7 @@
interp.interpret()
def test_compile_method():
- py.test.skip("Not working yet.")
+ #py.test.skip("Not working yet.")
sourcecode = """fib
^self < 2
ifTrue: [ 1 ]
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:24:49 2008
@@ -1,7 +1,7 @@
import py
from pypy.lang.smalltalk import model, shadow, objtable
from pypy.lang.smalltalk.shadow import MethodNotFound
-from pypy.lang.smalltalk import classtable
+from pypy.lang.smalltalk import classtable, utility
mockclass = classtable.bootstrap_class
@@ -85,3 +85,24 @@
h2 = w_inst.gethash()
assert h1 == h2
assert h1 == w_inst.hash
+
+def test_compiledmethod_fetchbyte():
+ w_method = model.W_CompiledMethod()
+ w_method.bytes = "abc"
+ w_method.literalsize = 2
+ w_method.fetchbyte(9) == ord('a')
+ w_method.fetchbyte(10) == ord('b')
+ w_method.fetchbyte(11) == ord('c')
+
+def test_compiledmethod_at0():
+ w_method = model.W_CompiledMethod()
+ w_method.bytes = "abc"
+ w_method.header = 100
+ w_method.literals = [ 'lit1', 'lit2' ]
+ w_method.literalsize = 2
+ assert utility.unwrap_int(w_method.at0(0)) == 100
+ 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