Skip to content

HTTPS clone URL

Subversion checkout URL

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