Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 552 lines (354 sloc) 10.931 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
4 =head1 NAME
5
f474cd7 @bschmalhofer [perl #38235] Rename (dyn)?classes to (dyn)?pmc
bschmalhofer authored
6 src/pmc/fixedfloatarray.pmc - fixed size array for floating point numbers only
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored
7
8 =head1 DESCRIPTION
9
f6d5c3e @chromatic [PMC] More minor cleanups and reformattings.
chromatic authored
10 This class, FixedFloatArray, implements an array of fixed size which
11 stored FLOATVALs. It uses Float PMCs to do all necessary conversions.
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored
12
13 =head2 Functions
14
15 =over 4
16
17 =cut
18
19 */
20
6bdd5f9 @petdance headerizer now runs on PMC files
petdance authored
21 /* HEADERIZER HFILE: none */
22 /* HEADERIZER BEGIN: static */
23 /* HEADERIZER END: static */
24
6b81760 @Whiteknight [pmc] we don't need need_ext anymore, so BALEETED
Whiteknight authored
25 pmclass FixedFloatArray auto_attrs provides array {
a638c12 @cotto [pmc] get rid of UnionVal in *FloatArray
cotto authored
26 ATTR INTVAL size;
27 ATTR FLOATVAL *float_array;
7298186 @particle pmc: convert Fixed*Array and Resizable*Array internal_exceptions to r…
particle authored
28
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored
29 /*
30
31 =back
32
33 =head2 Methods
34
35 =over 4
36
37 =item C<void destroy()>
38
39 Destroys the array.
40
41 =cut
42
43 */
44
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
45 VTABLE void destroy() {
a638c12 @cotto [pmc] get rid of UnionVal in *FloatArray
cotto authored
46 FLOATVAL *float_array;
47 GET_ATTR_float_array(INTERP, SELF, float_array);
48 if (float_array)
4833868 @bacek Merge branch 'sys_mem' into trunk
bacek authored
49 mem_gc_free(INTERP, float_array);
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored
50 }
51
52 /*
53
714df2a @tewk VTABLE_init_int commented out tests
tewk authored
54 =item C<void init_int(INTVAL size)>
55
56 Initializes the array.
57
58 =cut
59
60 */
61
4d64842 @leto [t][TT#1509] Prevent core dumps by preventing negative length array c…
leto authored
62 VTABLE void init_int(INTVAL size) {
63 if (size < 0)
26914e1 changed interp in pmc class to INTERP for unification
Jimmy Zhuo authored
64 Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_OUT_OF_BOUNDS,
4d64842 @leto [t][TT#1509] Prevent core dumps by preventing negative length array c…
leto authored
65 _("FixedFloatArray: Cannot set array size to a negative number (%d)"), size);
66 SET_ATTR_size(INTERP, SELF, size);
67 SET_ATTR_float_array(INTERP, SELF, mem_gc_allocate_n_typed(INTERP, size, FLOATVAL));
714df2a @tewk VTABLE_init_int commented out tests
tewk authored
68 PObj_custom_destroy_SET(SELF);
69 }
70
71 /*
72
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored
73 =item C<PMC *clone()>
74
75 Creates and returns a copy of the array.
76
77 =cut
78
79 */
80
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
81 VTABLE PMC *clone() {
3b6ebda @NotFound clean FPA.clone
NotFound authored
82 FLOATVAL *self_float_array;
83 PMC * const dest = Parrot_pmc_new(INTERP, SELF->vtable->base_type);
a638c12 @cotto [pmc] get rid of UnionVal in *FloatArray
cotto authored
84 GET_ATTR_float_array(INTERP, SELF, self_float_array);
3b6ebda @NotFound clean FPA.clone
NotFound authored
85 if (self_float_array) {
86 INTVAL size;
87 GET_ATTR_size(INTERP, SELF, size);
88 {
89 FLOATVAL * const dest_float_array = mem_gc_allocate_n_typed(INTERP,
90 size, FLOATVAL);
91 mem_copy_n_typed(dest_float_array, self_float_array,
92 size, FLOATVAL);
93 SET_ATTR_float_array(INTERP, dest, dest_float_array);
94 }
95 SET_ATTR_size(INTERP, dest, size);
96 PObj_custom_destroy_SET(dest);
97 }
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored
98 return dest;
99 }
100
101 /*
102
c2b50bf @cotto [PMC] add get_iter + tests to *FloatArray
cotto authored
103 =item C<PMC *get_iter()>
104
105 Return an Iterator for this PMC.
106
107 =cut
108
109 */
110
111 VTABLE PMC *get_iter() {
083213a @Whiteknight start rename of pmc_new to Parrot_pmc_new
Whiteknight authored
112 return Parrot_pmc_new_init(INTERP, enum_class_ArrayIterator, SELF);
c2b50bf @cotto [PMC] add get_iter + tests to *FloatArray
cotto authored
113 }
114
115 /*
116
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored
117 =item C<INTVAL get_bool()>
118
119 Returns whether the array has any elements (meaning been initialized, for a
120 fixed sized array).
121
122 =cut
123
124 */
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
125 VTABLE INTVAL get_bool() {
a35f6fd @petdance consting & localizing
petdance authored
126 const INTVAL size = SELF.elements();
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored
127 return (INTVAL)(size != 0);
128 }
129
130 /*
131
132 =item C<INTVAL elements()>
133
134 =cut
135
136 */
137
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
138 VTABLE INTVAL elements() {
a638c12 @cotto [pmc] get rid of UnionVal in *FloatArray
cotto authored
139 INTVAL size;
140 GET_ATTR_size(INTERP, SELF, size);
141 return size;
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored
142 }
143
144 /*
145
146 =item C<INTVAL get_integer()>
147
148 Returns the number of elements in the array.
149
150 =cut
151
152 */
153
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
154 VTABLE INTVAL get_integer() {
ae8baa5 @bschmalhofer DYNDYNSELF in the Fixed*Array PMC looks like a typo. Using SELF propably
bschmalhofer authored
155 return SELF.elements();
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored
156 }
157
158
159 /*
160
161 =item C<INTVAL get_integer_keyed_int(INTVAL key)>
162
163 Returns the integer value of the element at index C<key>.
164
165 =cut
166
167 */
168
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
169 VTABLE INTVAL get_integer_keyed_int(INTVAL key) {
170 const FLOATVAL f = SELF.get_number_keyed_int(key);
8275ff5 @chromatic [PMC] Fixed a couple of casting warnings of function return values.
chromatic authored
171 return (INTVAL)f;
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored
172 }
173
174 /*
175
176 =item C<INTVAL get_integer_keyed(PMC *key)>
177
178 Returns the integer value of the element at index C<*key>.
179
180 =cut
181
182 */
183
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
184 VTABLE INTVAL get_integer_keyed(PMC *key) {
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored
185 /* simple int keys only */
757f3a8 @chromatic [PMC] Replaced all uses of key_integer() outside of Key PMC and src/k…
chromatic authored
186 const INTVAL k = VTABLE_get_integer(INTERP, key);
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
187 return SELF.get_integer_keyed_int(k);
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored
188 }
189
190
191 /*
192
193 =item C<FLOATVAL get_number_keyed_int(INTVAL key)>
194
195 Returns the floating-point value of the element at index C<key>.
196
197 =cut
198
199 */
200
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
201 VTABLE FLOATVAL get_number_keyed_int(INTVAL key) {
a638c12 @cotto [pmc] get rid of UnionVal in *FloatArray
cotto authored
202 FLOATVAL *float_array;
203 INTVAL size;
f6d5c3e @chromatic [PMC] More minor cleanups and reformattings.
chromatic authored
204
a638c12 @cotto [pmc] get rid of UnionVal in *FloatArray
cotto authored
205 GET_ATTR_size(INTERP, SELF, size);
206 if (key < 0 || key >= size)
2255840 @allisonrandal [pdd17pmc] Merging the pdd25cx branch into trunk for r26555 to r29949.
allisonrandal authored
207 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
208 "FixedFloatArray: index out of bounds!");
7298186 @particle pmc: convert Fixed*Array and Resizable*Array internal_exceptions to r…
particle authored
209
a638c12 @cotto [pmc] get rid of UnionVal in *FloatArray
cotto authored
210 GET_ATTR_float_array(INTERP, SELF, float_array);
211 return float_array[key];
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored
212 }
213
214 /*
215
95e3676 @Infinoid [pmc] PDD07-ize function signatures in src/pmc/[b-f]*.pmc
Infinoid authored
216 =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
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(PMC *key) {
757f3a8 @chromatic [PMC] Replaced all uses of key_integer() outside of Key PMC and src/k…
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_number_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 =item C<STRING *get_string_keyed_int(INTVAL key)>
232
233 Returns the Parrot string 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 STRING *get_string_keyed_int(INTVAL key) {
240 PMC * const e = SELF.get_pmc_keyed_int(key);
f6d5c3e @chromatic [PMC] More minor cleanups and reformattings.
chromatic authored
241 return VTABLE_get_string(INTERP, e);
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(PMC *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(PMC *key) {
757f3a8 @chromatic [PMC] Replaced all uses of key_integer() outside of Key PMC and src/k…
chromatic authored
255 const INTVAL k = VTABLE_get_integer(INTERP, key);
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
256 return SELF.get_string_keyed_int(k);
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored
257 }
258
259
260 /*
261
262 =item C<PMC *get_pmc_keyed_int(INTVAL key)>
263
264 Returns the PMC 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 PMC *get_pmc_keyed_int(INTVAL key) {
083213a @Whiteknight start rename of pmc_new to Parrot_pmc_new
Whiteknight authored
271 PMC * const ret = Parrot_pmc_new(INTERP, enum_class_Float);
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
272 const FLOATVAL val = SELF.get_number_keyed_int(key);
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored
273
274 VTABLE_set_number_native(INTERP, ret, val);
275 return ret;
276 }
277
278 /*
279
280 =item C<PMC *get_pmc_keyed(PMC *key)>
281
282 Returns the PMC value of the element at index C<*key>.
283
284 =cut
285
286 */
287
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
288 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
289 const INTVAL k = VTABLE_get_integer(INTERP, key);
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
290 return SELF.get_pmc_keyed_int(k);
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored
291 }
292
293 /*
294
c5bf220 @Whiteknight add a get_pointer vtable to FixedFloatArray, so people doing mathish …
Whiteknight authored
295 =item C<void * get_pointer()>
296
297 Return a pointer to the underlying data buffer. This is a C C<FLOATVAL*> array
298 and can be treated like any other array. This array should not be resized or
299 freed.
300
301 =cut
302
303 */
304
305 VTABLE void * get_pointer() {
306 FLOATVAL *float_array;
307 GET_ATTR_float_array(INTERP, SELF, float_array);
308 return float_array;
309 }
310
311 /*
312
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored
313 =item C<void set_integer_native(INTVAL size)>
314
315 Resizes the array to C<size> elements.
316
317 =cut
318
319 */
320
a638c12 @cotto [pmc] get rid of UnionVal in *FloatArray
cotto authored
321 VTABLE void set_integer_native(INTVAL new_size) {
322 INTVAL old_size;
323 GET_ATTR_size(INTERP, SELF, old_size);
324 if (old_size || new_size < 1)
2255840 @allisonrandal [pdd17pmc] Merging the pdd25cx branch into trunk for r26555 to r29949.
allisonrandal authored
325 Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_OUT_OF_BOUNDS,
7298186 @particle pmc: convert Fixed*Array and Resizable*Array internal_exceptions to r…
particle authored
326 "FixedFloatArray: Can't resize!");
f6d5c3e @chromatic [PMC] More minor cleanups and reformattings.
chromatic authored
327
a638c12 @cotto [pmc] get rid of UnionVal in *FloatArray
cotto authored
328 SET_ATTR_size(INTERP, SELF, new_size);
1bc2b58 @bschmalhofer [codingstd] trailing_space.t
bschmalhofer authored
329 SET_ATTR_float_array(INTERP, SELF,
4833868 @bacek Merge branch 'sys_mem' into trunk
bacek authored
330 mem_gc_allocate_n_typed(INTERP, new_size, FLOATVAL));
4591dbb @chromatic [HLL] Fixed two compilation-breaking typos accidentally committed in …
chromatic authored
331 PObj_custom_destroy_SET(SELF);
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored
332 }
333
334 /*
335
336 =item C<void set_integer_keyed_int(INTVAL key, INTVAL value)>
337
338 Sets the integer value of the element at index C<key> to C<value>.
339
340 =cut
341
342 */
343
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
344 VTABLE void set_integer_keyed_int(INTVAL key, INTVAL value) {
345 SELF.set_number_keyed_int(key, (FLOATVAL)value);
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored
346 }
347
348 /*
349
350 =item C<void set_integer_keyed(PMC *key, INTVAL value)>
351
352 Sets the integer value of the element at index C<key> to C<value>.
353
354 =cut
355
356 */
357
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
358 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
359 const INTVAL k = VTABLE_get_integer(INTERP, key);
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
360 SELF.set_integer_keyed_int(k, value);
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored
361 }
362
363 /*
364
365 =item C<void set_number_keyed_int(INTVAL key, FLOATVAL value)>
366
367 Sets the floating-point value of the element at index C<key> to
368 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_number_keyed_int(INTVAL key, FLOATVAL value) {
a638c12 @cotto [pmc] get rid of UnionVal in *FloatArray
cotto authored
375 FLOATVAL *float_array;
376 INTVAL size;
377
378 GET_ATTR_size(INTERP, SELF, size);
379 if (key < 0 || key >= size)
2255840 @allisonrandal [pdd17pmc] Merging the pdd25cx branch into trunk for r26555 to r29949.
allisonrandal authored
380 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
381 "FixedFloatArray: index out of bounds!");
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored
382
a638c12 @cotto [pmc] get rid of UnionVal in *FloatArray
cotto authored
383 GET_ATTR_float_array(INTERP, SELF, float_array);
384 float_array[key] = value;
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored
385 }
386
387 /*
388
389 =item C<void set_number_keyed(PMC *key, FLOATVAL value)>
390
391 Sets the floating-point value of the element at index C<key> to
392 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_number_keyed(PMC *key, FLOATVAL 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_number_keyed_int(k, value);
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored
401 }
7298186 @particle pmc: convert Fixed*Array and Resizable*Array internal_exceptions to r…
particle authored
402
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored
403 /*
404
405 =item C<void set_string_keyed_int(INTVAL key, STRING *value)>
406
407 Sets the Parrot string 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_string_keyed_int(INTVAL key, STRING *value) {
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored
414 FLOATVAL tempNum;
083213a @Whiteknight start rename of pmc_new to Parrot_pmc_new
Whiteknight authored
415 PMC * const tempPMC = Parrot_pmc_new(INTERP, enum_class_Float);
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored
416
417 VTABLE_set_string_native(INTERP, tempPMC, value);
418 tempNum = VTABLE_get_number(INTERP, tempPMC);
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
419 SELF.set_number_keyed_int(key, tempNum);
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored
420 }
421
422 /*
423
95e3676 @Infinoid [pmc] PDD07-ize function signatures in src/pmc/[b-f]*.pmc
Infinoid authored
424 =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
425
426 Sets the string value of the element at index C<key> to
427 C<value>.
428
429 =cut
430
431 */
432
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
433 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
434 const INTVAL k = VTABLE_get_integer(INTERP, key);
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
435 SELF.set_string_keyed_int(k, value);
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored
436 }
437
438 /*
439
440 =item C<void set_pmc_keyed_int(INTVAL key, PMC *src)>
441
442 Sets the PMC value of the element at index C<key> to C<*src>.
443
444 =cut
445
446 */
447
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
448 VTABLE void set_pmc_keyed_int(INTVAL key, PMC *src) {
a35f6fd @petdance consting & localizing
petdance authored
449 const FLOATVAL tempNum = VTABLE_get_number(INTERP, src);
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
450 SELF.set_number_keyed_int(key, tempNum);
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored
451 }
452
453 /*
454
95e3676 @Infinoid [pmc] PDD07-ize function signatures in src/pmc/[b-f]*.pmc
Infinoid authored
455 =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
456
457 Sets the string value of the element at index C<key> to
458 C<value>.
459
460 =cut
461
462 */
463
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
464 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
465 const INTVAL k = VTABLE_get_integer(INTERP, key);
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
466 SELF.set_pmc_keyed_int(k, value);
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored
467 }
468
fccdff0 @Benabik Add get_string to Fixed Float and Integer Array
Benabik authored
469 /*
470
471 =item C<STRING *get_string()>
472
473 =item C<STRING *get_repo()>
474
475 Returns the Parrot string representation C<key>
476
477 =cut
478
479 */
480
481 VTABLE STRING *get_string() {
482 return STATICSELF.get_repr();
483 }
484
485 VTABLE STRING *get_repr() {
486 STRING *str = CONST_STRING(INTERP, "[ ");
487 STRING *comma = CONST_STRING(INTERP, ", ");
488 UINTVAL i;
489 const UINTVAL elems = SELF.elements();
490
491 if (elems > 0)
492 str = Parrot_str_concat(INTERP, str,
493 SELF.get_string_keyed_int(0));
494
495 for (i = 1; i < elems; ++i) {
496 str = Parrot_str_concat(INTERP, str, comma);
497 str = Parrot_str_concat(INTERP, str,
498 SELF.get_string_keyed_int((INTVAL)i));
499 }
500
501 str = Parrot_str_concat(INTERP, str, CONST_STRING(INTERP, " ]"));
502 return str;
503 }
504
47a64b4 @mlschroe add a "reverse" method for the array types (except boolarray)
mlschroe authored
505 /*
506
507 =item C<METHOD reverse()>
508
509 Reverse the contents of the array.
510
511 =cut
512
513 */
514
515 METHOD reverse() {
516 INTVAL n;
f55a488 @Benabik codingstd fixes
Benabik authored
517 GET_ATTR_size(INTERP, SELF, n);
47a64b4 @mlschroe add a "reverse" method for the array types (except boolarray)
mlschroe authored
518 if (n > 1) {
519 FLOATVAL val;
520 FLOATVAL *data;
521 INTVAL i;
522
523 GET_ATTR_float_array(INTERP, SELF, data);
524 for (i = 0; i <= --n; i++) {
525 val = data[i];
526 data[i] = data[n];
527 data[n] = val;
528 }
529 }
f55a488 @Benabik codingstd fixes
Benabik authored
530 }
47a64b4 @mlschroe add a "reverse" method for the array types (except boolarray)
mlschroe authored
531
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored
532 }
533
534 /*
535
536 =back
537
538 =head1 SEE ALSO
539
1e8a4ab this patch adds some relevant 'push' ops to the resizable PMCs, descr…
Dan Sugalski authored
540 F<docs/pdds/pdd17_basic_types.pod>.
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored
541
542 =cut
543
544 */
545
546 /*
547 * Local variables:
72575ae @bschmalhofer #40481: [PATCH] C-code coda in pmc files
bschmalhofer authored
548 * c-file-style: "parrot"
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored
549 * End:
1d7dded @plobsing update C file vim modelines
plobsing authored
550 * vim: expandtab shiftwidth=4 cinoptions='\:2=2' :
72575ae @bschmalhofer #40481: [PATCH] C-code coda in pmc files
bschmalhofer authored
551 */
Something went wrong with that request. Please try again.