Skip to content

HTTPS clone URL

Subversion checkout URL

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