Skip to content
Newer
Older
100644 722 lines (462 sloc) 14.1 KB
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored Jun 12, 2004
1 /*
09dc23b @NotFound rarrange initialization and freeze/thaw of FIA and RIA to avoid redun…
NotFound authored Feb 4, 2011
2 Copyright (C) 2001-2011, Parrot Foundation.
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored Jun 12, 2004
3
4 =head1 NAME
5
f474cd7 @bschmalhofer [perl #38235] Rename (dyn)?classes to (dyn)?pmc
bschmalhofer authored Jan 18, 2006
6 src/pmc/fixedintegerarray.pmc - fixed size array for integers only
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored Jun 12, 2004
7
8 =head1 DESCRIPTION
9
894d448 @chromatic [PMC] Minor cleanups and tidyings.
chromatic authored Sep 4, 2007
10 This class, FixedIntegerArray, implements an array of fixed size which stores
11 INTVALs. It uses Integer PMCs for all of the conversions.
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored Jun 12, 2004
12
13 =cut
14
15 */
16
6bdd5f9 @petdance headerizer now runs on PMC files
petdance authored Mar 28, 2010
17 /* HEADERIZER HFILE: none */
18 /* HEADERIZER BEGIN: static */
4927d8a @NotFound make FIA sort method half-usable
NotFound authored Jun 10, 2010
19 /* Don't modify between HEADERIZER BEGIN / HEADERIZER END. Your changes will be lost. */
20
f9cca7d @petdance consting and annotating
petdance authored Jun 30, 2010
21 PARROT_PURE_FUNCTION
22 static int auxcmpfunc(ARGIN(const INTVAL *i), ARGIN(const INTVAL *j))
23 __attribute__nonnull__(1)
24 __attribute__nonnull__(2);
25
26 #define ASSERT_ARGS_auxcmpfunc __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
27 PARROT_ASSERT_ARG(i) \
28 , PARROT_ASSERT_ARG(j))
4927d8a @NotFound make FIA sort method half-usable
NotFound authored Jun 10, 2010
29 /* Don't modify between HEADERIZER BEGIN / HEADERIZER END. Your changes will be lost. */
6bdd5f9 @petdance headerizer now runs on PMC files
petdance authored Mar 28, 2010
30 /* HEADERIZER END: static */
31
4927d8a @NotFound make FIA sort method half-usable
NotFound authored Jun 10, 2010
32
6b81760 @Whiteknight [pmc] we don't need need_ext anymore, so BALEETED
Whiteknight authored Aug 23, 2009
33 pmclass FixedIntegerArray auto_attrs provides array {
e5dead2 @cotto [pmc] update *IntegerArray to use ATTRs
cotto authored Jan 27, 2009
34 ATTR INTVAL size; /* number of INTVALs stored in this array */
35 ATTR INTVAL * int_array; /* INTVALs are stored here */
d1f7c98 JIT/i386 ord_i_s*
Leopold Toetsch authored Mar 22, 2005
36
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored Jun 12, 2004
37 /*
38
ac9988d @NotFound some cleaning of FIA: put METHOD after vtable functions and fix and i…
NotFound authored Aug 12, 2010
39 =head2 Vtable functions
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored Jun 12, 2004
40
41 =over 4
42
43 =item C<void init()>
44
45 Initializes the array.
46
47 =cut
48
49 */
50
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored Mar 11, 2008
51 VTABLE void init() {
4591dbb @chromatic [HLL] Fixed two compilation-breaking typos accidentally committed in …
chromatic authored Sep 3, 2009
52 PObj_custom_destroy_SET(SELF);
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored Jun 12, 2004
53 }
54
55 /*
56
714df2a @tewk VTABLE_init_int commented out tests
tewk authored Mar 10, 2010
57 =item C<void init_int(INTVAL size)>
58
59 Initializes the array.
60
61 =cut
62
63 */
64
65 VTABLE void init_int(INTVAL size) {
4d64842 @leto [t][TT#1509] Prevent core dumps by preventing negative length array c…
leto authored Mar 11, 2010
66 if (size < 0)
26914e1 changed interp in pmc class to INTERP for unification
Jimmy Zhuo authored May 5, 2010
67 Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_OUT_OF_BOUNDS,
4d64842 @leto [t][TT#1509] Prevent core dumps by preventing negative length array c…
leto authored Mar 11, 2010
68 _("FixedIntegerArray: Cannot set array size to a negative number (%d)"), size);
09dc23b @NotFound rarrange initialization and freeze/thaw of FIA and RIA to avoid redun…
NotFound authored Feb 4, 2011
69 if (size > 0) {
70 SET_ATTR_size(INTERP, SELF, size);
71 SET_ATTR_int_array(INTERP, SELF, mem_gc_allocate_n_typed(INTERP, size, INTVAL));
72 }
714df2a @tewk VTABLE_init_int commented out tests
tewk authored Mar 10, 2010
73 PObj_custom_destroy_SET(SELF);
74 }
75
76 /*
77
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored Jun 12, 2004
78 =item C<void destroy()>
79
80 Destroys the array.
81
82 =cut
83
84 */
85
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored Mar 11, 2008
86 VTABLE void destroy() {
e5dead2 @cotto [pmc] update *IntegerArray to use ATTRs
cotto authored Jan 27, 2009
87 INTVAL* int_array;
88 GET_ATTR_int_array(INTERP, SELF, int_array);
89 if (int_array)
4833868 @bacek Merge branch 'sys_mem' into trunk
bacek authored Feb 22, 2010
90 Parrot_gc_free_memory_chunk(INTERP, int_array);
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored Jun 12, 2004
91 }
92
93 /*
94
95 =item C<PMC *clone()>
96
97 Creates and returns a copy of the array.
98
99 =cut
100
101 */
102
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored Mar 11, 2008
103 VTABLE PMC *clone() {
9822a24 var_args 8 - verify signature during bytecode creation
Leopold Toetsch authored Jun 14, 2005
104 /* a quick hack to create a clone in the constant PMC arena
105 * this is needed for the call signatures
106 *
107 * a better way would be probably to supply a flag to the clone
108 * vtable
109 */
110
e5dead2 @cotto [pmc] update *IntegerArray to use ATTRs
cotto authored Jan 27, 2009
111 INTVAL * int_array;
84fbdb5 @bacek Don't clone self to constant PMC.
bacek authored Nov 18, 2011
112 PMC * const dest = Parrot_pmc_new(INTERP, SELF->vtable->base_type);
894d448 @chromatic [PMC] Minor cleanups and tidyings.
chromatic authored Sep 4, 2007
113
e5dead2 @cotto [pmc] update *IntegerArray to use ATTRs
cotto authored Jan 27, 2009
114 GET_ATTR_int_array(INTERP, SELF, int_array);
8d33429 @chromatic [PMC] Replaced vtable function calls to find size of fixed integer ar…
chromatic authored May 1, 2009
115
e5dead2 @cotto [pmc] update *IntegerArray to use ATTRs
cotto authored Jan 27, 2009
116 if (int_array) {
42f27d4 @NotFound clean FIA.clone
NotFound authored Apr 24, 2010
117 INTVAL size;
8d33429 @chromatic [PMC] Replaced vtable function calls to find size of fixed integer ar…
chromatic authored May 1, 2009
118 GET_ATTR_size(INTERP, SELF, size);
42f27d4 @NotFound clean FIA.clone
NotFound authored Apr 24, 2010
119 {
120 INTVAL * const dest_int_array = mem_gc_allocate_n_typed(INTERP,
121 size, INTVAL);
122 mem_copy_n_typed(dest_int_array, int_array,
123 size, INTVAL);
124 SET_ATTR_int_array(INTERP, dest, dest_int_array);
125 }
e5dead2 @cotto [pmc] update *IntegerArray to use ATTRs
cotto authored Jan 27, 2009
126 SET_ATTR_size(INTERP, dest, size);
4591dbb @chromatic [HLL] Fixed two compilation-breaking typos accidentally committed in …
chromatic authored Sep 3, 2009
127 PObj_custom_destroy_SET(dest);
a35f6fd @petdance consting & localizing
petdance authored Feb 9, 2008
128 }
894d448 @chromatic [PMC] Minor cleanups and tidyings.
chromatic authored Sep 4, 2007
129
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored Jun 12, 2004
130 return dest;
131 }
132
133 /*
134
135 =item C<INTVAL get_bool()>
136
137 Returns whether the array has any elements (meaning been initialized, for a
138 fixed sized array).
139
140 =cut
141
142 */
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored Mar 11, 2008
143 VTABLE INTVAL get_bool() {
8d33429 @chromatic [PMC] Replaced vtable function calls to find size of fixed integer ar…
chromatic authored May 1, 2009
144 INTVAL size;
145 GET_ATTR_size(INTERP, SELF, size);
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored Jun 12, 2004
146 return (INTVAL)(size != 0);
147 }
148
149 /*
150
151 =item C<INTVAL elements()>
152
153 =cut
154
155 */
156
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored Mar 11, 2008
157 VTABLE INTVAL elements() {
8d33429 @chromatic [PMC] Replaced vtable function calls to find size of fixed integer ar…
chromatic authored May 1, 2009
158 INTVAL size;
159 GET_ATTR_size(INTERP, SELF, size);
160
161 return size;
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored Jun 12, 2004
162 }
163
164 /*
165
166 =item C<INTVAL get_integer()>
167
168 Returns the number of elements in the array.
169
170 =cut
171
172 */
173
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored Mar 11, 2008
174 VTABLE INTVAL get_integer() {
8d33429 @chromatic [PMC] Replaced vtable function calls to find size of fixed integer ar…
chromatic authored May 1, 2009
175 INTVAL size;
176 GET_ATTR_size(INTERP, SELF, size);
177 return size;
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored Jun 12, 2004
178 }
179
180
181 /*
182
183 =item C<INTVAL get_integer_keyed_int(INTVAL key)>
184
185 Returns the integer value of the element at index C<key>.
186
187 =cut
188
189 */
190
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored Mar 11, 2008
191 VTABLE INTVAL get_integer_keyed_int(INTVAL key) {
e5dead2 @cotto [pmc] update *IntegerArray to use ATTRs
cotto authored Jan 27, 2009
192 INTVAL *int_array;
8d33429 @chromatic [PMC] Replaced vtable function calls to find size of fixed integer ar…
chromatic authored May 1, 2009
193 INTVAL size;
894d448 @chromatic [PMC] Minor cleanups and tidyings.
chromatic authored Sep 4, 2007
194
8d33429 @chromatic [PMC] Replaced vtable function calls to find size of fixed integer ar…
chromatic authored May 1, 2009
195 GET_ATTR_size(INTERP, SELF, size);
196
197 if (key < 0 || key >= size)
26914e1 changed interp in pmc class to INTERP for unification
Jimmy Zhuo authored May 5, 2010
198 Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_OUT_OF_BOUNDS,
d185452 @chromatic Standardize internal exception calls (James deBoer, james at huronbox…
chromatic authored Dec 12, 2004
199 "FixedIntegerArray: index out of bounds!");
d1f7c98 JIT/i386 ord_i_s*
Leopold Toetsch authored Mar 22, 2005
200
e5dead2 @cotto [pmc] update *IntegerArray to use ATTRs
cotto authored Jan 27, 2009
201 GET_ATTR_int_array(INTERP, SELF, int_array);
202 return int_array[key];
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored Jun 12, 2004
203 }
204
205 /*
206
207 =item C<INTVAL get_integer_keyed(PMC *key)>
208
209 Returns the integer value of the element at index C<*key>.
210
211 =cut
212
213 */
214
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored Mar 11, 2008
215 VTABLE INTVAL get_integer_keyed(PMC *key) {
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored Jun 12, 2004
216 /* simple int keys only */
757f3a8 @chromatic [PMC] Replaced all uses of key_integer() outside of Key PMC and src/k…
chromatic authored May 8, 2009
217 const INTVAL k = VTABLE_get_integer(INTERP, key);
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored Mar 11, 2008
218 return SELF.get_integer_keyed_int(k);
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored Jun 12, 2004
219 }
220
221
222 /*
223
224 =item C<FLOATVAL get_number_keyed_int(INTVAL key)>
225
226 Returns the floating-point value of the element at index C<key>.
227
228 =cut
229
230 */
231
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored Mar 11, 2008
232 VTABLE FLOATVAL get_number_keyed_int(INTVAL key) {
233 const INTVAL i = SELF.get_integer_keyed_int(key);
8275ff5 @chromatic [PMC] Fixed a couple of casting warnings of function return values.
chromatic authored Aug 18, 2007
234 return (FLOATVAL)i;
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored Jun 12, 2004
235 }
236
237 /*
238
95e3676 @Infinoid [pmc] PDD07-ize function signatures in src/pmc/[b-f]*.pmc
Infinoid authored Aug 9, 2007
239 =item C<FLOATVAL get_number_keyed(PMC *key)>
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored Jun 12, 2004
240
241 Returns the floating-point value of the element at index C<*key>.
242
243 =cut
244
245 */
246
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored Mar 11, 2008
247 VTABLE FLOATVAL get_number_keyed(PMC *key) {
757f3a8 @chromatic [PMC] Replaced all uses of key_integer() outside of Key PMC and src/k…
chromatic authored May 8, 2009
248 const INTVAL k = VTABLE_get_integer(INTERP, key);
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored Mar 11, 2008
249 return SELF.get_number_keyed_int(k);
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored Jun 12, 2004
250 }
251
252 /*
253
254 =item C<STRING *get_string_keyed_int(INTVAL key)>
255
256 Returns the Parrot string value of the element at index C<key>.
257
258 =cut
259
260 */
261
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored Mar 11, 2008
262 VTABLE STRING *get_string_keyed_int(INTVAL key) {
263 PMC * const temp = SELF.get_pmc_keyed_int(key);
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored Jun 12, 2004
264 return VTABLE_get_string(INTERP, temp);
265 }
bf41b66 @particle [PDD07]: ws cleanup in src/, src/dynpmc/, and src/pmc/
particle authored Oct 25, 2006
266
5a67dac @tewk Add get_repr to fixedintegerarray and integer
tewk authored Oct 18, 2006
267 /*
268
fccdff0 @Benabik Add get_string to Fixed Float and Integer Array
Benabik authored Oct 16, 2011
269 =item C<STRING *get_string()>
270
5a67dac @tewk Add get_repr to fixedintegerarray and integer
tewk authored Oct 18, 2006
271 =item C<STRING *get_repr()>
272
273 Returns the Parrot string representation C<key>.
274
275 =cut
276
277 */
278
fccdff0 @Benabik Add get_string to Fixed Float and Integer Array
Benabik authored Oct 17, 2011
279 VTABLE STRING *get_string() {
280 return STATICSELF.get_repr();
281 }
282
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored Mar 11, 2008
283 VTABLE STRING *get_repr() {
a35f6fd @petdance consting & localizing
petdance authored Feb 9, 2008
284 STRING *res = CONST_STRING(INTERP, "[ ");
8d33429 @chromatic [PMC] Replaced vtable function calls to find size of fixed integer ar…
chromatic authored May 1, 2009
285 INTVAL n;
894d448 @chromatic [PMC] Minor cleanups and tidyings.
chromatic authored Sep 4, 2007
286 INTVAL j;
5a67dac @tewk Add get_repr to fixedintegerarray and integer
tewk authored Oct 18, 2006
287
8d33429 @chromatic [PMC] Replaced vtable function calls to find size of fixed integer ar…
chromatic authored May 1, 2009
288 GET_ATTR_size(INTERP, SELF, n);
289
5a67dac @tewk Add get_repr to fixedintegerarray and integer
tewk authored Oct 18, 2006
290 for (j = 0; j < n; ++j) {
a35f6fd @petdance consting & localizing
petdance authored Feb 9, 2008
291 PMC * const val = SELF.get_pmc_keyed_int(j);
9b0f14a @bacek Everybody freeze! Immutable strings enters the building.
bacek authored Apr 21, 2010
292 res = Parrot_str_concat(INTERP, res, VTABLE_get_repr(INTERP, val));
894d448 @chromatic [PMC] Minor cleanups and tidyings.
chromatic authored Sep 4, 2007
293
5a67dac @tewk Add get_repr to fixedintegerarray and integer
tewk authored Oct 18, 2006
294 if (j < n - 1)
9b0f14a @bacek Everybody freeze! Immutable strings enters the building.
bacek authored Apr 21, 2010
295 res = Parrot_str_concat(INTERP, res, CONST_STRING(INTERP, ", "));
5a67dac @tewk Add get_repr to fixedintegerarray and integer
tewk authored Oct 18, 2006
296 }
894d448 @chromatic [PMC] Minor cleanups and tidyings.
chromatic authored Sep 4, 2007
297
9b0f14a @bacek Everybody freeze! Immutable strings enters the building.
bacek authored Apr 21, 2010
298 res = Parrot_str_concat(INTERP, res, CONST_STRING(INTERP, " ]"));
5a67dac @tewk Add get_repr to fixedintegerarray and integer
tewk authored Oct 18, 2006
299 return res;
300 }
301
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored Jun 12, 2004
302
303 /*
304
f3c2cd1 @plobsing add hashval() implementation to FIA for faster, more efficient hashing
plobsing authored Mar 2, 2011
305 =item C<INTVAL hashvalue()>
306
307 Get a hashvalue for this PMC.
308
309 Providing a non-default C<hashvalue()> implementation avoids creating
310 unecessary string temporaries.
311
312 =cut
313
314 */
315
316 VTABLE INTVAL hashvalue() {
317 INTVAL *int_array;
318 INTVAL size;
319 GET_ATTR_int_array(INTERP, SELF, int_array);
320 GET_ATTR_size(INTERP, SELF, size);
c114262 s/Parrot_hsh_hash_buffer/Parrot_hash_buffer/
Jimmy Zhuo authored Mar 6, 2011
321 return Parrot_hash_buffer((const unsigned char *)int_array,
f3c2cd1 @plobsing add hashval() implementation to FIA for faster, more efficient hashing
plobsing authored Mar 3, 2011
322 size * sizeof (INTVAL), INTERP->hash_seed);
323 }
324
325
326 /*
327
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored Jun 12, 2004
328 =item C<STRING *get_string_keyed(PMC *key)>
329
330 Returns the Parrot string value of the element at index C<*key>.
331
332 =cut
333
334 */
335
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored Mar 11, 2008
336 VTABLE STRING *get_string_keyed(PMC *key) {
757f3a8 @chromatic [PMC] Replaced all uses of key_integer() outside of Key PMC and src/k…
chromatic authored May 8, 2009
337 const INTVAL k = VTABLE_get_integer(INTERP, key);
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored Mar 11, 2008
338 return SELF.get_string_keyed_int(k);
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored Jun 12, 2004
339 }
340
341
342 /*
343
344 =item C<PMC *get_pmc_keyed_int(INTVAL key)>
345
346 Returns the PMC value of the element at index C<key>.
347
348 =cut
349
350 */
351
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored Mar 11, 2008
352 VTABLE PMC *get_pmc_keyed_int(INTVAL key) {
353 const INTVAL val = SELF.get_integer_keyed_int(key);
75d112f @NotFound implement Integer vtable init_int and use it in several places where …
NotFound authored May 1, 2010
354 PMC * const ret = Parrot_pmc_new_init_int(INTERP, enum_class_Integer, val);
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored Jun 12, 2004
355 return ret;
356 }
357
358 /*
359
360 =item C<PMC *get_pmc_keyed(PMC *key)>
361
362 Returns the PMC value of the element at index C<*key>.
363
364 =cut
365
366 */
367
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored Mar 11, 2008
368 VTABLE PMC *get_pmc_keyed(PMC *key) {
757f3a8 @chromatic [PMC] Replaced all uses of key_integer() outside of Key PMC and src/k…
chromatic authored May 8, 2009
369 const INTVAL k = VTABLE_get_integer(INTERP, key);
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored Mar 11, 2008
370 return SELF.get_pmc_keyed_int(k);
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored Jun 12, 2004
371 }
372
373 /*
374
375 =item C<void set_integer_native(INTVAL size)>
376
377 Resizes the array to C<size> elements.
378
379 =cut
380
381 */
382
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored Mar 11, 2008
383 VTABLE void set_integer_native(INTVAL size) {
e5dead2 @cotto [pmc] update *IntegerArray to use ATTRs
cotto authored Jan 27, 2009
384 INTVAL *int_array;
8d33429 @chromatic [PMC] Replaced vtable function calls to find size of fixed integer ar…
chromatic authored May 1, 2009
385 INTVAL cur_size;
386
387 GET_ATTR_size(INTERP, SELF, cur_size);
388
389 if (cur_size || size < 1)
2255840 @allisonrandal [pdd17pmc] Merging the pdd25cx branch into trunk for r26555 to r29949.
allisonrandal authored Aug 2, 2008
390 Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_OUT_OF_BOUNDS,
d1f7c98 JIT/i386 ord_i_s*
Leopold Toetsch authored Mar 22, 2005
391 "FixedIntegerArray: Can't resize!");
2255840 @allisonrandal [pdd17pmc] Merging the pdd25cx branch into trunk for r26555 to r29949.
allisonrandal authored Aug 2, 2008
392
e5dead2 @cotto [pmc] update *IntegerArray to use ATTRs
cotto authored Jan 27, 2009
393 SET_ATTR_size(INTERP, SELF, size);
394 GET_ATTR_int_array(INTERP, SELF, int_array);
7a96a21 @bschmalhofer [codingstd] tabs.t and trailing_space.t
bschmalhofer authored Jan 28, 2009
395 SET_ATTR_int_array(INTERP, SELF,
4833868 @bacek Merge branch 'sys_mem' into trunk
bacek authored Feb 22, 2010
396 mem_gc_realloc_n_typed(INTERP, int_array, size, INTVAL));
4591dbb @chromatic [HLL] Fixed two compilation-breaking typos accidentally committed in …
chromatic authored Sep 3, 2009
397 PObj_custom_destroy_SET(SELF);
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored Jun 12, 2004
398 }
399
400 /*
401
402 =item C<void set_integer_keyed_int(INTVAL key, INTVAL value)>
403
404 Sets the integer value of the element at index C<key> to C<value>.
405
406 =cut
407
408 */
409
8fcbee3 @bacek Mark set_foo_keyed_bar methods with :manual_wb in FIA
bacek authored Feb 17, 2011
410 VTABLE void set_integer_keyed_int(INTVAL key, INTVAL value) :manual_wb {
e5dead2 @cotto [pmc] update *IntegerArray to use ATTRs
cotto authored Jan 27, 2009
411 INTVAL *int_array;
8d33429 @chromatic [PMC] Replaced vtable function calls to find size of fixed integer ar…
chromatic authored May 1, 2009
412 INTVAL size;
894d448 @chromatic [PMC] Minor cleanups and tidyings.
chromatic authored Sep 4, 2007
413
8d33429 @chromatic [PMC] Replaced vtable function calls to find size of fixed integer ar…
chromatic authored May 1, 2009
414 GET_ATTR_size(INTERP, SELF, size);
415
416 if (key < 0 || key >= size)
26914e1 changed interp in pmc class to INTERP for unification
Jimmy Zhuo authored May 5, 2010
417 Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_OUT_OF_BOUNDS,
d185452 @chromatic Standardize internal exception calls (James deBoer, james at huronbox…
chromatic authored Dec 12, 2004
418 "FixedIntegerArray: index out of bounds!");
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored Jun 12, 2004
419
e5dead2 @cotto [pmc] update *IntegerArray to use ATTRs
cotto authored Jan 27, 2009
420 GET_ATTR_int_array(INTERP, SELF, int_array);
421 int_array[key] = value;
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored Jun 12, 2004
422 }
423
424 /*
425
426 =item C<void set_integer_keyed(PMC *key, INTVAL value)>
427
428 Sets the integer value of the element at index C<key> to C<value>.
429
430 =cut
431
432 */
433
8fcbee3 @bacek Mark set_foo_keyed_bar methods with :manual_wb in FIA
bacek authored Feb 17, 2011
434 VTABLE void set_integer_keyed(PMC *key, INTVAL value) :manual_wb {
757f3a8 @chromatic [PMC] Replaced all uses of key_integer() outside of Key PMC and src/k…
chromatic authored May 8, 2009
435 const INTVAL k = VTABLE_get_integer(INTERP, key);
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored Mar 11, 2008
436 SELF.set_integer_keyed_int(k, value);
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored Jun 12, 2004
437 }
438
439 /*
440
441 =item C<void set_number_keyed_int(INTVAL key, FLOATVAL value)>
442
894d448 @chromatic [PMC] Minor cleanups and tidyings.
chromatic authored Sep 4, 2007
443 Sets the floating-point value of the element at index C<key> to C<value>.
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored Jun 12, 2004
444
445 =cut
446
447 */
448
8fcbee3 @bacek Mark set_foo_keyed_bar methods with :manual_wb in FIA
bacek authored Feb 17, 2011
449 VTABLE void set_number_keyed_int(INTVAL key, FLOATVAL value) :manual_wb {
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored Mar 11, 2008
450 SELF.set_integer_keyed_int(key, (INTVAL)value);
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored Jun 12, 2004
451 }
452
453 /*
454
455 =item C<void set_number_keyed(PMC *key, FLOATVAL value)>
456
894d448 @chromatic [PMC] Minor cleanups and tidyings.
chromatic authored Sep 4, 2007
457 Sets the floating-point value of the element at index C<key> to C<value>.
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored Jun 12, 2004
458
459 =cut
460
461 */
462
8fcbee3 @bacek Mark set_foo_keyed_bar methods with :manual_wb in FIA
bacek authored Feb 17, 2011
463 VTABLE void set_number_keyed(PMC *key, FLOATVAL value) :manual_wb {
757f3a8 @chromatic [PMC] Replaced all uses of key_integer() outside of Key PMC and src/k…
chromatic authored May 8, 2009
464 const INTVAL k = VTABLE_get_integer(INTERP, key);
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored Mar 11, 2008
465 SELF.set_number_keyed_int(k, value);
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored Jun 12, 2004
466 }
d1f7c98 JIT/i386 ord_i_s*
Leopold Toetsch authored Mar 22, 2005
467
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored Jun 12, 2004
468 /*
469
470 =item C<void set_string_keyed_int(INTVAL key, STRING *value)>
471
472 Sets the Parrot string value of the element at index C<key> to C<value>.
473
474 =cut
475
476 */
477
8fcbee3 @bacek Mark set_foo_keyed_bar methods with :manual_wb in FIA
bacek authored Feb 17, 2011
478 VTABLE void set_string_keyed_int(INTVAL key, STRING *value) :manual_wb {
06e2d1e @NotFound avoid a temporary PMC in FPA set_string_keyed_int
NotFound authored Apr 30, 2010
479 const INTVAL tempInt = Parrot_str_to_int(INTERP, value);
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored Mar 11, 2008
480 SELF.set_integer_keyed_int(key, tempInt);
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored Jun 12, 2004
481 }
482
483 /*
484
95e3676 @Infinoid [pmc] PDD07-ize function signatures in src/pmc/[b-f]*.pmc
Infinoid authored Aug 9, 2007
485 =item C<void set_string_keyed(PMC *key, STRING *value)>
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored Jun 12, 2004
486
894d448 @chromatic [PMC] Minor cleanups and tidyings.
chromatic authored Sep 4, 2007
487 Sets the string value of the element at index C<key> to C<value>.
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored Jun 12, 2004
488
489 =cut
490
491 */
492
8fcbee3 @bacek Mark set_foo_keyed_bar methods with :manual_wb in FIA
bacek authored Feb 17, 2011
493 VTABLE void set_string_keyed(PMC *key, STRING *value) :manual_wb {
757f3a8 @chromatic [PMC] Replaced all uses of key_integer() outside of Key PMC and src/k…
chromatic authored May 8, 2009
494 const INTVAL k = VTABLE_get_integer(INTERP, key);
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored Mar 11, 2008
495 SELF.set_string_keyed_int(k, value);
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored Jun 12, 2004
496 }
497
498 /*
499
500 =item C<void set_pmc_keyed_int(INTVAL key, PMC *src)>
501
502 Sets the PMC value of the element at index C<key> to C<*src>.
503
504 =cut
505
506 */
507
8fcbee3 @bacek Mark set_foo_keyed_bar methods with :manual_wb in FIA
bacek authored Feb 17, 2011
508 VTABLE void set_pmc_keyed_int(INTVAL key, PMC *src) :manual_wb {
a35f6fd @petdance consting & localizing
petdance authored Feb 9, 2008
509 const INTVAL tempInt = VTABLE_get_integer(INTERP, src);
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored Mar 11, 2008
510 SELF.set_integer_keyed_int(key, tempInt);
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored Jun 12, 2004
511 }
512
513 /*
514
95e3676 @Infinoid [pmc] PDD07-ize function signatures in src/pmc/[b-f]*.pmc
Infinoid authored Aug 9, 2007
515 =item C<void set_pmc_keyed(PMC *key, PMC *value)>
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored Jun 12, 2004
516
894d448 @chromatic [PMC] Minor cleanups and tidyings.
chromatic authored Sep 4, 2007
517 Sets the string value of the element at index C<key> to C<value>.
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored Jun 12, 2004
518
519 =cut
520
521 */
522
8fcbee3 @bacek Mark set_foo_keyed_bar methods with :manual_wb in FIA
bacek authored Feb 17, 2011
523 VTABLE void set_pmc_keyed(PMC *key, PMC *value) :manual_wb {
757f3a8 @chromatic [PMC] Replaced all uses of key_integer() outside of Key PMC and src/k…
chromatic authored May 8, 2009
524 const INTVAL k = VTABLE_get_integer(INTERP, key);
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored Mar 11, 2008
525 SELF.set_pmc_keyed_int(k, value);
526 }
527
6287ae3 add missing fixedintegerarray.freeze and .thaw
Leopold Toetsch authored Jul 3, 2005
528 /*
529
0c38764 @bacek [core] Implement FixedIntegerArray.is_equal
bacek authored Sep 20, 2009
530 =item C<INTVAL is_equal(PMC *value)>
531
532 The C<==> operation. Compares two array to hold equal elements.
533
534 =cut
535
536 */
537
538 VTABLE INTVAL is_equal(PMC *value) {
539 INTVAL j, n;
540
541 if (value->vtable->base_type != SELF->vtable->base_type)
542 return 0;
543
544 n = SELF.elements();
545
546 if (VTABLE_elements(INTERP, value) != n)
547 return 0;
548
549 for (j = 0; j < n; ++j) {
f9cca7d @petdance consting and annotating
petdance authored Jun 30, 2010
550 const INTVAL item1 = SELF.get_integer_keyed_int(j);
551 const INTVAL item2 = VTABLE_get_integer_keyed_int(INTERP, value, j);
0c38764 @bacek [core] Implement FixedIntegerArray.is_equal
bacek authored Sep 20, 2009
552
553 if (item1 != item2)
554 return 0;
555 }
556
557 return 1;
558 }
559
560 /*
561
bd8aacd @cotto [PMC] add get_iter VTABLE function and tests to *IntegerArray
cotto authored Mar 22, 2009
562 =item C<PMC *get_iter()>
563
564 Return a new Iterator for this PMC.
565
566 =cut
567
568 */
569
570 VTABLE PMC *get_iter() {
083213a @Whiteknight start rename of pmc_new to Parrot_pmc_new
Whiteknight authored Feb 16, 2010
571 return Parrot_pmc_new_init(INTERP, enum_class_ArrayIterator, SELF);
bd8aacd @cotto [PMC] add get_iter VTABLE function and tests to *IntegerArray
cotto authored Mar 22, 2009
572 }
573
574 /*
575
b101f2c @darbelo Merge pmc_freeze_with_pmcs into trunk.
darbelo authored Feb 2, 2010
576 =item C<void freeze(PMC *info)>
6287ae3 add missing fixedintegerarray.freeze and .thaw
Leopold Toetsch authored Jul 3, 2005
577
578 Used to archive the array.
579
b101f2c @darbelo Merge pmc_freeze_with_pmcs into trunk.
darbelo authored Feb 2, 2010
580 =item C<void thaw(PMC *info)>
6287ae3 add missing fixedintegerarray.freeze and .thaw
Leopold Toetsch authored Jul 3, 2005
581
582 Used to unarchive the array.
583
09dc23b @NotFound rarrange initialization and freeze/thaw of FIA and RIA to avoid redun…
NotFound authored Feb 4, 2011
584 C<*info> is the visit info, (see F<include/parrot/pmc_freeze.h>).
585
6287ae3 add missing fixedintegerarray.freeze and .thaw
Leopold Toetsch authored Jul 3, 2005
586 =cut
587
588 */
589
b101f2c @darbelo Merge pmc_freeze_with_pmcs into trunk.
darbelo authored Feb 2, 2010
590 VTABLE void freeze(PMC *info) {
e5dead2 @cotto [pmc] update *IntegerArray to use ATTRs
cotto authored Jan 27, 2009
591 INTVAL *int_array;
894d448 @chromatic [PMC] Minor cleanups and tidyings.
chromatic authored Sep 4, 2007
592 INTVAL i, n;
6287ae3 add missing fixedintegerarray.freeze and .thaw
Leopold Toetsch authored Jul 3, 2005
593
594 SUPER(info);
894d448 @chromatic [PMC] Minor cleanups and tidyings.
chromatic authored Sep 4, 2007
595
8d33429 @chromatic [PMC] Replaced vtable function calls to find size of fixed integer ar…
chromatic authored May 1, 2009
596 GET_ATTR_size(INTERP, SELF, n);
4c43475 @plobsing merge branch pmc_freeze_cleanup
plobsing authored Jan 13, 2010
597 VTABLE_push_integer(INTERP, info, n);
e5dead2 @cotto [pmc] update *IntegerArray to use ATTRs
cotto authored Jan 27, 2009
598 GET_ATTR_int_array(INTERP, SELF, int_array);
894d448 @chromatic [PMC] Minor cleanups and tidyings.
chromatic authored Sep 4, 2007
599
600 for (i = 0; i < n; ++i)
4c43475 @plobsing merge branch pmc_freeze_cleanup
plobsing authored Jan 13, 2010
601 VTABLE_push_integer(INTERP, info, int_array[i]);
6287ae3 add missing fixedintegerarray.freeze and .thaw
Leopold Toetsch authored Jul 3, 2005
602 }
603
b101f2c @darbelo Merge pmc_freeze_with_pmcs into trunk.
darbelo authored Feb 2, 2010
604 VTABLE void thaw(PMC *info) {
8640c33 @petdance consting vars. Fixed some POD.
petdance authored Feb 26, 2011
605 const INTVAL n = VTABLE_shift_integer(INTERP, info);
09dc23b @NotFound rarrange initialization and freeze/thaw of FIA and RIA to avoid redun…
NotFound authored Feb 4, 2011
606 SELF.init_int(n);
607 if (n > 0) {
4c43475 @plobsing merge branch pmc_freeze_cleanup
plobsing authored Jan 13, 2010
608 INTVAL i;
609 INTVAL *int_array;
610 GET_ATTR_int_array(INTERP, SELF, int_array);
611 for (i = 0; i < n; ++i)
612 int_array[i] = VTABLE_shift_integer(INTERP, info);
6287ae3 add missing fixedintegerarray.freeze and .thaw
Leopold Toetsch authored Jul 3, 2005
613 }
614 }
ac9988d @NotFound some cleaning of FIA: put METHOD after vtable functions and fix and i…
NotFound authored Aug 12, 2010
615
616 /*
617
618 =back
619
620 =head2 Methods
621
622 =over 4
623
624 =item C<PMC *sort()>
625
626 Sort the array and return self.
627
628 =cut
629
630 */
631
632 METHOD sort(PMC *cmp_func :optional) {
633 UINTVAL n;
634 INTVAL size;
635
636 GET_ATTR_size(INTERP, SELF, size);
637 n = (UINTVAL)size;
638
639 if (n > 1) {
640 INTVAL *int_array;
641 GET_ATTR_int_array(INTERP, SELF, int_array);
642 if (PMC_IS_NULL(cmp_func))
643 qsort(int_array, n, sizeof (INTVAL),
644 (int (*)(const void *, const void*))auxcmpfunc);
645 else
4379aa4 @bacek Pass cmp signature to quicksort to avoid segmentation fault during fe…
bacek authored Dec 25, 2010
646 Parrot_util_quicksort(INTERP, (void**)int_array, n, cmp_func, "II->I");
ac9988d @NotFound some cleaning of FIA: put METHOD after vtable functions and fix and i…
NotFound authored Aug 12, 2010
647 }
648 RETURN(PMC *SELF);
649 }
650
47a64b4 @mlschroe add a "reverse" method for the array types (except boolarray)
mlschroe authored Oct 20, 2011
651 /*
652
653 =item C<METHOD reverse()>
654
655 Reverse the contents of the array.
656
657 =cut
658
659 */
660
661 METHOD reverse() {
662 INTVAL n;
663 GET_ATTR_size(INTERP, SELF, n);
664 if (n > 1) {
665 INTVAL val;
666 INTVAL *data;
667 INTVAL i;
668
669 GET_ATTR_int_array(INTERP, SELF, data);
670 for (i = 0; i <= --n; i++) {
671 val = data[i];
672 data[i] = data[n];
673 data[n] = val;
674 }
675 }
f55a488 @Benabik codingstd fixes
Benabik authored Oct 20, 2011
676 }
47a64b4 @mlschroe add a "reverse" method for the array types (except boolarray)
mlschroe authored Oct 20, 2011
677
ac9988d @NotFound some cleaning of FIA: put METHOD after vtable functions and fix and i…
NotFound authored Aug 12, 2010
678 }
679
680 /*
681
682 =back
683
cbe2617 @jkeenan Correct spelling error in POD.
jkeenan authored Aug 14, 2010
684 =head2 Auxiliary functions
ac9988d @NotFound some cleaning of FIA: put METHOD after vtable functions and fix and i…
NotFound authored Aug 12, 2010
685
686 =over 4
687
688 =item C<static int auxcmpfunc(const INTVAL *i, const INTVAL *j)>
689
690 INTVAL compare function for qsort usage.
691
692 =cut
693
694 */
695
696 PARROT_PURE_FUNCTION
697 static int
698 auxcmpfunc(ARGIN(const INTVAL *i), ARGIN(const INTVAL *j))
699 {
700 ASSERT_ARGS(auxcmpfunc)
701 return *i - *j;
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored Jun 12, 2004
702 }
703
704 /*
705
706 =back
707
708 =head1 SEE ALSO
709
1e8a4ab this patch adds some relevant 'push' ops to the resizable PMCs, descr…
Dan Sugalski authored Oct 19, 2004
710 F<docs/pdds/pdd17_basic_types.pod>.
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored Jun 12, 2004
711
712 =cut
713
714 */
715
716 /*
717 * Local variables:
72575ae @bschmalhofer #40481: [PATCH] C-code coda in pmc files
bschmalhofer authored Oct 9, 2006
718 * c-file-style: "parrot"
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored Jun 12, 2004
719 * End:
1d7dded @plobsing update C file vim modelines
plobsing authored Nov 29, 2010
720 * vim: expandtab shiftwidth=4 cinoptions='\:2=2' :
72575ae @bschmalhofer #40481: [PATCH] C-code coda in pmc files
bschmalhofer authored Oct 9, 2006
721 */
Something went wrong with that request. Please try again.