Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

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