[pypy-svn] r47912 - in pypy/dist/pypy/lang/smalltalk: . test
arigo at codespeak.net
arigo at codespeak.net
Thu Oct 25 13:38:20 CEST 2007
Author: arigo
Date: Thu Oct 25 13:38:20 2007
New Revision: 47912
Added:
pypy/dist/pypy/lang/smalltalk/shadow.py
- copied, changed from r47897, pypy/dist/pypy/lang/smalltalk/mirror.py
Removed:
pypy/dist/pypy/lang/smalltalk/mirror.py
Modified:
pypy/dist/pypy/lang/smalltalk/classtable.py
pypy/dist/pypy/lang/smalltalk/interpreter.py
pypy/dist/pypy/lang/smalltalk/model.py
pypy/dist/pypy/lang/smalltalk/objtable.py
pypy/dist/pypy/lang/smalltalk/primitives.py
pypy/dist/pypy/lang/smalltalk/squeakimage.py
pypy/dist/pypy/lang/smalltalk/test/test_classtable.py
pypy/dist/pypy/lang/smalltalk/test/test_interpreter.py
pypy/dist/pypy/lang/smalltalk/test/test_model.py
pypy/dist/pypy/lang/smalltalk/test/test_primitives.py
Log:
(cfbolz, arigo)
Rename the "mirror" to "shadow". Make it a bit more general.
Now we use it a bit more like a cache, and go via the w_class
in general instead of directly to the w_class' shadow.
Modified: pypy/dist/pypy/lang/smalltalk/classtable.py
==============================================================================
--- pypy/dist/pypy/lang/smalltalk/classtable.py (original)
+++ pypy/dist/pypy/lang/smalltalk/classtable.py Thu Oct 25 13:38:20 2007
@@ -1,92 +1,96 @@
-from pypy.lang.smalltalk import mirror
+from pypy.lang.smalltalk import shadow
-def bootstrap_classmirror(instsize, m_superclass=None, m_metaclass=None,
- name='?', format=mirror.POINTERS, varsized=False):
+def bootstrap_class(instsize, w_superclass=None, w_metaclass=None,
+ name='?', format=shadow.POINTERS, varsized=False):
from pypy.lang.smalltalk import model
- w_class = model.W_Object() # a dummy placeholder for testing
- m = mirror.ClassMirror(w_class)
- m.methoddict = {}
- m.m_superclass = m_superclass
- m.m_metaclass = m_metaclass
- m.name = name
- m.instance_size = instsize
- m.instance_kind = format
- m.instance_varsized = varsized or format != mirror.POINTERS
- m.invalid = False
- mirror.mirrorcache.cache[w_class] = m
- return m
+ w_class = model.W_PointersObject(None, 0) # a dummy placeholder for testing
+ s = shadow.ClassShadow(w_class)
+ s.methoddict = {}
+ if w_superclass is not None:
+ s.s_superclass = w_superclass.as_class_get_shadow()
+ if w_metaclass is not None:
+ s.s_metaclass = w_metaclass.as_class_get_shadow()
+ s.name = name
+ s.instance_size = instsize
+ s.instance_kind = format
+ s.instance_varsized = varsized or format != shadow.POINTERS
+ s.invalid = False
+ w_class._shadow = s
+ return w_class
# ___________________________________________________________________________
# Core Bootstrapping Objects
classtable = {}
def create_classtable():
- def define_core_cls(name, m_superclass, m_metaclass):
- assert name.startswith('m_')
- mirror = bootstrap_classmirror(instsize=0, # XXX
- m_superclass=m_superclass,
- m_metaclass=m_metaclass,
- name=name[2:])
- classtable[name] = mirror
- globals()[name] = mirror
- return mirror
+ def define_core_cls(name, w_superclass, w_metaclass):
+ assert name.startswith('w_')
+ shadow = bootstrap_class(instsize=0, # XXX
+ w_superclass=w_superclass,
+ w_metaclass=w_metaclass,
+ name=name[2:])
+ classtable[name] = shadow
+ globals()[name] = shadow
+ return shadow
# Class Name Super class name
cls_nm_tbl = [
- ["m_Object", "m_ProtoObject"],
- ["m_Behavior", "m_Object"],
- ["m_ClassDescription", "m_Behavior"],
- ["m_Class", "m_ClassDescription"],
- ["m_Metaclass", "m_ClassDescription"],
+ ["w_Object", "w_ProtoObject"],
+ ["w_Behavior", "w_Object"],
+ ["w_ClassDescription", "w_Behavior"],
+ ["w_Class", "w_ClassDescription"],
+ ["w_Metaclass", "w_ClassDescription"],
]
- define_core_cls("m_ProtoObjectClass", None, None)
- define_core_cls("m_ProtoObject", None, m_ProtoObjectClass)
+ define_core_cls("w_ProtoObjectClass", None, None)
+ 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"
- m_metacls = define_core_cls(meta_nm, classtable[meta_super_nm], None)
- define_core_cls(cls_nm, classtable[super_cls_nm], m_metacls)
- m_ProtoObjectClass.m_superclass = m_Class
- # at this point, all classes that still lack a m_metaclass are themselves
+ w_metacls = define_core_cls(meta_nm, classtable[meta_super_nm], None)
+ define_core_cls(cls_nm, classtable[super_cls_nm], w_metacls)
+ w_ProtoObjectClass.as_class_get_shadow().s_superclass = \
+ w_Class.as_class_get_shadow()
+ # at this point, all classes that still lack a w_metaclass are themselves
# metaclasses
- for nm, m_cls_obj in classtable.items():
- if m_cls_obj.m_metaclass is None:
- m_cls_obj.m_metaclass = m_Metaclass
+ for nm, w_cls_obj in classtable.items():
+ s = w_cls_obj.as_class_get_shadow()
+ if s.s_metaclass is None:
+ s.s_metaclass = w_Metaclass.as_class_get_shadow()
create_classtable()
# ___________________________________________________________________________
# Other classes
-def define_cls(cls_nm, supercls_nm, instvarsize=0, format=mirror.POINTERS):
- assert cls_nm.startswith("m_")
+def define_cls(cls_nm, supercls_nm, instvarsize=0, format=shadow.POINTERS):
+ assert cls_nm.startswith("w_")
meta_nm = cls_nm + "Class"
meta_super_nm = supercls_nm + "Class"
- m_meta_cls = globals()[meta_nm] = classtable[meta_nm] = \
- bootstrap_classmirror(0, # XXX
- classtable[meta_super_nm],
- m_Metaclass,
- name=meta_nm[2:])
- m_cls = globals()[cls_nm] = classtable[cls_nm] = \
- bootstrap_classmirror(instvarsize,
- classtable[supercls_nm],
- m_meta_cls,
- format=format,
- name=cls_nm[2:])
-
-define_cls("m_Magnitude", "m_Object")
-define_cls("m_Character", "m_Magnitude", instvarsize=1)
-define_cls("m_Number", "m_Magnitude")
-define_cls("m_Integer", "m_Number")
-define_cls("m_SmallInteger", "m_Integer")
-define_cls("m_Float", "m_Number", format=mirror.BYTES)
-define_cls("m_Collection", "m_Object")
-define_cls("m_SequencableCollection", "m_Collection")
-define_cls("m_ArrayedCollection", "m_SequencableCollection")
-define_cls("m_String", "m_ArrayedCollection")
-define_cls("m_ByteString", "m_String", format=mirror.BYTES)
-define_cls("m_UndefinedObject", "m_Object")
-define_cls("m_Boolean", "m_Object")
-define_cls("m_True", "m_Boolean")
-define_cls("m_False", "m_Boolean")
-define_cls("m_ByteArray", "m_ArrayedCollection", format=mirror.BYTES)
-define_cls("m_CompiledMethod", "m_ByteArray", format=mirror.COMPILED_METHOD)
+ w_meta_cls = globals()[meta_nm] = classtable[meta_nm] = \
+ bootstrap_class(0, # XXX
+ classtable[meta_super_nm],
+ w_Metaclass,
+ name=meta_nm[2:])
+ w_cls = globals()[cls_nm] = classtable[cls_nm] = \
+ bootstrap_class(instvarsize,
+ classtable[supercls_nm],
+ w_meta_cls,
+ format=format,
+ 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_SequencableCollection", "w_Collection")
+define_cls("w_ArrayedCollection", "w_SequencableCollection")
+define_cls("w_String", "w_ArrayedCollection")
+define_cls("w_ByteString", "w_String", 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_CompiledMethod", "w_ByteArray", format=shadow.COMPILED_METHOD)
Modified: pypy/dist/pypy/lang/smalltalk/interpreter.py
==============================================================================
--- pypy/dist/pypy/lang/smalltalk/interpreter.py (original)
+++ pypy/dist/pypy/lang/smalltalk/interpreter.py Thu Oct 25 13:38:20 2007
@@ -19,9 +19,9 @@
self.temps = arguments + [None] * method.tempsize
self.pc = 0
- def getclassmirror(self):
- from pypy.lang.smalltalk.classtable import m_MethodContext # XXX do me
- return m_MethodContext
+ def getclass(self):
+ from pypy.lang.smalltalk.classtable import w_MethodContext # XXX do me
+ return w_MethodContext
def gethash(self):
return 44 # XXX
@@ -126,15 +126,16 @@
def _sendSelfSelector(self, selector, argcount, interp):
receiver = self.peek(argcount)
self._sendSelector(selector, argcount, interp,
- receiver, receiver.getclassmirror())
+ receiver, receiver.shadow_of_my_class())
def _sendSuperSelector(self, selector, argcount, interp):
+ s_compiledin = self.method.w_compiledin.as_class_get_shadow()
self._sendSelector(selector, argcount, interp, self.receiver,
- self.method.m_compiledin.m_superclass)
+ s_compiledin.s_superclass)
def _sendSelector(self, selector, argcount, interp,
- receiver, m_receiverclass):
- method = m_receiverclass.lookup(selector)
+ receiver, receiverclassshadow):
+ method = receiverclassshadow.lookup(selector)
assert method
if method.primitive:
func = primitives.prim_table[method.primitive]
Modified: pypy/dist/pypy/lang/smalltalk/model.py
==============================================================================
--- pypy/dist/pypy/lang/smalltalk/model.py (original)
+++ pypy/dist/pypy/lang/smalltalk/model.py Thu Oct 25 13:38:20 2007
@@ -11,7 +11,7 @@
def size(self):
return 0
- def getclassmirror(self):
+ def getclass(self):
raise NotImplementedError
def gethash(self):
@@ -20,13 +20,16 @@
def invariant(self):
return True
+ def shadow_of_my_class(self):
+ return self.getclass().as_class_get_shadow()
+
class W_SmallInteger(W_Object):
def __init__(self, value):
self.value = value
- def getclassmirror(self):
- from pypy.lang.smalltalk.classtable import m_SmallInteger
- return m_SmallInteger
+ def getclass(self):
+ from pypy.lang.smalltalk.classtable import w_SmallInteger
+ return w_SmallInteger
def gethash(self):
return self.value
@@ -41,9 +44,9 @@
def __init__(self, value):
self.value = value
- def getclassmirror(self):
- from pypy.lang.smalltalk.classtable import m_Float
- return m_Float
+ def getclass(self):
+ from pypy.lang.smalltalk.classtable import w_Float
+ return w_Float
def gethash(self):
return XXX # check this
@@ -71,54 +74,64 @@
return isinstance(self.hash, int)
class W_AbstractObjectWithClassReference(W_AbstractObjectWithIdentityHash):
- """ The base class of objects that store 'm_class' explicitly. """
+ """ The base class of objects that store 'w_class' explicitly. """
- def __init__(self, m_class):
- self.m_class = m_class
+ def __init__(self, w_class):
+ if w_class is not None: # it's None only for testing
+ assert isinstance(w_class, W_PointersObject)
+ self.w_class = w_class
- def getclassmirror(self):
- return self.m_class
+ def getclass(self):
+ return self.w_class
def __str__(self):
- self.getclassmirror().check()
+ # XXX use the shadow of my class
if self.size() >= 9:
return ''.join(self.fetch(constants.CLASS_NAME_INDEX).bytes) + " class"
else:
return "a " + ''.join(self.getclass().fetch(constants.CLASS_NAME_INDEX).bytes)
-
- def getclass(self):
- self.getclassmirror().check()
- return self.getclassmirror().w_self
-
+
def invariant(self):
- from pypy.lang.smalltalk.mirror import ClassMirror
return (W_AbstractObjectWithIdentityHash.invariant(self) and
- isinstance(self.m_class, ClassMirror))
+ isinstance(self.w_class, W_PointersObject))
class W_PointersObject(W_AbstractObjectWithClassReference):
""" The normal object """
- def __init__(self, m_class, size):
- W_AbstractObjectWithClassReference.__init__(self, m_class)
- self.vars = [None] * size
+ def __init__(self, w_class, size):
+ W_AbstractObjectWithClassReference.__init__(self, w_class)
+ self._vars = [None] * size
+ self._shadow = None
def fetch(self, index):
- return self.vars[index]
+ return self._vars[index]
def store(self, index, w_value):
- self.vars[index] = w_value
+ if self._shadow is not None:
+ self._shadow.invalidate()
+ self._vars[index] = w_value
def size(self):
- return len(self.vars)
+ return len(self._vars)
def invariant(self):
return (W_AbstractObjectWithClassReference.invariant(self) and
- isinstance(self.vars, list))
+ isinstance(self._vars, list))
+
+ def as_class_get_shadow(self):
+ from pypy.lang.smalltalk.shadow import ClassShadow
+ shadow = self._shadow
+ if shadow is None:
+ self._shadow = shadow = ClassShadow(self)
+ assert isinstance(shadow, ClassShadow) # for now, the only kind
+ shadow.check_for_updates()
+ return shadow
def compiledmethodnamed(self, methodname):
- w_methoddict = self.fetch(constants.CLASS_METHODDICT_INDEX).vars
+ # XXX kill me. Temporary, for testing
+ w_methoddict = self.fetch(constants.CLASS_METHODDICT_INDEX)._vars
names = w_methoddict[constants.METHODDICT_NAMES_INDEX:]
- values = w_methoddict[constants.METHODDICT_VALUES_INDEX].vars
+ values = w_methoddict[constants.METHODDICT_VALUES_INDEX]._vars
for var in names:
if isinstance(var, W_BytesObject):
if str(var) == repr(methodname):
@@ -126,6 +139,7 @@
raise MethodNotFound
def lookup(self, methodname):
+ # XXX kill me. Temporary, for testing
in_class = self
while in_class != None:
try:
@@ -143,8 +157,8 @@
return self.lookup("doesNotUnderstand")
class W_BytesObject(W_AbstractObjectWithClassReference):
- def __init__(self, m_class, size):
- W_AbstractObjectWithClassReference.__init__(self, m_class)
+ def __init__(self, w_class, size):
+ W_AbstractObjectWithClassReference.__init__(self, w_class)
self.bytes = ['\x00'] * size
def getbyte(self, n):
@@ -168,8 +182,8 @@
return True
class W_WordsObject(W_AbstractObjectWithClassReference):
- def __init__(self, m_class, size):
- W_AbstractObjectWithClassReference.__init__(self, m_class)
+ def __init__(self, w_class, size):
+ W_AbstractObjectWithClassReference.__init__(self, w_class)
self.words = [0] * size
def getword(self, n):
@@ -208,18 +222,18 @@
The trailer has two variant formats. In the first variant, the last byte is at least 252 and the last four bytes represent a source pointer into one of the sources files (see #sourcePointer). In the second variant, the last byte is less than 252, and the last several bytes are a compressed version of the names of the method's temporary variables. The number of bytes used for this purpose is the value of the last byte in the method.
"""
def __init__(self, literalsize, bytes, argsize=0,
- tempsize=0, primitive=0, m_compiledin=None):
+ tempsize=0, primitive=0, w_compiledin=None):
# self.literals = [None] * size
self.literalsize = literalsize
- self.m_compiledin = m_compiledin
+ self.w_compiledin = w_compiledin
self.bytes = bytes
self.argsize = argsize
self.tempsize = tempsize
self.primitive = primitive
- def getclassmirror(self):
- from pypy.lang.smalltalk.classtable import m_CompiledMethod
- return m_CompiledMethod
+ def getclass(self):
+ from pypy.lang.smalltalk.classtable import w_CompiledMethod
+ return w_CompiledMethod
def gethash(self):
return 43 # XXX
Modified: pypy/dist/pypy/lang/smalltalk/objtable.py
==============================================================================
--- pypy/dist/pypy/lang/smalltalk/objtable.py (original)
+++ pypy/dist/pypy/lang/smalltalk/objtable.py Thu Oct 25 13:38:20 2007
@@ -14,7 +14,7 @@
return model.W_Float(i)
def wrap_string(str):
- w_inst = ct.m_ByteString.new(len(str))
+ w_inst = ct.w_ByteString.as_class_get_shadow().new(len(str))
for i in range(len(str)):
w_inst.setbyte(i, ord(str[i]))
return w_inst
@@ -23,9 +23,9 @@
return CharacterTable[ord(c)]
def ord_w_char(w_c):
- assert w_c.getclassmirror() is ct.m_Character
+ assert w_c.getclass() is ct.w_Character
w_ord = w_c.fetch(CHARACTER_VALUE_INDEX)
- assert w_ord.getclassmirror() is ct.m_SmallInteger
+ assert w_ord.getclass() is ct.w_SmallInteger
assert isinstance(w_ord, model.W_SmallInteger)
return w_ord.value
@@ -41,15 +41,15 @@
def wrap_char_table():
global CharacterTable
def bld_char(i):
- w_cinst = ct.m_Character.new()
+ w_cinst = ct.w_Character.as_class_get_shadow().new()
w_cinst.store(CHARACTER_VALUE_INDEX, wrap_int(i))
return w_cinst
CharacterTable = [bld_char(i) for i in range(256)]
wrap_char_table()
-w_true = ct.m_True.new()
-w_false = ct.m_False.new()
-w_nil = ct.m_UndefinedObject.new()
+w_true = ct.w_True.as_class_get_shadow().new()
+w_false = ct.w_False.as_class_get_shadow().new()
+w_nil = ct.w_UndefinedObject.as_class_get_shadow().new()
w_mone = wrap_int(-1)
w_zero = wrap_int(0)
w_one = wrap_int(1)
Modified: pypy/dist/pypy/lang/smalltalk/primitives.py
==============================================================================
--- pypy/dist/pypy/lang/smalltalk/primitives.py (original)
+++ pypy/dist/pypy/lang/smalltalk/primitives.py Thu Oct 25 13:38:20 2007
@@ -1,5 +1,5 @@
import operator
-from pypy.lang.smalltalk import model, mirror
+from pypy.lang.smalltalk import model, shadow
from pypy.lang.smalltalk import classtable
from pypy.lang.smalltalk import objtable
from pypy.rlib import rarithmetic
@@ -229,7 +229,7 @@
@primitive(SIZE)
@stack(1)
def func(args, (w_obj,)):
- if not w_obj.getclassmirror().isvariable():
+ if not w_obj.shadow_of_my_class().isvariable():
raise PrimitiveFailedError()
return w_obj.size()
@@ -244,7 +244,7 @@
@stack(3)
def func(args, stack):
w_obj, idx, w_val = common_at_put(stack)
- if w_val.getclassmirror() is not classtable.m_Character:
+ if w_val.getclass() is not classtable.w_Character:
raise PrimitiveFailedError()
w_obj.setbyte(idx, objtable.ord_w_char(w_val))
return w_val
@@ -270,7 +270,7 @@
def func(args, (w_rcvr, w_idx)):
idx = unwrap_int(w_idx)
# XXX should be idx-1, probably
- assert_bounds(idx, 0, w_rcvr.getclassmirror().instance_size)
+ assert_bounds(idx, 0, w_rcvr.shadow_of_my_class().instance_size)
return w_rcvr.fetch(idx)
@primitive(OBJECT_AT_PUT)
@@ -278,26 +278,26 @@
def func(args, (w_rcvr, w_idx, w_val)):
idx = unwrap_int(w_idx)
# XXX should be idx-1, probably
- assert_bounds(idx, 0, w_rcvr.getclassmirror().instance_size)
+ assert_bounds(idx, 0, w_rcvr.shadow_of_my_class().instance_size)
w_rcvr.store(idx, w_val)
return w_val
@primitive(NEW)
@stack(1)
def func(args, (w_cls,)):
- m_cls = mirror.mirrorcache.getmirror(w_cls)
- if m_cls.isvariable():
+ shadow = w_cls.as_class_get_shadow()
+ if shadow.isvariable():
raise PrimitiveFailedError()
- return m_cls.new()
+ return shadow.new()
@primitive(NEW_WITH_ARG)
@stack(2)
def func(args, (w_cls, w_size)):
- m_cls = mirror.mirrorcache.getmirror(w_cls)
- if not m_cls.isvariable():
+ shadow = w_cls.as_class_get_shadow()
+ if not shadow.isvariable():
raise PrimitiveFailedError()
size = unwrap_int(w_size)
- return m_cls.new(size)
+ return shadow.new(size)
@primitive(ARRAY_BECOME_ONE_WAY)
def func(args):
@@ -309,12 +309,12 @@
# I *think* this is the correct behavior, but I'm not quite sure.
# Might be restricted to fixed length fields?
idx = unwrap_int(w_idx)
- m_cls = w_rcvr.getclassmirror()
+ shadow = w_rcvr.shadow_of_my_class()
if idx < 0:
raise PrimitiveFailedError()
- if idx < m_cls.instsize():
+ if idx < shadow.instsize():
return w_rcvr.fetch(idx)
- idx -= m_cls.instsize()
+ idx -= shadow.instsize()
if idx < w_rcvr.size():
return subscript(idx, w_rcvr)
raise PrimitiveFailedError()
Modified: pypy/dist/pypy/lang/smalltalk/squeakimage.py
==============================================================================
--- pypy/dist/pypy/lang/smalltalk/squeakimage.py (original)
+++ pypy/dist/pypy/lang/smalltalk/squeakimage.py Thu Oct 25 13:38:20 2007
@@ -1,7 +1,6 @@
import py
from pypy.lang.smalltalk import model
from pypy.lang.smalltalk import objtable
-from pypy.lang.smalltalk.mirror import mirrorcache
from pypy.rlib import objectmodel
def int2str(integer):
@@ -120,6 +119,7 @@
def assign_mirrors(self):
# assign the mirrors to the classes already in classtable
from pypy.lang.smalltalk import classtable, constants
+ import py; py.test.skip("FIX ME")
for so_index, name in [
(constants.SO_SMALLINTEGER_CLASS, "m_SmallInteger"),
(constants.SO_STRING_CLASS, "m_String"),
Modified: pypy/dist/pypy/lang/smalltalk/test/test_classtable.py
==============================================================================
--- pypy/dist/pypy/lang/smalltalk/test/test_classtable.py (original)
+++ pypy/dist/pypy/lang/smalltalk/test/test_classtable.py Thu Oct 25 13:38:20 2007
@@ -1,23 +1,20 @@
-from pypy.lang.smalltalk.classtable import classtable
-import pypy.lang.smalltalk.classtable as ct
-
-def inherits_from(m_cls, m_superclass):
- m_p = m_cls
- while m_p and m_p != m_superclass:
- m_p = m_p.m_superclass
- return m_p == m_superclass
+from pypy.lang.smalltalk import classtable
def test_every_class_is_an_instance_of_a_metaclass():
- for (nm, m_cls) in classtable.items():
- assert (m_cls.m_metaclass is ct.m_Metaclass or
- m_cls.m_metaclass.m_metaclass is ct.m_Metaclass)
-
+ for (nm, w_cls) in classtable.classtable.items():
+ shadow = w_cls.as_class_get_shadow()
+ assert shadow.ismetaclass() or shadow.s_metaclass.ismetaclass()
+
def test_every_metaclass_inherits_from_class_and_behavior():
- for (nm, m_cls) in classtable.items():
- if m_cls.m_metaclass is ct.m_Metaclass:
- assert inherits_from(m_cls, ct.m_Class)
- assert inherits_from(ct.m_Class, ct.m_Behavior)
+ s_Class = classtable.w_Class.as_class_get_shadow()
+ s_Behavior = classtable.w_Behavior.as_class_get_shadow()
+ for (nm, w_cls) in classtable.classtable.items():
+ shadow = w_cls.as_class_get_shadow()
+ if shadow.ismetaclass():
+ assert shadow.inherits_from(s_Class)
+ assert s_Class.inherits_from(s_Behavior)
def test_metaclass_of_metaclass_is_an_instance_of_metaclass():
- assert ct.m_Metaclass.m_metaclass.m_metaclass is ct.m_Metaclass
+ s_Metaclass = classtable.w_Metaclass.as_class_get_shadow()
+ assert s_Metaclass.s_metaclass.s_metaclass is s_Metaclass
Modified: pypy/dist/pypy/lang/smalltalk/test/test_interpreter.py
==============================================================================
--- pypy/dist/pypy/lang/smalltalk/test/test_interpreter.py (original)
+++ pypy/dist/pypy/lang/smalltalk/test/test_interpreter.py Thu Oct 25 13:38:20 2007
@@ -1,9 +1,9 @@
import py
-from pypy.lang.smalltalk import model, interpreter, primitives, mirror
+from pypy.lang.smalltalk import model, interpreter, primitives, shadow
from pypy.lang.smalltalk.objtable import wrap_int
import pypy.lang.smalltalk.classtable as ct
-mockclassmirror = ct.bootstrap_classmirror
+mockclass = ct.bootstrap_class
# expose the bytecode's values as global constants.
# Bytecodes that have a whole range are exposed as global functions:
@@ -79,7 +79,7 @@
def test_pushReceiverVariableBytecode(bytecode = (pushReceiverVariableBytecode(0) +
pushReceiverVariableBytecode(1) +
pushReceiverVariableBytecode(2))):
- w_demo = mockclassmirror(3).new()
+ w_demo = mockclass(3).as_class_get_shadow().new()
w_demo.store(0, "egg")
w_demo.store(1, "bar")
w_demo.store(2, "baz")
@@ -110,7 +110,7 @@
assert interp.activeContext.stack == ["a", "b", "c"]
def test_pushLiteralVariableBytecode(bytecode=pushLiteralVariableBytecode(0)):
- w_association = mockclassmirror(2).new()
+ w_association = mockclass(2).as_class_get_shadow().new()
w_association.store(0, "mykey")
w_association.store(1, "myvalue")
interp = new_interpreter(bytecode)
@@ -120,9 +120,9 @@
def test_storeAndPopReceiverVariableBytecode(bytecode=storeAndPopReceiverVariableBytecode,
popped=True):
- m_class = mockclassmirror(8)
+ shadow = mockclass(8).as_class_get_shadow()
for index in range(8):
- w_object = m_class.new()
+ w_object = shadow.new()
interp = new_interpreter(pushConstantTrueBytecode + bytecode(index))
interp.activeContext.receiver = w_object
interp.step()
@@ -198,18 +198,19 @@
interp.step()
assert interp.activeContext.stack == [interp.ZERO, interp.ZERO]
-# m_class - the class from which the method is going to be called
+# w_class - the class from which the method is going to be called
# (and on which it is going to be installed)
# w_object - the actual object we will be sending the method to
# bytecodes - the bytecode to be executed
-def sendBytecodesTest(m_class, w_object, bytecodes):
+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) ]:
- m_class.installmethod("foo",
- model.W_CompiledMethod(0, pushConstantOneBytecode + bytecode))
+ shadow = w_class.as_class_get_shadow()
+ shadow.installmethod("foo",
+ model.W_CompiledMethod(0, pushConstantOneBytecode + bytecode))
interp = new_interpreter(bytecodes)
interp.activeContext.method.literals = fakeliterals("foo")
interp.activeContext.push(w_object)
@@ -218,7 +219,7 @@
assert interp.activeContext.sender == callerContext
assert interp.activeContext.stack == []
assert interp.activeContext.receiver == w_object
- assert interp.activeContext.method == m_class.methoddict["foo"]
+ assert interp.activeContext.method == shadow.methoddict["foo"]
assert callerContext.stack == []
interp.step()
interp.step()
@@ -226,17 +227,17 @@
assert interp.activeContext.stack == [result]
def test_sendLiteralSelectorBytecode():
- m_class = mockclassmirror(0)
- w_object = m_class.new()
- sendBytecodesTest(m_class, w_object, sendLiteralSelectorBytecode(0))
+ w_class = mockclass(0)
+ w_object = w_class.as_class_get_shadow().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 ]))
- m_class = mockclassmirror(0)
+ shadow = mockclass(0).as_class_get_shadow()
method = model.W_CompiledMethod(1, bytecode, 1)
method.literals = fakeliterals("fib:")
- m_class.installmethod("fib:", method)
- w_object = m_class.new()
+ shadow.installmethod("fib:", method)
+ w_object = shadow.new()
interp = new_interpreter(sendLiteralSelectorBytecode(16) + returnTopFromMethod)
interp.activeContext.method.literals = fakeliterals("fib:")
interp.activeContext.push(w_object)
@@ -245,10 +246,10 @@
assert primitives.unwrap_int(result) == 34
def test_send_to_primitive():
- m_smallintclass = ct.m_SmallInteger
+ s_smallintclass = ct.w_SmallInteger.as_class_get_shadow()
prim_meth = model.W_CompiledMethod(0, "", argsize=1,
primitive=primitives.SUBTRACT)
- m_smallintclass.installmethod("sub", prim_meth)
+ s_smallintclass.installmethod("sub", prim_meth)
try:
interp = new_interpreter(sendLiteralSelectorBytecode(1 + 16))
interp.activeContext.method.literals = fakeliterals("foo", "sub")
@@ -261,7 +262,7 @@
w_result = interp.activeContext.pop()
assert primitives.unwrap_int(w_result) == 42
finally:
- del m_smallintclass.methoddict['sub'] # clean up after you
+ del s_smallintclass.methoddict['sub'] # clean up after you
def test_longJumpIfTrue():
interp = new_interpreter(longJumpIfTrue(0) + chr(15) + longJumpIfTrue(0) + chr(15))
@@ -334,7 +335,7 @@
test_pushLiteralVariableBytecode(extendedPushBytecode + chr((3<<6) + 0))
def storeAssociation(bytecode):
- w_association = mockclassmirror(2).new()
+ w_association = mockclass(2).as_class_get_shadow().new()
w_association.store(0, "mykey")
w_association.store(1, "myvalue")
interp = new_interpreter(pushConstantOneBytecode + bytecode)
@@ -356,13 +357,13 @@
def test_callPrimitiveAndPush_fallback():
interp = new_interpreter(bytecodePrimAdd)
- m_class = mockclassmirror(0)
- m_class.installmethod("+", model.W_CompiledMethod(1, "", 1))
- w_object = m_class.new()
+ shadow = mockclass(0).as_class_get_shadow()
+ shadow.installmethod("+", model.W_CompiledMethod(1, "", 1))
+ w_object = shadow.new()
interp.activeContext.push(w_object)
interp.activeContext.push(interp.ONE)
interp.step()
- assert interp.activeContext.method == m_class.methoddict["+"]
+ assert interp.activeContext.method == shadow.methoddict["+"]
assert interp.activeContext.receiver is w_object
assert interp.activeContext.gettemp(0) == interp.ONE
assert interp.activeContext.stack == []
@@ -383,49 +384,50 @@
interp.FALSE, interp.TRUE]
def test_singleExtendedSendBytecode():
- m_class = mockclassmirror(0)
- w_object = m_class.new()
- sendBytecodesTest(m_class, w_object, singleExtendedSendBytecode + chr((0<<5)+0))
+ w_class = mockclass(0)
+ w_object = w_class.as_class_get_shadow().new()
+ sendBytecodesTest(w_class, w_object, singleExtendedSendBytecode + chr((0<<5)+0))
def test_singleExtendedSuperBytecode(bytecode=singleExtendedSuperBytecode + chr((0<<5) + 0)):
- m_supersuper = mockclassmirror(0)
- m_super = mockclassmirror(0, m_superclass=m_supersuper)
- m_class = mockclassmirror(0, m_superclass=m_super)
- w_object = m_class.new()
- # first call method installed in m_class
+ 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()
+ # first call method installed in w_class
bytecodes = singleExtendedSendBytecode + chr(0)
# which does a call to its super
- m_class.installmethod("foo",
- model.W_CompiledMethod(0, bytecode))
+ meth1 = model.W_CompiledMethod(0, bytecode)
+ w_class.as_class_get_shadow().installmethod("foo", meth1)
# and that one again to its super
- m_super.installmethod("foo",
- model.W_CompiledMethod(0, bytecode))
- m_supersuper.installmethod("foo",
- model.W_CompiledMethod(0, ""))
- m_class.methoddict["foo"].literals = fakeliterals("foo")
- m_super.methoddict["foo"].literals = fakeliterals("foo")
+ meth2 = model.W_CompiledMethod(0, bytecode)
+ w_super.as_class_get_shadow().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")
interp = new_interpreter(bytecodes)
interp.activeContext.method.literals = fakeliterals("foo")
interp.activeContext.push(w_object)
- for m_specificclass in [m_class, m_super, m_supersuper]:
+ for w_specificclass in [w_class, w_super, w_supersuper]:
callerContext = interp.activeContext
interp.step()
assert interp.activeContext.sender == callerContext
assert interp.activeContext.stack == []
assert interp.activeContext.receiver == w_object
- assert interp.activeContext.method == m_specificclass.methoddict["foo"]
+ meth = w_specificclass.as_class_get_shadow().methoddict["foo"]
+ assert interp.activeContext.method == meth
assert callerContext.stack == []
def test_secondExtendedSendBytecode():
- m_class = mockclassmirror(0)
- w_object = m_class.new()
- sendBytecodesTest(m_class, w_object, secondExtendedSendBytecode + chr(0))
+ w_class = mockclass(0)
+ w_object = w_class.as_class_get_shadow().new()
+ sendBytecodesTest(w_class, w_object, secondExtendedSendBytecode + chr(0))
def test_doubleExtendedDoAnythinBytecode():
- m_class = mockclassmirror(0)
- w_object = m_class.new()
+ w_class = mockclass(0)
+ w_object = w_class.as_class_get_shadow().new()
- sendBytecodesTest(m_class, w_object, doubleExtendedDoAnythingBytecode + chr((0<<5) + 0) + chr(0))
+ sendBytecodesTest(w_class, w_object, doubleExtendedDoAnythingBytecode + chr((0<<5) + 0) + chr(0))
test_singleExtendedSuperBytecode(doubleExtendedDoAnythingBytecode + (chr((1<<5) + 0) + chr(0)))
Modified: pypy/dist/pypy/lang/smalltalk/test/test_model.py
==============================================================================
--- pypy/dist/pypy/lang/smalltalk/test/test_model.py (original)
+++ pypy/dist/pypy/lang/smalltalk/test/test_model.py Thu Oct 25 13:38:20 2007
@@ -1,31 +1,32 @@
import py
-from pypy.lang.smalltalk import model, mirror
+from pypy.lang.smalltalk import model, shadow
import pypy.lang.smalltalk.classtable as ct
-mockclassmirror = ct.bootstrap_classmirror
+mockclass = ct.bootstrap_class
def test_new():
- m_mycls = mockclassmirror(0)
- w_myinstance = m_mycls.new()
+ w_mycls = mockclass(0)
+ w_myinstance = w_mycls.as_class_get_shadow().new()
assert isinstance(w_myinstance, model.W_PointersObject)
- assert w_myinstance.getclassmirror() is m_mycls
+ assert w_myinstance.getclass() is w_mycls
+ assert w_myinstance.shadow_of_my_class() is w_mycls.as_class_get_shadow()
def test_new_namedvars():
- m_mycls = mockclassmirror(3)
- w_myinstance = m_mycls.new()
+ w_mycls = mockclass(3)
+ w_myinstance = w_mycls.as_class_get_shadow().new()
assert isinstance(w_myinstance, model.W_PointersObject)
- assert w_myinstance.getclassmirror() is m_mycls
+ assert w_myinstance.getclass() is w_mycls
assert w_myinstance.fetch(0) is None
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():
- m_class = mockclassmirror(0, format=mirror.BYTES)
- w_bytes = m_class.new(20)
- assert w_bytes.getclassmirror() is m_class
+ w_class = mockclass(0, format=shadow.BYTES)
+ w_bytes = w_class.as_class_get_shadow().new(20)
+ assert w_bytes.getclass() is w_class
assert w_bytes.size() == 20
- assert m_class.instsize() == 0
+ assert w_class.as_class_get_shadow().instsize() == 0
assert w_bytes.getbyte(3) == 00
w_bytes.setbyte(3, 0xAA)
assert w_bytes.getbyte(3) == 0xAA
@@ -33,11 +34,11 @@
py.test.raises(IndexError, lambda: w_bytes.getbyte(20))
def test_word_object():
- m_class = mockclassmirror(0, format=mirror.WORDS)
- w_bytes = m_class.new(20)
- assert w_bytes.getclassmirror() is m_class
+ w_class = mockclass(0, format=shadow.WORDS)
+ w_bytes = w_class.as_class_get_shadow().new(20)
+ assert w_bytes.getclass() is w_class
assert w_bytes.size() == 20
- assert m_class.instsize() == 0
+ assert w_class.as_class_get_shadow().instsize() == 0
assert w_bytes.getword(3) == 0
w_bytes.setword(3, 42)
assert w_bytes.getword(3) == 42
@@ -45,29 +46,34 @@
py.test.raises(IndexError, lambda: w_bytes.getword(20))
def test_method_lookup():
- m_class = mockclassmirror(0)
- m_class.methoddict["foo"] = 1
- m_class.methoddict["bar"] = 2
- m_subclass = mockclassmirror(0, m_superclass=m_class)
- m_subclass.methoddict["foo"] = 3
- assert m_class.lookup("foo") == 1
- assert m_class.lookup("bar") == 2
- assert m_class.lookup("zork") == None
- assert m_subclass.lookup("foo") == 3
- assert m_subclass.lookup("bar") == 2
- assert m_subclass.lookup("zork") == None
-
-def test_m_compiledin():
- m_super = mockclassmirror(0)
- m_class = mockclassmirror(0, m_superclass=m_super)
- m_super.installmethod("foo", model.W_CompiledMethod(0, ""))
- assert m_class.lookup("foo").m_compiledin is m_super
+ w_class = mockclass(0)
+ shadow = w_class.as_class_get_shadow()
+ shadow.methoddict["foo"] = 1
+ shadow.methoddict["bar"] = 2
+ w_subclass = mockclass(0, w_superclass=w_class)
+ subshadow = w_subclass.as_class_get_shadow()
+ assert subshadow.s_superclass is shadow
+ subshadow.methoddict["foo"] = 3
+ assert shadow.lookup("foo") == 1
+ assert shadow.lookup("bar") == 2
+ assert shadow.lookup("zork") == None
+ assert subshadow.lookup("foo") == 3
+ assert subshadow.lookup("bar") == 2
+ assert subshadow.lookup("zork") == None
+
+def test_w_compiledin():
+ w_super = mockclass(0)
+ w_class = mockclass(0, w_superclass=w_super)
+ supershadow = w_super.as_class_get_shadow()
+ supershadow.installmethod("foo", model.W_CompiledMethod(0, ""))
+ classshadow = w_class.as_class_get_shadow()
+ assert classshadow.lookup("foo").w_compiledin is w_super
def test_hashes():
w_five = model.W_SmallInteger(5)
assert w_five.gethash() == 5
- m_class = mockclassmirror(0)
- w_inst = m_class.new()
+ w_class = mockclass(0)
+ w_inst = w_class.as_class_get_shadow().new()
assert w_inst.hash == w_inst.UNASSIGNED_HASH
h1 = w_inst.gethash()
h2 = w_inst.gethash()
Modified: pypy/dist/pypy/lang/smalltalk/test/test_primitives.py
==============================================================================
--- pypy/dist/pypy/lang/smalltalk/test/test_primitives.py (original)
+++ pypy/dist/pypy/lang/smalltalk/test/test_primitives.py Thu Oct 25 13:38:20 2007
@@ -1,6 +1,6 @@
import py
from pypy.lang.smalltalk.primitives import prim_table, PrimitiveFailedError
-from pypy.lang.smalltalk import model, mirror
+from pypy.lang.smalltalk import model, shadow
from pypy.lang.smalltalk import interpreter
from pypy.lang.smalltalk import classtable
from pypy.lang.smalltalk import objtable
@@ -8,7 +8,7 @@
# Violates the guideline, but we use it A LOT to reference the primitive codes:
import pypy.lang.smalltalk.primitives as p
-mockclassmirror = classtable.bootstrap_classmirror
+mockclass = classtable.bootstrap_class
class MockFrame(interpreter.W_MethodContext):
def __init__(self, stack):
@@ -20,7 +20,6 @@
if isinstance(x, model.W_Object): return x
if isinstance(x, str) and len(x) == 1: return objtable.wrap_char(x)
if isinstance(x, str): return objtable.wrap_string(x)
- if isinstance(x, mirror.ClassMirror): return x.w_self
raise NotImplementedError
def mock(stack):
@@ -145,21 +144,21 @@
assert prim(p.FLOAT_ADD, [3,4.5]).value == 7.5
def test_at():
- w_obj = mockclassmirror(0, varsized=True).new(1)
+ w_obj = mockclass(0, varsized=True).as_class_get_shadow().new(1)
w_obj.store(0, "foo")
assert prim(p.AT, [w_obj, 0]) == "foo"
def test_invalid_at():
- w_obj = mockclassmirror(0).new()
+ w_obj = mockclass(0).as_class_get_shadow().new()
prim_fails(p.AT, [w_obj, 0])
def test_at_put():
- w_obj = mockclassmirror(0, varsized=1).new(1)
+ w_obj = mockclass(0, varsized=1).as_class_get_shadow().new(1)
assert prim(p.AT_PUT, [w_obj, 0, 22]).value == 22
assert prim(p.AT, [w_obj, 0]).value == 22
def test_invalid_at_put():
- w_obj = mockclassmirror(0).new()
+ w_obj = mockclass(0).as_class_get_shadow().new()
prim_fails(p.AT_PUT, [w_obj, 0, 22])
def test_string_at():
@@ -180,12 +179,12 @@
prim_fails(p.OBJECT_AT, ["q", objtable.CHARACTER_VALUE_INDEX+1])
def test_object_at_put():
- w_obj = mockclassmirror(1).new()
+ w_obj = mockclass(1).as_class_get_shadow().new()
assert prim(p.OBJECT_AT_PUT, [w_obj, 0, "q"]) is wrap("q")
assert prim(p.OBJECT_AT, [w_obj, 0]) is wrap("q")
def test_invalid_object_at_put():
- w_obj = mockclassmirror(1).new()
+ w_obj = mockclass(1).as_class_get_shadow().new()
prim_fails(p.OBJECT_AT, [w_obj, 1, 1])
def test_string_at_put():
@@ -196,19 +195,19 @@
assert prim(p.STRING_AT, [test_str, i]) == wrap(exp[i])
def test_new():
- w_res = prim(p.NEW, [classtable.m_Object])
- assert w_res.getclassmirror() == classtable.m_Object
+ w_res = prim(p.NEW, [classtable.w_Object])
+ assert w_res.getclass() == classtable.w_Object
def test_invalid_new():
- prim_fails(p.NEW, [classtable.m_ByteString])
+ prim_fails(p.NEW, [classtable.w_ByteString])
def test_new_with_arg():
- w_res = prim(p.NEW_WITH_ARG, [classtable.m_ByteString, 20])
- assert w_res.getclassmirror() == classtable.m_ByteString
+ w_res = prim(p.NEW_WITH_ARG, [classtable.w_ByteString, 20])
+ assert w_res.getclass() == classtable.w_ByteString
assert w_res.size() == 20
def test_invalid_new_with_arg():
- prim_fails(p.NEW_WITH_ARG, [classtable.m_Object, 20])
+ prim_fails(p.NEW_WITH_ARG, [classtable.w_Object, 20])
def test_inst_var_at():
# I am not entirely sure if this is what this primitive is
@@ -219,7 +218,7 @@
assert w_v.value == ord("b")
def test_as_oop():
- w_obj = mockclassmirror(0).new()
+ w_obj = mockclass(0).as_class_get_shadow().new()
w_obj.w_hash = wrap(22)
assert prim(p.AS_OOP, [w_obj]).value == 22
More information about the Pypy-commit
mailing list