Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 625 lines (407 sloc) 13.023 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)
2255840 @allisonrandal [pdd17pmc] Merging the pdd25cx branch into trunk for r26555 to r29949.
allisonrandal authored
76 Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_INVALID_ENCODING,
1af9ad9 fixed integer array new_from_string
Leopold Toetsch authored
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() {
8e04ace @NotFound exchange roles of elements and get_integer in FixedIntegerArray
NotFound authored
197 const INTVAL size = SELF.get_integer();
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() {
8e04ace @NotFound exchange roles of elements and get_integer in FixedIntegerArray
NotFound authored
210 return SELF.get_integer();
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored
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() {
8e04ace @NotFound exchange roles of elements and get_integer in FixedIntegerArray
NotFound authored
224 return PMC_int_val(SELF);
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))
2255840 @allisonrandal [pdd17pmc] Merging the pdd25cx branch into trunk for r26555 to r29949.
allisonrandal authored
242 Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_OUT_OF_BOUNDS,
d185452 @chromatic Standardize internal exception calls (James deBoer, james at huronbox do...
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, "[ ");
8e04ace @NotFound exchange roles of elements and get_integer in FixedIntegerArray
NotFound authored
323 const INTVAL n = SELF.get_integer();
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 #40523...
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)
2255840 @allisonrandal [pdd17pmc] Merging the pdd25cx branch into trunk for r26555 to r29949.
allisonrandal authored
399 Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_OUT_OF_BOUNDS,
d1f7c98 JIT/i386 ord_i_s*
Leopold Toetsch authored
400 "FixedIntegerArray: Can't resize!");
2255840 @allisonrandal [pdd17pmc] Merging the pdd25cx branch into trunk for r26555 to r29949.
allisonrandal authored
401
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored
402 PMC_int_val(SELF) = size;
4e87173 @chromatic [PMC] Fixed a potential memory leak when resizing a FixedIntegerArray.
chromatic authored
403 mem_realloc_n_typed(PMC_data(SELF), size, INTVAL);
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored
404 PObj_active_destroy_SET(SELF);
405 }
406
407 /*
408
409 =item C<void set_integer_keyed_int(INTVAL key, INTVAL value)>
410
411 Sets the integer value of the element at index C<key> to C<value>.
412
413 =cut
414
415 */
416
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
417 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
418 INTVAL *data;
894d448 @chromatic [PMC] Minor cleanups and tidyings.
chromatic authored
419
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored
420 if (key < 0 || key >= PMC_int_val(SELF))
2255840 @allisonrandal [pdd17pmc] Merging the pdd25cx branch into trunk for r26555 to r29949.
allisonrandal authored
421 Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_OUT_OF_BOUNDS,
d185452 @chromatic Standardize internal exception calls (James deBoer, james at huronbox do...
chromatic authored
422 "FixedIntegerArray: index out of bounds!");
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored
423
894d448 @chromatic [PMC] Minor cleanups and tidyings.
chromatic authored
424 data = (INTVAL *)PMC_data(SELF);
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored
425 data[key] = value;
426 }
427
428 /*
429
430 =item C<void set_integer_keyed(PMC *key, INTVAL value)>
431
432 Sets the integer value of the element at index C<key> to C<value>.
433
434 =cut
435
436 */
437
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
438 VTABLE void set_integer_keyed(PMC *key, INTVAL value) {
a35f6fd @petdance consting & localizing
petdance authored
439 const INTVAL k = key_integer(INTERP, key);
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
440 SELF.set_integer_keyed_int(k, value);
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored
441 }
442
443 /*
444
445 =item C<void set_number_keyed_int(INTVAL key, FLOATVAL value)>
446
894d448 @chromatic [PMC] Minor cleanups and tidyings.
chromatic authored
447 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
448
449 =cut
450
451 */
452
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
453 VTABLE void set_number_keyed_int(INTVAL key, FLOATVAL value) {
454 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
455 }
456
457 /*
458
459 =item C<void set_number_keyed(PMC *key, FLOATVAL value)>
460
894d448 @chromatic [PMC] Minor cleanups and tidyings.
chromatic authored
461 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
462
463 =cut
464
465 */
466
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
467 VTABLE void set_number_keyed(PMC *key, FLOATVAL value) {
a35f6fd @petdance consting & localizing
petdance authored
468 const INTVAL k = key_integer(INTERP, key);
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
469 SELF.set_number_keyed_int(k, value);
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored
470 }
d1f7c98 JIT/i386 ord_i_s*
Leopold Toetsch authored
471
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored
472 /*
473
474 =item C<void set_string_keyed_int(INTVAL key, STRING *value)>
475
476 Sets the Parrot string value of the element at index C<key> to C<value>.
477
478 =cut
479
480 */
481
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
482 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
483 INTVAL tempInt;
4e87173 @chromatic [PMC] Fixed a potential memory leak when resizing a FixedIntegerArray.
chromatic authored
484 PMC * const tempPMC = temporary_pmc_new(INTERP, enum_class_Integer);
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored
485 VTABLE_set_string_native(INTERP, tempPMC, value);
894d448 @chromatic [PMC] Minor cleanups and tidyings.
chromatic authored
486 tempInt = VTABLE_get_integer(INTERP, tempPMC);
4e87173 @chromatic [PMC] Fixed a potential memory leak when resizing a FixedIntegerArray.
chromatic authored
487 temporary_pmc_free(interp, tempPMC);
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
488 SELF.set_integer_keyed_int(key, tempInt);
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored
489 }
490
491 /*
492
95e3676 @Infinoid [pmc] PDD07-ize function signatures in src/pmc/[b-f]*.pmc
Infinoid authored
493 =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
494
894d448 @chromatic [PMC] Minor cleanups and tidyings.
chromatic authored
495 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
496
497 =cut
498
499 */
500
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
501 VTABLE void set_string_keyed(PMC *key, STRING *value) {
a35f6fd @petdance consting & localizing
petdance authored
502 const INTVAL k = key_integer(INTERP, key);
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
503 SELF.set_string_keyed_int(k, value);
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored
504 }
505
506 /*
507
508 =item C<void set_pmc_keyed_int(INTVAL key, PMC *src)>
509
510 Sets the PMC value of the element at index C<key> to C<*src>.
511
512 =cut
513
514 */
515
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
516 VTABLE void set_pmc_keyed_int(INTVAL key, PMC *src) {
a35f6fd @petdance consting & localizing
petdance authored
517 const INTVAL tempInt = VTABLE_get_integer(INTERP, src);
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
518 SELF.set_integer_keyed_int(key, tempInt);
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored
519 }
520
521 /*
522
95e3676 @Infinoid [pmc] PDD07-ize function signatures in src/pmc/[b-f]*.pmc
Infinoid authored
523 =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
524
894d448 @chromatic [PMC] Minor cleanups and tidyings.
chromatic authored
525 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
526
527 =cut
528
529 */
530
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
531 VTABLE void set_pmc_keyed(PMC *key, PMC *value) {
a35f6fd @petdance consting & localizing
petdance authored
532 const INTVAL k = key_integer(INTERP, key);
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
533 SELF.set_pmc_keyed_int(k, value);
534 }
535
536 METHOD sort(PMC *cmp_func) {
537 UINTVAL n = (UINTVAL)PMC_int_val(SELF);
538
539 if (n > 1)
540 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
541 }
542
6287ae3 add missing fixedintegerarray.freeze and .thaw
Leopold Toetsch authored
543 /*
544
545 =item C<void visit(visit_info *info)>
546
547 This is used by freeze/thaw to visit the contents of the array.
548
549 C<*info> is the visit info, (see F<include/parrot/pmc_freeze.h>).
550
551 =item C<void freeze(visit_info *info)>
552
553 Used to archive the array.
554
555 =item C<void thaw(visit_info *info)>
556
557 Used to unarchive the array.
558
559 =cut
560
561 */
562
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
563 VTABLE void visit(visit_info *info) {
6287ae3 add missing fixedintegerarray.freeze and .thaw
Leopold Toetsch authored
564 SUPER(info);
565 }
566
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
567 VTABLE void freeze(visit_info *info) {
6287ae3 add missing fixedintegerarray.freeze and .thaw
Leopold Toetsch authored
568 IMAGE_IO *io = info->image_io;
894d448 @chromatic [PMC] Minor cleanups and tidyings.
chromatic authored
569 INTVAL *ar;
570 INTVAL i, n;
6287ae3 add missing fixedintegerarray.freeze and .thaw
Leopold Toetsch authored
571
572 SUPER(info);
894d448 @chromatic [PMC] Minor cleanups and tidyings.
chromatic authored
573
8e04ace @NotFound exchange roles of elements and get_integer in FixedIntegerArray
NotFound authored
574 n = SELF.get_integer();
297024c @paultcochrane [pmc] Changed instances of io->vtable->whatever() to VTABLE_whatever() a...
paultcochrane authored
575 VTABLE_push_integer(INTERP, io, n);
6287ae3 add missing fixedintegerarray.freeze and .thaw
Leopold Toetsch authored
576 ar = (INTVAL *)PMC_data(SELF);
894d448 @chromatic [PMC] Minor cleanups and tidyings.
chromatic authored
577
578 for (i = 0; i < n; ++i)
297024c @paultcochrane [pmc] Changed instances of io->vtable->whatever() to VTABLE_whatever() a...
paultcochrane authored
579 VTABLE_push_integer(INTERP, io, ar[i]);
6287ae3 add missing fixedintegerarray.freeze and .thaw
Leopold Toetsch authored
580 }
581
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
582 VTABLE void thaw(visit_info *info) {
6287ae3 add missing fixedintegerarray.freeze and .thaw
Leopold Toetsch authored
583
584 if (info->extra_flags == EXTRA_IS_NULL) {
a35f6fd @petdance consting & localizing
petdance authored
585 IMAGE_IO * const io = info->image_io;
586 const INTVAL n = VTABLE_shift_integer(INTERP, io);
894d448 @chromatic [PMC] Minor cleanups and tidyings.
chromatic authored
587
6287ae3 add missing fixedintegerarray.freeze and .thaw
Leopold Toetsch authored
588 PMC_int_val(SELF) = 0;
894d448 @chromatic [PMC] Minor cleanups and tidyings.
chromatic authored
589 PMC_data(SELF) = NULL;
590
a35f6fd @petdance consting & localizing
petdance authored
591 if (n) {
592 INTVAL i;
593 INTVAL *ar;
894d448 @chromatic [PMC] Minor cleanups and tidyings.
chromatic authored
594
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
595 SELF.set_integer_native(n);
a35f6fd @petdance consting & localizing
petdance authored
596 ar = (INTVAL *)PMC_data(SELF);
894d448 @chromatic [PMC] Minor cleanups and tidyings.
chromatic authored
597
a35f6fd @petdance consting & localizing
petdance authored
598 for (i = 0; i < n; ++i)
599 ar[i] = VTABLE_shift_integer(INTERP, io);
600 }
6287ae3 add missing fixedintegerarray.freeze and .thaw
Leopold Toetsch authored
601 }
602 else
603 SUPER(info);
604 }
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored
605 }
606
607 /*
608
609 =back
610
611 =head1 SEE ALSO
612
1e8a4ab this patch adds some relevant 'push' ops to the resizable PMCs, describe...
Dan Sugalski authored
613 F<docs/pdds/pdd17_basic_types.pod>.
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored
614
615 =cut
616
617 */
618
619 /*
620 * Local variables:
72575ae @bschmalhofer #40481: [PATCH] C-code coda in pmc files
bschmalhofer authored
621 * c-file-style: "parrot"
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored
622 * End:
623 * vim: expandtab shiftwidth=4:
72575ae @bschmalhofer #40481: [PATCH] C-code coda in pmc files
bschmalhofer authored
624 */
Something went wrong with that request. Please try again.