Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 623 lines (406 sloc) 12.902 kB
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored
1 /*
a35f6fd @petdance consting & localizing
petdance authored
2 Copyright (C) 2001-2008, The Perl Foundation.
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored
3 $Id$
4
5 =head1 NAME
6
f474cd7 @bschmalhofer [perl #38235] Rename (dyn)?classes to (dyn)?pmc
bschmalhofer authored
7 src/pmc/fixedintegerarray.pmc - fixed size array for integers only
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored
8
9 =head1 DESCRIPTION
10
894d448 @chromatic [PMC] Minor cleanups and tidyings.
chromatic authored
11 This class, FixedIntegerArray, implements an array of fixed size which stores
12 INTVALs. It uses Integer PMCs for all of the conversions.
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored
13
14 =head2 Functions
15
16 =over 4
17
18 =cut
19
20 */
21
22 #include "parrot/parrot.h"
23
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
24 pmclass FixedIntegerArray need_ext provides array {
d1f7c98 JIT/i386 ord_i_s*
Leopold Toetsch authored
25
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored
26 /*
27
28 =back
29
30 =head2 Methods
31
32 =over 4
33
34 =item C<void init()>
35
36 Initializes the array.
37
38 =cut
39
40 */
41
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
42 VTABLE void init() {
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored
43 PMC_int_val(SELF) = 0;
894d448 @chromatic [PMC] Minor cleanups and tidyings.
chromatic authored
44 PMC_data(SELF) = NULL;
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored
45 }
46
47 /*
48
2760c33 update =pod for new_from_string
Leopold Toetsch authored
49 =item C<PMC new_from_string(STRING *rep, INTVAL flags)>
1af9ad9 fixed integer array new_from_string
Leopold Toetsch authored
50
51 Class method to construct an array from the string representation C<rep>,
bf41b66 @particle [PDD07]: ws cleanup in src/, src/dynpmc/, and src/pmc/
particle authored
52 which is a string I<"(el0, el1, ...)">. C<flags> may have the
2760c33 update =pod for new_from_string
Leopold Toetsch authored
53 C<PObj_constant_FLAG> bit set, which will be honored to create a PMC
54 in the constant PMC pool.
1af9ad9 fixed integer array new_from_string
Leopold Toetsch authored
55
56 =cut
57
58 */
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
59 VTABLE PMC *new_from_string(STRING *rep, INTVAL flags) {
a35f6fd @petdance consting & localizing
petdance authored
60 const INTVAL type = SELF->vtable->base_type;
894d448 @chromatic [PMC] Minor cleanups and tidyings.
chromatic authored
61 INTVAL n, elem, i, l;
62 char *p, *start;
63 int base;
1af9ad9 fixed integer array new_from_string
Leopold Toetsch authored
64
65 if (flags & PObj_constant_FLAG)
66 SELF = constant_pmc_new(INTERP, type);
67 else
68 SELF = pmc_new(INTERP, type);
894d448 @chromatic [PMC] Minor cleanups and tidyings.
chromatic authored
69
d2478f6 fix argument passing ops w/o parens in signature
Leopold Toetsch authored
70 l = string_length(INTERP, rep);
894d448 @chromatic [PMC] Minor cleanups and tidyings.
chromatic authored
71
d2478f6 fix argument passing ops w/o parens in signature
Leopold Toetsch authored
72 if (!l)
1af9ad9 fixed integer array new_from_string
Leopold Toetsch authored
73 return SELF;
894d448 @chromatic [PMC] Minor cleanups and tidyings.
chromatic authored
74
1af9ad9 fixed integer array new_from_string
Leopold Toetsch authored
75 if (rep->encoding != Parrot_fixed_8_encoding_ptr)
76 real_exception(INTERP, NULL, E_ValueError,
77 "unhandled string encoding in constructor");
894d448 @chromatic [PMC] Minor cleanups and tidyings.
chromatic authored
78
79 /* "()" - no args */
80 if (l <= 2 && ((char *)rep->strstart)[0] == '(')
d2478f6 fix argument passing ops w/o parens in signature
Leopold Toetsch authored
81 return SELF;
894d448 @chromatic [PMC] Minor cleanups and tidyings.
chromatic authored
82
1af9ad9 fixed integer array new_from_string
Leopold Toetsch authored
83 /* count commas */
84 p = rep->strstart;
85 for (i = l, n = 0; i; --i, ++p) {
86 if (*p == ',')
87 ++n;
88 }
894d448 @chromatic [PMC] Minor cleanups and tidyings.
chromatic authored
89
1af9ad9 fixed integer array new_from_string
Leopold Toetsch authored
90 /* presize the array */
91 SELF.set_integer_native(n + 1);
894d448 @chromatic [PMC] Minor cleanups and tidyings.
chromatic authored
92
1af9ad9 fixed integer array new_from_string
Leopold Toetsch authored
93 /* parse string */
94 p = rep->strstart;
894d448 @chromatic [PMC] Minor cleanups and tidyings.
chromatic authored
95
1af9ad9 fixed integer array new_from_string
Leopold Toetsch authored
96 for (i = l, n = 0; i; --i, ++p) {
97 switch (*p) {
98 case ' ': continue;
99 case '\t': continue;
100 case '(': continue;
101 case ')': break;
102 case ',':
103 n++;
104 break;
105 default:
106 base = 10;
107 if (*p == '0') {
108 ++p;
109 --i;
110 if (*p == 'b' || *p == 'B') {
111 base = 2;
112 ++p;
113 --i;
114 }
115 else if (*p == 'x' || *p == 'X') {
116 base = 16;
117 ++p;
118 --i;
119 }
120 }
121 start = p;
894d448 @chromatic [PMC] Minor cleanups and tidyings.
chromatic authored
122 elem = strtoul(p, &p, base);
1af9ad9 fixed integer array new_from_string
Leopold Toetsch authored
123 --p;
124 i -= (p - start);
125 SELF.set_integer_keyed_int(n, elem);
126 break;
127 }
128 }
894d448 @chromatic [PMC] Minor cleanups and tidyings.
chromatic authored
129
1af9ad9 fixed integer array new_from_string
Leopold Toetsch authored
130 return SELF;
131 }
132
133 /*
134
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored
135 =item C<void destroy()>
136
137 Destroys the array.
138
139 =cut
140
141 */
142
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
143 VTABLE void destroy() {
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored
144 if (PMC_data(SELF))
145 mem_sys_free(PMC_data(SELF));
894d448 @chromatic [PMC] Minor cleanups and tidyings.
chromatic authored
146
147 PMC_data(SELF) = NULL;
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored
148 PMC_int_val(SELF) = 0;
149 }
150
151 /*
152
153 =item C<PMC *clone()>
154
155 Creates and returns a copy of the array.
156
157 =cut
158
159 */
160
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
161 VTABLE PMC *clone() {
9822a24 var_args 8 - verify signature during bytecode creation
Leopold Toetsch authored
162 /* a quick hack to create a clone in the constant PMC arena
163 * this is needed for the call signatures
164 *
165 * a better way would be probably to supply a flag to the clone
166 * vtable
167 */
168
a35f6fd @petdance consting & localizing
petdance authored
169 PMC * const dest =
170 PObj_constant_TEST(SELF)
171 ? constant_pmc_new(INTERP, SELF->vtable->base_type)
172 : pmc_new(INTERP, SELF->vtable->base_type);
894d448 @chromatic [PMC] Minor cleanups and tidyings.
chromatic authored
173
a35f6fd @petdance consting & localizing
petdance authored
174 if (PMC_data(SELF)) {
175 const INTVAL size = PMC_int_val(SELF);
176 PMC_int_val(dest) = size;
177 PMC_data(dest) = mem_allocate_n_typed(size, INTVAL);
d1f7c98 JIT/i386 ord_i_s*
Leopold Toetsch authored
178
a35f6fd @petdance consting & localizing
petdance authored
179 mem_sys_memcopy(PMC_data(dest), PMC_data(SELF), size * sizeof (INTVAL));
180 PObj_active_destroy_SET(dest);
181 }
894d448 @chromatic [PMC] Minor cleanups and tidyings.
chromatic authored
182
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored
183 return dest;
184 }
185
186 /*
187
188 =item C<INTVAL get_bool()>
189
190 Returns whether the array has any elements (meaning been initialized, for a
191 fixed sized array).
192
193 =cut
194
195 */
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
196 VTABLE INTVAL get_bool() {
a35f6fd @petdance consting & localizing
petdance authored
197 const INTVAL size = SELF.elements();
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored
198 return (INTVAL)(size != 0);
199 }
200
201 /*
202
203 =item C<INTVAL elements()>
204
205 =cut
206
207 */
208
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
209 VTABLE INTVAL elements() {
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored
210 return PMC_int_val(SELF);
211 }
212
213 /*
214
215 =item C<INTVAL get_integer()>
216
217 Returns the number of elements in the array.
218
219 =cut
220
221 */
222
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
223 VTABLE INTVAL get_integer() {
ae8baa5 @bschmalhofer DYNDYNSELF in the Fixed*Array PMC looks like a typo. Using SELF propably
bschmalhofer authored
224 return SELF.elements();
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored
225 }
226
227
228 /*
229
230 =item C<INTVAL get_integer_keyed_int(INTVAL key)>
231
232 Returns the integer value of the element at index C<key>.
233
234 =cut
235
236 */
237
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
238 VTABLE INTVAL get_integer_keyed_int(INTVAL key) {
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored
239 INTVAL *data;
894d448 @chromatic [PMC] Minor cleanups and tidyings.
chromatic authored
240
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored
241 if (key < 0 || key >= PMC_int_val(SELF))
3240c6e @chipdude Consistently name interpreter "interp" instead of "interpreter".
chipdude authored
242 real_exception(interp, NULL, E_IndexError,
d185452 @chromatic Standardize internal exception calls (James deBoer, james at huronbox…
chromatic authored
243 "FixedIntegerArray: index out of bounds!");
d1f7c98 JIT/i386 ord_i_s*
Leopold Toetsch authored
244
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored
245 data = (INTVAL *)PMC_data(SELF);
246 return data[key];
247 }
248
249 /*
250
251 =item C<INTVAL get_integer_keyed(PMC *key)>
252
253 Returns the integer value of the element at index C<*key>.
254
255 =cut
256
257 */
258
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
259 VTABLE INTVAL get_integer_keyed(PMC *key) {
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored
260 /* simple int keys only */
a35f6fd @petdance consting & localizing
petdance authored
261 const INTVAL k = key_integer(INTERP, key);
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
262 return SELF.get_integer_keyed_int(k);
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored
263 }
264
265
266 /*
267
268 =item C<FLOATVAL get_number_keyed_int(INTVAL key)>
269
270 Returns the floating-point value of the element at index C<key>.
271
272 =cut
273
274 */
275
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
276 VTABLE FLOATVAL get_number_keyed_int(INTVAL key) {
277 const INTVAL i = SELF.get_integer_keyed_int(key);
8275ff5 @chromatic [PMC] Fixed a couple of casting warnings of function return values.
chromatic authored
278 return (FLOATVAL)i;
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored
279 }
280
281 /*
282
95e3676 @Infinoid [pmc] PDD07-ize function signatures in src/pmc/[b-f]*.pmc
Infinoid authored
283 =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
284
285 Returns the floating-point value of the element at index C<*key>.
286
287 =cut
288
289 */
290
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
291 VTABLE FLOATVAL get_number_keyed(PMC *key) {
a35f6fd @petdance consting & localizing
petdance authored
292 const INTVAL k = key_integer(INTERP, key);
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
293 return SELF.get_number_keyed_int(k);
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored
294 }
295
296 /*
297
298 =item C<STRING *get_string_keyed_int(INTVAL key)>
299
300 Returns the Parrot string value of the element at index C<key>.
301
302 =cut
303
304 */
305
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
306 VTABLE STRING *get_string_keyed_int(INTVAL key) {
307 PMC * const temp = SELF.get_pmc_keyed_int(key);
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored
308 return VTABLE_get_string(INTERP, temp);
309 }
bf41b66 @particle [PDD07]: ws cleanup in src/, src/dynpmc/, and src/pmc/
particle authored
310
5a67dac @tewk Add get_repr to fixedintegerarray and integer
tewk authored
311 /*
312
313 =item C<STRING *get_repr()>
314
315 Returns the Parrot string representation C<key>.
316
317 =cut
318
319 */
320
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
321 VTABLE STRING *get_repr() {
a35f6fd @petdance consting & localizing
petdance authored
322 STRING *res = CONST_STRING(INTERP, "[ ");
323 const INTVAL n = VTABLE_elements(INTERP, SELF);
894d448 @chromatic [PMC] Minor cleanups and tidyings.
chromatic authored
324 INTVAL j;
5a67dac @tewk Add get_repr to fixedintegerarray and integer
tewk authored
325
326 for (j = 0; j < n; ++j) {
a35f6fd @petdance consting & localizing
petdance authored
327 PMC * const val = SELF.get_pmc_keyed_int(j);
2c75606 @jnthn Remove UFlags argument from string_append, as requested in ticket #40…
jnthn authored
328 res = string_append(INTERP, res, VTABLE_get_repr(INTERP, val));
894d448 @chromatic [PMC] Minor cleanups and tidyings.
chromatic authored
329
5a67dac @tewk Add get_repr to fixedintegerarray and integer
tewk authored
330 if (j < n - 1)
ba2c387 @chromatic [src] Converted all applicable uses of const_string() to CONST_STRING().
chromatic authored
331 res = string_append(INTERP, res, CONST_STRING(INTERP, ", "));
5a67dac @tewk Add get_repr to fixedintegerarray and integer
tewk authored
332 }
894d448 @chromatic [PMC] Minor cleanups and tidyings.
chromatic authored
333
ba2c387 @chromatic [src] Converted all applicable uses of const_string() to CONST_STRING().
chromatic authored
334 res = string_append(INTERP, res, CONST_STRING(INTERP, " ]"));
5a67dac @tewk Add get_repr to fixedintegerarray and integer
tewk authored
335 return res;
336 }
337
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored
338
339 /*
340
341 =item C<STRING *get_string_keyed(PMC *key)>
342
343 Returns the Parrot string value of the element at index C<*key>.
344
345 =cut
346
347 */
348
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
349 VTABLE STRING *get_string_keyed(PMC *key) {
a35f6fd @petdance consting & localizing
petdance authored
350 const INTVAL k = key_integer(INTERP, key);
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
351 return SELF.get_string_keyed_int(k);
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored
352 }
353
354
355 /*
356
357 =item C<PMC *get_pmc_keyed_int(INTVAL key)>
358
359 Returns the PMC value of the element at index C<key>.
360
361 =cut
362
363 */
364
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
365 VTABLE PMC *get_pmc_keyed_int(INTVAL key) {
a35f6fd @petdance consting & localizing
petdance authored
366 PMC * const ret = pmc_new(INTERP, enum_class_Integer);
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
367 const INTVAL val = SELF.get_integer_keyed_int(key);
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored
368 VTABLE_set_integer_native(INTERP, ret, val);
369 return ret;
370 }
371
372 /*
373
374 =item C<PMC *get_pmc_keyed(PMC *key)>
375
376 Returns the PMC value of the element at index C<*key>.
377
378 =cut
379
380 */
381
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
382 VTABLE PMC *get_pmc_keyed(PMC *key) {
a35f6fd @petdance consting & localizing
petdance authored
383 const INTVAL k = key_integer(INTERP, key);
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
384 return SELF.get_pmc_keyed_int(k);
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored
385 }
386
387 /*
388
389 =item C<void set_integer_native(INTVAL size)>
390
391 Resizes the array to C<size> elements.
392
393 =cut
394
395 */
396
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
397 VTABLE void set_integer_native(INTVAL size) {
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored
398 if (PMC_int_val(SELF) || size < 1)
7298186 @particle pmc: convert Fixed*Array and Resizable*Array internal_exceptions to r…
particle authored
399 real_exception(INTERP, NULL, E_IndexError,
d1f7c98 JIT/i386 ord_i_s*
Leopold Toetsch authored
400 "FixedIntegerArray: Can't resize!");
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored
401 PMC_int_val(SELF) = size;
894d448 @chromatic [PMC] Minor cleanups and tidyings.
chromatic authored
402 PMC_data(SELF) = mem_sys_allocate_zeroed(size * sizeof (INTVAL));
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored
403 PObj_active_destroy_SET(SELF);
404 }
405
406 /*
407
408 =item C<void set_integer_keyed_int(INTVAL key, INTVAL value)>
409
410 Sets the integer value of the element at index C<key> to 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_integer_keyed_int(INTVAL key, INTVAL value) {
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored
417 INTVAL *data;
894d448 @chromatic [PMC] Minor cleanups and tidyings.
chromatic authored
418
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored
419 if (key < 0 || key >= PMC_int_val(SELF))
3240c6e @chipdude Consistently name interpreter "interp" instead of "interpreter".
chipdude authored
420 real_exception(interp, NULL, E_IndexError,
d185452 @chromatic Standardize internal exception calls (James deBoer, james at huronbox…
chromatic authored
421 "FixedIntegerArray: index out of bounds!");
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored
422
894d448 @chromatic [PMC] Minor cleanups and tidyings.
chromatic authored
423 data = (INTVAL *)PMC_data(SELF);
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored
424 data[key] = value;
425 }
426
427 /*
428
429 =item C<void set_integer_keyed(PMC *key, INTVAL value)>
430
431 Sets the integer value of the element at index C<key> to C<value>.
432
433 =cut
434
435 */
436
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
437 VTABLE void set_integer_keyed(PMC *key, INTVAL value) {
a35f6fd @petdance consting & localizing
petdance authored
438 const INTVAL k = key_integer(INTERP, key);
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
439 SELF.set_integer_keyed_int(k, value);
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored
440 }
441
442 /*
443
444 =item C<void set_number_keyed_int(INTVAL key, FLOATVAL value)>
445
894d448 @chromatic [PMC] Minor cleanups and tidyings.
chromatic authored
446 Sets the floating-point value of the element at index C<key> to C<value>.
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored
447
448 =cut
449
450 */
451
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
452 VTABLE void set_number_keyed_int(INTVAL key, FLOATVAL value) {
453 SELF.set_integer_keyed_int(key, (INTVAL)value);
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored
454 }
455
456 /*
457
458 =item C<void set_number_keyed(PMC *key, FLOATVAL value)>
459
894d448 @chromatic [PMC] Minor cleanups and tidyings.
chromatic authored
460 Sets the floating-point value of the element at index C<key> to C<value>.
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored
461
462 =cut
463
464 */
465
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
466 VTABLE void set_number_keyed(PMC *key, FLOATVAL value) {
a35f6fd @petdance consting & localizing
petdance authored
467 const INTVAL k = key_integer(INTERP, key);
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
468 SELF.set_number_keyed_int(k, value);
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored
469 }
d1f7c98 JIT/i386 ord_i_s*
Leopold Toetsch authored
470
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored
471 /*
472
473 =item C<void set_string_keyed_int(INTVAL key, STRING *value)>
474
475 Sets the Parrot string value of the element at index C<key> to C<value>.
476
477 =cut
478
479 */
480
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
481 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
482 INTVAL tempInt;
a35f6fd @petdance consting & localizing
petdance authored
483 PMC * const tempPMC = pmc_new(INTERP, enum_class_Integer);
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored
484 VTABLE_set_string_native(INTERP, tempPMC, value);
894d448 @chromatic [PMC] Minor cleanups and tidyings.
chromatic authored
485 tempInt = VTABLE_get_integer(INTERP, tempPMC);
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
486 SELF.set_integer_keyed_int(key, tempInt);
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored
487 }
488
489 /*
490
95e3676 @Infinoid [pmc] PDD07-ize function signatures in src/pmc/[b-f]*.pmc
Infinoid authored
491 =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
492
894d448 @chromatic [PMC] Minor cleanups and tidyings.
chromatic authored
493 Sets the string value of the element at index C<key> to C<value>.
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored
494
495 =cut
496
497 */
498
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
499 VTABLE void set_string_keyed(PMC *key, STRING *value) {
a35f6fd @petdance consting & localizing
petdance authored
500 const INTVAL k = key_integer(INTERP, key);
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
501 SELF.set_string_keyed_int(k, value);
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored
502 }
503
504 /*
505
506 =item C<void set_pmc_keyed_int(INTVAL key, PMC *src)>
507
508 Sets the PMC value of the element at index C<key> to C<*src>.
509
510 =cut
511
512 */
513
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
514 VTABLE void set_pmc_keyed_int(INTVAL key, PMC *src) {
a35f6fd @petdance consting & localizing
petdance authored
515 const INTVAL tempInt = VTABLE_get_integer(INTERP, src);
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
516 SELF.set_integer_keyed_int(key, tempInt);
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored
517 }
518
519 /*
520
95e3676 @Infinoid [pmc] PDD07-ize function signatures in src/pmc/[b-f]*.pmc
Infinoid authored
521 =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
522
894d448 @chromatic [PMC] Minor cleanups and tidyings.
chromatic authored
523 Sets the string value of the element at index C<key> to C<value>.
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored
524
525 =cut
526
527 */
528
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
529 VTABLE void set_pmc_keyed(PMC *key, PMC *value) {
a35f6fd @petdance consting & localizing
petdance authored
530 const INTVAL k = key_integer(INTERP, key);
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
531 SELF.set_pmc_keyed_int(k, value);
532 }
533
534 METHOD sort(PMC *cmp_func) {
535 UINTVAL n = (UINTVAL)PMC_int_val(SELF);
536
537 if (n > 1)
538 Parrot_quicksort(interp, PMC_data_typed(SELF, void **), n, cmp_func);
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored
539 }
540
6287ae3 add missing fixedintegerarray.freeze and .thaw
Leopold Toetsch authored
541 /*
542
543 =item C<void visit(visit_info *info)>
544
545 This is used by freeze/thaw to visit the contents of the array.
546
547 C<*info> is the visit info, (see F<include/parrot/pmc_freeze.h>).
548
549 =item C<void freeze(visit_info *info)>
550
551 Used to archive the array.
552
553 =item C<void thaw(visit_info *info)>
554
555 Used to unarchive the array.
556
557 =cut
558
559 */
560
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
561 VTABLE void visit(visit_info *info) {
6287ae3 add missing fixedintegerarray.freeze and .thaw
Leopold Toetsch authored
562 SUPER(info);
563 }
564
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
565 VTABLE void freeze(visit_info *info) {
6287ae3 add missing fixedintegerarray.freeze and .thaw
Leopold Toetsch authored
566 IMAGE_IO *io = info->image_io;
894d448 @chromatic [PMC] Minor cleanups and tidyings.
chromatic authored
567 INTVAL *ar;
568 INTVAL i, n;
6287ae3 add missing fixedintegerarray.freeze and .thaw
Leopold Toetsch authored
569
570 SUPER(info);
894d448 @chromatic [PMC] Minor cleanups and tidyings.
chromatic authored
571
572 n = VTABLE_elements(INTERP, SELF);
297024c @paultcochrane [pmc] Changed instances of io->vtable->whatever() to VTABLE_whatever(…
paultcochrane authored
573 VTABLE_push_integer(INTERP, io, n);
6287ae3 add missing fixedintegerarray.freeze and .thaw
Leopold Toetsch authored
574 ar = (INTVAL *)PMC_data(SELF);
894d448 @chromatic [PMC] Minor cleanups and tidyings.
chromatic authored
575
576 for (i = 0; i < n; ++i)
297024c @paultcochrane [pmc] Changed instances of io->vtable->whatever() to VTABLE_whatever(…
paultcochrane authored
577 VTABLE_push_integer(INTERP, io, ar[i]);
6287ae3 add missing fixedintegerarray.freeze and .thaw
Leopold Toetsch authored
578 }
579
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
580 VTABLE void thaw(visit_info *info) {
6287ae3 add missing fixedintegerarray.freeze and .thaw
Leopold Toetsch authored
581
582 if (info->extra_flags == EXTRA_IS_NULL) {
a35f6fd @petdance consting & localizing
petdance authored
583 IMAGE_IO * const io = info->image_io;
584 const INTVAL n = VTABLE_shift_integer(INTERP, io);
894d448 @chromatic [PMC] Minor cleanups and tidyings.
chromatic authored
585
6287ae3 add missing fixedintegerarray.freeze and .thaw
Leopold Toetsch authored
586 PMC_int_val(SELF) = 0;
894d448 @chromatic [PMC] Minor cleanups and tidyings.
chromatic authored
587 PMC_data(SELF) = NULL;
588
a35f6fd @petdance consting & localizing
petdance authored
589 if (n) {
590 INTVAL i;
591 INTVAL *ar;
894d448 @chromatic [PMC] Minor cleanups and tidyings.
chromatic authored
592
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
593 SELF.set_integer_native(n);
a35f6fd @petdance consting & localizing
petdance authored
594 ar = (INTVAL *)PMC_data(SELF);
894d448 @chromatic [PMC] Minor cleanups and tidyings.
chromatic authored
595
a35f6fd @petdance consting & localizing
petdance authored
596 for (i = 0; i < n; ++i)
597 ar[i] = VTABLE_shift_integer(INTERP, io);
598 }
6287ae3 add missing fixedintegerarray.freeze and .thaw
Leopold Toetsch authored
599 }
600 else
601 SUPER(info);
602 }
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored
603 }
604
605 /*
606
607 =back
608
609 =head1 SEE ALSO
610
1e8a4ab this patch adds some relevant 'push' ops to the resizable PMCs, descr…
Dan Sugalski authored
611 F<docs/pdds/pdd17_basic_types.pod>.
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored
612
613 =cut
614
615 */
616
617 /*
618 * Local variables:
72575ae @bschmalhofer #40481: [PATCH] C-code coda in pmc files
bschmalhofer authored
619 * c-file-style: "parrot"
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored
620 * End:
621 * vim: expandtab shiftwidth=4:
72575ae @bschmalhofer #40481: [PATCH] C-code coda in pmc files
bschmalhofer authored
622 */
Something went wrong with that request. Please try again.