2 Copyright (C) 2001-2007, The Perl Foundation.
7 src/pmc/intlist.pmc - Array of integers
11 C<IntList> provides an integer-only array.
21 #include "parrot/parrot.h"
23 pmclass IntList provides array {
29 Creates and returns a clone of the list.
36 PMC * const dest = pmc_new_noinit(INTERP, SELF->vtable->base_type);
37 PObj_custom_mark_SET(dest);
38 PMC_struct_val(dest) = intlist_clone(INTERP,
39 (IntList *)PMC_struct_val(SELF));
54 PMC_struct_val(SELF) = intlist_new(INTERP);
55 PObj_custom_mark_SET(SELF);
62 Marks the list as live.
69 intlist_mark(INTERP, (IntList *)PMC_struct_val(SELF));
74 =item C<void set_integer_keyed_int(INTVAL key, INTVAL value)>
76 Sets C<value> at index C<key>.
82 VTABLE void set_integer_keyed_int(INTVAL key, INTVAL value) {
83 intlist_assign(INTERP, (IntList *)PMC_struct_val(SELF), key, value);
86 VTABLE void set_integer_native(INTVAL len) {
87 list_set_length(INTERP, (List *)PMC_struct_val(SELF), len);
91 =item C<void set_integer_keyed(PMC *key, INTVAL value)>
93 Sets C<value> at index C<*key>.
99 VTABLE void set_integer_keyed(PMC *key, INTVAL value) {
105 ix = key_integer(INTERP, key);
106 intlist_assign(INTERP, (IntList *)PMC_struct_val(SELF), ix, value);
111 =item C<INTVAL get_integer()>
113 Returns the number of elements in the list.
119 VTABLE INTVAL get_integer() {
120 return intlist_length(INTERP, (IntList *)PMC_struct_val(SELF));
123 VTABLE INTVAL elements() {
124 return intlist_length(INTERP, (IntList *)PMC_struct_val(SELF));
129 =item C<INTVAL get_integer_keyed_int(INTVAL key)>
131 Returns the value of the element at index C<key>.
137 VTABLE INTVAL get_integer_keyed_int(INTVAL key) {
138 return intlist_get(INTERP, (IntList *)PMC_struct_val(SELF), key);
143 =item C<INTVAL get_integer_keyed(PMC *key)>
145 Returns the value of the element at index C<*key>.
151 VTABLE INTVAL get_integer_keyed(PMC *key) {
154 ix = key_integer(INTERP, key);
155 return intlist_get(INTERP, (IntList*) PMC_struct_val(SELF), ix);
160 =item C<void push_integer(INTVAL value)>
162 Adds C<value> to the end of the list.
168 VTABLE void push_integer(INTVAL value) {
169 intlist_push(INTERP, (IntList *)PMC_struct_val(SELF), value);
174 =item C<INTVAL pop_integer()>
176 Removes and returns the last element in the list.
182 VTABLE INTVAL pop_integer() {
183 return intlist_pop(INTERP, (IntList *)PMC_struct_val(SELF));
188 =item C<void unshift_integer(INTVAL value)>
190 Adds C<value> to the start of the list.
196 VTABLE void unshift_integer(INTVAL value) {
197 IntList **list = (IntList **)PMC_struct_val(SELF);
198 intlist_unshift(INTERP, list, value);
203 =item C<INTVAL shift_integer()>
205 Removes and returns the first element in the list.
211 VTABLE INTVAL shift_integer() {
212 IntList **list = (IntList **)PMC_struct_val(SELF);
213 return intlist_shift(INTERP, list);
216 void splice(PMC *value, INTVAL offset, INTVAL count) {
217 if (SELF->vtable->base_type != value->vtable->base_type)
218 real_exception(INTERP, NULL, E_TypeError,
219 "Type mismatch in splice");
221 list_splice(INTERP, (List *)PMC_struct_val(SELF),
222 (List *)PMC_struct_val(value), offset, count);
225 VTABLE PMC *slice(PMC *key, INTVAL f) {
227 real_exception(INTERP, NULL, E_IndexError,
228 "IntList: Unknown slice type");
231 PMC * const iter = pmc_new_init(INTERP, enum_class_Iterator, SELF);
232 PMC_struct_val(iter) = key;
237 VTABLE PMC *get_iter() {
238 PMC * const iter = pmc_new_init(INTERP, enum_class_Iterator, SELF);
239 PMC * const key = pmc_new(INTERP, enum_class_Key);
241 PMC_struct_val(iter) = key;
242 PObj_get_FLAGS(key) |= KEY_integer_FLAG;
243 PMC_int_val(key) = 0;
245 if (!((List *)PMC_struct_val(SELF))->length)
246 PMC_int_val(key) = -1;
262 * c-file-style: "parrot"
264 * vim: expandtab shiftwidth=4: