1. Pypy
  2. Untitled project
  3. lang-smalltalk

Commits

Lars Wassermann  committed 4398592

fixed bitBlit primitive and test
fixed some problems with testing sequence

  • Participants
  • Parent commits 1330f5e
  • Branches default

Comments (0)

Files changed (5)

File spyvm/interpreter.py

View file
  • Ignore whitespace
         self._loop = True
         s_new_context = w_active_context.as_context_get_shadow(self.space)
         while True:
+            assert self.remaining_stack_depth == self.max_stack_depth
             s_sender = s_new_context.s_sender()
             try:
                 s_new_context = self.c_loop(s_new_context)
             except StackOverflow, e:
-                self.remaining_stack_depth = self.max_stack_depth
                 s_new_context = e.s_context
             except Return, nlr:
                 while s_new_context is not nlr.s_target_context:
                     s_new_context.mark_returned()
                     s_new_context = s_sender
-                self.remaining_stack_depth = self.max_stack_depth
                 s_new_context.push(nlr.value)
             except ProcessSwitch, p:
-                self.remaining_stack_depth = self.max_stack_depth
                 s_new_context = p.s_new_context
 
     def c_loop(self, s_context):
         if not self._loop:
             return s_new_frame # this test is done to not loop in test,
                                # but rather step just once where wanted
-        if self.remaining_stack_depth == 1:
+        if self.remaining_stack_depth <= 1:
             raise StackOverflow(s_new_frame)
 
         self.remaining_stack_depth -= 1

File spyvm/primitives.py

View file
  • Ignore whitespace
     if not isinstance(w_rcvr, model.W_PointersObject) or w_rcvr.size() < 15:
         raise PrimitiveFailedError
 
-    interp.perform(w_rcvr, "simulateCopyBits")
+    space = interp.space
+    s_frame.push(w_rcvr)
+    s_frame._sendSelfSelector(interp.image.w_simulateCopyBits, 0, interp)
 
-    w_dest_form = w_rcvr.fetch(interp.space, 0)
-    if w_dest_form.is_same_object(interp.space.objtable['w_display']):
-        w_bitmap = w_dest_form.fetch(interp.space, 0)
+    w_dest_form = w_rcvr.fetch(space, 0)
+    if w_dest_form.is_same_object(space.objtable['w_display']):
+        w_bitmap = w_dest_form.fetch(space, 0)
         assert isinstance(w_bitmap, model.W_DisplayBitmap)
         w_bitmap.flush_to_screen()
 

File spyvm/squeakimage.py

View file
  • Ignore whitespace
         for name, idx in constants.objects_in_special_object_table.items():
             space.objtable["w_" + name] = self.special_objects[idx]
 
-        self.w_asSymbol = self.find_asSymbol(space, reader)
+        self.w_asSymbol = self.find_symbol(space, reader, "asSymbol")
+        self.w_simulateCopyBits = self.find_symbol(space, reader, "simulateCopyBits")
 
-    def find_asSymbol(self, space, reader):
+    def find_symbol(self, space, reader, symbol):
         w_dnu = self.special(constants.SO_DOES_NOT_UNDERSTAND)
         assert isinstance(w_dnu, model.W_BytesObject)
         assert w_dnu.as_string() == "doesNotUnderstand:"
                 continue
             if not w_obj.getclass(space).is_same_object(w_Symbol):
                 continue
-            if w_obj.as_string() == "asSymbol":
+            if w_obj.as_string() == symbol:
                 break
         assert w_obj is not None
         return w_obj

File spyvm/test/test_miniimage.py

View file
  • Ignore whitespace
     size = prim(primitives.PERFORM_WITH_ARGS, [w_o, w_sel, []])
     assert size.value == 3
 
-def test_step_run_something():
-    from spyvm.test import test_miniimage
-    setup_module(test_miniimage, filename='running-something-mini.image')
-    from spyvm import wrapper
-    ap = wrapper.ProcessWrapper(space, wrapper.scheduler(space).active_process())
-    w_ctx = ap.suspended_context()
-    s_ctx = w_ctx.as_context_get_shadow(space)
-    ap.store_suspended_context(space.w_nil)
-
-    interp = interpreter.Interpreter(space)
-    assert isinstance(s_ctx, shadow.MethodContextShadow)
-    assert s_ctx.top().is_same_object(space.w_true)
-    interp.step(s_ctx)
-    interp.step(s_ctx)
-    assert s_ctx.top().value == 1
-    interp.step(s_ctx)
-    assert s_ctx.top().value == 2
-    interp.step(s_ctx)
-    assert s_ctx.top().value == 3
-
 def test_create_new_symbol():
     w_result = perform(w("someString"), "asSymbol")
     assert w_result is not None
     assert s_message_cls.getname() == "Message class"
     w_message = s_message_cls.new()
     assert isinstance(w_message, model.W_PointersObject)
+
+def test_step_run_something():
+    from spyvm.test import test_miniimage
+    setup_module(test_miniimage, filename='running-something-mini.image')
+    from spyvm import wrapper
+    ap = wrapper.ProcessWrapper(space, wrapper.scheduler(space).active_process())
+    w_ctx = ap.suspended_context()
+    s_ctx = w_ctx.as_context_get_shadow(space)
+    ap.store_suspended_context(space.w_nil)
+
+    interp = interpreter.Interpreter(space)
+    assert isinstance(s_ctx, shadow.MethodContextShadow)
+    assert s_ctx.top().is_same_object(space.w_true)
+    interp.step(s_ctx)
+    interp.step(s_ctx)
+    assert s_ctx.top().value == 1
+    interp.step(s_ctx)
+    assert s_ctx.top().value == 2
+    interp.step(s_ctx)
+    assert s_ctx.top().value == 3

File spyvm/test/test_primitives.py

View file
  • Ignore whitespace
 def test_bitblt_copy_bits(monkeypatch):
     class CallCopyBitsSimulation(Exception):
         pass
+    class Image():
+        def __init__(self):
+            self.w_simulateCopyBits = "simulateCopyBits"
 
     mock_bitblt = model.W_PointersObject(space.w_Point, 15)
 
-    def perform_mock(w_rcvr, string):
-        if w_rcvr is mock_bitblt and string == "simulateCopyBits":
+    def perform_mock(w_selector, argcount, interp):
+        if w_selector == "simulateCopyBits" or w_selector.as_string() == "simulateCopyBits":
+            assert argcount == 0
             raise CallCopyBitsSimulation
 
     interp, w_frame, argument_count = mock([mock_bitblt], None)
+    if interp.image is None:
+        interp.image = Image()
 
     try:
-        monkeypatch.setattr(interp, "perform", perform_mock)
+        monkeypatch.setattr(w_frame._shadow, "_sendSelfSelector", perform_mock)
         with py.test.raises(CallCopyBitsSimulation):
             prim_table[primitives.BITBLT_COPY_BITS](interp, w_frame.as_context_get_shadow(space), argument_count-1)
     finally:
         monkeypatch.undo()
+    assert w_frame._shadow.pop() is mock_bitblt # the new receiver
+    assert w_frame._shadow.pop() is mock_bitblt # previous state is still there
 
 # Note:
 #   primitives.NEXT is unimplemented as it is a performance optimization