Skip to content
This repository
Newer
Older
100644 547 lines (352 sloc) 10.915 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 =cut
16
17 */
18
6bdd5f99 » petdance
2010-03-28 headerizer now runs on PMC files
19 /* HEADERIZER HFILE: none */
20 /* HEADERIZER BEGIN: static */
21 /* HEADERIZER END: static */
22
6b817608 » Whiteknight
2009-08-23 [pmc] we don't need need_ext anymore, so BALEETED
23 pmclass FixedFloatArray auto_attrs provides array {
a638c12e » cotto
2009-01-25 [pmc] get rid of UnionVal in *FloatArray
24 ATTR INTVAL size;
25 ATTR FLOATVAL *float_array;
72981862 » particle
2006-02-17 pmc: convert Fixed*Array and Resizable*Array internal_exceptions to r…
26
4498fea9 » Dan Sugalski
2004-06-12 This patch adds the above Fixed*Array classes. They are basic tests for
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
59661f18 » allisonrandal
2008-03-11 [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
41 VTABLE void destroy() {
a638c12e » cotto
2009-01-25 [pmc] get rid of UnionVal in *FloatArray
42 FLOATVAL *float_array;
43 GET_ATTR_float_array(INTERP, SELF, float_array);
44 if (float_array)
4833868f » bacek
2010-02-22 Merge branch 'sys_mem' into trunk
45 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
46 }
47
48 /*
49
714df2a3 » tewk
2010-03-10 VTABLE_init_int commented out tests
50 =item C<void init_int(INTVAL size)>
51
52 Initializes the array.
53
54 =cut
55
56 */
57
4d64842d » leto
2010-03-11 [t][TT#1509] Prevent core dumps by preventing negative length array c…
58 VTABLE void init_int(INTVAL size) {
59 if (size < 0)
26914e12 » Jimmy Zhuo
2010-05-05 changed interp in pmc class to INTERP for unification
60 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…
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));
714df2a3 » tewk
2010-03-10 VTABLE_init_int commented out tests
64 PObj_custom_destroy_SET(SELF);
65 }
66
67 /*
68
4498fea9 » Dan Sugalski
2004-06-12 This patch adds the above Fixed*Array classes. They are basic tests for
69 =item C<PMC *clone()>
70
71 Creates and returns a copy of the array.
72
73 =cut
74
75 */
76
59661f18 » allisonrandal
2008-03-11 [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
77 VTABLE PMC *clone() {
3b6ebda9 » NotFound
2010-04-24 clean FPA.clone
78 FLOATVAL *self_float_array;
79 PMC * const dest = Parrot_pmc_new(INTERP, SELF->vtable->base_type);
a638c12e » cotto
2009-01-25 [pmc] get rid of UnionVal in *FloatArray
80 GET_ATTR_float_array(INTERP, SELF, self_float_array);
3b6ebda9 » NotFound
2010-04-24 clean FPA.clone
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 }
4498fea9 » Dan Sugalski
2004-06-12 This patch adds the above Fixed*Array classes. They are basic tests for
94 return dest;
95 }
96
97 /*
98
c2b50bfb » cotto
2009-03-22 [PMC] add get_iter + tests to *FloatArray
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() {
083213a2 » Whiteknight
2010-02-16 start rename of pmc_new to Parrot_pmc_new
108 return Parrot_pmc_new_init(INTERP, enum_class_ArrayIterator, SELF);
c2b50bfb » cotto
2009-03-22 [PMC] add get_iter + tests to *FloatArray
109 }
110
111 /*
112
4498fea9 » Dan Sugalski
2004-06-12 This patch adds the above Fixed*Array classes. They are basic tests for
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 */
59661f18 » allisonrandal
2008-03-11 [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
121 VTABLE INTVAL get_bool() {
a35f6fdb » petdance
2008-02-09 consting & localizing
122 const INTVAL size = SELF.elements();
4498fea9 » Dan Sugalski
2004-06-12 This patch adds the above Fixed*Array classes. They are basic tests for
123 return (INTVAL)(size != 0);
124 }
125
126 /*
127
128 =item C<INTVAL elements()>
129
130 =cut
131
132 */
133
59661f18 » allisonrandal
2008-03-11 [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
134 VTABLE INTVAL elements() {
a638c12e » cotto
2009-01-25 [pmc] get rid of UnionVal in *FloatArray
135 INTVAL size;
136 GET_ATTR_size(INTERP, SELF, size);
137 return size;
4498fea9 » Dan Sugalski
2004-06-12 This patch adds the above Fixed*Array classes. They are basic tests for
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
59661f18 » allisonrandal
2008-03-11 [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
150 VTABLE INTVAL get_integer() {
ae8baa55 » bschmalhofer
2005-03-20 DYNDYNSELF in the Fixed*Array PMC looks like a typo. Using SELF propably
151 return SELF.elements();
4498fea9 » Dan Sugalski
2004-06-12 This patch adds the above Fixed*Array classes. They are basic tests for
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
59661f18 » allisonrandal
2008-03-11 [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
165 VTABLE INTVAL get_integer_keyed_int(INTVAL key) {
166 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.
167 return (INTVAL)f;
4498fea9 » Dan Sugalski
2004-06-12 This patch adds the above Fixed*Array classes. They are basic tests for
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
59661f18 » allisonrandal
2008-03-11 [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
180 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
181 /* simple int keys only */
757f3a87 » chromatic
2009-05-08 [PMC] Replaced all uses of key_integer() outside of Key PMC and src/k…
182 const INTVAL k = VTABLE_get_integer(INTERP, key);
59661f18 » allisonrandal
2008-03-11 [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
183 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
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
59661f18 » allisonrandal
2008-03-11 [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
197 VTABLE FLOATVAL get_number_keyed_int(INTVAL key) {
a638c12e » cotto
2009-01-25 [pmc] get rid of UnionVal in *FloatArray
198 FLOATVAL *float_array;
199 INTVAL size;
f6d5c3e9 » chromatic
2007-09-04 [PMC] More minor cleanups and reformattings.
200
a638c12e » cotto
2009-01-25 [pmc] get rid of UnionVal in *FloatArray
201 GET_ATTR_size(INTERP, SELF, size);
202 if (key < 0 || key >= size)
2255840f » allisonrandal
2008-08-02 [pdd17pmc] Merging the pdd25cx branch into trunk for r26555 to r29949.
203 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…
204 "FixedFloatArray: index out of bounds!");
72981862 » particle
2006-02-17 pmc: convert Fixed*Array and Resizable*Array internal_exceptions to r…
205
a638c12e » cotto
2009-01-25 [pmc] get rid of UnionVal in *FloatArray
206 GET_ATTR_float_array(INTERP, SELF, float_array);
207 return float_array[key];
4498fea9 » Dan Sugalski
2004-06-12 This patch adds the above Fixed*Array classes. They are basic tests for
208 }
209
210 /*
211
95e36766 » Infinoid
2007-08-09 [pmc] PDD07-ize function signatures in src/pmc/[b-f]*.pmc
212 =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
213
214 Returns the floating-point value of the element at index C<*key>.
215
216 =cut
217
218 */
219
59661f18 » allisonrandal
2008-03-11 [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
220 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…
221 const INTVAL k = VTABLE_get_integer(INTERP, key);
59661f18 » allisonrandal
2008-03-11 [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
222 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
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
59661f18 » allisonrandal
2008-03-11 [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
235 VTABLE STRING *get_string_keyed_int(INTVAL key) {
236 PMC * const e = SELF.get_pmc_keyed_int(key);
f6d5c3e9 » chromatic
2007-09-04 [PMC] More minor cleanups and reformattings.
237 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
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
59661f18 » allisonrandal
2008-03-11 [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
250 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…
251 const INTVAL k = VTABLE_get_integer(INTERP, key);
59661f18 » allisonrandal
2008-03-11 [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
252 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
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
59661f18 » allisonrandal
2008-03-11 [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
266 VTABLE PMC *get_pmc_keyed_int(INTVAL key) {
083213a2 » Whiteknight
2010-02-16 start rename of pmc_new to Parrot_pmc_new
267 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).
268 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
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
59661f18 » allisonrandal
2008-03-11 [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
284 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…
285 const INTVAL k = VTABLE_get_integer(INTERP, key);
59661f18 » allisonrandal
2008-03-11 [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
286 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
287 }
288
289 /*
290
c5bf2205 » Whiteknight
2011-04-13 add a get_pointer vtable to FixedFloatArray, so people doing mathish …
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
4498fea9 » Dan Sugalski
2004-06-12 This patch adds the above Fixed*Array classes. They are basic tests for
309 =item C<void set_integer_native(INTVAL size)>
310
311 Resizes the array to C<size> elements.
312
313 =cut
314
315 */
316
a638c12e » cotto
2009-01-25 [pmc] get rid of UnionVal in *FloatArray
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)
2255840f » allisonrandal
2008-08-02 [pdd17pmc] Merging the pdd25cx branch into trunk for r26555 to r29949.
321 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…
322 "FixedFloatArray: Can't resize!");
f6d5c3e9 » chromatic
2007-09-04 [PMC] More minor cleanups and reformattings.
323
a638c12e » cotto
2009-01-25 [pmc] get rid of UnionVal in *FloatArray
324 SET_ATTR_size(INTERP, SELF, new_size);
1bc2b588 » bschmalhofer
2009-01-25 [codingstd] trailing_space.t
325 SET_ATTR_float_array(INTERP, SELF,
4833868f » bacek
2010-02-22 Merge branch 'sys_mem' into trunk
326 mem_gc_allocate_n_typed(INTERP, new_size, FLOATVAL));
4591dbb8 » chromatic
2009-09-03 [HLL] Fixed two compilation-breaking typos accidentally committed in …
327 PObj_custom_destroy_SET(SELF);
4498fea9 » Dan Sugalski
2004-06-12 This patch adds the above Fixed*Array classes. They are basic tests for
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
59661f18 » allisonrandal
2008-03-11 [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
340 VTABLE void set_integer_keyed_int(INTVAL key, INTVAL value) {
341 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
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
59661f18 » allisonrandal
2008-03-11 [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
354 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…
355 const INTVAL k = VTABLE_get_integer(INTERP, key);
59661f18 » allisonrandal
2008-03-11 [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
356 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
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
59661f18 » allisonrandal
2008-03-11 [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
370 VTABLE void set_number_keyed_int(INTVAL key, FLOATVAL value) {
a638c12e » cotto
2009-01-25 [pmc] get rid of UnionVal in *FloatArray
371 FLOATVAL *float_array;
372 INTVAL size;
373
374 GET_ATTR_size(INTERP, SELF, size);
375 if (key < 0 || key >= size)
2255840f » allisonrandal
2008-08-02 [pdd17pmc] Merging the pdd25cx branch into trunk for r26555 to r29949.
376 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…
377 "FixedFloatArray: index out of bounds!");
4498fea9 » Dan Sugalski
2004-06-12 This patch adds the above Fixed*Array classes. They are basic tests for
378
a638c12e » cotto
2009-01-25 [pmc] get rid of UnionVal in *FloatArray
379 GET_ATTR_float_array(INTERP, SELF, float_array);
380 float_array[key] = value;
4498fea9 » Dan Sugalski
2004-06-12 This patch adds the above Fixed*Array classes. They are basic tests for
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
59661f18 » allisonrandal
2008-03-11 [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
394 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…
395 const INTVAL k = VTABLE_get_integer(INTERP, key);
59661f18 » allisonrandal
2008-03-11 [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
396 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
397 }
72981862 » particle
2006-02-17 pmc: convert Fixed*Array and Resizable*Array internal_exceptions to r…
398
4498fea9 » Dan Sugalski
2004-06-12 This patch adds the above Fixed*Array classes. They are basic tests for
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
59661f18 » allisonrandal
2008-03-11 [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
409 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
410 FLOATVAL tempNum;
083213a2 » Whiteknight
2010-02-16 start rename of pmc_new to Parrot_pmc_new
411 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
412
413 VTABLE_set_string_native(INTERP, tempPMC, value);
414 tempNum = VTABLE_get_number(INTERP, tempPMC);
59661f18 » allisonrandal
2008-03-11 [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
415 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
416 }
417
418 /*
419
95e36766 » Infinoid
2007-08-09 [pmc] PDD07-ize function signatures in src/pmc/[b-f]*.pmc
420 =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
421
422 Sets the string value of the element at index C<key> to
423 C<value>.
424
425 =cut
426
427 */
428
59661f18 » allisonrandal
2008-03-11 [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
429 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…
430 const INTVAL k = VTABLE_get_integer(INTERP, key);
59661f18 » allisonrandal
2008-03-11 [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
431 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
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
59661f18 » allisonrandal
2008-03-11 [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
444 VTABLE void set_pmc_keyed_int(INTVAL key, PMC *src) {
a35f6fdb » petdance
2008-02-09 consting & localizing
445 const FLOATVAL tempNum = VTABLE_get_number(INTERP, src);
59661f18 » allisonrandal
2008-03-11 [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
446 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
447 }
448
449 /*
450
95e36766 » Infinoid
2007-08-09 [pmc] PDD07-ize function signatures in src/pmc/[b-f]*.pmc
451 =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
452
453 Sets the string value of the element at index C<key> to
454 C<value>.
455
456 =cut
457
458 */
459
59661f18 » allisonrandal
2008-03-11 [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
460 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…
461 const INTVAL k = VTABLE_get_integer(INTERP, key);
59661f18 » allisonrandal
2008-03-11 [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
462 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
463 }
464
fccdff0d » Benabik
2011-10-16 Add get_string to Fixed Float and Integer Array
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
47a64b48 » mlschroe
2011-10-20 add a "reverse" method for the array types (except boolarray)
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;
f55a4889 » Benabik
2011-10-20 codingstd fixes
513 GET_ATTR_size(INTERP, SELF, n);
47a64b48 » mlschroe
2011-10-20 add a "reverse" method for the array types (except boolarray)
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 }
f55a4889 » Benabik
2011-10-20 codingstd fixes
526 }
47a64b48 » mlschroe
2011-10-20 add a "reverse" method for the array types (except boolarray)
527
4498fea9 » Dan Sugalski
2004-06-12 This patch adds the above Fixed*Array classes. They are basic tests for
528 }
529
530 /*
531
532 =back
533
534 =head1 SEE ALSO
535
1e8a4ab7 » Dan Sugalski
2004-10-19 this patch adds some relevant 'push' ops to the resizable PMCs, descr…
536 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
537
538 =cut
539
540 */
541
542 /*
543 * Local variables:
72575ae0 » bschmalhofer
2006-10-09 #40481: [PATCH] C-code coda in pmc files
544 * c-file-style: "parrot"
4498fea9 » Dan Sugalski
2004-06-12 This patch adds the above Fixed*Array classes. They are basic tests for
545 * End:
1d7dded8 » plobsing
2010-11-29 update C file vim modelines
546 * vim: expandtab shiftwidth=4 cinoptions='\:2=2' :
72575ae0 » bschmalhofer
2006-10-09 #40481: [PATCH] C-code coda in pmc files
547 */
Something went wrong with that request. Please try again.