[pypy-svn] r48027 - in pypy/dist/pypy/lang/smalltalk: . test
niko at codespeak.net
niko at codespeak.net
Fri Oct 26 11:39:06 CEST 2007
Author: niko
Date: Fri Oct 26 11:39:06 2007
New Revision: 48027
Modified:
pypy/dist/pypy/lang/smalltalk/interpreter.py
pypy/dist/pypy/lang/smalltalk/primitives.py
pypy/dist/pypy/lang/smalltalk/test/test_interpreter.py
pypy/dist/pypy/lang/smalltalk/test/test_primitives.py
Log:
(niko, lukas)
adjust argument_count convention for primitives:
should not include rcvr
Modified: pypy/dist/pypy/lang/smalltalk/interpreter.py
==============================================================================
--- pypy/dist/pypy/lang/smalltalk/interpreter.py (original)
+++ pypy/dist/pypy/lang/smalltalk/interpreter.py Fri Oct 26 11:39:06 2007
@@ -131,8 +131,8 @@
if method.primitive:
func = primitives.prim_table[method.primitive]
try:
- # add +1 to account for the receiver
- w_result = func(interp, argcount + 1)
+ # note: argcount does not include rcvr
+ w_result = func(interp, argcount)
except primitives.PrimitiveFailedError:
pass # ignore this error and fall back to the Smalltalk version
else:
@@ -295,8 +295,8 @@
def callPrimitiveAndPush(self, primitive, selector,
argcount, interp):
try:
- # add one to the argcount to account for the self
- self.push(primitives.prim_table[primitive](interp, argcount + 1))
+ # note that argcount does not include self
+ self.push(primitives.prim_table[primitive](interp, argcount))
except primitives.PrimitiveFailedError:
self._sendSelfSelector(selector, argcount, interp)
@@ -382,7 +382,8 @@
primitives.PRIMITIVE_VALUE, "value", 0, interp)
def bytecodePrimValueWithArg(self, interp):
- raise MissingBytecode
+ self.callPrimitiveAndPush(
+ primitives.PRIMITIVE_VALUE, "value", 1, interp)
def bytecodePrimDo(self, interp):
self._sendSelfSelector("do:", 1, interp)
@@ -477,18 +478,21 @@
def initialize_bytecode_table():
result = [None] * 256
for entry in BYTECODE_RANGES:
- #def dump_func(f):
- # def wrapped(*args):
- # print "Bytecode: %s" % (f.__name__)
- # return f(*args)
- # return wrapped
+ def dump_func(f):
+ def wrapped(self, interp):
+ print "Bytecode: %s" % (f.__name__,)
+ res = f(self, interp)
+ print " stack after: %s" % (
+ interp.w_active_context.stack)
+ return res
+ return wrapped
if len(entry) == 2:
positions = [entry[0]]
else:
positions = range(entry[0], entry[1]+1)
for pos in positions:
- #result[pos] = dump_func(entry[-1])
- result[pos] = entry[-1]
+ result[pos] = dump_func(entry[-1])
+ #result[pos] = entry[-1]
assert None not in result
return result
Modified: pypy/dist/pypy/lang/smalltalk/primitives.py
==============================================================================
--- pypy/dist/pypy/lang/smalltalk/primitives.py (original)
+++ pypy/dist/pypy/lang/smalltalk/primitives.py Fri Oct 26 11:39:06 2007
@@ -74,7 +74,8 @@
assert (len_unwrap_spec == len(inspect.getargspec(func)[0]) + 1,
"wrong number of arguments")
unrolling_unwrap_spec = unrolling_iterable(enumerate(unwrap_spec))
- def wrapped(interp, argument_count):
+ def wrapped(interp, argument_count_m1):
+ argument_count = argument_count_m1 + 1 # to account for the rcvr
frame = interp.w_active_context
assert argument_count == len_unwrap_spec
if len(frame.stack) < len_unwrap_spec:
@@ -614,8 +615,9 @@
@expose_primitive(PRIMITIVE_VALUE)
def func(interp, argument_count):
# XXX XXX XXX XXX test me
- # If argument_count == 4, stack looks like:
- # 3 2 1 0
+ # argument_count does NOT include the receiver.
+ # This means that for argument_count == 3 the stack looks like:
+ # 3 2 1 Top
# Rcvr | Arg 0 | Arg1 | Arg 2
#
@@ -623,17 +625,18 @@
# Validate that we have a block on the stack and that it received
# the proper number of arguments:
- w_block_ctx = frame.peek(argument_count-1)
+ w_block_ctx = frame.peek(argument_count)
if not isinstance(w_block_ctx, model.W_BlockContext):
raise PrimitiveFailedError()
exp_arg_cnt = w_block_ctx.expected_argument_count()
- if argument_count != exp_arg_cnt + 1: # exp_arg_cnt doesn't count self
+ if argument_count != exp_arg_cnt: # exp_arg_cnt doesn't count self
raise PrimitiveFailedError()
- # Initialize the block stack from the contents of the stack:
- # Don't bother to copy the 'self' argument
+ # Initialize the block stack with the arguments that were
+ # pushed. Also pop the receiver.
block_args = frame.pop_n(exp_arg_cnt)
w_block_ctx.push_all(block_args)
+ frame.pop()
# Set some fields
w_block_ctx.pc = w_block_ctx.initialip
Modified: pypy/dist/pypy/lang/smalltalk/test/test_interpreter.py
==============================================================================
--- pypy/dist/pypy/lang/smalltalk/test/test_interpreter.py (original)
+++ pypy/dist/pypy/lang/smalltalk/test/test_interpreter.py Fri Oct 26 11:39:06 2007
@@ -463,18 +463,27 @@
storeAssociation(doubleExtendedDoAnythingBytecode + chr(7<<5) + chr(0))
-def test_block_copy_and_value():
+def interp_bc_and_check_result_is_7(bcodes):
+ bcode = "".join([chr(x) for x in bcodes])
+ interp = new_interpreter(bcode)
+ interp.w_active_context.w_method().literals = \
+ fakeliterals(wrap_int(3),
+ wrap_int(4))
+ res = interp.interpret()
+ assert res.value == 7
- bc_3_plus_4 = [ 137, 117, 200, 164, 4, 32, 33, 176, 125, 201, 124]
- #bc_x_plus_x_plus_1 = [ 137, 118, 200, 164, 7, 104, 16, 16, 176, 118, 176, 125, 32, 202, 124 ]
- #bc_x_plus_y = [ 137, 119, 200, 164, 6, 105, 104, 16, 17, 176, 125, 33, 34, 240, 124 ]
+def test_bc_3_plus_4():
+ interp_bc_and_check_result_is_7(
+ [ 137, 117, 200, 164, 4, 32, 33, 176, 125, 201, 124])
- for bcodes in [ bc_3_plus_4 ]: #, bc_x_plus_x_plus_1, bc_x_plus_y ]:
- bcode = "".join([chr(x) for x in bcodes])
- interp = new_interpreter(bcode)
- interp.w_active_context.w_method().literals = \
- fakeliterals(wrap_int(3),
- wrap_int(4))
- res = interp.interpret()
- assert res.value == 7
+def test_bc_x_plus_x_plus_1():
+ interp_bc_and_check_result_is_7(
+ [ 137, 118, 200, 164, 7, 104, 16, 16,
+ 176, 118, 176, 125, 32, 202, 124 ])
+
+def test_bc_x_plus_y():
+ py.test.skip("not yet working")
+ interp_bc_and_check_result_is_7(
+ [ 137, 119, 200, 164, 6, 105, 104, 16, 17,
+ 176, 125, 33, 34, 240, 124 ])
Modified: pypy/dist/pypy/lang/smalltalk/test/test_primitives.py
==============================================================================
--- pypy/dist/pypy/lang/smalltalk/test/test_primitives.py (original)
+++ pypy/dist/pypy/lang/smalltalk/test/test_primitives.py Fri Oct 26 11:39:06 2007
@@ -33,7 +33,7 @@
def prim(code, stack):
interp, argument_count = mock(stack)
- res = prim_table[code](interp, argument_count)
+ res = prim_table[code](interp, argument_count-1)
assert not len(interp.w_active_context.stack) # check args are consumed
return res
@@ -41,7 +41,7 @@
interp, argument_count = mock(stack)
orig_stack = list(interp.w_active_context.stack)
try:
- prim_table[code](interp, argument_count)
+ prim_table[code](interp, argument_count-1)
py.test.fail("Expected PrimitiveFailedError")
except PrimitiveFailedError:
assert interp.w_active_context.stack == orig_stack
More information about the Pypy-commit
mailing list