Skip to content
This repository
Newer
Older
100644 551 lines (354 sloc) 10.931 kb
4498fea9 » Dan Sugalski
2004-06-12 This patch adds the above Fixed*Array classes. They are basic tests for
1 /*
0e362895 » allisonrandal
2009-02-17 [cage] Updating all copyrights in src/ to Parrot Foundation.
2 Copyright (C) 2001-2009, Parrot Foundation.
4498fea9 » Dan Sugalski
2004-06-12 This patch adds the above Fixed*Array classes. They are basic tests for
3
4 =head1 NAME
5
f474cd7f » bschmalhofer
2006-01-18 [perl #38235] Rename (dyn)?classes to (dyn)?pmc
6 src/pmc/fixedfloatarray.pmc - fixed size array for floating point numbers only
4498fea9 » Dan Sugalski
2004-06-12 This patch adds the above Fixed*Array classes. They are basic tests for
7
8 =head1 DESCRIPTION
9
f6d5c3e9 » chromatic
2007-09-04 [PMC] More minor cleanups and reformattings.
10 This class, FixedFloatArray, implements an array of fixed size which
11 stored FLOATVALs. It uses Float PMCs to do all necessary conversions.
4498fea9 » Dan Sugalski
2004-06-12 This patch adds the above Fixed*Array classes. They are basic tests for
12
13 =head2 Functions
14
15 =over 4
16
17 =cut
18
19 */
20
6bdd5f99 » petdance
2010-03-28 headerizer now runs on PMC files
21 /* HEADERIZER HFILE: none */
22 /* HEADERIZER BEGIN: static */
23 /* HEADERIZER END: static */
24
6b817608 » Whiteknight
2009-08-23 [pmc] we don't need need_ext anymore, so BALEETED
25 pmclass FixedFloatArray auto_attrs provides array {
a638c12e » cotto
2009-01-25 [pmc] get rid of UnionVal in *FloatArray
26 ATTR INTVAL size;
27 ATTR FLOATVAL *float_array;
72981862 » particle
2006-02-17 pmc: convert Fixed*Array and Resizable*Array internal_exceptions to r…
28
4498fea9 » Dan Sugalski
2004-06-12 This patch adds the above Fixed*Array classes. They are basic tests for
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
59661f18 » allisonrandal
2008-03-11 [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
45 VTABLE void destroy() {
a638c12e » cotto
2009-01-25 [pmc] get rid of UnionVal in *FloatArray
46 FLOATVAL *float_array;
47 GET_ATTR_float_array(INTERP, SELF, float_array);
48 if (float_array)
4833868f » bacek
2010-02-22 Merge branch 'sys_mem' into trunk
49 mem_gc_free(INTERP, float_array);
4498fea9 » Dan Sugalski
2004-06-12 This patch adds the above Fixed*Array classes. They are basic tests for
50 }
51
52 /*
53
714df2a3 » tewk
2010-03-10 VTABLE_init_int commented out tests
54 =item C<void init_int(INTVAL size)>
55
56 Initializes the array.
57
58 =cut
59
60 */
61
4d64842d » leto
2010-03-11 [t][TT#1509] Prevent core dumps by preventing negative length array c…
62 VTABLE void init_int(INTVAL size) {
63 if (size < 0)
26914e12 » Jimmy Zhuo
2010-05-05 changed interp in pmc class to INTERP for unification
64 Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_OUT_OF_BOUNDS,
4d64842d » leto
2010-03-11 [t][TT#1509] Prevent core dumps by preventing negative length array c…
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));
714df2a3 » tewk
2010-03-10 VTABLE_init_int commented out tests
68 PObj_custom_destroy_SET(SELF);
69 }
70
71 /*
72
4498fea9 » Dan Sugalski
2004-06-12 This patch adds the above Fixed*Array classes. They are basic tests for
73 =item C<PMC *clone()>
74
75 Creates and returns a copy of the array.
76
77 =cut
78
79 */
80
59661f18 » allisonrandal
2008-03-11 [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
81 VTABLE PMC *clone() {
3b6ebda9 » NotFound
2010-04-24 clean FPA.clone
82 FLOATVAL *self_float_array;
83 PMC * const dest = Parrot_pmc_new(INTERP, SELF->vtable->base_type);
a638c12e » cotto
2009-01-25 [pmc] get rid of UnionVal in *FloatArray
84 GET_ATTR_float_array(INTERP, SELF, self_float_array);
3b6ebda9 » NotFound
2010-04-24 clean FPA.clone
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 }
4498fea9 » Dan Sugalski
2004-06-12 This patch adds the above Fixed*Array classes. They are basic tests for
98 return dest;
99 }
100
101 /*
102
c2b50bfb » cotto
2009-03-22 [PMC] add get_iter + tests to *FloatArray
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() {
083213a2 » Whiteknight
2010-02-16 start rename of pmc_new to Parrot_pmc_new
112 return Parrot_pmc_new_init(INTERP, enum_class_ArrayIterator, SELF);
c2b50bfb » cotto
2009-03-22 [PMC] add get_iter + tests to *FloatArray
113 }
114
115 /*
116
4498fea9 » Dan Sugalski
2004-06-12 This patch adds the above Fixed*Array classes. They are basic tests for
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 */
59661f18 » allisonrandal
2008-03-11 [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
125 VTABLE INTVAL get_bool() {
a35f6fdb » petdance
2008-02-09 consting & localizing
126 const INTVAL size = SELF.elements();
4498fea9 » Dan Sugalski
2004-06-12 This patch adds the above Fixed*Array classes. They are basic tests for
127 return (INTVAL)(size != 0);
128 }
129
130 /*
131
132 =item C<INTVAL elements()>
133
134 =cut
135
136 */
137
59661f18 » allisonrandal
2008-03-11 [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
138 VTABLE INTVAL elements() {
a638c12e » cotto
2009-01-25 [pmc] get rid of UnionVal in *FloatArray
139 INTVAL size;
140 GET_ATTR_size(INTERP, SELF, size);
141 return size;
4498fea9 » Dan Sugalski
2004-06-12 This patch adds the above Fixed*Array classes. They are basic tests for
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
59661f18 » allisonrandal
2008-03-11 [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
154 VTABLE INTVAL get_integer() {
ae8baa55 » bschmalhofer
2005-03-20 DYNDYNSELF in the Fixed*Array PMC looks like a typo. Using SELF propably
155 return SELF.elements();
4498fea9 » Dan Sugalski
2004-06-12 This patch adds the above Fixed*Array classes. They are basic tests for
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
59661f18 » allisonrandal
2008-03-11 [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
169 VTABLE INTVAL get_integer_keyed_int(INTVAL key) {
170 const FLOATVAL f = SELF.get_number_keyed_int(key);
8275ff5f » chromatic
2007-08-18 [PMC] Fixed a couple of casting warnings of function return values.
171 return (INTVAL)f;
4498fea9 » Dan Sugalski
2004-06-12 This patch adds the above Fixed*Array classes. They are basic tests for
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
59661f18 » allisonrandal
2008-03-11 [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
184 VTABLE INTVAL get_integer_keyed(PMC *key) {
4498fea9 » Dan Sugalski
2004-06-12 This patch adds the above Fixed*Array classes. They are basic tests for
185 /* simple int keys only */
757f3a87 » chromatic
2009-05-08 [PMC] Replaced all uses of key_integer() outside of Key PMC and src/k…
186 const INTVAL k = VTABLE_get_integer(INTERP, key);
59661f18 » allisonrandal
2008-03-11 [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
187 return SELF.get_integer_keyed_int(k);
4498fea9 » Dan Sugalski
2004-06-12 This patch adds the above Fixed*Array classes. They are basic tests for
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
59661f18 » allisonrandal
2008-03-11 [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
201 VTABLE FLOATVAL get_number_keyed_int(INTVAL key) {
a638c12e » cotto
2009-01-25 [pmc] get rid of UnionVal in *FloatArray
202 FLOATVAL *float_array;
203 INTVAL size;
f6d5c3e9 » chromatic
2007-09-04 [PMC] More minor cleanups and reformattings.
204
a638c12e » cotto
2009-01-25 [pmc] get rid of UnionVal in *FloatArray
205 GET_ATTR_size(INTERP, SELF, size);
206 if (key < 0 || key >= size)
2255840f » allisonrandal
2008-08-02 [pdd17pmc] Merging the pdd25cx branch into trunk for r26555 to r29949.
207 Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_OUT_OF_BOUNDS,
d1854520 » chromatic
2004-12-12 Standardize internal exception calls (James deBoer, james at huronbox…
208 "FixedFloatArray: index out of bounds!");
72981862 » particle
2006-02-17 pmc: convert Fixed*Array and Resizable*Array internal_exceptions to r…
209
a638c12e » cotto
2009-01-25 [pmc] get rid of UnionVal in *FloatArray
210 GET_ATTR_float_array(INTERP, SELF, float_array);
211 return float_array[key];
4498fea9 » Dan Sugalski
2004-06-12 This patch adds the above Fixed*Array classes. They are basic tests for
212 }
213
214 /*
215
95e36766 » Infinoid
2007-08-09 [pmc] PDD07-ize function signatures in src/pmc/[b-f]*.pmc
216 =item C<FLOATVAL get_number_keyed(PMC *key)>
4498fea9 » Dan Sugalski
2004-06-12 This patch adds the above Fixed*Array classes. They are basic tests for
217
218 Returns the floating-point value of the element at index C<*key>.
219
220 =cut
221
222 */
223
59661f18 » allisonrandal
2008-03-11 [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
224 VTABLE FLOATVAL get_number_keyed(PMC *key) {
757f3a87 » chromatic
2009-05-08 [PMC] Replaced all uses of key_integer() outside of Key PMC and src/k…
225 const INTVAL k = VTABLE_get_integer(INTERP, key);
59661f18 » allisonrandal
2008-03-11 [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
226 return SELF.get_number_keyed_int(k);
4498fea9 » Dan Sugalski
2004-06-12 This patch adds the above Fixed*Array classes. They are basic tests for
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
59661f18 » allisonrandal
2008-03-11 [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
239 VTABLE STRING *get_string_keyed_int(INTVAL key) {
240 PMC * const e = SELF.get_pmc_keyed_int(key);
f6d5c3e9 » chromatic
2007-09-04 [PMC] More minor cleanups and reformattings.
241 return VTABLE_get_string(INTERP, e);
4498fea9 » Dan Sugalski
2004-06-12 This patch adds the above Fixed*Array classes. They are basic tests for
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
59661f18 » allisonrandal
2008-03-11 [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
254 VTABLE STRING *get_string_keyed(PMC *key) {
757f3a87 » chromatic
2009-05-08 [PMC] Replaced all uses of key_integer() outside of Key PMC and src/k…
255 const INTVAL k = VTABLE_get_integer(INTERP, key);
59661f18 » allisonrandal
2008-03-11 [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
256 return SELF.get_string_keyed_int(k);
4498fea9 » Dan Sugalski
2004-06-12 This patch adds the above Fixed*Array classes. They are basic tests for
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
59661f18 » allisonrandal
2008-03-11 [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
270 VTABLE PMC *get_pmc_keyed_int(INTVAL key) {
083213a2 » Whiteknight
2010-02-16 start rename of pmc_new to Parrot_pmc_new
271 PMC * const ret = Parrot_pmc_new(INTERP, enum_class_Float);
59661f18 » allisonrandal
2008-03-11 [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
272 const FLOATVAL val = SELF.get_number_keyed_int(key);
4498fea9 » Dan Sugalski
2004-06-12 This patch adds the above Fixed*Array classes. They are basic tests for
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
59661f18 » allisonrandal
2008-03-11 [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
288 VTABLE PMC *get_pmc_keyed(PMC *key) {
757f3a87 » chromatic
2009-05-08 [PMC] Replaced all uses of key_integer() outside of Key PMC and src/k…
289 const INTVAL k = VTABLE_get_integer(INTERP, key);
59661f18 » allisonrandal
2008-03-11 [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
290 return SELF.get_pmc_keyed_int(k);
4498fea9 » Dan Sugalski
2004-06-12 This patch adds the above Fixed*Array classes. They are basic tests for
291 }
292
293 /*
294
c5bf2205 » Whiteknight
2011-04-13 add a get_pointer vtable to FixedFloatArray, so people doing mathish …
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
4498fea9 » Dan Sugalski
2004-06-12 This patch adds the above Fixed*Array classes. They are basic tests for
313 =item C<void set_integer_native(INTVAL size)>
314
315 Resizes the array to C<size> elements.
316
317 =cut
318
319 */
320
a638c12e » cotto
2009-01-25 [pmc] get rid of UnionVal in *FloatArray
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)
2255840f » allisonrandal
2008-08-02 [pdd17pmc] Merging the pdd25cx branch into trunk for r26555 to r29949.
325 Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_OUT_OF_BOUNDS,
72981862 » particle
2006-02-17 pmc: convert Fixed*Array and Resizable*Array internal_exceptions to r…
326 "FixedFloatArray: Can't resize!");
f6d5c3e9 » chromatic
2007-09-04 [PMC] More minor cleanups and reformattings.
327
a638c12e » cotto
2009-01-25 [pmc] get rid of UnionVal in *FloatArray
328 SET_ATTR_size(INTERP, SELF, new_size);
1bc2b588 » bschmalhofer
2009-01-25 [codingstd] trailing_space.t
329 SET_ATTR_float_array(INTERP, SELF,
4833868f » bacek
2010-02-22 Merge branch 'sys_mem' into trunk
330 mem_gc_allocate_n_typed(INTERP, new_size, FLOATVAL));
4591dbb8 » chromatic
2009-09-03 [HLL] Fixed two compilation-breaking typos accidentally committed in …
331 PObj_custom_destroy_SET(SELF);
4498fea9 » Dan Sugalski
2004-06-12 This patch adds the above Fixed*Array classes. They are basic tests for
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
59661f18 » allisonrandal
2008-03-11 [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
344 VTABLE void set_integer_keyed_int(INTVAL key, INTVAL value) {
345 SELF.set_number_keyed_int(key, (FLOATVAL)value);
4498fea9 » Dan Sugalski
2004-06-12 This patch adds the above Fixed*Array classes. They are basic tests for
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
59661f18 » allisonrandal
2008-03-11 [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
358 VTABLE void set_integer_keyed(PMC *key, INTVAL value) {
757f3a87 » chromatic
2009-05-08 [PMC] Replaced all uses of key_integer() outside of Key PMC and src/k…
359 const INTVAL k = VTABLE_get_integer(INTERP, key);
59661f18 » allisonrandal
2008-03-11 [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
360 SELF.set_integer_keyed_int(k, value);
4498fea9 » Dan Sugalski
2004-06-12 This patch adds the above Fixed*Array classes. They are basic tests for
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
59661f18 » allisonrandal
2008-03-11 [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
374 VTABLE void set_number_keyed_int(INTVAL key, FLOATVAL value) {
a638c12e » cotto
2009-01-25 [pmc] get rid of UnionVal in *FloatArray
375 FLOATVAL *float_array;
376 INTVAL size;
377
378 GET_ATTR_size(INTERP, SELF, size);
379 if (key < 0 || key >= size)
2255840f » allisonrandal
2008-08-02 [pdd17pmc] Merging the pdd25cx branch into trunk for r26555 to r29949.
380 Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_OUT_OF_BOUNDS,
d1854520 » chromatic
2004-12-12 Standardize internal exception calls (James deBoer, james at huronbox…
381 "FixedFloatArray: index out of bounds!");
4498fea9 » Dan Sugalski
2004-06-12 This patch adds the above Fixed*Array classes. They are basic tests for
382
a638c12e » cotto
2009-01-25 [pmc] get rid of UnionVal in *FloatArray
383 GET_ATTR_float_array(INTERP, SELF, float_array);
384 float_array[key] = value;
4498fea9 » Dan Sugalski
2004-06-12 This patch adds the above Fixed*Array classes. They are basic tests for
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
59661f18 » allisonrandal
2008-03-11 [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
398 VTABLE void set_number_keyed(PMC *key, FLOATVAL value) {
757f3a87 » chromatic
2009-05-08 [PMC] Replaced all uses of key_integer() outside of Key PMC and src/k…
399 const INTVAL k = VTABLE_get_integer(INTERP, key);
59661f18 » allisonrandal
2008-03-11 [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
400 SELF.set_number_keyed_int(k, value);
4498fea9 » Dan Sugalski
2004-06-12 This patch adds the above Fixed*Array classes. They are basic tests for
401 }
72981862 » particle
2006-02-17 pmc: convert Fixed*Array and Resizable*Array internal_exceptions to r…
402
4498fea9 » Dan Sugalski
2004-06-12 This patch adds the above Fixed*Array classes. They are basic tests for
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
59661f18 » allisonrandal
2008-03-11 [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
413 VTABLE void set_string_keyed_int(INTVAL key, STRING *value) {
4498fea9 » Dan Sugalski
2004-06-12 This patch adds the above Fixed*Array classes. They are basic tests for
414 FLOATVAL tempNum;
083213a2 » Whiteknight
2010-02-16 start rename of pmc_new to Parrot_pmc_new
415 PMC * const tempPMC = Parrot_pmc_new(INTERP, enum_class_Float);
4498fea9 » Dan Sugalski
2004-06-12 This patch adds the above Fixed*Array classes. They are basic tests for
416
417 VTABLE_set_string_native(INTERP, tempPMC, value);
418 tempNum = VTABLE_get_number(INTERP, tempPMC);
59661f18 » allisonrandal
2008-03-11 [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
419 SELF.set_number_keyed_int(key, tempNum);
4498fea9 » Dan Sugalski
2004-06-12 This patch adds the above Fixed*Array classes. They are basic tests for
420 }
421
422 /*
423
95e36766 » Infinoid
2007-08-09 [pmc] PDD07-ize function signatures in src/pmc/[b-f]*.pmc
424 =item C<void set_string_keyed(PMC *key, STRING *value)>
4498fea9 » Dan Sugalski
2004-06-12 This patch adds the above Fixed*Array classes. They are basic tests for
425
426 Sets the string value of the element at index C<key> to
427 C<value>.
428
429 =cut
430
431 */
432
59661f18 » allisonrandal
2008-03-11 [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
433 VTABLE void set_string_keyed(PMC *key, STRING *value) {
757f3a87 » chromatic
2009-05-08 [PMC] Replaced all uses of key_integer() outside of Key PMC and src/k…
434 const INTVAL k = VTABLE_get_integer(INTERP, key);
59661f18 » allisonrandal
2008-03-11 [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
435 SELF.set_string_keyed_int(k, value);
4498fea9 » Dan Sugalski
2004-06-12 This patch adds the above Fixed*Array classes. They are basic tests for
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
59661f18 » allisonrandal
2008-03-11 [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
448 VTABLE void set_pmc_keyed_int(INTVAL key, PMC *src) {
a35f6fdb » petdance
2008-02-09 consting & localizing
449 const FLOATVAL tempNum = VTABLE_get_number(INTERP, src);
59661f18 » allisonrandal
2008-03-11 [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
450 SELF.set_number_keyed_int(key, tempNum);
4498fea9 » Dan Sugalski
2004-06-12 This patch adds the above Fixed*Array classes. They are basic tests for
451 }
452
453 /*
454
95e36766 » Infinoid
2007-08-09 [pmc] PDD07-ize function signatures in src/pmc/[b-f]*.pmc
455 =item C<void set_pmc_keyed(PMC *key, PMC *value)>
4498fea9 » Dan Sugalski
2004-06-12 This patch adds the above Fixed*Array classes. They are basic tests for
456
457 Sets the string value of the element at index C<key> to
458 C<value>.
459
460 =cut
461
462 */
463
59661f18 » allisonrandal
2008-03-11 [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
464 VTABLE void set_pmc_keyed(PMC *key, PMC *value) {
757f3a87 » chromatic
2009-05-08 [PMC] Replaced all uses of key_integer() outside of Key PMC and src/k…
465 const INTVAL k = VTABLE_get_integer(INTERP, key);
59661f18 » allisonrandal
2008-03-11 [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
466 SELF.set_pmc_keyed_int(k, value);
4498fea9 » Dan Sugalski
2004-06-12 This patch adds the above Fixed*Array classes. They are basic tests for
467 }
468
fccdff0d » Benabik
2011-10-16 Add get_string to Fixed Float and Integer Array
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
47a64b48 » mlschroe
2011-10-20 add a "reverse" method for the array types (except boolarray)
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;
f55a4889 » Benabik
2011-10-20 codingstd fixes
517 GET_ATTR_size(INTERP, SELF, n);
47a64b48 » mlschroe
2011-10-20 add a "reverse" method for the array types (except boolarray)
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 }
f55a4889 » Benabik
2011-10-20 codingstd fixes
530 }
47a64b48 » mlschroe
2011-10-20 add a "reverse" method for the array types (except boolarray)
531
4498fea9 » Dan Sugalski
2004-06-12 This patch adds the above Fixed*Array classes. They are basic tests for
532 }
533
534 /*
535
536 =back
537
538 =head1 SEE ALSO
539
1e8a4ab7 » Dan Sugalski
2004-10-19 this patch adds some relevant 'push' ops to the resizable PMCs, descr…
540 F<docs/pdds/pdd17_basic_types.pod>.
4498fea9 » Dan Sugalski
2004-06-12 This patch adds the above Fixed*Array classes. They are basic tests for
541
542 =cut
543
544 */
545
546 /*
547 * Local variables:
72575ae0 » bschmalhofer
2006-10-09 #40481: [PATCH] C-code coda in pmc files
548 * c-file-style: "parrot"
4498fea9 » Dan Sugalski
2004-06-12 This patch adds the above Fixed*Array classes. They are basic tests for
549 * End:
1d7dded8 » plobsing
2010-11-29 update C file vim modelines
550 * vim: expandtab shiftwidth=4 cinoptions='\:2=2' :
72575ae0 » bschmalhofer
2006-10-09 #40481: [PATCH] C-code coda in pmc files
551 */
Something went wrong with that request. Please try again.