[pypy-commit] lang-smalltalk default: removed the w_class field of w_objects with class reference. Only s_class remains, the interface remains the same
lwassermann
noreply at buildbot.pypy.org
Mon Apr 8 00:15:00 CEST 2013
Author: Lars Wassermann <lars.wassermann at gmail.com>
Branch:
Changeset: r248:f0a08c690de4
Date: 2013-04-03 14:57 +0200
http://bitbucket.org/pypy/lang-smalltalk/changeset/f0a08c690de4/
Log: removed the w_class field of w_objects with class reference. Only
s_class remains, the interface remains the same
diff --git a/spyvm/model.py b/spyvm/model.py
--- a/spyvm/model.py
+++ b/spyvm/model.py
@@ -117,6 +117,7 @@
def __repr__(self):
return self.as_repr_string()
+ @jit.elidable
def as_repr_string(self):
return "%r" % self
@@ -139,6 +140,7 @@
def invariant(self):
return isinstance(self.value, int) and self.value < 0x8000
+ @jit.elidable
def as_repr_string(self):
return "W_SmallInteger(%d)" % self.value
@@ -330,30 +332,29 @@
class W_AbstractObjectWithClassReference(W_AbstractObjectWithIdentityHash):
"""Objects with arbitrary class (ie not CompiledMethod, SmallInteger or
Float)."""
- _attrs_ = ['w_class', 's_class', 'space']
- s_class = None
+ _attrs_ = ['s_class', 'space']
def __init__(self, space, w_class):
if w_class is not None: # it's None only for testing and space generation
assert isinstance(w_class, W_PointersObject)
- if w_class.has_shadow():
- self.s_class = w_class.as_class_get_shadow(w_class._shadow.space)
- self.w_class = w_class
+ self.s_class = w_class.as_class_get_penumbra(space)
+ else:
+ self.s_class = None
self.space = space
def getclass(self, space):
- assert self.w_class is not None
- return self.w_class
+ return self.shadow_of_my_class(space).w_self()
def __str__(self):
if isinstance(self, W_PointersObject) and self.has_shadow():
return self._shadow.getname()
else:
name = None
- if self.w_class.has_shadow():
- name = self.w_class._shadow.name
+ if self.has_class():
+ name = self.s_class.name
return "a %s" % (name or '?',)
+ @jit.elidable
def as_repr_string(self):
return self.as_embellished_string("W_O /w Class", "")
@@ -365,20 +366,19 @@
additionalInformation)
def invariant(self):
+ from spyvm import shadow
return (W_AbstractObjectWithIdentityHash.invariant(self) and
- isinstance(self.w_class, W_PointersObject))
+ isinstance(self.s_class, shadow.ClassShadow))
def _become(self, w_other):
- self.w_class, w_other.w_class = w_other.w_class, self.w_class
self.s_class, w_other.s_class = w_other.s_class, self.s_class
W_AbstractObjectWithIdentityHash._become(self, w_other)
def has_class(self):
- return self.w_class is not None
+ return self.s_class is not None
def shadow_of_my_class(self, space):
- if self.s_class is None:
- self.s_class = self.w_class.as_class_get_shadow(space)
+ assert self.s_class is not None
return self.s_class
class W_PointersObject(W_AbstractObjectWithClassReference):
@@ -398,8 +398,7 @@
def fillin(self, space, g_self):
self._vars = g_self.get_pointers()
- self.w_class = g_self.get_class()
- self.s_class = None
+ self.s_class = g_self.get_class().as_class_get_penumbra(space)
self.hash = g_self.get_hash()
self.space = space
@@ -481,7 +480,9 @@
# Should only be used during squeak-image loading.
def as_class_get_penumbra(self, space):
from spyvm.shadow import ClassShadow
- self.store_shadow(ClassShadow(space, self))
+ assert self._shadow is None or isinstance(self._shadow, ClassShadow)
+ if self._shadow is None:
+ self.store_shadow(ClassShadow(space, self))
return self._shadow
def as_blockcontext_get_shadow(self, space):
@@ -529,14 +530,15 @@
return True
def clone(self, space):
- w_result = W_PointersObject(self.space, self.w_class, len(self._vars))
+ w_result = W_PointersObject(self.space, self.getclass(space), len(self._vars))
w_result._vars = [self.fetch(space, i) for i in range(len(self._vars))]
return w_result
+ @jit.elidable
def as_repr_string(self):
return W_AbstractObjectWithClassReference.as_embellished_string(self,
className='W_PointersObject',
- additionalInformation='len(%d)' % self.size())
+ additionalInformation='len=%d' % self.size())
class W_BytesObject(W_AbstractObjectWithClassReference):
_attrs_ = ['bytes']
@@ -547,7 +549,7 @@
self.bytes = ['\x00'] * size
def fillin(self, space, g_self):
- self.w_class = g_self.get_class()
+ self.s_class = g_self.get_class().as_class_get_penumbra(space)
self.bytes = g_self.get_bytes()
self.hash = g_self.get_hash()
self.space = space
@@ -593,7 +595,7 @@
return self.bytes == other.bytes
def clone(self, space):
- w_result = W_BytesObject(self.space, self.w_class, len(self.bytes))
+ w_result = W_BytesObject(self.space, self.getclass(space), len(self.bytes))
w_result.bytes = list(self.bytes)
return w_result
@@ -606,7 +608,7 @@
def fillin(self, space, g_self):
self.words = g_self.get_ruints()
- self.w_class = g_self.get_class()
+ self.s_class = g_self.get_class().as_class_get_penumbra(space)
self.hash = g_self.get_hash()
self.space = space
@@ -632,7 +634,7 @@
isinstance(self.words, list))
def clone(self, space):
- w_result = W_WordsObject(self.space, self.w_class, len(self.words))
+ w_result = W_WordsObject(self.space, self.getclass(space), len(self.words))
w_result.words = list(self.words)
return w_result
@@ -677,7 +679,7 @@
return False
def clone(self, space):
- w_result = W_WordsObject(self.space, self.w_class, self._realsize)
+ w_result = W_WordsObject(self.space, self.getclass(space), self._realsize)
n = 0
while n < self._realsize:
w_result.words[n] = self.getword(n)
diff --git a/spyvm/objspace.py b/spyvm/objspace.py
--- a/spyvm/objspace.py
+++ b/spyvm/objspace.py
@@ -51,15 +51,15 @@
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"]
+ s_Metaclass = self.classtable["w_Metaclass"].as_class_get_penumbra(self)
# XXX
proto_shadow = w_ProtoObjectClass._shadow
proto_shadow.store_w_superclass(w_Class)
# 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
+ if w_cls_obj.s_class is None:
+ w_cls_obj.s_class = s_Metaclass
def define_cls(cls_nm, supercls_nm, instvarsize=0, format=shadow.POINTERS,
varsized=False):
@@ -136,7 +136,7 @@
# package, and then patch up its fields here:
w_nil = self.w_nil = model.w_nil
w_nil.space = self
- w_nil.w_class = self.classtable['w_UndefinedObject']
+ w_nil.s_class = self.classtable['w_UndefinedObject'].as_class_get_penumbra(self)
w_true = self.classtable['w_True'].as_class_get_shadow(self).new()
self.w_true = w_true
diff --git a/spyvm/primitives.py b/spyvm/primitives.py
--- a/spyvm/primitives.py
+++ b/spyvm/primitives.py
@@ -752,7 +752,6 @@
if w_arg_class.instsize() != w_rcvr_class.instsize():
raise PrimitiveFailedError()
- w_rcvr.w_class = w_arg.w_class
w_rcvr.s_class = w_arg.s_class
# ___________________________________________________________________________
diff --git a/spyvm/test/test_objectspace.py b/spyvm/test/test_objectspace.py
--- a/spyvm/test/test_objectspace.py
+++ b/spyvm/test/test_objectspace.py
@@ -8,11 +8,11 @@
# Heuristic to detect if this is a metaclass. Don't use apart
# from in this test file, because classtable['w_Metaclass'] is
# bogus after loading an image.
- return w_cls.w_class is space.classtable['w_Metaclass']
+ return w_cls.s_class is space.classtable['w_Metaclass']._shadow
def test_every_class_is_an_instance_of_a_metaclass():
for (nm, w_cls) in space.classtable.items():
- assert ismetaclass(w_cls) or ismetaclass(w_cls.w_class)
+ assert ismetaclass(w_cls) or ismetaclass(w_cls.s_class._w_self)
def test_every_metaclass_inherits_from_class_and_behavior():
s_Class = space.classtable['w_Class'].as_class_get_shadow(space)
@@ -25,7 +25,7 @@
def test_metaclass_of_metaclass_is_an_instance_of_metaclass():
w_Metaclass = space.classtable['w_Metaclass']
- assert w_Metaclass.w_class.w_class is w_Metaclass
+ assert w_Metaclass.getclass(space).getclass(space) is w_Metaclass
def test_ruint():
from spyvm import model
diff --git a/spyvm/test/test_primitives.py b/spyvm/test/test_primitives.py
--- a/spyvm/test/test_primitives.py
+++ b/spyvm/test/test_primitives.py
@@ -19,7 +19,7 @@
s_self.reset_stack()
s_self.push_all(stack)
s_self.store_expected_argument_count(0)
- self.w_class = space.w_MethodContext
+ self.s_class = space.w_MethodContext.as_class_get_shadow(space)
def as_blockcontext_get_shadow(self):
self._shadow = shadow.BlockContextShadow(space, self)
diff --git a/spyvm/test/test_shadow.py b/spyvm/test/test_shadow.py
--- a/spyvm/test/test_shadow.py
+++ b/spyvm/test/test_shadow.py
@@ -32,7 +32,7 @@
w_classofclass=None, methods={}):
if w_classofclass is None:
w_classofclass = build_smalltalk_class(None, 0x94,
- w_superclass.w_class,
+ w_superclass.getclass(space),
w_Metaclass)
w_methoddict = build_methoddict(methods)
size = constants.CLASS_NAME_INDEX + 1
diff --git a/targetimageloadingsmalltalk.py b/targetimageloadingsmalltalk.py
--- a/targetimageloadingsmalltalk.py
+++ b/targetimageloadingsmalltalk.py
@@ -9,7 +9,7 @@
def _run_benchmark(interp, number, benchmark):
- w_object = model.W_SmallInteger(number)
+ w_object = interp.space.wrap_int(number)
t1 = time.time()
try:
w_result = interp.perform(w_object, benchmark)
More information about the pypy-commit
mailing list