Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 722 lines (462 sloc) 14.486 kb
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored
1 /*
09dc23b NotFound rarrange initialization and freeze/thaw of FIA and RIA to avoid redundan...
NotFound authored
2 Copyright (C) 2001-2011, Parrot Foundation.
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored
3
4 =head1 NAME
5
f474cd7 Bernhard Schmalhofer [perl #38235] Rename (dyn)?classes to (dyn)?pmc
bschmalhofer authored
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
7
8 =head1 DESCRIPTION
9
894d448 chromatic [PMC] Minor cleanups and tidyings.
chromatic authored
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
12
13 =cut
14
15 */
16
6bdd5f9 Andy Lester headerizer now runs on PMC files
petdance authored
17 /* HEADERIZER HFILE: none */
18 /* HEADERIZER BEGIN: static */
4927d8a NotFound make FIA sort method half-usable
NotFound authored
19 /* Don't modify between HEADERIZER BEGIN / HEADERIZER END. Your changes will be lost. */
20
f9cca7d Andy Lester consting and annotating
petdance authored
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
29 /* Don't modify between HEADERIZER BEGIN / HEADERIZER END. Your changes will be lost. */
6bdd5f9 Andy Lester headerizer now runs on PMC files
petdance authored
30 /* HEADERIZER END: static */
31
4927d8a NotFound make FIA sort method half-usable
NotFound authored
32
6b81760 Andrew Whitworth [pmc] we don't need need_ext anymore, so BALEETED
Whiteknight authored
33 pmclass FixedIntegerArray auto_attrs provides array {
e5dead2 cotto [pmc] update *IntegerArray to use ATTRs
cotto authored
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
36
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored
37 /*
38
ac9988d NotFound some cleaning of FIA: put METHOD after vtable functions and fix and impr...
NotFound authored
39 =head2 Vtable functions
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored
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
51 VTABLE void init() {
4591dbb chromatic [HLL] Fixed two compilation-breaking typos accidentally committed in r40...
chromatic authored
52 PObj_custom_destroy_SET(SELF);
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored
53 }
54
55 /*
56
714df2a tewk VTABLE_init_int commented out tests
tewk authored
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 Duke Leto [t][TT#1509] Prevent core dumps by preventing negative length array crea...
leto authored
66 if (size < 0)
26914e1 changed interp in pmc class to INTERP for unification
Jimmy Zhuo authored
67 Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_OUT_OF_BOUNDS,
4d64842 Duke Leto [t][TT#1509] Prevent core dumps by preventing negative length array crea...
leto authored
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 redundan...
NotFound authored
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
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
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
86 VTABLE void destroy() {
e5dead2 cotto [pmc] update *IntegerArray to use ATTRs
cotto authored
87 INTVAL* int_array;
88 GET_ATTR_int_array(INTERP, SELF, int_array);
89 if (int_array)
4833868 Vasily Chekalkin Merge branch 'sys_mem' into trunk
bacek authored
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
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
103 VTABLE PMC *clone() {
9822a24 var_args 8 - verify signature during bytecode creation
Leopold Toetsch authored
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
111 INTVAL * int_array;
84fbdb5 Vasily Chekalkin Don't clone self to constant PMC.
bacek authored
112 PMC * const dest = Parrot_pmc_new(INTERP, SELF->vtable->base_type);
894d448 chromatic [PMC] Minor cleanups and tidyings.
chromatic authored
113
e5dead2 cotto [pmc] update *IntegerArray to use ATTRs
cotto authored
114 GET_ATTR_int_array(INTERP, SELF, int_array);
8d33429 chromatic [PMC] Replaced vtable function calls to find size of fixed integer array...
chromatic authored
115
e5dead2 cotto [pmc] update *IntegerArray to use ATTRs
cotto authored
116 if (int_array) {
42f27d4 NotFound clean FIA.clone
NotFound authored
117 INTVAL size;
8d33429 chromatic [PMC] Replaced vtable function calls to find size of fixed integer array...
chromatic authored
118 GET_ATTR_size(INTERP, SELF, size);
42f27d4 NotFound clean FIA.clone
NotFound authored
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
126 SET_ATTR_size(INTERP, dest, size);
4591dbb chromatic [HLL] Fixed two compilation-breaking typos accidentally committed in r40...
chromatic authored
127 PObj_custom_destroy_SET(dest);
a35f6fd Andy Lester consting & localizing
petdance authored
128 }
894d448 chromatic [PMC] Minor cleanups and tidyings.
chromatic authored
129
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored
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
143 VTABLE INTVAL get_bool() {
8d33429 chromatic [PMC] Replaced vtable function calls to find size of fixed integer array...
chromatic authored
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
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
157 VTABLE INTVAL elements() {
8d33429 chromatic [PMC] Replaced vtable function calls to find size of fixed integer array...
chromatic authored
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
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
174 VTABLE INTVAL get_integer() {
8d33429 chromatic [PMC] Replaced vtable function calls to find size of fixed integer array...
chromatic authored
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
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
191 VTABLE INTVAL get_integer_keyed_int(INTVAL key) {
e5dead2 cotto [pmc] update *IntegerArray to use ATTRs
cotto authored
192 INTVAL *int_array;
8d33429 chromatic [PMC] Replaced vtable function calls to find size of fixed integer array...
chromatic authored
193 INTVAL size;
894d448 chromatic [PMC] Minor cleanups and tidyings.
chromatic authored
194
8d33429 chromatic [PMC] Replaced vtable function calls to find size of fixed integer array...
chromatic authored
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
198 Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_OUT_OF_BOUNDS,
d185452 chromatic Standardize internal exception calls (James deBoer, james at huronbox do...
chromatic authored
199 "FixedIntegerArray: index out of bounds!");
d1f7c98 JIT/i386 ord_i_s*
Leopold Toetsch authored
200
e5dead2 cotto [pmc] update *IntegerArray to use ATTRs
cotto authored
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
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
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
216 /* simple int keys only */
757f3a8 chromatic [PMC] Replaced all uses of key_integer() outside of Key PMC and src/key....
chromatic authored
217 const INTVAL k = VTABLE_get_integer(INTERP, key);
59661f1 allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
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
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
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
234 return (FLOATVAL)i;
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored
235 }
236
237 /*
238
95e3676 Infinoid [pmc] PDD07-ize function signatures in src/pmc/[b-f]*.pmc
Infinoid authored
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
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
247 VTABLE FLOATVAL get_number_keyed(PMC *key) {
757f3a8 chromatic [PMC] Replaced all uses of key_integer() outside of Key PMC and src/key....
chromatic authored
248 const INTVAL k = VTABLE_get_integer(INTERP, key);
59661f1 allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
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
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
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
264 return VTABLE_get_string(INTERP, temp);
265 }
bf41b66 Jerry Gay [PDD07]: ws cleanup in src/, src/dynpmc/, and src/pmc/
particle authored
266
5a67dac tewk Add get_repr to fixedintegerarray and integer
tewk authored
267 /*
268
fccdff0 Brian Gernhardt Add get_string to Fixed Float and Integer Array
Benabik authored
269 =item C<STRING *get_string()>
270
5a67dac tewk Add get_repr to fixedintegerarray and integer
tewk authored
271 =item C<STRING *get_repr()>
272
273 Returns the Parrot string representation C<key>.
274
275 =cut
276
277 */
278
fccdff0 Brian Gernhardt Add get_string to Fixed Float and Integer Array
Benabik authored
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
283 VTABLE STRING *get_repr() {
a35f6fd Andy Lester consting & localizing
petdance authored
284 STRING *res = CONST_STRING(INTERP, "[ ");
8d33429 chromatic [PMC] Replaced vtable function calls to find size of fixed integer array...
chromatic authored
285 INTVAL n;
894d448 chromatic [PMC] Minor cleanups and tidyings.
chromatic authored
286 INTVAL j;
5a67dac tewk Add get_repr to fixedintegerarray and integer
tewk authored
287
8d33429 chromatic [PMC] Replaced vtable function calls to find size of fixed integer array...
chromatic authored
288 GET_ATTR_size(INTERP, SELF, n);
289
5a67dac tewk Add get_repr to fixedintegerarray and integer
tewk authored
290 for (j = 0; j < n; ++j) {
a35f6fd Andy Lester consting & localizing
petdance authored
291 PMC * const val = SELF.get_pmc_keyed_int(j);
9b0f14a Vasily Chekalkin Everybody freeze! Immutable strings enters the building.
bacek authored
292 res = Parrot_str_concat(INTERP, res, VTABLE_get_repr(INTERP, val));
894d448 chromatic [PMC] Minor cleanups and tidyings.
chromatic authored
293
5a67dac tewk Add get_repr to fixedintegerarray and integer
tewk authored
294 if (j < n - 1)
9b0f14a Vasily Chekalkin Everybody freeze! Immutable strings enters the building.
bacek authored
295 res = Parrot_str_concat(INTERP, res, CONST_STRING(INTERP, ", "));
5a67dac tewk Add get_repr to fixedintegerarray and integer
tewk authored
296 }
894d448 chromatic [PMC] Minor cleanups and tidyings.
chromatic authored
297
9b0f14a Vasily Chekalkin Everybody freeze! Immutable strings enters the building.
bacek authored
298 res = Parrot_str_concat(INTERP, res, CONST_STRING(INTERP, " ]"));
5a67dac tewk Add get_repr to fixedintegerarray and integer
tewk authored
299 return res;
300 }
301
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored
302
303 /*
304
f3c2cd1 Peter Lobsinger add hashval() implementation to FIA for faster, more efficient hashing
plobsing authored
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
321 return Parrot_hash_buffer((const unsigned char *)int_array,
f3c2cd1 Peter Lobsinger add hashval() implementation to FIA for faster, more efficient hashing
plobsing authored
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
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
336 VTABLE STRING *get_string_keyed(PMC *key) {
757f3a8 chromatic [PMC] Replaced all uses of key_integer() outside of Key PMC and src/key....
chromatic authored
337 const INTVAL k = VTABLE_get_integer(INTERP, key);
59661f1 allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
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
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
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 is ...
NotFound authored
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
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
368 VTABLE PMC *get_pmc_keyed(PMC *key) {
757f3a8 chromatic [PMC] Replaced all uses of key_integer() outside of Key PMC and src/key....
chromatic authored
369 const INTVAL k = VTABLE_get_integer(INTERP, key);
59661f1 allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
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
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
383 VTABLE void set_integer_native(INTVAL size) {
e5dead2 cotto [pmc] update *IntegerArray to use ATTRs
cotto authored
384 INTVAL *int_array;
8d33429 chromatic [PMC] Replaced vtable function calls to find size of fixed integer array...
chromatic authored
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
390 Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_OUT_OF_BOUNDS,
d1f7c98 JIT/i386 ord_i_s*
Leopold Toetsch authored
391 "FixedIntegerArray: Can't resize!");
2255840 allisonrandal [pdd17pmc] Merging the pdd25cx branch into trunk for r26555 to r29949.
allisonrandal authored
392
e5dead2 cotto [pmc] update *IntegerArray to use ATTRs
cotto authored
393 SET_ATTR_size(INTERP, SELF, size);
394 GET_ATTR_int_array(INTERP, SELF, int_array);
7a96a21 Bernhard Schmalhofer [codingstd] tabs.t and trailing_space.t
bschmalhofer authored
395 SET_ATTR_int_array(INTERP, SELF,
4833868 Vasily Chekalkin Merge branch 'sys_mem' into trunk
bacek authored
396 mem_gc_realloc_n_typed(INTERP, int_array, size, INTVAL));
4591dbb chromatic [HLL] Fixed two compilation-breaking typos accidentally committed in r40...
chromatic authored
397 PObj_custom_destroy_SET(SELF);
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored
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 Vasily Chekalkin Mark set_foo_keyed_bar methods with :manual_wb in FIA
bacek authored
410 VTABLE void set_integer_keyed_int(INTVAL key, INTVAL value) :manual_wb {
e5dead2 cotto [pmc] update *IntegerArray to use ATTRs
cotto authored
411 INTVAL *int_array;
8d33429 chromatic [PMC] Replaced vtable function calls to find size of fixed integer array...
chromatic authored
412 INTVAL size;
894d448 chromatic [PMC] Minor cleanups and tidyings.
chromatic authored
413
8d33429 chromatic [PMC] Replaced vtable function calls to find size of fixed integer array...
chromatic authored
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
417 Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_OUT_OF_BOUNDS,
d185452 chromatic Standardize internal exception calls (James deBoer, james at huronbox do...
chromatic authored
418 "FixedIntegerArray: index out of bounds!");
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored
419
e5dead2 cotto [pmc] update *IntegerArray to use ATTRs
cotto authored
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
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 Vasily Chekalkin Mark set_foo_keyed_bar methods with :manual_wb in FIA
bacek authored
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/key....
chromatic authored
435 const INTVAL k = VTABLE_get_integer(INTERP, key);
59661f1 allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
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
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
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
444
445 =cut
446
447 */
448
8fcbee3 Vasily Chekalkin Mark set_foo_keyed_bar methods with :manual_wb in FIA
bacek authored
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
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
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
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
458
459 =cut
460
461 */
462
8fcbee3 Vasily Chekalkin Mark set_foo_keyed_bar methods with :manual_wb in FIA
bacek authored
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/key....
chromatic authored
464 const INTVAL k = VTABLE_get_integer(INTERP, key);
59661f1 allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
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
466 }
d1f7c98 JIT/i386 ord_i_s*
Leopold Toetsch authored
467
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored
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 Vasily Chekalkin Mark set_foo_keyed_bar methods with :manual_wb in FIA
bacek authored
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
479 const INTVAL tempInt = Parrot_str_to_int(INTERP, value);
59661f1 allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
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
481 }
482
483 /*
484
95e3676 Infinoid [pmc] PDD07-ize function signatures in src/pmc/[b-f]*.pmc
Infinoid authored
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
486
894d448 chromatic [PMC] Minor cleanups and tidyings.
chromatic authored
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
488
489 =cut
490
491 */
492
8fcbee3 Vasily Chekalkin Mark set_foo_keyed_bar methods with :manual_wb in FIA
bacek authored
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/key....
chromatic authored
494 const INTVAL k = VTABLE_get_integer(INTERP, key);
59661f1 allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
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
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 Vasily Chekalkin Mark set_foo_keyed_bar methods with :manual_wb in FIA
bacek authored
508 VTABLE void set_pmc_keyed_int(INTVAL key, PMC *src) :manual_wb {
a35f6fd Andy Lester consting & localizing
petdance authored
509 const INTVAL tempInt = VTABLE_get_integer(INTERP, src);
59661f1 allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
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
511 }
512
513 /*
514
95e3676 Infinoid [pmc] PDD07-ize function signatures in src/pmc/[b-f]*.pmc
Infinoid authored
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
516
894d448 chromatic [PMC] Minor cleanups and tidyings.
chromatic authored
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
518
519 =cut
520
521 */
522
8fcbee3 Vasily Chekalkin Mark set_foo_keyed_bar methods with :manual_wb in FIA
bacek authored
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/key....
chromatic authored
524 const INTVAL k = VTABLE_get_integer(INTERP, key);
59661f1 allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
525 SELF.set_pmc_keyed_int(k, value);
526 }
527
6287ae3 add missing fixedintegerarray.freeze and .thaw
Leopold Toetsch authored
528 /*
529
0c38764 Vasily Chekalkin [core] Implement FixedIntegerArray.is_equal
bacek authored
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 Andy Lester consting and annotating
petdance authored
550 const INTVAL item1 = SELF.get_integer_keyed_int(j);
551 const INTVAL item2 = VTABLE_get_integer_keyed_int(INTERP, value, j);
0c38764 Vasily Chekalkin [core] Implement FixedIntegerArray.is_equal
bacek authored
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
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 Andrew Whitworth start rename of pmc_new to Parrot_pmc_new
Whiteknight authored
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
572 }
573
574 /*
575
b101f2c Daniel Arbelo Arrocha Merge pmc_freeze_with_pmcs into trunk.
darbelo authored
576 =item C<void freeze(PMC *info)>
6287ae3 add missing fixedintegerarray.freeze and .thaw
Leopold Toetsch authored
577
578 Used to archive the array.
579
b101f2c Daniel Arbelo Arrocha Merge pmc_freeze_with_pmcs into trunk.
darbelo authored
580 =item C<void thaw(PMC *info)>
6287ae3 add missing fixedintegerarray.freeze and .thaw
Leopold Toetsch authored
581
582 Used to unarchive the array.
583
09dc23b NotFound rarrange initialization and freeze/thaw of FIA and RIA to avoid redundan...
NotFound authored
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
586 =cut
587
588 */
589
b101f2c Daniel Arbelo Arrocha Merge pmc_freeze_with_pmcs into trunk.
darbelo authored
590 VTABLE void freeze(PMC *info) {
e5dead2 cotto [pmc] update *IntegerArray to use ATTRs
cotto authored
591 INTVAL *int_array;
894d448 chromatic [PMC] Minor cleanups and tidyings.
chromatic authored
592 INTVAL i, n;
6287ae3 add missing fixedintegerarray.freeze and .thaw
Leopold Toetsch authored
593
594 SUPER(info);
894d448 chromatic [PMC] Minor cleanups and tidyings.
chromatic authored
595
8d33429 chromatic [PMC] Replaced vtable function calls to find size of fixed integer array...
chromatic authored
596 GET_ATTR_size(INTERP, SELF, n);
4c43475 Peter Lobsinger merge branch pmc_freeze_cleanup
plobsing authored
597 VTABLE_push_integer(INTERP, info, n);
e5dead2 cotto [pmc] update *IntegerArray to use ATTRs
cotto authored
598 GET_ATTR_int_array(INTERP, SELF, int_array);
894d448 chromatic [PMC] Minor cleanups and tidyings.
chromatic authored
599
600 for (i = 0; i < n; ++i)
4c43475 Peter Lobsinger merge branch pmc_freeze_cleanup
plobsing authored
601 VTABLE_push_integer(INTERP, info, int_array[i]);
6287ae3 add missing fixedintegerarray.freeze and .thaw
Leopold Toetsch authored
602 }
603
b101f2c Daniel Arbelo Arrocha Merge pmc_freeze_with_pmcs into trunk.
darbelo authored
604 VTABLE void thaw(PMC *info) {
8640c33 Andy Lester consting vars. Fixed some POD.
petdance authored
605 const INTVAL n = VTABLE_shift_integer(INTERP, info);
09dc23b NotFound rarrange initialization and freeze/thaw of FIA and RIA to avoid redundan...
NotFound authored
606 SELF.init_int(n);
607 if (n > 0) {
4c43475 Peter Lobsinger merge branch pmc_freeze_cleanup
plobsing authored
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
613 }
614 }
ac9988d NotFound some cleaning of FIA: put METHOD after vtable functions and fix and impr...
NotFound authored
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 Vasily Chekalkin Pass cmp signature to quicksort to avoid segmentation fault during fetch...
bacek authored
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 impr...
NotFound authored
647 }
648 RETURN(PMC *SELF);
649 }
650
47a64b4 Michael Schroeder add a "reverse" method for the array types (except boolarray)
mlschroe authored
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 Brian Gernhardt codingstd fixes
Benabik authored
676 }
47a64b4 Michael Schroeder add a "reverse" method for the array types (except boolarray)
mlschroe authored
677
ac9988d NotFound some cleaning of FIA: put METHOD after vtable functions and fix and impr...
NotFound authored
678 }
679
680 /*
681
682 =back
683
cbe2617 James E Keenan Correct spelling error in POD.
jkeenan authored
684 =head2 Auxiliary functions
ac9988d NotFound some cleaning of FIA: put METHOD after vtable functions and fix and impr...
NotFound authored
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
702 }
703
704 /*
705
706 =back
707
708 =head1 SEE ALSO
709
1e8a4ab this patch adds some relevant 'push' ops to the resizable PMCs, describe...
Dan Sugalski authored
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
711
712 =cut
713
714 */
715
716 /*
717 * Local variables:
72575ae Bernhard Schmalhofer #40481: [PATCH] C-code coda in pmc files
bschmalhofer authored
718 * c-file-style: "parrot"
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored
719 * End:
1d7dded Peter Lobsinger update C file vim modelines
plobsing authored
720 * vim: expandtab shiftwidth=4 cinoptions='\:2=2' :
72575ae Bernhard Schmalhofer #40481: [PATCH] C-code coda in pmc files
bschmalhofer authored
721 */
Something went wrong with that request. Please try again.