Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

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