[pypy-svn] r55003 - in pypy/branch/smalltalk-shadow-changes/pypy/lang/smalltalk: . test
tverwaes at codespeak.net
tverwaes at codespeak.net
Tue May 20 16:12:10 CEST 2008
Author: tverwaes
Date: Tue May 20 16:12:09 2008
New Revision: 55003
Modified:
pypy/branch/smalltalk-shadow-changes/pypy/lang/smalltalk/model.py
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_shadow.py
Log:
(cfbolz, tverwaes) moving factory methods for contexts from model to shadow
Modified: pypy/branch/smalltalk-shadow-changes/pypy/lang/smalltalk/model.py
==============================================================================
--- pypy/branch/smalltalk-shadow-changes/pypy/lang/smalltalk/model.py (original)
+++ pypy/branch/smalltalk-shadow-changes/pypy/lang/smalltalk/model.py Tue May 20 16:12:09 2008
@@ -442,9 +442,9 @@
return w_literal.as_string() # XXX performance issue here
def create_frame(self, receiver, arguments, sender = None):
- from pypy.lang.smalltalk import objtable
+ from pypy.lang.smalltalk import objtable, shadow
assert len(arguments) == self.argsize
- w_new = W_MethodContext(self, receiver, arguments, sender)
+ w_new = shadow.MethodContextShadow.make_context(self, receiver, arguments, sender)
return w_new
def __str__(self):
@@ -557,45 +557,6 @@
self.bytes = (self.bytes[:index0] + character +
self.bytes[index0 + 1:])
-def W_BlockContext(w_home, w_sender, argcnt, initialip):
- from pypy.lang.smalltalk.classtable import w_BlockContext
- from pypy.lang.smalltalk import shadow
- # create and attach a shadow manually, to not have to carefully put things
- # into the right places in the W_PointersObject
- # XXX could hack some more to never have to create the _vars of w_result
- w_result = W_PointersObject(w_BlockContext, w_home.size())
- s_result = shadow.BlockContextShadow(w_result)
- w_result._shadow = s_result
- s_result.store_expected_argument_count(argcnt)
- s_result.store_initialip(initialip)
- s_result.store_w_home(w_home)
- s_result.store_pc(initialip)
- return w_result
-
-def W_MethodContext(w_method, w_receiver,
- arguments, w_sender=None):
- from pypy.lang.smalltalk.classtable import w_MethodContext
- from pypy.lang.smalltalk import objtable, shadow
- # From blue book: normal mc have place for 12 temps+maxstack
- # mc for methods with islarge flag turned on 32
- size = 12 + w_method.islarge * 20 + w_method.argsize
- w_result = w_MethodContext.as_class_get_shadow().new(size)
- assert isinstance(w_result, W_PointersObject)
- # create and attach a shadow manually, to not have to carefully put things
- # into the right places in the W_PointersObject
- # XXX could hack some more to never have to create the _vars of w_result
- s_result = shadow.MethodContextShadow(w_result)
- w_result._shadow = s_result
- s_result.store_w_method(w_method)
- if w_sender:
- s_result.store_w_sender(w_sender)
- s_result.store_w_receiver(w_receiver)
- s_result.store_pc(0)
- s_result._temps = [objtable.w_nil] * w_method.tempframesize()
- for i in range(len(arguments)):
- s_result.settemp(i, arguments[i])
- return w_result
-
# Use black magic to create w_nil without running the constructor,
# thus allowing it to be used even in the constructor of its own
# class. Note that we patch its class in objtable.
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 Tue May 20 16:12:09 2008
@@ -637,7 +637,7 @@
# The block bytecodes are stored inline: so we skip past the
# byteodes to invoke this primitive to find them (hence +2)
initialip = frame.pc() + 2
- w_new_context = model.W_BlockContext(
+ w_new_context = shadow.BlockContextShadow.make_context(
w_method_context, objtable.w_nil, argcnt, initialip)
return w_new_context
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 Tue May 20 16:12:09 2008
@@ -479,8 +479,20 @@
class BlockContextShadow(ContextPartShadow):
- def __init__(self, w_self):
- ContextPartShadow.__init__(self, w_self)
+ @staticmethod
+ def make_context(w_home, w_sender, argcnt, initialip):
+ from pypy.lang.smalltalk.classtable import w_BlockContext
+ # create and attach a shadow manually, to not have to carefully put things
+ # into the right places in the W_PointersObject
+ # XXX could hack some more to never have to create the _vars of w_result
+ w_result = model.W_PointersObject(w_BlockContext, w_home.size())
+ s_result = BlockContextShadow(w_result)
+ w_result._shadow = s_result
+ s_result.store_expected_argument_count(argcnt)
+ s_result.store_initialip(initialip)
+ s_result.store_w_home(w_home)
+ s_result.store_pc(initialip)
+ return w_result
def fetch(self, n0):
if n0 == constants.BLKCTX_HOME_INDEX:
@@ -558,6 +570,31 @@
self._w_receiver = None
ContextPartShadow.__init__(self, w_self)
+ @staticmethod
+ def make_context(w_method, w_receiver,
+ arguments, w_sender=None):
+ from pypy.lang.smalltalk.classtable import w_MethodContext
+ from pypy.lang.smalltalk import objtable
+ # From blue book: normal mc have place for 12 temps+maxstack
+ # mc for methods with islarge flag turned on 32
+ size = 12 + w_method.islarge * 20 + w_method.argsize
+ w_result = w_MethodContext.as_class_get_shadow().new(size)
+ assert isinstance(w_result, model.W_PointersObject)
+ # create and attach a shadow manually, to not have to carefully put things
+ # into the right places in the W_PointersObject
+ # XXX could hack some more to never have to create the _vars of w_result
+ s_result = MethodContextShadow(w_result)
+ w_result._shadow = s_result
+ s_result.store_w_method(w_method)
+ if w_sender:
+ s_result.store_w_sender(w_sender)
+ s_result.store_w_receiver(w_receiver)
+ s_result.store_pc(0)
+ s_result._temps = [objtable.w_nil] * w_method.tempframesize()
+ for i in range(len(arguments)):
+ s_result.settemp(i, arguments[i])
+ return w_result
+
def fetch(self, n0):
if n0 == constants.MTHDCTX_METHOD:
return self.w_method()
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 Tue May 20 16:12:09 2008
@@ -135,36 +135,4 @@
assert s_object.getbytecode() == 101
assert s_object.s_home() == s_object
-#def test_scheduler():
-# w_process = process()
-# w_pl = model.W_PointersObject(None, 0)
-# w_object = model.W_PointersObject(None, 2)
-# w_object.store(constants.SCHEDULER_ACTIVE_PROCESS_INDEX, w_process)
-# w_object.store(constants.SCHEDULER_PROCESS_LISTS_INDEX, w_pl)
-# s_object = w_object.as_scheduler_get_shadow()
-# assert s_object.s_active_process() == w_process.as_process_get_shadow()
-# assert s_object.process_lists() == w_pl
-# w_process2 = process()
-# s_object.store_w_active_process(w_process2)
-# assert s_object.process_lists() == w_pl
-# assert s_object.s_active_process() != w_process.as_process_get_shadow()
-# assert s_object.s_active_process() == w_process2.as_process_get_shadow()
-#def test_shadowchanges():
-# w_object = model.W_PointersObject(None, 2)
-# w_o1 = link('a')
-# w_o2 = link('b')
-# w_object.store(0, w_o1)
-# w_object.store(1, w_o2)
-# s_object = w_object.as_linkedlist_get_shadow()
-# assert s_object.w_firstlink() == w_o1
-# assert s_object.w_lastlink() == w_o2
-# assert w_object._shadow == s_object
-# s_object2 = w_object.as_association_get_shadow()
-# assert s_object2.key() == w_o1
-# assert s_object2.value() == w_o2
-# assert w_object._shadow == s_object2
-# s_object.sync_shadow()
-# assert s_object.w_firstlink() == w_o1
-# assert s_object.w_lastlink() == w_o2
-# assert w_object._shadow == s_object
More information about the Pypy-commit
mailing list