Author: Anton Gulenko <[email protected]>
Branch: storage
Changeset: r716:db7a0bfbcbee
Date: 2014-03-28 17:33 +0100
http://bitbucket.org/pypy/lang-smalltalk/changeset/db7a0bfbcbee/
Log: Added is_nil(space) as convenience method to test for nil. Mainly to
make different comparisons consistent (== vs is vs is_same_object).
Also made comparisons with w_true/w_false consistent (not often
enough for special method). Fixed test_interpreter.py to only put
W_Object instances into other W_Objects.
diff --git a/spyvm/interpreter.py b/spyvm/interpreter.py
--- a/spyvm/interpreter.py
+++ b/spyvm/interpreter.py
@@ -197,7 +197,7 @@
if not self.next_wakeup_tick == 0 and now >= self.next_wakeup_tick:
self.next_wakeup_tick = 0
semaphore = self.space.objtable["w_timerSemaphore"]
- if not semaphore.is_same_object(self.space.w_nil):
+ if not semaphore.is_nil(self.space):
wrapper.SemaphoreWrapper(self.space,
semaphore).signal(s_frame.w_self())
# We have no finalization process, so far.
# We do not support external semaphores.
@@ -445,7 +445,7 @@
def activate_unwind_context(self, interp):
# the first temp is executed flag for both #ensure: and #ifCurtailed:
- if self.gettemp(1) is self.space.w_nil:
+ if self.gettemp(1).is_nil(self.space):
self.settemp(1, self.space.w_true) # mark unwound
self.push(self.gettemp(0)) # push the first argument
try:
diff --git a/spyvm/interpreter_proxy.py b/spyvm/interpreter_proxy.py
--- a/spyvm/interpreter_proxy.py
+++ b/spyvm/interpreter_proxy.py
@@ -380,9 +380,9 @@
@expose_on_virtual_machine_proxy([oop], bool)
def booleanValueOf(w_object):
space = IProxy.space
- if w_object is space.w_true:
+ if space.w_true.is_same_object(w_object):
return True
- if w_object is space.w_false:
+ if space.w_false.is_same_object(w_object):
return False
raise ProxyFunctionFailed
diff --git a/spyvm/model.py b/spyvm/model.py
--- a/spyvm/model.py
+++ b/spyvm/model.py
@@ -123,6 +123,10 @@
SmallIntegers and Floats need a different implementation."""
return self is other
+ def is_nil(self, space):
+ """Return True, if the receiver represents the nil object in the given
Object Space."""
+ return self.is_same_object(space.w_nil)
+
def become(self, other):
"""Become swaps two objects.
False means swapping failed"""
diff --git a/spyvm/plugins/bitblt.py b/spyvm/plugins/bitblt.py
--- a/spyvm/plugins/bitblt.py
+++ b/spyvm/plugins/bitblt.py
@@ -38,7 +38,7 @@
def intOrIfNil(space, w_int, i):
- if w_int is space.w_nil:
+ if w_int.is_nil(space):
return i
elif isinstance(w_int, model.W_Float):
return intmask(int(space.unwrap_float(w_int)))
@@ -68,7 +68,7 @@
return s_form
def loadHalftone(self, w_halftone_form):
- if w_halftone_form is self.space.w_nil:
+ if w_halftone_form.is_nil(self.space):
return None
elif isinstance(w_halftone_form, model.W_WordsObject):
# Already a bitmap
@@ -94,7 +94,7 @@
self.w_destForm = self.fetch(0)
self.dest = self.loadForm(self.w_destForm)
self.w_sourceForm = self.fetch(1)
- if self.w_sourceForm is not self.space.w_nil:
+ if not self.w_sourceForm.is_nil(self.space):
self.source = self.loadForm(self.w_sourceForm)
else:
self.source = None
@@ -739,7 +739,7 @@
if self.size() < 5:
return
self.w_bits = self.fetch(0)
- if self.w_bits is self.space.w_nil:
+ if self.w_bits.is_nil(self.space):
return
if not (isinstance(self.w_bits, model.W_WordsObject) or
isinstance(self.w_bits, model.W_DisplayBitmap)):
return
@@ -755,7 +755,7 @@
return
w_offset = self.fetch(4)
assert isinstance(w_offset, model.W_PointersObject)
- if not w_offset is self.space.w_nil:
+ if not w_offset.is_nil(self.space):
self.offsetX = self.intOrIfNil(w_offset.fetch(self.space, 0), 0)
self.offsetY = self.intOrIfNil(w_offset.fetch(self.space, 1), 0)
self.pixPerWord = 32 / self.depth
diff --git a/spyvm/primitives.py b/spyvm/primitives.py
--- a/spyvm/primitives.py
+++ b/spyvm/primitives.py
@@ -1157,7 +1157,7 @@
@expose_primitive(FILE_OPEN, unwrap_spec=[object, str, object])
def func(interp, s_frame, w_rcvr, filename, w_writeable_flag):
- if w_writeable_flag is interp.space.w_true:
+ if w_writeable_flag.is_same_object(interp.space.w_true):
mode = os.O_RDWR | os.O_CREAT | os.O_TRUNC
else:
mode = os.O_RDONLY
diff --git a/spyvm/shadow.py b/spyvm/shadow.py
--- a/spyvm/shadow.py
+++ b/spyvm/shadow.py
@@ -83,7 +83,7 @@
return find_storage_for_objects(self.space, [w_val])
@staticmethod
def static_can_contain(space, w_val):
- return w_val == space.w_nil
+ return isinstance(w_val, model.W_Object) and w_val.is_nil(space)
class AbstractValueOrNilStorageMixin(object):
# Class must provide: wrap, unwrap, nil_value, is_nil_value, wrapper_class
@@ -108,7 +108,7 @@
return self.wrap(self.space, val)
def do_store(self, n0, w_val):
- if w_val == self.space.w_nil:
+ if w_val.is_nil(self.space):
self.storage[n0] = self.nil_value
else:
self.storage[n0] = self.unwrap(self.space, w_val)
@@ -116,7 +116,7 @@
# This is to avoid code duplication
@objectmodel.specialize.arg(0)
def _value_or_nil_can_handle(cls, space, w_val):
- return w_val == space.w_nil or \
+ return isinstance(w_val, model.W_Object) and w_val.is_nil(space) or \
(isinstance(w_val, cls.wrapper_class) \
and not cls.is_nil_value(cls.unwrap(space, w_val)))
@@ -338,7 +338,7 @@
def store_w_superclass(self, w_class):
superclass = self._s_superclass
- if w_class is None or w_class.is_same_object(self.space.w_nil):
+ if w_class is None or w_class.is_nil(self.space):
if superclass: superclass.detach_s_class(self)
self._s_superclass = None
else:
@@ -352,7 +352,7 @@
def store_w_methoddict(self, w_methoddict):
methoddict = self._s_methoddict
- if w_methoddict is None or
w_methoddict.is_same_object(self.space.w_nil):
+ if w_methoddict is None or w_methoddict.is_nil(self.space):
if methoddict: methoddict.s_class = None
self._s_methoddict = None
else:
@@ -554,7 +554,7 @@
self.methoddict = {}
for i in range(size):
w_selector = self.w_self().fetch(self.space,
constants.METHODDICT_NAMES_INDEX+i)
- if not w_selector.is_same_object(self.space.w_nil):
+ if not w_selector.is_nil(self.space):
if not isinstance(w_selector, model.W_BytesObject):
pass
# TODO: Check if there's more assumptions about this.
@@ -713,7 +713,7 @@
def store_w_sender(self, w_sender):
assert isinstance(w_sender, model.W_PointersObject)
- if w_sender.is_same_object(self.space.w_nil):
+ if w_sender.is_nil(self.space):
self._s_sender = None
else:
self.store_s_sender(w_sender.as_context_get_shadow(self.space))
@@ -727,7 +727,7 @@
return self._s_sender
def store_unwrap_pc(self, w_pc):
- if w_pc.is_same_object(self.space.w_nil):
+ if w_pc.is_nil(self.space):
self.store_pc(-1)
else:
pc = self.space.unwrap_int(w_pc)
@@ -762,7 +762,7 @@
assert self == e.s_context
def is_returned(self):
- return self.pc() == -1 and self.w_sender is self.space.w_nil
+ return self.pc() == -1 and self.w_sender.is_nil(self.space)
# ______________________________________________________________________
# Method that contains the bytecode for this method/block context
@@ -1147,7 +1147,7 @@
return self.size() - self.tempsize()
def is_closure_context(self):
- return self.w_closure_or_nil is not self.space.w_nil
+ return not self.w_closure_or_nil.is_nil(self.space)
def __str__(self):
retval = '\nMethodContext of:'
diff --git a/spyvm/squeakimage.py b/spyvm/squeakimage.py
--- a/spyvm/squeakimage.py
+++ b/spyvm/squeakimage.py
@@ -299,7 +299,7 @@
if self.special_object(so_index).w_object is None:
self.special_object(so_index).w_object = w_object
else:
- if self.special_object(0).w_object is not self.space.w_nil:
+ if not self.special_object(0).w_object.is_nil(self.space):
raise Warning('Object found in multiple places in the
special objects array')
def special_object(self, index):
@@ -382,7 +382,7 @@
def run_spy_hacks(self, space):
pass
# w_display = space.objtable["w_display"]
- # if w_display is not None and w_display is not space.w_nil:
+ # if w_display is not None and not w_display.is_nil(space):
# if space.unwrap_int(w_display.fetch(space, 3)) < 8:
# # non-native indexed color depth not well supported
# w_display.store(space, 3, space.wrap_int(8))
diff --git a/spyvm/test/test_interpreter.py b/spyvm/test/test_interpreter.py
--- a/spyvm/test/test_interpreter.py
+++ b/spyvm/test/test_interpreter.py
@@ -6,6 +6,7 @@
def setup_module():
space, interp = create_space_interp(bootstrap = True)
+ w = space.w
copy_to_module(locals(), __name__)
def teardown_module():
@@ -26,6 +27,15 @@
nlr.s_target_context.push(nlr.value)
return nlr.s_target_context.w_self()
+def assert_list(list, expected):
+ for i in range(len(list)):
+ exp = expected[i]
+ if isinstance(exp, str):
+ assert exp == list[i].as_string()
+ if not isinstance(exp, model.W_Object):
+ exp = w(exp)
+ assert list[i].is_same_object(exp)
+
# expose the bytecode's values as global constants.
# Bytecodes that have a whole range are exposed as global functions:
# call them with an argument 'n' to get the bytecode number 'base + n'.
@@ -103,7 +113,7 @@
w_method.setliterals([model.W_PointersObject(space, None, 2)])
if receiver is None:
receiver = space.w_nil
- s_frame = w_method.as_compiledmethod_get_shadow(space).create_frame(space,
receiver, ["foo", "bar"])
+ s_frame = w_method.as_compiledmethod_get_shadow(space).create_frame(space,
receiver, [space.w("foo"), space.w("bar")])
return s_frame.w_self(), s_frame
def new_frame(bytes, receiver=None):
@@ -117,31 +127,31 @@
w_method.islarge = 1
w_method.argsize=2
w_method.tempsize=8
- s_frame = w_method.as_compiledmethod_get_shadow(space).create_frame(space,
"receiver", ["foo", "bar"])
+ s_frame = w_method.as_compiledmethod_get_shadow(space).create_frame(space,
w("receiver"), [w("foo"), w("bar")])
w_frame = s_frame.w_self()
- assert s_frame.w_receiver() == "receiver"
- assert s_frame.gettemp(0) == "foo"
- assert s_frame.gettemp(1) == "bar"
- assert s_frame.gettemp(2) is space.w_nil
- s_frame.settemp(2, "spam")
- assert s_frame.gettemp(2) == "spam"
+ assert s_frame.w_receiver().as_string() == "receiver"
+ assert s_frame.gettemp(0).as_string() == "foo"
+ assert s_frame.gettemp(1).as_string() == "bar"
+ assert s_frame.gettemp(2).is_nil(space)
+ s_frame.settemp(2, w("spam"))
+ assert s_frame.gettemp(2).as_string() == "spam"
assert s_frame.getbytecode() == ord("h")
assert s_frame.getbytecode() == ord("e")
assert s_frame.getbytecode() == ord("l")
def test_push_pop():
_, frame = new_frame("")
- frame.push(12)
- frame.push(34)
- frame.push(56)
- assert frame.peek(2) == 12
- assert frame.pop() == 56
- assert frame.top() == 34
+ frame.push(w(12))
+ frame.push(w(34))
+ frame.push(w(56))
+ assert frame.peek(2).value == 12
+ assert frame.pop().value == 56
+ assert frame.top().value == 34
frame.pop_n(0)
- assert frame.top() == 34
- frame.push(56)
+ assert frame.top().value == 34
+ frame.push(w(56))
frame.pop_n(2)
- assert frame.top() == 12
+ assert frame.top().value == 12
def test_unknownBytecode():
w_frame, s_frame = new_frame(unknownBytecode)
@@ -158,26 +168,26 @@
pushReceiverVariableBytecode(1) +
pushReceiverVariableBytecode(2))):
w_demo = bootstrap_class(3).as_class_get_shadow(space).new()
- w_demo.store(space, 0, "egg")
- w_demo.store(space, 1, "bar")
- w_demo.store(space, 2, "baz")
+ w_demo.store(space, 0, w("egg"))
+ w_demo.store(space, 1, w("bar"))
+ w_demo.store(space, 2, w("baz"))
w_frame, s_frame = new_frame(bytecode, receiver = w_demo)
s_frame = w_frame.as_context_get_shadow(space)
step_in_interp(s_frame)
step_in_interp(s_frame)
step_in_interp(s_frame)
- assert s_frame.stack() == ["egg", "bar", "baz"]
+ assert_list(s_frame.stack(), ["egg", "bar", "baz"])
def
test_pushTemporaryVariableBytecode(bytecode=(pushTemporaryVariableBytecode(0) +
pushTemporaryVariableBytecode(1) +
pushTemporaryVariableBytecode(2))):
w_frame, s_frame = new_frame(bytecode)
s_frame = w_frame.as_context_get_shadow(space)
- s_frame.settemp(2, "temp")
+ s_frame.settemp(2, w("temp"))
step_in_interp(s_frame)
step_in_interp(s_frame)
step_in_interp(s_frame)
- assert s_frame.stack() == ["foo", "bar", "temp"]
+ assert_list(s_frame.stack(), ["foo", "bar", "temp"])
def test_pushLiteralConstantBytecode(bytecode=pushLiteralConstantBytecode(0) +
pushLiteralConstantBytecode(1) +
@@ -187,18 +197,16 @@
step_in_interp(s_frame)
step_in_interp(s_frame)
step_in_interp(s_frame)
- assert s_frame.stack() == [fakesymbol("a"),
- fakesymbol("b"),
- fakesymbol("c")]
+ assert_list(s_frame.stack(), [fakesymbol("a"), fakesymbol("b"),
fakesymbol("c")])
def test_pushLiteralVariableBytecode(bytecode=pushLiteralVariableBytecode(0)):
w_association = bootstrap_class(2).as_class_get_shadow(space).new()
- w_association.store(space, 0, "mykey")
- w_association.store(space, 1, "myvalue")
+ w_association.store(space, 0, w("mykey"))
+ w_association.store(space, 1, w("myvalue"))
w_frame, s_frame = new_frame(bytecode)
s_frame.w_method().setliterals( fakeliterals(space, w_association))
step_in_interp(s_frame)
- assert s_frame.stack() == ["myvalue"]
+ assert_list(s_frame.stack(), ["myvalue"])
def
test_storeAndPopReceiverVariableBytecode(bytecode=storeAndPopReceiverVariableBytecode,
popped=True):
@@ -212,13 +220,13 @@
if popped:
assert s_frame.stack() == []
else:
- assert s_frame.stack() == [space.w_true]
+ assert_list(s_frame.stack(), [space.w_true])
for test_index in range(8):
if test_index == index:
assert w_object.fetch(space,
test_index).is_same_object(space.w_true)
else:
- assert w_object.fetch(space, test_index) is space.w_nil
+ assert w_object.fetch(space, test_index).is_nil(space)
def
test_storeAndPopTemporaryVariableBytecode(bytecode=storeAndPopTemporaryVariableBytecode):
for index in range(8):
@@ -230,9 +238,9 @@
for test_index in range(8):
print w_frame.fetch_all(s_frame.space)
if test_index == index:
- assert s_frame.gettemp(test_index) == space.w_true
+ assert s_frame.gettemp(test_index).is_same_object(space.w_true)
else:
- assert s_frame.gettemp(test_index) != space.w_true
+ assert not
s_frame.gettemp(test_index).is_same_object(space.w_true)
def test_pushConstantTrueBytecode():
w_frame, s_frame = new_frame(pushConstantTrueBytecode)
@@ -249,7 +257,7 @@
def test_pushConstantNilBytecode():
w_frame, s_frame = new_frame(pushConstantNilBytecode)
step_in_interp(s_frame)
- assert s_frame.pop().is_same_object(space.w_nil)
+ assert s_frame.pop().is_nil(space)
assert s_frame.stack() == []
def test_pushConstantMinusOneBytecode():
@@ -279,14 +287,14 @@
def test_pushActiveContextBytecode():
w_frame, s_frame = new_frame(pushActiveContextBytecode)
step_in_interp(s_frame)
- assert s_frame.pop() == w_frame
+ assert s_frame.pop().is_same_object(w_frame)
assert s_frame.stack() == []
def test_duplicateTopBytecode():
w_frame, s_frame = new_frame(pushConstantZeroBytecode +
duplicateTopBytecode)
step_in_interp(s_frame)
step_in_interp(s_frame)
- assert s_frame.stack() == [space.w_zero, space.w_zero]
+ assert_list(s_frame.stack(), [space.w_zero, space.w_zero])
def test_bytecodePrimBitAnd():
w_frame, s_frame = new_frame(pushConstantOneBytecode +
pushConstantTwoBytecode + bytecodePrimBitAnd)
@@ -364,14 +372,14 @@
step_in_interp(s_frame)
step_in_interp(s_frame)
step_in_interp(s_frame)
- assert s_frame.pop() == space.w_false
+ assert s_frame.pop().is_same_object(space.w_false)
assert s_frame.stack() == []
w_frame, s_frame = new_frame(pushConstantOneBytecode +
pushConstantOneBytecode + bytecodePrimEquivalent)
step_in_interp(s_frame)
step_in_interp(s_frame)
step_in_interp(s_frame)
- assert s_frame.pop() == space.w_true
+ assert s_frame.pop().is_same_object(space.w_true)
assert s_frame.stack() == []
def test_bytecodePrimNew():
@@ -447,7 +455,7 @@
w_active_context = step_in_interp(s_active_context)
s_active_context = w_active_context.as_context_get_shadow(space)
assert w_active_context == w_frame
- assert s_active_context.stack() == [result]
+ assert_list(s_active_context.stack(), [result])
def test_sendLiteralSelectorBytecode():
w_class = bootstrap_class(0)
@@ -554,7 +562,7 @@
w_frame, s_frame = new_frame(pushConstantTrueBytecode +
popStackBytecode)
step_in_interp(s_frame)
- assert s_frame.stack() == [space.w_true]
+ assert_list(s_frame.stack(), [space.w_true])
step_in_interp(s_frame)
assert s_frame.stack() == []
@@ -575,8 +583,8 @@
def storeAssociation(bytecode):
w_association = bootstrap_class(2).as_class_get_shadow(space).new()
- w_association.store(space, 0, "mykey")
- w_association.store(space, 1, "myvalue")
+ w_association.store(space, 0, w("mykey"))
+ w_association.store(space, 1, w("myvalue"))
w_frame, s_frame = new_frame(pushConstantOneBytecode + bytecode)
s_frame.w_method().setliterals(fakeliterals(space, w_association))
step_in_interp(s_frame)
@@ -627,9 +635,9 @@
s_frame.push(space.w_one)
s_frame.push(space.w_two)
step_in_interp(s_frame)
- assert s_frame.stack() == [space.w_true, space.w_false,
+ assert_list(s_frame.stack(), [space.w_true, space.w_false,
space.w_true, space.w_false,
- space.w_false, space.w_true]
+ space.w_false, space.w_true])
def test_singleExtendedSendBytecode():
w_class = bootstrap_class(0)
@@ -760,7 +768,7 @@
# ^ [ self ] value
assert interpret_bc(
[ 137, 117, 200, 164, 2, 112, 125, 201, 124 ],
- fakeliterals(space, space.wrap_int(3))) is space.w_nil
+ fakeliterals(space, space.wrap_int(3))).is_nil(space)
def test_bc_value_return():
# valueReturn
@@ -877,52 +885,52 @@
# Closure Bytecodes
def test_bc_pushNewArrayBytecode(bytecode=pushNewArrayBytecode):
w_frame, s_frame = new_frame(bytecode + chr(0x83))
- s_frame.push(fakeliterals(space, "egg"))
- s_frame.push(fakeliterals(space, "bar"))
- s_frame.push(fakeliterals(space, "baz"))
+ s_frame.push(w(fakeliterals(space, "egg")))
+ s_frame.push(w(fakeliterals(space, "bar")))
+ s_frame.push(w(fakeliterals(space, "baz")))
step_in_interp(s_frame)
array = s_frame.pop()
- assert array.at0(space, 0) == fakeliterals(space, "egg")
- assert array.at0(space, 1) == fakeliterals(space, "bar")
- assert array.at0(space, 2) == fakeliterals(space, "baz")
+ assert space.unwrap_array(array.at0(space, 0)) == fakeliterals(space,
"egg")
+ assert space.unwrap_array(array.at0(space, 1)) == fakeliterals(space,
"bar")
+ assert space.unwrap_array(array.at0(space, 2)) == fakeliterals(space,
"baz")
def test_bc_pushNewArray(bytecode=pushNewArrayBytecode):
w_frame, s_frame = new_frame(bytecode + chr(0x07))
step_in_interp(s_frame)
array = s_frame.pop()
assert array.size() == 7
- assert array.at0(space, 0) == space.w_nil
+ assert array.at0(space, 0).is_nil(space)
def test_bc_pushRemoteTempLongBytecode(bytecode = pushRemoteTempLongBytecode):
w_frame, s_frame = new_frame(bytecode + chr(0) + chr(0))
s_frame.settemp(0, space.w_Array.as_class_get_shadow(interp.space).new(2))
step_in_interp(s_frame)
- assert s_frame.top() == space.w_nil
+ assert s_frame.top().is_nil(space)
def setupTempArrayAndContext(bytecode):
# both indizes are 0-relative
w_frame, s_frame = new_frame(bytecode + chr(2) + chr(1))
- s_frame.push(fakeliterals(space, "english"))
- s_frame.push(fakeliterals(space, "bar"))
+ s_frame.push(w(fakeliterals(space, "english")))
+ s_frame.push(w(fakeliterals(space, "bar")))
temp_array = space.w_Array.as_class_get_shadow(interp.space).new(3)
- temp_array.atput0(space, 2, fakeliterals(space, "pub"))
+ temp_array.atput0(space, 2, w(fakeliterals(space, "pub")))
s_frame.settemp(1, temp_array)
step_in_interp(s_frame)
return s_frame, temp_array
def test_bc_pushRemoteTempLongBytecode2(bytecode = pushRemoteTempLongBytecode):
context, _ = setupTempArrayAndContext(bytecode)
- assert context.top() == fakeliterals(space, "pub")
+ assert space.unwrap_array(context.top()) == fakeliterals(space, "pub")
def test_bc_storeRemoteTempLongBytecode(bytecode =
storeRemoteTempLongBytecode):
context, temp_array = setupTempArrayAndContext(bytecode)
- assert context.top() == fakeliterals(space, "bar")
- assert temp_array.at0(space, 2) == fakeliterals(space, "bar")
+ assert space.unwrap_array(context.top()) == fakeliterals(space, "bar")
+ assert space.unwrap_array(temp_array.at0(space, 2)) == fakeliterals(space,
"bar")
def test_bc_storeAndPopRemoteTempLongBytecode(bytecode =
storeAndPopRemoteTempLongBytecode):
context, temp_array = setupTempArrayAndContext(bytecode)
- assert temp_array.at0(space, 2) == fakeliterals(space, "bar")
- assert context.top() == fakeliterals(space, "english")
+ assert space.unwrap_array(temp_array.at0(space, 2)) == fakeliterals(space,
"bar")
+ assert space.unwrap_array(context.top()) == fakeliterals(space, "english")
def test_bc_pushClosureCopyCopied0ValuesBytecode(bytecode =
pushClosureCopyCopiedValuesBytecode):
for i in (0, 0xF0, 0x0FF0, 0xFFF0):
@@ -937,16 +945,16 @@
def test_bc_pushClosureCopyCopied2ValuesBytecode(bytecode =
pushClosureCopyCopiedValuesBytecode):
w_frame, s_frame = new_frame(bytecode + chr(0x23) + chr(0) + chr(0))
- s_frame.push("english")
- s_frame.push("bar")
+ s_frame.push(w("english"))
+ s_frame.push(w("bar"))
pc = s_frame.pc()
step_in_interp(s_frame)
assert s_frame.pc() == pc + 4
closure = wrapper.BlockClosureWrapper(space, s_frame.top())
assert closure.startpc() == pc + 4 + 5
assert closure.outerContext() is s_frame._w_self
- assert closure.at0(0) == "english"
- assert closure.at0(1) == "bar"
+ assert closure.at0(0).as_string() == "english"
+ assert closure.at0(1).as_string() == "bar"
def test_blockclosure_valuevalue():
#someTest
diff --git a/spyvm/test/test_model.py b/spyvm/test/test_model.py
--- a/spyvm/test/test_model.py
+++ b/spyvm/test/test_model.py
@@ -34,7 +34,7 @@
w_myinstance = w_mycls.as_class_get_shadow(space).new()
assert isinstance(w_myinstance, model.W_PointersObject)
assert w_myinstance.getclass(space).is_same_object(w_mycls)
- assert w_myinstance.fetch(space, 0) is space.w_nil
+ assert w_myinstance.fetch(space, 0).is_nil(space)
py.test.raises(IndexError, lambda: w_myinstance.fetch(space, 3))
w_myinstance.store(space, 1, w_myinstance)
assert w_myinstance.fetch(space, 1) is w_myinstance
@@ -416,4 +416,4 @@
# When executed using pypy, del is not immediately executed.
# Thus the reference may linger until the next gc...
import gc; gc.collect()
- assert weak_object.fetch(space, 0) is space.w_nil
+ assert weak_object.fetch(space, 0).is_nil(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
@@ -328,7 +328,7 @@
w_q = space.w_Character.as_class_get_shadow(space).new()
vidx = constants.CHARACTER_VALUE_INDEX+1
ordq = ord("q")
- assert prim(primitives.INST_VAR_AT, [w_q, vidx]) == space.w_nil
+ assert prim(primitives.INST_VAR_AT, [w_q, vidx]).is_nil(space)
assert prim(primitives.INST_VAR_AT_PUT, [w_q, vidx, ordq]).value == ordq
assert prim(primitives.INST_VAR_AT, [w_q, vidx]).value == ordq
@@ -361,7 +361,7 @@
(primitives.PUSH_TWO, space.w_two),
]:
assert prim(code, [space.w_nil]).is_same_object(const)
- assert prim(primitives.PUSH_SELF,
[space.w_nil]).is_same_object(space.w_nil)
+ assert prim(primitives.PUSH_SELF, [space.w_nil]).is_nil(space)
assert prim(primitives.PUSH_SELF, ["a"]) is wrap("a")
def test_boolean():
@@ -451,7 +451,7 @@
def test_interrupt_semaphore():
prim(primitives.INTERRUPT_SEMAPHORE, [1, space.w_true])
- assert space.objtable["w_interrupt_semaphore"] is space.w_nil
+ assert space.objtable["w_interrupt_semaphore"].is_nil(space)
class SemaphoreInst(model.W_Object):
def getclass(self, space):
@@ -485,7 +485,7 @@
w_method = prim(primitives.NEW_METHOD, [space.w_CompiledMethod,
len(bytecode), 1025])
assert w_method.literalat0(space, 0).value == 1025
assert w_method.literalsize == 2
- assert w_method.literalat0(space, 1).is_same_object(space.w_nil)
+ assert w_method.literalat0(space, 1).is_nil(space)
assert w_method.bytes == ["\x00"] * len(bytecode)
def test_image_name():
@@ -567,7 +567,7 @@
w_outer_frame, s_initial_context = new_frame("<never called, but used for
method generation>")
w_block = prim(primitives.CLOSURE_COPY_WITH_COPIED_VALUES, map(wrap,
[w_outer_frame, 2, [wrap(1), wrap(2)]]), w_frame)
- assert w_block is not space.w_nil
+ assert not w_block.is_nil(space)
w_w_block = wrapper.BlockClosureWrapper(space, w_block)
assert w_w_block.startpc() is 5
assert w_w_block.at0(0) == wrap(1)
@@ -604,7 +604,7 @@
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.w_receiver().is_nil(space)
def test_primitive_closure_value_value():
s_initial_context, closure, s_new_context = build_up_closure_environment([
@@ -612,7 +612,7 @@
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.w_receiver().is_nil(space)
assert s_new_context.gettemp(0).as_string() == "first arg"
assert s_new_context.gettemp(1).as_string() == "second arg"
@@ -623,7 +623,7 @@
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.w_receiver().is_nil(space)
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"
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
@@ -171,7 +171,7 @@
def assert_contains_nils(w_obj):
for i in range(w_obj.size()):
- assert space.w_nil == w_obj.fetch(space, i)
+ assert w_obj.fetch(space, i).is_nil(space)
def test_attach_mc():
w_m = create_method()
@@ -257,7 +257,7 @@
s_methoddict.sync_method_cache()
i = 0
key = s_methoddict.w_self().fetch(s_methoddict.space,
constants.METHODDICT_NAMES_INDEX+i)
- while key is space.w_nil:
+ while key.is_nil(space):
i = i + 1
key = s_methoddict.w_self().fetch(s_methoddict.space,
constants.METHODDICT_NAMES_INDEX+i)
@@ -295,9 +295,9 @@
def test_returned_contexts_pc():
w_context = methodcontext()
s_context = w_context.as_methodcontext_get_shadow(space)
- assert w_context.fetch(space, constants.CTXPART_PC_INDEX) is not
space.w_nil
+ assert not w_context.fetch(space, constants.CTXPART_PC_INDEX).is_nil(space)
s_context.mark_returned()
- assert w_context.fetch(space, constants.CTXPART_PC_INDEX) is space.w_nil
+ assert w_context.fetch(space, constants.CTXPART_PC_INDEX).is_nil(space)
def test_methodcontext_s_home():
w_context = methodcontext()
diff --git a/spyvm/test/test_strategies.py b/spyvm/test/test_strategies.py
--- a/spyvm/test/test_strategies.py
+++ b/spyvm/test/test_strategies.py
@@ -34,7 +34,7 @@
for i in range(arr.size()):
w_val = arr.fetch(space, i)
if expected[i] == w_nil:
- assert w_val == w_nil
+ assert w_val.is_nil(space)
elif isinstance(expected[i], int):
assert isinstance(w_val, model.W_SmallInteger)
assert space.unwrap_int(w_val) == expected[i]
@@ -79,7 +79,7 @@
def test_List_fetch():
a = list_arr(5)
assert a.fetch(space, 0).getclass(space) == class_Array
- assert a.fetch(space, 4) == w_nil
+ assert a.fetch(space, 4).is_nil(space)
def test_List_size():
a = list_arr(5)
diff --git a/spyvm/test/test_wrapper.py b/spyvm/test/test_wrapper.py
--- a/spyvm/test/test_wrapper.py
+++ b/spyvm/test/test_wrapper.py
@@ -97,7 +97,7 @@
w_last = space.w_nil
for w_process in processes_w[::-1]:
w_first = newprocess(w_first, w_processlist)._w_self
- if w_last is space.w_nil:
+ if w_last.is_nil(space):
w_last = w_first
pl = wrapper.ProcessListWrapper(space, w_processlist)
pl.store_first_link(w_first)
@@ -155,8 +155,8 @@
w_frame = process.suspend(space.w_true)
process_list =
wrapper.scheduler(space).get_process_list(process.priority())
assert process_list.first_link() is process_list.last_link()
- assert process_list.first_link() is space.w_nil
- assert process.my_list() is space.w_nil
+ assert process_list.first_link().is_nil(space)
+ assert process.my_list().is_nil(space)
def test_suspend_active(self):
suspended_context = new_frame()
@@ -166,8 +166,8 @@
old_process.suspend(current_context)
process_list =
wrapper.scheduler(space).get_process_list(old_process.priority())
assert process_list.first_link() is process_list.last_link()
- assert process_list.first_link() is space.w_nil
- assert old_process.my_list() is space.w_nil
+ assert process_list.first_link().is_nil(space)
+ assert old_process.my_list().is_nil(space)
assert old_process.suspended_context() is current_context
assert wrapper.scheduler(space).active_process() is process._w_self
diff --git a/spyvm/wrapper.py b/spyvm/wrapper.py
--- a/spyvm/wrapper.py
+++ b/spyvm/wrapper.py
@@ -103,12 +103,12 @@
def suspend(self, w_current_frame):
if self.is_active_process():
- assert self.my_list().is_same_object(self.space.w_nil)
+ assert self.my_list().is_nil(self.space)
w_process = scheduler(self.space).pop_highest_priority_process()
self.store_suspended_context(w_current_frame)
return ProcessWrapper(self.space, w_process).activate()
else:
- if self.my_list() is not self.space.w_nil:
+ if not self.my_list().is_nil(self.space):
process_list = ProcessListWrapper(self.space, self.my_list())
process_list.remove(self._w_self)
self.store_my_list(self.space.w_nil)
@@ -119,7 +119,7 @@
last_link, store_last_link = make_getter_setter(1)
def is_empty_list(self):
- return self.first_link().is_same_object(self.space.w_nil)
+ return self.first_link().is_nil(self.space)
def add_last_link(self, w_object):
if self.is_empty_list():
@@ -147,12 +147,12 @@
else:
current = LinkWrapper(self.space, self.first_link())
w_next = current.next_link()
- while not w_next.is_same_object(self.space.w_nil):
+ while not w_next.is_nil(self.space):
if w_next.is_same_object(w_link):
LinkWrapper(self.space,
w_link).store_next_link(self.space.w_nil)
w_tail = LinkWrapper(self.space, w_next).next_link()
current.store_next_link(w_tail)
- if w_tail.is_same_object(self.space.w_nil):
+ if w_tail.is_nil(self.space):
self.store_last_link(current._w_self)
return
current = LinkWrapper(self.space, w_next)
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit