[pypy-commit] lang-smalltalk rstrategies: Tests green now.

anton_gulenko noreply at buildbot.pypy.org
Thu Aug 21 12:55:00 CEST 2014


Author: Anton Gulenko <anton.gulenko at googlemail.com>
Branch: rstrategies
Changeset: r1038:baecfe86835c
Date: 2014-08-20 16:38 +0200
http://bitbucket.org/pypy/lang-smalltalk/changeset/baecfe86835c/

Log:	Tests green now.

diff --git a/rstrategies.py b/rstrategies.py
--- a/rstrategies.py
+++ b/rstrategies.py
@@ -11,15 +11,17 @@
     return subclasses
 
 class StrategyFactory(object):
-    _immutable_fields_ = ["xx[*]"]
+    _immutable_fields_ = ["strategies[*]"]
     
     def __init__(self, root_class, all_strategy_classes=None):
         if all_strategy_classes is None:
             all_strategy_classes = collect_subclasses(root_class)
-        self.strategies = all_strategy_classes
+        self.strategies = []
         
-        for strategy_class in self.strategies:
-            strategy_class._strategy_instance = self.instantiate_empty(strategy_class)
+        for strategy_class in all_strategy_classes:
+            if hasattr(strategy_class, "_is_strategy") and strategy_class._is_strategy:
+                strategy_class._strategy_instance = self.instantiate_empty(strategy_class)
+                self.strategies.append(strategy_class)
             
             # Patch root class: Add default handler for visitor
             def copy_from_OTHER(self, other):
@@ -33,10 +35,10 @@
                 getattr(other, funcname)(self)
             strategy_class.initiate_copy_into = initiate_copy_into
     
-    def setup_strategy_transitions(self, transitions):
+    def decorate_strategies(self, transitions):
         "NOT_RPYTHON"
         for strategy_class, generalized in transitions.items():
-            generalize(generalized)(strategy_class)
+            strategy(generalized)(strategy_class)
     
     # Instantiate new_strategy_type with size, replace old_strategy with it,
     # and return the new instance
@@ -78,17 +80,19 @@
         # Instance will be frozen at compile time, making accesses constant.
         return True
 
-def generalize(generalized):
+def strategy(generalize=None):
     def decorator(strategy_class):
-        # Patch strategy class: Add generalized_strategy_for
-        # TODO - optimize this method
-        @jit.unroll_safe
-        def generalized_strategy_for(self, value):
-            for strategy in generalized:
-                if strategy._strategy_instance.check_can_handle(value):
-                    return strategy
-            raise Exception("Could not find generalized strategy for %s coming from %s" % (value, self))
-        strategy_class.generalized_strategy_for = generalized_strategy_for
+        # Patch strategy class: Add generalized_strategy_for and mark as strategy class.
+        if generalize:
+            # TODO - optimize this method
+            @jit.unroll_safe
+            def generalized_strategy_for(self, value):
+                for strategy in generalize:
+                    if strategy._strategy_instance.check_can_handle(value):
+                        return strategy
+                raise Exception("Could not find generalized strategy for %s coming from %s" % (value, self))
+            strategy_class.generalized_strategy_for = generalized_strategy_for
+        strategy_class._is_strategy = True
         return strategy_class
     return decorator
 
diff --git a/spyvm/objspace.py b/spyvm/objspace.py
--- a/spyvm/objspace.py
+++ b/spyvm/objspace.py
@@ -1,6 +1,6 @@
 import os
 
-from spyvm import constants, model, wrapper, display
+from spyvm import constants, model, wrapper, display, storage
 from spyvm.error import UnwrappingError, WrappingError
 from rpython.rlib import jit, rpath
 from rpython.rlib.objectmodel import instantiate, specialize, import_from_mixin
diff --git a/spyvm/storage.py b/spyvm/storage.py
--- a/spyvm/storage.py
+++ b/spyvm/storage.py
@@ -46,17 +46,19 @@
     def copy_from_AllNilStrategy(self, all_nil_storage):
         pass # Fields already initialized to nil
 
+ at rstrat.strategy()
 class ListStorageShadow(AbstractStorageShadow):
     repr_classname = "ListStorageShadow"
     import_from_mixin(rstrat.GenericStrategy)
     def default_value(self): return self.space.w_nil
 
+ at rstrat.strategy()
 class WeakListStorageShadow(AbstractStorageShadow):
     repr_classname = "WeakListStorageShadow"
     import_from_mixin(rstrat.WeakGenericStrategy)
     def default_value(self): return self.space.w_nil
 
- at rstrat.generalize([ListStorageShadow])
+ at rstrat.strategy(generalize=[ListStorageShadow])
 class SmallIntegerOrNilStorageShadow(AbstractStorageShadow):
     repr_classname = "SmallIntegerOrNilStorageShadow"
     import_from_mixin(rstrat.TaggingStrategy)
@@ -67,7 +69,7 @@
     def wrapped_tagged_value(self): return self.space.w_nil
     def unwrapped_tagged_value(self): return constants.MAXINT
 
- at rstrat.generalize([ListStorageShadow])
+ at rstrat.strategy(generalize=[ListStorageShadow])
 class FloatOrNilStorageShadow(AbstractStorageShadow):
     repr_classname = "FloatOrNilStorageShadow"
     import_from_mixin(rstrat.TaggingStrategy)
@@ -78,7 +80,7 @@
     def wrapped_tagged_value(self): return self.space.w_nil
     def unwrapped_tagged_value(self): import sys; return sys.float_info.max
 
- at rstrat.generalize([
+ at rstrat.strategy(generalize=[
     SmallIntegerOrNilStorageShadow,
     FloatOrNilStorageShadow,
     ListStorageShadow])
@@ -93,7 +95,7 @@
         from spyvm import objspace
         self.space = space
         self.no_specialized_storage = objspace.ConstantFlag()
-        rstrat.StrategyFactory.__init__(self, AbstractStorageShadow)
+        rstrat.StrategyFactory.__init__(self, AbstractShadow)
     
     def strategy_type_for(self, objects, weak=False):
         if weak:


More information about the pypy-commit mailing list