cvsuser 03/07/16 17:40:21
Modified: t/op stacks.t
Log:
Tests for poptop, popbottom, savetop and restoretop
Revision Changes Path
1.30 +483 -13 parrot/t/op/stacks.t
Index: stacks.t
===================================================================
RCS file: /cvs/public/parrot/t/op/stacks.t,v
retrieving revision 1.29
retrieving revision 1.30
diff -u -w -r1.29 -r1.30
--- stacks.t 9 Jul 2003 15:20:25 -0000 1.29
+++ stacks.t 17 Jul 2003 00:40:21 -0000 1.30
@@ -1,6 +1,6 @@
#! perl -w
-use Parrot::Test tests => 43;
+use Parrot::Test tests => 56;
use Test::More;
# Tests for stack operations, currently push*, push_*_c and pop*
@@ -84,10 +84,59 @@
3031
OUTPUT
-output_is(<<"CODE", <<OUTPUT, "poptopi");
+output_is(<<"CODE", <<OUTPUT, "pushtopi & poptopi");
[EMAIL PROTECTED] set_int_regs( sub { $_[0]} )]}
+ pushtopi
[EMAIL PROTECTED] set_int_regs( sub {-$_[0]} )]}
+ poptopi
[EMAIL PROTECTED] print_int_regs() ]}
+ end
+CODE
+0-1-2-3-4
+-5-6-7-8-9
+-10-11-12-13-14
+-1516171819
+2021222324
+2526272829
+3031
+OUTPUT
+
+output_is(<<"CODE", <<OUTPUT, "pushbottomi & popbottomi");
[EMAIL PROTECTED] set_int_regs( sub { $_[0]} )]}
+ pushbottomi
[EMAIL PROTECTED] set_int_regs( sub {-$_[0]} )]}
+ popbottomi
[EMAIL PROTECTED] print_int_regs() ]}
+ end
+CODE
+01234
+56789
+1011121314
+15-16-17-18-19
+-20-21-22-23-24
+-25-26-27-28-29
+-30-31
+OUTPUT
+
+output_is(<<"CODE", <<OUTPUT, "combining pushi with poptopi, popbottomi");
[EMAIL PROTECTED] set_int_regs( sub { $_[0]} )]}
+ pushi
[EMAIL PROTECTED] set_int_regs( sub {-$_[0]} )]}
+ poptopi
[EMAIL PROTECTED] print_int_regs() ]}
+ print "\\n"
+ popbottomi
[EMAIL PROTECTED] print_int_regs() ]}
+ print "\\n"
+
+ cleari
+
@{[ set_int_regs( sub { $_[0]} )]}
pushi
@{[ set_int_regs( sub {-$_[0]} )]}
+ popbottomi
[EMAIL PROTECTED] print_int_regs() ]}
+ print "\\n"
poptopi
@{[ print_int_regs() ]}
end
@@ -99,6 +148,88 @@
2021222324
2526272829
3031
+
+01234
+56789
+1011121314
+1516171819
+2021222324
+2526272829
+3031
+
+1617181920
+2122232425
+2627282930
+31-16-17-18-19
+-20-21-22-23-24
+-25-26-27-28-29
+-30-31
+
+1617181920
+2122232425
+2627282930
+310123
+45678
+910111213
+1415
+OUTPUT
+
+output_is(<<"CODE", <<OUTPUT, "combining popi with pushtopi, pushbottomi");
[EMAIL PROTECTED] set_int_regs( sub {$_[0]} ) ]}
+ pushtopi
[EMAIL PROTECTED] set_int_regs( sub {-$_[0]} ) ]}
+ pushbottomi
[EMAIL PROTECTED] set_int_regs( sub {0} ) ]}
[EMAIL PROTECTED] print_int_regs() ]}
+ print "\\n"
+ popi
[EMAIL PROTECTED] print_int_regs() ]}
+ print "\\n"
+
+ cleari
+
[EMAIL PROTECTED] set_int_regs( sub {$_[0]} ) ]}
+ pushbottomi
[EMAIL PROTECTED] set_int_regs( sub {-$_[0]} ) ]}
+ pushtopi
[EMAIL PROTECTED] set_int_regs( sub {0} ) ]}
[EMAIL PROTECTED] print_int_regs() ]}
+ print "\\n"
+ popi
[EMAIL PROTECTED] print_int_regs() ]}
+ end
+CODE
+00000
+00000
+00000
+00000
+00000
+00000
+00
+
+1617181920
+2122232425
+2627282930
+310-1-2-3
+-4-5-6-7-8
+-9-10-11-12-13
+-14-15
+
+00000
+00000
+00000
+00000
+00000
+00000
+00
+
+01234
+56789
+1011121314
+15-16-17-18-19
+-20-21-22-23-24
+-25-26-27-28-29
+-30-31
OUTPUT
my ($code, $output);
@@ -133,19 +264,103 @@
01010101010101010101010101010101
OUTPUT
-output_is(<<"CODE", <<'OUTPUT', 'poptopss');
+output_is(<<"CODE", <<'OUTPUT', 'pushtops & poptops');
[EMAIL PROTECTED] set_str_regs( sub {$_[0]%2} ) ]}
+ pushtops
[EMAIL PROTECTED] set_str_regs( sub {($_[0]+1) %2} ) ]}
[EMAIL PROTECTED] print_str_regs() ]}
+ print "\\n"
+ poptops
[EMAIL PROTECTED] print_str_regs() ]}
+ print "\\n"
+ end
+CODE
+10101010101010101010101010101010
+10101010101010100101010101010101
+OUTPUT
+
+output_is(<<"CODE", <<'OUTPUT', 'pushbottoms & popbottoms');
[EMAIL PROTECTED] set_str_regs( sub {$_[0]%2} ) ]}
+ pushbottoms
[EMAIL PROTECTED] set_str_regs( sub {($_[0]+1) %2} ) ]}
[EMAIL PROTECTED] print_str_regs() ]}
+ print "\\n"
+ popbottoms
[EMAIL PROTECTED] print_str_regs() ]}
+ print "\\n"
+ end
+CODE
+10101010101010101010101010101010
+01010101010101011010101010101010
+OUTPUT
+
+output_is(<<"CODE", <<OUTPUT, "combining pushs with poptops, popbottoms");
[EMAIL PROTECTED] set_str_regs( sub {$_[0]%2} ) ]}
+ pushs
[EMAIL PROTECTED] set_str_regs( sub {($_[0]+1) %2} ) ]}
[EMAIL PROTECTED] print_str_regs() ]}
+ print "\\n"
+ poptops
[EMAIL PROTECTED] print_str_regs() ]}
+ print "\\n"
+ popbottoms
[EMAIL PROTECTED] print_str_regs() ]}
+ print "\\n"
+
+ clears
+
@{[ set_str_regs( sub {$_[0]%2} ) ]}
pushs
@{[ set_str_regs( sub {($_[0]+1) %2} ) ]}
@{[ print_str_regs() ]}
print "\\n"
+ popbottoms
[EMAIL PROTECTED] print_str_regs() ]}
+ print "\\n"
poptops
@{[ print_str_regs() ]}
print "\\n"
+
end
CODE
10101010101010101010101010101010
10101010101010100101010101010101
+01010101010101010101010101010101
+10101010101010101010101010101010
+01010101010101011010101010101010
+01010101010101010101010101010101
+OUTPUT
+
+output_is(<<"CODE", <<OUTPUT, "combining pops with pushtops, pushbottoms");
[EMAIL PROTECTED] set_str_regs( sub {$_[0]} ) ]}
+ pushtops
[EMAIL PROTECTED] set_str_regs( sub {-$_[0]} ) ]}
+ pushbottoms
[EMAIL PROTECTED] set_str_regs( sub {0} ) ]}
[EMAIL PROTECTED] print_str_regs() ]}
+ print "\\n"
+ pops
[EMAIL PROTECTED] print_str_regs() ]}
+ print "\\n"
+
+ clears
+
[EMAIL PROTECTED] set_str_regs( sub {$_[0]} ) ]}
+ pushbottoms
[EMAIL PROTECTED] set_str_regs( sub {-$_[0]} ) ]}
+ pushtops
[EMAIL PROTECTED] set_str_regs( sub {0} ) ]}
[EMAIL PROTECTED] print_str_regs() ]}
+ print "\\n"
+ pops
[EMAIL PROTECTED] print_str_regs() ]}
+ print "\\n"
+ end
+CODE
+00000000000000000000000000000000
+161718192021222324252627282930310-1-2-3-4-5-6-7-8-9-10-11-12-13-14-15
+00000000000000000000000000000000
+0123456789101112131415-16-17-18-19-20-21-22-23-24-25-26-27-28-29-30-31
OUTPUT
($code, $output) = ();
@@ -176,26 +391,107 @@
print "Seem to have positive Nx after pop\\n"
branch ALLOK
ERROR: print "not ok\\n"
[EMAIL PROTECTED] print_num_regs() ]}
ALLOK: end
CODE
Seem to have negative Nx
Seem to have positive Nx after pop
OUTPUT
-output_is(<<"CODE", <<'OUTPUT', 'poptopn');
+output_is(<<"CODE", <<'OUTPUT', 'pushtopn & poptopn');
@{[ set_num_regs( sub { "1.0".$_ } ) ]}
- pushn
+ pushtopn
@{[ set_num_regs( sub { "-1.0".$_} ) ]}
poptopn
[EMAIL PROTECTED] check_num_regs() ]}
[EMAIL PROTECTED] check_num_regs(1) ]}
print "all ok\\n"
branch ALLOK
ERROR: print "not ok\\n"
[EMAIL PROTECTED] print_num_regs() ]}
ALLOK: end
CODE
all ok
OUTPUT
+output_is(<<"CODE", <<'OUTPUT', 'pushbottomn & popbottomn');
[EMAIL PROTECTED] set_num_regs( sub { "1.0".$_ } ) ]}
+ pushbottomn
[EMAIL PROTECTED] set_num_regs( sub { "-1.0".$_} ) ]}
+ popbottomn
[EMAIL PROTECTED] check_num_regs(0) ]}
+ print "all ok\\n"
+ branch ALLOK
+ERROR: print "not ok\\n"
[EMAIL PROTECTED] print_num_regs() ]}
+ALLOK: end
+CODE
+all ok
+OUTPUT
+
+output_is(<<"CODE", <<OUTPUT, "combining pushn with poptopn, popbottomn");
[EMAIL PROTECTED] set_num_regs( sub { "1.0".$_ } ) ]}
+ pushn
[EMAIL PROTECTED] set_num_regs( sub { "-1.0".$_} ) ]}
+ poptopn
[EMAIL PROTECTED] check_num_regs(1) ]}
[EMAIL PROTECTED] set_num_regs( sub { "-1.0".$_} ) ]}
+ popbottomn
[EMAIL PROTECTED] check_num_regs(0) ]}
+
+ print "ok 1\\n"
+ clearn
+
[EMAIL PROTECTED] set_num_regs( sub { "1.0".$_ } ) ]}
+ pushn
[EMAIL PROTECTED] set_num_regs( sub { "-1.0".$_} ) ]}
+ popbottomn
[EMAIL PROTECTED] check_num_regs(0) ]}
[EMAIL PROTECTED] set_num_regs( sub { "-1.0".$_} ) ]}
+ poptopn
[EMAIL PROTECTED] check_num_regs(1) ]}
+
+ print "ok 2\\n"
+ branch ALLOK
+ERROR: print "not ok\\n"
[EMAIL PROTECTED] print_num_regs() ]}
+ALLOK: end
+CODE
+ok 1
+ok 2
+OUTPUT
+
+output_is(<<"CODE", <<OUTPUT, "combining popn with pushtopn, pushbottomn");
[EMAIL PROTECTED] $fp_equality_macro ]}
[EMAIL PROTECTED] set_num_regs( sub { "1.0".$_ } ) ]}
+ pushtopn
[EMAIL PROTECTED] set_num_regs( sub { "-1.0".$_} ) ]}
+ pushbottomn
+ popn
[EMAIL PROTECTED] check_num_regs(0) ]}
+ .fp_ne(N15, 1.031, ERROR)
+ .fp_ne(N16, -1.000, ERROR)
+
+ print "ok 1\\n"
+
[EMAIL PROTECTED] set_num_regs( sub { "1.0".$_ } ) ]}
+ pushbottomn
[EMAIL PROTECTED] set_num_regs( sub { "-1.0".$_} ) ]}
+ pushtopn
+ popn
[EMAIL PROTECTED] check_num_regs(0) ]}
+ .fp_ne(N15, 1.015, ERROR)
+ .fp_ne(N16, -1.016, ERROR)
+
+ print "ok 2\\n"
+ branch ALLOK
+ERROR: print "not ok\\n"
[EMAIL PROTECTED] print_num_regs() ]}
+ALLOK: end
+CODE
+ok 1
+ok 2
+OUTPUT
+
output_is(<<"CODE", <<'OUTPUT', 'pushp & popp');
new P0, .PerlString
set P0, "BUTTER IN HELL!\\n"
@@ -210,7 +506,37 @@
THERE'LL BE NO BUTTER IN HELL!
OUTPUT
-output_is(<<"CODE", <<'OUTPUT', 'poptopp');
+output_is(<<"CODE", <<'OUTPUT', 'pushtopp & poptopp');
[EMAIL PROTECTED] set_pmc_regs( sub {$_[0]%2} ) ]}
+ pushtopp
[EMAIL PROTECTED] set_pmc_regs( sub {($_[0]+1) %2} ) ]}
[EMAIL PROTECTED] print_pmc_regs() ]}
+ print "\\n"
+ poptopp
[EMAIL PROTECTED] print_pmc_regs() ]}
+ print "\\n"
+ end
+CODE
+10101010101010101010101010101010
+10101010101010100101010101010101
+OUTPUT
+
+output_is(<<"CODE", <<'OUTPUT', 'pushbottomp & popbottomp');
[EMAIL PROTECTED] set_pmc_regs( sub {$_[0]%2} ) ]}
+ pushbottomp
[EMAIL PROTECTED] set_pmc_regs( sub {($_[0]+1) %2} ) ]}
[EMAIL PROTECTED] print_pmc_regs() ]}
+ print "\\n"
+ popbottomp
[EMAIL PROTECTED] print_pmc_regs() ]}
+ print "\\n"
+ end
+CODE
+10101010101010101010101010101010
+01010101010101011010101010101010
+OUTPUT
+
+output_is(<<"CODE", <<OUTPUT, "combining pushp with poptopp, popbottomp");
@{[ set_pmc_regs( sub {$_[0]%2} ) ]}
pushp
@{[ set_pmc_regs( sub {($_[0]+1) %2} ) ]}
@@ -219,10 +545,64 @@
poptopp
@{[ print_pmc_regs() ]}
print "\\n"
+ popbottomp
[EMAIL PROTECTED] print_pmc_regs() ]}
+ print "\\n"
+
+ clearp
+
[EMAIL PROTECTED] set_pmc_regs( sub {$_[0]%2} ) ]}
+ pushp
[EMAIL PROTECTED] set_pmc_regs( sub {($_[0]+1) %2} ) ]}
[EMAIL PROTECTED] print_pmc_regs() ]}
+ print "\\n"
+ popbottomp
[EMAIL PROTECTED] print_pmc_regs() ]}
+ print "\\n"
+ poptopp
[EMAIL PROTECTED] print_pmc_regs() ]}
+ print "\\n"
+
end
CODE
10101010101010101010101010101010
10101010101010100101010101010101
+01010101010101010101010101010101
+10101010101010101010101010101010
+01010101010101011010101010101010
+01010101010101010101010101010101
+OUTPUT
+
+output_is(<<"CODE", <<OUTPUT, "combining popp with pushtopp, pushbottomp");
[EMAIL PROTECTED] set_pmc_regs( sub {$_[0]} ) ]}
+ pushtopp
[EMAIL PROTECTED] set_pmc_regs( sub {-$_[0]} ) ]}
+ pushbottomp
[EMAIL PROTECTED] set_pmc_regs( sub {0} ) ]}
[EMAIL PROTECTED] print_pmc_regs() ]}
+ print "\\n"
+ popp
[EMAIL PROTECTED] print_pmc_regs() ]}
+ print "\\n"
+
+ clearp
+
[EMAIL PROTECTED] set_pmc_regs( sub {$_[0]} ) ]}
+ pushbottomp
[EMAIL PROTECTED] set_pmc_regs( sub {-$_[0]} ) ]}
+ pushtopp
[EMAIL PROTECTED] set_pmc_regs( sub {0} ) ]}
[EMAIL PROTECTED] print_pmc_regs() ]}
+ print "\\n"
+ popp
[EMAIL PROTECTED] print_pmc_regs() ]}
+ print "\\n"
+ end
+CODE
+00000000000000000000000000000000
+161718192021222324252627282930310-1-2-3-4-5-6-7-8-9-10-11-12-13-14-15
+00000000000000000000000000000000
+0123456789101112131415-16-17-18-19-20-21-22-23-24-25-26-27-28-29-30-31
OUTPUT
output_is(<<"CODE", <<'OUTPUT', 'poptopp, aggregate PMCs');
@@ -791,6 +1171,71 @@
test ok
OUTPUT
+output_is(<<"CODE", <<'OUTPUT', "savetop/restoretop");
[EMAIL PROTECTED] $fp_equality_macro ]}
+ new P15, .PerlHash
+ new P16, .PerlHash
+ set I15, 1
+ set I16, 2
+ set N15, 1.0
+ set N16, 2.0
+ set S15, "one"
+ set S16, "two"
+ set P15["one"], 1
+ set P16["two"], 2
+
+ savetop
+
+ new P15, .PerlHash
+ new P16, .PerlHash
+ set I15, 3
+ set I16, 4
+ set N15, 3.0
+ set N16, 4.0
+ set S15, "three"
+ set S16, "four"
+ set P15["three"], 3
+ set P16["four"], 4
+
+ restoretop
+
+ ne I15, 3, ERROR
+ ne I16, 2, ERROR
+ .fp_ne(N15, 3.0, ERROR)
+ .fp_ne(N16, 2.0, ERROR)
+ ne S15, "three", ERROR
+ ne S16, "two", ERROR
+ set I1, P15["three"]
+ ne I1, 3, ERROR
+ set I2, P16["two"]
+ ne I2, 2, ERROR
+
+ print "all ok\\n"
+ branch DONE
+
+ERROR: print "not ok\\n"
+ print I15
+ print "\\n"
+ print I16
+ print "\\n"
+ print N15
+ print "\\n"
+ print N16
+ print "\\n"
+ print S15
+ print "\\n"
+ print S16
+ print "\\n"
+ print I1
+ print "\\n"
+ print I2
+ print "\\n"
+
+DONE: end
+CODE
+all ok
+OUTPUT
+
$code = $fp_equality_macro;
$output = "";
for (0..1024) {
@@ -995,15 +1440,40 @@
return $rt;
}
-# first half like clt_num_regs, second half like cgt_num_regs
-# (for testing poptopn op)
+# Compare num regs with zero -- half should be less than zero, half
+# should be greater than zero. Pass in $lower to determine which half.
+# If $lower is true, it's the lower half; otherwise, it's the upper half
+
sub check_num_regs {
+ my $lower = shift;
my $rt;
+
+# lower half negative
+ if ($lower) {
for (0..15) {
$rt .= "\tgt N$_, 0.0, ERROR\n";
}
for (16..31) {
$rt .= "\tlt N$_, 0.0, ERROR\n";
}
+ }
+# upper half negative
+ else {
+ for (0..15) {
+ $rt .= "\tlt N$_, 0.0, ERROR\n";
+ }
+ for (16..31) {
+ $rt .= "\tgt N$_, 0.0, ERROR\n";
+ }
+ }
+ return $rt;
+}
+
+sub print_num_regs {
+ my $rt;
+ for (0..31) {
+ $rt .= "\tprint N$_\n";
+ }
return $rt;
}
+