Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

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