[pypy-svn] r55036 - in pypy/branch/smalltalk-shadow-changes/pypy/lang/smalltalk: . test
tverwaes at codespeak.net
tverwaes at codespeak.net
Tue May 20 20:16:10 CEST 2008
Author: tverwaes
Date: Tue May 20 20:16:09 2008
New Revision: 55036
Modified:
pypy/branch/smalltalk-shadow-changes/pypy/lang/smalltalk/model.py
pypy/branch/smalltalk-shadow-changes/pypy/lang/smalltalk/running-something-mini.image
pypy/branch/smalltalk-shadow-changes/pypy/lang/smalltalk/shadow.py
pypy/branch/smalltalk-shadow-changes/pypy/lang/smalltalk/test/test_miniimage.py
Log:
(cfbolz, tverwaes) adding tests for partly image continuating
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 Tue May 20 20:16:09 2008
@@ -319,8 +319,11 @@
def as_context_get_shadow(self):
from pypy.lang.smalltalk.shadow import ContextPartShadow
# XXX TODO should figure out itself if its method or block context
- assert self._shadow is not None
- return self.as_special_get_shadow(ContextPartShadow)
+ if self._shadow is None:
+ if ContextPartShadow.is_block_context(self):
+ return self.as_blockcontext_get_shadow()
+ return self.as_methodcontext_get_shadow()
+ return self._shadow
def as_methoddict_get_shadow(self):
from pypy.lang.smalltalk.shadow import MethodDictionaryShadow
Modified: pypy/branch/smalltalk-shadow-changes/pypy/lang/smalltalk/running-something-mini.image
==============================================================================
Binary files. No diff available.
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 Tue May 20 20:16:09 2008
@@ -308,7 +308,12 @@
self._stack = []
AbstractRedirectingShadow.__init__(self, w_self)
- # TODO test
+ @staticmethod
+ def is_block_context(w_pointers):
+ from pypy.lang.smalltalk.classtable import w_SmallInteger
+ method_or_argc = w_pointers.fetch(constants.MTHDCTX_METHOD)
+ return method_or_argc.getclass().is_same_object(w_SmallInteger)
+
def fetch(self, n0):
if n0 == constants.CTXPART_SENDER_INDEX:
return self.w_sender()
@@ -325,7 +330,6 @@
# XXX later should store tail out of known context part as well
raise error.WrapperException("Index in context out of bounds")
- # TODO test
def store(self, n0, w_value):
if n0 == constants.CTXPART_SENDER_INDEX:
return self.store_w_sender(w_value)
@@ -349,7 +353,6 @@
self.store_stackpointer(utility.unwrap_int(w_sp1) -
self.tempframesize())
- # TODO test
def store_stackpointer(self, size):
from pypy.lang.smalltalk import objtable
if size < len(self._stack):
@@ -362,7 +365,6 @@
return utility.wrap_int(len(self._stack) +
self.tempframesize())
- # TODO test
def external_stackpointer(self):
return len(self._stack) + self.stackstart()
@@ -397,14 +399,12 @@
else:
return w_sender.as_context_get_shadow()
- # TODO test
def store_unwrap_pc(self, w_pc):
pc = utility.unwrap_int(w_pc)
pc -= self.w_method().bytecodeoffset()
pc -= 1
self.store_pc(pc)
- # TODO test
def wrap_pc(self):
pc = self.pc()
pc += 1
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 Tue May 20 20:16:09 2008
@@ -12,11 +12,12 @@
from pypy.lang.smalltalk import utility
# lazy initialization of test data, ie ImageReader and Float class
-def setup_module(module):
+def setup_module(module, filename='mini.image'):
+ # XXX XXX find a way to get rid of global state
global mini_image
global reader
global image
- mini_image = py.magic.autopath().dirpath().dirpath().join('mini.image')
+ mini_image = py.magic.autopath().dirpath().dirpath().join(filename)
reader = open_miniimage()
reader.initialize()
image = squeakimage.SqueakImage()
@@ -228,18 +229,10 @@
def test_runimage():
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()
- s_ap = s_scheduler.s_active_process()
- s_ctx = s_ap.w_suspended_context().as_methodcontext_get_shadow()
- s_ap.store_w_suspended_context(objtable.w_nil)
-
- # XXX Important
- # Push return value of snapshot primitive
- # The interpreter must resume at the very moment the snapshot primitive
- # returns.
- s_ctx._stack = [objtable.w_true]
+ from pypy.lang.smalltalk import wrapper
+ ap = wrapper.ProcessWraper(wrapper.scheduler().active_process())
+ s_ctx = ap.suspended_context().as_methodcontext_get_shadow()
+ ap.store_suspended_context(objtable.w_nil)
interp = interpreter.Interpreter()
interp.store_w_active_context(s_ctx.w_self())
@@ -285,3 +278,29 @@
#print interp.s_active_context.stack
except interpreter.ReturnFromTopLevel, e:
return e.object
+
+def test_step_forged_image():
+ from pypy.lang.smalltalk import wrapper
+ ap = wrapper.ProcessWrapper(wrapper.scheduler().active_process())
+ s_ctx = ap.suspended_context().as_context_get_shadow()
+ assert isinstance(s_ctx, shadow.BlockContextShadow)
+ assert s_ctx.top().is_same_object(objtable.w_true)
+
+def test_step_forged_image():
+ setup_module(None, filename='running-something-mini.image')
+ from pypy.lang.smalltalk import wrapper
+ ap = wrapper.ProcessWrapper(wrapper.scheduler().active_process())
+ s_ctx = ap.suspended_context().as_context_get_shadow()
+ ap.store_suspended_context(objtable.w_nil)
+
+ interp = interpreter.Interpreter()
+ interp.store_w_active_context(s_ctx.w_self())
+ assert isinstance(s_ctx, shadow.MethodContextShadow)
+ assert interp.s_active_context().top().is_same_object(objtable.w_true)
+ interp.step()
+ interp.step()
+ assert interp.s_active_context().top().value == 1
+ interp.step()
+ assert interp.s_active_context().top().value == 2
+ interp.step()
+ assert interp.s_active_context().top().value == 3
More information about the Pypy-commit
mailing list