Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

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