# New Ticket Created by Cory Spencer
# Please include the string: [perl #49582]
# in the subject line of all future correspondence about this issue.
# <URL: http://rt.perl.org/rt3/Ticket/Display.html?id=49582 >
The following patch against r24710:
- adds a push and a pop method to the P6 List PMC
- adds basic documentation for other methods
- modifies the unshift method to accept a list of elements to unshift
onto the list
Cory
Index: src/classes/List.pir
===================================================================
--- src/classes/List.pir (revision 24707)
+++ src/classes/List.pir (working copy)
@@ -42,19 +42,90 @@
.return ($I0)
.end
+=item unshift(ELEMENTS)
+Prepends ELEMENTS to the front of the list.
+
+=cut
+
.sub 'unshift' :method
- .param pmc x
- unshift self, x
+ .param pmc args :slurpy
+ .local int narg
+ .local int i
+
+ narg = args
+ i = 0
+
+ .local pmc tmp
+ loop:
+ if i == narg goto done
+ pop tmp, args
+ unshift self, tmp
+ inc i
+ goto loop
+ done:
.end
+=item shift()
+Shifts the first item off the list and returns it.
+
+=cut
+
.sub 'shift' :method
.local pmc x
x = shift self
.return (x)
.end
+=item pop()
+
+Treats the list as a stack, popping the last item off the list and returning
it.
+
+=cut
+
+.sub 'pop' :method
+ .local pmc x
+ .local int len
+
+ len = elements self
+
+ if len == 0 goto empty
+ pop x, self
+ goto done
+
+ empty:
+ x = undef()
+ goto done
+
+ done:
+ .return (x)
+.end
+
+=item push(ELEMENTS)
+
+Treats the list as a stack, pushing ELEMENTS onto the end of the list.
+
+=cut
+
+.sub 'push' :method
+ .param pmc args :slurpy
+ .local int narg
+ .local pmc tmp
+ .local int i
+
+ narg = args
+ i = 0
+
+ loop:
+ if i == narg goto done
+ shift tmp, args
+ push self, tmp
+ inc i
+ goto loop
+ done:
+.end
+
=back
=cut