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

tverwaes at codespeak.net tverwaes at codespeak.net
Tue May 27 20:30:17 CEST 2008


Author: tverwaes
Date: Tue May 27 20:30:13 2008
New Revision: 55317

Modified:
   pypy/branch/smalltalk-shadow-changes/pypy/lang/smalltalk/constants.py
   pypy/branch/smalltalk-shadow-changes/pypy/lang/smalltalk/interpreter.py
   pypy/branch/smalltalk-shadow-changes/pypy/lang/smalltalk/objspace.py
   pypy/branch/smalltalk-shadow-changes/pypy/lang/smalltalk/primitives.py
   pypy/branch/smalltalk-shadow-changes/pypy/lang/smalltalk/test/test_interpreter.py
   pypy/branch/smalltalk-shadow-changes/pypy/lang/smalltalk/test/test_miniimage.py
   pypy/branch/smalltalk-shadow-changes/pypy/lang/smalltalk/test/test_wrapper.py
   pypy/branch/smalltalk-shadow-changes/pypy/lang/smalltalk/wrapper.py
Log:
adding support for Points for the become-test which we compile in
test_miniimage


Modified: pypy/branch/smalltalk-shadow-changes/pypy/lang/smalltalk/constants.py
==============================================================================
--- pypy/branch/smalltalk-shadow-changes/pypy/lang/smalltalk/constants.py	(original)
+++ pypy/branch/smalltalk-shadow-changes/pypy/lang/smalltalk/constants.py	Tue May 27 20:30:13 2008
@@ -108,7 +108,7 @@
     "Float" : SO_FLOAT_CLASS,
     "MethodContext" : SO_METHODCONTEXT_CLASS,
     "BlockContext" : SO_BLOCKCONTEXT_CLASS,
-#    "Point" : SO_POINT_CLASS,
+    "Point" : SO_POINT_CLASS,
 #    "LargePositiveInteger" : SO_LARGEPOSITIVEINTEGER_CLASS,
 #    "Display" : SO_DISPLAY_CLASS,
 #    "Message" : SO_MESSAGE_CLASS,

Modified: pypy/branch/smalltalk-shadow-changes/pypy/lang/smalltalk/interpreter.py
==============================================================================
--- pypy/branch/smalltalk-shadow-changes/pypy/lang/smalltalk/interpreter.py	(original)
+++ pypy/branch/smalltalk-shadow-changes/pypy/lang/smalltalk/interpreter.py	Tue May 27 20:30:13 2008
@@ -441,7 +441,7 @@
         self.callPrimitive(primitives.MOD, "\\\\", 1, interp)
 
     def bytecodePrimMakePoint(self, interp):
-        raise MissingBytecode("bytecodePrimMakePoint")
+        self.callPrimitive(primitives.MAKE_POINT, "@", 1, interp)
 
     def bytecodePrimBitShift(self, interp):
         self.callPrimitive(primitives.BIT_SHIFT, "bitShift:", 1, interp)

Modified: pypy/branch/smalltalk-shadow-changes/pypy/lang/smalltalk/objspace.py
==============================================================================
--- pypy/branch/smalltalk-shadow-changes/pypy/lang/smalltalk/objspace.py	(original)
+++ pypy/branch/smalltalk-shadow-changes/pypy/lang/smalltalk/objspace.py	Tue May 27 20:30:13 2008
@@ -106,6 +106,7 @@
         define_cls("w_MethodContext", "w_ContextPart")
         define_cls("w_Link", "w_Object")
         define_cls("w_Process", "w_Link")
+        define_cls("w_Point", "w_Object")
         define_cls("w_LinkedList", "w_SequenceableCollection")
         define_cls("w_Semaphore", "w_LinkedList")
         define_cls("w_BlockContext", "w_ContextPart",

Modified: pypy/branch/smalltalk-shadow-changes/pypy/lang/smalltalk/primitives.py
==============================================================================
--- pypy/branch/smalltalk-shadow-changes/pypy/lang/smalltalk/primitives.py	(original)
+++ pypy/branch/smalltalk-shadow-changes/pypy/lang/smalltalk/primitives.py	Tue May 27 20:30:13 2008
@@ -280,10 +280,21 @@
     w_res = interp.space.wrap_float(math.exp(f))
     return w_res
 
+MAKE_POINT = 18
+
+ at expose_primitive(MAKE_POINT, unwrap_spec=[int, int])
+def func(interp, x, y):
+    w_res = interp.space.classtable['w_Point'].as_class_get_shadow(interp.space).new(2)
+    point = wrapper.PointWrapper(interp.space, w_res)
+    point.store_x(interp.space, x)
+    point.store_y(interp.space, y)
+    return w_res
+
+
 # ___________________________________________________________________________
 # Failure
 
-FAIL = 18
+FAIL = 19
 
 # ___________________________________________________________________________
 # Subscript and Stream Primitives

Modified: pypy/branch/smalltalk-shadow-changes/pypy/lang/smalltalk/test/test_interpreter.py
==============================================================================
--- pypy/branch/smalltalk-shadow-changes/pypy/lang/smalltalk/test/test_interpreter.py	(original)
+++ pypy/branch/smalltalk-shadow-changes/pypy/lang/smalltalk/test/test_interpreter.py	Tue May 27 20:30:13 2008
@@ -454,6 +454,19 @@
           1, "sub"]],
         test)
 
+def test_makePoint():
+    interp = new_interpreter(pushConstantZeroBytecode +
+                             pushConstantOneBytecode +
+                             bytecodePrimMakePoint)
+    interp.step()
+    interp.step()
+    interp.step()
+    w_point = interp.s_active_context().top()
+    from pypy.lang.smalltalk.wrapper import PointWrapper
+    point = PointWrapper(interp.space, w_point)
+    assert point.x(interp.space) == 0
+    assert point.y(interp.space) == 1
+
 def test_longJumpIfTrue():
     interp = new_interpreter(longJumpIfTrue(0) + chr(15) + longJumpIfTrue(0) + chr(15))
     interp.s_active_context().push(space.w_false)

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 27 20:30:13 2008
@@ -225,7 +225,7 @@
     interp = interpreter.Interpreter()
     interp.store_w_active_context(s_ctx.w_self())
     interp.interpret()
-    
+
 def test_compile_method():
     sourcecode = """fib 
                         ^self < 2 
@@ -234,6 +234,7 @@
     perform(w(10).getclass(space), "compile:classified:notifying:", w(sourcecode), w('pypy'), w(None))
     assert perform(w(10), "fib").is_same_object(w(89))
 
+
 def w(any): 
     # XXX could put this on the space?
     if any is None:
@@ -244,15 +245,40 @@
             return space.wrap_chr(any)
         else:
             return space.wrap_string(any)
-    if isinstance(any, int):    
-        return space.wrap_int(any)
     if isinstance(any, bool):
         return space.wrap_bool(any)
+    if isinstance(any, int):    
+        return space.wrap_int(any)
     if isinstance(any, float):
         return space.wrap_float(any)
     else:
         raise Exception    
-        
+
+def test_become():
+    sourcecode = """
+    testBecome
+      | p1 p2 a |
+      p1 := 1 at 2.
+      p2 := #(3 4 5).
+      a := p1 -> p2.
+      (1 at 2 = a key)        ifFalse: [^false].
+      (#(3 4 5) = a value) ifFalse: [^false].
+      (p1 -> p2 = a)       ifFalse: [^false].
+      (p1 == a key)        ifFalse: [^false].
+      (p2 == a value)      ifFalse: [^false].
+      p1 become: p2.
+      (1 at 2 = a value)      ifFalse: [^false].
+      (#(3 4 5) = a key)   ifFalse: [^false].
+      (p1 -> p2 = a)       ifFalse: [^false].
+      (p1 == a key)        ifFalse: [^false].
+      (p2 == a value)      ifFalse: [^false].
+  
+      ^true"""
+    perform(w(10).getclass(space), "compile:classified:notifying:", w(sourcecode), w('pypy'), w(None))
+    w_true = w(True)
+    w_result = perform(w(10), "testBecome")
+    w_result.is_same_object(w_true)
+       
 def perform(w_receiver, selector, *arguments_w):
     interp = interpreter.Interpreter(space)
     s_class = w_receiver.shadow_of_my_class(space)

Modified: pypy/branch/smalltalk-shadow-changes/pypy/lang/smalltalk/test/test_wrapper.py
==============================================================================
--- pypy/branch/smalltalk-shadow-changes/pypy/lang/smalltalk/test/test_wrapper.py	(original)
+++ pypy/branch/smalltalk-shadow-changes/pypy/lang/smalltalk/test/test_wrapper.py	Tue May 27 20:30:13 2008
@@ -115,7 +115,7 @@
 def new_semaphore(excess_signals=0):
     w_semaphore = model.W_PointersObject(None, 3)
     semaphore = wrapper.SemaphoreWrapper(space, w_semaphore)
-    semaphore.store_excess_signals(space.wrap_int(excess_signals))
+    semaphore.store_excess_signals(space, excess_signals)
     return semaphore
 
         
@@ -203,9 +203,9 @@
 
     def test_semaphore_excess_signal(self):
         semaphore = new_semaphore()
-        
-        semaphore.signal(None)
-        assert space.unwrap_int(semaphore.excess_signals()) == 1
+        self.space = space
+        semaphore.signal(self)
+        assert semaphore.excess_signals(space) == 1
 
     def test_highest_priority(self):
         py.test.raises(FatalError, wrapper.scheduler(space).highest_priority_process)
@@ -227,7 +227,8 @@
 
     def test_semaphore_signal_wait(self):
         semaphore = new_semaphore()
-        semaphore.signal(None)
+        self.space = space
+        semaphore.signal(self)
         interp, process, old_process = self.make_processes(4, 2, space.w_false, space.w_true)
         semaphore.wait(interp)
         assert semaphore.is_empty_list()

Modified: pypy/branch/smalltalk-shadow-changes/pypy/lang/smalltalk/wrapper.py
==============================================================================
--- pypy/branch/smalltalk-shadow-changes/pypy/lang/smalltalk/wrapper.py	(original)
+++ pypy/branch/smalltalk-shadow-changes/pypy/lang/smalltalk/wrapper.py	Tue May 27 20:30:13 2008
@@ -32,7 +32,20 @@
 
 def make_getter_setter(index0):
     return make_getter(index0), make_setter(index0)
-    
+
+def make_int_getter(index0):
+    def getter(self, space):
+        return space.unwrap_int(self.read(index0))
+    return getter
+
+def make_int_setter(index0):
+    def setter(self, space, new):
+        return self.write(index0, space.wrap_int(new))
+    return setter
+
+def make_int_getter_setter(index0):
+    return make_int_getter(index0), make_int_setter(index0)
+   
 class LinkWrapper(Wrapper):
     next_link, store_next_link = make_getter_setter(0)
 
@@ -169,23 +182,43 @@
 
 class SemaphoreWrapper(LinkedListWrapper):
 
-    excess_signals, store_excess_signals = make_getter_setter(2)
+    excess_signals, store_excess_signals = make_int_getter_setter(2)
 
     def signal(self, interp):
         if self.is_empty_list():
-            w_value = self.excess_signals()
-            w_value = self.space.wrap_int(self.space.unwrap_int(w_value) + 1)
-            self.store_excess_signals(w_value)
+            value = self.excess_signals(interp.space)
+            self.store_excess_signals(interp.space, value + 1)
         else:
             process = self.remove_first_link_of_list()
             ProcessWrapper(self.space, process).resume(interp)
 
     def wait(self, interp):
-        excess = self.space.unwrap_int(self.excess_signals())
+        excess = self.excess_signals(interp.space)
         w_process = scheduler(interp.space).active_process()
         if excess > 0:
-            w_excess = self.space.wrap_int(excess - 1)
-            self.store_excess_signals(w_excess)
+            self.store_excess_signals(interp.space, excess - 1)
         else:
             self.add_last_link(w_process)
             ProcessWrapper(self.space, w_process).suspend(interp)
+
+class PointWrapper(Wrapper):
+    x, store_x = make_int_getter_setter(0)
+    y, store_y = make_int_getter_setter(1)
+
+# XXX Wrappers below are not used yet.
+class OffsetWrapper(Wrapper):
+    offset_x  = make_int_getter(0)
+    offset_y  = make_int_setter(1)
+
+class MaskWrapper(Wrapper):
+    bits       = make_getter(0)
+    extend_x   = make_int_getter(1)
+    extend_y   = make_int_getter(2)
+    depth      = make_int_getter(3)
+
+class CursorWrapper(MaskWrapper):
+    offset   = make_getter(4)
+ 
+class PointWrapper(Wrapper):
+    x, store_x = make_int_getter_setter(0)
+    y, store_y = make_int_getter_setter(1)



More information about the Pypy-commit mailing list