Skip to content

HTTPS clone URL

Subversion checkout URL

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