Author: Anton Gulenko <[email protected]>
Branch: rstrategies
Changeset: r1056:facac740262e
Date: 2014-10-03 13:09 +0200
http://bitbucket.org/pypy/lang-smalltalk/changeset/facac740262e/

Log:    Fixed some RPython compiler errors.

diff --git a/rstrategies.py b/rstrategies.py
--- a/rstrategies.py
+++ b/rstrategies.py
@@ -1,7 +1,7 @@
 
 import weakref
 import rstrategies_logger
-from rpython.rlib import jit
+from rpython.rlib import jit, objectmodel
 
 class StrategyMetaclass(type):
     def __new__(self, name, bases, attrs):
@@ -80,21 +80,24 @@
     
     # This can be overwritten into a more appropriate call to self.logger.log
     def log(self, new_strategy, old_strategy=None, new_element=None):
-        str = lambda obj: obj.__str__().replace(" ", "").replace("\n", "") if 
obj else None
-        new_strategy_str = str(new_strategy)
-        old_strategy_str = str(old_strategy)
-        element_typename = str(new_element)
+        if not self.logger.active: return
+        new_strategy_str = self.log_string_for_object(new_strategy)
+        old_strategy_str = self.log_string_for_object(old_strategy)
+        element_typename = self.log_string_for_object(new_element)
         size = new_strategy.size()
-        typename = None
-        cause = "SwitchedStrategy"
+        typename = ""
+        cause = "Switched" if old_strategy else "Created"
         self.logger.log(new_strategy_str, size, cause, old_strategy_str, 
typename, element_typename)
+        
+    @objectmodel.specialize.call_location()
+    def log_string_for_object(self, obj):
+        return obj.__class__.__name__ if obj else ""
     
     def switch_strategy(self, old_strategy, new_strategy_type, 
new_element=None):
         new_instance = self.instantiate_and_switch(old_strategy, 
old_strategy.size(), new_strategy_type)
         old_strategy.initiate_copy_into(new_instance)
         new_instance.strategy_switched()
-        if self.logger.active:
-            self.log(new_instance, old_strategy, new_element)
+        self.log(new_instance, old_strategy, new_element)
         return new_instance
     
     @jit.unroll_safe
diff --git a/rstrategies_logger.py b/rstrategies_logger.py
--- a/rstrategies_logger.py
+++ b/rstrategies_logger.py
@@ -12,9 +12,7 @@
             self.element_typenames[element_typename] = None
     
     def classnames(self):
-        if len(self.element_typenames) > 0:
-            return self.element_typenames.keys()
-        return None
+        return self.element_typenames.keys()
 
 class Logger(object):
     _attrs_ = ["active", "aggregate", "logs"]
@@ -29,7 +27,7 @@
         self.active = True
         self.aggregate = self.aggregate or aggregate
     
-    def log(self, new_strategy, size, cause=None, old_strategy=None, 
typename=None, element_typename=None):
+    def log(self, new_strategy, size, cause="", old_strategy="", typename="", 
element_typename=""):
         if self.aggregate:
             key = (cause, old_strategy, new_strategy, typename)
             if key not in self.logs:
@@ -37,7 +35,7 @@
             entry = self.logs[key]
             entry.add(size, element_typename)
         else:
-            element_typenames = [ element_typename ] if element_typename else 
None
+            element_typenames = [ element_typename ] if element_typename else 
[]
             self.output(cause, old_strategy, new_strategy, typename, size, 1, 
element_typenames)
     
     def print_aggregated_log(self):
diff --git a/spyvm/storage.py b/spyvm/storage.py
--- a/spyvm/storage.py
+++ b/spyvm/storage.py
@@ -119,8 +119,7 @@
         if elements:
             w_object.store_all(self.space, elements)
         strategy.strategy_switched()
-        if self.logger.active:
-            self.log(strategy)
+        self.log(strategy)
     
     def instantiate_and_switch(self, old_strategy, size, strategy_class):
         w_self = old_strategy.w_self()
@@ -132,13 +131,14 @@
         return strategy_type(self.space, None, 0)
     
     def log(self, new_strategy, old_strategy=None, new_element=None):
+        if not self.logger.active: return
         # Gather information to be logged
         image_loaded = self.space.image_loaded.is_set()
         size = new_strategy.size()
         new_strategy_str = new_strategy.repr_classname
-        old_strategy_str = old_strategy.repr_classname if old_strategy else 
None
-        classname = new_strategy.w_self().guess_classname() if image_loaded 
else None
-        element_classname = new_element.guess_classname() if new_element and 
image_loaded else None
+        old_strategy_str = old_strategy.repr_classname if old_strategy else ""
+        classname = new_strategy.w_self().guess_classname() if image_loaded 
else ""
+        element_classname = new_element.guess_classname() if new_element and 
image_loaded else ""
         if image_loaded:
             cause = "Switched" if old_strategy else "Initialized"
         else:
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to