Front page | perl.perl6.internals |
Postings from July 2002
[netlabs #754] [PATCH] Fix lookback op and add test
From:
Simon Glover
Date:
July 2, 2002 16:38
Subject:
[netlabs #754] [PATCH] Fix lookback op and add test
Message ID:
rt-754-3546.10.1740186613002@netlabs
# New Ticket Created by Simon Glover
# Please include the string: [netlabs #754]
# in the subject line of all future correspondence about this issue.
# <URL: http://bugs6.perl.org/rt2/Ticket/Display.html?id=754 >
This patch fixes the lookback ops to work properly when given negative
offsets, and adds a test of them to stacks.t
Simon
--- core.ops.old Tue Jul 2 19:05:23 2002
+++ core.ops Tue Jul 2 19:05:50 2002
@@ -3336,9 +3336,8 @@ op lookback(out INT, in INT) {
/* If they're counting up from the bottom, figure out where we'd be
if we counted down from the top */
if (depth < 0) {
- depth += 1;
total_depth = stack_height(interpreter, interpreter->user_stack);
- depth = total_depth - depth;
+ depth = total_depth + depth;
if (depth < 0) {
internal_exception(99, "Stack depth wrong");
}
@@ -3359,9 +3358,8 @@ op lookback(out STR, in INT) {
/* If they're counting up from the bottom, figure out where we'd be
if we counted down from the top */
if (depth < 0) {
- depth += 1;
total_depth = stack_height(interpreter, interpreter->user_stack);
- depth = total_depth - depth;
+ depth = total_depth + depth;
if (depth < 0) {
internal_exception(99, "Stack depth wrong");
}
@@ -3382,9 +3380,8 @@ op lookback(out NUM, in INT) {
/* If they're counting up from the bottom, figure out where we'd be
if we counted down from the top */
if (depth < 0) {
- depth += 1;
total_depth = stack_height(interpreter, interpreter->user_stack);
- depth = total_depth - depth;
+ depth = total_depth + depth;
if (depth < 0) {
internal_exception(99, "Stack depth wrong");
}
@@ -3405,9 +3402,8 @@ op lookback(out PMC, in INT) {
/* If they're counting up from the bottom, figure out where we'd be
if we counted down from the top */
if (depth < 0) {
- depth += 1;
total_depth = stack_height(interpreter, interpreter->user_stack);
- depth = total_depth - depth;
+ depth = total_depth + depth;
if (depth < 0) {
internal_exception(99, "Stack depth wrong");
}
--- t/op/stacks.t.old Tue Jul 2 18:46:52 2002
+++ t/op/stacks.t Tue Jul 2 19:17:48 2002
@@ -1,6 +1,6 @@
#! perl -w
-use Parrot::Test tests => 34;
+use Parrot::Test tests => 35;
use Test::More;
# Tests for stack operations, currently push*, push_*_c and pop*
@@ -736,6 +736,73 @@ $code .= " end\n";
$code .= "FAIL: end\n";
output_is($code, $output, "pushn & popn (deep)" );
+
+output_is(<<CODE, <<'OUTPUT', "lookback");
+@{[ $fp_equality_macro ]}
+ save 1
+ save 1.0
+ save "Foo"
+
+ new P12, .PerlHash
+ set P12["Apple"], "Banana"
+ save P12
+
+ lookback P0, 0
+ lookback S0, 1
+ lookback N0, 2
+ lookback I0, 3
+
+ set S2, P0["Apple"]
+ eq S2, "Banana", OK1
+ print "not "
+OK1: print "ok 1\\n"
+
+ eq I0, 1, OK2
+ print "not "
+OK2: print "ok 2\\n"
+
+ .fp_eq (N0, 1.0, OK3)
+ print "not "
+OK3: print "ok 3\\n"
+
+ eq S0, "Foo", OK4
+ print "not "
+OK4: print "ok 4\\n"
+
+ lookback I1, -1
+ lookback N1, -2
+ lookback S1, -3
+ lookback P1, -4
+
+ eq I0, 1, OK5
+ print "not "
+OK5: print "ok 5\\n"
+
+ .fp_eq (N0, 1.0, OK6)
+ print "not "
+OK6: print "ok 6\\n"
+
+ eq S0, "Foo", OK7
+ print "not "
+OK7: print "ok 7\\n"
+
+ set S3, P1["Apple"]
+ eq S3, "Banana", OK8
+ print "not "
+OK8: print "ok 8\\n"
+
+ end
+CODE
+ok 1
+ok 2
+ok 3
+ok 4
+ok 5
+ok 6
+ok 7
+ok 8
+OUTPUT
+
##############################
# set integer registers to some value given by $code...
-
[netlabs #754] [PATCH] Fix lookback op and add test
by Simon Glover