Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 723 lines (463 sloc) 14.509 kB
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored
1 /*
c1411da @rurban [cage] mark and document unused parameters as such
rurban authored
2 Copyright (C) 2001-2012, 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() {
c1411da @rurban [cage] mark and document unused parameters as such
rurban authored
52 UNUSED(INTERP)
4591dbb @chromatic [HLL] Fixed two compilation-breaking typos accidentally committed in …
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 c…
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 c…
leto authored
69 _("FixedIntegerArray: Cannot set array size to a negative number (%d)"), size);
09dc23b @NotFound rarrange initialization and freeze/thaw of FIA and RIA to avoid redun…
NotFound authored
70 if (size > 0) {
71 SET_ATTR_size(INTERP, SELF, size);
72 SET_ATTR_int_array(INTERP, SELF, mem_gc_allocate_n_typed(INTERP, size, INTVAL));
73 }
714df2a @tewk VTABLE_init_int commented out tests
tewk authored
74 PObj_custom_destroy_SET(SELF);
75 }
76
77 /*
78
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored
79 =item C<void destroy()>
80
81 Destroys the array.
82
83 =cut
84
85 */
86
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
87 VTABLE void destroy() {
e5dead2 @cotto [pmc] update *IntegerArray to use ATTRs
cotto authored
88 INTVAL* int_array;
89 GET_ATTR_int_array(INTERP, SELF, int_array);
90 if (int_array)
4833868 @bacek Merge branch 'sys_mem' into trunk
bacek authored
91 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
92 }
93
94 /*
95
96 =item C<PMC *clone()>
97
98 Creates and returns a copy of the array.
99
100 =cut
101
102 */
103
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
104 VTABLE PMC *clone() {
9822a24 var_args 8 - verify signature during bytecode creation
Leopold Toetsch authored
105 /* a quick hack to create a clone in the constant PMC arena
106 * this is needed for the call signatures
107 *
108 * a better way would be probably to supply a flag to the clone
109 * vtable
110 */
111
e5dead2 @cotto [pmc] update *IntegerArray to use ATTRs
cotto authored
112 INTVAL * int_array;
84fbdb5 @bacek Don't clone self to constant PMC.
bacek authored
113 PMC * const dest = 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
fccdff0 @Benabik Add get_string to Fixed Float and Integer Array
Benabik authored
270 =item C<STRING *get_string()>
271
5a67dac @tewk Add get_repr to fixedintegerarray and integer
tewk authored
272 =item C<STRING *get_repr()>
273
274 Returns the Parrot string representation C<key>.
275
276 =cut
277
278 */
279
fccdff0 @Benabik Add get_string to Fixed Float and Integer Array
Benabik authored
280 VTABLE STRING *get_string() {
281 return STATICSELF.get_repr();
282 }
283
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
284 VTABLE STRING *get_repr() {
a35f6fd @petdance consting & localizing
petdance authored
285 STRING *res = CONST_STRING(INTERP, "[ ");
8d33429 @chromatic [PMC] Replaced vtable function calls to find size of fixed integer ar…
chromatic authored
286 INTVAL n;
894d448 @chromatic [PMC] Minor cleanups and tidyings.
chromatic authored
287 INTVAL j;
5a67dac @tewk Add get_repr to fixedintegerarray and integer
tewk authored
288
8d33429 @chromatic [PMC] Replaced vtable function calls to find size of fixed integer ar…
chromatic authored
289 GET_ATTR_size(INTERP, SELF, n);
290
5a67dac @tewk Add get_repr to fixedintegerarray and integer
tewk authored
291 for (j = 0; j < n; ++j) {
a35f6fd @petdance consting & localizing
petdance authored
292 PMC * const val = SELF.get_pmc_keyed_int(j);
9b0f14a @bacek Everybody freeze! Immutable strings enters the building.
bacek authored
293 res = Parrot_str_concat(INTERP, res, VTABLE_get_repr(INTERP, val));
894d448 @chromatic [PMC] Minor cleanups and tidyings.
chromatic authored
294
5a67dac @tewk Add get_repr to fixedintegerarray and integer
tewk authored
295 if (j < n - 1)
9b0f14a @bacek Everybody freeze! Immutable strings enters the building.
bacek authored
296 res = Parrot_str_concat(INTERP, res, CONST_STRING(INTERP, ", "));
5a67dac @tewk Add get_repr to fixedintegerarray and integer
tewk authored
297 }
894d448 @chromatic [PMC] Minor cleanups and tidyings.
chromatic authored
298
9b0f14a @bacek Everybody freeze! Immutable strings enters the building.
bacek authored
299 res = Parrot_str_concat(INTERP, res, CONST_STRING(INTERP, " ]"));
5a67dac @tewk Add get_repr to fixedintegerarray and integer
tewk authored
300 return res;
301 }
302
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored
303
304 /*
305
f3c2cd1 @plobsing add hashval() implementation to FIA for faster, more efficient hashing
plobsing authored
306 =item C<INTVAL hashvalue()>
307
308 Get a hashvalue for this PMC.
309
310 Providing a non-default C<hashvalue()> implementation avoids creating
311 unecessary string temporaries.
312
313 =cut
314
315 */
316
317 VTABLE INTVAL hashvalue() {
318 INTVAL *int_array;
319 INTVAL size;
320 GET_ATTR_int_array(INTERP, SELF, int_array);
321 GET_ATTR_size(INTERP, SELF, size);
c114262 s/Parrot_hsh_hash_buffer/Parrot_hash_buffer/
Jimmy Zhuo authored
322 return Parrot_hash_buffer((const unsigned char *)int_array,
f3c2cd1 @plobsing add hashval() implementation to FIA for faster, more efficient hashing
plobsing authored
323 size * sizeof (INTVAL), INTERP->hash_seed);
324 }
325
326
327 /*
328
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored
329 =item C<STRING *get_string_keyed(PMC *key)>
330
331 Returns the Parrot string value of the element at index C<*key>.
332
333 =cut
334
335 */
336
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
337 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
338 const INTVAL k = VTABLE_get_integer(INTERP, key);
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
339 return SELF.get_string_keyed_int(k);
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored
340 }
341
342
343 /*
344
345 =item C<PMC *get_pmc_keyed_int(INTVAL key)>
346
347 Returns the PMC value of the element at index C<key>.
348
349 =cut
350
351 */
352
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
353 VTABLE PMC *get_pmc_keyed_int(INTVAL key) {
354 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
355 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
356 return ret;
357 }
358
359 /*
360
361 =item C<PMC *get_pmc_keyed(PMC *key)>
362
363 Returns the PMC value of the element at index C<*key>.
364
365 =cut
366
367 */
368
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
369 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
370 const INTVAL k = VTABLE_get_integer(INTERP, key);
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
371 return SELF.get_pmc_keyed_int(k);
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_native(INTVAL size)>
377
378 Resizes the array to C<size> elements.
379
380 =cut
381
382 */
383
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
384 VTABLE void set_integer_native(INTVAL size) {
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 ar…
chromatic authored
386 INTVAL cur_size;
387
388 GET_ATTR_size(INTERP, SELF, cur_size);
389
390 if (cur_size || size < 1)
2255840 @allisonrandal [pdd17pmc] Merging the pdd25cx branch into trunk for r26555 to r29949.
allisonrandal authored
391 Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_OUT_OF_BOUNDS,
d1f7c98 JIT/i386 ord_i_s*
Leopold Toetsch authored
392 "FixedIntegerArray: Can't resize!");
2255840 @allisonrandal [pdd17pmc] Merging the pdd25cx branch into trunk for r26555 to r29949.
allisonrandal authored
393
e5dead2 @cotto [pmc] update *IntegerArray to use ATTRs
cotto authored
394 SET_ATTR_size(INTERP, SELF, size);
395 GET_ATTR_int_array(INTERP, SELF, int_array);
7a96a21 @bschmalhofer [codingstd] tabs.t and trailing_space.t
bschmalhofer authored
396 SET_ATTR_int_array(INTERP, SELF,
4833868 @bacek Merge branch 'sys_mem' into trunk
bacek authored
397 mem_gc_realloc_n_typed(INTERP, int_array, size, INTVAL));
4591dbb @chromatic [HLL] Fixed two compilation-breaking typos accidentally committed in …
chromatic authored
398 PObj_custom_destroy_SET(SELF);
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored
399 }
400
401 /*
402
403 =item C<void set_integer_keyed_int(INTVAL key, INTVAL value)>
404
405 Sets the integer value of the element at index C<key> to C<value>.
406
407 =cut
408
409 */
410
8fcbee3 @bacek Mark set_foo_keyed_bar methods with :manual_wb in FIA
bacek authored
411 VTABLE void set_integer_keyed_int(INTVAL key, INTVAL value) :manual_wb {
e5dead2 @cotto [pmc] update *IntegerArray to use ATTRs
cotto authored
412 INTVAL *int_array;
8d33429 @chromatic [PMC] Replaced vtable function calls to find size of fixed integer ar…
chromatic authored
413 INTVAL size;
894d448 @chromatic [PMC] Minor cleanups and tidyings.
chromatic authored
414
8d33429 @chromatic [PMC] Replaced vtable function calls to find size of fixed integer ar…
chromatic authored
415 GET_ATTR_size(INTERP, SELF, size);
416
417 if (key < 0 || key >= size)
26914e1 changed interp in pmc class to INTERP for unification
Jimmy Zhuo authored
418 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
419 "FixedIntegerArray: index out of bounds!");
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored
420
e5dead2 @cotto [pmc] update *IntegerArray to use ATTRs
cotto authored
421 GET_ATTR_int_array(INTERP, SELF, int_array);
422 int_array[key] = 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_integer_keyed(PMC *key, INTVAL value)>
428
429 Sets the integer value of the element at index C<key> to C<value>.
430
431 =cut
432
433 */
434
8fcbee3 @bacek Mark set_foo_keyed_bar methods with :manual_wb in FIA
bacek authored
435 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/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_integer_keyed_int(k, value);
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored
438 }
439
440 /*
441
442 =item C<void set_number_keyed_int(INTVAL key, FLOATVAL value)>
443
894d448 @chromatic [PMC] Minor cleanups and tidyings.
chromatic authored
444 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
445
446 =cut
447
448 */
449
8fcbee3 @bacek Mark set_foo_keyed_bar methods with :manual_wb in FIA
bacek authored
450 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
451 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
452 }
453
454 /*
455
456 =item C<void set_number_keyed(PMC *key, FLOATVAL value)>
457
894d448 @chromatic [PMC] Minor cleanups and tidyings.
chromatic authored
458 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
459
460 =cut
461
462 */
463
8fcbee3 @bacek Mark set_foo_keyed_bar methods with :manual_wb in FIA
bacek authored
464 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/k…
chromatic authored
465 const INTVAL k = VTABLE_get_integer(INTERP, key);
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
466 SELF.set_number_keyed_int(k, value);
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored
467 }
d1f7c98 JIT/i386 ord_i_s*
Leopold Toetsch authored
468
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored
469 /*
470
471 =item C<void set_string_keyed_int(INTVAL key, STRING *value)>
472
473 Sets the Parrot string value of the element at index C<key> to C<value>.
474
475 =cut
476
477 */
478
8fcbee3 @bacek Mark set_foo_keyed_bar methods with :manual_wb in FIA
bacek authored
479 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
480 const INTVAL tempInt = Parrot_str_to_int(INTERP, value);
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
481 SELF.set_integer_keyed_int(key, tempInt);
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored
482 }
483
484 /*
485
95e3676 @Infinoid [pmc] PDD07-ize function signatures in src/pmc/[b-f]*.pmc
Infinoid authored
486 =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
487
894d448 @chromatic [PMC] Minor cleanups and tidyings.
chromatic authored
488 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
489
490 =cut
491
492 */
493
8fcbee3 @bacek Mark set_foo_keyed_bar methods with :manual_wb in FIA
bacek authored
494 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/k…
chromatic authored
495 const INTVAL k = VTABLE_get_integer(INTERP, key);
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
496 SELF.set_string_keyed_int(k, value);
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored
497 }
498
499 /*
500
501 =item C<void set_pmc_keyed_int(INTVAL key, PMC *src)>
502
503 Sets the PMC value of the element at index C<key> to C<*src>.
504
505 =cut
506
507 */
508
8fcbee3 @bacek Mark set_foo_keyed_bar methods with :manual_wb in FIA
bacek authored
509 VTABLE void set_pmc_keyed_int(INTVAL key, PMC *src) :manual_wb {
a35f6fd @petdance consting & localizing
petdance authored
510 const INTVAL tempInt = VTABLE_get_integer(INTERP, src);
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
511 SELF.set_integer_keyed_int(key, tempInt);
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored
512 }
513
514 /*
515
95e3676 @Infinoid [pmc] PDD07-ize function signatures in src/pmc/[b-f]*.pmc
Infinoid authored
516 =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
517
894d448 @chromatic [PMC] Minor cleanups and tidyings.
chromatic authored
518 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
519
520 =cut
521
522 */
523
8fcbee3 @bacek Mark set_foo_keyed_bar methods with :manual_wb in FIA
bacek authored
524 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/k…
chromatic authored
525 const INTVAL k = VTABLE_get_integer(INTERP, key);
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
526 SELF.set_pmc_keyed_int(k, value);
527 }
528
6287ae3 add missing fixedintegerarray.freeze and .thaw
Leopold Toetsch authored
529 /*
530
0c38764 @bacek [core] Implement FixedIntegerArray.is_equal
bacek authored
531 =item C<INTVAL is_equal(PMC *value)>
532
533 The C<==> operation. Compares two array to hold equal elements.
534
535 =cut
536
537 */
538
539 VTABLE INTVAL is_equal(PMC *value) {
540 INTVAL j, n;
541
542 if (value->vtable->base_type != SELF->vtable->base_type)
543 return 0;
544
545 n = SELF.elements();
546
547 if (VTABLE_elements(INTERP, value) != n)
548 return 0;
549
550 for (j = 0; j < n; ++j) {
f9cca7d @petdance consting and annotating
petdance authored
551 const INTVAL item1 = SELF.get_integer_keyed_int(j);
552 const INTVAL item2 = VTABLE_get_integer_keyed_int(INTERP, value, j);
0c38764 @bacek [core] Implement FixedIntegerArray.is_equal
bacek authored
553
554 if (item1 != item2)
555 return 0;
556 }
557
558 return 1;
559 }
560
561 /*
562
bd8aacd @cotto [PMC] add get_iter VTABLE function and tests to *IntegerArray
cotto authored
563 =item C<PMC *get_iter()>
564
565 Return a new Iterator for this PMC.
566
567 =cut
568
569 */
570
571 VTABLE PMC *get_iter() {
083213a @Whiteknight start rename of pmc_new to Parrot_pmc_new
Whiteknight authored
572 return Parrot_pmc_new_init(INTERP, enum_class_ArrayIterator, SELF);
bd8aacd @cotto [PMC] add get_iter VTABLE function and tests to *IntegerArray
cotto authored
573 }
574
575 /*
576
b101f2c @darbelo Merge pmc_freeze_with_pmcs into trunk.
darbelo authored
577 =item C<void freeze(PMC *info)>
6287ae3 add missing fixedintegerarray.freeze and .thaw
Leopold Toetsch authored
578
579 Used to archive the array.
580
b101f2c @darbelo Merge pmc_freeze_with_pmcs into trunk.
darbelo authored
581 =item C<void thaw(PMC *info)>
6287ae3 add missing fixedintegerarray.freeze and .thaw
Leopold Toetsch authored
582
583 Used to unarchive the array.
584
09dc23b @NotFound rarrange initialization and freeze/thaw of FIA and RIA to avoid redun…
NotFound authored
585 C<*info> is the visit info, (see F<include/parrot/pmc_freeze.h>).
586
6287ae3 add missing fixedintegerarray.freeze and .thaw
Leopold Toetsch authored
587 =cut
588
589 */
590
b101f2c @darbelo Merge pmc_freeze_with_pmcs into trunk.
darbelo authored
591 VTABLE void freeze(PMC *info) {
e5dead2 @cotto [pmc] update *IntegerArray to use ATTRs
cotto authored
592 INTVAL *int_array;
894d448 @chromatic [PMC] Minor cleanups and tidyings.
chromatic authored
593 INTVAL i, n;
6287ae3 add missing fixedintegerarray.freeze and .thaw
Leopold Toetsch authored
594
595 SUPER(info);
894d448 @chromatic [PMC] Minor cleanups and tidyings.
chromatic authored
596
8d33429 @chromatic [PMC] Replaced vtable function calls to find size of fixed integer ar…
chromatic authored
597 GET_ATTR_size(INTERP, SELF, n);
4c43475 @plobsing merge branch pmc_freeze_cleanup
plobsing authored
598 VTABLE_push_integer(INTERP, info, n);
e5dead2 @cotto [pmc] update *IntegerArray to use ATTRs
cotto authored
599 GET_ATTR_int_array(INTERP, SELF, int_array);
894d448 @chromatic [PMC] Minor cleanups and tidyings.
chromatic authored
600
601 for (i = 0; i < n; ++i)
4c43475 @plobsing merge branch pmc_freeze_cleanup
plobsing authored
602 VTABLE_push_integer(INTERP, info, int_array[i]);
6287ae3 add missing fixedintegerarray.freeze and .thaw
Leopold Toetsch authored
603 }
604
b101f2c @darbelo Merge pmc_freeze_with_pmcs into trunk.
darbelo authored
605 VTABLE void thaw(PMC *info) {
8640c33 @petdance consting vars. Fixed some POD.
petdance authored
606 const INTVAL n = VTABLE_shift_integer(INTERP, info);
09dc23b @NotFound rarrange initialization and freeze/thaw of FIA and RIA to avoid redun…
NotFound authored
607 SELF.init_int(n);
608 if (n > 0) {
4c43475 @plobsing merge branch pmc_freeze_cleanup
plobsing authored
609 INTVAL i;
610 INTVAL *int_array;
611 GET_ATTR_int_array(INTERP, SELF, int_array);
612 for (i = 0; i < n; ++i)
613 int_array[i] = VTABLE_shift_integer(INTERP, info);
6287ae3 add missing fixedintegerarray.freeze and .thaw
Leopold Toetsch authored
614 }
615 }
ac9988d @NotFound some cleaning of FIA: put METHOD after vtable functions and fix and i…
NotFound authored
616
617 /*
618
619 =back
620
621 =head2 Methods
622
623 =over 4
624
625 =item C<PMC *sort()>
626
627 Sort the array and return self.
628
629 =cut
630
631 */
632
633 METHOD sort(PMC *cmp_func :optional) {
634 UINTVAL n;
635 INTVAL size;
636
637 GET_ATTR_size(INTERP, SELF, size);
638 n = (UINTVAL)size;
639
640 if (n > 1) {
641 INTVAL *int_array;
642 GET_ATTR_int_array(INTERP, SELF, int_array);
643 if (PMC_IS_NULL(cmp_func))
644 qsort(int_array, n, sizeof (INTVAL),
645 (int (*)(const void *, const void*))auxcmpfunc);
646 else
4379aa4 @bacek Pass cmp signature to quicksort to avoid segmentation fault during fe…
bacek authored
647 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
648 }
649 RETURN(PMC *SELF);
650 }
651
47a64b4 @mlschroe add a "reverse" method for the array types (except boolarray)
mlschroe authored
652 /*
653
654 =item C<METHOD reverse()>
655
656 Reverse the contents of the array.
657
658 =cut
659
660 */
661
662 METHOD reverse() {
663 INTVAL n;
664 GET_ATTR_size(INTERP, SELF, n);
665 if (n > 1) {
666 INTVAL val;
667 INTVAL *data;
668 INTVAL i;
669
670 GET_ATTR_int_array(INTERP, SELF, data);
671 for (i = 0; i <= --n; i++) {
672 val = data[i];
673 data[i] = data[n];
674 data[n] = val;
675 }
676 }
f55a488 @Benabik codingstd fixes
Benabik authored
677 }
47a64b4 @mlschroe add a "reverse" method for the array types (except boolarray)
mlschroe authored
678
ac9988d @NotFound some cleaning of FIA: put METHOD after vtable functions and fix and i…
NotFound authored
679 }
680
681 /*
682
683 =back
684
cbe2617 @jkeenan Correct spelling error in POD.
jkeenan authored
685 =head2 Auxiliary functions
ac9988d @NotFound some cleaning of FIA: put METHOD after vtable functions and fix and i…
NotFound authored
686
687 =over 4
688
689 =item C<static int auxcmpfunc(const INTVAL *i, const INTVAL *j)>
690
691 INTVAL compare function for qsort usage.
692
693 =cut
694
695 */
696
697 PARROT_PURE_FUNCTION
698 static int
699 auxcmpfunc(ARGIN(const INTVAL *i), ARGIN(const INTVAL *j))
700 {
701 ASSERT_ARGS(auxcmpfunc)
702 return *i - *j;
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored
703 }
704
705 /*
706
707 =back
708
709 =head1 SEE ALSO
710
1e8a4ab this patch adds some relevant 'push' ops to the resizable PMCs, descr…
Dan Sugalski authored
711 F<docs/pdds/pdd17_basic_types.pod>.
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored
712
713 =cut
714
715 */
716
717 /*
718 * Local variables:
72575ae @bschmalhofer #40481: [PATCH] C-code coda in pmc files
bschmalhofer authored
719 * c-file-style: "parrot"
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored
720 * End:
1d7dded @plobsing update C file vim modelines
plobsing authored
721 * vim: expandtab shiftwidth=4 cinoptions='\:2=2' :
72575ae @bschmalhofer #40481: [PATCH] C-code coda in pmc files
bschmalhofer authored
722 */
Something went wrong with that request. Please try again.