Skip to content

HTTPS clone URL

Subversion checkout URL

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