Author: Anton Gulenko <[email protected]>
Branch: strategies-tagging
Changeset: r670:dcaa168e8fe8
Date: 2014-03-20 11:53 +0100
http://bitbucket.org/pypy/lang-smalltalk/changeset/dcaa168e8fe8/

Log:    Renamed set_storage to initialize_storage and _storage to
        list_storage. Moved the special casing based on uses_int_storage
        into the strategy base class.

diff --git a/spyvm/model.py b/spyvm/model.py
--- a/spyvm/model.py
+++ b/spyvm/model.py
@@ -653,7 +653,7 @@
 strategy_stats = StrategyStatistics()
 
 class W_PointersObject(W_AbstractPointersObject):
-    _attrs_ = ['_size', '_storage', 'int_storage', 'strategy']
+    _attrs_ = ['_size', 'list_storage', 'int_storage', 'strategy']
 
     @jit.unroll_safe
     def __init__(self, space, w_class, size):
@@ -661,7 +661,7 @@
         """Create new object with size = fixed + variable size."""
         W_AbstractPointersObject.__init__(self, space, w_class, size)
         self.strategy = strategy_of_size(self.s_class, size)
-        self.set_storage(space, size)
+        self.initialize_storage(space, size)
         self.log_strategy_operation("Initialized")
     
     def log_strategy_operation(self, op, old_strategy=None):
@@ -679,24 +679,15 @@
             if strategy_stats.do_log:
                 strategy_stats.log_operation(op, new_strategy_tag, 
old_strategy_tag, classname, size)
     
-    def set_storage(self, space, size):
+    def initialize_storage(self, space, size):
         self._size = size
-        if self.strategy.uses_int_storage:
-            self.int_storage = self.strategy.initial_int_storage(space, size)
-        else:
-            self._storage = self.strategy.initial_storage(space, size)
-    
-    def get_strategy(self):
-        return self.strategy
+        self.strategy.set_initial_storage(space, self, size)
     
     def fillin_pointers(self, space, collection):
         from spyvm.strategies import strategy_for_list
         self.strategy = strategy_for_list(self.s_class, collection)
         self._size = len(collection)
-        if self.strategy.uses_int_storage:
-            self.int_storage = self.strategy.int_storage_for_list(space, 
collection)
-        else:
-            self._storage = self.strategy.storage_for_list(space, collection)
+        self.strategy.set_storage_for_list(space, self, collection)
     
     def fillin(self, space, g_self):
         W_AbstractPointersObject.fillin(self, space, g_self)
@@ -705,10 +696,7 @@
 
     def switch_strategy(self, space, new_strategy):
         assert self.strategy != new_strategy
-        if new_strategy.uses_int_storage:
-            self.int_storage = new_strategy.copy_int_storage_from(space, self, 
reuse_storage=True)
-        else:
-            self._storage = new_strategy.copy_storage_from(space, self, 
reuse_storage=True)
+        new_strategy.set_storage_copied_from(space, self, self, 
reuse_storage=True)
         old_strategy = self.strategy
         self.strategy = new_strategy
         self.log_strategy_operation("Switched", old_strategy)
@@ -735,10 +723,10 @@
             i = i+1
     
     def _fetch(self, space, n0):
-        return self.get_strategy().fetch(space, self, n0)
+        return self.strategy.fetch(space, self, n0)
 
     def _store(self, space, n0, w_value):
-        return self.get_strategy().store(space, self, n0, w_value)
+        return self.strategy.store(space, self, n0, w_value)
 
     def basic_size(self):
         return self._size
@@ -748,7 +736,7 @@
             return False
         self.strategy, w_other.strategy = w_other.strategy, self.strategy
         self._size, w_other._size = w_other._size, self._size
-        self._storage, w_other._storage = w_other._storage, self._storage
+        self.list_storage, w_other.list_storage = w_other.list_storage, 
self.list_storage
         self.int_storage, w_other.int_storage = w_other.int_storage, 
self.int_storage
         return W_AbstractPointersObject.become(self, w_other)
 
diff --git a/spyvm/objspace.py b/spyvm/objspace.py
--- a/spyvm/objspace.py
+++ b/spyvm/objspace.py
@@ -165,7 +165,7 @@
             from spyvm.strategies import ListStorageStrategy
             w_nil.space = self
             w_nil.strategy = ListStorageStrategy.singleton
-            w_nil.set_storage(self, 0)
+            w_nil.initialize_storage(self, 0)
             w_nil.s_class = 
self.classtable['w_UndefinedObject'].as_class_get_penumbra(self)
             return w_nil
         w_nil = self.w_nil = patch_nil(model.w_nil)
diff --git a/spyvm/shadow.py b/spyvm/shadow.py
--- a/spyvm/shadow.py
+++ b/spyvm/shadow.py
@@ -432,7 +432,7 @@
                 self.copy_from_w_self(i)
             except error.SenderChainManipulation, e:
                 assert e.s_context == self
-        w_self.set_storage(self.space, 0)
+        w_self.initialize_storage(self.space, 0)
 
     # def detach_shadow(self):
     #     w_self = self.w_self()
diff --git a/spyvm/strategies.py b/spyvm/strategies.py
--- a/spyvm/strategies.py
+++ b/spyvm/strategies.py
@@ -1,8 +1,6 @@
 from spyvm import model, shadow
 
-from rpython.rlib import rerased
-from rpython.rlib import objectmodel, jit, signature
-from rpython.rlib.listsort import TimSort
+from rpython.rlib import rerased, objectmodel, jit, signature
 from rpython.rlib.objectmodel import import_from_mixin
 from rpython.rlib.debug import make_sure_not_resized
 
@@ -23,6 +21,24 @@
         # If not, the space-parameter can be passed in as None (probably).
         return False
     
+    def set_initial_storage(self, space, w_obj, size):
+        if self.uses_int_storage:
+            w_obj.int_storage = self.initial_int_storage(space, size)
+        else:
+            w_obj.list_storage = self.initial_storage(space, size)
+    
+    def set_storage_for_list(self, space, w_obj, collection):
+        if self.uses_int_storage:
+            w_obj.int_storage = self.int_storage_for_list(space, collection)
+        else:
+            w_obj.list_storage = self.storage_for_list(space, collection)
+    
+    def set_storage_copied_from(self, space, w_obj, w_source_obj, 
reuse_storage=False):
+        if self.uses_int_storage:
+            w_obj.int_storage = self.int_storage_for_list(space, collection)
+        else:
+            w_obj.list_storage = self.storage_for_list(space, collection)
+    
     def fetch(self, space, w_obj, n0):
         raise NotImplementedError("Abstract base class")
     def store(self, space, w_obj, n0, w_val):
@@ -48,7 +64,7 @@
     def copy_storage_from(self, space, w_obj, reuse_storage=False):
         old_strategy = w_obj.strategy
         if old_strategy == self and reuse_storage:
-            return w_obj._storage
+            return w_obj.list_storage
         else:
             # This can be overridden and optimized (reuse_storage flag, less 
temporary storage)
             return self.storage_for_list(space, w_obj.fetch_all(space))
@@ -69,7 +85,7 @@
     def int_storage(self, w_obj):
         return w_obj.int_storage
     def storage(self, w_obj):
-        return w_obj._storage
+        return w_obj.list_storage
     def erase(self, a): return a
     def unerase(self, a): return a
 
@@ -128,7 +144,7 @@
 
 class TaggingSmallIntegerStorageStrategy(AbstractStorageStrategy):
     __metaclass__ = SingletonMeta
-    strategy_tag = 'tagging-small-int'
+    strategy_tag = 'tagging'
     # erase, unerase = 
rerased.new_static_erasing_pair("tagging-small-integer-strategry")
     import_from_mixin(BasicStorageStrategyMixin)
     uses_int_storage = True
diff --git a/spyvm/test/test_primitives.py b/spyvm/test/test_primitives.py
--- a/spyvm/test/test_primitives.py
+++ b/spyvm/test/test_primitives.py
@@ -16,7 +16,7 @@
     def __init__(self, stack):
         size = 6 + len(stack) + 6
         self.strategy = strategies.ListStorageStrategy.singleton
-        self.set_storage(space, size)
+        self.initialize_storage(space, size)
         self.store_all(space, [None] * 6 + stack + [space.w_nil] * 6)
         s_self = self.as_blockcontext_get_shadow()
         s_self.init_stack_and_temps()
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to