[pypy-svn] r62140 - in pypy/trunk/pypy: lang/smalltalk translator/goal
cfbolz at codespeak.net
cfbolz at codespeak.net
Wed Feb 25 14:45:02 CET 2009
Author: cfbolz
Date: Wed Feb 25 14:45:01 2009
New Revision: 62140
Modified:
pypy/trunk/pypy/lang/smalltalk/constants.py
pypy/trunk/pypy/lang/smalltalk/model.py
pypy/trunk/pypy/lang/smalltalk/objspace.py
pypy/trunk/pypy/lang/smalltalk/primitives.py
pypy/trunk/pypy/lang/smalltalk/shadow.py
pypy/trunk/pypy/translator/goal/targetimageloadingsmalltalk.py
Log:
Partially revert revision r62131. The object space is supposed to be created at
translation time, not at runtime. This fixes translation.
Modified: pypy/trunk/pypy/lang/smalltalk/constants.py
==============================================================================
--- pypy/trunk/pypy/lang/smalltalk/constants.py (original)
+++ pypy/trunk/pypy/lang/smalltalk/constants.py Wed Feb 25 14:45:01 2009
@@ -131,8 +131,5 @@
"smalltalkdict" : SO_SMALLTALK,
}
-BITS = 32
-# Above should become:
-# BITS = LONG_BIT
-TAGGED_MAXINT = 2 ** (BITS - 2) - 1
-TAGGED_MININT = -2 ** (BITS - 2)
+TAGGED_MAXINT = 2 ** (LONG_BIT - 2) - 1
+TAGGED_MININT = -2 ** (LONG_BIT - 2)
Modified: pypy/trunk/pypy/lang/smalltalk/model.py
==============================================================================
--- pypy/trunk/pypy/lang/smalltalk/model.py (original)
+++ pypy/trunk/pypy/lang/smalltalk/model.py Wed Feb 25 14:45:01 2009
@@ -106,7 +106,7 @@
def getclass(self, space):
"""Return SmallInteger from special objects array."""
- return space.classtable['w_SmallInteger']
+ return space.w_SmallInteger
def gethash(self):
return self.value
@@ -142,7 +142,7 @@
def getclass(self, space):
"""Return Float from special objects array."""
- return space.classtable['w_Float']
+ return space.w_Float
def gethash(self):
return 41 # XXX check this
@@ -202,8 +202,7 @@
Float)."""
def __init__(self, w_class):
- if w_class is not None: # it's None for testing and bootstrapping the
- # class hierarchy
+ if w_class is not None: # it's None only for testing
assert isinstance(w_class, W_PointersObject)
self.w_class = w_class
@@ -219,9 +218,7 @@
return self._shadow.getname()
else:
name = None
- if (hasattr(self, 'w_class') and
- self.w_class is not None and
- self.w_class._shadow is not None):
+ if self.w_class._shadow is not None:
name = self.w_class._shadow.name
return "a %s" % (name or '?',)
@@ -413,10 +410,10 @@
# TODO: Completely untested! This failed translation bigtime...
# XXX Probably we want to allow all subclasses
if not (w_value.getclass(space).is_same_object(
- space.classtable['w_LargePositiveInteger']) and
- w_value.size() == 4):
+ space.w_LargePositiveInteger) and
+ w_value.size() == 4):
raise error.UnwrappingError("Failed to convert bytes to word")
- word = 0
+ word = 0
for i in range(4):
word += ord(w_value.getchar(i)) << 8*i
else:
@@ -477,7 +474,7 @@
return self.w_compiledin
def getclass(self, space):
- return space.classtable['w_CompiledMethod']
+ return space.w_CompiledMethod
def getliteral(self, index):
# We changed this part
Modified: pypy/trunk/pypy/lang/smalltalk/objspace.py
==============================================================================
--- pypy/trunk/pypy/lang/smalltalk/objspace.py (original)
+++ pypy/trunk/pypy/lang/smalltalk/objspace.py Wed Feb 25 14:45:01 2009
@@ -10,36 +10,16 @@
self.make_bootstrap_classes()
self.make_bootstrap_objects()
- def define_core_cls(self, 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
-
- def define_cls(self, 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:])
-
-
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:
@@ -63,14 +43,14 @@
["w_Class", "w_ClassDescription"],
["w_Metaclass", "w_ClassDescription"],
]
- w_ProtoObjectClass = self.define_core_cls("w_ProtoObjectClass", None, None)
- # w_ProtoObjectClass = self.classtable["w_ProtoObjectClass"]
- self.define_core_cls("w_ProtoObject", None, w_ProtoObjectClass)
+ 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 = self.define_core_cls(meta_nm, self.classtable[meta_super_nm], None)
- self.define_core_cls(cls_nm, self.classtable[super_cls_nm], w_metacls)
+ 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
@@ -85,53 +65,71 @@
if w_cls_obj.w_class is None:
w_cls_obj.w_class = w_Metaclass
- self.define_cls("w_Magnitude", "w_Object")
- self.define_cls("w_Character", "w_Magnitude", instvarsize=1)
- self.define_cls("w_Number", "w_Magnitude")
- self.define_cls("w_Integer", "w_Number")
- self.define_cls("w_SmallInteger", "w_Integer")
- self.define_cls("w_LargePositiveInteger", "w_Integer", format=shadow.BYTES)
- self.define_cls("w_Float", "w_Number", format=shadow.BYTES)
- self.define_cls("w_Collection", "w_Object")
- self.define_cls("w_SequenceableCollection", "w_Collection")
- self.define_cls("w_ArrayedCollection", "w_SequenceableCollection")
- self.define_cls("w_Array", "w_ArrayedCollection", varsized=True)
- self.define_cls("w_String", "w_ArrayedCollection", format=shadow.BYTES)
- self.define_cls("w_UndefinedObject", "w_Object")
- self.define_cls("w_Boolean", "w_Object")
- self.define_cls("w_True", "w_Boolean")
- self.define_cls("w_False", "w_Boolean")
- self.define_cls("w_ByteArray", "w_ArrayedCollection", format=shadow.BYTES)
- self.define_cls("w_MethodDict", "w_Object", instvarsize=2, varsized=True)
- self.define_cls("w_CompiledMethod", "w_ByteArray", format=shadow.COMPILED_METHOD)
- self.define_cls("w_ContextPart", "w_Object")
- self.define_cls("w_MethodContext", "w_ContextPart")
- self.define_cls("w_Link", "w_Object")
- self.define_cls("w_Process", "w_Link")
- self.define_cls("w_Point", "w_Object")
- self.define_cls("w_LinkedList", "w_SequenceableCollection")
- self.define_cls("w_Semaphore", "w_LinkedList")
- self.define_cls("w_BlockContext", "w_ContextPart",
+ 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_LargePositiveInteger", "w_Integer", format=shadow.BYTES)
+ 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_Point", "w_Object")
+ 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[name])
+ setattr(self, name, self.classtable.get(name))
- def bld_char(self, i):
- w_cinst = self.classtable['w_Character'].as_class_get_shadow(self).new()
+ def make_bootstrap_objects(self):
+ def bld_char(i):
+ w_cinst = self.w_Character.as_class_get_shadow(self).new()
w_cinst.store(self, constants.CHARACTER_VALUE_INDEX,
model.W_SmallInteger(i))
return w_cinst
-
- def make_bootstrap_objects(self):
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, self.bld_char(i))
+ self.w_charactertable.atput0(self, i, bld_char(i))
# Very special nil hack: in order to allow W_PointersObject's to
@@ -148,22 +146,14 @@
self.w_zero = model.W_SmallInteger(0)
self.w_one = model.W_SmallInteger(1)
self.w_two = model.W_SmallInteger(2)
- self.objtable = {
- "w_nil" : w_nil,
- "w_true" : w_true,
- "w_false" : w_false,
- "w_charactertable" : w_charactertable,
- "w_schedulerassociationpointer" : None,
- "w_smalltalkdict" : None,
- }
-
- # XXX Does not work when we load images dynamically!
- # 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
+ 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
@@ -177,7 +167,7 @@
return model.W_Float(i)
def wrap_string(self, string):
- w_inst = self.classtable['w_String'].as_class_get_shadow(self).new(len(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
@@ -197,7 +187,7 @@
a wrapped smalltalk array
"""
lstlen = len(lst_w)
- res = self.classtable['w_Array'].as_class_get_shadow().new(lstlen)
+ res = self.w_Array.as_class_get_shadow().new(lstlen)
for i in range(lstlen):
res.storevarpointer(i, lit[i])
return res
@@ -210,11 +200,11 @@
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.classtable['w_Character']):
+ if not w_class.is_same_object(self.w_Character):
raise UnwrappingError("expected character, got %s" % (w_class, ))
w_ord = w_char.fetch(self, constants.CHARACTER_VALUE_INDEX)
w_class = w_ord.getclass(self)
- if not w_class.is_same_object(self.classtable['w_SmallInteger']):
+ 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)
@@ -227,6 +217,7 @@
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
Modified: pypy/trunk/pypy/lang/smalltalk/primitives.py
==============================================================================
--- pypy/trunk/pypy/lang/smalltalk/primitives.py (original)
+++ pypy/trunk/pypy/lang/smalltalk/primitives.py Wed Feb 25 14:45:01 2009
@@ -503,8 +503,8 @@
# 1. Rcvr or arg are SmallIntegers
# XXX this is wrong too
- if (w_arg_class.is_same_object(interp.space.classtable['w_SmallInteger']) or
- w_rcvr_class.is_same_object(interp.space.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
@@ -704,7 +704,7 @@
# XXX need to check this since VALUE is called on all sorts of objects.
if not w_block_ctx.getclass(interp.space).is_same_object(
- interp.space.classtable['w_BlockContext']):
+ interp.space.w_BlockContext):
raise PrimitiveFailedError()
assert isinstance(w_block_ctx, model.W_PointersObject)
@@ -736,7 +736,7 @@
# Check that our arguments have pointers format and the right size:
if not w_args.getclass(interp.space).is_same_object(
- interp.space.classtable['w_Array']):
+ interp.space.w_Array):
raise PrimitiveFailedError()
if w_args.size() != exp_arg_cnt:
raise PrimitiveFailedError()
Modified: pypy/trunk/pypy/lang/smalltalk/shadow.py
==============================================================================
--- pypy/trunk/pypy/lang/smalltalk/shadow.py (original)
+++ pypy/trunk/pypy/lang/smalltalk/shadow.py Wed Feb 25 14:45:01 2009
@@ -323,7 +323,7 @@
def is_block_context(w_pointers, space):
method_or_argc = w_pointers.fetch(space, constants.MTHDCTX_METHOD)
return method_or_argc.getclass(space).is_same_object(
- space.classtable['w_SmallInteger'])
+ space.w_SmallInteger)
def fetch(self, n0):
if n0 == constants.CTXPART_SENDER_INDEX:
@@ -509,7 +509,7 @@
# 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(space).myblocksize()
- w_result = model.W_PointersObject(space.classtable['w_BlockContext'], contextsize)
+ 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)
@@ -603,7 +603,7 @@
# 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 = space.classtable['w_MethodContext'].as_class_get_shadow(space).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
Modified: pypy/trunk/pypy/translator/goal/targetimageloadingsmalltalk.py
==============================================================================
--- pypy/trunk/pypy/translator/goal/targetimageloadingsmalltalk.py (original)
+++ pypy/trunk/pypy/translator/goal/targetimageloadingsmalltalk.py Wed Feb 25 14:45:01 2009
@@ -41,14 +41,15 @@
print w_result.as_string()
return 0
+from pypy.lang.smalltalk import objspace
+space = objspace.ObjSpace()
+
def entry_point(argv):
if len(argv) > 1:
filename = argv[1]
else:
print "usage:", argv[0], "<image name>"
return -1
- from pypy.lang.smalltalk import objspace
- space = objspace.ObjSpace()
reader = squeakimage.ImageReader(space, squeakimage.Stream(DummyFile(filename)))
reader.initialize()
image = squeakimage.SqueakImage()
More information about the Pypy-commit
mailing list