Author: coke
Date: Tue May 1 07:37:45 2007
New Revision: 18374
Modified:
trunk/ (props changed)
trunk/runtime/parrot/library/Range.pir
trunk/t/library/range.t
Log:
[library]
* test them
* add :vtable variants of 'shift' and 'pop'
Modified: trunk/runtime/parrot/library/Range.pir
==============================================================================
--- trunk/runtime/parrot/library/Range.pir (original)
+++ trunk/runtime/parrot/library/Range.pir Tue May 1 07:37:45 2007
@@ -149,7 +149,7 @@
=cut
-.sub shift :method
+.sub 'shift' :vtable('shift_pmc') :method
.exhausted_check()
.local pmc exhausted, from, to, by
@@ -172,6 +172,25 @@
.return (from)
.end
+# RT#42430
+# :method is only specified on the shift_* vtables for self.
+
+# Wrappers for the shift_pmc vtable - rely on autoboxing.
+.sub 'shift_integer' :vtable :method
+ $P0 = shift self
+ .return ($P0)
+.end
+
+.sub 'shift_float' :vtable :method
+ $P0 = shift self
+ .return ($P0)
+.end
+
+.sub 'shift_string' :vtable :method
+ $P0 = shift self
+ .return ($P0)
+.end
+
=head2 pop
pop a value off the "end" of the range.
@@ -180,7 +199,7 @@
=cut
-.sub pop :method
+.sub 'pop' :vtable('pop_pmc') :method
.exhausted_check()
# can we pull a number off the end?
# return it.
@@ -204,6 +223,26 @@
.return (to)
.end
+# RT#42430
+# :method is only specified on the shift_* vtables for self.
+
+# Wrappers for the shift_pmc vtable - rely on autoboxing.
+.sub 'pop_integer' :vtable :method
+ $P0 = pop self
+ .return ($P0)
+.end
+
+.sub 'pop_float' :vtable :method
+ $P0 = pop self
+ .return ($P0)
+.end
+
+.sub 'pop_string' :vtable :method
+ $P0 = pop self
+ .return ($P0)
+.end
+
+
=head2
Reverse the direction of the range.
Modified: trunk/t/library/range.t
==============================================================================
--- trunk/t/library/range.t (original)
+++ trunk/t/library/range.t Tue May 1 07:37:45 2007
@@ -30,7 +30,7 @@
load_bytecode 'Range.pir' # XXX eventually convert to pbc.
- plan(68)
+ plan(78)
# XXX Convert this to the PDD15 way of creating an object
# at the same time you specify the attributes...
@@ -47,6 +47,8 @@
test_10() # 7 tests
test_11() # 7 tests
test_12() # 7 tests
+ test_13() # 5 tests
+ test_14() # 5 tests
.end
.sub 'test_1'
@@ -458,6 +460,59 @@
.return()
.end
+.sub 'test_13'
+ .local string test_desc
+ test_desc = "1..4, vtable shift, all varieties"
+
+ $P0 = new 'Range'
+ $P1 = new 'Integer'
+ $P1 = 1
+ setattribute $P0, 'from', $P1
+ $P1 = new 'Integer'
+ $P1 = 4
+ setattribute $P0, 'to', $P1
+ ok(1, test_desc)
+
+ $P1 = shift $P0
+ is($P1, 1, '13 - 1st')
+ $I0 = shift $P0
+ is($I0, 2, '13 - 2nd')
+ $N0 = shift $P0
+ is($N0, 3.0, '13 - 3rd')
+ $S0 = shift $P0
+ is($S0, "4", '13 - 4th')
+
+finally:
+ .return()
+.end
+
+.sub 'test_14'
+ .local string test_desc
+ test_desc = "1..4, vtable pop, all varieties"
+
+ $P0 = new 'Range'
+ $P1 = new 'Integer'
+ $P1 = 1
+ setattribute $P0, 'from', $P1
+ $P1 = new 'Integer'
+ $P1 = 4
+ setattribute $P0, 'to', $P1
+ ok(1, test_desc)
+
+ $P1 = pop $P0
+ is($P1, 4, '14 - 1st')
+ $I0 = pop $P0
+ is($I0, 3, '14 - 2nd')
+ $N0 = pop $P0
+ is($N0, 2.0, '14 - 3rd')
+ $S0 = pop $P0
+ is($S0, "1", '14 - 4th')
+
+finally:
+ .return()
+.end
+
+
# Local Variables:
# mode: cperl
# cperl-indent-level: 4