Author: Lars Wassermann <[email protected]>
Branch:
Changeset: r123:cb75ad6978de
Date: 2013-03-06 21:06 +0100
http://bitbucket.org/pypy/lang-smalltalk/changeset/cb75ad6978de/
Log: (cfbolz, lwassermann): added attribute information to the model
classes to prevent the typechecker from pulling variables up In the
wake, added some assertions to pacify the typechecker
diff --git a/spyvm/model.py b/spyvm/model.py
--- a/spyvm/model.py
+++ b/spyvm/model.py
@@ -25,7 +25,8 @@
class W_Object(object):
"""Root of Squeak model, abstract."""
- __slots__ = () # no RPython-level instance variables allowed in W_Object
+ _attrs_ = [] # no RPython-level instance variables allowed in W_Object
+ _settled_ = True
def size(self):
"""Return bytesize that conforms to Blue Book.
@@ -112,6 +113,7 @@
class W_SmallInteger(W_Object):
"""Boxed integer value"""
# TODO can we tell pypy that its never larger then 31-bit?
+ _attrs_ = ['value']
__slots__ = ('value',) # the only allowed slot here
_immutable_fields_ = ["value"]
@@ -152,6 +154,8 @@
class W_Float(W_Object):
"""Boxed float value."""
+ _attrs_ = ['value']
+
def __init__(self, value):
self.value = value
@@ -191,6 +195,8 @@
class W_AbstractObjectWithIdentityHash(W_Object):
"""Object with explicit hash (ie all except small
ints and floats)."""
+ _attrs_ = ['hash']
+
#XXX maybe this is too extreme, but it's very random
hash_generator = rrandom.Random()
UNASSIGNED_HASH = sys.maxint
@@ -215,6 +221,7 @@
class W_AbstractObjectWithClassReference(W_AbstractObjectWithIdentityHash):
"""Objects with arbitrary class (ie not CompiledMethod, SmallInteger or
Float)."""
+ _attrs_ = ['w_class']
def __init__(self, w_class):
if w_class is not None: # it's None only for testing and space
generation
@@ -251,6 +258,7 @@
class W_PointersObject(W_AbstractObjectWithClassReference):
"""Common object."""
+ _attrs_ = ['_shadow', '_vars']
_shadow = None # Default value
@@ -371,6 +379,8 @@
return w_result
class W_BytesObject(W_AbstractObjectWithClassReference):
+ _attrs_ = ['bytes']
+
def __init__(self, w_class, size):
W_AbstractObjectWithClassReference.__init__(self, w_class)
assert isinstance(size, int)
@@ -421,6 +431,8 @@
return w_result
class W_WordsObject(W_AbstractObjectWithClassReference):
+ _attrs_ = ['words']
+
def __init__(self, w_class, size):
W_AbstractObjectWithClassReference.__init__(self, w_class)
self.words = [r_uint(0)] * size
diff --git a/spyvm/shadow.py b/spyvm/shadow.py
--- a/spyvm/shadow.py
+++ b/spyvm/shadow.py
@@ -298,12 +298,16 @@
def attach_shadow(self):
AbstractShadow.attach_shadow(self)
+ w_self = self.w_self()
+ assert isinstance(w_self, model.W_PointersObject)
for i in range(self._w_self_size):
self.copy_from_w_self(i)
- self.w_self()._vars = None
+ w_self._vars = None
def detach_shadow(self):
- self.w_self()._vars = [self.space.w_nil] * self._w_self_size
+ w_self = self.w_self()
+ assert isinstance(w_self, model.W_PointersObject)
+ 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)
@@ -325,6 +329,7 @@
def __init__(self, space, w_self):
self._s_sender = None
AbstractRedirectingShadow.__init__(self, space, w_self)
+ self.instances_w = None
@staticmethod
def is_block_context(w_pointers, space):
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
@@ -492,24 +492,26 @@
assert s_new_context.w_receiver() is space.w_nil
def test_primitive_closure_value_value():
- s_initial_context, closure, s_new_context =
build_up_closure_environment(["first arg", "second arg"])
+ s_initial_context, closure, s_new_context = build_up_closure_environment([
+ wrap("first arg"), wrap("second arg")])
assert s_new_context.w_closure_or_nil is closure
assert s_new_context.s_sender() is s_initial_context
assert s_new_context.w_receiver() is space.w_nil
- assert s_new_context.gettemp(0) == "first arg"
- assert s_new_context.gettemp(1) == "second arg"
+ assert s_new_context.gettemp(0).as_string() == "first arg"
+ assert s_new_context.gettemp(1).as_string() == "second arg"
def test_primitive_closure_value_value_with_temps():
- s_initial_context, closure, s_new_context =
build_up_closure_environment(["first arg", "second arg"],
- copiedValues=['some value'])
+ s_initial_context, closure, s_new_context = build_up_closure_environment(
+ [wrap("first arg"), wrap("second arg")],
+ copiedValues=[wrap('some value')])
assert s_new_context.w_closure_or_nil is closure
assert s_new_context.s_sender() is s_initial_context
assert s_new_context.w_receiver() is space.w_nil
- assert s_new_context.gettemp(0) == "first arg"
- assert s_new_context.gettemp(1) == "second arg"
- assert s_new_context.gettemp(2) == "some value"
+ assert s_new_context.gettemp(0).as_string() == "first arg"
+ assert s_new_context.gettemp(1).as_string() == "second arg"
+ assert s_new_context.gettemp(2).as_string() == "some value"
def test_primitive_some_instance():
someInstance = map(space.wrap_list, [[1], [2]])
diff --git a/spyvm/wrapper.py b/spyvm/wrapper.py
--- a/spyvm/wrapper.py
+++ b/spyvm/wrapper.py
@@ -1,5 +1,5 @@
from spyvm import model, constants
-from spyvm.error import FatalError, WrapperException
+from spyvm.error import FatalError, WrapperException, PrimitiveFailedError
class Wrapper(object):
def __init__(self, space, w_self):
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit