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

tverwaes at codespeak.net tverwaes at codespeak.net
Sun May 18 19:13:07 CEST 2008


Author: tverwaes
Date: Sun May 18 19:13:06 2008
New Revision: 54902

Modified:
   pypy/branch/smalltalk-shadow-changes/pypy/lang/smalltalk/primitives.py
   pypy/branch/smalltalk-shadow-changes/pypy/lang/smalltalk/shadow.py
   pypy/branch/smalltalk-shadow-changes/pypy/lang/smalltalk/test/test_interpreter.py
   pypy/branch/smalltalk-shadow-changes/pypy/lang/smalltalk/test/test_model.py
   pypy/branch/smalltalk-shadow-changes/pypy/lang/smalltalk/test/test_shadow.py
Log:
(cfbolz, tverwaes) cleaning up classes to use methoddict's shadow instead of
local cache


Modified: pypy/branch/smalltalk-shadow-changes/pypy/lang/smalltalk/primitives.py
==============================================================================
--- pypy/branch/smalltalk-shadow-changes/pypy/lang/smalltalk/primitives.py	(original)
+++ pypy/branch/smalltalk-shadow-changes/pypy/lang/smalltalk/primitives.py	Sun May 18 19:13:06 2008
@@ -727,24 +727,36 @@
 
 @expose_primitive(PRIMITIVE_SIGNAL, unwrap_spec=[object])
 def func(interp, w_rcvr):
-    #if w_rcvr.getclass() != classtable.classtable['w_Semaphore']:
+    # XXX we might want to disable this check
+    if w_rcvr.getclass() is not classtable.classtable['w_Semaphore']:
         raise PrimitiveFailedError()
-    #assert isinstance(w_rcvr, model.W_PointersObject)
-    #w_rcvr.as_semaphore_get_shadow().synchronous_signal(interp)
-    #return w_rcvr
+    wrapper.SemaphoreWrapper(w_rcvr).signal(interp)
+    return w_rcvr
     
 @expose_primitive(PRIMITIVE_WAIT, unwrap_spec=[object])
 def func(interp, w_rcvr):
-    raise PrimitiveNotYetWrittenError()
+    # XXX we might want to disable this check
+    if w_rcvr.getclass() is not classtable.classtable['w_Semaphore']:
+        raise PrimitiveFailedError()
+    wrapper.SemaphoreWrapper(w_rcvr).wait(interp)
+    return w_rcvr
     
 @expose_primitive(PRIMITIVE_RESUME, unwrap_spec=[object])
 def func(interp, w_rcvr,):
-    raise PrimitiveNotYetWrittenError()
-
+    # XXX we might want to disable this check
+    if w_rcvr.getclass() is not classtable.classtable['w_Process']:
+        raise PrimitiveFailedError()
+    wrapper.ProcessWrapper(w_rcvr).resume(interp)
+    return w_rcvr
+ 
 @expose_primitive(PRIMITIVE_SUSPEND, unwrap_spec=[object])
 def func(interp, w_rcvr):
-    raise PrimitiveNotYetWrittenError()
-
+    # XXX we might want to disable this check
+    if w_rcvr.getclass() is not classtable.classtable['w_Process']:
+        raise PrimitiveFailedError()
+    wrapper.ProcessWrapper(w_rcvr).suspend(interp)
+    return w_rcvr
+ 
 @expose_primitive(PRIMITIVE_FLUSH_CACHE, unwrap_spec=[object])
 def func(interp, w_rcvr):
     # XXX we currently don't care about bad flushes :) XXX

Modified: pypy/branch/smalltalk-shadow-changes/pypy/lang/smalltalk/shadow.py
==============================================================================
--- pypy/branch/smalltalk-shadow-changes/pypy/lang/smalltalk/shadow.py	(original)
+++ pypy/branch/smalltalk-shadow-changes/pypy/lang/smalltalk/shadow.py	Sun May 18 19:13:06 2008
@@ -86,7 +86,7 @@
 
     def invalidate_shadow(self):
         AbstractShadow.invalidate_shadow(self)
-        self.methoddict = {}
+        self.w_methoddict = None
         self.s_superclass = None     # the ClassShadow of the super class
         self.name = None
 
@@ -154,11 +154,8 @@
         if isinstance(w_name, model.W_BytesObject):
             self.name = w_name.as_string()
         # read the methoddict
-        w_methoddict = w_self._vars[constants.CLASS_METHODDICT_INDEX]
-        assert isinstance(w_methoddict, model.W_PointersObject)
-        s_methoddict = w_methoddict.as_methoddict_get_shadow()
-        self.methoddict = s_methoddict.methoddict
-        s_methoddict.notifyinvalid(self)
+        self.w_methoddict = w_self._vars[constants.CLASS_METHODDICT_INDEX]
+        assert isinstance(self.w_methoddict, model.W_PointersObject)
 
         # for the rest, we need to reset invalid to False already so
         # that cycles in the superclass and/or metaclass chains don't
@@ -240,7 +237,7 @@
         look_in_shadow = self
         while look_in_shadow is not None:
             try:
-                w_method = look_in_shadow.methoddict[selector]
+                w_method = look_in_shadow.s_methoddict().methoddict[selector]
                 # We locally cache the method we found.
                 #if look_in_shadow is not self:
                 #    self.methoddict[selector] = w_method
@@ -249,18 +246,29 @@
                 look_in_shadow = look_in_shadow.s_superclass
         raise MethodNotFound(self, selector)
 
+    def s_methoddict(self):
+        return self.w_methoddict.as_methoddict_get_shadow()
+
+    def initialize_methoddict(self):
+        "NOT_RPYTHON"     # this is only for testing.
+        if self.w_methoddict is None:
+            self.w_methoddict = model.W_PointersObject(None, 2)
+            self.w_methoddict._vars[1] = model.W_PointersObject(None, 0)
+            self.s_methoddict().invalid = False
+
     def installmethod(self, selector, method):
         "NOT_RPYTHON"     # this is only for testing.
-        assert isinstance(method, model.W_CompiledMethod)
-        self.methoddict[selector] = method
-        method.w_compiledin = self.w_self()
+        self.initialize_methoddict()
+        self.s_methoddict().methoddict[selector] = method
+        if isinstance(method, model.W_CompiledMethod):
+            method.w_compiledin = self.w_self()
 
 class MethodDictionaryShadow(AbstractShadow):
     def __init__(self, w_self, invalid):
         AbstractShadow.__init__(self, w_self, invalid)
 
     def invalidate_shadow(self):
-        self.methoddict = {}
+        self.methoddict = None
 
     def update_shadow(self):
         from pypy.lang.smalltalk import objtable
@@ -269,6 +277,7 @@
         s_values = w_values.get_shadow()
         s_values.notifyinvalid(self)
         size = self.w_self().size() - constants.METHODDICT_NAMES_INDEX
+        self.methoddict = {}
         for i in range(size):
             w_selector = self.w_self()._vars[constants.METHODDICT_NAMES_INDEX+i]
             if w_selector is not objtable.w_nil:

Modified: pypy/branch/smalltalk-shadow-changes/pypy/lang/smalltalk/test/test_interpreter.py
==============================================================================
--- pypy/branch/smalltalk-shadow-changes/pypy/lang/smalltalk/test/test_interpreter.py	(original)
+++ pypy/branch/smalltalk-shadow-changes/pypy/lang/smalltalk/test/test_interpreter.py	Sun May 18 19:13:06 2008
@@ -36,13 +36,15 @@
         prim_meth.argsize = argsize
         s_class.installmethod(methname, prim_meth)
         
+        assert objtable.w_nil._shadow is None
     try:
         func()
     finally:
         # Uninstall those methods:
+        assert objtable.w_nil._shadow is None
         for (w_class, _, _, methname) in methods:
             s_class = w_class.as_class_get_shadow()
-            del s_class.methoddict[methname]
+            del s_class.s_methoddict().methoddict[methname]
 
 def fakesymbol(s, _cache={}):
     try:
@@ -402,7 +404,7 @@
         assert interp.s_active_context().w_sender() == callerContext
         assert interp.s_active_context().stack() == []
         assert interp.w_active_context().as_methodcontext_get_shadow().w_receiver() == w_object
-        assert interp.w_active_context().as_methodcontext_get_shadow().w_method() == shadow.methoddict["foo"]
+        assert interp.w_active_context().as_methodcontext_get_shadow().w_method() == shadow.s_methoddict().methoddict["foo"]
         assert callerContext.as_context_get_shadow().stack() == []
         interp.step()
         interp.step()
@@ -553,7 +555,7 @@
     interp.s_active_context().push(w_object)
     interp.s_active_context().push(interp.ONE)
     interp.step()
-    assert interp.w_active_context().as_methodcontext_get_shadow().w_method() == shadow.methoddict["+"]
+    assert interp.w_active_context().as_methodcontext_get_shadow().w_method() == shadow.s_methoddict().methoddict["+"]
     assert interp.s_active_context().w_receiver() is w_object
     assert interp.w_active_context().as_methodcontext_get_shadow().gettemp(0) == interp.ONE
     assert interp.s_active_context().stack() == []
@@ -608,7 +610,7 @@
         assert interp.s_active_context().w_sender() == callerContext
         assert interp.s_active_context().stack() == []
         assert interp.w_active_context().as_methodcontext_get_shadow().w_receiver() == w_object
-        meth = w_specificclass.as_class_get_shadow().methoddict["foo"]
+        meth = w_specificclass.as_class_get_shadow().s_methoddict().methoddict["foo"]
         assert interp.w_active_context().as_methodcontext_get_shadow().w_method() == meth
         assert callerContext.as_context_get_shadow().stack() == []
 

Modified: pypy/branch/smalltalk-shadow-changes/pypy/lang/smalltalk/test/test_model.py
==============================================================================
--- pypy/branch/smalltalk-shadow-changes/pypy/lang/smalltalk/test/test_model.py	(original)
+++ pypy/branch/smalltalk-shadow-changes/pypy/lang/smalltalk/test/test_model.py	Sun May 18 19:13:06 2008
@@ -56,12 +56,14 @@
 def test_method_lookup():
     w_class = mockclass(0)
     shadow = w_class.as_class_get_shadow()
-    shadow.methoddict["foo"] = 1
-    shadow.methoddict["bar"] = 2
+    shadow.installmethod("foo", 1)
+    shadow.installmethod("bar", 2)
     w_subclass = mockclass(0, w_superclass=w_class)
     subshadow = w_subclass.as_class_get_shadow()
     assert subshadow.s_superclass is shadow
-    subshadow.methoddict["foo"] = 3
+    subshadow.installmethod("foo", 3)
+    shadow.initialize_methoddict()
+    subshadow.initialize_methoddict()
     assert shadow.lookup("foo") == 1
     assert shadow.lookup("bar") == 2
     py.test.raises(MethodNotFound, shadow.lookup, "zork")
@@ -76,6 +78,7 @@
     supershadow = w_super.as_class_get_shadow()
     supershadow.installmethod("foo", model.W_CompiledMethod(0))
     classshadow = w_class.as_class_get_shadow()
+    classshadow.initialize_methoddict()
     assert classshadow.lookup("foo").w_compiledin is w_super
 
 def test_compiledmethod_setchar():

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	Sun May 18 19:13:06 2008
@@ -67,7 +67,7 @@
                'bar': model.W_CompiledMethod(0)}
     w_class = build_smalltalk_class("Demo", 0x90, methods=methods)
     classshadow = w_class.as_class_get_shadow()
-    assert classshadow.methoddict == methods
+    assert classshadow.s_methoddict().methoddict == methods
 
 def method(tempsize=3,argsize=2, bytes="abcde"):
     w_m = model.W_CompiledMethod()



More information about the Pypy-commit mailing list