Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 669 lines (426 sloc) 13.515 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;
112 PMC * const dest =
a35f6fd Andy Lester consting & localizing
petdance authored
113 PObj_constant_TEST(SELF)
dc5a60b Andrew Whitworth finish the bulk of the conversions, parrot builds
Whiteknight authored
114 ? Parrot_pmc_new_constant(INTERP, SELF->vtable->base_type)
083213a Andrew Whitworth start rename of pmc_new to Parrot_pmc_new
Whiteknight authored
115 : Parrot_pmc_new(INTERP, SELF->vtable->base_type);
894d448 chromatic [PMC] Minor cleanups and tidyings.
chromatic authored
116
e5dead2 cotto [pmc] update *IntegerArray to use ATTRs
cotto authored
117 GET_ATTR_int_array(INTERP, SELF, int_array);
8d33429 chromatic [PMC] Replaced vtable function calls to find size of fixed integer array...
chromatic authored
118
e5dead2 cotto [pmc] update *IntegerArray to use ATTRs
cotto authored
119 if (int_array) {
42f27d4 NotFound clean FIA.clone
NotFound authored
120 INTVAL size;
8d33429 chromatic [PMC] Replaced vtable function calls to find size of fixed integer array...
chromatic authored
121 GET_ATTR_size(INTERP, SELF, size);
42f27d4 NotFound clean FIA.clone
NotFound authored
122 {
123 INTVAL * const dest_int_array = mem_gc_allocate_n_typed(INTERP,
124 size, INTVAL);
125 mem_copy_n_typed(dest_int_array, int_array,
126 size, INTVAL);
127 SET_ATTR_int_array(INTERP, dest, dest_int_array);
128 }
e5dead2 cotto [pmc] update *IntegerArray to use ATTRs
cotto authored
129 SET_ATTR_size(INTERP, dest, size);
4591dbb chromatic [HLL] Fixed two compilation-breaking typos accidentally committed in r40...
chromatic authored
130 PObj_custom_destroy_SET(dest);
a35f6fd Andy Lester consting & localizing
petdance authored
131 }
894d448 chromatic [PMC] Minor cleanups and tidyings.
chromatic authored
132
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored
133 return dest;
134 }
135
136 /*
137
138 =item C<INTVAL get_bool()>
139
140 Returns whether the array has any elements (meaning been initialized, for a
141 fixed sized array).
142
143 =cut
144
145 */
59661f1 allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
146 VTABLE INTVAL get_bool() {
8d33429 chromatic [PMC] Replaced vtable function calls to find size of fixed integer array...
chromatic authored
147 INTVAL size;
148 GET_ATTR_size(INTERP, SELF, size);
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored
149 return (INTVAL)(size != 0);
150 }
151
152 /*
153
154 =item C<INTVAL elements()>
155
156 =cut
157
158 */
159
59661f1 allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
160 VTABLE INTVAL elements() {
8d33429 chromatic [PMC] Replaced vtable function calls to find size of fixed integer array...
chromatic authored
161 INTVAL size;
162 GET_ATTR_size(INTERP, SELF, size);
163
164 return size;
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored
165 }
166
167 /*
168
169 =item C<INTVAL get_integer()>
170
171 Returns the number of elements in the array.
172
173 =cut
174
175 */
176
59661f1 allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
177 VTABLE INTVAL get_integer() {
8d33429 chromatic [PMC] Replaced vtable function calls to find size of fixed integer array...
chromatic authored
178 INTVAL size;
179 GET_ATTR_size(INTERP, SELF, size);
180 return size;
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored
181 }
182
183
184 /*
185
186 =item C<INTVAL get_integer_keyed_int(INTVAL key)>
187
188 Returns the integer value of the element at index C<key>.
189
190 =cut
191
192 */
193
59661f1 allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
194 VTABLE INTVAL get_integer_keyed_int(INTVAL key) {
e5dead2 cotto [pmc] update *IntegerArray to use ATTRs
cotto authored
195 INTVAL *int_array;
8d33429 chromatic [PMC] Replaced vtable function calls to find size of fixed integer array...
chromatic authored
196 INTVAL size;
894d448 chromatic [PMC] Minor cleanups and tidyings.
chromatic authored
197
8d33429 chromatic [PMC] Replaced vtable function calls to find size of fixed integer array...
chromatic authored
198 GET_ATTR_size(INTERP, SELF, size);
199
200 if (key < 0 || key >= size)
26914e1 changed interp in pmc class to INTERP for unification
Jimmy Zhuo authored
201 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
202 "FixedIntegerArray: index out of bounds!");
d1f7c98 JIT/i386 ord_i_s*
Leopold Toetsch authored
203
e5dead2 cotto [pmc] update *IntegerArray to use ATTRs
cotto authored
204 GET_ATTR_int_array(INTERP, SELF, int_array);
205 return int_array[key];
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored
206 }
207
208 /*
209
210 =item C<INTVAL get_integer_keyed(PMC *key)>
211
212 Returns the integer value of the element at index C<*key>.
213
214 =cut
215
216 */
217
59661f1 allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
218 VTABLE INTVAL get_integer_keyed(PMC *key) {
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored
219 /* simple int keys only */
757f3a8 chromatic [PMC] Replaced all uses of key_integer() outside of Key PMC and src/key....
chromatic authored
220 const INTVAL k = VTABLE_get_integer(INTERP, key);
59661f1 allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
221 return SELF.get_integer_keyed_int(k);
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored
222 }
223
224
225 /*
226
227 =item C<FLOATVAL get_number_keyed_int(INTVAL key)>
228
229 Returns the floating-point value of the element at index C<key>.
230
231 =cut
232
233 */
234
59661f1 allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
235 VTABLE FLOATVAL get_number_keyed_int(INTVAL key) {
236 const INTVAL i = SELF.get_integer_keyed_int(key);
8275ff5 chromatic [PMC] Fixed a couple of casting warnings of function return values.
chromatic authored
237 return (FLOATVAL)i;
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored
238 }
239
240 /*
241
95e3676 Infinoid [pmc] PDD07-ize function signatures in src/pmc/[b-f]*.pmc
Infinoid authored
242 =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
243
244 Returns the floating-point value of the element at index C<*key>.
245
246 =cut
247
248 */
249
59661f1 allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
250 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
251 const INTVAL k = VTABLE_get_integer(INTERP, key);
59661f1 allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
252 return SELF.get_number_keyed_int(k);
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored
253 }
254
255 /*
256
257 =item C<STRING *get_string_keyed_int(INTVAL key)>
258
259 Returns the Parrot string value of the element at index C<key>.
260
261 =cut
262
263 */
264
59661f1 allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
265 VTABLE STRING *get_string_keyed_int(INTVAL key) {
266 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
267 return VTABLE_get_string(INTERP, temp);
268 }
bf41b66 Jerry Gay [PDD07]: ws cleanup in src/, src/dynpmc/, and src/pmc/
particle authored
269
5a67dac tewk Add get_repr to fixedintegerarray and integer
tewk authored
270 /*
271
272 =item C<STRING *get_repr()>
273
274 Returns the Parrot string representation C<key>.
275
276 =cut
277
278 */
279
59661f1 allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
280 VTABLE STRING *get_repr() {
a35f6fd Andy Lester consting & localizing
petdance authored
281 STRING *res = CONST_STRING(INTERP, "[ ");
8d33429 chromatic [PMC] Replaced vtable function calls to find size of fixed integer array...
chromatic authored
282 INTVAL n;
894d448 chromatic [PMC] Minor cleanups and tidyings.
chromatic authored
283 INTVAL j;
5a67dac tewk Add get_repr to fixedintegerarray and integer
tewk authored
284
8d33429 chromatic [PMC] Replaced vtable function calls to find size of fixed integer array...
chromatic authored
285 GET_ATTR_size(INTERP, SELF, n);
286
5a67dac tewk Add get_repr to fixedintegerarray and integer
tewk authored
287 for (j = 0; j < n; ++j) {
a35f6fd Andy Lester consting & localizing
petdance authored
288 PMC * const val = SELF.get_pmc_keyed_int(j);
9b0f14a Vasily Chekalkin Everybody freeze! Immutable strings enters the building.
bacek authored
289 res = Parrot_str_concat(INTERP, res, VTABLE_get_repr(INTERP, val));
894d448 chromatic [PMC] Minor cleanups and tidyings.
chromatic authored
290
5a67dac tewk Add get_repr to fixedintegerarray and integer
tewk authored
291 if (j < n - 1)
9b0f14a Vasily Chekalkin Everybody freeze! Immutable strings enters the building.
bacek authored
292 res = Parrot_str_concat(INTERP, res, CONST_STRING(INTERP, ", "));
5a67dac tewk Add get_repr to fixedintegerarray and integer
tewk authored
293 }
894d448 chromatic [PMC] Minor cleanups and tidyings.
chromatic authored
294
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 return res;
297 }
298
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored
299
300 /*
301
302 =item C<STRING *get_string_keyed(PMC *key)>
303
304 Returns the Parrot string value of the element at index C<*key>.
305
306 =cut
307
308 */
309
59661f1 allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
310 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
311 const INTVAL k = VTABLE_get_integer(INTERP, key);
59661f1 allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
312 return SELF.get_string_keyed_int(k);
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored
313 }
314
315
316 /*
317
318 =item C<PMC *get_pmc_keyed_int(INTVAL key)>
319
320 Returns the PMC value of the element at index C<key>.
321
322 =cut
323
324 */
325
59661f1 allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
326 VTABLE PMC *get_pmc_keyed_int(INTVAL key) {
327 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
328 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
329 return ret;
330 }
331
332 /*
333
334 =item C<PMC *get_pmc_keyed(PMC *key)>
335
336 Returns the PMC value of the element at index C<*key>.
337
338 =cut
339
340 */
341
59661f1 allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
342 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
343 const INTVAL k = VTABLE_get_integer(INTERP, key);
59661f1 allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
344 return SELF.get_pmc_keyed_int(k);
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored
345 }
346
347 /*
348
349 =item C<void set_integer_native(INTVAL size)>
350
351 Resizes the array to C<size> elements.
352
353 =cut
354
355 */
356
59661f1 allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
357 VTABLE void set_integer_native(INTVAL size) {
e5dead2 cotto [pmc] update *IntegerArray to use ATTRs
cotto authored
358 INTVAL *int_array;
8d33429 chromatic [PMC] Replaced vtable function calls to find size of fixed integer array...
chromatic authored
359 INTVAL cur_size;
360
361 GET_ATTR_size(INTERP, SELF, cur_size);
362
363 if (cur_size || size < 1)
2255840 allisonrandal [pdd17pmc] Merging the pdd25cx branch into trunk for r26555 to r29949.
allisonrandal authored
364 Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_OUT_OF_BOUNDS,
d1f7c98 JIT/i386 ord_i_s*
Leopold Toetsch authored
365 "FixedIntegerArray: Can't resize!");
2255840 allisonrandal [pdd17pmc] Merging the pdd25cx branch into trunk for r26555 to r29949.
allisonrandal authored
366
e5dead2 cotto [pmc] update *IntegerArray to use ATTRs
cotto authored
367 SET_ATTR_size(INTERP, SELF, size);
368 GET_ATTR_int_array(INTERP, SELF, int_array);
7a96a21 Bernhard Schmalhofer [codingstd] tabs.t and trailing_space.t
bschmalhofer authored
369 SET_ATTR_int_array(INTERP, SELF,
4833868 Vasily Chekalkin Merge branch 'sys_mem' into trunk
bacek authored
370 mem_gc_realloc_n_typed(INTERP, int_array, size, INTVAL));
4591dbb chromatic [HLL] Fixed two compilation-breaking typos accidentally committed in r40...
chromatic authored
371 PObj_custom_destroy_SET(SELF);
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored
372 }
373
374 /*
375
376 =item C<void set_integer_keyed_int(INTVAL key, INTVAL value)>
377
378 Sets the integer value of the element at index C<key> to C<value>.
379
380 =cut
381
382 */
383
8fcbee3 Vasily Chekalkin Mark set_foo_keyed_bar methods with :manual_wb in FIA
bacek authored
384 VTABLE void set_integer_keyed_int(INTVAL key, INTVAL value) :manual_wb {
e5dead2 cotto [pmc] update *IntegerArray to use ATTRs
cotto authored
385 INTVAL *int_array;
8d33429 chromatic [PMC] Replaced vtable function calls to find size of fixed integer array...
chromatic authored
386 INTVAL size;
894d448 chromatic [PMC] Minor cleanups and tidyings.
chromatic authored
387
8d33429 chromatic [PMC] Replaced vtable function calls to find size of fixed integer array...
chromatic authored
388 GET_ATTR_size(INTERP, SELF, size);
389
390 if (key < 0 || key >= size)
26914e1 changed interp in pmc class to INTERP for unification
Jimmy Zhuo authored
391 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
392 "FixedIntegerArray: index out of bounds!");
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored
393
e5dead2 cotto [pmc] update *IntegerArray to use ATTRs
cotto authored
394 GET_ATTR_int_array(INTERP, SELF, int_array);
395 int_array[key] = value;
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored
396 }
397
398 /*
399
400 =item C<void set_integer_keyed(PMC *key, INTVAL value)>
401
402 Sets the integer value of the element at index C<key> to C<value>.
403
404 =cut
405
406 */
407
8fcbee3 Vasily Chekalkin Mark set_foo_keyed_bar methods with :manual_wb in FIA
bacek authored
408 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
409 const INTVAL k = VTABLE_get_integer(INTERP, key);
59661f1 allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
410 SELF.set_integer_keyed_int(k, value);
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored
411 }
412
413 /*
414
415 =item C<void set_number_keyed_int(INTVAL key, FLOATVAL value)>
416
894d448 chromatic [PMC] Minor cleanups and tidyings.
chromatic authored
417 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
418
419 =cut
420
421 */
422
8fcbee3 Vasily Chekalkin Mark set_foo_keyed_bar methods with :manual_wb in FIA
bacek authored
423 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
424 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
425 }
426
427 /*
428
429 =item C<void set_number_keyed(PMC *key, FLOATVAL value)>
430
894d448 chromatic [PMC] Minor cleanups and tidyings.
chromatic authored
431 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
432
433 =cut
434
435 */
436
8fcbee3 Vasily Chekalkin Mark set_foo_keyed_bar methods with :manual_wb in FIA
bacek authored
437 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
438 const INTVAL k = VTABLE_get_integer(INTERP, key);
59661f1 allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
439 SELF.set_number_keyed_int(k, value);
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored
440 }
d1f7c98 JIT/i386 ord_i_s*
Leopold Toetsch authored
441
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored
442 /*
443
444 =item C<void set_string_keyed_int(INTVAL key, STRING *value)>
445
446 Sets the Parrot string value of the element at index C<key> to C<value>.
447
448 =cut
449
450 */
451
8fcbee3 Vasily Chekalkin Mark set_foo_keyed_bar methods with :manual_wb in FIA
bacek authored
452 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
453 const INTVAL tempInt = Parrot_str_to_int(INTERP, value);
59661f1 allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
454 SELF.set_integer_keyed_int(key, tempInt);
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored
455 }
456
457 /*
458
95e3676 Infinoid [pmc] PDD07-ize function signatures in src/pmc/[b-f]*.pmc
Infinoid authored
459 =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
460
894d448 chromatic [PMC] Minor cleanups and tidyings.
chromatic authored
461 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
462
463 =cut
464
465 */
466
8fcbee3 Vasily Chekalkin Mark set_foo_keyed_bar methods with :manual_wb in FIA
bacek authored
467 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
468 const INTVAL k = VTABLE_get_integer(INTERP, key);
59661f1 allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
469 SELF.set_string_keyed_int(k, value);
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored
470 }
471
472 /*
473
474 =item C<void set_pmc_keyed_int(INTVAL key, PMC *src)>
475
476 Sets the PMC value of the element at index C<key> to C<*src>.
477
478 =cut
479
480 */
481
8fcbee3 Vasily Chekalkin Mark set_foo_keyed_bar methods with :manual_wb in FIA
bacek authored
482 VTABLE void set_pmc_keyed_int(INTVAL key, PMC *src) :manual_wb {
a35f6fd Andy Lester consting & localizing
petdance authored
483 const INTVAL tempInt = VTABLE_get_integer(INTERP, src);
59661f1 allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
484 SELF.set_integer_keyed_int(key, tempInt);
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored
485 }
486
487 /*
488
95e3676 Infinoid [pmc] PDD07-ize function signatures in src/pmc/[b-f]*.pmc
Infinoid authored
489 =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
490
894d448 chromatic [PMC] Minor cleanups and tidyings.
chromatic authored
491 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
492
493 =cut
494
495 */
496
8fcbee3 Vasily Chekalkin Mark set_foo_keyed_bar methods with :manual_wb in FIA
bacek authored
497 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
498 const INTVAL k = VTABLE_get_integer(INTERP, key);
59661f1 allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
499 SELF.set_pmc_keyed_int(k, value);
500 }
501
6287ae3 add missing fixedintegerarray.freeze and .thaw
Leopold Toetsch authored
502 /*
503
0c38764 Vasily Chekalkin [core] Implement FixedIntegerArray.is_equal
bacek authored
504 =item C<INTVAL is_equal(PMC *value)>
505
506 The C<==> operation. Compares two array to hold equal elements.
507
508 =cut
509
510 */
511
512 VTABLE INTVAL is_equal(PMC *value) {
513 INTVAL j, n;
514
515 if (value->vtable->base_type != SELF->vtable->base_type)
516 return 0;
517
518 n = SELF.elements();
519
520 if (VTABLE_elements(INTERP, value) != n)
521 return 0;
522
523 for (j = 0; j < n; ++j) {
f9cca7d Andy Lester consting and annotating
petdance authored
524 const INTVAL item1 = SELF.get_integer_keyed_int(j);
525 const INTVAL item2 = VTABLE_get_integer_keyed_int(INTERP, value, j);
0c38764 Vasily Chekalkin [core] Implement FixedIntegerArray.is_equal
bacek authored
526
527 if (item1 != item2)
528 return 0;
529 }
530
531 return 1;
532 }
533
534 /*
535
bd8aacd cotto [PMC] add get_iter VTABLE function and tests to *IntegerArray
cotto authored
536 =item C<PMC *get_iter()>
537
538 Return a new Iterator for this PMC.
539
540 =cut
541
542 */
543
544 VTABLE PMC *get_iter() {
083213a Andrew Whitworth start rename of pmc_new to Parrot_pmc_new
Whiteknight authored
545 return Parrot_pmc_new_init(INTERP, enum_class_ArrayIterator, SELF);
bd8aacd cotto [PMC] add get_iter VTABLE function and tests to *IntegerArray
cotto authored
546 }
547
548 /*
549
b101f2c Daniel Arbelo Arrocha Merge pmc_freeze_with_pmcs into trunk.
darbelo authored
550 =item C<void freeze(PMC *info)>
6287ae3 add missing fixedintegerarray.freeze and .thaw
Leopold Toetsch authored
551
552 Used to archive the array.
553
b101f2c Daniel Arbelo Arrocha Merge pmc_freeze_with_pmcs into trunk.
darbelo authored
554 =item C<void thaw(PMC *info)>
6287ae3 add missing fixedintegerarray.freeze and .thaw
Leopold Toetsch authored
555
556 Used to unarchive the array.
557
09dc23b NotFound rarrange initialization and freeze/thaw of FIA and RIA to avoid redundan...
NotFound authored
558 C<*info> is the visit info, (see F<include/parrot/pmc_freeze.h>).
559
6287ae3 add missing fixedintegerarray.freeze and .thaw
Leopold Toetsch authored
560 =cut
561
562 */
563
b101f2c Daniel Arbelo Arrocha Merge pmc_freeze_with_pmcs into trunk.
darbelo authored
564 VTABLE void freeze(PMC *info) {
e5dead2 cotto [pmc] update *IntegerArray to use ATTRs
cotto authored
565 INTVAL *int_array;
894d448 chromatic [PMC] Minor cleanups and tidyings.
chromatic authored
566 INTVAL i, n;
6287ae3 add missing fixedintegerarray.freeze and .thaw
Leopold Toetsch authored
567
568 SUPER(info);
894d448 chromatic [PMC] Minor cleanups and tidyings.
chromatic authored
569
8d33429 chromatic [PMC] Replaced vtable function calls to find size of fixed integer array...
chromatic authored
570 GET_ATTR_size(INTERP, SELF, n);
4c43475 Peter Lobsinger merge branch pmc_freeze_cleanup
plobsing authored
571 VTABLE_push_integer(INTERP, info, n);
e5dead2 cotto [pmc] update *IntegerArray to use ATTRs
cotto authored
572 GET_ATTR_int_array(INTERP, SELF, int_array);
894d448 chromatic [PMC] Minor cleanups and tidyings.
chromatic authored
573
574 for (i = 0; i < n; ++i)
4c43475 Peter Lobsinger merge branch pmc_freeze_cleanup
plobsing authored
575 VTABLE_push_integer(INTERP, info, int_array[i]);
6287ae3 add missing fixedintegerarray.freeze and .thaw
Leopold Toetsch authored
576 }
577
b101f2c Daniel Arbelo Arrocha Merge pmc_freeze_with_pmcs into trunk.
darbelo authored
578 VTABLE void thaw(PMC *info) {
09dc23b NotFound rarrange initialization and freeze/thaw of FIA and RIA to avoid redundan...
NotFound authored
579 INTVAL n = VTABLE_shift_integer(INTERP, info);
580 SELF.init_int(n);
581 if (n > 0) {
4c43475 Peter Lobsinger merge branch pmc_freeze_cleanup
plobsing authored
582 INTVAL i;
583 INTVAL *int_array;
584 GET_ATTR_int_array(INTERP, SELF, int_array);
585 for (i = 0; i < n; ++i)
586 int_array[i] = VTABLE_shift_integer(INTERP, info);
6287ae3 add missing fixedintegerarray.freeze and .thaw
Leopold Toetsch authored
587 }
588 }
ac9988d NotFound some cleaning of FIA: put METHOD after vtable functions and fix and impr...
NotFound authored
589
590 /*
591
592 =back
593
594 =head2 Methods
595
596 =over 4
597
598 =item C<PMC *sort()>
599
600 Sort the array and return self.
601
602 =cut
603
604 */
605
606 METHOD sort(PMC *cmp_func :optional) {
607 UINTVAL n;
608 INTVAL size;
609
610 GET_ATTR_size(INTERP, SELF, size);
611 n = (UINTVAL)size;
612
613 if (n > 1) {
614 INTVAL *int_array;
615 GET_ATTR_int_array(INTERP, SELF, int_array);
616 if (PMC_IS_NULL(cmp_func))
617 qsort(int_array, n, sizeof (INTVAL),
618 (int (*)(const void *, const void*))auxcmpfunc);
619 else
4379aa4 Vasily Chekalkin Pass cmp signature to quicksort to avoid segmentation fault during fetch...
bacek authored
620 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
621 }
622 RETURN(PMC *SELF);
623 }
624
625 }
626
627 /*
628
629 =back
630
cbe2617 James E Keenan Correct spelling error in POD.
jkeenan authored
631 =head2 Auxiliary functions
ac9988d NotFound some cleaning of FIA: put METHOD after vtable functions and fix and impr...
NotFound authored
632
633 =over 4
634
635 =item C<static int auxcmpfunc(const INTVAL *i, const INTVAL *j)>
636
637 INTVAL compare function for qsort usage.
638
639 =cut
640
641 */
642
643 PARROT_PURE_FUNCTION
644 static int
645 auxcmpfunc(ARGIN(const INTVAL *i), ARGIN(const INTVAL *j))
646 {
647 ASSERT_ARGS(auxcmpfunc)
648 return *i - *j;
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored
649 }
650
651 /*
652
653 =back
654
655 =head1 SEE ALSO
656
1e8a4ab this patch adds some relevant 'push' ops to the resizable PMCs, describe...
Dan Sugalski authored
657 F<docs/pdds/pdd17_basic_types.pod>.
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored
658
659 =cut
660
661 */
662
663 /*
664 * Local variables:
72575ae Bernhard Schmalhofer #40481: [PATCH] C-code coda in pmc files
bschmalhofer authored
665 * c-file-style: "parrot"
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored
666 * End:
1d7dded Peter Lobsinger update C file vim modelines
plobsing authored
667 * vim: expandtab shiftwidth=4 cinoptions='\:2=2' :
72575ae Bernhard Schmalhofer #40481: [PATCH] C-code coda in pmc files
bschmalhofer authored
668 */
Something went wrong with that request. Please try again.