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