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

tverwaes at codespeak.net tverwaes at codespeak.net
Fri Feb 22 01:18:40 CET 2008


Author: tverwaes
Date: Fri Feb 22 01:18:38 2008
New Revision: 51765

Modified:
   pypy/branch/smalltalk-shadow-changes/pypy/lang/smalltalk/classtable.py
   pypy/branch/smalltalk-shadow-changes/pypy/lang/smalltalk/constants.py
   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/squeakimage.py
   pypy/branch/smalltalk-shadow-changes/pypy/lang/smalltalk/test/test_shadow.py
Log:
adding tests + making sure Process and Semaphore are known to the VM, fixing
getting correct overloaded shadows


Modified: pypy/branch/smalltalk-shadow-changes/pypy/lang/smalltalk/classtable.py
==============================================================================
--- pypy/branch/smalltalk-shadow-changes/pypy/lang/smalltalk/classtable.py	(original)
+++ pypy/branch/smalltalk-shadow-changes/pypy/lang/smalltalk/classtable.py	Fri Feb 22 01:18:38 2008
@@ -111,8 +111,8 @@
 define_cls("w_SmallInteger", "w_Integer")
 define_cls("w_Float", "w_Number", format=shadow.BYTES)
 define_cls("w_Collection", "w_Object")
-define_cls("w_SequencableCollection", "w_Collection")
-define_cls("w_ArrayedCollection", "w_SequencableCollection")
+define_cls("w_SequenceableCollection", "w_Collection")
+define_cls("w_ArrayedCollection", "w_SequenceableCollection")
 define_cls("w_Array", "w_ArrayedCollection", varsized=True)
 define_cls("w_String", "w_ArrayedCollection", format=shadow.BYTES)
 define_cls("w_UndefinedObject", "w_Object")
@@ -122,9 +122,12 @@
 define_cls("w_ByteArray", "w_ArrayedCollection", format=shadow.BYTES)
 define_cls("w_MethodDict", "w_Object", instvarsize=2, varsized=True)
 define_cls("w_CompiledMethod", "w_ByteArray", format=shadow.COMPILED_METHOD)
-define_cls("w_MethodContext", "w_Object")
 define_cls("w_ContextPart", "w_Object")
 define_cls("w_MethodContext", "w_ContextPart")
+define_cls("w_Link", "w_Object")
+define_cls("w_Process", "w_Link")
+define_cls("w_LinkedList", "w_SequenceableCollection")
+define_cls("w_Semaphore", "w_LinkedList")
 define_cls("w_BlockContext", "w_ContextPart",
            instvarsize=constants.BLKCTX_TEMP_FRAME_START)
 

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	Fri Feb 22 01:18:38 2008
@@ -15,43 +15,53 @@
 CLASS_FORMAT_INDEX = 2
 CLASS_NAME_INDEX = 6                # in the mini.image, at least
 
-NEXT_LINK_INDEX = 0                 # "
+# Link
+NEXT_LINK_INDEX = 0                 
 
-PROCESS_SUSPENDED_CONTEXT_INDEX = 1 # "
-PROCESS_PRIORITY_INDEX = 2          # "
-PROCESS_MY_LIST_INDEX = 3           # "
-
-FIRST_LINK_INDEX = 0                # "
-LAST_LINK_INDEX = 1                 # "
-EXCESS_SIGNALS_INDEX = 2            # "
-
-SCHEDULER_PROCESS_LISTS_INDEX = 0   # "
-SCHEDULER_ACTIVE_PROCESS_INDEX = 1  # "
+# Process < Link
+PROCESS_SUSPENDED_CONTEXT_INDEX = 1 
+PROCESS_PRIORITY_INDEX = 2          
+PROCESS_MY_LIST_INDEX = 3           
+
+# LinkedList
+FIRST_LINK_INDEX = 0                
+LAST_LINK_INDEX = 1                 
+
+# Semaphore < LinkedList
+EXCESS_SIGNALS_INDEX = 2            
+
+# Scheduler
+SCHEDULER_PROCESS_LISTS_INDEX = 0   
+SCHEDULER_ACTIVE_PROCESS_INDEX = 1  
 
+# MethodDict
 METHODDICT_TALLY_INDEX = 0
 METHODDICT_VALUES_INDEX = 1
 METHODDICT_NAMES_INDEX  = 2
 
+# Message
 MESSAGE_SELECTOR_INDEX = 0
 MESSAGE_ARGUMENTS_INDEX = 1
 MESSAGE_LOOKUP_CLASS_INDEX = 2
 
+# Association
 ASSOCIATION_KEY_INDEX = 0
 ASSOCIATION_VALUE_INDEX = 1
 
+# ContextPart
 CTXPART_SENDER_INDEX = 0
 CTXPART_PC_INDEX = 1
 CTXPART_STACKP_INDEX = 2
 
 METHOD_HEADER_INDEX = 0
 
-# Extends CTXPART_*
+# BlockContext < ContextPart
 BLKCTX_BLOCK_ARGUMENT_COUNT_INDEX = 3
 BLKCTX_INITIAL_IP_INDEX = 4
 BLKCTX_HOME_INDEX = 5
 BLKCTX_TEMP_FRAME_START = 6
 
-# Extends CTXPART_*
+# MethodContext < ContextPart
 MTHDCTX_METHOD = 3
 MTHDCTX_RECEIVER_MAP = 4
 MTHDCTX_RECEIVER = 5
@@ -126,10 +136,10 @@
 #    "Display" : SO_DISPLAY_CLASS,
 #    "Message" : SO_MESSAGE_CLASS,
     "CompiledMethod" : SO_COMPILEDMETHOD_CLASS,
-#    "Semaphore" : SO_SEMAPHORE_CLASS,
+    "Semaphore" : SO_SEMAPHORE_CLASS,
     "Character" : SO_CHARACTER_CLASS,
     "ByteArray" : SO_BYTEARRAY_CLASS,
-#    "Process" : SO_PROCESS_CLASS,
+    "Process" : SO_PROCESS_CLASS,
 #    "PseudoContext" : SO_PSEUDOCONTEXT_CLASS,
 #    "TranslatedMethod" : SO_TRANSLATEDMETHOD_CLASS,
     # "LargeNegativeInteger" : SO_LARGENEGATIVEINTEGER_CLASS, # Not available in mini.image

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 01:18:38 2008
@@ -181,6 +181,8 @@
         return (W_AbstractObjectWithClassReference.invariant(self) and
                 isinstance(self._vars, list))
 
+    # XXX XXX
+    # Need to find better way of handling overloading of shadows!!!
     def as_special_get_shadow(self, TheClass):
         shadow = self._shadow
         if shadow is None:
@@ -195,6 +197,9 @@
         return shadow
 
     def as_link_get_shadow(self):
+        from pypy.lang.smalltalk import classtable
+        if self.getclass() == classtable.w_Process:
+            return self.as_process_get_shadow()
         from pypy.lang.smalltalk.shadow import LinkShadow
         return self.as_special_get_shadow(LinkShadow)
     
@@ -203,6 +208,9 @@
         return self.as_special_get_shadow(SemaphoreShadow)
 
     def as_linkedlist_get_shadow(self):
+        from pypy.lang.smalltalk import classtable
+        if self.getclass() == classtable.w_Semaphore:
+            return self.as_semaphore_get_shadow()
         from pypy.lang.smalltalk.shadow import LinkedListShadow
         return self.as_special_get_shadow(LinkedListShadow)
 

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 01:18:38 2008
@@ -221,40 +221,40 @@
     def __init__(self, w_self):
         self._w_self = w_self
 
-    def firstlink(self):
+    def w_firstlink(self):
         return self._w_self.fetch(constants.FIRST_LINK_INDEX)
 
-    def store_firstlink(self, w_object):
+    def store_w_firstlink(self, w_object):
         return self._w_self.atput0(constants.FIRST_LINK_INDEX, w_object)
 
-    def lastlink(self):
+    def w_lastlink(self):
         return self._w_self.fetch(constants.LAST_LINK_INDEX)
 
-    def store_lastlink(self, w_object):
+    def store_w_lastlink(self, w_object):
         return self._w_self.atput0(constants.LAST_LINK_INDEX, w_object)
 
     def is_empty_list(self):
         from pypy.lang.smalltalk import objtable
-        return self.firstlink() == objtable.w_nil
+        return self.w_firstlink() == objtable.w_nil
 
     def add_last_link(self, w_object):
         if self.is_empty_list():
-            self.store_firstlink(w_object)
+            self.store_w_firstlink(w_object)
         else:
-            self.lastlink().store_next(w_object)
+            self.w_lastlink().as_link_get_shadow().store_next(w_object)
         # XXX Slang version stores list in process here...
-        self.store_lastlink(w_object)
+        self.store_w_lastlink(w_object)
 
     def remove_first_link_of_list(self):
         from pypy.lang.smalltalk import objtable
-        first = self.firstlink()
-        last = self.lastlink()
+        first = self.w_firstlink()
+        last = self.w_lastlink()
         if first == last:
-            self.store_firstlink(objtable.w_nil)
-            self.store_lastlink(objtable.w_nil)
+            self.store_w_firstlink(objtable.w_nil)
+            self.store_w_lastlink(objtable.w_nil)
         else:
             next = first.as_process_get_shadow().next()
-            self.store_firstlink(next)
+            self.store_w_firstlink(next)
         first.as_process_get_shadow().store_next(objtable.w_nil)
         return first
 
@@ -275,8 +275,8 @@
     def transfer_to(self, s_process, interp):
         from pypy.lang.smalltalk import objtable
         s_scheduler = self.scheduler()
-        s_old_process = s_scheduler.active_process()
-        s_scheduler.store_active_process(s_process)
+        s_old_process = s_scheduler.s_active_process()
+        s_scheduler.store_w_active_process(s_process.w_self())
         s_old_process.store_w_suspended_context(interp.s_active_context.w_self())
         interp.s_active_context = s_process.s_suspended_context()
         s_process.store_w_suspended_context(objtable.w_nil)
@@ -291,7 +291,7 @@
     def resume(self, w_process, interp):
         s_process = w_process.as_process_get_shadow()
         s_scheduler = self.s_scheduler()
-        s_active_process = s_scheduler.active_process()
+        s_active_process = s_scheduler.s_active_process()
         active_priority = s_active_process.priority()
         new_priority = s_process.priority()
         if new_priority > active_priority:
@@ -354,11 +354,11 @@
     def __init__(self, w_self):
         self._w_self = w_self
 
-    def active_process(self):
+    def s_active_process(self):
         return self._w_self.fetch(constants.SCHEDULER_ACTIVE_PROCESS_INDEX).as_process_get_shadow()
 
-    def store_active_process(self, w_object):
-        self._w_self.atput0(constants.SCHEDULER_ACTIVE_PROCESS_INDEX, w_object)
+    def store_w_active_process(self, w_object):
+        self._w_self.store(constants.SCHEDULER_ACTIVE_PROCESS_INDEX, w_object)
     
     def process_lists(self):
         return self._w_self.fetch(constants.SCHEDULER_PROCESS_LISTS_INDEX)

Modified: pypy/branch/smalltalk-shadow-changes/pypy/lang/smalltalk/squeakimage.py
==============================================================================
--- pypy/branch/smalltalk-shadow-changes/pypy/lang/smalltalk/squeakimage.py	(original)
+++ pypy/branch/smalltalk-shadow-changes/pypy/lang/smalltalk/squeakimage.py	Fri Feb 22 01:18:38 2008
@@ -205,7 +205,7 @@
         self.objects = [chunk.g_object.w_object for chunk in reader.chunklist]
         from pypy.lang.smalltalk import constants, objtable
         for name, idx in constants.objects_in_special_object_table.items():
-            objtable.objtable["w_" + name] = self.objects[idx]
+            objtable.objtable["w_" + name] = self.special_objects[idx]
 
     def special(self, index):
         return self.special_objects[index]

Modified: pypy/branch/smalltalk-shadow-changes/pypy/lang/smalltalk/test/test_shadow.py
==============================================================================
--- pypy/branch/smalltalk-shadow-changes/pypy/lang/smalltalk/test/test_shadow.py	(original)
+++ pypy/branch/smalltalk-shadow-changes/pypy/lang/smalltalk/test/test_shadow.py	Fri Feb 22 01:18:38 2008
@@ -70,9 +70,13 @@
     classshadow = w_class.as_class_get_shadow()
     assert classshadow.methoddict == methods
 
-def test_link():
+def link(w_next='foo'):
     w_object = model.W_PointersObject(None, 1)
-    w_object.store(constants.NEXT_LINK_INDEX, 'foo')
+    w_object.store(constants.NEXT_LINK_INDEX, w_next)
+    return w_object
+
+def test_link():
+    w_object = link()
     assert w_object.as_link_get_shadow().next() == 'foo'
 
 def method(tempsize=3,argsize=2, bytes="abcde"):
@@ -158,5 +162,39 @@
     w_object.store(constants.SCHEDULER_ACTIVE_PROCESS_INDEX, w_process)
     w_object.store(constants.SCHEDULER_PROCESS_LISTS_INDEX, 'pl')
     s_object = w_object.as_scheduler_get_shadow()
-    assert s_object.active_process() == w_process.as_process_get_shadow()
+    assert s_object.s_active_process() == w_process.as_process_get_shadow()
+    assert s_object.process_lists() == 'pl'
+    w_process2 = process()
+    s_object.store_w_active_process(w_process2)
     assert s_object.process_lists() == 'pl'
+    assert s_object.s_active_process() != w_process.as_process_get_shadow()
+    assert s_object.s_active_process() == w_process2.as_process_get_shadow()
+
+def test_linkedlist():
+    w_object = model.W_PointersObject(None,2)
+    w_last = link(objtable.w_nil)
+    w_lb1 = link(w_last)
+    w_lb2 = link(w_lb1)
+    w_lb3 = link(w_lb2)
+    w_lb4 = link(w_lb3)
+    w_first = link(w_lb4)
+    w_object.store(constants.FIRST_LINK_INDEX, w_first)
+    w_object.store(constants.LAST_LINK_INDEX, w_last)
+    s_object = w_object.as_linkedlist_get_shadow()
+    assert w_first == s_object.w_firstlink()
+    assert w_last == s_object.w_lastlink()
+    assert s_object.remove_first_link_of_list() == w_first
+    assert s_object.remove_first_link_of_list() == w_lb4
+    assert s_object.remove_first_link_of_list() == w_lb3
+    assert not s_object.is_empty_list()
+    assert s_object.remove_first_link_of_list() == w_lb2
+    assert s_object.remove_first_link_of_list() == w_lb1
+    assert s_object.remove_first_link_of_list() == w_last
+    assert s_object.is_empty_list()
+    s_object.add_last_link(w_first)
+    assert s_object.w_firstlink() == w_first
+    assert s_object.w_lastlink() == w_first
+    s_object.add_last_link(w_last)
+    assert s_object.w_firstlink() == w_first
+    assert s_object.w_lastlink() == w_last
+    



More information about the Pypy-commit mailing list