[pypy-commit] lang-smalltalk rstrategies: Fixed RPython compilation.

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


Author: Anton Gulenko <anton.gulenko at googlemail.com>
Branch: rstrategies
Changeset: r1045:e281e2683374
Date: 2014-08-20 22:53 +0200
http://bitbucket.org/pypy/lang-smalltalk/changeset/e281e2683374/

Log:	Fixed RPython compilation. Added StrategyMetaclass for correctness.

diff --git a/rstrategies.py b/rstrategies.py
--- a/rstrategies.py
+++ b/rstrategies.py
@@ -2,6 +2,11 @@
 import weakref
 from rpython.rlib import jit
 
+class StrategyMetaclass(type):
+    def __new__(self, name, bases, attrs):
+        attrs['_is_strategy'] = False
+        return super(StrategyMetaclass, self).__new__(self, name, bases, attrs)
+
 def collect_subclasses(cls):
     "NOT_RPYTHON"
     subclasses = []
diff --git a/spyvm/model.py b/spyvm/model.py
--- a/spyvm/model.py
+++ b/spyvm/model.py
@@ -680,6 +680,7 @@
         shadow = old_shadow
         if not isinstance(old_shadow, TheClass):
             shadow = space.strategy_factory.switch_strategy(old_shadow, TheClass)
+        assert isinstance(shadow, TheClass)
         return shadow
 
     def get_shadow(self, space):
diff --git a/spyvm/storage.py b/spyvm/storage.py
--- a/spyvm/storage.py
+++ b/spyvm/storage.py
@@ -14,6 +14,7 @@
     _immutable_fields_ = ['space']
     provides_getname = False
     repr_classname = "AbstractShadow"
+    __metaclass__ = rstrat.StrategyMetaclass
     import_from_mixin(rstrat.AbstractCollection)
     
     def __init__(self, space, w_self, size):
@@ -75,11 +76,12 @@
     repr_classname = "FloatOrNilStorageShadow"
     import_from_mixin(rstrat.TaggingStrategy)
     contained_type = model.W_Float
+    tag_float = sys.float_info.max
     def wrap(self, val): return self.space.wrap_float(val)
     def unwrap(self, w_val): return self.space.unwrap_float(w_val)
     def default_value(self): return self.space.w_nil
     def wrapped_tagged_value(self): return self.space.w_nil
-    def unwrapped_tagged_value(self): import sys; return sys.float_info.max
+    def unwrapped_tagged_value(self): return self.tag_float
 
 @rstrat.strategy(generalize=[
     SmallIntegerOrNilStorageShadow,
diff --git a/spyvm/storage_classes.py b/spyvm/storage_classes.py
--- a/spyvm/storage_classes.py
+++ b/spyvm/storage_classes.py
@@ -127,6 +127,7 @@
             self.store_s_methoddict(s_new_methoddict)
 
     def store_s_methoddict(self, s_methoddict):
+        assert isinstance(s_methoddict, MethodDictionaryShadow)
         s_methoddict.s_class = self
         s_methoddict.sync_method_cache()
         self._s_methoddict = s_methoddict
@@ -193,20 +194,6 @@
     # included so that we can reproduce code from the reference impl
     # more easily
 
-    def ispointers(self):
-        " True if instances of this class have data stored as pointers "
-        XXX   # what about weak pointers?
-        return self.format == POINTERS
-
-    def iswords(self):
-        " True if instances of this class have data stored as numerical words "
-        XXX   # what about weak pointers?
-        return self.format in (POINTERS, WORDS)
-
-    def isbytes(self):
-        " True if instances of this class have data stored as numerical bytes "
-        return self.format == BYTES
-
     @constant_for_version
     def isvariable(self):
         " True if instances of this class have indexed inst variables "
diff --git a/spyvm/storage_contexts.py b/spyvm/storage_contexts.py
--- a/spyvm/storage_contexts.py
+++ b/spyvm/storage_contexts.py
@@ -3,6 +3,7 @@
 from spyvm.storage import AbstractRedirectingShadow
 from rpython.tool.pairtype import extendabletype
 from rpython.rlib import rarithmetic, jit, objectmodel
+import rstrategies as rstrat
 
 @objectmodel.specialize.call_location()
 def fresh_virtualizable(x):
@@ -19,9 +20,12 @@
 ActiveContext = ContextState("ActiveContext")
 DirtyContext = ContextState("DirtyContext")
 
+class ExtendableStrategyMetaclass(extendabletype, rstrat.StrategyMetaclass):
+    pass
+
 class ContextPartShadow(AbstractRedirectingShadow):
 
-    __metaclass__ = extendabletype
+    __metaclass__ = ExtendableStrategyMetaclass
     _attrs_ = ['_s_sender',
             '_pc', '_temps_and_stack',
             '_stack_ptr', 'instances_w', 'state']


More information about the pypy-commit mailing list