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

cfbolz at codespeak.net cfbolz at codespeak.net
Sun May 25 16:09:10 CEST 2008


Author: cfbolz
Date: Sun May 25 16:09:07 2008
New Revision: 55204

Added:
   pypy/branch/smalltalk-shadow-changes/pypy/lang/smalltalk/space.py   (contents, props changed)
   pypy/branch/smalltalk-shadow-changes/pypy/lang/smalltalk/test/test_objectspace.py
      - copied, changed from r55192, pypy/branch/smalltalk-shadow-changes/pypy/lang/smalltalk/test/test_classtable.py
Removed:
   pypy/branch/smalltalk-shadow-changes/pypy/lang/smalltalk/classtable.py
   pypy/branch/smalltalk-shadow-changes/pypy/lang/smalltalk/objtable.py
   pypy/branch/smalltalk-shadow-changes/pypy/lang/smalltalk/test/test_classtable.py
   pypy/branch/smalltalk-shadow-changes/pypy/lang/smalltalk/utility.py
Modified:
   pypy/branch/smalltalk-shadow-changes/pypy/lang/smalltalk/interpreter.py
   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/squeakimage.py
   pypy/branch/smalltalk-shadow-changes/pypy/lang/smalltalk/test/test_interpreter.py
   pypy/branch/smalltalk-shadow-changes/pypy/lang/smalltalk/test/test_miniimage.py
   pypy/branch/smalltalk-shadow-changes/pypy/lang/smalltalk/test/test_model.py
   pypy/branch/smalltalk-shadow-changes/pypy/lang/smalltalk/test/test_primitives.py
   pypy/branch/smalltalk-shadow-changes/pypy/lang/smalltalk/test/test_shadow.py
   pypy/branch/smalltalk-shadow-changes/pypy/lang/smalltalk/test/test_squeakimage.py
   pypy/branch/smalltalk-shadow-changes/pypy/lang/smalltalk/test/test_wrapper.py
   pypy/branch/smalltalk-shadow-changes/pypy/lang/smalltalk/wrapper.py
Log:
huge refactoring to introduce an "object space" that holds all globally
accessible objects and has helper functionality. No the interpreter has no
globals any more. On the other hand, the space needs to be passed a bit
everywhere.


Modified: pypy/branch/smalltalk-shadow-changes/pypy/lang/smalltalk/interpreter.py
==============================================================================
--- pypy/branch/smalltalk-shadow-changes/pypy/lang/smalltalk/interpreter.py	(original)
+++ pypy/branch/smalltalk-shadow-changes/pypy/lang/smalltalk/interpreter.py	Sun May 25 16:09:07 2008
@@ -1,7 +1,6 @@
 import py
 from pypy.lang.smalltalk.shadow import ContextPartShadow, MethodContextShadow, BlockContextShadow
 from pypy.lang.smalltalk import model, constants, primitives
-from pypy.lang.smalltalk import objtable
 from pypy.lang.smalltalk.shadow import ContextPartShadow
 from pypy.lang.smalltalk.conftest import option
 from pypy.rlib import objectmodel, unroll
@@ -19,18 +18,11 @@
 
 class Interpreter(object):
 
-    TRUE = objtable.w_true
-    FALSE = objtable.w_false
-    NIL = objtable.w_nil
-    MINUS_ONE = objtable.w_minus_one
-    ZERO = objtable.w_zero
-    ONE = objtable.w_one
-    TWO = objtable.w_two
-
     _w_last_active_context = None
     
-    def __init__(self):
+    def __init__(self, space):
         self._w_active_context = None
+        self.space = space
         self.cnt = 0
 
     def w_active_context(self):
@@ -41,7 +33,7 @@
         self._w_active_context = w_context
 
     def s_active_context(self):
-        return self.w_active_context().as_context_get_shadow()
+        return self.w_active_context().as_context_get_shadow(self.space)
 
     def interpret(self):
         try:
@@ -65,11 +57,11 @@
                     cnt = 0
                     p = self.w_active_context()
                     # AK make method
-                    while p is not objtable.w_nil:
+                    while p is not self.space.w_nil:
                         cnt += 1
                                                   # Do not update the context
                                                   # for this action.
-                        p = p.as_context_get_shadow().w_sender()
+                        p = p.as_context_get_shadow(self.space).w_sender()
                     self._last_indent = "  " * cnt
                     self._w_last_active_context = self.w_active_context()
 
@@ -124,7 +116,7 @@
         # named var (the value).
         index = self.currentBytecode & 31
         w_association = self.w_method().getliteral(index)
-        association = wrapper.AssociationWrapper(w_association)
+        association = wrapper.AssociationWrapper(self.space, w_association)
         self.push(association.value())
 
     def storeAndPopReceiverVariableBytecode(self, interp):
@@ -140,25 +132,25 @@
         self.push(self.w_receiver())
 
     def pushConstantTrueBytecode(self, interp):
-        self.push(interp.TRUE)
+        self.push(interp.space.w_true)
 
     def pushConstantFalseBytecode(self, interp):
-        self.push(interp.FALSE)
+        self.push(interp.space.w_false)
 
     def pushConstantNilBytecode(self, interp):
-        self.push(interp.NIL)
+        self.push(interp.space.w_nil)
 
     def pushConstantMinusOneBytecode(self, interp):
-        self.push(interp.MINUS_ONE)
+        self.push(interp.space.w_minus_one)
 
     def pushConstantZeroBytecode(self, interp):
-        self.push(interp.ZERO)
+        self.push(interp.space.w_zero)
 
     def pushConstantOneBytecode(self, interp):
-        self.push(interp.ONE)
+        self.push(interp.space.w_one)
 
     def pushConstantTwoBytecode(self, interp):
-        self.push(interp.TWO)
+        self.push(interp.space.w_two)
 
     def pushActiveContextBytecode(self, interp):
         self.push(self.w_self())
@@ -175,12 +167,12 @@
     def _sendSelfSelector(self, selector, argcount, interp):
         receiver = self.peek(argcount)
         self._sendSelector(selector, argcount, interp,
-                           receiver, receiver.shadow_of_my_class())             
+                           receiver, receiver.shadow_of_my_class(self.space))
 
     def _sendSuperSelector(self, selector, argcount, interp):
         w_compiledin = self.w_method().compiledin()
         assert isinstance(w_compiledin, model.W_PointersObject)
-        s_compiledin = w_compiledin.as_class_get_shadow()
+        s_compiledin = w_compiledin.as_class_get_shadow(self.space)
         self._sendSelector(selector, argcount, interp, self.w_receiver(),
                            s_compiledin.s_superclass())
 
@@ -219,28 +211,29 @@
                         print "PRIMITIVE FAILED: %d %s" % (method.primitive, selector,)
                     pass # ignore this error and fall back to the Smalltalk version
         arguments = self.pop_and_return_n(argcount)
-        interp.store_w_active_context(method.create_frame(receiver, arguments,
-                                                          self.w_self()))
+        frame = method.create_frame(self.space, receiver, arguments,
+                                    self.w_self())
+        interp.store_w_active_context(frame)
         self.pop()
 
     def _return(self, object, interp, w_return_to):
         # for tests, when returning from the top-level context
-        if w_return_to is objtable.w_nil:
+        if w_return_to is self.space.w_nil:
             raise ReturnFromTopLevel(object)
-        w_return_to.as_context_get_shadow().push(object)
+        w_return_to.as_context_get_shadow(self.space).push(object)
         interp.store_w_active_context(w_return_to)
 
     def returnReceiver(self, interp):
         self._return(self.w_receiver(), interp, self.s_home().w_sender())
 
     def returnTrue(self, interp):
-        self._return(interp.TRUE, interp, self.s_home().w_sender())
+        self._return(interp.space.w_true, interp, self.s_home().w_sender())
 
     def returnFalse(self, interp):
-        self._return(interp.FALSE, interp, self.s_home().w_sender())
+        self._return(interp.space.w_false, interp, self.s_home().w_sender())
 
     def returnNil(self, interp):
-        self._return(interp.NIL, interp, self.s_home().w_sender())
+        self._return(interp.space.w_nil, interp, self.s_home().w_sender())
 
     def returnTopFromMethod(self, interp):
         self._return(self.top(), interp, self.s_home().w_sender())
@@ -266,7 +259,7 @@
             self.push(self.w_method().getliteral(variableIndex))
         elif variableType == 3:
             w_association = self.w_method().getliteral(variableIndex)
-            association = wrapper.AssociationWrapper(w_association)
+            association = wrapper.AssociationWrapper(self.space, w_association)
             self.push(association.value())
         else:
             assert 0
@@ -281,7 +274,7 @@
             raise IllegalStoreError
         elif variableType == 3:
             w_association = self.w_method().getliteral(variableIndex)
-            association = wrapper.AssociationWrapper(w_association)
+            association = wrapper.AssociationWrapper(self.space, w_association)
             association.store_value(self.top())
 
     def extendedStoreAndPopBytecode(self, interp):
@@ -318,7 +311,7 @@
         elif opType == 4:
             # pushLiteralVariable
             w_association = self.w_method().getliteral(third)
-            association = wrapper.AssociationWrapper(w_association)
+            association = wrapper.AssociationWrapper(self.space, w_association)
             self.push(association.value())
         elif opType == 5:
             self.w_receiver().store(third, self.top())
@@ -326,7 +319,7 @@
             self.w_receiver().store(third, self.pop())
         elif opType == 7:
             w_association = self.w_method().getliteral(third)
-            association = wrapper.AssociationWrapper(w_association)
+            association = wrapper.AssociationWrapper(self.space, w_association)
             association.store_value(self.top())
 
     def singleExtendedSuperBytecode(self, interp):
@@ -360,7 +353,7 @@
         self.jump(self.shortJumpPosition())
 
     def shortConditionalJump(self, interp):
-        self.jumpConditional(interp.FALSE,self.shortJumpPosition())
+        self.jumpConditional(interp.space.w_false, self.shortJumpPosition())
 
     def longUnconditionalJump(self, interp):
         self.jump((((self.currentBytecode & 7) - 4) << 8) + self.getbytecode())
@@ -369,10 +362,10 @@
         return ((self.currentBytecode & 3) << 8) + self.getbytecode()
 
     def longJumpIfTrue(self, interp):
-        self.jumpConditional(interp.TRUE,self.longJumpPosition())
+        self.jumpConditional(interp.space.w_true, self.longJumpPosition())
 
     def longJumpIfFalse(self, interp):
-        self.jumpConditional(interp.FALSE,self.longJumpPosition())
+        self.jumpConditional(interp.space.w_false, self.longJumpPosition())
 
     # RPython trick: specialize the following function on its second argument
     # this makes sure that the primitive call is a direct one

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	Sun May 25 16:09:07 2008
@@ -33,17 +33,17 @@
         space, as memory representation varies depending on PyPy translation."""
         return 0
 
-    def varsize(self):
+    def varsize(self, space):
         """Return bytesize of variable-sized part.
 
         Variable sized objects are those created with #new:."""
-        return self.size()
+        return self.size(space)
 
-    def primsize(self):
+    def primsize(self, space):
         # TODO remove this method
         return self.size()
 
-    def getclass(self):
+    def getclass(self, space):
         """Return Squeak class."""
         raise NotImplementedError()
 
@@ -51,7 +51,7 @@
         """Return 31-bit hash value."""
         raise NotImplementedError()
 
-    def at0(self, index0):
+    def at0(self, space, index0):
         """Access variable-sized part, as by Object>>at:.
 
         Return value depends on layout of instance. Byte objects return bytes,
@@ -60,7 +60,7 @@
         otherwise returns byte (ie byte code indexing starts at literalsize)."""
         raise NotImplementedError()
 
-    def atput0(self, index0, w_value):
+    def atput0(self, space, index0, w_value):
         """Access variable-sized part, as by Object>>at:put:.
 
         Semantics depend on layout of instance. Byte objects set bytes,
@@ -83,9 +83,9 @@
     def invariant(self):
         return True
 
-    def shadow_of_my_class(self):
+    def shadow_of_my_class(self, space):
         """Return internal representation of Squeak class."""
-        return self.getclass().as_class_get_shadow()
+        return self.getclass(space).as_class_get_shadow(space)
 
     def is_same_object(self, other):
         """Compare object identity"""
@@ -104,10 +104,9 @@
     def __init__(self, value):
         self.value = value
 
-    def getclass(self):
+    def getclass(self, space):
         """Return SmallInteger from special objects array."""
-        from pypy.lang.smalltalk.classtable import w_SmallInteger
-        return w_SmallInteger
+        return space.w_SmallInteger
 
     def gethash(self):
         return self.value
@@ -141,10 +140,9 @@
     def __init__(self, value):
         self.value = value
 
-    def getclass(self):
+    def getclass(self, space):
         """Return Float from special objects array."""
-        from pypy.lang.smalltalk.classtable import w_Float
-        return w_Float
+        return space.w_Float
 
     def gethash(self):
         return 41    # XXX check this
@@ -208,7 +206,7 @@
             assert isinstance(w_class, W_PointersObject)
         self.w_class = w_class
 
-    def getclass(self):
+    def getclass(self, space):
         assert self.w_class is not None
         return self.w_class
 
@@ -219,7 +217,10 @@
         if isinstance(self, W_PointersObject) and self._shadow is not None:
             return self._shadow.getname()
         else:
-            return "a %s" % (self.shadow_of_my_class().name or '?',)
+            name = None
+            if self.w_class._shadow is not None:
+                name = self.w_class._shadow.name
+            return "a %s" % (name or '?',)
 
     def invariant(self):
         return (W_AbstractObjectWithIdentityHash.invariant(self) and
@@ -242,13 +243,13 @@
         W_AbstractObjectWithClassReference.__init__(self, w_class)
         self._vars = [w_nil] * size
 
-    def at0(self, index0):
+    def at0(self, space, index0):
         # To test, at0 = in varsize part
-        return self.fetch(index0+self.instsize())
+        return self.fetch(index0+self.instsize(space))
 
-    def atput0(self, index0, w_value):
+    def atput0(self, space, index0, w_value):
         # To test, at0 = in varsize part
-        self.store(index0+self.instsize(), w_value)
+        self.store(index0+self.instsize(space), w_value)
 
     def fetch(self, n0):
         if self._shadow is not None:
@@ -272,14 +273,14 @@
     # def storevarpointer(self, idx, value):
     #    self._vars[idx+self.instsize()] = value
 
-    def varsize(self):
-        return self.size() - self.instsize()
+    def varsize(self, space):
+        return self.size() - self.instsize(space)
 
-    def instsize(self):
-        return self.shadow_of_my_class().instsize()
+    def instsize(self, space):
+        return self.shadow_of_my_class(space).instsize()
 
-    def primsize(self):
-        return self.varsize()
+    def primsize(self, space):
+        return self.varsize(space)
 
     def size(self):
         if self._shadow is not None:
@@ -296,52 +297,52 @@
     def store_shadow(self, shadow):
         self._shadow = shadow
 
-    @objectmodel.specialize.arg(1)
-    def attach_shadow_of_class(self, TheClass):
-        shadow = TheClass(self)
+    @objectmodel.specialize.arg(2)
+    def attach_shadow_of_class(self, space, TheClass):
+        shadow = TheClass(space, self)
         self._shadow = shadow
         shadow.attach_shadow()
         return shadow
 
-    @objectmodel.specialize.arg(1)
-    def as_special_get_shadow(self, TheClass):
+    @objectmodel.specialize.arg(2)
+    def as_special_get_shadow(self, space, TheClass):
         shadow = self._shadow
         if shadow is None:
-            shadow = self.attach_shadow_of_class(TheClass)
+            shadow = self.attach_shadow_of_class(space, TheClass)
         elif not isinstance(shadow, TheClass):
             shadow.detach_shadow()
-            shadow = self.attach_shadow_of_class(TheClass)
+            shadow = self.attach_shadow_of_class(space, TheClass)
         shadow.sync_shadow()
         return shadow
 
-    def get_shadow(self):
+    def get_shadow(self, space):
         from pypy.lang.smalltalk.shadow import AbstractShadow
-        return self.as_special_get_shadow(AbstractShadow)
+        return self.as_special_get_shadow(space, AbstractShadow)
 
-    def as_class_get_shadow(self):
+    def as_class_get_shadow(self, space):
         from pypy.lang.smalltalk.shadow import ClassShadow
-        return self.as_special_get_shadow(ClassShadow)
+        return self.as_special_get_shadow(space, ClassShadow)
 
-    def as_blockcontext_get_shadow(self):
+    def as_blockcontext_get_shadow(self, space):
         from pypy.lang.smalltalk.shadow import BlockContextShadow
-        return self.as_special_get_shadow(BlockContextShadow)
+        return self.as_special_get_shadow(space, BlockContextShadow)
 
-    def as_methodcontext_get_shadow(self):
+    def as_methodcontext_get_shadow(self, space):
         from pypy.lang.smalltalk.shadow import MethodContextShadow
-        return self.as_special_get_shadow(MethodContextShadow)
+        return self.as_special_get_shadow(space, MethodContextShadow)
 
-    def as_context_get_shadow(self):
+    def as_context_get_shadow(self, space):
         from pypy.lang.smalltalk.shadow import ContextPartShadow
         # XXX TODO should figure out itself if its method or block context
         if self._shadow is None:
-            if ContextPartShadow.is_block_context(self):
-                return self.as_blockcontext_get_shadow()
-            return self.as_methodcontext_get_shadow()
-        return self.as_special_get_shadow(ContextPartShadow)
+            if ContextPartShadow.is_block_context(self, space):
+                return self.as_blockcontext_get_shadow(space)
+            return self.as_methodcontext_get_shadow(space)
+        return self.as_special_get_shadow(space, ContextPartShadow)
 
-    def as_methoddict_get_shadow(self):
+    def as_methoddict_get_shadow(self, space):
         from pypy.lang.smalltalk.shadow import MethodDictionaryShadow
-        return self.as_special_get_shadow(MethodDictionaryShadow)
+        return self.as_special_get_shadow(space, MethodDictionaryShadow)
 
     def become(self, w_other):
         if not isinstance(w_other, W_PointersObject):
@@ -356,13 +357,11 @@
         W_AbstractObjectWithClassReference.__init__(self, w_class)
         self.bytes = ['\x00'] * size
 
-    def at0(self, index0):
-        from pypy.lang.smalltalk import utility
-        return utility.wrap_int(ord(self.getchar(index0)))
+    def at0(self, space, index0):
+        return space.wrap_int(ord(self.getchar(index0)))
        
-    def atput0(self, index0, w_value):
-        from pypy.lang.smalltalk import utility
-        self.setchar(index0, chr(utility.unwrap_int(w_value)))
+    def atput0(self, space, index0, w_value):
+        self.setchar(index0, chr(space.unwrap_int(w_value)))
 
     def getchar(self, n0):
         return self.bytes[n0]
@@ -401,13 +400,11 @@
         W_AbstractObjectWithClassReference.__init__(self, w_class)
         self.words = [0] * size
         
-    def at0(self, index0):
-        from pypy.lang.smalltalk import utility
-        return utility.wrap_int(self.getword(index0))
+    def at0(self, space, index0):
+        return space.wrap_int(self.getword(index0))
        
-    def atput0(self, index0, w_value):
-        from pypy.lang.smalltalk import utility
-        self.setword(index0, utility.unwrap_int(w_value))
+    def atput0(self, space, index0, w_value):
+        self.setword(index0, space.unwrap_int(w_value))
 
     def getword(self, n):
         return self.words[n]
@@ -457,13 +454,13 @@
             # Last of the literals is an association with compiledin
             # as a class
             w_association = self.literals[-1]
-            association = wrapper.AssociationWrapper(w_association)
+            # XXX XXX XXX where to get a space from here
+            association = wrapper.AssociationWrapper(None, w_association)
             self.w_compiledin = association.value()
         return self.w_compiledin
 
-    def getclass(self):
-        from pypy.lang.smalltalk.classtable import w_CompiledMethod
-        return w_CompiledMethod
+    def getclass(self, space):
+        return space.w_CompiledMethod
 
     def getliteral(self, index):
                                     # We changed this part
@@ -474,10 +471,11 @@
         assert isinstance(w_literal, W_BytesObject)
         return w_literal.as_string()    # XXX performance issue here
 
-    def create_frame(self, receiver, arguments, sender = None):
-        from pypy.lang.smalltalk import objtable, shadow
+    def create_frame(self, space, receiver, arguments, sender = None):
+        from pypy.lang.smalltalk import shadow
         assert len(arguments) == self.argsize
-        w_new = shadow.MethodContextShadow.make_context(self, receiver, arguments, sender)
+        w_new = shadow.MethodContextShadow.make_context(
+                space, self, receiver, arguments, sender)
         return w_new
 
     def __str__(self):
@@ -541,17 +539,15 @@
         self.w_compiledin = None
         self.islarge = islarge
 
-    def literalat0(self, index0):
+    def literalat0(self, space, index0):
         if index0 == 0:
-            from pypy.lang.smalltalk import utility
-            return utility.wrap_int(self.getheader())
+            return space.wrap_int(self.getheader())
         else:
             return self.literals[index0-1]
 
-    def literalatput0(self, index0, w_value):
+    def literalatput0(self, space, index0, w_value):
         if index0 == 0:
-            from pypy.lang.smalltalk import utility
-            header = utility.unwrap_int(w_value)
+            header = space.unwrap_int(w_value)
             self.setheader(header)
         else:
             self.literals[index0-1] = w_value
@@ -559,10 +555,9 @@
     def store(self, index0, w_v):
         self.atput0(index0, w_v)
 
-    def at0(self, index0):
-        from pypy.lang.smalltalk import utility
+    def at0(self, space, index0):
         if index0 <= self.getliteralsize():
-            return self.literalat0(index0/constants.BYTES_PER_WORD)
+            return self.literalat0(space, index0 / constants.BYTES_PER_WORD)
         else:
             # From blue book:
             # The literal count indicates the size of the
@@ -571,17 +566,16 @@
             # CompiledMethod's bytecodes start. 
             index0 = index0 - self.getliteralsize() - self.headersize()
             assert index0 < len(self.bytes)
-            return utility.wrap_int(ord(self.bytes[index0]))
+            return space.wrap_int(ord(self.bytes[index0]))
         
-    def atput0(self, index0, w_value):
-        from pypy.lang.smalltalk import utility
+    def atput0(self, space, index0, w_value):
         if index0 <= self.getliteralsize():
-            self.literalatput0(index0/constants.BYTES_PER_WORD, w_value)
+            self.literalatput0(space, index0 / constants.BYTES_PER_WORD, w_value)
         else:
             # XXX use to-be-written unwrap_char
             index0 = index0 - self.getliteralsize() - self.headersize()
             assert index0 < len(self.bytes)
-            self.setchar(index0, chr(utility.unwrap_int(w_value)))
+            self.setchar(index0, chr(space.unwrap_int(w_value)))
 
     def setchar(self, index0, character):
         assert index0 >= 0
@@ -590,6 +584,7 @@
 
 # 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.
+# class.  Note that we patch its class in the space
+# YYY there should be no global w_nil
 w_nil = instantiate(W_PointersObject)
 w_nil._vars = []

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 25 16:09:07 2008
@@ -1,9 +1,7 @@
 import inspect
 import math
 import operator
-from pypy.lang.smalltalk import model, shadow, utility
-from pypy.lang.smalltalk import classtable
-from pypy.lang.smalltalk import objtable
+from pypy.lang.smalltalk import model, shadow
 from pypy.lang.smalltalk import constants
 from pypy.lang.smalltalk.error import PrimitiveFailedError, \
     PrimitiveNotYetWrittenError
@@ -15,8 +13,8 @@
     if not minimum <= n0 < maximum:
         raise PrimitiveFailedError()
 
-def assert_valid_index(n0, w_obj):
-    if not 0 <= n0 < w_obj.primsize():
+def assert_valid_index(space, n0, w_obj):
+    if not 0 <= n0 < w_obj.primsize(space):
         raise PrimitiveFailedError()
     # return the index, since from here on the annotator knows that
     # n0 cannot be negative
@@ -79,7 +77,7 @@
             def wrapped(interp, argument_count_m1):
                 argument_count = argument_count_m1 + 1 # to account for the rcvr
                 frame = interp.w_active_context()
-                s_frame = frame.as_context_get_shadow()
+                s_frame = frame.as_context_get_shadow(interp.space)
                 assert argument_count == len_unwrap_spec
                 if len(s_frame.stack()) < len_unwrap_spec:
                     raise PrimitiveFailedError()
@@ -88,11 +86,11 @@
                     index = len_unwrap_spec - 1 - i
                     w_arg = s_frame.peek(index)
                     if spec is int:
-                        args += (utility.unwrap_int(w_arg), )
+                        args += (interp.space.unwrap_int(w_arg), )
                     elif spec is index1_0:
-                        args += (utility.unwrap_int(w_arg)-1, )
+                        args += (interp.space.unwrap_int(w_arg)-1, )
                     elif spec is float:
-                        args += (utility.unwrap_float(w_arg), )
+                        args += (interp.space.unwrap_float(w_arg), )
                     elif spec is object:
                         args += (w_arg, )
                     elif spec is str:
@@ -107,7 +105,7 @@
                 # After calling primitive, reload context-shadow in case it
                 # needs to be updated
                 new_s_frame = interp.s_active_context()
-                frame.as_context_get_shadow().pop_n(len_unwrap_spec)   # only if no exception occurs!
+                frame.as_context_get_shadow(interp.space).pop_n(len_unwrap_spec)   # only if no exception occurs!
                 if not no_result:
                     assert w_result is not None
                     new_s_frame.push(w_result)
@@ -146,7 +144,7 @@
                 res = rarithmetic.ovfcheck(op(receiver, argument))
             except OverflowError:
                 raise PrimitiveFailedError()
-            return utility.wrap_int(res)
+            return interp.space.wrap_int(res)
     make_func(op)
 
 bitwise_binary_ops = {
@@ -159,7 +157,7 @@
         @expose_primitive(code, unwrap_spec=[int, int])
         def func(interp, receiver, argument):
             res = op(receiver, argument)
-            return utility.wrap_int(res)
+            return interp.space.wrap_int(res)
     make_func(op)
 
 # #/ -- return the result of a division, only succeed if the division is exact
@@ -169,28 +167,28 @@
         raise PrimitiveFailedError()
     if receiver % argument != 0:
         raise PrimitiveFailedError()
-    return utility.wrap_int(receiver // argument)
+    return interp.space.wrap_int(receiver // argument)
 
 # #\\ -- return the remainder of a division
 @expose_primitive(MOD, unwrap_spec=[int, int])
 def func(interp, receiver, argument):
     if argument == 0:
         raise PrimitiveFailedError()
-    return utility.wrap_int(receiver % argument)
+    return interp.space.wrap_int(receiver % argument)
 
 # #// -- return the result of a division, rounded towards negative zero
 @expose_primitive(DIV, unwrap_spec=[int, int])
 def func(interp, receiver, argument):
     if argument == 0:
         raise PrimitiveFailedError()
-    return utility.wrap_int(receiver // argument)
+    return interp.space.wrap_int(receiver // argument)
     
 # #// -- return the result of a division, rounded towards negative infinity
 @expose_primitive(QUO, unwrap_spec=[int, int])
 def func(interp, receiver, argument):
     if argument == 0:
         raise PrimitiveFailedError()
-    return utility.wrap_int(receiver // argument)
+    return interp.space.wrap_int(receiver // argument)
     
 # #bitShift: -- return the shifted value
 @expose_primitive(BIT_SHIFT, unwrap_spec=[int, int])
@@ -201,11 +199,11 @@
         shifted = receiver << argument
         if (shifted >> argument) != receiver:
             raise PrimitiveFailedError()
-        return utility.wrap_int(shifted)
+        return interp.space.wrap_int(shifted)
             
     # right shift, ok to lose bits
     else:
-        return utility.wrap_int(receiver >> -argument)
+        return interp.space.wrap_int(receiver >> -argument)
    
 
 # ___________________________________________________________________________
@@ -236,35 +234,35 @@
     def make_func(op):
         @expose_primitive(code, unwrap_spec=[float, float])
         def func(interp, v1, v2):
-            w_res = utility.wrap_float(op(v1, v2))
+            w_res = interp.space.wrap_float(op(v1, v2))
             return w_res
     make_func(op)
 
 @expose_primitive(FLOAT_TRUNCATED, unwrap_spec=[float])
 def func(interp, f): 
-    w_res = utility.wrap_int(int(f))
+    w_res = interp.space.wrap_int(int(f))
     return w_res
 
 @expose_primitive(FLOAT_TIMES_TWO_POWER, unwrap_spec=[float, int])
 def func(interp, rcvr, arg): 
-    w_res = utility.wrap_float(math.ldexp(rcvr, arg))
+    w_res = interp.space.wrap_float(math.ldexp(rcvr, arg))
     return w_res
 
 @expose_primitive(FLOAT_SQUARE_ROOT, unwrap_spec=[float])
 def func(interp, f): 
     if f < 0.0:
         raise PrimitiveFailedError
-    w_res = utility.wrap_float(math.sqrt(f))
+    w_res = interp.space.wrap_float(math.sqrt(f))
     return w_res
 
 @expose_primitive(FLOAT_SIN, unwrap_spec=[float])
 def func(interp, f): 
-    w_res = utility.wrap_float(math.sin(f))
+    w_res = interp.space.wrap_float(math.sin(f))
     return w_res
 
 @expose_primitive(FLOAT_ARCTAN, unwrap_spec=[float])
 def func(interp, f): 
-    w_res = utility.wrap_float(math.atan(f))
+    w_res = interp.space.wrap_float(math.atan(f))
     return w_res
 
 @expose_primitive(FLOAT_LOG_N, unwrap_spec=[float])
@@ -275,11 +273,11 @@
         res = rarithmetic.NAN
     else:
         res = math.log(f)
-    return utility.wrap_float(res)
+    return interp.space.wrap_float(res)
 
 @expose_primitive(FLOAT_EXP, unwrap_spec=[float])
 def func(interp, f): 
-    w_res = utility.wrap_float(math.exp(f))
+    w_res = interp.space.wrap_float(math.exp(f))
     return w_res
 
 # ___________________________________________________________________________
@@ -298,34 +296,34 @@
 
 @expose_primitive(AT, unwrap_spec=[object, index1_0])
 def func(interp, w_obj, n0):
-    n0 = assert_valid_index(n0, w_obj)
-    return w_obj.at0(n0)
+    n0 = assert_valid_index(interp.space, n0, w_obj)
+    return w_obj.at0(interp.space, n0)
 
 @expose_primitive(AT_PUT, unwrap_spec=[object, index1_0, object])
 def func(interp, w_obj, n0, w_val):
-    n0 = assert_valid_index(n0, w_obj)
-    w_obj.atput0(n0, w_val)
+    n0 = assert_valid_index(interp.space, n0, w_obj)
+    w_obj.atput0(interp.space, n0, w_val)
     return w_val
 
 @expose_primitive(SIZE, unwrap_spec=[object])
 def func(interp, w_obj):
-    if not w_obj.shadow_of_my_class().isvariable():
+    if not w_obj.shadow_of_my_class(interp.space).isvariable():
         raise PrimitiveFailedError()
-    return utility.wrap_int(w_obj.primsize())
+    return interp.space.wrap_int(w_obj.primsize(interp.space))
 
 @expose_primitive(STRING_AT, unwrap_spec=[object, index1_0])
 def func(interp, w_obj, n0):
-    n0 = assert_valid_index(n0, w_obj)
+    n0 = assert_valid_index(interp.space, n0, w_obj)
     # XXX I am not sure this is correct, but it un-breaks translation:
     # make sure that getbyte is only performed on W_BytesObjects
     if not isinstance(w_obj, model.W_BytesObject):
         raise PrimitiveFailedError
-    return utility.wrap_char(w_obj.getchar(n0))
+    return interp.space.wrap_char(w_obj.getchar(n0))
 
 @expose_primitive(STRING_AT_PUT, unwrap_spec=[object, index1_0, object])
 def func(interp, w_obj, n0, w_val):
-    val = utility.unwrap_char(w_val)
-    n0 = assert_valid_index(n0, w_obj)
+    val = interp.space.unwrap_char(w_val)
+    n0 = assert_valid_index(interp.space, n0, w_obj)
     if not (isinstance(w_obj, model.W_CompiledMethod) or
             isinstance(w_obj, model.W_BytesObject)):
         raise PrimitiveFailedError()
@@ -359,20 +357,20 @@
 def func(interp, w_rcvr, n0):
     if not isinstance(w_rcvr, model.W_CompiledMethod):
         raise PrimitiveFailedError()
-    return w_rcvr.literalat0(n0)
+    return w_rcvr.literalat0(interp.space, n0)
 
 @expose_primitive(OBJECT_AT_PUT, unwrap_spec=[object, index1_0, object])
 def func(interp, w_rcvr, n0, w_value):
     if not isinstance(w_rcvr, model.W_CompiledMethod):
         raise PrimitiveFailedError()
     #assert_bounds(n0, 0, len(w_rcvr.literals))
-    w_rcvr.literalatput0(n0, w_value)
+    w_rcvr.literalatput0(interp.space, n0, w_value)
     return w_value
 
 @expose_primitive(NEW, unwrap_spec=[object])
 def func(interp, w_cls):
     assert isinstance(w_cls, model.W_PointersObject)
-    s_class = w_cls.as_class_get_shadow()
+    s_class = w_cls.as_class_get_shadow(interp.space)
     if s_class.isvariable():
         raise PrimitiveFailedError()
     return s_class.new()
@@ -380,7 +378,7 @@
 @expose_primitive(NEW_WITH_ARG, unwrap_spec=[object, int])
 def func(interp, w_cls, size):
     assert isinstance(w_cls, model.W_PointersObject)
-    s_class = w_cls.as_class_get_shadow()
+    s_class = w_cls.as_class_get_shadow(interp.space)
     if not s_class.isvariable():
         raise PrimitiveFailedError()
     return s_class.new(size)
@@ -392,7 +390,7 @@
 @expose_primitive(INST_VAR_AT, unwrap_spec=[object, index1_0])
 def func(interp, w_rcvr, n0):
     "Fetches a fixed field from the object, and fails otherwise"
-    s_class = w_rcvr.shadow_of_my_class()
+    s_class = w_rcvr.shadow_of_my_class(interp.space)
     assert_bounds(n0, 0, s_class.instsize())
     # only pointers have non-0 size
     # XXX Now MethodContext is still own format, leave
@@ -402,7 +400,7 @@
 @expose_primitive(INST_VAR_AT_PUT, unwrap_spec=[object, index1_0, object])
 def func(interp, w_rcvr, n0, w_value):
     "Stores a value into a fixed field from the object, and fails otherwise"
-    s_class = w_rcvr.shadow_of_my_class()
+    s_class = w_rcvr.shadow_of_my_class(interp.space)
     assert_bounds(n0, 0, s_class.instsize())
     # XXX Now MethodContext is still own format, leave
     #assert isinstance(w_rcvr, model.W_PointersObject)
@@ -413,7 +411,7 @@
 def func(interp, w_rcvr):
     if isinstance(w_rcvr, model.W_SmallInteger):
         raise PrimitiveFailedError()
-    return utility.wrap_int(w_rcvr.gethash())
+    return interp.space.wrap_int(w_rcvr.gethash())
 
 @expose_primitive(STORE_STACKP, unwrap_spec=[object, object])
 def func(interp, w_obj1, w_obj2):
@@ -452,11 +450,11 @@
 
 @expose_primitive(EQUIVALENT, unwrap_spec=[object, object])
 def func(interp, w_arg, w_rcvr):
-    return utility.wrap_bool(w_arg.is_same_object(w_rcvr))
+    return interp.space.wrap_bool(w_arg.is_same_object(w_rcvr))
 
 @expose_primitive(CLASS, unwrap_spec=[object])
 def func(interp, w_obj):
-    return w_obj.getclass()
+    return w_obj.getclass(interp.space)
 
 @expose_primitive(BYTES_LEFT, unwrap_spec=[object])
 def func(interp, w_rcvr):
@@ -472,15 +470,15 @@
 
 @expose_primitive(CHANGE_CLASS, unwrap_spec=[object, object], no_result=True)
 def func(interp, w_arg, w_rcvr):
-    w_arg_class = w_arg.getclass()
-    w_rcvr_class = w_rcvr.getclass()
+    w_arg_class = w_arg.getclass(interp.space)
+    w_rcvr_class = w_rcvr.getclass(interp.space)
 
     # We should fail if:
 
     # 1. Rcvr or arg are SmallIntegers
     # XXX this is wrong too
-    if (w_arg_class.is_same_object(classtable.w_SmallInteger) or
-        w_rcvr_class.is_same_object(classtable.w_SmallInteger)):
+    if (w_arg_class.is_same_object(interp.space.w_SmallInteger) or
+        w_rcvr_class.is_same_object(interp.space.w_SmallInteger)):
         raise PrimitiveFailedError()
 
     # 2. Rcvr is an instance of a compact class and argument isn't
@@ -510,15 +508,15 @@
         return w_rcvr
     raise PrimitiveFailedError
 
-def fake_bytes_left():
-    return utility.wrap_int(2**20) # XXX we don't know how to do this :-(
+def fake_bytes_left(interp):
+    return interp.space.wrap_int(2**20) # XXX we don't know how to do this :-(
 
 @expose_primitive(INC_GC, unwrap_spec=[object])
 @expose_primitive(FULL_GC, unwrap_spec=[object])
 def func(interp, w_arg): # Squeak pops the arg and ignores it ... go figure
     from pypy.rlib import rgc
     rgc.collect()
-    return fake_bytes_left()
+    return fake_bytes_left(interp)
 
 #____________________________________________________________________________
 # Time Primitives
@@ -529,13 +527,13 @@
 def func(interp, w_arg):
     import time
     import math
-    return utility.wrap_int(int(math.fmod(time.time()*1000, constants.TAGGED_MAXINT/2)))
+    return interp.space.wrap_int(int(math.fmod(time.time()*1000, constants.TAGGED_MAXINT/2)))
 
 @expose_primitive(SECONDS_CLOCK, unwrap_spec=[object])
 def func(interp, w_arg):
     import time
-    return utility.wrap_int(0x23910d6c)      # HACK: too big for a small int!
-    #return utility.wrap_int(int(time.time()))
+    return interp.space.wrap_int(0x23910d6c)      # HACK: too big for a small int!
+    #return interp.space.wrap_int(int(time.time()))
 
 # ___________________________________________________________________________
 # Boolean Primitives
@@ -567,7 +565,7 @@
         @expose_primitive(code, unwrap_spec=[int, int])
         def func(interp, v1, v2):
             res = op(v1, v2)
-            w_res = utility.wrap_bool(res)
+            w_res = interp.space.wrap_bool(res)
             return w_res
     make_func(op)
 
@@ -576,7 +574,7 @@
         @expose_primitive(code+_FLOAT_OFFSET, unwrap_spec=[float, float])
         def func(interp, v1, v2):
             res = op(v1, v2)
-            w_res = utility.wrap_bool(res)
+            w_res = interp.space.wrap_bool(res)
             return w_res
     make_func(op)
     
@@ -597,20 +595,21 @@
     # no-op really
     return w_self
 
-for (code, const) in [
-    (PUSH_TRUE, objtable.w_true),
-    (PUSH_FALSE, objtable.w_false),
-    (PUSH_NIL, objtable.w_nil),
-    (PUSH_MINUS_ONE, objtable.w_minus_one),
-    (PUSH_ZERO, objtable.w_zero),
-    (PUSH_ONE, objtable.w_one),
-    (PUSH_TWO, objtable.w_two),
+def make_push_const_func(code, name):
+    @expose_primitive(code, unwrap_spec=[object])
+    def func(interp, w_ignored):
+        return getattr(interp.space, name)
+
+for (code, name) in [
+    (PUSH_TRUE, "w_true"),
+    (PUSH_FALSE, "w_false"),
+    (PUSH_NIL, "w_nil"),
+    (PUSH_MINUS_ONE, "w_minus_one"),
+    (PUSH_ZERO, "w_zero"),
+    (PUSH_ONE, "w_one"),
+    (PUSH_TWO, "w_two"),
     ]:
-    def make_func(const):
-        @expose_primitive(code, unwrap_spec=[object])
-        def func(interp, w_ignored):
-            return const
-    make_func(const)
+    make_push_const_func(code, name)
         
 # ___________________________________________________________________________
 # Control Primitives
@@ -635,13 +634,14 @@
     # context of the receiver is used for the new BlockContext.
     # Note that in our impl, MethodContext.w_home == self
     assert isinstance(w_context, model.W_PointersObject)
-    w_method_context = w_context.as_context_get_shadow().w_home()
+    w_method_context = w_context.as_context_get_shadow(interp.space).w_home()
 
     # 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 = shadow.BlockContextShadow.make_context(
-        w_method_context, objtable.w_nil, argcnt, initialip)
+        interp.space,
+        w_method_context, interp.space.w_nil, argcnt, initialip)
     return w_new_context
 
 def finalize_block_ctx(interp, s_block_ctx, frame):
@@ -665,12 +665,13 @@
     w_block_ctx = frame.peek(argument_count)
 
     # XXX need to check this since VALUE is called on all sorts of objects.
-    if not w_block_ctx.getclass().is_same_object(classtable.w_BlockContext):
+    if not w_block_ctx.getclass(interp.space).is_same_object(
+        interp.space.w_BlockContext):
         raise PrimitiveFailedError()
     
     assert isinstance(w_block_ctx, model.W_PointersObject)
 
-    s_block_ctx = w_block_ctx.as_blockcontext_get_shadow()
+    s_block_ctx = w_block_ctx.as_blockcontext_get_shadow(interp.space)
 
     exp_arg_cnt = s_block_ctx.expected_argument_count()
     if argument_count != exp_arg_cnt: # exp_arg_cnt doesn't count self
@@ -692,11 +693,12 @@
 def func(interp, w_block_ctx, w_args):
 
     assert isinstance(w_block_ctx, model.W_PointersObject)
-    s_block_ctx = w_block_ctx.as_blockcontext_get_shadow()
+    s_block_ctx = w_block_ctx.as_blockcontext_get_shadow(interp.space)
     exp_arg_cnt = s_block_ctx.expected_argument_count()
 
     # Check that our arguments have pointers format and the right size:
-    if not w_args.getclass().is_same_object(classtable.w_Array):
+    if not w_args.getclass(interp.space).is_same_object(
+            interp.space.w_Array):
         raise PrimitiveFailedError()
     if w_args.size() != exp_arg_cnt:
         raise PrimitiveFailedError()
@@ -704,7 +706,7 @@
     assert isinstance(w_args, model.W_PointersObject)
     # Push all the items from the array
     for i in range(exp_arg_cnt):
-        s_block_ctx.push(w_args.at0(i))
+        s_block_ctx.push(w_args.at0(interp.space, i))
 
     # XXX Check original logic. Image does not test this anyway
     # because falls back to value + internal implementation
@@ -718,45 +720,49 @@
                   unwrap_spec=[object, str, object],
                   no_result=True)
 def func(interp, w_rcvr, sel, w_args):
-    w_method = w_rcvr.shadow_of_my_class().lookup(sel)
+    w_method = w_rcvr.shadow_of_my_class(interp.space).lookup(sel)
     assert w_method
 
-    w_frame = w_method.create_frame(w_rcvr,
+    w_frame = w_method.create_frame(interp.space, w_rcvr,
         [w_args.fetch(i) for i in range(w_args.size())])
 
-    w_frame.as_context_get_shadow().store_w_sender(interp.w_active_context())
+    w_frame.as_context_get_shadow(interp.space).store_w_sender(interp.w_active_context())
     interp.store_w_active_context(w_frame)
 
 @expose_primitive(PRIMITIVE_SIGNAL, unwrap_spec=[object])
 def func(interp, w_rcvr):
     # XXX we might want to disable this check
-    if not w_rcvr.getclass().is_same_object(classtable.classtable['w_Semaphore']):
+    if not w_rcvr.getclass(interp.space).is_same_object(
+        interp.space.classtable['w_Semaphore']):
         raise PrimitiveFailedError()
-    wrapper.SemaphoreWrapper(w_rcvr).signal(interp)
+    wrapper.SemaphoreWrapper(interp.space, w_rcvr).signal(interp)
     return w_rcvr
     
 @expose_primitive(PRIMITIVE_WAIT, unwrap_spec=[object])
 def func(interp, w_rcvr):
     # XXX we might want to disable this check
-    if not w_rcvr.getclass().is_same_object(classtable.classtable['w_Semaphore']):
+    if not w_rcvr.getclass(interp.space).is_same_object(
+        interp.space.classtable['w_Semaphore']):
         raise PrimitiveFailedError()
-    wrapper.SemaphoreWrapper(w_rcvr).wait(interp)
+    wrapper.SemaphoreWrapper(interp.space, w_rcvr).wait(interp)
     return w_rcvr
     
 @expose_primitive(PRIMITIVE_RESUME, unwrap_spec=[object])
 def func(interp, w_rcvr,):
     # XXX we might want to disable this check
-    if not w_rcvr.getclass().is_same_object(classtable.classtable['w_Process']):
+    if not w_rcvr.getclass(interp.space).is_same_object(
+        interp.space.classtable['w_Process']):
         raise PrimitiveFailedError()
-    wrapper.ProcessWrapper(w_rcvr).resume(interp)
+    wrapper.ProcessWrapper(interp.space, w_rcvr).resume(interp)
     return w_rcvr
  
 @expose_primitive(PRIMITIVE_SUSPEND, unwrap_spec=[object])
 def func(interp, w_rcvr):
     # XXX we might want to disable this check
-    if not w_rcvr.getclass().is_same_object(classtable.classtable['w_Process']):
+    if not w_rcvr.getclass(interp.space).is_same_object(
+        interp.space.classtable['w_Process']):
         raise PrimitiveFailedError()
-    wrapper.ProcessWrapper(w_rcvr).suspend(interp)
+    wrapper.ProcessWrapper(interp.space, w_rcvr).suspend(interp)
     return w_rcvr
  
 @expose_primitive(PRIMITIVE_FLUSH_CACHE, unwrap_spec=[object])

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 25 16:09:07 2008
@@ -1,12 +1,13 @@
 import weakref
-from pypy.lang.smalltalk import model, constants, utility, error
+from pypy.lang.smalltalk import model, constants, error
 from pypy.tool.pairtype import extendabletype
 
 class AbstractShadow(object):
     """A shadow is an optional extra bit of information that
     can be attached at run-time to any Smalltalk object.
     """
-    def __init__(self, w_self):
+    def __init__(self, space, w_self):
+        self.space = space
         self._w_self = w_self
     def fetch(self, n0):
         return self.w_self()._fetch(n0)
@@ -23,8 +24,8 @@
     def sync_shadow(self): pass
    
 class AbstractCachingShadow(AbstractShadow):
-    def __init__(self, w_self):
-        AbstractShadow.__init__(self, w_self)
+    def __init__(self, space, w_self):
+        AbstractShadow.__init__(self, space, w_self)
         self.invalid = True
         self.invalidate_shadow()
 
@@ -75,9 +76,9 @@
     """A shadow for Smalltalk objects that are classes
     (i.e. used as the class of another Smalltalk object).
     """
-    def __init__(self, w_self):
+    def __init__(self, space, w_self):
         self.name = ""
-        AbstractCachingShadow.__init__(self, w_self)
+        AbstractCachingShadow.__init__(self, space, w_self)
     def invalidate_shadow(self):
         AbstractCachingShadow.invalidate_shadow(self)
         self.w_methoddict = None
@@ -87,12 +88,11 @@
         return "%s class" % (self.name or '?',)
 
     def sync_cache(self):
-        from pypy.lang.smalltalk.objtable import w_nil
         "Update the ClassShadow with data from the w_self class."
 
         w_self = self.w_self()
         # read and painfully decode the format
-        classformat = utility.unwrap_int(
+        classformat = self.space.unwrap_int(
             w_self._fetch(constants.CLASS_FORMAT_INDEX))
         # The classformat in Squeak, as an integer value, is:
         #    <2 bits=instSize//64><5 bits=cClass><4 bits=instSpec>
@@ -135,7 +135,7 @@
         self.w_methoddict = w_methoddict
 
         w_superclass = w_self._fetch(constants.CLASS_SUPERCLASS_INDEX)
-        if w_superclass.is_same_object(w_nil):
+        if w_superclass.is_same_object(self.space.w_nil):
             self.w_superclass = None
         else:
             assert isinstance(w_superclass, model.W_PointersObject)
@@ -166,7 +166,6 @@
             self.name = w_name.as_string()
 
     def new(self, extrasize=0):
-        from pypy.lang.smalltalk import classtable
         w_cls = self.w_self()
         if self.instance_kind == POINTERS:
             w_new = model.W_PointersObject(w_cls, self.instance_size+extrasize)
@@ -181,12 +180,12 @@
         return w_new
 
     def s_methoddict(self):
-        return self.w_methoddict.as_methoddict_get_shadow()
+        return self.w_methoddict.as_methoddict_get_shadow(self.space)
 
     def s_superclass(self):
         if self.w_superclass is None:
             return None
-        return self.w_superclass.as_class_get_shadow()
+        return self.w_superclass.as_class_get_shadow(self.space)
 
     # _______________________________________________________________
     # Methods for querying the format word, taken from the blue book:
@@ -262,17 +261,16 @@
         self.methoddict = None
 
     def sync_cache(self):
-        from pypy.lang.smalltalk import objtable
         w_values = self.w_self()._fetch(constants.METHODDICT_VALUES_INDEX)
         assert isinstance(w_values, model.W_PointersObject)
-        s_values = w_values.get_shadow()
+        s_values = w_values.get_shadow(self.space)
         # XXX Should add!
         # 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()._fetch(constants.METHODDICT_NAMES_INDEX+i)
-            if not w_selector.is_same_object(objtable.w_nil):
+            if not w_selector.is_same_object(self.space.w_nil):
                 if not isinstance(w_selector, model.W_BytesObject):
                     raise ClassShadowError("bogus selector in method dict")
                 selector = w_selector.as_string()
@@ -284,8 +282,8 @@
 
 
 class AbstractRedirectingShadow(AbstractShadow):
-    def __init__(self, w_self):
-        AbstractShadow.__init__(self, w_self)
+    def __init__(self, space, w_self):
+        AbstractShadow.__init__(self, space, w_self)
         self._w_self_size = self.w_self().size()
     def fetch(self, n0):
         raise NotImplementedError()
@@ -301,8 +299,7 @@
         self.w_self()._vars = None
 
     def detach_shadow(self):
-        from pypy.lang.smalltalk import objtable
-        self.w_self()._vars = [objtable.w_nil] * self._w_self_size
+        self.w_self()._vars = [self.space.w_nil] * self._w_self_size
         for i in range(self._w_self_size):
             self.copy_to_w_self(i)
 
@@ -315,18 +312,17 @@
 
     __metaclass__ = extendabletype
 
-    def __init__(self, w_self):
-        from pypy.lang.smalltalk import objtable
-        self._w_sender = objtable.w_nil
+    def __init__(self, space, w_self):
+        self._w_sender = space.w_nil
         self._stack = []
         self.currentBytecode = -1
-        AbstractRedirectingShadow.__init__(self, w_self)
+        AbstractRedirectingShadow.__init__(self, space, w_self)
 
     @staticmethod
-    def is_block_context(w_pointers):
-        from pypy.lang.smalltalk.classtable import w_SmallInteger
+    def is_block_context(w_pointers, space):
         method_or_argc = w_pointers.fetch(constants.MTHDCTX_METHOD)
-        return method_or_argc.getclass().is_same_object(w_SmallInteger)
+        return method_or_argc.getclass(space).is_same_object(
+            space.w_SmallInteger)
 
     def fetch(self, n0):
         if n0 == constants.CTXPART_SENDER_INDEX:
@@ -338,8 +334,7 @@
         if self.stackstart() <= n0 < self.external_stackpointer():
             return self._stack[n0-self.stackstart()]
         if self.external_stackpointer() <= n0 < self.stackend():
-            from pypy.lang.smalltalk import objtable
-            return objtable.w_nil
+            return self.space.w_nil
         else:
             # XXX later should store tail out of known context part as well
             raise error.WrapperException("Index in context out of bounds")
@@ -364,21 +359,20 @@
         # the stackpointer in the W_PointersObject starts counting at the
         # tempframe start
         # Stackpointer from smalltalk world == stacksize in python world
-        self.store_stackpointer(utility.unwrap_int(w_sp1) -
+        self.store_stackpointer(self.space.unwrap_int(w_sp1) -
                                 self.tempsize())
 
     def store_stackpointer(self, size):
-        from pypy.lang.smalltalk import objtable
         if size < len(self._stack):
             # TODO Warn back to user
             assert size >= 0
             self._stack = self._stack[:size]
         else:
-            add = [objtable.w_nil] * (size - len(self._stack))
+            add = [self.space.w_nil] * (size - len(self._stack))
             self._stack.extend(add)
 
     def wrap_stackpointer(self):
-        return utility.wrap_int(len(self._stack) + 
+        return self.space.wrap_int(len(self._stack) + 
                                 self.tempsize())
 
     def external_stackpointer(self):
@@ -388,7 +382,7 @@
         raise NotImplementedError()
 
     def s_home(self):
-        return self.w_home().as_methodcontext_get_shadow()
+        return self.w_home().as_methodcontext_get_shadow(self.space)
     
     def stackstart(self):
         raise NotImplementedError()
@@ -408,18 +402,16 @@
         return self._w_sender
 
     def s_sender(self):
-        from pypy.lang.smalltalk import objtable
         w_sender = self.w_sender()
-        if w_sender.is_same_object(objtable.w_nil):
+        if w_sender.is_same_object(self.space.w_nil):
             return None
         else:
-            return w_sender.as_context_get_shadow()
+            return w_sender.as_context_get_shadow(self.space)
 
     def store_unwrap_pc(self, w_pc):
-        from pypy.lang.smalltalk import objtable
-        if w_pc.is_same_object(objtable.w_nil):
+        if w_pc.is_same_object(self.space.w_nil):
             return
-        pc = utility.unwrap_int(w_pc)
+        pc = self.space.unwrap_int(w_pc)
         pc -= self.w_method().bytecodeoffset()
         pc -= 1
         self.store_pc(pc)
@@ -428,7 +420,7 @@
         pc = self.pc()
         pc += 1
         pc += self.w_method().bytecodeoffset()
-        return utility.wrap_int(pc)
+        return self.space.wrap_int(pc)
 
     def pc(self):
         return self._pc
@@ -511,14 +503,13 @@
 class BlockContextShadow(ContextPartShadow):
 
     @staticmethod
-    def make_context(w_home, w_sender, argcnt, initialip):
-        from pypy.lang.smalltalk.classtable import w_BlockContext
+    def make_context(space, w_home, w_sender, argcnt, initialip):
         # 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
-        contextsize = w_home.as_methodcontext_get_shadow().myblocksize()
-        w_result = model.W_PointersObject(w_BlockContext, contextsize)
-        s_result = BlockContextShadow(w_result)
+        contextsize = w_home.as_methodcontext_get_shadow(space).myblocksize()
+        w_result = model.W_PointersObject(space.w_BlockContext, contextsize)
+        s_result = BlockContextShadow(space, w_result)
         w_result.store_shadow(s_result)
         s_result.store_expected_argument_count(argcnt)
         s_result.store_initialip(initialip)
@@ -552,20 +543,20 @@
         ContextPartShadow.attach_shadow(self)
 
     def unwrap_store_initialip(self, w_value):
-        initialip = utility.unwrap_int(w_value)
+        initialip = self.space.unwrap_int(w_value)
         initialip -= 1 + self.w_method().getliteralsize()
         self.store_initialip(initialip)
 
     def wrap_initialip(self):
         initialip = self.initialip()
         initialip += 1 + self.w_method().getliteralsize()
-        return utility.wrap_int(initialip)
+        return self.space.wrap_int(initialip)
 
     def unwrap_store_eargc(self, w_value):
-        self.store_expected_argument_count(utility.unwrap_int(w_value))
+        self.store_expected_argument_count(self.space.unwrap_int(w_value))
     
     def wrap_eargc(self):
-        return utility.wrap_int(self.expected_argument_count())
+        return self.space.wrap_int(self.expected_argument_count())
 
     def expected_argument_count(self):
         return self._eargc
@@ -600,33 +591,30 @@
         return 0
 
 class MethodContextShadow(ContextPartShadow):
-    def __init__(self, w_self):
-        from pypy.lang.smalltalk import objtable
-        self.w_receiver_map = objtable.w_nil
+    def __init__(self, space, w_self):
+        self.w_receiver_map = space.w_nil
         self._w_receiver = None
-        ContextPartShadow.__init__(self, w_self)
+        ContextPartShadow.__init__(self, space, w_self)
 
     @staticmethod
-    def make_context(w_method, w_receiver,
+    def make_context(space, 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)
+        w_result = space.w_MethodContext.as_class_get_shadow(space).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)
+        s_result = MethodContextShadow(space, w_result)
         w_result.store_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.tempsize
+        s_result._temps = [space.w_nil] * w_method.tempsize
         for i in range(len(arguments)):
             s_result.settemp(i, arguments[i])
         return w_result
@@ -661,11 +649,10 @@
             return ContextPartShadow.store(self, n0, w_value)
     
     def attach_shadow(self):
-        from pypy.lang.smalltalk import objtable
         # Make sure the method is updated first
         self.copy_from_w_self(constants.MTHDCTX_METHOD)
         # And that there is space for the temps
-        self._temps = [objtable.w_nil] * self.tempsize()
+        self._temps = [self.space.w_nil] * self.tempsize()
         ContextPartShadow.attach_shadow(self)
 
     def tempsize(self):

Added: pypy/branch/smalltalk-shadow-changes/pypy/lang/smalltalk/space.py
==============================================================================
--- (empty file)
+++ pypy/branch/smalltalk-shadow-changes/pypy/lang/smalltalk/space.py	Sun May 25 16:09:07 2008
@@ -0,0 +1,236 @@
+from pypy.lang.smalltalk import constants
+from pypy.lang.smalltalk import model
+from pypy.lang.smalltalk import shadow
+from pypy.rlib.objectmodel import instantiate
+from pypy.lang.smalltalk.error import UnwrappingError, WrappingError
+
+class ObjSpace(object):
+    def __init__(self):
+        self.classtable = {}
+        self.make_bootstrap_classes()
+        self.make_bootstrap_objects()
+
+    def make_bootstrap_classes(self):
+        def define_core_cls(name, w_superclass, w_metaclass):
+            assert name.startswith('w_')
+            w_class = bootstrap_class(self, instsize=0,    # XXX
+                                      w_superclass=w_superclass,
+                                      w_metaclass=w_metaclass,
+                                      name=name[2:])
+            self.classtable[name] = w_class
+            return w_class
+        
+        #   A complete minimal setup (including Behavior) would look like this
+        #
+        #   class:              superclass:         metaclass:
+        #   ------------------- ------------------- -------------------
+        #   Object              *nil                 Object class
+        #   Behavior            Object              Behavior class
+        #   ClassDescription    Behavior            ClassDescription class
+        #   Class               ClassDescription    Class class
+        #   Metaclass           ClassDescription    Metaclass class
+        #   Object class        *Class              *Metaclass
+        #   Behavior class      Object class        *Metaclass
+        #   ClassDescription cl Behavior class      *Metaclass
+        #   Class class         ClassDescription cl *Metaclass
+        #   Metaclass class     ClassDescription cl *Metaclass
+        
+        #    Class Name            Super class name
+        cls_nm_tbl = [
+            ["w_Object",           "w_ProtoObject"], # there is not ProtoObject in mini.image
+            ["w_Behavior",         "w_Object"],
+            ["w_ClassDescription", "w_Behavior"],
+            ["w_Class",            "w_ClassDescription"],
+            ["w_Metaclass",        "w_ClassDescription"],
+            ]
+        define_core_cls("w_ProtoObjectClass", None, None)
+        w_ProtoObjectClass = self.classtable["w_ProtoObjectClass"]
+        define_core_cls("w_ProtoObject", None, w_ProtoObjectClass)
+        for (cls_nm, super_cls_nm) in cls_nm_tbl:
+            meta_nm = cls_nm + "Class"
+            meta_super_nm = super_cls_nm + "Class"
+            w_metacls = define_core_cls(meta_nm, self.classtable[meta_super_nm], None)
+            define_core_cls(cls_nm, self.classtable[super_cls_nm], w_metacls)
+        w_Class = self.classtable["w_Class"]
+        w_Metaclass = self.classtable["w_Metaclass"]
+        # XXX
+        proto_shadow = instantiate(shadow.ClassShadow)
+        proto_shadow.space = self
+        proto_shadow.invalid = False
+        proto_shadow.w_superclass = w_Class
+        w_ProtoObjectClass.store_shadow(proto_shadow)
+        # at this point, all classes that still lack a w_class are themselves
+        # metaclasses
+        for nm, w_cls_obj in self.classtable.items():
+            if w_cls_obj.w_class is None:
+                w_cls_obj.w_class = w_Metaclass
+        
+        def define_cls(cls_nm, supercls_nm, instvarsize=0, format=shadow.POINTERS,
+                       varsized=False):
+            assert cls_nm.startswith("w_")
+            meta_nm = cls_nm + "Class"
+            meta_super_nm = supercls_nm + "Class"
+            w_Metaclass = self.classtable["w_Metaclass"]
+            w_meta_cls = self.classtable[meta_nm] = \
+                         bootstrap_class(self, 0,   # XXX
+                                         self.classtable[meta_super_nm],
+                                         w_Metaclass,
+                                         name=meta_nm[2:])
+            w_cls = self.classtable[cls_nm] = \
+                         bootstrap_class(self, instvarsize,
+                                         self.classtable[supercls_nm],
+                                         w_meta_cls,
+                                         format=format,
+                                         varsized=varsized,
+                                         name=cls_nm[2:])
+
+        define_cls("w_Magnitude", "w_Object")
+        define_cls("w_Character", "w_Magnitude", instvarsize=1)
+        define_cls("w_Number", "w_Magnitude")
+        define_cls("w_Integer", "w_Number")
+        define_cls("w_SmallInteger", "w_Integer")
+        define_cls("w_Float", "w_Number", format=shadow.BYTES)
+        define_cls("w_Collection", "w_Object")
+        define_cls("w_SequenceableCollection", "w_Collection")
+        define_cls("w_ArrayedCollection", "w_SequenceableCollection")
+        define_cls("w_Array", "w_ArrayedCollection", varsized=True)
+        define_cls("w_String", "w_ArrayedCollection", format=shadow.BYTES)
+        define_cls("w_UndefinedObject", "w_Object")
+        define_cls("w_Boolean", "w_Object")
+        define_cls("w_True", "w_Boolean")
+        define_cls("w_False", "w_Boolean")
+        define_cls("w_ByteArray", "w_ArrayedCollection", format=shadow.BYTES)
+        define_cls("w_MethodDict", "w_Object", instvarsize=2, varsized=True)
+        define_cls("w_CompiledMethod", "w_ByteArray", format=shadow.COMPILED_METHOD)
+        define_cls("w_ContextPart", "w_Object")
+        define_cls("w_MethodContext", "w_ContextPart")
+        define_cls("w_Link", "w_Object")
+        define_cls("w_Process", "w_Link")
+        define_cls("w_LinkedList", "w_SequenceableCollection")
+        define_cls("w_Semaphore", "w_LinkedList")
+        define_cls("w_BlockContext", "w_ContextPart",
+                   instvarsize=constants.BLKCTX_STACK_START)
+
+        # make better accessors for classes that can be found in special object
+        # table
+        for name in constants.classes_in_special_object_table.keys():
+            name = 'w_' + name
+            setattr(self, name, self.classtable.get(name))
+
+    def make_bootstrap_objects(self):
+        def bld_char(i):
+            w_cinst = self.w_Character.as_class_get_shadow(self).new()
+            w_cinst.store(constants.CHARACTER_VALUE_INDEX,
+                          model.W_SmallInteger(i))
+            return w_cinst
+        w_charactertable = model.W_PointersObject(
+            self.classtable['w_Array'], 256)
+        self.w_charactertable = w_charactertable
+        for i in range(256):
+            self.w_charactertable.atput0(self, i, bld_char(i))
+
+
+        # Very special nil hack: in order to allow W_PointersObject's to
+        # initialize their fields to nil, we have to create it in the model
+        # package, and then patch up its fields here:
+        w_nil = self.w_nil = model.w_nil
+        w_nil.w_class = self.classtable['w_UndefinedObject']
+
+        w_true = self.classtable['w_True'].as_class_get_shadow(self).new()
+        self.w_true = w_true
+        w_false = self.classtable['w_False'].as_class_get_shadow(self).new()
+        self.w_false = w_false
+        self.w_minus_one = model.W_SmallInteger(-1)
+        self.w_zero = model.W_SmallInteger(0)
+        self.w_one = model.W_SmallInteger(1)
+        self.w_two = model.W_SmallInteger(2)
+        self.objtable = {}
+
+        for name in constants.objects_in_special_object_table:
+            name = "w_" + name
+            try:
+                self.objtable[name] = locals()[name]
+            except KeyError, e:
+                self.objtable[name] = None
+
+    # methods for wrapping and unwrapping stuff
+
+    def wrap_int(self, val):
+        from pypy.lang.smalltalk import constants
+        if constants.TAGGED_MININT <= val <= constants.TAGGED_MAXINT:
+            return model.W_SmallInteger(val)
+        raise WrappingError("integer too large to fit into a tagged pointer")
+
+    def wrap_float(self, i):
+        return model.W_Float(i)
+
+    def wrap_string(self, string):
+        w_inst = self.w_String.as_class_get_shadow(self).new(len(string))
+        for i in range(len(string)):
+            w_inst.setchar(i, string[i])
+        return w_inst
+
+    def wrap_char(self, c):
+        return self.w_charactertable.fetch(ord(c))
+
+    def wrap_bool(self, b):
+        if b:
+            return self.w_true
+        else:
+            return self.w_false
+
+    def wrap_list(self, lst_w):
+        """
+        Converts a Python list of wrapper objects into
+        a wrapped smalltalk array
+        """
+        lstlen = len(lst_w)
+        res = self.w_Array.as_class_get_shadow().new(lstlen)
+        for i in range(lstlen):
+            res.storevarpointer(i, lit[i])
+        return res
+
+    def unwrap_int(self, w_value):
+        if isinstance(w_value, model.W_SmallInteger):
+            return w_value.value
+        raise UnwrappingError("expected a W_SmallInteger, got %s" % (w_value,))
+
+    def unwrap_char(self, w_char):
+        from pypy.lang.smalltalk import constants
+        w_class = w_char.getclass(self)
+        if not w_class.is_same_object(self.w_Character):
+            raise UnwrappingError("expected character, got %s" % (w_class, ))
+        w_ord = w_char.fetch(constants.CHARACTER_VALUE_INDEX)
+        w_class = w_ord.getclass(self)
+        if not w_class.is_same_object(self.w_SmallInteger):
+            raise UnwrappingError("expected smallint from character, got %s" % (w_class, ))
+
+        assert isinstance(w_ord, model.W_SmallInteger)
+        return chr(w_ord.value)
+
+    def unwrap_float(self, w_v):
+        from pypy.lang.smalltalk import model
+        if isinstance(w_v, model.W_Float): return w_v.value
+        elif isinstance(w_v, model.W_SmallInteger): return float(w_v.value)
+        raise UnwrappingError()
+
+
+
+def bootstrap_class(space, instsize, w_superclass=None, w_metaclass=None,
+                    name='?', format=shadow.POINTERS, varsized=False):
+    from pypy.lang.smalltalk import model
+    w_class = model.W_PointersObject(w_metaclass, 0)
+                                             # a dummy placeholder for testing
+    # XXX
+    s = instantiate(shadow.ClassShadow)
+    s.space = space
+    s._w_self = w_class
+    s.w_superclass = w_superclass
+    s.name = name
+    s.instance_size = instsize
+    s.instance_kind = format
+    s.w_methoddict = None
+    s.instance_varsized = varsized or format != shadow.POINTERS
+    s.invalid = False
+    w_class.store_shadow(s)
+    return w_class

Modified: pypy/branch/smalltalk-shadow-changes/pypy/lang/smalltalk/squeakimage.py
==============================================================================
--- pypy/branch/smalltalk-shadow-changes/pypy/lang/smalltalk/squeakimage.py	(original)
+++ pypy/branch/smalltalk-shadow-changes/pypy/lang/smalltalk/squeakimage.py	Sun May 25 16:09:07 2008
@@ -1,7 +1,7 @@
 import py
 import os
+from pypy.lang.smalltalk import constants
 from pypy.lang.smalltalk import model
-from pypy.lang.smalltalk import objtable, utility
 from pypy.rlib import objectmodel
 from pypy.lang.smalltalk.tool.bitmanipulation import splitter
 
@@ -69,7 +69,8 @@
 # ____________________________________________________________
 
 class ImageReader(object):
-    def __init__(self, stream):
+    def __init__(self, space, stream):
+        self.space = space
         self.stream = stream
         self.chunks = {}
         self.chunklist = []
@@ -124,16 +125,13 @@
             chunk.g_object.init_w_object()
 
     def assign_prebuilt_constants(self):
-        from pypy.lang.smalltalk import classtable, constants
         # assign w_objects for objects that are already in classtable
         for name, so_index in constants.classes_in_special_object_table.items():
-            # w_object = getattr(classtable, "w_" + name)
-            w_object = classtable.classtable["w_" + name]
+            w_object = self.space.classtable["w_" + name]
             self.special_object(so_index).w_object = w_object
         # assign w_objects for objects that are already in objtable
         for name, so_index in constants.objects_in_special_object_table.items():
-            # w_object = getattr(objtable, "w_" + name)
-            w_object = objtable.get_objtable()["w_" + name]
+            w_object = self.space.objtable["w_" + name]
             self.special_object(so_index).w_object = w_object
 
     def special_object(self, index):
@@ -173,14 +171,14 @@
         kind, size, format, classid, idhash = (
             splitter[2,6,4,5,12](self.stream.next()))
         assert kind == 3
-        return ImageChunk(size, format, classid, idhash), self.stream.count - 4
+        return ImageChunk(self.space, size, format, classid, idhash), self.stream.count - 4
 
     def read_2wordobjectheader(self):
         assert self.stream.peek() & 3 == 1 #kind
         classid = self.stream.next() - 01 # remove headertype to get pointer
         kind, size, format, _, idhash = splitter[2,6,4,5,12](self.stream.next())
         assert kind == 1
-        return ImageChunk(size, format, classid, idhash), self.stream.count - 4
+        return ImageChunk(self.space, size, format, classid, idhash), self.stream.count - 4
 
     def read_3wordobjectheader(self):
         kind, size = splitter[2,30](self.stream.next())
@@ -189,22 +187,21 @@
         classid = self.stream.next() - 00 # remove headertype to get pointer
         kind, _, format, _, idhash = splitter[2,6,4,5,12](self.stream.next())
         assert kind == 0
-        return ImageChunk(size, format, classid, idhash), self.stream.count - 4
+        return ImageChunk(self.space, size, format, classid, idhash), self.stream.count - 4
 
 
 # ____________________________________________________________
 
 class SqueakImage(object):
 
-    def from_reader(self, reader):
-        from pypy.lang.smalltalk import constants, classtable
+    def from_reader(self, space, reader):
+        from pypy.lang.smalltalk import constants
         self.special_objects = [g_object.w_object for g_object in
                                 reader.chunks[reader.specialobjectspointer]
                                 .g_object.pointers]
 
-        from pypy.lang.smalltalk import objtable
         for name, idx in constants.objects_in_special_object_table.items():
-            objtable.get_objtable()["w_" + name] = self.special_objects[idx]
+            space.objtable["w_" + name] = self.special_objects[idx]
 
     def special(self, index):
         return self.special_objects[index]
@@ -219,7 +216,8 @@
         GenericObject from the image chunks, and uses them as starting
         point for the actual create of pypy.lang.smalltalk.model classes.
         """
-    def __init__(self):
+    def __init__(self, space):
+        self.space = space
         self.owner = None
 
     def isinitialized(self):
@@ -229,7 +227,7 @@
         self.owner = reader
         self.value = value
         self.size = -1
-        self.w_object = utility.wrap_int(value)
+        self.w_object = self.space.wrap_int(value)
 
     def initialize(self, chunk, reader):
         self.owner = reader
@@ -256,7 +254,7 @@
 
     def decode_pointer(self, pointer):
         if (pointer & 1) == 1:
-            small_int = GenericObject()
+            small_int = GenericObject(self.space)
             small_int.initialize_int(pointer >> 1, self.owner)
             return small_int
         else:
@@ -369,20 +367,19 @@
         header = self.chunk.data[0]
         w_compiledmethod.setheader(header>>1) # We untag before giving header
         for i in range(1,w_compiledmethod.literalsize+1):
-            w_compiledmethod.literalatput0(i, self.decode_pointer(self.chunk.data[i]).w_object)
+            w_compiledmethod.literalatput0(
+                self.space, i, self.decode_pointer(self.chunk.data[i]).w_object)
         bbytes = self.get_bytes()[(w_compiledmethod.literalsize + 1)*4:]
-        # XXX assert mirrorcache.get_or_build(self.g_class.w_object) is
-        #            ct.m_CompiledMethod
         w_compiledmethod.bytes = ''.join(bbytes)
 
 class ImageChunk(object):
-    def __init__(self, size, format, classid, hash12):
+    def __init__(self, space, size, format, classid, hash12):
         self.size = size
         self.format = format
         self.classid = classid
         self.hash12 = hash12
         self.data = None
-        self.g_object = GenericObject()
+        self.g_object = GenericObject(space)
 
     def __eq__(self, other):
         "(for testing)"

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 25 16:09:07 2008
@@ -1,10 +1,10 @@
 import py
 from pypy.lang.smalltalk import model, interpreter, primitives, shadow
-from pypy.lang.smalltalk import objtable, classtable, utility
-from pypy.lang.smalltalk.utility import wrap_int, wrap_char, wrap_string, \
-    unwrap_int
+from pypy.lang.smalltalk import space as objspace
 
-mockclass = classtable.bootstrap_class
+mockclass = objspace.bootstrap_class
+
+space = objspace.ObjSpace()
 
 # expose the bytecode's values as global constants.
 # Bytecodes that have a whole range are exposed as global functions:
@@ -29,54 +29,54 @@
 
     # Install faked compiled methods that just invoke the primitive:
     for (w_class, primnum, argsize, methname) in methods:
-        s_class = w_class.as_class_get_shadow()
+        s_class = w_class.as_class_get_shadow(space)
         prim_meth = model.W_CompiledMethod(0)
         prim_meth.primitive = primnum
         prim_meth.w_compiledin = w_class
         prim_meth.argsize = argsize
         s_class.installmethod(methname, prim_meth)
         
-        assert objtable.w_nil._shadow is None
+        assert space.w_nil._shadow is None
     try:
         func()
     finally:
         # Uninstall those methods:
-        assert objtable.w_nil._shadow is None
+        assert space.w_nil._shadow is None
         for (w_class, _, _, methname) in methods:
-            s_class = w_class.as_class_get_shadow()
+            s_class = w_class.as_class_get_shadow(space)
             del s_class.s_methoddict().methoddict[methname]
 
 def fakesymbol(s, _cache={}):
     try:
         return _cache[s]
     except KeyError:
-        result = _cache[s] = wrap_string(s)
+        result = _cache[s] = space.wrap_string(s)
         return result
 
-def fakeliterals(*literals):
+def fakeliterals(space, *literals):
     def fakeliteral(lit):
         if isinstance(lit, str):
             return fakesymbol(lit)
         elif isinstance(lit, int):
-            return wrap_int(lit)
+            return space.wrap_int(lit)
         elif isinstance(lit, list):
             lstlen = len(lit)
-            res = classtable.w_Array.as_class_get_shadow().new(lstlen)
+            res = space.w_Array.as_class_get_shadow(space).new(lstlen)
             for i in range(lstlen):
-                res.atput0(i, fakeliteral(lit[i]))
+                res.atput0(space, i, fakeliteral(lit[i]))
             return res
         return lit
     return [fakeliteral(lit) for lit in literals]
 
-def new_interpreter(bytes, receiver=objtable.w_nil):
+def new_interpreter(bytes, receiver=space.w_nil):
     assert isinstance(bytes, str)
     w_method = model.W_CompiledMethod(len(bytes))
     w_method.islarge = 1
     w_method.bytes = bytes
     w_method.argsize=2
     w_method.tempsize=8
-    w_frame = w_method.create_frame(receiver, ["foo", "bar"])
-    interp = interpreter.Interpreter()
+    w_frame = w_method.create_frame(space, receiver, ["foo", "bar"])
+    interp = interpreter.Interpreter(space)
     interp.store_w_active_context(w_frame)
     return interp
 
@@ -86,12 +86,12 @@
     w_method.islarge = 1
     w_method.argsize=2
     w_method.tempsize=8
-    w_frame = w_method.create_frame("receiver", ["foo", "bar"])
-    s_frame = w_frame.as_context_get_shadow()
+    w_frame = w_method.create_frame(space, "receiver", ["foo", "bar"])
+    s_frame = w_frame.as_context_get_shadow(space)
     assert s_frame.w_receiver() == "receiver"
     assert s_frame.gettemp(0) == "foo"
     assert s_frame.gettemp(1) == "bar"
-    assert s_frame.gettemp(2) is objtable.w_nil
+    assert s_frame.gettemp(2) is space.w_nil
     s_frame.settemp(2, "spam")
     assert s_frame.gettemp(2) == "spam"
     assert s_frame.getNextBytecode() == ord("h")
@@ -121,12 +121,13 @@
 def test_pushReceiverBytecode():
     interp = new_interpreter(pushReceiverBytecode)
     interp.step()
-    assert interp.s_active_context().top() == interp.w_active_context().as_methodcontext_get_shadow().w_receiver()
+    assert interp.s_active_context().top().is_same_object(
+            interp.w_active_context().as_methodcontext_get_shadow(space).w_receiver())
 
 def test_pushReceiverVariableBytecode(bytecode = (pushReceiverVariableBytecode(0) +
                                                   pushReceiverVariableBytecode(1) +
                                                   pushReceiverVariableBytecode(2))):
-    w_demo = mockclass(3).as_class_get_shadow().new()
+    w_demo = mockclass(space, 3).as_class_get_shadow(space).new()
     w_demo.store(0, "egg")
     w_demo.store(1, "bar")
     w_demo.store(2, "baz")
@@ -140,7 +141,7 @@
                                                  pushTemporaryVariableBytecode(1) +
                                                  pushTemporaryVariableBytecode(2))):
     interp = new_interpreter(bytecode)
-    interp.w_active_context().as_methodcontext_get_shadow().settemp(2, "temp")
+    interp.w_active_context().as_methodcontext_get_shadow(space).settemp(2, "temp")
     interp.step()
     interp.step()
     interp.step()
@@ -150,7 +151,7 @@
                                               pushLiteralConstantBytecode(1) +
                                               pushLiteralConstantBytecode(2)):
     interp = new_interpreter(bytecode)
-    interp.w_active_context().as_methodcontext_get_shadow().w_method().literals = fakeliterals("a", "b", "c")
+    interp.w_active_context().as_methodcontext_get_shadow(space).w_method().literals = fakeliterals(space, "a", "b", "c")
     interp.step()
     interp.step()
     interp.step()
@@ -159,89 +160,89 @@
                                              fakesymbol("c")]
 
 def test_pushLiteralVariableBytecode(bytecode=pushLiteralVariableBytecode(0)):
-    w_association = mockclass(2).as_class_get_shadow().new()
+    w_association = mockclass(space, 2).as_class_get_shadow(space).new()
     w_association.store(0, "mykey")
     w_association.store(1, "myvalue")
     interp = new_interpreter(bytecode)
-    interp.w_active_context().as_methodcontext_get_shadow().w_method().literals = fakeliterals(w_association)
+    interp.w_active_context().as_methodcontext_get_shadow(space).w_method().literals = fakeliterals(space, w_association)
     interp.step()
     assert interp.s_active_context().stack() == ["myvalue"]
 
 def test_storeAndPopReceiverVariableBytecode(bytecode=storeAndPopReceiverVariableBytecode,
                                              popped=True):
-    shadow = mockclass(8).as_class_get_shadow()
+    shadow = mockclass(space, 8).as_class_get_shadow(space)
     for index in range(8):
         w_object = shadow.new()
         interp = new_interpreter(pushConstantTrueBytecode + bytecode(index))
-        interp.w_active_context().as_methodcontext_get_shadow().store_w_receiver(w_object)
+        interp.w_active_context().as_methodcontext_get_shadow(space).store_w_receiver(w_object)
         interp.step()
         interp.step()
         if popped:
             assert interp.s_active_context().stack() == []
         else:
-            assert interp.s_active_context().stack() == [interp.TRUE]
+            assert interp.s_active_context().stack() == [space.w_true]
 
         for test_index in range(8):
             if test_index == index:
-                assert w_object.fetch(test_index) == interp.TRUE
+                assert w_object.fetch(test_index).is_same_object(space.w_true)
             else:
-                assert w_object.fetch(test_index) is objtable.w_nil
+                assert w_object.fetch(test_index) is space.w_nil
 
 def test_storeAndPopTemporaryVariableBytecode(bytecode=storeAndPopTemporaryVariableBytecode):
     for index in range(8):
         interp = new_interpreter(pushConstantTrueBytecode + bytecode(index))
-        #interp.w_active_context().as_methodcontext_get_shadow().temps = [None] * 8
+        #interp.w_active_context().as_methodcontext_get_shadow(space).temps = [None] * 8
         interp.step()
         interp.step()
         assert interp.s_active_context().stack() == []
-        interp.w_active_context().as_methodcontext_get_shadow()
+        interp.w_active_context().as_methodcontext_get_shadow(space)
         for test_index in range(8):
             print interp.w_active_context()._vars
             if test_index == index:
-                assert interp.s_active_context().gettemp(test_index) == interp.TRUE
+                assert interp.s_active_context().gettemp(test_index) == space.w_true
             else:
-                assert interp.s_active_context().gettemp(test_index) != interp.TRUE
+                assert interp.s_active_context().gettemp(test_index) != space.w_true
 
 def test_pushConstantTrueBytecode():
     interp = new_interpreter(pushConstantTrueBytecode)
     interp.step()
-    assert interp.s_active_context().pop() == interp.TRUE
+    assert interp.s_active_context().pop().is_same_object(space.w_true)
     assert interp.s_active_context().stack() == []
 
 def test_pushConstantFalseBytecode():
     interp = new_interpreter(pushConstantFalseBytecode)
     interp.step()
-    assert interp.s_active_context().pop() == interp.FALSE
+    assert interp.s_active_context().pop().is_same_object(space.w_false)
     assert interp.s_active_context().stack() == []
 
 def test_pushConstantNilBytecode():
     interp = new_interpreter(pushConstantNilBytecode)
     interp.step()
-    assert interp.s_active_context().pop() == interp.NIL
+    assert interp.s_active_context().pop().is_same_object(space.w_nil)
     assert interp.s_active_context().stack() == []
 
 def test_pushConstantMinusOneBytecode():
     interp = new_interpreter(pushConstantMinusOneBytecode)
     interp.step()
-    assert interp.s_active_context().pop() == interp.MINUS_ONE
+    assert interp.s_active_context().pop().is_same_object(space.w_minus_one)
     assert interp.s_active_context().stack() == []
 
 def test_pushConstantZeroBytecode():
     interp = new_interpreter(pushConstantZeroBytecode)
     interp.step()
-    assert interp.s_active_context().pop() == interp.ZERO
+    assert interp.s_active_context().pop().is_same_object(space.w_zero)
     assert interp.s_active_context().stack() == []
     
 def test_pushConstantOneBytecode():
     interp = new_interpreter(pushConstantOneBytecode)
     interp.step()
-    assert interp.s_active_context().pop() == interp.ONE
+    assert interp.s_active_context().pop().is_same_object(space.w_one)
     assert interp.s_active_context().stack() == []
 
 def test_pushConstantTwoBytecode():
     interp = new_interpreter(pushConstantTwoBytecode)
     interp.step()
-    assert interp.s_active_context().pop() == interp.TWO
+    assert interp.s_active_context().pop().is_same_object(space.w_two)
     assert interp.s_active_context().stack() == []
 
 def test_pushActiveContextBytecode():
@@ -254,7 +255,7 @@
     interp = new_interpreter(pushConstantZeroBytecode + duplicateTopBytecode)
     interp.step()
     interp.step()
-    assert interp.s_active_context().stack() == [interp.ZERO, interp.ZERO]
+    assert interp.s_active_context().stack() == [space.w_zero, space.w_zero]
     
 def test_bytecodePrimBitAnd():
     interp = new_interpreter(pushConstantOneBytecode + pushConstantTwoBytecode + bytecodePrimBitAnd)
@@ -284,7 +285,7 @@
     interp = new_interpreter(pushConstantOneBytecode + bytecodePrimClass)
     interp.step()
     interp.step()
-    assert interp.s_active_context().pop() == classtable.w_SmallInteger
+    assert interp.s_active_context().pop() == space.w_SmallInteger
     assert interp.s_active_context().stack() == []
     
 def test_bytecodePrimSubtract():
@@ -332,19 +333,19 @@
     interp.step()
     interp.step()
     interp.step()
-    assert interp.s_active_context().pop() == interpreter.Interpreter.FALSE
+    assert interp.s_active_context().pop() == space.w_false
     assert interp.s_active_context().stack() == []
     
     interp = new_interpreter(pushConstantOneBytecode + pushConstantOneBytecode + bytecodePrimEquivalent)
     interp.step()
     interp.step()
     interp.step()
-    assert interp.s_active_context().pop() == interpreter.Interpreter.TRUE
+    assert interp.s_active_context().pop() == space.w_true
     assert interp.s_active_context().stack() == []
     
 def test_bytecodePrimNew():
-    w_fakeclassclass = mockclass(10, name='fakeclassclass')
-    w_fakeclass = mockclass(1, name='fakeclass', varsized=False,
+    w_fakeclassclass = mockclass(space, 10, name='fakeclassclass')
+    w_fakeclass = mockclass(space, 1, name='fakeclass', varsized=False,
                             w_metaclass=w_fakeclassclass)
     interp = new_interpreter(bytecodePrimNew)
     interp.s_active_context().push(w_fakeclass)
@@ -353,27 +354,27 @@
         interp.step)
     w_fakeinst = interp.s_active_context().pop()
     assert interp.s_active_context().stack() == []
-    assert w_fakeinst.getclass().is_same_object(w_fakeclass)
+    assert w_fakeinst.getclass(space).is_same_object(w_fakeclass)
     assert w_fakeinst.size() == 1
     
 def test_bytecodePrimNewWithArg():
-    w_fakeclassclass = mockclass(10, name='fakeclassclass')
-    w_fakeclass = mockclass(1, name='fakeclass', varsized=True,
+    w_fakeclassclass = mockclass(space, 10, name='fakeclassclass')
+    w_fakeclass = mockclass(space, 1, name='fakeclass', varsized=True,
                             w_metaclass=w_fakeclassclass)
     interp = new_interpreter(bytecodePrimNewWithArg)
     interp.s_active_context().push(w_fakeclass)
-    interp.s_active_context().push(interpreter.Interpreter.TWO)
+    interp.s_active_context().push(space.w_two)
     run_with_faked_methods(
         [[w_fakeclassclass, primitives.NEW_WITH_ARG, 1, "new:"]],
         interp.step)
     w_fakeinst = interp.s_active_context().pop()
     assert interp.s_active_context().stack() == []
-    assert w_fakeinst.getclass().is_same_object(w_fakeclass)
+    assert w_fakeinst.getclass(space).is_same_object(w_fakeclass)
     assert w_fakeinst.size() == 3
  
 def test_bytecodePrimSize():
-    w_fakeclass = mockclass(2, name='fakeclass', varsized=True)
-    w_fakeinst = w_fakeclass.as_class_get_shadow().new(5)
+    w_fakeclass = mockclass(space, 2, name='fakeclass', varsized=True)
+    w_fakeinst = w_fakeclass.as_class_get_shadow(space).new(5)
     interp = new_interpreter(bytecodePrimSize)
     interp.s_active_context().push(w_fakeinst)
     run_with_faked_methods(
@@ -388,78 +389,78 @@
 # bytecodes - the bytecode to be executed
 def sendBytecodesTest(w_class, w_object, bytecodes):
     for bytecode, result in [ (returnReceiver, w_object), 
-          (returnTrue, interpreter.Interpreter.TRUE), 
-          (returnFalse, interpreter.Interpreter.FALSE),
-          (returnNil, interpreter.Interpreter.NIL),
-          (returnTopFromMethod, interpreter.Interpreter.ONE) ]:
-        shadow = w_class.as_class_get_shadow()
+          (returnTrue, space.w_true), 
+          (returnFalse, space.w_false),
+          (returnNil, space.w_nil),
+          (returnTopFromMethod, space.w_one) ]:
+        shadow = w_class.as_class_get_shadow(space)
         w_method = model.W_CompiledMethod(2)
         w_method.bytes = pushConstantOneBytecode + bytecode
         shadow.installmethod("foo", w_method)
         interp = new_interpreter(bytecodes)
-        interp.w_active_context().as_methodcontext_get_shadow().w_method().literals = fakeliterals("foo")
+        interp.w_active_context().as_methodcontext_get_shadow(space).w_method().literals = fakeliterals(space, "foo")
         interp.s_active_context().push(w_object)
         callerContext = interp.w_active_context()
         interp.step()
         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.s_methoddict().methoddict["foo"]
-        assert callerContext.as_context_get_shadow().stack() == []
+        assert interp.w_active_context().as_methodcontext_get_shadow(space).w_receiver().is_same_object(w_object)
+        assert interp.w_active_context().as_methodcontext_get_shadow(space).w_method().is_same_object(shadow.s_methoddict().methoddict["foo"])
+        assert callerContext.as_context_get_shadow(space).stack() == []
         interp.step()
         interp.step()
         assert interp.w_active_context() == callerContext
         assert interp.s_active_context().stack() == [result]
 
 def test_sendLiteralSelectorBytecode():
-    w_class = mockclass(0)
-    w_object = w_class.as_class_get_shadow().new()
+    w_class = mockclass(space, 0)
+    w_object = w_class.as_class_get_shadow(space).new()
     sendBytecodesTest(w_class, w_object, sendLiteralSelectorBytecode(0))
         
 def test_fibWithArgument():
     bytecode = ''.join(map(chr, [ 16, 119, 178, 154, 118, 164, 11, 112, 16, 118, 177, 224, 112, 16, 119, 177, 224, 176, 124 ]))
-    shadow = mockclass(0).as_class_get_shadow()
+    shadow = mockclass(space, 0).as_class_get_shadow(space)
     method = model.W_CompiledMethod(len(bytecode))
     method.literalsize = 1
     method.bytes = bytecode
     method.argsize = 1
     method.tempsize = 1
-    method.literals = fakeliterals("fib:")
+    method.literals = fakeliterals(space, "fib:")
     shadow.installmethod("fib:", method)
     w_object = shadow.new()
     interp = new_interpreter(sendLiteralSelectorBytecode(16) + returnTopFromMethod)
-    interp.w_active_context().as_methodcontext_get_shadow().w_method().literals = fakeliterals("fib:")
+    interp.w_active_context().as_methodcontext_get_shadow(space).w_method().literals = fakeliterals(space, "fib:")
     interp.s_active_context().push(w_object)
-    interp.s_active_context().push(wrap_int(8))
+    interp.s_active_context().push(space.wrap_int(8))
     result = interp.interpret()
-    assert unwrap_int(result) == 34
+    assert space.unwrap_int(result) == 34
 
 def test_send_to_primitive():
 
     def test():
         interp = new_interpreter(sendLiteralSelectorBytecode(1 + 16))
-        interp.w_active_context().as_methodcontext_get_shadow().w_method().literals = fakeliterals("foo", "sub")
-        interp.s_active_context().push(wrap_int(50))
-        interp.s_active_context().push(wrap_int(8))
+        interp.w_active_context().as_methodcontext_get_shadow(space).w_method().literals = fakeliterals(space, "foo", "sub")
+        interp.s_active_context().push(space.wrap_int(50))
+        interp.s_active_context().push(space.wrap_int(8))
         callerContext = interp.w_active_context()
         interp.step()
         assert interp.w_active_context() is callerContext
         assert len(interp.s_active_context().stack()) == 1
         w_result = interp.s_active_context().pop()
-        assert unwrap_int(w_result) == 42
+        assert space.unwrap_int(w_result) == 42
         
     run_with_faked_methods(
-        [[classtable.w_SmallInteger, primitives.SUBTRACT,
+        [[space.w_SmallInteger, primitives.SUBTRACT,
           1, "sub"]],
         test)
 
 def test_longJumpIfTrue():
     interp = new_interpreter(longJumpIfTrue(0) + chr(15) + longJumpIfTrue(0) + chr(15))
-    interp.s_active_context().push(interp.FALSE)
+    interp.s_active_context().push(space.w_false)
     pc = interp.s_active_context().pc() + 2
     interp.step()
     assert interp.s_active_context().pc() == pc
-    interp.s_active_context().push(interp.TRUE)
+    interp.s_active_context().push(space.w_true)
     pc = interp.s_active_context().pc() + 2
     interp.step()
     assert interp.s_active_context().pc() == pc + 15
@@ -504,7 +505,7 @@
     interp = new_interpreter(pushConstantTrueBytecode +
                              popStackBytecode)
     interp.step()
-    assert interp.s_active_context().stack() == [interp.TRUE]
+    assert interp.s_active_context().stack() == [space.w_true]
     interp.step()
     assert interp.s_active_context().stack() == []
 
@@ -524,14 +525,14 @@
     test_pushLiteralVariableBytecode(extendedPushBytecode + chr((3<<6) + 0))
 
 def storeAssociation(bytecode):
-    w_association = mockclass(2).as_class_get_shadow().new()
+    w_association = mockclass(space, 2).as_class_get_shadow(space).new()
     w_association.store(0, "mykey")
     w_association.store(1, "myvalue")
     interp = new_interpreter(pushConstantOneBytecode + bytecode)
-    interp.w_active_context().as_methodcontext_get_shadow().w_method().literals = fakeliterals(w_association)
+    interp.w_active_context().as_methodcontext_get_shadow(space).w_method().literals = fakeliterals(space, w_association)
     interp.step()
     interp.step()
-    assert w_association.fetch(1) == interp.ONE
+    assert w_association.fetch(1).is_same_object(space.w_one)
 
 def test_extendedStoreAndPopBytecode():
     test_storeAndPopReceiverVariableBytecode(lambda index: extendedStoreAndPopBytecode + chr((0<<6) + index))
@@ -546,7 +547,7 @@
 
 def test_callPrimitiveAndPush_fallback():
     interp = new_interpreter(bytecodePrimAdd)
-    shadow = mockclass(0).as_class_get_shadow()
+    shadow = mockclass(space, 0).as_class_get_shadow(space)
     w_method = model.W_CompiledMethod(0)
     w_method.argsize = 1
     w_method.tempsize = 1
@@ -555,11 +556,11 @@
     
     w_object = shadow.new()
     interp.s_active_context().push(w_object)
-    interp.s_active_context().push(interp.ONE)
+    interp.s_active_context().push(space.w_one)
     interp.step()
-    assert interp.w_active_context().as_methodcontext_get_shadow().w_method() == shadow.s_methoddict().methoddict["+"]
+    assert interp.w_active_context().as_methodcontext_get_shadow(space).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.w_active_context().as_methodcontext_get_shadow(space).gettemp(0).is_same_object(space.w_one)
     assert interp.s_active_context().stack() == []
 
 def test_bytecodePrimBool():
@@ -570,39 +571,39 @@
                              bytecodePrimEqual +
                              bytecodePrimNotEqual)
     for i in range(6):
-        interp.s_active_context().push(interp.ONE)
-        interp.s_active_context().push(interp.TWO)
+        interp.s_active_context().push(space.w_one)
+        interp.s_active_context().push(space.w_two)
         interp.step()
-    assert interp.s_active_context().stack() == [interp.TRUE, interp.FALSE,
-                                          interp.TRUE, interp.FALSE,
-                                          interp.FALSE, interp.TRUE]
+    assert interp.s_active_context().stack() == [space.w_true, space.w_false,
+                                          space.w_true, space.w_false,
+                                          space.w_false, space.w_true]
 
 def test_singleExtendedSendBytecode():
-    w_class = mockclass(0)
-    w_object = w_class.as_class_get_shadow().new()
+    w_class = mockclass(space, 0)
+    w_object = w_class.as_class_get_shadow(space).new()
     sendBytecodesTest(w_class, w_object, singleExtendedSendBytecode + chr((0<<5)+0))
 
 def test_singleExtendedSuperBytecode(bytecode=singleExtendedSuperBytecode + chr((0<<5) + 0)):
-    w_supersuper = mockclass(0)
-    w_super = mockclass(0, w_superclass=w_supersuper)
-    w_class = mockclass(0, w_superclass=w_super)
-    w_object = w_class.as_class_get_shadow().new()
+    w_supersuper = mockclass(space, 0)
+    w_super = mockclass(space, 0, w_superclass=w_supersuper)
+    w_class = mockclass(space, 0, w_superclass=w_super)
+    w_object = w_class.as_class_get_shadow(space).new()
     # first call method installed in w_class
     bytecodes = singleExtendedSendBytecode + chr(0)
     # which does a call to its super
     meth1 = model.W_CompiledMethod(2)
     meth1.bytes = pushReceiverBytecode + bytecode
-    w_class.as_class_get_shadow().installmethod("foo", meth1)
+    w_class.as_class_get_shadow(space).installmethod("foo", meth1)
     # and that one again to its super
     meth2 = model.W_CompiledMethod(2)
     meth2.bytes = pushReceiverBytecode + bytecode
-    w_super.as_class_get_shadow().installmethod("foo", meth2)
+    w_super.as_class_get_shadow(space).installmethod("foo", meth2)
     meth3 = model.W_CompiledMethod(0)
-    w_supersuper.as_class_get_shadow().installmethod("foo", meth3)
-    meth1.literals = fakeliterals("foo")
-    meth2.literals = fakeliterals("foo")
+    w_supersuper.as_class_get_shadow(space).installmethod("foo", meth3)
+    meth1.literals = fakeliterals(space, "foo")
+    meth2.literals = fakeliterals(space, "foo")
     interp = new_interpreter(bytecodes)
-    interp.w_active_context().as_methodcontext_get_shadow().w_method().literals = fakeliterals("foo")
+    interp.w_active_context().as_methodcontext_get_shadow(space).w_method().literals = fakeliterals(space, "foo")
     interp.s_active_context().push(w_object)
     interp.step()
     for w_specificclass in [w_super, w_supersuper]:
@@ -611,19 +612,19 @@
         interp.step()
         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().s_methoddict().methoddict["foo"]
-        assert interp.w_active_context().as_methodcontext_get_shadow().w_method() == meth
-        assert callerContext.as_context_get_shadow().stack() == []
+        assert interp.w_active_context().as_methodcontext_get_shadow(space).w_receiver() == w_object
+        meth = w_specificclass.as_class_get_shadow(space).s_methoddict().methoddict["foo"]
+        assert interp.w_active_context().as_methodcontext_get_shadow(space).w_method() == meth
+        assert callerContext.as_context_get_shadow(space).stack() == []
 
 def test_secondExtendedSendBytecode():
-    w_class = mockclass(0)
-    w_object = w_class.as_class_get_shadow().new()
+    w_class = mockclass(space, 0)
+    w_object = w_class.as_class_get_shadow(space).new()
     sendBytecodesTest(w_class, w_object, secondExtendedSendBytecode + chr(0)) 
 
 def test_doubleExtendedDoAnythinBytecode():
-    w_class = mockclass(0)
-    w_object = w_class.as_class_get_shadow().new()
+    w_class = mockclass(space, 0)
+    w_object = w_class.as_class_get_shadow(space).new()
 
     sendBytecodesTest(w_class, w_object, doubleExtendedDoAnythingBytecode + chr((0<<5) + 0) + chr(0))
 
@@ -645,10 +646,10 @@
 
     storeAssociation(doubleExtendedDoAnythingBytecode + chr(7<<5) + chr(0))
 
-def interpret_bc(bcodes, literals, receiver=objtable.w_nil):
+def interpret_bc(bcodes, literals, receiver=space.w_nil):
     bcode = "".join([chr(x) for x in bcodes])
     interp = new_interpreter(bcode, receiver=receiver)
-    interp.w_active_context().as_methodcontext_get_shadow().w_method().literals = literals
+    interp.w_active_context().as_methodcontext_get_shadow(space).w_method().literals = literals
     return interp.interpret()
 
 # tests: bytecodePrimValue & bytecodePrimValueWithArg
@@ -660,7 +661,7 @@
     #   ^ [ 3 + 4 ] value
     assert interpret_bc(
         [ 137, 117, 200, 164, 4, 32, 33, 176, 125, 201, 124],
-        fakeliterals(wrap_int(3), wrap_int(4))).value == 7
+        fakeliterals(space, space.wrap_int(3), space.wrap_int(4))).value == 7
 
 
 def test_bc_x_plus_x_plus_1():
@@ -672,7 +673,7 @@
     assert interpret_bc(
         [ 137, 118, 200, 164, 7, 104, 16, 16,
           176, 118, 176, 125, 32, 202, 124 ],
-        fakeliterals(wrap_int(3))).value == 7
+        fakeliterals(space, space.wrap_int(3))).value == 7
 
 def test_bc_x_plus_y():
     # value2
@@ -685,9 +686,9 @@
         assert interpret_bc(
             [ 137, 119, 200, 164, 6, 105, 104, 16, 17,
               176, 125, 33, 34, 240, 124 ],
-            fakeliterals("value:value:", wrap_int(3), wrap_int(4))).value == 7
+            fakeliterals(space, "value:value:", space.wrap_int(3), space.wrap_int(4))).value == 7
     run_with_faked_methods(
-        [[classtable.w_BlockContext, primitives.PRIMITIVE_VALUE,
+        [[space.w_BlockContext, primitives.PRIMITIVE_VALUE,
           2, "value:value:"]],
         test)
 
@@ -699,7 +700,7 @@
     #   ^ [ self ] value
     assert interpret_bc(
         [ 137, 117, 200, 164, 2, 112, 125, 201, 124 ],
-        fakeliterals(wrap_int(3))) is objtable.w_nil
+        fakeliterals(space, space.wrap_int(3))) is space.w_nil
 
 def test_bc_value_return():
     # valueReturn
@@ -709,7 +710,7 @@
     #   [ ^ 1 ] value. ^ 2
     assert interpret_bc(
         [ 137, 117, 200, 164, 2, 118, 124, 201, 135, 119, 124 ],
-        fakeliterals()).value == 1
+        fakeliterals(space, )).value == 1
 
 def test_bc_value_with_args():
     # valueWithArgs
@@ -722,10 +723,10 @@
             [ 137, 119, 200, 164, 6,
               105, 104, 16, 17, 177,
               125, 33, 224, 124 ],
-            fakeliterals("valueWithArguments:",
+            fakeliterals(space, "valueWithArguments:",
                          [3, 2])).value == 1
     run_with_faked_methods(
-        [[classtable.w_BlockContext, primitives.PRIMITIVE_VALUE_WITH_ARGS,
+        [[space.w_BlockContext, primitives.PRIMITIVE_VALUE_WITH_ARGS,
           1, "valueWithArguments:"]],
         test)
 
@@ -734,9 +735,9 @@
     def test():
         assert interpret_bc(
             [ 32, 118, 192, 124],
-            fakeliterals("a")) == wrap_char("a")
+            fakeliterals(space, "a")) == space.wrap_char("a")
     run_with_faked_methods(
-        [[classtable.w_String, primitives.STRING_AT, 1, "at:"]],
+        [[space.w_String, primitives.STRING_AT, 1, "at:"]],
         test)
     
 def test_bc_primBytecodeAtPut_string():
@@ -744,21 +745,21 @@
     def test():
         assert interpret_bc(
             [ 32, 118, 33, 193, 124 ],
-            fakeliterals("a", wrap_char("b"))) == wrap_char("b")
+            fakeliterals(space, "a", space.wrap_char("b"))) == space.wrap_char("b")
     run_with_faked_methods(
-        [[classtable.w_String, primitives.STRING_AT_PUT, 2, "at:put:"]],
+        [[space.w_String, primitives.STRING_AT_PUT, 2, "at:put:"]],
         test)
 
 def test_bc_primBytecodeAt_with_instvars():
     #   ^ self at: 1
-    w_fakeclass = mockclass(1, name='fakeclass', varsized=True)
-    w_fakeinst = w_fakeclass.as_class_get_shadow().new(1)
-    w_fakeinst.store(0, wrap_char("a")) # static slot 0: instance variable
-    w_fakeinst.store(1, wrap_char("b")) # varying slot 1
+    w_fakeclass = mockclass(space, 1, name='fakeclass', varsized=True)
+    w_fakeinst = w_fakeclass.as_class_get_shadow(space).new(1)
+    w_fakeinst.store(0, space.wrap_char("a")) # static slot 0: instance variable
+    w_fakeinst.store(1, space.wrap_char("b")) # varying slot 1
     def test():
-        assert utility.unwrap_char(interpret_bc(
+        assert space.unwrap_char(interpret_bc(
             [112, 118, 192, 124],
-            fakeliterals(),
+            fakeliterals(space, ),
             receiver=w_fakeinst)) == "b"
     run_with_faked_methods(
         [[w_fakeclass, primitives.AT, 1, "at:"]],
@@ -766,17 +767,17 @@
 
 def test_bc_primBytecodeAtPut_with_instvars():
     #   ^ self at: 1 put: #b
-    w_fakeclass = mockclass(1, name='fakeclass', varsized=True)
-    w_fakeinst = w_fakeclass.as_class_get_shadow().new(1)
-    w_fakeinst.store(0, wrap_char("a")) # static slot 0: instance variable
-    w_fakeinst.store(1, wrap_char("a")) # varying slot 1
+    w_fakeclass = mockclass(space, 1, name='fakeclass', varsized=True)
+    w_fakeinst = w_fakeclass.as_class_get_shadow(space).new(1)
+    w_fakeinst.store(0, space.wrap_char("a")) # static slot 0: instance variable
+    w_fakeinst.store(1, space.wrap_char("a")) # varying slot 1
     def test():
-        assert utility.unwrap_char(interpret_bc(
+        assert space.unwrap_char(interpret_bc(
             [0x70, 0x76, 0x20, 0xc1, 0x7c],
-            fakeliterals(wrap_char("b")),
+            fakeliterals(space, space.wrap_char("b")),
             receiver=w_fakeinst)) == "b"
-        assert utility.unwrap_char(w_fakeinst.fetch(0)) == "a"
-        assert utility.unwrap_char(w_fakeinst.fetch(1)) == "b"
+        assert space.unwrap_char(w_fakeinst.fetch(0)) == "a"
+        assert space.unwrap_char(w_fakeinst.fetch(1)) == "b"
     run_with_faked_methods(
         [[w_fakeclass, primitives.AT_PUT, 2, "at:put:"]],
         test)
@@ -787,9 +788,9 @@
     #   ^ self objectAt: 2 put: 3.   changes the first literal to 3
     #   ^ self objectAt: 2.          yields the new first literal (3)
     prim_meth = model.W_CompiledMethod(header=1024)
-    prim_meth.literals = fakeliterals(22)
-    oal = fakeliterals("objectAt:")
-    oalp = fakeliterals("objectAt:put:", 3)
+    prim_meth.literals = fakeliterals(space, 22)
+    oal = fakeliterals(space, "objectAt:")
+    oalp = fakeliterals(space, "objectAt:put:", 3)
     def test():
         assert interpret_bc(
             [112, 118, 224, 124], oal, receiver=prim_meth).value == 1024
@@ -800,8 +801,8 @@
         assert interpret_bc(
             [112, 119, 224, 124], oal, receiver=prim_meth).value == 3
     run_with_faked_methods(
-        [[classtable.w_CompiledMethod, primitives.OBJECT_AT, 1, "objectAt:"],
-         [classtable.w_CompiledMethod, primitives.OBJECT_AT_PUT, 2, "objectAt:put:"]],
+        [[space.w_CompiledMethod, primitives.OBJECT_AT, 1, "objectAt:"],
+         [space.w_CompiledMethod, primitives.OBJECT_AT_PUT, 2, "objectAt:put:"]],
         test)
 
 def test_runwithtrace():

Modified: pypy/branch/smalltalk-shadow-changes/pypy/lang/smalltalk/test/test_miniimage.py
==============================================================================
--- pypy/branch/smalltalk-shadow-changes/pypy/lang/smalltalk/test/test_miniimage.py	(original)
+++ pypy/branch/smalltalk-shadow-changes/pypy/lang/smalltalk/test/test_miniimage.py	Sun May 25 16:09:07 2008
@@ -6,25 +6,21 @@
 from pypy.lang.smalltalk import model
 from pypy.lang.smalltalk import constants
 from pypy.lang.smalltalk import interpreter
-from pypy.lang.smalltalk import objtable
-from pypy.lang.smalltalk import classtable
 from pypy.lang.smalltalk import shadow
-from pypy.lang.smalltalk import utility
+from pypy.lang.smalltalk import space as objspace
 # lazy initialization of test data, ie ImageReader and Float class
 
 def setup_module(module, filename='mini.image'):
-    # XXX XXX find a way to get rid of global state
-    global mini_image
-    global reader
-    global image
-    mini_image = py.magic.autopath().dirpath().dirpath().join(filename)
-    reader = open_miniimage()
+    space = objspace.ObjSpace()
+    module.mini_image = py.magic.autopath().dirpath().dirpath().join(filename)
+    module.reader = open_miniimage(space)
     reader.initialize()
-    image = squeakimage.SqueakImage()
-    image.from_reader(get_reader())
+    module.image = squeakimage.SqueakImage()
+    module.image.from_reader(space, get_reader())
+    module.space = space
     
-def open_miniimage():
-    return squeakimage.ImageReader(squeakimage.Stream(mini_image.open()))
+def open_miniimage(space):
+    return squeakimage.ImageReader(space, squeakimage.Stream(mini_image.open()))
 
 def get_reader():
     return reader
@@ -42,27 +38,19 @@
     assert mini_image.check(dir=False)
 
 def test_read_header():
-    reader = open_miniimage()
+    reader = open_miniimage(space)
     reader.read_header()
     assert reader.endofmemory == 0x93174
     assert reader.oldbaseaddress == 0x6649000
     assert reader.specialobjectspointer == 0x6668380
 
 def test_read_all_header(): 
-    reader = open_miniimage()
+    reader = open_miniimage(space)
     reader.read_header()
     next = reader.stream.peek()
     assert next != 0 #expects object header, which must not be 0x00000000 
       
       
-      
-def test_number_of_objects():
-    py.test.skip("we don't store globally available objects other than the special objects array")
-    image = get_image()
-    objects = objtable.objects
-    assert len(objects) > 0
-    assert 15000 < len(objects) < 16000 
-    
 def test_all_pointers_are_valid():
     reader = get_reader()
     for each in reader.chunks.itervalues():
@@ -76,12 +64,6 @@
     reader = get_reader()
     assert len(reader.compactclasses) == 31
     
-def test_invariant():
-    py.test.skip("we don't store globally available objects other than the special objects array")
-    image = get_image()
-    for each in objtable.objects:
-        each.invariant()
-    
 def test_float_class_size():
     w_float_class = get_float_class()
     assert w_float_class.size() == 9
@@ -94,18 +76,23 @@
     
 def test_str_w_object():
     w_float_class = get_float_class()
-    w_float_class.as_class_get_shadow()
+    w_float_class.as_class_get_shadow(space)
     assert str(w_float_class) == "Float class"
-    assert str(w_float_class.getclass()) == "a Metaclass" #yes, with article
-    assert str(w_float_class.getclass().getclass()) == "Metaclass class"
+    w_float_class.shadow_of_my_class(space)
+    #assert str(w_float_class.getclass(space)) == "a Metaclass" #yes, with article
+    w_float_class.getclass(space).shadow_of_my_class(space)
+    #assert str(w_float_class.getclass(space).getclass(space)) == "Metaclass class"
 
 def test_nil_true_false():
     image = get_image()
     w = image.special(constants.SO_NIL)
+    w.shadow_of_my_class(space)
     assert str(w) == "a UndefinedObject" #yes, with article
     w = image.special(constants.SO_FALSE)
+    w.shadow_of_my_class(space)
     assert str(w) == "a False" #yes, with article
     w = image.special(constants.SO_TRUE)
+    w.shadow_of_my_class(space)
     assert str(w) == "a True" #yes, with article
     
 def test_scheduler():
@@ -114,6 +101,7 @@
     w0 = w.fetch(0)
     assert str(w0) == "Processor" 
     w0 = w.fetch(1)
+    w0.shadow_of_my_class(space)
     assert str(w0) == "a ProcessorScheduler" 
    
 def test_special_classes0():
@@ -150,20 +138,20 @@
 def test_name_of_shadow_of_specials():
     image = get_image()
     w_doesnot = image.special(constants.SO_DOES_NOT_UNDERSTAND)
-    assert repr(w_doesnot.shadow_of_my_class()) == "<ClassShadow Symbol>"
-    assert repr(objtable.w_nil.shadow_of_my_class()) == "<ClassShadow UndefinedObject>"
-    assert repr(objtable.w_minus_one.shadow_of_my_class()) == "<ClassShadow SmallInteger>"
-    assert repr(objtable.w_zero.shadow_of_my_class()) == "<ClassShadow SmallInteger>"
-    assert repr(objtable.w_one.shadow_of_my_class()) == "<ClassShadow SmallInteger>"
-    assert repr(objtable.w_two.shadow_of_my_class()) == "<ClassShadow SmallInteger>"
-    assert repr(objtable.w_true.shadow_of_my_class()) == "<ClassShadow True>"
-    assert repr(objtable.w_false.shadow_of_my_class()) == "<ClassShadow False>"
+    assert repr(w_doesnot.shadow_of_my_class(space)) == "<ClassShadow Symbol>"
+    assert repr(space.w_nil.shadow_of_my_class(space)) == "<ClassShadow UndefinedObject>"
+    assert repr(space.w_minus_one.shadow_of_my_class(space)) == "<ClassShadow SmallInteger>"
+    assert repr(space.w_zero.shadow_of_my_class(space)) == "<ClassShadow SmallInteger>"
+    assert repr(space.w_one.shadow_of_my_class(space)) == "<ClassShadow SmallInteger>"
+    assert repr(space.w_two.shadow_of_my_class(space)) == "<ClassShadow SmallInteger>"
+    assert repr(space.w_true.shadow_of_my_class(space)) == "<ClassShadow True>"
+    assert repr(space.w_false.shadow_of_my_class(space)) == "<ClassShadow False>"
 
 def test_special_classes0():
     image = get_image()
     w = image.special(constants.SO_DOES_NOT_UNDERSTAND)
     assert str(w) == "doesNotUnderstand:"
-    assert str(w.getclass()) == "Symbol class" # for some strange reason not a symbol
+    assert str(w.getclass(space)) == "Symbol class" # for some strange reason not a symbol
     
     
     """SO_DOES_NOT_UNDERSTAND = 20
@@ -194,17 +182,17 @@
 
 def test_lookup_abs_in_integer(int=10):
     image = get_image()
-    interp = interpreter.Interpreter()
+    interp = interpreter.Interpreter(space)
 
     w_object = model.W_SmallInteger(int)
 
     # Should get this from w_object
     w_smallint_class = image.special(constants.SO_SMALLINTEGER_CLASS)
-    s_class = w_object.shadow_of_my_class()
+    s_class = w_object.shadow_of_my_class(space)
     w_method = s_class.lookup("abs")
 
     assert w_method
-    w_frame = w_method.create_frame(w_object, [])
+    w_frame = w_method.create_frame(space, w_object, [])
     interp.store_w_active_context(w_frame)
 
     while True:
@@ -219,58 +207,58 @@
 
 def test_map_mirrors_to_classtable():
     w_compiledmethod_class = image.special(constants.SO_COMPILEDMETHOD_CLASS)
-    assert w_compiledmethod_class is classtable.w_CompiledMethod
+    assert w_compiledmethod_class.is_same_object(space.w_CompiledMethod)
     w_nil = image.special(constants.SO_NIL)
-    assert w_nil is objtable.w_nil
+    assert w_nil.is_same_object(space.w_nil)
     w_true = image.special(constants.SO_TRUE)
-    assert w_true is objtable.w_true
+    assert w_true.is_same_object(space.w_true)
     w_false = image.special(constants.SO_FALSE)
-    assert w_false is objtable.w_false
+    assert w_false.is_same_object(space.w_false)
     
 def test_runimage():
     py.test.skip("This method actually runs an image. Fails since no graphical primitives yet")
     from pypy.lang.smalltalk import wrapper
     ap = wrapper.ProcessWraper(wrapper.scheduler().active_process())
     s_ctx = ap.suspended_context().as_methodcontext_get_shadow()
-    ap.store_suspended_context(objtable.w_nil)
+    ap.store_suspended_context(space.w_nil)
 
     interp = interpreter.Interpreter()
     interp.store_w_active_context(s_ctx.w_self())
     interp.interpret()
     
 def test_compile_method():
-    #py.test.skip("fails again because of the removed become. should work with new pypy become")
     sourcecode = """fib 
                         ^self < 2 
                             ifTrue: [ 1 ] 
                             ifFalse: [ (self - 1) fib + (self - 2) fib ]"""
-    perform(w(10).getclass(), "compile:classified:notifying:", w(sourcecode), w('pypy'), w(None))
+    perform(w(10).getclass(space), "compile:classified:notifying:", w(sourcecode), w('pypy'), w(None))
     assert perform(w(10), "fib").is_same_object(w(89))
 
 def w(any): 
+    # XXX could put this on the space?
     if any is None:
-        return objtable.w_nil
+        return space.w_nil
     if isinstance(any, str):
         # assume never have strings of length 1
         if len(any) == 1: 
-            return utility.wrap_chr(any)
+            return space.wrap_chr(any)
         else:
-            return utility.wrap_string(any)
+            return space.wrap_string(any)
     if isinstance(any, int):    
-        return utility.wrap_int(any)
+        return space.wrap_int(any)
     if isinstance(any, bool):
-        return utility.wrap_bool(any)
+        return space.wrap_bool(any)
     if isinstance(any, float):
-        return utility.wrap_float(any)
+        return space.wrap_float(any)
     else:
         raise Exception    
         
 def perform(w_receiver, selector, *arguments_w):
-    interp = interpreter.Interpreter()
-    s_class = w_receiver.shadow_of_my_class()
+    interp = interpreter.Interpreter(space)
+    s_class = w_receiver.shadow_of_my_class(space)
     w_method = s_class.lookup(selector)
     assert w_method
-    w_frame = w_method.create_frame(w_receiver, list(arguments_w))
+    w_frame = w_method.create_frame(space, w_receiver, list(arguments_w))
     interp.store_w_active_context(w_frame)
     while True:
         try:
@@ -281,22 +269,23 @@
 
 def test_step_forged_image():
     from pypy.lang.smalltalk import wrapper
-    ap = wrapper.ProcessWrapper(wrapper.scheduler().active_process())
-    s_ctx = ap.suspended_context().as_context_get_shadow()
+    ap = wrapper.ProcessWrapper(space, wrapper.scheduler(space).active_process())
+    s_ctx = ap.suspended_context().as_context_get_shadow(space)
     assert isinstance(s_ctx, shadow.MethodContextShadow)
-    assert s_ctx.top().is_same_object(objtable.w_true)
+    assert s_ctx.top().is_same_object(space.w_true)
 
 def test_step_run_something():
-    setup_module(None, filename='running-something-mini.image')
+    from pypy.lang.smalltalk.test import test_miniimage
+    setup_module(test_miniimage, filename='running-something-mini.image')
     from pypy.lang.smalltalk import wrapper
-    ap = wrapper.ProcessWrapper(wrapper.scheduler().active_process())
-    s_ctx = ap.suspended_context().as_context_get_shadow()
-    ap.store_suspended_context(objtable.w_nil)
+    ap = wrapper.ProcessWrapper(space, wrapper.scheduler(space).active_process())
+    s_ctx = ap.suspended_context().as_context_get_shadow(space)
+    ap.store_suspended_context(space.w_nil)
 
-    interp = interpreter.Interpreter()
+    interp = interpreter.Interpreter(space)
     interp.store_w_active_context(s_ctx.w_self())
     assert isinstance(s_ctx, shadow.MethodContextShadow)
-    assert interp.s_active_context().top().is_same_object(objtable.w_true)
+    assert interp.s_active_context().top().is_same_object(space.w_true)
     interp.step()
     interp.step() 
     assert interp.s_active_context().top().value == 1

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 25 16:09:07 2008
@@ -1,7 +1,11 @@
 import py
-from pypy.lang.smalltalk import model, shadow, objtable
+from pypy.lang.smalltalk import model, shadow
 from pypy.lang.smalltalk.shadow import MethodNotFound
-from pypy.lang.smalltalk import classtable, utility
+from pypy.lang.smalltalk import space as objspace
+
+mockclass = objspace.bootstrap_class
+
+space = objspace.ObjSpace()
 
 def joinbits(values, lengths):
     result = 0
@@ -10,31 +14,30 @@
         result += each
     return result   
 
-mockclass = classtable.bootstrap_class
 
 def test_new():
-    w_mycls = mockclass(0)
-    w_myinstance = w_mycls.as_class_get_shadow().new()
+    w_mycls = mockclass(space, 0)
+    w_myinstance = w_mycls.as_class_get_shadow(space).new()
     assert isinstance(w_myinstance, model.W_PointersObject)
-    assert w_myinstance.getclass().is_same_object(w_mycls)
-    assert w_myinstance.shadow_of_my_class() is w_mycls.as_class_get_shadow()
+    assert w_myinstance.getclass(space).is_same_object(w_mycls)
+    assert w_myinstance.shadow_of_my_class(space) is w_mycls.as_class_get_shadow(space)
 
 def test_new_namedvars():
-    w_mycls = mockclass(3)
-    w_myinstance = w_mycls.as_class_get_shadow().new()
+    w_mycls = mockclass(space, 3)
+    w_myinstance = w_mycls.as_class_get_shadow(space).new()
     assert isinstance(w_myinstance, model.W_PointersObject)
-    assert w_myinstance.getclass().is_same_object(w_mycls)
-    assert w_myinstance.fetch(0) is objtable.w_nil
+    assert w_myinstance.getclass(space).is_same_object(w_mycls)
+    assert w_myinstance.fetch(0) is space.w_nil
     py.test.raises(IndexError, lambda: w_myinstance.fetch(3))
     w_myinstance.store(1, w_myinstance)
     assert w_myinstance.fetch(1) is w_myinstance
 
 def test_bytes_object():
-    w_class = mockclass(0, format=shadow.BYTES)
-    w_bytes = w_class.as_class_get_shadow().new(20)
-    assert w_bytes.getclass().is_same_object(w_class)
+    w_class = mockclass(space, 0, format=shadow.BYTES)
+    w_bytes = w_class.as_class_get_shadow(space).new(20)
+    assert w_bytes.getclass(space).is_same_object(w_class)
     assert w_bytes.size() == 20
-    assert w_class.as_class_get_shadow().instsize() == 0
+    assert w_class.as_class_get_shadow(space).instsize() == 0
     assert w_bytes.getchar(3) == "\x00"
     w_bytes.setchar(3, "\xAA")
     assert w_bytes.getchar(3) == "\xAA"
@@ -42,11 +45,11 @@
     py.test.raises(IndexError, lambda: w_bytes.getchar(20))
 
 def test_word_object():
-    w_class = mockclass(0, format=shadow.WORDS)
-    w_bytes = w_class.as_class_get_shadow().new(20)
-    assert w_bytes.getclass().is_same_object(w_class)
+    w_class = mockclass(space, 0, format=shadow.WORDS)
+    w_bytes = w_class.as_class_get_shadow(space).new(20)
+    assert w_bytes.getclass(space).is_same_object(w_class)
     assert w_bytes.size() == 20
-    assert w_class.as_class_get_shadow().instsize() == 0
+    assert w_class.as_class_get_shadow(space).instsize() == 0
     assert w_bytes.getword(3) == 0
     w_bytes.setword(3, 42)  
     assert w_bytes.getword(3) == 42
@@ -54,12 +57,12 @@
     py.test.raises(IndexError, lambda: w_bytes.getword(20))
 
 def test_method_lookup():
-    w_class = mockclass(0)
-    shadow = w_class.as_class_get_shadow()
+    w_class = mockclass(space, 0)
+    shadow = w_class.as_class_get_shadow(space)
     shadow.installmethod("foo", 1)
     shadow.installmethod("bar", 2)
-    w_subclass = mockclass(0, w_superclass=w_class)
-    subshadow = w_subclass.as_class_get_shadow()
+    w_subclass = mockclass(space, 0, w_superclass=w_class)
+    subshadow = w_subclass.as_class_get_shadow(space)
     assert subshadow.s_superclass() is shadow
     subshadow.installmethod("foo", 3)
     shadow.initialize_methoddict()
@@ -72,11 +75,11 @@
     py.test.raises(MethodNotFound, subshadow.lookup, "zork")
 
 def test_w_compiledin():
-    w_super = mockclass(0)
-    w_class = mockclass(0, w_superclass=w_super)
-    supershadow = w_super.as_class_get_shadow()
+    w_super = mockclass(space, 0)
+    w_class = mockclass(space, 0, w_superclass=w_super)
+    supershadow = w_super.as_class_get_shadow(space)
     supershadow.installmethod("foo", model.W_CompiledMethod(0))
-    classshadow = w_class.as_class_get_shadow()
+    classshadow = w_class.as_class_get_shadow(space)
     classshadow.initialize_methoddict()
     assert classshadow.lookup("foo").w_compiledin is w_super
 
@@ -88,8 +91,8 @@
 def test_hashes():
     w_five = model.W_SmallInteger(5)
     assert w_five.gethash() == 5
-    w_class = mockclass(0)
-    w_inst = w_class.as_class_get_shadow().new()
+    w_class = mockclass(space, 0)
+    w_inst = w_class.as_class_get_shadow(space).new()
     assert w_inst.hash == w_inst.UNASSIGNED_HASH
     h1 = w_inst.gethash()
     h2 = w_inst.gethash()
@@ -102,30 +105,30 @@
     w_method.header = 100
     w_method.literals = [ 'lit1', 'lit2' ]
     w_method.literalsize = 2
-    assert utility.unwrap_int(w_method.at0(0)) == 100
-    assert w_method.at0(4) == 'lit1'
-    assert w_method.at0(8) == 'lit2'
-    assert utility.unwrap_int(w_method.at0(12)) == ord('a')
-    assert utility.unwrap_int(w_method.at0(13)) == ord('b')
-    assert utility.unwrap_int(w_method.at0(14)) == ord('c')
+    assert space.unwrap_int(w_method.at0(space, 0)) == 100
+    assert w_method.at0(space, 4) == 'lit1'
+    assert w_method.at0(space, 8) == 'lit2'
+    assert space.unwrap_int(w_method.at0(space, 12)) == ord('a')
+    assert space.unwrap_int(w_method.at0(space, 13)) == ord('b')
+    assert space.unwrap_int(w_method.at0(space, 14)) == ord('c')
 
 def test_compiledmethod_atput0():
     w_method = model.W_CompiledMethod(3)
     newheader = joinbits([0,2,0,0,0,0],[9,8,1,6,4,1])
     assert w_method.getliteralsize() == 0
-    w_method.atput0(0, utility.wrap_int(newheader))
+    w_method.atput0(space, 0, space.wrap_int(newheader))
     assert w_method.getliteralsize() == 8 # 2 from new header * BYTES_PER_WORD (= 4)
-    w_method.atput0(4, 'lit1')
-    w_method.atput0(8, 'lit2')
-    w_method.atput0(12, utility.wrap_int(ord('a')))
-    w_method.atput0(13, utility.wrap_int(ord('b')))
-    w_method.atput0(14, utility.wrap_int(ord('c')))
-    assert utility.unwrap_int(w_method.at0(0)) == newheader
-    assert w_method.at0(4) == 'lit1'
-    assert w_method.at0(8) == 'lit2'
-    assert utility.unwrap_int(w_method.at0(12)) == ord('a')
-    assert utility.unwrap_int(w_method.at0(13)) == ord('b')
-    assert utility.unwrap_int(w_method.at0(14)) == ord('c')
+    w_method.atput0(space, 4, 'lit1')
+    w_method.atput0(space, 8, 'lit2')
+    w_method.atput0(space, 12, space.wrap_int(ord('a')))
+    w_method.atput0(space, 13, space.wrap_int(ord('b')))
+    w_method.atput0(space, 14, space.wrap_int(ord('c')))
+    assert space.unwrap_int(w_method.at0(space, 0)) == newheader
+    assert w_method.at0(space, 4) == 'lit1'
+    assert w_method.at0(space, 8) == 'lit2'
+    assert space.unwrap_int(w_method.at0(space, 12)) == ord('a')
+    assert space.unwrap_int(w_method.at0(space, 13)) == ord('b')
+    assert space.unwrap_int(w_method.at0(space, 14)) == ord('c')
 
 def test_is_same_object(w_o1=model.W_PointersObject(None,0), w_o2=None):
     if w_o2 is None:
@@ -155,20 +158,20 @@
     test_not_is_same_object(model.W_SmallInteger(101), model.W_SmallInteger(100))
 
 def test_charis_same_object():
-    test_is_same_object(utility.wrap_char('a'), utility.wrap_char('a'))
-    test_is_same_object(utility.wrap_char('d'), utility.wrap_char('d'))
+    test_is_same_object(space.wrap_char('a'), space.wrap_char('a'))
+    test_is_same_object(space.wrap_char('d'), space.wrap_char('d'))
 
 def test_not_charis_same_object():
-    test_not_is_same_object(utility.wrap_char('a'), utility.wrap_char('d'))
-    test_not_is_same_object(utility.wrap_char('d'), utility.wrap_int(3))
-    test_not_is_same_object(utility.wrap_char('d'), utility.wrap_float(3.0))
+    test_not_is_same_object(space.wrap_char('a'), space.wrap_char('d'))
+    test_not_is_same_object(space.wrap_char('d'), space.wrap_int(3))
+    test_not_is_same_object(space.wrap_char('d'), space.wrap_float(3.0))
 
 def test_become_pointers():
-    w_clsa = mockclass(3)
-    w_a = w_clsa.as_class_get_shadow().new()
+    w_clsa = mockclass(space, 3)
+    w_a = w_clsa.as_class_get_shadow(space).new()
 
-    w_clsb = mockclass(4)
-    w_b = w_clsb.as_class_get_shadow().new()
+    w_clsb = mockclass(space, 4)
+    w_b = w_clsb.as_class_get_shadow(space).new()
     
     hasha = w_a.gethash()
     hashb = w_b.gethash()
@@ -181,18 +184,18 @@
     assert w_a.gethash() == hashb
     assert w_b.gethash() == hasha
 
-    assert w_a.getclass().is_same_object(w_clsb)
-    assert w_b.getclass().is_same_object(w_clsa)
+    assert w_a.getclass(space).is_same_object(w_clsb)
+    assert w_b.getclass(space).is_same_object(w_clsa)
 
     assert w_b.fetch(0) is w_b
     assert w_a.fetch(1) is w_a
 
 def test_become_with_shadow():
-    w_clsa = mockclass(3)
-    s_clsa = w_clsa.as_class_get_shadow()
-    w_clsb = mockclass(4)
-    s_clsb = w_clsb.as_class_get_shadow()
+    w_clsa = mockclass(space, 3)
+    s_clsa = w_clsa.as_class_get_shadow(space)
+    w_clsb = mockclass(space, 4)
+    s_clsb = w_clsb.as_class_get_shadow(space)
     res = w_clsa.become(w_clsb)
     assert res
-    assert w_clsa.as_class_get_shadow() is s_clsb
-    assert w_clsb.as_class_get_shadow() is s_clsa
+    assert w_clsa.as_class_get_shadow(space) is s_clsb
+    assert w_clsb.as_class_get_shadow(space) is s_clsa

Modified: pypy/branch/smalltalk-shadow-changes/pypy/lang/smalltalk/test/test_primitives.py
==============================================================================
--- pypy/branch/smalltalk-shadow-changes/pypy/lang/smalltalk/test/test_primitives.py	(original)
+++ pypy/branch/smalltalk-shadow-changes/pypy/lang/smalltalk/test/test_primitives.py	Sun May 25 16:09:07 2008
@@ -1,13 +1,15 @@
 import py
 import math
 from pypy.lang.smalltalk.primitives import prim_table, PrimitiveFailedError
-from pypy.lang.smalltalk import model, shadow
-from pypy.lang.smalltalk import interpreter, utility
-from pypy.lang.smalltalk import classtable, objtable, constants
+from pypy.lang.smalltalk import model, shadow, interpreter
+from pypy.lang.smalltalk import constants
 from pypy.rlib.rarithmetic import INFINITY, NAN, isinf, isnan
 from pypy.lang.smalltalk import primitives
+from pypy.lang.smalltalk import space as objspace
 
-mockclass = classtable.bootstrap_class
+mockclass = objspace.bootstrap_class
+
+space = objspace.ObjSpace()
 
 class MockFrame(model.W_PointersObject):
     def __init__(self, stack):
@@ -16,21 +18,21 @@
         s_self._stack = stack
         s_self.store_expected_argument_count(0)
     def as_blockcontext_get_shadow(self):
-        self._shadow = shadow.BlockContextShadow(self)
+        self._shadow = shadow.BlockContextShadow(space, self)
         return self._shadow
 
 def wrap(x):
-    if isinstance(x, int): return utility.wrap_int(x)
-    if isinstance(x, float): return utility.wrap_float(x)
+    if isinstance(x, int): return space.wrap_int(x)
+    if isinstance(x, float): return space.wrap_float(x)
     if isinstance(x, model.W_Object): return x
-    if isinstance(x, str) and len(x) == 1: return utility.wrap_char(x)
-    if isinstance(x, str): return utility.wrap_string(x)
+    if isinstance(x, str) and len(x) == 1: return space.wrap_char(x)
+    if isinstance(x, str): return space.wrap_string(x)
     raise NotImplementedError
     
 def mock(stack):
     mapped_stack = [wrap(x) for x in stack]
     frame = MockFrame(mapped_stack)
-    interp = interpreter.Interpreter()
+    interp = interpreter.Interpreter(space)
     interp.store_w_active_context(frame)
     return (interp, len(stack))
 
@@ -181,16 +183,16 @@
     assert prim(primitives.FLOAT_TRUNCATED, [4.6]).value == 4
 
 def test_at():
-    w_obj = mockclass(0, varsized=True).as_class_get_shadow().new(1)
+    w_obj = mockclass(space, 0, varsized=True).as_class_get_shadow(space).new(1)
     w_obj.store(0, "foo")
     assert prim(primitives.AT, [w_obj, 1]) == "foo"
 
 def test_invalid_at():
-    w_obj = mockclass(0).as_class_get_shadow().new()
+    w_obj = mockclass(space, 0).as_class_get_shadow(space).new()
     prim_fails(primitives.AT, [w_obj, 1])
 
 def test_at_put():
-    w_obj = mockclass(0, varsized=1).as_class_get_shadow().new(1)
+    w_obj = mockclass(space, 0, varsized=1).as_class_get_shadow(space).new(1)
     assert prim(primitives.AT_PUT, [w_obj, 1, 22]).value == 22
     assert prim(primitives.AT, [w_obj, 1]).value == 22
     
@@ -203,13 +205,13 @@
     assert prim(primitives.AT, [w_str, 3]).value == ord('c')
 
 def test_invalid_at_put():
-    w_obj = mockclass(0).as_class_get_shadow().new()
+    w_obj = mockclass(space, 0).as_class_get_shadow(space).new()
     prim_fails(primitives.AT_PUT, [w_obj, 1, 22])
     
 def test_size():
-    w_obj = mockclass(0, varsized=True).as_class_get_shadow().new(0)
+    w_obj = mockclass(space, 0, varsized=True).as_class_get_shadow(space).new(0)
     assert prim(primitives.SIZE, [w_obj]).value == 0
-    w_obj = mockclass(3, varsized=True).as_class_get_shadow().new(5)
+    w_obj = mockclass(space, 3, varsized=True).as_class_get_shadow(space).new(5)
     assert prim(primitives.SIZE, [w_obj]).value == 5
 
 def test_size_of_compiled_method():
@@ -233,7 +235,7 @@
     prim_fails(primitives.OBJECT_AT, ["q", constants.CHARACTER_VALUE_INDEX+2])
     
 def test_invalid_object_at_put():
-    w_obj = mockclass(1).as_class_get_shadow().new()
+    w_obj = mockclass(space, 1).as_class_get_shadow(space).new()
     prim_fails(primitives.OBJECT_AT_PUT, [w_obj, 2, 42])
     
 def test_string_at_put():
@@ -244,20 +246,20 @@
         assert prim(primitives.STRING_AT, [test_str, i]) == wrap(exp[i-1])
 
 def test_new():
-    w_Object = classtable.classtable['w_Object']
+    w_Object = space.classtable['w_Object']
     w_res = prim(primitives.NEW, [w_Object])
-    assert w_res.getclass().is_same_object(w_Object)
+    assert w_res.getclass(space).is_same_object(w_Object)
     
 def test_invalid_new():
-    prim_fails(primitives.NEW, [classtable.w_String])
+    prim_fails(primitives.NEW, [space.w_String])
 
 def test_new_with_arg():
-    w_res = prim(primitives.NEW_WITH_ARG, [classtable.w_String, 20])
-    assert w_res.getclass().is_same_object(classtable.w_String)
+    w_res = prim(primitives.NEW_WITH_ARG, [space.w_String, 20])
+    assert w_res.getclass(space).is_same_object(space.w_String)
     assert w_res.size() == 20    
 
 def test_invalid_new_with_arg():
-    w_Object = classtable.classtable['w_Object']
+    w_Object = space.classtable['w_Object']
     prim_fails(primitives.NEW_WITH_ARG, [w_Object, 20])
     
 def test_inst_var_at():
@@ -272,10 +274,10 @@
 
 def test_inst_var_at_put():
     # n.b.: 1-based indexing!
-    w_q = classtable.w_Character.as_class_get_shadow().new()
+    w_q = space.w_Character.as_class_get_shadow(space).new()
     vidx = constants.CHARACTER_VALUE_INDEX+1
     ordq = ord("q")
-    assert prim(primitives.INST_VAR_AT, [w_q, vidx]) == objtable.w_nil
+    assert prim(primitives.INST_VAR_AT, [w_q, vidx]) == space.w_nil
     assert prim(primitives.INST_VAR_AT_PUT, [w_q, vidx, ordq]).value == ordq
     assert prim(primitives.INST_VAR_AT, [w_q, vidx]).value == ordq
 
@@ -285,12 +287,12 @@
                ["q", constants.CHARACTER_VALUE_INDEX+2, "t"])
     
 def test_class():
-    assert prim(primitives.CLASS, ["string"]) == classtable.w_String
-    assert prim(primitives.CLASS, [1]) == classtable.w_SmallInteger
+    assert prim(primitives.CLASS, ["string"]).is_same_object(space.w_String)
+    assert prim(primitives.CLASS, [1]).is_same_object(space.w_SmallInteger)
 
 def test_as_oop():
     py.test.skip("not yet clear what AS_OOP returns: hash or header?")
-    w_obj = mockclass(0).as_class_get_shadow().new()
+    w_obj = mockclass(space, 0).as_class_get_shadow(space).new()
     w_obj.w_hash = wrap(22)
     assert prim(primitives.AS_OOP, [w_obj]).value == 22
 
@@ -299,33 +301,33 @@
 
 def test_const_primitives():
     for (code, const) in [
-        (primitives.PUSH_TRUE, objtable.w_true),
-        (primitives.PUSH_FALSE, objtable.w_false),
-        (primitives.PUSH_NIL, objtable.w_nil),
-        (primitives.PUSH_MINUS_ONE, objtable.w_minus_one),
-        (primitives.PUSH_ZERO, objtable.w_zero),
-        (primitives.PUSH_ONE, objtable.w_one),
-        (primitives.PUSH_TWO, objtable.w_two),
+        (primitives.PUSH_TRUE, space.w_true),
+        (primitives.PUSH_FALSE, space.w_false),
+        (primitives.PUSH_NIL, space.w_nil),
+        (primitives.PUSH_MINUS_ONE, space.w_minus_one),
+        (primitives.PUSH_ZERO, space.w_zero),
+        (primitives.PUSH_ONE, space.w_one),
+        (primitives.PUSH_TWO, space.w_two),
         ]:
-        assert prim(code, [objtable.w_nil]) is const
-    assert prim(primitives.PUSH_SELF, [objtable.w_nil]) is objtable.w_nil
+        assert prim(code, [space.w_nil]).is_same_object(const)
+    assert prim(primitives.PUSH_SELF, [space.w_nil]).is_same_object(space.w_nil)
     assert prim(primitives.PUSH_SELF, ["a"]) is wrap("a")
 
 def test_boolean():
-    assert prim(primitives.LESSTHAN, [1,2]) == objtable.w_true
-    assert prim(primitives.GREATERTHAN, [3,4]) == objtable.w_false
-    assert prim(primitives.LESSOREQUAL, [1,2]) == objtable.w_true
-    assert prim(primitives.GREATEROREQUAL, [3,4]) == objtable.w_false
-    assert prim(primitives.EQUAL, [2,2]) == objtable.w_true
-    assert prim(primitives.NOTEQUAL, [2,2]) == objtable.w_false
+    assert prim(primitives.LESSTHAN, [1,2]).is_same_object(space.w_true)
+    assert prim(primitives.GREATERTHAN, [3,4]).is_same_object(space.w_false)
+    assert prim(primitives.LESSOREQUAL, [1,2]).is_same_object(space.w_true)
+    assert prim(primitives.GREATEROREQUAL, [3,4]).is_same_object(space.w_false)
+    assert prim(primitives.EQUAL, [2,2]).is_same_object(space.w_true)
+    assert prim(primitives.NOTEQUAL, [2,2]).is_same_object(space.w_false)
 
 def test_float_boolean():
-    assert prim(primitives.FLOAT_LESSTHAN, [1.0,2.0]) == objtable.w_true
-    assert prim(primitives.FLOAT_GREATERTHAN, [3.0,4.0]) == objtable.w_false
-    assert prim(primitives.FLOAT_LESSOREQUAL, [1.3,2.6]) == objtable.w_true
-    assert prim(primitives.FLOAT_GREATEROREQUAL, [3.5,4.9]) == objtable.w_false
-    assert prim(primitives.FLOAT_EQUAL, [2.2,2.2]) == objtable.w_true
-    assert prim(primitives.FLOAT_NOTEQUAL, [2.2,2.2]) == objtable.w_false
+    assert prim(primitives.FLOAT_LESSTHAN, [1.0,2.0]).is_same_object(space.w_true)
+    assert prim(primitives.FLOAT_GREATERTHAN, [3.0,4.0]).is_same_object(space.w_false)
+    assert prim(primitives.FLOAT_LESSOREQUAL, [1.3,2.6]).is_same_object(space.w_true)
+    assert prim(primitives.FLOAT_GREATEROREQUAL, [3.5,4.9]).is_same_object(space.w_false)
+    assert prim(primitives.FLOAT_EQUAL, [2.2,2.2]).is_same_object(space.w_true)
+    assert prim(primitives.FLOAT_NOTEQUAL, [2.2,2.2]).is_same_object(space.w_false)
     
 def test_block_copy_and_value():
     # see test_interpreter for tests of these opcodes
@@ -404,11 +406,11 @@
 def test_new_method():
     bytecode = ''.join(map(chr, [ 16, 119, 178, 154, 118, 164, 11, 112, 16, 118, 177, 224, 112, 16, 119, 177, 224, 176, 124 ]))
 
-    shadow = mockclass(0).as_class_get_shadow()
-    w_method = prim(primitives.NEW_METHOD, [classtable.w_CompiledMethod, len(bytecode), 1025])
-    assert w_method.literalat0(0).value == 1025
+    shadow = mockclass(space, 0).as_class_get_shadow(space)
+    w_method = prim(primitives.NEW_METHOD, [space.w_CompiledMethod, len(bytecode), 1025])
+    assert w_method.literalat0(space, 0).value == 1025
     assert w_method.literalsize == 2
-    assert w_method.literalat0(1) is objtable.w_nil
+    assert w_method.literalat0(space, 1).is_same_object(space.w_nil)
     assert w_method.bytes == "\x00" * len(bytecode)
 
 

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 25 16:09:07 2008
@@ -1,27 +1,29 @@
 import random
-from pypy.lang.smalltalk import model, shadow, classtable, constants, objtable
-from pypy.lang.smalltalk import utility
+from pypy.lang.smalltalk import model, shadow, constants
+from pypy.lang.smalltalk import space as objspace
 
-w_Object = classtable.classtable['w_Object']
-w_Metaclass  = classtable.classtable['w_Metaclass']
-w_MethodDict = classtable.classtable['w_MethodDict']
-w_Array      = classtable.classtable['w_Array']
+space = objspace.ObjSpace()
+
+w_Object = space.classtable['w_Object']
+w_Metaclass  = space.classtable['w_Metaclass']
+w_MethodDict = space.classtable['w_MethodDict']
+w_Array      = space.classtable['w_Array']
 
 def build_methoddict(methods):
     size = int(len(methods) * 1.5)
-    w_methoddict = w_MethodDict.as_class_get_shadow().new(size)
-    w_array = w_Array.as_class_get_shadow().new(size)
+    w_methoddict = w_MethodDict.as_class_get_shadow(space).new(size)
+    w_array = w_Array.as_class_get_shadow(space).new(size)
     for i in range(size):
-        w_array.store(i, objtable.w_nil)
-        w_methoddict.store(constants.METHODDICT_NAMES_INDEX+i, objtable.w_nil)
-    w_tally = utility.wrap_int(len(methods))
+        w_array.store(i, space.w_nil)
+        w_methoddict.store(constants.METHODDICT_NAMES_INDEX+i, space.w_nil)
+    w_tally = space.wrap_int(len(methods))
     w_methoddict.store(constants.METHODDICT_TALLY_INDEX, w_tally)
     w_methoddict.store(constants.METHODDICT_VALUES_INDEX, w_array)
     positions = range(size)
     random.shuffle(positions)
     for selector, w_compiledmethod in methods.items():
         pos = positions.pop()
-        w_selector = utility.wrap_string(selector)
+        w_selector = space.wrap_string(selector)
         w_methoddict.store(constants.METHODDICT_NAMES_INDEX+pos, w_selector)
         w_array.store(pos, w_compiledmethod)
     return w_methoddict
@@ -37,19 +39,19 @@
     w_class = model.W_PointersObject(w_classofclass, size)
     w_class.store(constants.CLASS_SUPERCLASS_INDEX, w_superclass)
     w_class.store(constants.CLASS_METHODDICT_INDEX, w_methoddict)
-    w_class.store(constants.CLASS_FORMAT_INDEX, utility.wrap_int(format))
+    w_class.store(constants.CLASS_FORMAT_INDEX, space.wrap_int(format))
     if name is not None:
-        w_class.store(constants.CLASS_NAME_INDEX, utility.wrap_string(name))
+        w_class.store(constants.CLASS_NAME_INDEX, space.wrap_string(name))
     return w_class
 
 def basicshape(name, format, kind, varsized, instsize):
     w_class = build_smalltalk_class(name, format)
-    classshadow = w_class.as_class_get_shadow()
+    classshadow = w_class.as_class_get_shadow(space)
     assert classshadow.instance_kind == kind
     assert classshadow.isvariable() == varsized
     assert classshadow.instsize() == instsize
     assert classshadow.name == name
-    assert classshadow.s_superclass() is w_Object.as_class_get_shadow()
+    assert classshadow.s_superclass() is w_Object.as_class_get_shadow(space)
 
 def test_basic_shape():
     yield basicshape, "Empty",        0x02,    shadow.POINTERS, False, 0
@@ -66,7 +68,7 @@
     methods = {'foo': model.W_CompiledMethod(0),
                'bar': model.W_CompiledMethod(0)}
     w_class = build_smalltalk_class("Demo", 0x90, methods=methods)
-    classshadow = w_class.as_class_get_shadow()
+    classshadow = w_class.as_class_get_shadow(space)
     assert classshadow.s_methoddict().methoddict == methods
 
 def method(tempsize=3,argsize=2, bytes="abcde"):
@@ -77,12 +79,12 @@
     w_m.literalsize = 2
     return w_m
 
-def methodcontext(w_sender=objtable.w_nil, pc=1, stackpointer=0, stacksize=5,
+def methodcontext(w_sender=space.w_nil, pc=1, stackpointer=0, stacksize=5,
                   method=method()):
-    w_object = model.W_PointersObject(classtable.w_MethodContext, constants.MTHDCTX_TEMP_FRAME_START+method.tempsize+stacksize)
+    w_object = model.W_PointersObject(space.w_MethodContext, constants.MTHDCTX_TEMP_FRAME_START+method.tempsize+stacksize)
     w_object.store(constants.CTXPART_SENDER_INDEX, w_sender)
-    w_object.store(constants.CTXPART_PC_INDEX, utility.wrap_int(pc))
-    w_object.store(constants.CTXPART_STACKP_INDEX, utility.wrap_int(method.tempsize+stackpointer))
+    w_object.store(constants.CTXPART_PC_INDEX, space.wrap_int(pc))
+    w_object.store(constants.CTXPART_STACKP_INDEX, space.wrap_int(method.tempsize+stackpointer))
     w_object.store(constants.MTHDCTX_METHOD, method)
     # XXX
     w_object.store(constants.MTHDCTX_RECEIVER_MAP, '???')
@@ -91,14 +93,14 @@
     w_object.store(constants.MTHDCTX_TEMP_FRAME_START, 'el')
     return w_object
 
-def blockcontext(w_sender=objtable.w_nil, pc=1, stackpointer=1, stacksize=5,
+def blockcontext(w_sender=space.w_nil, pc=1, stackpointer=1, stacksize=5,
                   home=methodcontext()):
-    w_object = model.W_PointersObject(classtable.w_MethodContext, constants.MTHDCTX_TEMP_FRAME_START+stacksize)
+    w_object = model.W_PointersObject(space.w_MethodContext, constants.MTHDCTX_TEMP_FRAME_START+stacksize)
     w_object.store(constants.CTXPART_SENDER_INDEX, w_sender)
-    w_object.store(constants.CTXPART_PC_INDEX, utility.wrap_int(pc))
-    w_object.store(constants.CTXPART_STACKP_INDEX, utility.wrap_int(stackpointer))
-    w_object.store(constants.BLKCTX_BLOCK_ARGUMENT_COUNT_INDEX, utility.wrap_int(54))
-    w_object.store(constants.BLKCTX_INITIAL_IP_INDEX, utility.wrap_int(17))
+    w_object.store(constants.CTXPART_PC_INDEX, space.wrap_int(pc))
+    w_object.store(constants.CTXPART_STACKP_INDEX, space.wrap_int(stackpointer))
+    w_object.store(constants.BLKCTX_BLOCK_ARGUMENT_COUNT_INDEX, space.wrap_int(54))
+    w_object.store(constants.BLKCTX_INITIAL_IP_INDEX, space.wrap_int(17))
     w_object.store(constants.BLKCTX_HOME_INDEX, home)
     w_object.store(constants.BLKCTX_STACK_START, 'el')
     return w_object
@@ -107,9 +109,9 @@
     w_m = method()
     w_object = methodcontext(stackpointer=3, method=w_m)
     w_object2 = methodcontext(w_sender=w_object)
-    s_object = w_object.as_methodcontext_get_shadow()
+    s_object = w_object.as_methodcontext_get_shadow(space)
     assert len(s_object.stack()) == 3
-    s_object2 = w_object2.as_methodcontext_get_shadow()
+    s_object2 = w_object2.as_methodcontext_get_shadow(space)
     assert w_object2.fetch(constants.CTXPART_SENDER_INDEX) == w_object
     assert s_object.w_self() == w_object
     assert s_object2.w_self() == w_object2
@@ -139,7 +141,7 @@
     w_m = method()
                               # Point over 2 literals of size 4
     w_object = methodcontext(pc=13,method=w_m)
-    s_object = w_object.as_methodcontext_get_shadow()
+    s_object = w_object.as_methodcontext_get_shadow(space)
     assert s_object.getbytecode() == 97
     assert s_object.getbytecode() == 98
     assert s_object.getbytecode() == 99
@@ -151,7 +153,7 @@
     w_m = method()
     w_object = methodcontext(pc=13, method=w_m)
     old_vars = w_object._vars
-    s_object = w_object.as_methodcontext_get_shadow()
+    s_object = w_object.as_methodcontext_get_shadow(space)
     assert w_object._vars is None
     s_object.detach_shadow()
     assert w_object._vars == old_vars
@@ -160,7 +162,7 @@
 def test_attach_detach_bc():
     w_object = blockcontext(pc=13)
     old_vars = w_object._vars
-    s_object = w_object.as_blockcontext_get_shadow()
+    s_object = w_object.as_blockcontext_get_shadow(space)
     assert w_object._vars is None
     s_object.detach_shadow()
     assert w_object._vars == old_vars
@@ -169,12 +171,12 @@
 def test_replace_to_bc():
     w_object = blockcontext(pc=13)
     old_vars = w_object._vars
-    s_object = w_object.as_blockcontext_get_shadow()
+    s_object = w_object.as_blockcontext_get_shadow(space)
     s_object.detach_shadow()
-    s_classshadow = shadow.ClassShadow(w_object)
+    s_classshadow = shadow.ClassShadow(space, w_object)
     w_object._shadow = s_classshadow
     s_classshadow.invalid = False
-    s_newobject = w_object.as_blockcontext_get_shadow()
+    s_newobject = w_object.as_blockcontext_get_shadow(space)
     assert s_classshadow.invalid
     assert ([s_newobject.fetch(i) for i in range(s_newobject.size())] ==
             [s_object.fetch(i) for i in range(s_newobject.size())])

Modified: pypy/branch/smalltalk-shadow-changes/pypy/lang/smalltalk/test/test_squeakimage.py
==============================================================================
--- pypy/branch/smalltalk-shadow-changes/pypy/lang/smalltalk/test/test_squeakimage.py	(original)
+++ pypy/branch/smalltalk-shadow-changes/pypy/lang/smalltalk/test/test_squeakimage.py	Sun May 25 16:09:07 2008
@@ -1,6 +1,9 @@
 import py
 from pypy.lang.smalltalk import squeakimage
 from pypy.lang.smalltalk.squeakimage import chrs2int
+from pypy.lang.smalltalk import space as objspace
+
+space = objspace.ObjSpace()
 
 # ----- helpers ----------------------------------------------
 
@@ -19,7 +22,7 @@
     import StringIO
     f = StringIO.StringIO(string)
     stream = squeakimage.Stream(f)
-    return squeakimage.ImageReader(stream)
+    return squeakimage.ImageReader(space, stream)
 
 
 # ----- tests ------------------------------------------------
@@ -91,31 +94,31 @@
 def test_1wordobjectheader():
     s = ints2str(joinbits([3, 1, 2, 3, 4], [2,6,4,5,12]))
     r = imagereader_mock(s)
-    assert (squeakimage.ImageChunk(1, 2, 3, 4), 0) == r.read_1wordobjectheader()
+    assert (squeakimage.ImageChunk(space, 1, 2, 3, 4), 0) == r.read_1wordobjectheader()
 
 def test_1wordobjectheader2():
     s = ints2str(joinbits([3, 1, 2, 3, 4], [2,6,4,5,12]))
     r = imagereader_mock(s * 3)
-    assert (squeakimage.ImageChunk(1, 2, 3, 4), 0) == r.read_1wordobjectheader()
-    assert (squeakimage.ImageChunk(1, 2, 3, 4), 4) == r.read_1wordobjectheader()
-    assert (squeakimage.ImageChunk(1, 2, 3, 4), 8) == r.read_1wordobjectheader()
+    assert (squeakimage.ImageChunk(space, 1, 2, 3, 4), 0) == r.read_1wordobjectheader()
+    assert (squeakimage.ImageChunk(space, 1, 2, 3, 4), 4) == r.read_1wordobjectheader()
+    assert (squeakimage.ImageChunk(space, 1, 2, 3, 4), 8) == r.read_1wordobjectheader()
 
 def test_2wordobjectheader():
     s = ints2str(4200 + 1, joinbits([1, 1, 2, 3, 4], [2,6,4,5,12]))
     r = imagereader_mock(s)
-    assert (squeakimage.ImageChunk(1, 2, 4200, 4), 4) == r.read_2wordobjectheader()
+    assert (squeakimage.ImageChunk(space, 1, 2, 4200, 4), 4) == r.read_2wordobjectheader()
 
 def test_3wordobjectheader():
     s = ints2str(1701 << 2, 4200 + 0, joinbits([0, 1, 2, 3, 4], [2,6,4,5,12]))
     r = imagereader_mock(s)
-    assert (squeakimage.ImageChunk(1701, 2, 4200, 4), 8) == r.read_3wordobjectheader()
+    assert (squeakimage.ImageChunk(space, 1701, 2, 4200, 4), 8) == r.read_3wordobjectheader()
     
 def test_read3wordheaderobject():
     size = 42
     s = ints2str(size << 2, 4200 + 0, joinbits([0, 1, 2, 3, 4], [2,6,4,5,12]))
     r = imagereader_mock(s + '\x00\x00\x19\x66' * (size - 1))
     chunk, pos = r.read_object()
-    chunk0 = squeakimage.ImageChunk(size, 2, 4200, 4)
+    chunk0 = squeakimage.ImageChunk(space, size, 2, 4200, 4)
     chunk0.data = [6502] * (size - 1)
     assert pos == 8
     assert chunk0 == chunk

Modified: pypy/branch/smalltalk-shadow-changes/pypy/lang/smalltalk/test/test_wrapper.py
==============================================================================
--- pypy/branch/smalltalk-shadow-changes/pypy/lang/smalltalk/test/test_wrapper.py	(original)
+++ pypy/branch/smalltalk-shadow-changes/pypy/lang/smalltalk/test/test_wrapper.py	Sun May 25 16:09:07 2008
@@ -1,13 +1,15 @@
 import py
 from pypy.lang.smalltalk import wrapper
 from pypy.lang.smalltalk import model
-from pypy.lang.smalltalk import objtable, utility
 from pypy.lang.smalltalk import interpreter
 from pypy.lang.smalltalk.error import WrapperException, FatalError
+from pypy.lang.smalltalk import space as objspace
+
+space = objspace.ObjSpace()
 
 def test_simpleread():
     w_o = model.W_PointersObject(None, 2)
-    w = wrapper.Wrapper(w_o)
+    w = wrapper.Wrapper(space, w_o)
     w_o._vars[0] = "hello"
     assert w.read(0) == "hello"
     w.write(1, "b")
@@ -17,7 +19,7 @@
 
 def test_accessor_generators():
     w_o = model.W_PointersObject(None, 1)
-    w = wrapper.LinkWrapper(w_o)
+    w = wrapper.LinkWrapper(space, w_o)
     w_o._vars[0] = "hello"
     assert w.next_link() == "hello"
     w.store_next_link("boe")
@@ -25,18 +27,18 @@
 
 def link(w_next='foo'):
     w_object = model.W_PointersObject(None, 1)
-    wrapper.LinkWrapper(w_object).store_next_link(w_next)
+    wrapper.LinkWrapper(space, w_object).store_next_link(w_next)
     return w_object
 
 def test_linked_list():
     w_object = model.W_PointersObject(None,2)
-    w_last = link(objtable.w_nil)
+    w_last = link(space.w_nil)
     w_lb1 = link(w_last)
     w_lb2 = link(w_lb1)
     w_lb3 = link(w_lb2)
     w_lb4 = link(w_lb3)
     w_first = link(w_lb4)
-    linkedlist = wrapper.LinkedListWrapper(w_object)
+    linkedlist = wrapper.LinkedListWrapper(space, w_object)
     linkedlist.store_first_link(w_first)
     linkedlist.store_last_link(w_last)
     assert w_first is linkedlist.first_link()
@@ -55,21 +57,21 @@
     linkedlist.add_last_link(w_last)
     assert linkedlist.first_link() is w_first
     assert linkedlist.last_link() is w_last
-    py.test.raises(WrapperException, linkedlist.remove, objtable.w_nil)
+    py.test.raises(WrapperException, linkedlist.remove, space.w_nil)
     linkedlist.remove(w_first)
     assert linkedlist.first_link() is w_last
     linkedlist.store_first_link(w_first)
-    wrapper.LinkWrapper(w_first).store_next_link(w_last)
+    wrapper.LinkWrapper(space, w_first).store_next_link(w_last)
     linkedlist.remove(w_last)
     assert linkedlist.last_link() is w_first
 
-def new_process(w_next=objtable.w_nil,
-                w_my_list=objtable.w_nil,
-                w_suspended_context=objtable.w_nil,
+def new_process(w_next=space.w_nil,
+                w_my_list=space.w_nil,
+                w_suspended_context=space.w_nil,
                 priority=0):
-    w_priority = utility.wrap_int(priority)
+    w_priority = space.wrap_int(priority)
     w_process = model.W_PointersObject(None, 4)
-    process = wrapper.ProcessWrapper(w_process)
+    process = wrapper.ProcessWrapper(space, w_process)
     process.store_next_link(w_next)
     process.store_my_list(w_my_list)
     process.store_suspended_context(w_suspended_context)
@@ -78,13 +80,13 @@
 
 def new_processlist(processes_w=[]):
     w_processlist = model.W_PointersObject(None, 2)
-    w_first = objtable.w_nil
-    w_last = objtable.w_nil
+    w_first = space.w_nil
+    w_last = space.w_nil
     for w_process in processes_w[::-1]:
         w_first = newprocess(w_first, w_processlist).w_self
-        if w_last is objtable.w_nil:
+        if w_last is space.w_nil:
             w_last = w_first
-    pl = wrapper.ProcessListWrapper(w_processlist)
+    pl = wrapper.ProcessListWrapper(space, w_processlist)
     pl.store_first_link(w_first)
     pl.store_last_link(w_last)
     return pl
@@ -96,31 +98,31 @@
         maxpriority = 5
         prioritydict = {}
     w_prioritylist = model.W_PointersObject(None, maxpriority)
-    prioritylist = wrapper.Wrapper(w_prioritylist)
+    prioritylist = wrapper.Wrapper(space, w_prioritylist)
     for i in range(maxpriority):
         prioritylist.write(i, new_processlist(prioritydict.get(i, [])).w_self)
     
     return prioritylist
 
-def new_scheduler(w_process=objtable.w_nil, prioritydict=None):
+def new_scheduler(w_process=space.w_nil, prioritydict=None):
     priority_list = new_prioritylist(prioritydict)
     w_scheduler = model.W_PointersObject(None, 2)
-    scheduler = wrapper.SchedulerWrapper(w_scheduler)
+    scheduler = wrapper.SchedulerWrapper(space, w_scheduler)
     scheduler.store_active_process(w_process)
     scheduler.write(0, priority_list.w_self)
     return scheduler
 
 def new_semaphore(excess_signals=0):
     w_semaphore = model.W_PointersObject(None, 3)
-    semaphore = wrapper.SemaphoreWrapper(w_semaphore)
-    semaphore.store_excess_signals(utility.wrap_int(excess_signals))
+    semaphore = wrapper.SemaphoreWrapper(space, w_semaphore)
+    semaphore.store_excess_signals(space.wrap_int(excess_signals))
     return semaphore
 
         
 class TestScheduler(object):
     def setup_method(self, meth):
         self.old_scheduler = wrapper.scheduler
-        wrapper.scheduler = lambda: scheduler
+        wrapper.scheduler = lambda space: scheduler
         scheduler = new_scheduler()
 
     def teardown_method(self, meth):
@@ -129,33 +131,33 @@
     def test_put_to_sleep(self):
         process = new_process(priority=2)
         process.put_to_sleep()
-        process_list = wrapper.scheduler().get_process_list(2)
+        process_list = wrapper.scheduler(space).get_process_list(2)
         assert process_list.first_link() is process_list.last_link()
         assert process_list.first_link() is process.w_self
 
     def test_suspend_asleep(self):
-        interp, process, old_process = self.make_processes(4, 2, objtable.w_false, objtable.w_true)
+        interp, process, old_process = self.make_processes(4, 2, space.w_false, space.w_true)
         process.suspend(interp)
-        process_list = wrapper.scheduler().get_process_list(process.priority())
+        process_list = wrapper.scheduler(space).get_process_list(process.priority())
         assert process_list.first_link() is process_list.last_link()
-        assert process_list.first_link() is objtable.w_nil
-        assert process.my_list() is objtable.w_nil
+        assert process_list.first_link() is space.w_nil
+        assert process.my_list() is space.w_nil
 
     def test_suspend_active(self):
-        interp, process, old_process = self.make_processes(4, 2, objtable.w_false, objtable.w_true)
+        interp, process, old_process = self.make_processes(4, 2, space.w_false, space.w_true)
         old_process.suspend(interp)
-        process_list = wrapper.scheduler().get_process_list(old_process.priority())
+        process_list = wrapper.scheduler(space).get_process_list(old_process.priority())
         assert process_list.first_link() is process_list.last_link()
-        assert process_list.first_link() is objtable.w_nil
-        assert old_process.my_list() is objtable.w_nil
-        assert wrapper.scheduler().active_process() is process.w_self
+        assert process_list.first_link() is space.w_nil
+        assert old_process.my_list() is space.w_nil
+        assert wrapper.scheduler(space).active_process() is process.w_self
 
     def new_process_consistency(self, process, old_process, interp,
                                     old_active_context, new_active_context):
-        scheduler = wrapper.scheduler()
+        scheduler = wrapper.scheduler(space)
         assert interp.w_active_context() is new_active_context
         assert scheduler.active_process() is process.w_self
-        priority_list = wrapper.scheduler().get_process_list(process.priority())
+        priority_list = wrapper.scheduler(space).get_process_list(process.priority())
         assert priority_list.first_link() is priority_list.last_link()
         # activate does not remove the process from the process_list.
         # The caller of activate is responsible
@@ -163,13 +165,13 @@
 
     def old_process_consistency(self, old_process, old_process_context):
         assert old_process.suspended_context() is old_process_context
-        priority_list = wrapper.scheduler().get_process_list(old_process.priority())
+        priority_list = wrapper.scheduler(space).get_process_list(old_process.priority())
         assert priority_list.first_link() is old_process.w_self
 
     def make_processes(self, sleepingpriority, runningpriority,
                              sleepingcontext, runningcontext):
-        interp = interpreter.Interpreter()
-        scheduler = wrapper.scheduler()
+        interp = interpreter.Interpreter(space)
+        scheduler = wrapper.scheduler(space)
         sleeping = new_process(priority=sleepingpriority,
                                w_suspended_context=sleepingcontext)
         sleeping.put_to_sleep()
@@ -181,79 +183,79 @@
 
 
     def test_activate(self):
-        interp, process, old_process = self.make_processes(4, 2, objtable.w_false, objtable.w_true)
+        interp, process, old_process = self.make_processes(4, 2, space.w_false, space.w_true)
         process.activate(interp)
         self.new_process_consistency(process, old_process, interp,
-                                         objtable.w_true, objtable.w_false)
+                                         space.w_true, space.w_false)
        
     def test_resume(self):
-        interp, process, old_process = self.make_processes(4, 2, objtable.w_false, objtable.w_true)
+        interp, process, old_process = self.make_processes(4, 2, space.w_false, space.w_true)
         process.resume(interp)
         self.new_process_consistency(process, old_process, interp,
-                                         objtable.w_true, objtable.w_false)
-        self.old_process_consistency(old_process, objtable.w_true)
+                                         space.w_true, space.w_false)
+        self.old_process_consistency(old_process, space.w_true)
 
         # Does not reactivate old_process because lower priority
         old_process.resume(interp)
         self.new_process_consistency(process, old_process, interp,
-                                         objtable.w_true, objtable.w_false)
-        self.old_process_consistency(old_process, objtable.w_true)
+                                         space.w_true, space.w_false)
+        self.old_process_consistency(old_process, space.w_true)
 
     def test_semaphore_excess_signal(self):
         semaphore = new_semaphore()
         
         semaphore.signal(None)
-        assert utility.unwrap_int(semaphore.excess_signals()) == 1
+        assert space.unwrap_int(semaphore.excess_signals()) == 1
 
     def test_highest_priority(self):
-        py.test.raises(FatalError, wrapper.scheduler().highest_priority_process)
-        interp, process, old_process = self.make_processes(4, 2, objtable.w_false, objtable.w_true)
+        py.test.raises(FatalError, wrapper.scheduler(space).highest_priority_process)
+        interp, process, old_process = self.make_processes(4, 2, space.w_false, space.w_true)
         process.put_to_sleep()
         old_process.put_to_sleep()
-        highest = wrapper.scheduler().highest_priority_process()
+        highest = wrapper.scheduler(space).highest_priority_process()
         assert highest is process.w_self
-        highest = wrapper.scheduler().highest_priority_process()
+        highest = wrapper.scheduler(space).highest_priority_process()
         assert highest is old_process.w_self
-        py.test.raises(FatalError, wrapper.scheduler().highest_priority_process)
+        py.test.raises(FatalError, wrapper.scheduler(space).highest_priority_process)
 
     def test_semaphore_wait(self):
         semaphore = new_semaphore()
-        interp, process, old_process = self.make_processes(4, 2, objtable.w_false, objtable.w_true)
+        interp, process, old_process = self.make_processes(4, 2, space.w_false, space.w_true)
         semaphore.wait(interp)
         assert semaphore.first_link() is old_process.w_self
-        assert wrapper.scheduler().active_process() is process.w_self
+        assert wrapper.scheduler(space).active_process() is process.w_self
 
     def test_semaphore_signal_wait(self):
         semaphore = new_semaphore()
         semaphore.signal(None)
-        interp, process, old_process = self.make_processes(4, 2, objtable.w_false, objtable.w_true)
+        interp, process, old_process = self.make_processes(4, 2, space.w_false, space.w_true)
         semaphore.wait(interp)
         assert semaphore.is_empty_list()
-        assert wrapper.scheduler().active_process() is old_process.w_self
+        assert wrapper.scheduler(space).active_process() is old_process.w_self
         semaphore.wait(interp)
         assert semaphore.first_link() is old_process.w_self
-        assert wrapper.scheduler().active_process() is process.w_self
+        assert wrapper.scheduler(space).active_process() is process.w_self
 
         py.test.raises(FatalError, semaphore.wait, interp)
 
     def test_semaphore_wait_signal(self):
         semaphore = new_semaphore()
-        interp, process, old_process = self.make_processes(4, 2, objtable.w_false, objtable.w_true)
+        interp, process, old_process = self.make_processes(4, 2, space.w_false, space.w_true)
 
         semaphore.wait(interp)
-        assert wrapper.scheduler().active_process() is process.w_self
+        assert wrapper.scheduler(space).active_process() is process.w_self
         semaphore.signal(interp)
-        assert wrapper.scheduler().active_process() is process.w_self
-        process_list = wrapper.scheduler().get_process_list(old_process.priority())
+        assert wrapper.scheduler(space).active_process() is process.w_self
+        process_list = wrapper.scheduler(space).get_process_list(old_process.priority())
         assert process_list.remove_first_link_of_list() is old_process.w_self
 
-        process.write(2, utility.wrap_int(1))        
+        process.write(2, space.wrap_int(1))        
         old_process.resume(interp)
-        assert wrapper.scheduler().active_process() is old_process.w_self        
+        assert wrapper.scheduler(space).active_process() is old_process.w_self        
         semaphore.wait(interp)
-        assert wrapper.scheduler().active_process() is process.w_self
+        assert wrapper.scheduler(space).active_process() is process.w_self
         semaphore.signal(interp)
-        assert wrapper.scheduler().active_process() is old_process.w_self        
+        assert wrapper.scheduler(space).active_process() is old_process.w_self        
 
-        process_list = wrapper.scheduler().get_process_list(process.priority())
+        process_list = wrapper.scheduler(space).get_process_list(process.priority())
         assert process_list.first_link() is process.w_self

Modified: pypy/branch/smalltalk-shadow-changes/pypy/lang/smalltalk/wrapper.py
==============================================================================
--- pypy/branch/smalltalk-shadow-changes/pypy/lang/smalltalk/wrapper.py	(original)
+++ pypy/branch/smalltalk-shadow-changes/pypy/lang/smalltalk/wrapper.py	Sun May 25 16:09:07 2008
@@ -1,12 +1,12 @@
 from pypy.lang.smalltalk import model
-from pypy.lang.smalltalk import utility, objtable
 from pypy.lang.smalltalk.error import FatalError, WrapperException
 
 class Wrapper(object):
-    def __init__(self, w_self):
+    def __init__(self, space, w_self):
         if not isinstance(w_self, model.W_PointersObject):
             raise WrapperException("Unexpected instance given to wrapper")
         self.w_self = w_self
+        self.space = space
 
     def read(self, index0):
         try:
@@ -42,29 +42,28 @@
 
     def priority(self):
         w_priority = self.read(2)
-        return utility.unwrap_int(w_priority)
+        return self.space.unwrap_int(w_priority)
 
     def put_to_sleep(self):
-        sched = scheduler()
+        sched = scheduler(self.space)
         priority = self.priority()
         process_list = sched.get_process_list(priority)
         process_list.add_process(self.w_self)
 
     def activate(self, interp):
-        from pypy.lang.smalltalk import objtable
-        sched = scheduler()
+        sched = scheduler(self.space)
         sched.store_active_process(self.w_self)
         interp.store_w_active_context(self.suspended_context())
-        self.store_suspended_context(objtable.w_nil)
-        self.store_my_list(objtable.w_nil)
+        self.store_suspended_context(interp.space.w_nil)
+        self.store_my_list(interp.space.w_nil)
 
     def deactivate(self, interp):
         self.put_to_sleep()
         self.store_suspended_context(interp.w_active_context())
 
     def resume(self, interp):
-        sched = scheduler()
-        active_process = ProcessWrapper(sched.active_process())
+        sched = scheduler(self.space)
+        active_process = ProcessWrapper(self.space, sched.active_process())
         active_priority = active_process.priority()
         priority = self.priority()
         if priority > active_priority:
@@ -74,43 +73,42 @@
             self.put_to_sleep()
 
     def is_active_process(self):
-        return self.w_self.is_same_object(scheduler().active_process())
+        return self.w_self.is_same_object(scheduler(self.space).active_process())
 
     def suspend(self, interp):
         if self.is_active_process():
-            assert self.my_list() is objtable.w_nil
-            ProcessWrapper(scheduler().highest_priority_process()).activate(interp)
+            assert self.my_list() is interp.space.w_nil
+            w_process = scheduler(self.space).highest_priority_process()
+            process = ProcessWrapper(self.space, w_process).activate(interp)
         else:
-            process_list = ProcessListWrapper(self.my_list())
+            process_list = ProcessListWrapper(self.space, self.my_list())
             process_list.remove(self.w_self)
-            self.store_my_list(objtable.w_nil)
+            self.store_my_list(interp.space.w_nil)
 
 class LinkedListWrapper(Wrapper):
     first_link, store_first_link = make_getter_setter(0)
     last_link, store_last_link = make_getter_setter(1)
 
     def is_empty_list(self):
-        from pypy.lang.smalltalk import objtable
-        return self.first_link() is objtable.w_nil
+        return self.first_link() is self.space.w_nil
 
     def add_last_link(self, w_object):
         if self.is_empty_list():
             self.store_first_link(w_object)
         else:
-            LinkWrapper(self.last_link()).store_next_link(w_object)
+            LinkWrapper(self.space, self.last_link()).store_next_link(w_object)
         self.store_last_link(w_object)
 
     def remove_first_link_of_list(self):
-        from pypy.lang.smalltalk import objtable
         w_first = self.first_link()
         w_last = self.last_link()
         if w_first.is_same_object(w_last):
-            self.store_first_link(objtable.w_nil)
-            self.store_last_link(objtable.w_nil)
+            self.store_first_link(self.space.w_nil)
+            self.store_last_link(self.space.w_nil)
         else:
-            w_next = LinkWrapper(w_first).next_link()
+            w_next = LinkWrapper(self.space, w_first).next_link()
             self.store_first_link(w_next)
-        LinkWrapper(w_first).store_next_link(objtable.w_nil)
+        LinkWrapper(self.space, w_first).store_next_link(self.space.w_nil)
         return w_first
 
     def remove(self, w_link):
@@ -118,24 +116,24 @@
             self.remove_first_link_of_list()
             return
         else:
-            current = LinkWrapper(self.first_link())
+            current = LinkWrapper(self.space, self.first_link())
             w_next = current.next_link()
-            while not w_next.is_same_object(objtable.w_nil):
+            while not w_next.is_same_object(self.space.w_nil):
                 if w_next.is_same_object(w_link):
-                    LinkWrapper(w_link).store_next_link(objtable.w_nil)
-                    w_tail = LinkWrapper(w_next).next_link()
+                    LinkWrapper(self.space, w_link).store_next_link(self.space.w_nil)
+                    w_tail = LinkWrapper(self.space, w_next).next_link()
                     current.store_next_link(w_tail)
-                    if w_tail.is_same_object(objtable.w_nil):
+                    if w_tail.is_same_object(self.space.w_nil):
                         self.store_last_link(current.w_self)
                     return
-                current = LinkWrapper(w_next)
+                current = LinkWrapper(self.space, w_next)
                 w_next = current.next_link()
         raise WrapperException("Could not find link")
 
 class ProcessListWrapper(LinkedListWrapper):
     def add_process(self, w_process):
         self.add_last_link(w_process)
-        ProcessWrapper(w_process).store_my_list(self.w_self)
+        ProcessWrapper(self.space, w_process).store_my_list(self.w_self)
 
 class AssociationWrapper(Wrapper):
     key = make_getter(0)
@@ -146,28 +144,28 @@
     active_process, store_active_process = make_getter_setter(1)
     
     def get_process_list(self, priority):
-        lists = self.priority_list()
-        return ProcessListWrapper(Wrapper(lists).read(priority))
+        lists = Wrapper(self.space, self.priority_list())
+
+        return ProcessListWrapper(self.space, lists.read(priority))
 
     def highest_priority_process(self):
         w_lists = self.priority_list()
         # Asserts as W_PointersObject
-        lists = Wrapper(w_lists)
+        lists = Wrapper(self.space, w_lists)
         
         for i in range(w_lists.size() - 1, -1, -1):
-            process_list = ProcessListWrapper(lists.read(i))
+            process_list = ProcessListWrapper(self.space, lists.read(i))
             if not process_list.is_empty_list():
                 return process_list.remove_first_link_of_list()
 
         raise FatalError("Scheduler could not find a runnable process")
 
-def scheduler():
-    from pypy.lang.smalltalk import objtable
-    w_association = objtable.get_objtable()["w_schedulerassociationpointer"]
+def scheduler(space):
+    w_association = space.objtable["w_schedulerassociationpointer"]
     assert w_association is not None
-    w_scheduler = AssociationWrapper(w_association).value()
+    w_scheduler = AssociationWrapper(space, w_association).value()
     assert isinstance(w_scheduler, model.W_PointersObject)
-    return SchedulerWrapper(w_scheduler)
+    return SchedulerWrapper(space, w_scheduler)
 
 class SemaphoreWrapper(LinkedListWrapper):
 
@@ -176,17 +174,18 @@
     def signal(self, interp):
         if self.is_empty_list():
             w_value = self.excess_signals()
-            w_value = utility.wrap_int(utility.unwrap_int(w_value) + 1)
+            w_value = self.space.wrap_int(self.space.unwrap_int(w_value) + 1)
             self.store_excess_signals(w_value)
         else:
-            ProcessWrapper(self.remove_first_link_of_list()).resume(interp)
+            process = self.remove_first_link_of_list()
+            ProcessWrapper(self.space, process).resume(interp)
 
     def wait(self, interp):
-        excess = utility.unwrap_int(self.excess_signals())
-        w_process = scheduler().active_process()
+        excess = self.space.unwrap_int(self.excess_signals())
+        w_process = scheduler(interp.space).active_process()
         if excess > 0:
-            w_excess = utility.wrap_int(excess - 1)
+            w_excess = self.space.wrap_int(excess - 1)
             self.store_excess_signals(w_excess)
         else:
             self.add_last_link(w_process)
-            ProcessWrapper(w_process).suspend(interp)
+            ProcessWrapper(self.space, w_process).suspend(interp)



More information about the Pypy-commit mailing list