Skip to content

HTTPS clone URL

Subversion checkout URL

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