Author: Anton Gulenko <[email protected]>
Branch: rstrategies
Changeset: r1051:22e577331561
Date: 2014-09-24 15:58 +0200
http://bitbucket.org/pypy/lang-smalltalk/changeset/22e577331561/
Log: Removed charactertable from regular objspace, moved to bootstrapped
objspace for tests. Instantiating empty W_PointersObjects for
precompiled constants, without assigned storage. Small cleanups in
squeakimage.py.
diff --git a/spyvm/model.py b/spyvm/model.py
--- a/spyvm/model.py
+++ b/spyvm/model.py
@@ -586,6 +586,7 @@
pointers = g_self.get_pointers()
storage_type = space.strategy_factory.strategy_type_for(pointers,
g_self.isweak())
storage = storage_type(space, self, len(pointers))
+ assert self.shadow is None, "Shadow should not be initialized yet!"
self.store_shadow(storage, operation="Filledin", log_classname=False)
self.store_all(space, pointers)
diff --git a/spyvm/objspace.py b/spyvm/objspace.py
--- a/spyvm/objspace.py
+++ b/spyvm/objspace.py
@@ -43,6 +43,9 @@
import_from_mixin(ConstantMixin)
default_value = None
+def empty_object():
+ return instantiate(model.W_PointersObject)
+
class ObjSpace(object):
def __init__(self):
# This is a hack; see compile_code() in targetimageloadingsmalltalk.py
@@ -59,7 +62,7 @@
# Create the nil object.
# Circumvent the constructor because nil is already referenced there.
- w_nil = instantiate(model.W_PointersObject)
+ w_nil = empty_object()
w_nil.w_class = None
self.add_bootstrap_object("w_nil", w_nil)
@@ -101,7 +104,7 @@
def make_bootstrap_classes(self):
names = [ "w_" + name for name in
constants.classes_in_special_object_table.keys() ]
for name in names:
- cls = model.W_PointersObject(self, None, 0)
+ cls = empty_object()
self.add_bootstrap_class(name, cls)
def add_bootstrap_object(self, name, obj):
@@ -109,23 +112,12 @@
setattr(self, name, obj)
def make_bootstrap_object(self, name):
- obj = model.W_PointersObject(self, None, 0)
+ obj = empty_object()
self.add_bootstrap_object(name, obj)
- def make_character_table(self):
- def build_char(i):
- # TODO - This is pretty hacky, maybe not required? At least
eliminate the constant 1.
- w_cinst = model.W_PointersObject(self, self.w_Character, 1)
- w_cinst.store(self, constants.CHARACTER_VALUE_INDEX,
- model.W_SmallInteger(i))
- return w_cinst
- char_table = model.W_PointersObject(self, self.classtable['w_Array'],
256)
- for i in range(256):
- char_table.store(self, i, build_char(i))
- self.add_bootstrap_object("w_charactertable", char_table)
-
def make_bootstrap_objects(self):
- self.make_character_table()
+ self.make_bootstrap_object("w_charactertable")
+ self.make_bootstrap_object("w_true")
self.make_bootstrap_object("w_true")
self.make_bootstrap_object("w_false")
self.make_bootstrap_object("w_special_selectors")
diff --git a/spyvm/squeakimage.py b/spyvm/squeakimage.py
--- a/spyvm/squeakimage.py
+++ b/spyvm/squeakimage.py
@@ -89,6 +89,7 @@
self.assign_prebuilt_constants()
self.init_w_objects()
self.fillin_w_objects()
+ self.populate_special_objects()
def try_read_version(self):
magic1 = self.stream.next()
@@ -190,19 +191,17 @@
def init_g_objects(self):
for chunk in self.chunks.itervalues():
- chunk.as_g_object(self) # initialized g_object
+ chunk.as_g_object(self) # initialize g_object
+ self.special_g_objects =
self.chunks[self.specialobjectspointer].g_object.pointers
def assign_prebuilt_constants(self):
# Assign classes and objects that in special objects array that are
already created.
self._assign_prebuilt_constants(constants.objects_in_special_object_table,
self.space.objtable)
+ classtable = self.space.classtable
if not self.version.is_modern:
- classtable = {}
- for name, so_index in self.space.classtable.items():
- # In non-modern images (pre 4.0), there was no BlockClosure
class.
- if not name == "BlockClosure":
- classtable[name] = so_index
- else:
- classtable = self.space.classtable
+ classtable = dict(classtable)
+ # In non-modern images (pre 4.0), there was no BlockClosure class.
+ del classtable["w_BlockClosure"]
self._assign_prebuilt_constants(constants.classes_in_special_object_table,
classtable)
def _assign_prebuilt_constants(self, names_and_indices, prebuilt_objects):
@@ -210,20 +209,24 @@
name = "w_" + name
if name in prebuilt_objects:
w_object = prebuilt_objects[name]
- if self.special_object(so_index).w_object is None:
- self.special_object(so_index).w_object = w_object
+ g_object = self.special_object(so_index)
+ if g_object.w_object is None:
+ g_object.w_object = w_object
else:
- if not self.special_object(0).w_object.is_nil(self.space):
+ if not g_object.w_object.is_nil(self.space):
raise Warning('Object found in multiple places in the
special objects array')
def special_object(self, index):
- special = self.chunks[self.specialobjectspointer].g_object.pointers
- return special[index]
+ return self.special_g_objects[index]
def init_w_objects(self):
for chunk in self.chunks.itervalues():
chunk.g_object.init_w_object()
+ self.special_w_objects = [g.w_object for g in self.special_g_objects]
+ def populate_special_objects(self):
+ self.space.populate_special_objects(self.special_w_objects)
+
def fillin_w_objects(self):
self.filledin_objects = 0
for chunk in self.chunks.itervalues():
@@ -241,10 +244,7 @@
def __init__(self, reader):
space = reader.space
- self.special_objects = [g_object.w_object for g_object in
- reader.chunks[reader.specialobjectspointer]
- .g_object.pointers]
- space.populate_special_objects(self.special_objects)
+ self.special_objects = reader.special_w_objects
self.w_asSymbol = self.find_symbol(space, reader, "asSymbol")
self.w_simulateCopyBits = self.find_symbol(space, reader,
"simulateCopyBits")
self.lastWindowSize = reader.lastWindowSize
diff --git a/spyvm/test/util.py b/spyvm/test/util.py
--- a/spyvm/test/util.py
+++ b/spyvm/test/util.py
@@ -252,7 +252,14 @@
patch_bootstrap_object(self.w_true, self.w_True, 0)
patch_bootstrap_object(self.w_false, self.w_False, 0)
patch_bootstrap_object(self.w_special_selectors, self.w_Array,
len(constants.SPECIAL_SELECTORS) * 2)
-
+ patch_bootstrap_object(self.w_charactertable, self.w_Array, 256)
+
+ # Bootstrap character table
+ for i in range(256):
+ w_cinst = model.W_PointersObject(self, self.w_Character, 1)
+ w_cinst.store(self, constants.CHARACTER_VALUE_INDEX,
model.W_SmallInteger(i))
+ self.w_charactertable.store(self, i, w_cinst)
+
def patch_class(self, w_class, instsize, w_superclass=None,
w_metaclass=None,
name='?', format=storage_classes.POINTERS,
varsized=False):
s = instantiate(storage_classes.ClassShadow)
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit