[pypy-commit] lang-smalltalk default: (timfel, cfbolz) start adding shadows to compiled methods
timfel
noreply at buildbot.pypy.org
Mon Feb 18 16:12:51 CET 2013
Author: Tim Felgentreff <timfelgentreff at gmail.com>
Branch:
Changeset: r36:8986dba2aebd
Date: 2013-02-18 15:08 +0100
http://bitbucket.org/pypy/lang-smalltalk/changeset/8986dba2aebd/
Log: (timfel, cfbolz) start adding shadows to compiled methods
diff --git a/spyvm/model.py b/spyvm/model.py
--- a/spyvm/model.py
+++ b/spyvm/model.py
@@ -464,6 +464,7 @@
def __init__(self, bytecount=0, header=0):
self.setheader(header)
self.bytes = ["\x00"] * bytecount
+ self._shadow = None
def become(self, w_other):
if not isinstance(w_other, W_CompiledMethod):
@@ -574,6 +575,15 @@
self.w_compiledin = None
self.islarge = islarge
+ def setbytes(self, bytes):
+ self.bytes = bytes
+
+ def as_compiledmethod_get_shadow(self, space):
+ from shadow import CompiledMethodShadow
+ if self._shadow is None:
+ self._shadow = CompiledMethodShadow(self)
+ return self._shadow
+
def literalat0(self, space, index0):
if index0 == 0:
return space.wrap_int(self.getheader())
diff --git a/spyvm/shadow.py b/spyvm/shadow.py
--- a/spyvm/shadow.py
+++ b/spyvm/shadow.py
@@ -706,3 +706,9 @@
def myblocksize(self):
return self.size() - self.tempsize()
+
+
+class CompiledMethodShadow(object):
+ def __init__(self, w_compiledmethod):
+ self.w_compiledmethod = w_compiledmethod
+ self.bytecode = "".join(w_compiledmethod.bytes)
diff --git a/spyvm/squeakimage.py b/spyvm/squeakimage.py
--- a/spyvm/squeakimage.py
+++ b/spyvm/squeakimage.py
@@ -373,6 +373,7 @@
w_bytesobject.w_class = w_class
w_bytesobject.bytes = self.get_bytes()
w_bytesobject.hash = self.chunk.hash12 # XXX check this
+
def get_bytes(self):
bytes = []
if self.reader.swap:
@@ -400,7 +401,7 @@
w_compiledmethod.literalatput0(
self.space, i, self.decode_pointer(self.chunk.data[i]).w_object)
bbytes = self.get_bytes()[(w_compiledmethod.literalsize + 1)*4:]
- w_compiledmethod.bytes = bbytes
+ w_compiledmethod.setbytes(bbytes)
class ImageChunk(object):
""" A chunk knows the information from the header, but the body of the
diff --git a/spyvm/test/test_shadow.py b/spyvm/test/test_shadow.py
--- a/spyvm/test/test_shadow.py
+++ b/spyvm/test/test_shadow.py
@@ -181,3 +181,9 @@
assert ([s_newobject.fetch(i) for i in range(s_newobject.size())] ==
[s_object.fetch(i) for i in range(s_newobject.size())])
assert w_object._shadow is s_newobject
+
+def test_compiledmethodshadow():
+ w_compiledmethod = model.W_CompiledMethod()
+ w_compiledmethod.setbytes(list("abc"))
+ shadow = w_compiledmethod.as_compiledmethod_get_shadow(space)
+ assert shadow.bytecode == "abc"
More information about the pypy-commit
mailing list