Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

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