Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 677 lines (448 sloc) 14.798 kB
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored
1 /*
0e36289 @allisonrandal [cage] Updating all copyrights in src/ to Parrot Foundation.
allisonrandal authored
2 Copyright (C) 2001-2009, Parrot Foundation.
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored
3 $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 {
e5dead2 @cotto [pmc] update *IntegerArray to use ATTRs
cotto authored
25 ATTR INTVAL size; /* number of INTVALs stored in this array */
26 ATTR INTVAL * int_array; /* INTVALs are stored here */
d1f7c98 JIT/i386 ord_i_s*
Leopold Toetsch authored
27
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored
28 /*
29
30 =back
31
32 =head2 Methods
33
34 =over 4
35
36 =item C<void init()>
37
38 Initializes the array.
39
40 =cut
41
42 */
43
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
44 VTABLE void init() {
e5dead2 @cotto [pmc] update *IntegerArray to use ATTRs
cotto authored
45 Parrot_FixedIntegerArray_attributes* attrs =
46 mem_allocate_zeroed_typed(Parrot_FixedIntegerArray_attributes);
47 PMC_data(SELF) = attrs;
48 PObj_active_destroy_SET(SELF);
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored
49 }
50
51 /*
52
21173f8 @chromatic [PMC] Changed new_from_string VTABLE entry name to instantiate_str, p…
chromatic authored
53 =item C<PMC instantiate_str(STRING *rep, INTVAL flags)>
1af9ad9 fixed integer array new_from_string
Leopold Toetsch authored
54
55 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
56 which is a string I<"(el0, el1, ...)">. C<flags> may have the
2760c33 update =pod for new_from_string
Leopold Toetsch authored
57 C<PObj_constant_FLAG> bit set, which will be honored to create a PMC
58 in the constant PMC pool.
1af9ad9 fixed integer array new_from_string
Leopold Toetsch authored
59
60 =cut
61
62 */
21173f8 @chromatic [PMC] Changed new_from_string VTABLE entry name to instantiate_str, p…
chromatic authored
63 VTABLE PMC *instantiate_str(STRING *rep, INTVAL flags) {
a35f6fd @petdance consting & localizing
petdance authored
64 const INTVAL type = SELF->vtable->base_type;
894d448 @chromatic [PMC] Minor cleanups and tidyings.
chromatic authored
65 INTVAL n, elem, i, l;
68b4820 @allisonrandal [cage] Change the parsing of FixedIntegerArray initialization strings…
allisonrandal authored
66 char *source, *p, *start;
894d448 @chromatic [PMC] Minor cleanups and tidyings.
chromatic authored
67 int base;
1af9ad9 fixed integer array new_from_string
Leopold Toetsch authored
68
69 if (flags & PObj_constant_FLAG)
70 SELF = constant_pmc_new(INTERP, type);
71 else
72 SELF = pmc_new(INTERP, type);
894d448 @chromatic [PMC] Minor cleanups and tidyings.
chromatic authored
73
b6bc0c3 @allisonrandal [pdd28str] Merging the pdd27mmd branch into trunk for r36123 to r36318.
allisonrandal authored
74 l = Parrot_str_byte_length(INTERP, rep);
894d448 @chromatic [PMC] Minor cleanups and tidyings.
chromatic authored
75
d2478f6 fix argument passing ops w/o parens in signature
Leopold Toetsch authored
76 if (!l)
1af9ad9 fixed integer array new_from_string
Leopold Toetsch authored
77 return SELF;
894d448 @chromatic [PMC] Minor cleanups and tidyings.
chromatic authored
78
1af9ad9 fixed integer array new_from_string
Leopold Toetsch authored
79 if (rep->encoding != Parrot_fixed_8_encoding_ptr)
2255840 @allisonrandal [pdd17pmc] Merging the pdd25cx branch into trunk for r26555 to r29949.
allisonrandal authored
80 Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_INVALID_ENCODING,
1af9ad9 fixed integer array new_from_string
Leopold Toetsch authored
81 "unhandled string encoding in constructor");
894d448 @chromatic [PMC] Minor cleanups and tidyings.
chromatic authored
82
b6bc0c3 @allisonrandal [pdd28str] Merging the pdd27mmd branch into trunk for r36123 to r36318.
allisonrandal authored
83 source = Parrot_str_to_cstring(interp, rep);
68b4820 @allisonrandal [cage] Change the parsing of FixedIntegerArray initialization strings…
allisonrandal authored
84
894d448 @chromatic [PMC] Minor cleanups and tidyings.
chromatic authored
85 /* "()" - no args */
68b4820 @allisonrandal [cage] Change the parsing of FixedIntegerArray initialization strings…
allisonrandal authored
86 if (l <= 2 && *source == '(') {
b6bc0c3 @allisonrandal [pdd28str] Merging the pdd27mmd branch into trunk for r36123 to r36318.
allisonrandal authored
87 Parrot_str_free_cstring(source);
d2478f6 fix argument passing ops w/o parens in signature
Leopold Toetsch authored
88 return SELF;
68b4820 @allisonrandal [cage] Change the parsing of FixedIntegerArray initialization strings…
allisonrandal authored
89 }
894d448 @chromatic [PMC] Minor cleanups and tidyings.
chromatic authored
90
1af9ad9 fixed integer array new_from_string
Leopold Toetsch authored
91 /* count commas */
68b4820 @allisonrandal [cage] Change the parsing of FixedIntegerArray initialization strings…
allisonrandal authored
92 p = source;
93 n = 0;
94 while (*p) {
1af9ad9 fixed integer array new_from_string
Leopold Toetsch authored
95 if (*p == ',')
96 ++n;
68b4820 @allisonrandal [cage] Change the parsing of FixedIntegerArray initialization strings…
allisonrandal authored
97 p++;
1af9ad9 fixed integer array new_from_string
Leopold Toetsch authored
98 }
894d448 @chromatic [PMC] Minor cleanups and tidyings.
chromatic authored
99
1af9ad9 fixed integer array new_from_string
Leopold Toetsch authored
100 /* presize the array */
101 SELF.set_integer_native(n + 1);
894d448 @chromatic [PMC] Minor cleanups and tidyings.
chromatic authored
102
1af9ad9 fixed integer array new_from_string
Leopold Toetsch authored
103 /* parse string */
68b4820 @allisonrandal [cage] Change the parsing of FixedIntegerArray initialization strings…
allisonrandal authored
104 p = source;
894d448 @chromatic [PMC] Minor cleanups and tidyings.
chromatic authored
105
1af9ad9 fixed integer array new_from_string
Leopold Toetsch authored
106 for (i = l, n = 0; i; --i, ++p) {
107 switch (*p) {
108 case ' ': continue;
109 case '\t': continue;
110 case '(': continue;
111 case ')': break;
112 case ',':
113 n++;
114 break;
115 default:
116 base = 10;
117 if (*p == '0') {
118 ++p;
119 --i;
120 if (*p == 'b' || *p == 'B') {
121 base = 2;
122 ++p;
123 --i;
124 }
125 else if (*p == 'x' || *p == 'X') {
126 base = 16;
127 ++p;
128 --i;
129 }
130 }
131 start = p;
894d448 @chromatic [PMC] Minor cleanups and tidyings.
chromatic authored
132 elem = strtoul(p, &p, base);
1af9ad9 fixed integer array new_from_string
Leopold Toetsch authored
133 --p;
134 i -= (p - start);
135 SELF.set_integer_keyed_int(n, elem);
136 break;
137 }
138 }
894d448 @chromatic [PMC] Minor cleanups and tidyings.
chromatic authored
139
b6bc0c3 @allisonrandal [pdd28str] Merging the pdd27mmd branch into trunk for r36123 to r36318.
allisonrandal authored
140 Parrot_str_free_cstring(source);
1af9ad9 fixed integer array new_from_string
Leopold Toetsch authored
141 return SELF;
142 }
143
144 /*
145
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored
146 =item C<void destroy()>
147
148 Destroys the array.
149
150 =cut
151
152 */
153
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
154 VTABLE void destroy() {
e5dead2 @cotto [pmc] update *IntegerArray to use ATTRs
cotto authored
155 INTVAL* int_array;
156 GET_ATTR_int_array(INTERP, SELF, int_array);
157 if (int_array)
158 mem_sys_free(int_array);
159 mem_sys_free(PMC_data(SELF));
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored
160 }
161
162 /*
163
164 =item C<PMC *clone()>
165
166 Creates and returns a copy of the array.
167
168 =cut
169
170 */
171
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
172 VTABLE PMC *clone() {
9822a24 var_args 8 - verify signature during bytecode creation
Leopold Toetsch authored
173 /* a quick hack to create a clone in the constant PMC arena
174 * this is needed for the call signatures
175 *
176 * a better way would be probably to supply a flag to the clone
177 * vtable
178 */
179
e5dead2 @cotto [pmc] update *IntegerArray to use ATTRs
cotto authored
180 INTVAL * int_array;
181 PMC * const dest =
a35f6fd @petdance consting & localizing
petdance authored
182 PObj_constant_TEST(SELF)
183 ? constant_pmc_new(INTERP, SELF->vtable->base_type)
184 : pmc_new(INTERP, SELF->vtable->base_type);
894d448 @chromatic [PMC] Minor cleanups and tidyings.
chromatic authored
185
e5dead2 @cotto [pmc] update *IntegerArray to use ATTRs
cotto authored
186 GET_ATTR_int_array(INTERP, SELF, int_array);
187 if (int_array) {
188 INTVAL *dest_int_array;
189 const INTVAL size = SELF.elements();
190 dest_int_array = mem_allocate_n_typed(size, INTVAL);
191 SET_ATTR_size(INTERP, dest, size);
192 SET_ATTR_int_array(INTERP, dest, dest_int_array);
d1f7c98 JIT/i386 ord_i_s*
Leopold Toetsch authored
193
e5dead2 @cotto [pmc] update *IntegerArray to use ATTRs
cotto authored
194 mem_sys_memcopy(dest_int_array, int_array, size * sizeof (INTVAL));
a35f6fd @petdance consting & localizing
petdance authored
195 PObj_active_destroy_SET(dest);
196 }
894d448 @chromatic [PMC] Minor cleanups and tidyings.
chromatic authored
197
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored
198 return dest;
199 }
200
201 /*
202
203 =item C<INTVAL get_bool()>
204
205 Returns whether the array has any elements (meaning been initialized, for a
206 fixed sized array).
207
208 =cut
209
210 */
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
211 VTABLE INTVAL get_bool() {
8e04ace @NotFound exchange roles of elements and get_integer in FixedIntegerArray
NotFound authored
212 const INTVAL size = SELF.get_integer();
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored
213 return (INTVAL)(size != 0);
214 }
215
216 /*
217
218 =item C<INTVAL elements()>
219
220 =cut
221
222 */
223
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
224 VTABLE INTVAL elements() {
8e04ace @NotFound exchange roles of elements and get_integer in FixedIntegerArray
NotFound authored
225 return SELF.get_integer();
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored
226 }
227
228 /*
229
230 =item C<INTVAL get_integer()>
231
232 Returns the number of elements in the array.
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() {
e5dead2 @cotto [pmc] update *IntegerArray to use ATTRs
cotto authored
239 return PARROT_FIXEDINTEGERARRAY(SELF)->size;
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored
240 }
241
242
243 /*
244
245 =item C<INTVAL get_integer_keyed_int(INTVAL key)>
246
247 Returns the integer value of the element at index C<key>.
248
249 =cut
250
251 */
252
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
253 VTABLE INTVAL get_integer_keyed_int(INTVAL key) {
e5dead2 @cotto [pmc] update *IntegerArray to use ATTRs
cotto authored
254 INTVAL *int_array;
894d448 @chromatic [PMC] Minor cleanups and tidyings.
chromatic authored
255
e5dead2 @cotto [pmc] update *IntegerArray to use ATTRs
cotto authored
256 if (key < 0 || key >= SELF.elements())
2255840 @allisonrandal [pdd17pmc] Merging the pdd25cx branch into trunk for r26555 to r29949.
allisonrandal authored
257 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
258 "FixedIntegerArray: index out of bounds!");
d1f7c98 JIT/i386 ord_i_s*
Leopold Toetsch authored
259
e5dead2 @cotto [pmc] update *IntegerArray to use ATTRs
cotto authored
260 GET_ATTR_int_array(INTERP, SELF, int_array);
261 return int_array[key];
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored
262 }
263
264 /*
265
266 =item C<INTVAL get_integer_keyed(PMC *key)>
267
268 Returns the integer value of the element at index C<*key>.
269
270 =cut
271
272 */
273
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
274 VTABLE INTVAL get_integer_keyed(PMC *key) {
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored
275 /* simple int keys only */
a35f6fd @petdance consting & localizing
petdance authored
276 const INTVAL k = key_integer(INTERP, key);
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
277 return SELF.get_integer_keyed_int(k);
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored
278 }
279
280
281 /*
282
283 =item C<FLOATVAL get_number_keyed_int(INTVAL key)>
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_int(INTVAL key) {
292 const INTVAL i = SELF.get_integer_keyed_int(key);
8275ff5 @chromatic [PMC] Fixed a couple of casting warnings of function return values.
chromatic authored
293 return (FLOATVAL)i;
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored
294 }
295
296 /*
297
95e3676 @Infinoid [pmc] PDD07-ize function signatures in src/pmc/[b-f]*.pmc
Infinoid authored
298 =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
299
300 Returns the floating-point 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 FLOATVAL get_number_keyed(PMC *key) {
a35f6fd @petdance consting & localizing
petdance authored
307 const INTVAL k = key_integer(INTERP, key);
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
308 return SELF.get_number_keyed_int(k);
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored
309 }
310
311 /*
312
313 =item C<STRING *get_string_keyed_int(INTVAL key)>
314
315 Returns the Parrot string value of the element at index 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_string_keyed_int(INTVAL key) {
322 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
323 return VTABLE_get_string(INTERP, temp);
324 }
bf41b66 @particle [PDD07]: ws cleanup in src/, src/dynpmc/, and src/pmc/
particle authored
325
5a67dac @tewk Add get_repr to fixedintegerarray and integer
tewk authored
326 /*
327
328 =item C<STRING *get_repr()>
329
330 Returns the Parrot string representation C<key>.
331
332 =cut
333
334 */
335
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
336 VTABLE STRING *get_repr() {
a35f6fd @petdance consting & localizing
petdance authored
337 STRING *res = CONST_STRING(INTERP, "[ ");
8e04ace @NotFound exchange roles of elements and get_integer in FixedIntegerArray
NotFound authored
338 const INTVAL n = SELF.get_integer();
894d448 @chromatic [PMC] Minor cleanups and tidyings.
chromatic authored
339 INTVAL j;
5a67dac @tewk Add get_repr to fixedintegerarray and integer
tewk authored
340
341 for (j = 0; j < n; ++j) {
a35f6fd @petdance consting & localizing
petdance authored
342 PMC * const val = SELF.get_pmc_keyed_int(j);
b6bc0c3 @allisonrandal [pdd28str] Merging the pdd27mmd branch into trunk for r36123 to r36318.
allisonrandal authored
343 res = Parrot_str_append(INTERP, res, VTABLE_get_repr(INTERP, val));
894d448 @chromatic [PMC] Minor cleanups and tidyings.
chromatic authored
344
5a67dac @tewk Add get_repr to fixedintegerarray and integer
tewk authored
345 if (j < n - 1)
b6bc0c3 @allisonrandal [pdd28str] Merging the pdd27mmd branch into trunk for r36123 to r36318.
allisonrandal authored
346 res = Parrot_str_append(INTERP, res, CONST_STRING(INTERP, ", "));
5a67dac @tewk Add get_repr to fixedintegerarray and integer
tewk authored
347 }
894d448 @chromatic [PMC] Minor cleanups and tidyings.
chromatic authored
348
b6bc0c3 @allisonrandal [pdd28str] Merging the pdd27mmd branch into trunk for r36123 to r36318.
allisonrandal authored
349 res = Parrot_str_append(INTERP, res, CONST_STRING(INTERP, " ]"));
5a67dac @tewk Add get_repr to fixedintegerarray and integer
tewk authored
350 return res;
351 }
352
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored
353
354 /*
355
356 =item C<STRING *get_string_keyed(PMC *key)>
357
358 Returns the Parrot string value of the element at index C<*key>.
359
360 =cut
361
362 */
363
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
364 VTABLE STRING *get_string_keyed(PMC *key) {
a35f6fd @petdance consting & localizing
petdance authored
365 const INTVAL k = key_integer(INTERP, key);
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
366 return SELF.get_string_keyed_int(k);
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored
367 }
368
369
370 /*
371
372 =item C<PMC *get_pmc_keyed_int(INTVAL key)>
373
374 Returns the PMC value of the element at index C<key>.
375
376 =cut
377
378 */
379
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
380 VTABLE PMC *get_pmc_keyed_int(INTVAL key) {
a35f6fd @petdance consting & localizing
petdance authored
381 PMC * const ret = pmc_new(INTERP, enum_class_Integer);
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
382 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
383 VTABLE_set_integer_native(INTERP, ret, val);
384 return ret;
385 }
386
387 /*
388
389 =item C<PMC *get_pmc_keyed(PMC *key)>
390
391 Returns the PMC value of the element at index C<*key>.
392
393 =cut
394
395 */
396
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
397 VTABLE PMC *get_pmc_keyed(PMC *key) {
a35f6fd @petdance consting & localizing
petdance authored
398 const INTVAL k = key_integer(INTERP, key);
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
399 return SELF.get_pmc_keyed_int(k);
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored
400 }
401
402 /*
403
404 =item C<void set_integer_native(INTVAL size)>
405
406 Resizes the array to C<size> elements.
407
408 =cut
409
410 */
411
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
412 VTABLE void set_integer_native(INTVAL size) {
e5dead2 @cotto [pmc] update *IntegerArray to use ATTRs
cotto authored
413 INTVAL *int_array;
414 if (SELF.elements() || size < 1)
2255840 @allisonrandal [pdd17pmc] Merging the pdd25cx branch into trunk for r26555 to r29949.
allisonrandal authored
415 Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_OUT_OF_BOUNDS,
d1f7c98 JIT/i386 ord_i_s*
Leopold Toetsch authored
416 "FixedIntegerArray: Can't resize!");
2255840 @allisonrandal [pdd17pmc] Merging the pdd25cx branch into trunk for r26555 to r29949.
allisonrandal authored
417
e5dead2 @cotto [pmc] update *IntegerArray to use ATTRs
cotto authored
418 SET_ATTR_size(INTERP, SELF, size);
419 GET_ATTR_int_array(INTERP, SELF, int_array);
7a96a21 @bschmalhofer [codingstd] tabs.t and trailing_space.t
bschmalhofer authored
420 SET_ATTR_int_array(INTERP, SELF,
d923b9f @cotto [pmc] remove SIG_x macros, mostly fix t/examples/shootout.t
cotto authored
421 mem_realloc_n_typed(int_array, size, INTVAL));
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored
422 PObj_active_destroy_SET(SELF);
423 }
424
425 /*
426
427 =item C<void set_integer_keyed_int(INTVAL key, INTVAL value)>
428
429 Sets the integer value of the element at index C<key> to C<value>.
430
431 =cut
432
433 */
434
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
435 VTABLE void set_integer_keyed_int(INTVAL key, INTVAL value) {
e5dead2 @cotto [pmc] update *IntegerArray to use ATTRs
cotto authored
436 INTVAL *int_array;
894d448 @chromatic [PMC] Minor cleanups and tidyings.
chromatic authored
437
e5dead2 @cotto [pmc] update *IntegerArray to use ATTRs
cotto authored
438 if (key < 0 || key >= SELF.elements())
2255840 @allisonrandal [pdd17pmc] Merging the pdd25cx branch into trunk for r26555 to r29949.
allisonrandal authored
439 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
440 "FixedIntegerArray: index out of bounds!");
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored
441
e5dead2 @cotto [pmc] update *IntegerArray to use ATTRs
cotto authored
442 GET_ATTR_int_array(INTERP, SELF, int_array);
443 int_array[key] = value;
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored
444 }
445
446 /*
447
448 =item C<void set_integer_keyed(PMC *key, INTVAL value)>
449
450 Sets the integer value of the element at index C<key> to C<value>.
451
452 =cut
453
454 */
455
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
456 VTABLE void set_integer_keyed(PMC *key, INTVAL value) {
a35f6fd @petdance consting & localizing
petdance authored
457 const INTVAL k = key_integer(INTERP, key);
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
458 SELF.set_integer_keyed_int(k, value);
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored
459 }
460
461 /*
462
463 =item C<void set_number_keyed_int(INTVAL key, FLOATVAL value)>
464
894d448 @chromatic [PMC] Minor cleanups and tidyings.
chromatic authored
465 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
466
467 =cut
468
469 */
470
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
471 VTABLE void set_number_keyed_int(INTVAL key, FLOATVAL value) {
472 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
473 }
474
475 /*
476
477 =item C<void set_number_keyed(PMC *key, FLOATVAL value)>
478
894d448 @chromatic [PMC] Minor cleanups and tidyings.
chromatic authored
479 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
480
481 =cut
482
483 */
484
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
485 VTABLE void set_number_keyed(PMC *key, FLOATVAL value) {
a35f6fd @petdance consting & localizing
petdance authored
486 const INTVAL k = key_integer(INTERP, key);
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
487 SELF.set_number_keyed_int(k, value);
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored
488 }
d1f7c98 JIT/i386 ord_i_s*
Leopold Toetsch authored
489
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored
490 /*
491
492 =item C<void set_string_keyed_int(INTVAL key, STRING *value)>
493
494 Sets the Parrot string value of the element at index C<key> to C<value>.
495
496 =cut
497
498 */
499
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
500 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
501 INTVAL tempInt;
e5dead2 @cotto [pmc] update *IntegerArray to use ATTRs
cotto authored
502 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
503 VTABLE_set_string_native(INTERP, tempPMC, value);
894d448 @chromatic [PMC] Minor cleanups and tidyings.
chromatic authored
504 tempInt = VTABLE_get_integer(INTERP, tempPMC);
4e87173 @chromatic [PMC] Fixed a potential memory leak when resizing a FixedIntegerArray.
chromatic authored
505 temporary_pmc_free(interp, tempPMC);
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
506 SELF.set_integer_keyed_int(key, tempInt);
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored
507 }
508
509 /*
510
95e3676 @Infinoid [pmc] PDD07-ize function signatures in src/pmc/[b-f]*.pmc
Infinoid authored
511 =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
512
894d448 @chromatic [PMC] Minor cleanups and tidyings.
chromatic authored
513 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
514
515 =cut
516
517 */
518
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
519 VTABLE void set_string_keyed(PMC *key, STRING *value) {
a35f6fd @petdance consting & localizing
petdance authored
520 const INTVAL k = key_integer(INTERP, key);
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
521 SELF.set_string_keyed_int(k, value);
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored
522 }
523
524 /*
525
526 =item C<void set_pmc_keyed_int(INTVAL key, PMC *src)>
527
528 Sets the PMC value of the element at index C<key> to C<*src>.
529
530 =cut
531
532 */
533
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
534 VTABLE void set_pmc_keyed_int(INTVAL key, PMC *src) {
a35f6fd @petdance consting & localizing
petdance authored
535 const INTVAL tempInt = VTABLE_get_integer(INTERP, src);
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
536 SELF.set_integer_keyed_int(key, tempInt);
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored
537 }
538
539 /*
540
95e3676 @Infinoid [pmc] PDD07-ize function signatures in src/pmc/[b-f]*.pmc
Infinoid authored
541 =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
542
894d448 @chromatic [PMC] Minor cleanups and tidyings.
chromatic authored
543 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
544
545 =cut
546
547 */
548
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
549 VTABLE void set_pmc_keyed(PMC *key, PMC *value) {
a35f6fd @petdance consting & localizing
petdance authored
550 const INTVAL k = key_integer(INTERP, key);
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
551 SELF.set_pmc_keyed_int(k, value);
552 }
553
554 METHOD sort(PMC *cmp_func) {
e5dead2 @cotto [pmc] update *IntegerArray to use ATTRs
cotto authored
555 INTVAL *int_array;
556 UINTVAL n = (UINTVAL)SELF.elements();
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
557
e5dead2 @cotto [pmc] update *IntegerArray to use ATTRs
cotto authored
558 if (n > 1) {
559 GET_ATTR_int_array(INTERP, SELF, int_array);
560 Parrot_quicksort(interp, (void**)int_array, n, cmp_func);
561 }
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored
562 }
563
6287ae3 add missing fixedintegerarray.freeze and .thaw
Leopold Toetsch authored
564 /*
565
bd8aacd @cotto [PMC] add get_iter VTABLE function and tests to *IntegerArray
cotto authored
566 =item C<PMC *get_iter()>
567
568 Return a new Iterator for this PMC.
569
570 =cut
571
572 */
573
574
575 VTABLE PMC *get_iter() {
576 STRING *name = CONST_STRING(interp, "set_key");
577 PMC * const iter = pmc_new_init(INTERP, enum_class_Iterator, SELF);
578 PMC * const key = pmc_new(INTERP, enum_class_Key);
579
580 Parrot_PCCINVOKE(interp, iter, name, "P->", key);
581 PObj_get_FLAGS(key) |= KEY_integer_FLAG;
582
583 if (SELF.get_integer() == 0)
584 VTABLE_set_integer_native(INTERP, key, -1);
585 else
586 VTABLE_set_integer_native(INTERP, key, 0);
587
588 return iter;
589 }
590
591 /*
592
6287ae3 add missing fixedintegerarray.freeze and .thaw
Leopold Toetsch authored
593 =item C<void visit(visit_info *info)>
594
595 This is used by freeze/thaw to visit the contents of the array.
596
597 C<*info> is the visit info, (see F<include/parrot/pmc_freeze.h>).
598
599 =item C<void freeze(visit_info *info)>
600
601 Used to archive the array.
602
603 =item C<void thaw(visit_info *info)>
604
605 Used to unarchive the array.
606
607 =cut
608
609 */
610
e5dead2 @cotto [pmc] update *IntegerArray to use ATTRs
cotto authored
611 /*VTABLE void visit(visit_info *info) {
6287ae3 add missing fixedintegerarray.freeze and .thaw
Leopold Toetsch authored
612 SUPER(info);
e5dead2 @cotto [pmc] update *IntegerArray to use ATTRs
cotto authored
613 }*/
6287ae3 add missing fixedintegerarray.freeze and .thaw
Leopold Toetsch authored
614
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
615 VTABLE void freeze(visit_info *info) {
6287ae3 add missing fixedintegerarray.freeze and .thaw
Leopold Toetsch authored
616 IMAGE_IO *io = info->image_io;
e5dead2 @cotto [pmc] update *IntegerArray to use ATTRs
cotto authored
617 INTVAL *int_array;
894d448 @chromatic [PMC] Minor cleanups and tidyings.
chromatic authored
618 INTVAL i, n;
6287ae3 add missing fixedintegerarray.freeze and .thaw
Leopold Toetsch authored
619
620 SUPER(info);
894d448 @chromatic [PMC] Minor cleanups and tidyings.
chromatic authored
621
8e04ace @NotFound exchange roles of elements and get_integer in FixedIntegerArray
NotFound authored
622 n = SELF.get_integer();
297024c @paultcochrane [pmc] Changed instances of io->vtable->whatever() to VTABLE_whatever(…
paultcochrane authored
623 VTABLE_push_integer(INTERP, io, n);
e5dead2 @cotto [pmc] update *IntegerArray to use ATTRs
cotto authored
624 GET_ATTR_int_array(INTERP, SELF, int_array);
894d448 @chromatic [PMC] Minor cleanups and tidyings.
chromatic authored
625
626 for (i = 0; i < n; ++i)
e5dead2 @cotto [pmc] update *IntegerArray to use ATTRs
cotto authored
627 VTABLE_push_integer(INTERP, io, int_array[i]);
6287ae3 add missing fixedintegerarray.freeze and .thaw
Leopold Toetsch authored
628 }
629
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
630 VTABLE void thaw(visit_info *info) {
6287ae3 add missing fixedintegerarray.freeze and .thaw
Leopold Toetsch authored
631
e5dead2 @cotto [pmc] update *IntegerArray to use ATTRs
cotto authored
632 Parrot_FixedIntegerArray_attributes *attrs =
633 mem_allocate_zeroed_typed(Parrot_FixedIntegerArray_attributes);
634 PMC_data(SELF) = attrs;
635
6287ae3 add missing fixedintegerarray.freeze and .thaw
Leopold Toetsch authored
636 if (info->extra_flags == EXTRA_IS_NULL) {
a35f6fd @petdance consting & localizing
petdance authored
637 IMAGE_IO * const io = info->image_io;
638 const INTVAL n = VTABLE_shift_integer(INTERP, io);
894d448 @chromatic [PMC] Minor cleanups and tidyings.
chromatic authored
639
e5dead2 @cotto [pmc] update *IntegerArray to use ATTRs
cotto authored
640 SET_ATTR_size(INTERP, SELF, 0);
641 SET_ATTR_int_array(INTERP, SELF, NULL);
894d448 @chromatic [PMC] Minor cleanups and tidyings.
chromatic authored
642
a35f6fd @petdance consting & localizing
petdance authored
643 if (n) {
644 INTVAL i;
e5dead2 @cotto [pmc] update *IntegerArray to use ATTRs
cotto authored
645 INTVAL *int_array;
894d448 @chromatic [PMC] Minor cleanups and tidyings.
chromatic authored
646
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
647 SELF.set_integer_native(n);
e5dead2 @cotto [pmc] update *IntegerArray to use ATTRs
cotto authored
648 GET_ATTR_int_array(INTERP, SELF, int_array);
894d448 @chromatic [PMC] Minor cleanups and tidyings.
chromatic authored
649
a35f6fd @petdance consting & localizing
petdance authored
650 for (i = 0; i < n; ++i)
e5dead2 @cotto [pmc] update *IntegerArray to use ATTRs
cotto authored
651 int_array[i] = VTABLE_shift_integer(INTERP, io);
a35f6fd @petdance consting & localizing
petdance authored
652 }
6287ae3 add missing fixedintegerarray.freeze and .thaw
Leopold Toetsch authored
653 }
654 else
655 SUPER(info);
656 }
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored
657 }
658
659 /*
660
661 =back
662
663 =head1 SEE ALSO
664
1e8a4ab this patch adds some relevant 'push' ops to the resizable PMCs, descr…
Dan Sugalski authored
665 F<docs/pdds/pdd17_basic_types.pod>.
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored
666
667 =cut
668
669 */
670
671 /*
672 * Local variables:
72575ae @bschmalhofer #40481: [PATCH] C-code coda in pmc files
bschmalhofer authored
673 * c-file-style: "parrot"
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored
674 * End:
675 * vim: expandtab shiftwidth=4:
72575ae @bschmalhofer #40481: [PATCH] C-code coda in pmc files
bschmalhofer authored
676 */
Something went wrong with that request. Please try again.