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

tverwaes at codespeak.net tverwaes at codespeak.net
Sat May 17 19:22:46 CEST 2008


Author: tverwaes
Date: Sat May 17 19:22:45 2008
New Revision: 54870

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/model.py
   pypy/branch/smalltalk-shadow-changes/pypy/lang/smalltalk/test/test_shadow.py
   pypy/branch/smalltalk-shadow-changes/pypy/lang/smalltalk/wrapper.py
Log:
moving AssociationShadow to associationwrapper


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	Sat May 17 19:22:45 2008
@@ -15,18 +15,6 @@
 CLASS_FORMAT_INDEX = 2
 CLASS_NAME_INDEX = 6                # in the mini.image, at least
 
-# 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  
@@ -41,10 +29,6 @@
 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

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	Sat May 17 19:22:45 2008
@@ -6,6 +6,7 @@
 from pypy.lang.smalltalk.shadow import ContextPartShadow
 from pypy.lang.smalltalk.conftest import option
 from pypy.rlib import objectmodel, unroll
+from pypy.lang.smalltalk import wrapper
 
 
 class MissingBytecode(Exception):
@@ -138,9 +139,8 @@
         # named var (the value).
         index = self.currentBytecode & 31
         w_association = self.w_method().getliteral(index)
-        assert isinstance(w_association, model.W_PointersObject)
-        s_association = w_association.as_association_get_shadow()
-        self.push(s_association.value())
+        association = wrapper.AssociationWrapper(w_association)
+        self.push(association.value())
 
     def storeAndPopReceiverVariableBytecode(self, interp):
         index = self.currentBytecode & 7
@@ -281,9 +281,8 @@
             self.push(self.w_method().getliteral(variableIndex))
         elif variableType == 3:
             w_association = self.w_method().getliteral(variableIndex)
-            assert isinstance(w_association, model.W_PointersObject)
-            s_association = w_association.as_association_get_shadow()
-            self.push(s_association.value())
+            association = wrapper.AssociationWrapper(w_association)
+            self.push(association.value())
         else:
             assert 0
         
@@ -297,9 +296,8 @@
             raise IllegalStoreError
         elif variableType == 3:
             w_association = self.w_method().getliteral(variableIndex)
-            assert isinstance(w_association, model.W_PointersObject)
-            s_association = w_association.as_association_get_shadow()
-            s_association.store_value(self.top())
+            association = wrapper.AssociationWrapper(w_association)
+            association.store_value(self.top())
 
     def extendedStoreAndPopBytecode(self, interp):
         self.extendedStoreBytecode(interp)
@@ -335,18 +333,16 @@
         elif opType == 4:
             # pushLiteralVariable
             w_association = self.w_method().getliteral(third)
-            assert isinstance(w_association, model.W_PointersObject)
-            s_association = w_association.as_association_get_shadow()
-            self.push(s_association.value())
+            association = wrapper.AssociationWrapper(w_association)
+            self.push(association.value())
         elif opType == 5:
             self.w_receiver().store(third, self.top())
         elif opType == 6:
             self.w_receiver().store(third, self.pop())
         elif opType == 7:
             w_association = self.w_method().getliteral(third)
-            assert isinstance(w_association, model.W_PointersObject)
-            s_association = w_association.as_association_get_shadow()
-            s_association.store_value(self.top())
+            association = wrapper.AssociationWrapper(w_association)
+            association.store_value(self.top())
 
     def singleExtendedSuperBytecode(self, interp):
         selector, argcount = self.getExtendedSelectorArgcount()

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	Sat May 17 19:22:45 2008
@@ -298,10 +298,6 @@
         from pypy.lang.smalltalk.shadow import SchedulerShadow
         return self.as_special_get_shadow(SchedulerShadow)
 
-    def as_association_get_shadow(self):
-        from pypy.lang.smalltalk.shadow import AssociationShadow
-        return self.as_special_get_shadow(AssociationShadow)
-
     def as_blockcontext_get_shadow(self, invalid=True):
         from pypy.lang.smalltalk.shadow import BlockContextShadow
         return self.as_special_get_shadow(BlockContextShadow, invalid)
@@ -426,15 +422,15 @@
 
     def compiledin(self):  
         if self.w_compiledin is None:
+            from pypy.lang.smalltalk import wrapper
             # (Blue book, p 607) All CompiledMethods that contain
             # extended-super bytecodes have the clain which they are found as
             # their last literal variable.   
             # Last of the literals is an association with compiledin
             # as a class
             w_association = self.literals[-1]
-            assert isinstance(w_association, W_PointersObject)
-            s_association = w_association.as_association_get_shadow()
-            self.w_compiledin = s_association.value()
+            association = wrapper.AssociationWrapper(w_association)
+            self.w_compiledin = association.value()
         return self.w_compiledin
 
     def getclass(self):

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	Sat May 17 19:22:45 2008
@@ -137,45 +137,20 @@
     assert s_object.getbytecode() == 101
     assert s_object.s_home() == s_object
 
-def process(w_context=methodcontext(), priority=utility.wrap_int(3)):
-    w_object = model.W_PointersObject(None, 4)
-    w_object.store(constants.NEXT_LINK_INDEX, 'foo')
-    w_object.store(constants.PROCESS_SUSPENDED_CONTEXT_INDEX, w_context)
-    w_object.store(constants.PROCESS_PRIORITY_INDEX, priority)
-    w_object.store(constants.PROCESS_MY_LIST_INDEX, 'mli')
-    return w_object
-
-def test_process():
-    w_context = methodcontext()
-    w_object = process(w_context)
-    s_object = w_object.as_process_get_shadow()
-    assert s_object.next() == 'foo'
-    assert s_object.priority() == 3
-    assert s_object.my_list() == 'mli'
-    assert s_object.w_suspended_context() == w_context
-
-def test_association():
-    w_object = model.W_PointersObject(None, 2)
-    w_object.store(constants.ASSOCIATION_KEY_INDEX, 'key')
-    w_object.store(constants.ASSOCIATION_VALUE_INDEX, 'value')
-    s_object = w_object.as_association_get_shadow()
-    assert s_object.key() == 'key'
-    assert s_object.value() == 'value'
-
-def test_scheduler():
-    w_process = process()
-    w_pl = model.W_PointersObject(None, 0)
-    w_object = model.W_PointersObject(None, 2)
-    w_object.store(constants.SCHEDULER_ACTIVE_PROCESS_INDEX, w_process)
-    w_object.store(constants.SCHEDULER_PROCESS_LISTS_INDEX, w_pl)
-    s_object = w_object.as_scheduler_get_shadow()
-    assert s_object.s_active_process() == w_process.as_process_get_shadow()
-    assert s_object.process_lists() == w_pl
-    w_process2 = process()
-    s_object.store_w_active_process(w_process2)
-    assert s_object.process_lists() == w_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_scheduler():
+#    w_process = process()
+#    w_pl = model.W_PointersObject(None, 0)
+#    w_object = model.W_PointersObject(None, 2)
+#    w_object.store(constants.SCHEDULER_ACTIVE_PROCESS_INDEX, w_process)
+#    w_object.store(constants.SCHEDULER_PROCESS_LISTS_INDEX, w_pl)
+#    s_object = w_object.as_scheduler_get_shadow()
+#    assert s_object.s_active_process() == w_process.as_process_get_shadow()
+#    assert s_object.process_lists() == w_pl
+#    w_process2 = process()
+#    s_object.store_w_active_process(w_process2)
+#    assert s_object.process_lists() == w_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_shadowchanges():
 #    w_object = model.W_PointersObject(None, 2)

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	Sat May 17 19:22:45 2008
@@ -67,10 +67,35 @@
             self.store_first_link(w_next)
         LinkWrapper(w_first).store_next_link(objtable.w_nil)
         return w_first
+
+class AssociationWrapper(Wrapper):
+    key = make_getter(0)
+    value, store_value = make_getter_setter(1)
+
 '''
-class SemaphoreShadow(LinkedListShadow):
-    """A shadow for Smalltalk objects that are semaphores
-    """
+class SchedulerShadow(AbstractShadow):
+    def __init__(self, w_self, invalid):
+        AbstractShadow.__init__(self, w_self, invalid)
+
+    def s_active_process(self):
+        w_v = self.w_self()._vars[constants.SCHEDULER_ACTIVE_PROCESS_INDEX]
+        assert isinstance(w_v, model.W_PointersObject)
+        return w_v.as_process_get_shadow()
+
+    def store_w_active_process(self, w_object):
+        self.w_self()._vars[constants.SCHEDULER_ACTIVE_PROCESS_INDEX] = w_object
+    
+    def process_lists(self):
+        w_v = self.w_self()._vars[constants.SCHEDULER_PROCESS_LISTS_INDEX]
+        assert isinstance(w_v, model.W_PointersObject)
+        return w_v
+
+
+
+class SemaphoreWrapper(LinkedListWrapper):
+
+    excess_signals, store_excess_signals = make_getter_setter(0)
+
     def __init__(self, w_self, invalid=False):
         LinkedListShadow.__init__(self, w_self, invalid)
 
@@ -103,53 +128,24 @@
         return w_scheduler.as_scheduler_get_shadow()
 
     def resume(self, w_process, interp):
-        s_process = w_process.as_process_get_shadow()
-        s_scheduler = self.s_scheduler()
-        s_active_process = s_scheduler.s_active_process()
-        active_priority = s_active_process.priority()
-        new_priority = s_process.priority()
+        process = ProcessWrapper(w_process)
+        scheduler = self.scheduler()
+        active_process = scheduler.s_active_process()
+        active_priority = active_process.priority()
+        new_priority = process.priority()
         if new_priority > active_priority:
-            self.put_to_sleep(s_active_process)
-            self.transfer_to(s_process, interp)
+            self.put_to_sleep(active_process)
+            self.transfer_to(process, interp)
         else:
-            self.put_to_sleep(s_process)
+            self.put_to_sleep(process)
 
     def synchronous_signal(self, interp):
         if self.is_empty_list():
-            w_value = self.w_self()._vars[constants.EXCESS_SIGNALS_INDEX]
+            w_value = self.excess_signals()
             w_value = utility.wrap_int(utility.unwrap_int(w_value) + 1)
-            self.w_self()._vars[constants.EXCESS_SIGNALS_INDEX] = w_value
+            self.store_excess_signals(w_value)
         else:
             self.resume(self.remove_first_link_of_list(), interp)
 
-class AssociationShadow(AbstractShadow):
-    def __init__(self, w_self, invalid):
-        AbstractShadow.__init__(self, w_self, invalid)
-
-    def key(self):
-        return self.w_self()._vars[constants.ASSOCIATION_KEY_INDEX]
-
-    def value(self):
-        return self.w_self()._vars[constants.ASSOCIATION_VALUE_INDEX]
-
-    def store_value(self, w_value):
-        self.w_self()._vars[constants.ASSOCIATION_VALUE_INDEX] = w_value
-
-class SchedulerShadow(AbstractShadow):
-    def __init__(self, w_self, invalid):
-        AbstractShadow.__init__(self, w_self, invalid)
-
-    def s_active_process(self):
-        w_v = self.w_self()._vars[constants.SCHEDULER_ACTIVE_PROCESS_INDEX]
-        assert isinstance(w_v, model.W_PointersObject)
-        return w_v.as_process_get_shadow()
-
-    def store_w_active_process(self, w_object):
-        self.w_self()._vars[constants.SCHEDULER_ACTIVE_PROCESS_INDEX] = w_object
-    
-    def process_lists(self):
-        w_v = self.w_self()._vars[constants.SCHEDULER_PROCESS_LISTS_INDEX]
-        assert isinstance(w_v, model.W_PointersObject)
-        return w_v
-
 '''
+



More information about the Pypy-commit mailing list