Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 706 lines (466 sloc) 15.286 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);
8d33429 @chromatic [PMC] Replaced vtable function calls to find size of fixed integer ar…
chromatic authored
187
e5dead2 @cotto [pmc] update *IntegerArray to use ATTRs
cotto authored
188 if (int_array) {
189 INTVAL *dest_int_array;
8d33429 @chromatic [PMC] Replaced vtable function calls to find size of fixed integer ar…
chromatic authored
190 INTVAL size;
191
192 GET_ATTR_size(INTERP, SELF, size);
193
e5dead2 @cotto [pmc] update *IntegerArray to use ATTRs
cotto authored
194 dest_int_array = mem_allocate_n_typed(size, INTVAL);
195 SET_ATTR_size(INTERP, dest, size);
196 SET_ATTR_int_array(INTERP, dest, dest_int_array);
d1f7c98 JIT/i386 ord_i_s*
Leopold Toetsch authored
197
e5dead2 @cotto [pmc] update *IntegerArray to use ATTRs
cotto authored
198 mem_sys_memcopy(dest_int_array, int_array, size * sizeof (INTVAL));
a35f6fd @petdance consting & localizing
petdance authored
199 PObj_active_destroy_SET(dest);
200 }
894d448 @chromatic [PMC] Minor cleanups and tidyings.
chromatic authored
201
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored
202 return dest;
203 }
204
205 /*
206
207 =item C<INTVAL get_bool()>
208
209 Returns whether the array has any elements (meaning been initialized, for a
210 fixed sized array).
211
212 =cut
213
214 */
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
215 VTABLE INTVAL get_bool() {
8d33429 @chromatic [PMC] Replaced vtable function calls to find size of fixed integer ar…
chromatic authored
216 INTVAL size;
217 GET_ATTR_size(INTERP, SELF, size);
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored
218 return (INTVAL)(size != 0);
219 }
220
221 /*
222
223 =item C<INTVAL elements()>
224
225 =cut
226
227 */
228
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
229 VTABLE INTVAL elements() {
8d33429 @chromatic [PMC] Replaced vtable function calls to find size of fixed integer ar…
chromatic authored
230 INTVAL size;
231 GET_ATTR_size(INTERP, SELF, size);
232
233 return size;
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored
234 }
235
236 /*
237
238 =item C<INTVAL get_integer()>
239
240 Returns the number of elements in the array.
241
242 =cut
243
244 */
245
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
246 VTABLE INTVAL get_integer() {
8d33429 @chromatic [PMC] Replaced vtable function calls to find size of fixed integer ar…
chromatic authored
247 INTVAL size;
248 GET_ATTR_size(INTERP, SELF, size);
249 return size;
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored
250 }
251
252
253 /*
254
255 =item C<INTVAL get_integer_keyed_int(INTVAL key)>
256
257 Returns the integer value of the element at index C<key>.
258
259 =cut
260
261 */
262
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
263 VTABLE INTVAL get_integer_keyed_int(INTVAL key) {
e5dead2 @cotto [pmc] update *IntegerArray to use ATTRs
cotto authored
264 INTVAL *int_array;
8d33429 @chromatic [PMC] Replaced vtable function calls to find size of fixed integer ar…
chromatic authored
265 INTVAL size;
894d448 @chromatic [PMC] Minor cleanups and tidyings.
chromatic authored
266
8d33429 @chromatic [PMC] Replaced vtable function calls to find size of fixed integer ar…
chromatic authored
267 GET_ATTR_size(INTERP, SELF, size);
268
269 if (key < 0 || key >= size)
2255840 @allisonrandal [pdd17pmc] Merging the pdd25cx branch into trunk for r26555 to r29949.
allisonrandal authored
270 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
271 "FixedIntegerArray: index out of bounds!");
d1f7c98 JIT/i386 ord_i_s*
Leopold Toetsch authored
272
e5dead2 @cotto [pmc] update *IntegerArray to use ATTRs
cotto authored
273 GET_ATTR_int_array(INTERP, SELF, int_array);
274 return int_array[key];
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored
275 }
276
277 /*
278
279 =item C<INTVAL get_integer_keyed(PMC *key)>
280
281 Returns the integer value of the element at index C<*key>.
282
283 =cut
284
285 */
286
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
287 VTABLE INTVAL get_integer_keyed(PMC *key) {
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored
288 /* simple int keys only */
757f3a8 @chromatic [PMC] Replaced all uses of key_integer() outside of Key PMC and src/k…
chromatic authored
289 const INTVAL k = VTABLE_get_integer(INTERP, key);
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
290 return SELF.get_integer_keyed_int(k);
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored
291 }
292
293
294 /*
295
296 =item C<FLOATVAL get_number_keyed_int(INTVAL key)>
297
298 Returns the floating-point value of the element at index C<key>.
299
300 =cut
301
302 */
303
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
304 VTABLE FLOATVAL get_number_keyed_int(INTVAL key) {
305 const INTVAL i = SELF.get_integer_keyed_int(key);
8275ff5 @chromatic [PMC] Fixed a couple of casting warnings of function return values.
chromatic authored
306 return (FLOATVAL)i;
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored
307 }
308
309 /*
310
95e3676 @Infinoid [pmc] PDD07-ize function signatures in src/pmc/[b-f]*.pmc
Infinoid authored
311 =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
312
313 Returns the floating-point value of the element at index C<*key>.
314
315 =cut
316
317 */
318
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
319 VTABLE FLOATVAL get_number_keyed(PMC *key) {
757f3a8 @chromatic [PMC] Replaced all uses of key_integer() outside of Key PMC and src/k…
chromatic authored
320 const INTVAL k = VTABLE_get_integer(INTERP, key);
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
321 return SELF.get_number_keyed_int(k);
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored
322 }
323
324 /*
325
326 =item C<STRING *get_string_keyed_int(INTVAL key)>
327
328 Returns the Parrot string value of the element at index C<key>.
329
330 =cut
331
332 */
333
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
334 VTABLE STRING *get_string_keyed_int(INTVAL key) {
335 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
336 return VTABLE_get_string(INTERP, temp);
337 }
bf41b66 @particle [PDD07]: ws cleanup in src/, src/dynpmc/, and src/pmc/
particle authored
338
5a67dac @tewk Add get_repr to fixedintegerarray and integer
tewk authored
339 /*
340
341 =item C<STRING *get_repr()>
342
343 Returns the Parrot string representation 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_repr() {
a35f6fd @petdance consting & localizing
petdance authored
350 STRING *res = CONST_STRING(INTERP, "[ ");
8d33429 @chromatic [PMC] Replaced vtable function calls to find size of fixed integer ar…
chromatic authored
351 INTVAL n;
894d448 @chromatic [PMC] Minor cleanups and tidyings.
chromatic authored
352 INTVAL j;
5a67dac @tewk Add get_repr to fixedintegerarray and integer
tewk authored
353
8d33429 @chromatic [PMC] Replaced vtable function calls to find size of fixed integer ar…
chromatic authored
354 GET_ATTR_size(INTERP, SELF, n);
355
5a67dac @tewk Add get_repr to fixedintegerarray and integer
tewk authored
356 for (j = 0; j < n; ++j) {
a35f6fd @petdance consting & localizing
petdance authored
357 PMC * const val = SELF.get_pmc_keyed_int(j);
b6bc0c3 @allisonrandal [pdd28str] Merging the pdd27mmd branch into trunk for r36123 to r36318.
allisonrandal authored
358 res = Parrot_str_append(INTERP, res, VTABLE_get_repr(INTERP, val));
894d448 @chromatic [PMC] Minor cleanups and tidyings.
chromatic authored
359
5a67dac @tewk Add get_repr to fixedintegerarray and integer
tewk authored
360 if (j < n - 1)
b6bc0c3 @allisonrandal [pdd28str] Merging the pdd27mmd branch into trunk for r36123 to r36318.
allisonrandal authored
361 res = Parrot_str_append(INTERP, res, CONST_STRING(INTERP, ", "));
5a67dac @tewk Add get_repr to fixedintegerarray and integer
tewk authored
362 }
894d448 @chromatic [PMC] Minor cleanups and tidyings.
chromatic authored
363
b6bc0c3 @allisonrandal [pdd28str] Merging the pdd27mmd branch into trunk for r36123 to r36318.
allisonrandal authored
364 res = Parrot_str_append(INTERP, res, CONST_STRING(INTERP, " ]"));
5a67dac @tewk Add get_repr to fixedintegerarray and integer
tewk authored
365 return res;
366 }
367
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored
368
369 /*
370
371 =item C<STRING *get_string_keyed(PMC *key)>
372
373 Returns the Parrot string value of the element at index C<*key>.
374
375 =cut
376
377 */
378
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
379 VTABLE STRING *get_string_keyed(PMC *key) {
757f3a8 @chromatic [PMC] Replaced all uses of key_integer() outside of Key PMC and src/k…
chromatic authored
380 const INTVAL k = VTABLE_get_integer(INTERP, key);
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
381 return SELF.get_string_keyed_int(k);
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored
382 }
383
384
385 /*
386
387 =item C<PMC *get_pmc_keyed_int(INTVAL key)>
388
389 Returns the PMC value of the element at index C<key>.
390
391 =cut
392
393 */
394
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
395 VTABLE PMC *get_pmc_keyed_int(INTVAL key) {
a35f6fd @petdance consting & localizing
petdance authored
396 PMC * const ret = pmc_new(INTERP, enum_class_Integer);
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
397 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
398 VTABLE_set_integer_native(INTERP, ret, val);
399 return ret;
400 }
401
402 /*
403
404 =item C<PMC *get_pmc_keyed(PMC *key)>
405
406 Returns the PMC value of the element at index C<*key>.
407
408 =cut
409
410 */
411
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
412 VTABLE PMC *get_pmc_keyed(PMC *key) {
757f3a8 @chromatic [PMC] Replaced all uses of key_integer() outside of Key PMC and src/k…
chromatic authored
413 const INTVAL k = VTABLE_get_integer(INTERP, key);
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
414 return SELF.get_pmc_keyed_int(k);
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored
415 }
416
417 /*
418
419 =item C<void set_integer_native(INTVAL size)>
420
421 Resizes the array to C<size> elements.
422
423 =cut
424
425 */
426
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
427 VTABLE void set_integer_native(INTVAL size) {
e5dead2 @cotto [pmc] update *IntegerArray to use ATTRs
cotto authored
428 INTVAL *int_array;
8d33429 @chromatic [PMC] Replaced vtable function calls to find size of fixed integer ar…
chromatic authored
429 INTVAL cur_size;
430
431 GET_ATTR_size(INTERP, SELF, cur_size);
432
433 if (cur_size || size < 1)
2255840 @allisonrandal [pdd17pmc] Merging the pdd25cx branch into trunk for r26555 to r29949.
allisonrandal authored
434 Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_OUT_OF_BOUNDS,
d1f7c98 JIT/i386 ord_i_s*
Leopold Toetsch authored
435 "FixedIntegerArray: Can't resize!");
2255840 @allisonrandal [pdd17pmc] Merging the pdd25cx branch into trunk for r26555 to r29949.
allisonrandal authored
436
e5dead2 @cotto [pmc] update *IntegerArray to use ATTRs
cotto authored
437 SET_ATTR_size(INTERP, SELF, size);
438 GET_ATTR_int_array(INTERP, SELF, int_array);
7a96a21 @bschmalhofer [codingstd] tabs.t and trailing_space.t
bschmalhofer authored
439 SET_ATTR_int_array(INTERP, SELF,
d923b9f @cotto [pmc] remove SIG_x macros, mostly fix t/examples/shootout.t
cotto authored
440 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
441 PObj_active_destroy_SET(SELF);
442 }
443
444 /*
445
446 =item C<void set_integer_keyed_int(INTVAL key, INTVAL value)>
447
448 Sets the integer value of the element at index C<key> to C<value>.
449
450 =cut
451
452 */
453
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
454 VTABLE void set_integer_keyed_int(INTVAL key, INTVAL value) {
e5dead2 @cotto [pmc] update *IntegerArray to use ATTRs
cotto authored
455 INTVAL *int_array;
8d33429 @chromatic [PMC] Replaced vtable function calls to find size of fixed integer ar…
chromatic authored
456 INTVAL size;
894d448 @chromatic [PMC] Minor cleanups and tidyings.
chromatic authored
457
8d33429 @chromatic [PMC] Replaced vtable function calls to find size of fixed integer ar…
chromatic authored
458 GET_ATTR_size(INTERP, SELF, size);
459
460 if (key < 0 || key >= size)
2255840 @allisonrandal [pdd17pmc] Merging the pdd25cx branch into trunk for r26555 to r29949.
allisonrandal authored
461 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
462 "FixedIntegerArray: index out of bounds!");
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored
463
e5dead2 @cotto [pmc] update *IntegerArray to use ATTRs
cotto authored
464 GET_ATTR_int_array(INTERP, SELF, int_array);
465 int_array[key] = value;
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored
466 }
467
468 /*
469
470 =item C<void set_integer_keyed(PMC *key, INTVAL value)>
471
472 Sets the integer value of the element at index C<key> to C<value>.
473
474 =cut
475
476 */
477
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
478 VTABLE void set_integer_keyed(PMC *key, INTVAL value) {
757f3a8 @chromatic [PMC] Replaced all uses of key_integer() outside of Key PMC and src/k…
chromatic authored
479 const INTVAL k = VTABLE_get_integer(INTERP, key);
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
480 SELF.set_integer_keyed_int(k, value);
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored
481 }
482
483 /*
484
485 =item C<void set_number_keyed_int(INTVAL key, FLOATVAL value)>
486
894d448 @chromatic [PMC] Minor cleanups and tidyings.
chromatic authored
487 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
488
489 =cut
490
491 */
492
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
493 VTABLE void set_number_keyed_int(INTVAL key, FLOATVAL value) {
494 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
495 }
496
497 /*
498
499 =item C<void set_number_keyed(PMC *key, FLOATVAL value)>
500
894d448 @chromatic [PMC] Minor cleanups and tidyings.
chromatic authored
501 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
502
503 =cut
504
505 */
506
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
507 VTABLE void set_number_keyed(PMC *key, FLOATVAL value) {
757f3a8 @chromatic [PMC] Replaced all uses of key_integer() outside of Key PMC and src/k…
chromatic authored
508 const INTVAL k = VTABLE_get_integer(INTERP, key);
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
509 SELF.set_number_keyed_int(k, value);
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored
510 }
d1f7c98 JIT/i386 ord_i_s*
Leopold Toetsch authored
511
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored
512 /*
513
514 =item C<void set_string_keyed_int(INTVAL key, STRING *value)>
515
516 Sets the Parrot string value of the element at index C<key> to C<value>.
517
518 =cut
519
520 */
521
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
522 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
523 INTVAL tempInt;
e5dead2 @cotto [pmc] update *IntegerArray to use ATTRs
cotto authored
524 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
525 VTABLE_set_string_native(INTERP, tempPMC, value);
894d448 @chromatic [PMC] Minor cleanups and tidyings.
chromatic authored
526 tempInt = VTABLE_get_integer(INTERP, tempPMC);
4e87173 @chromatic [PMC] Fixed a potential memory leak when resizing a FixedIntegerArray.
chromatic authored
527 temporary_pmc_free(interp, tempPMC);
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
528 SELF.set_integer_keyed_int(key, tempInt);
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored
529 }
530
531 /*
532
95e3676 @Infinoid [pmc] PDD07-ize function signatures in src/pmc/[b-f]*.pmc
Infinoid authored
533 =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
534
894d448 @chromatic [PMC] Minor cleanups and tidyings.
chromatic authored
535 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
536
537 =cut
538
539 */
540
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
541 VTABLE void set_string_keyed(PMC *key, STRING *value) {
757f3a8 @chromatic [PMC] Replaced all uses of key_integer() outside of Key PMC and src/k…
chromatic authored
542 const INTVAL k = VTABLE_get_integer(INTERP, key);
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
543 SELF.set_string_keyed_int(k, value);
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored
544 }
545
546 /*
547
548 =item C<void set_pmc_keyed_int(INTVAL key, PMC *src)>
549
550 Sets the PMC value of the element at index C<key> to C<*src>.
551
552 =cut
553
554 */
555
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
556 VTABLE void set_pmc_keyed_int(INTVAL key, PMC *src) {
a35f6fd @petdance consting & localizing
petdance authored
557 const INTVAL tempInt = VTABLE_get_integer(INTERP, src);
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
558 SELF.set_integer_keyed_int(key, tempInt);
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored
559 }
560
561 /*
562
95e3676 @Infinoid [pmc] PDD07-ize function signatures in src/pmc/[b-f]*.pmc
Infinoid authored
563 =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
564
894d448 @chromatic [PMC] Minor cleanups and tidyings.
chromatic authored
565 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
566
567 =cut
568
569 */
570
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
571 VTABLE void set_pmc_keyed(PMC *key, PMC *value) {
757f3a8 @chromatic [PMC] Replaced all uses of key_integer() outside of Key PMC and src/k…
chromatic authored
572 const INTVAL k = VTABLE_get_integer(INTERP, key);
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
573 SELF.set_pmc_keyed_int(k, value);
574 }
575
576 METHOD sort(PMC *cmp_func) {
e5dead2 @cotto [pmc] update *IntegerArray to use ATTRs
cotto authored
577 INTVAL *int_array;
8d33429 @chromatic [PMC] Replaced vtable function calls to find size of fixed integer ar…
chromatic authored
578 UINTVAL n;
579 INTVAL size;
580
581 GET_ATTR_size(INTERP, SELF, size);
582
583 n = (UINTVAL)size;
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
584
e5dead2 @cotto [pmc] update *IntegerArray to use ATTRs
cotto authored
585 if (n > 1) {
586 GET_ATTR_int_array(INTERP, SELF, int_array);
587 Parrot_quicksort(interp, (void**)int_array, n, cmp_func);
588 }
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored
589 }
590
6287ae3 add missing fixedintegerarray.freeze and .thaw
Leopold Toetsch authored
591 /*
592
bd8aacd @cotto [PMC] add get_iter VTABLE function and tests to *IntegerArray
cotto authored
593 =item C<PMC *get_iter()>
594
595 Return a new Iterator for this PMC.
596
597 =cut
598
599 */
600
601 VTABLE PMC *get_iter() {
8d33429 @chromatic [PMC] Replaced vtable function calls to find size of fixed integer ar…
chromatic authored
602 STRING *name = CONST_STRING(interp, "set_key");
603 PMC * const iter = pmc_new_init(INTERP, enum_class_Iterator, SELF);
604 PMC * const key = pmc_new(INTERP, enum_class_Key);
605 INTVAL size;
bd8aacd @cotto [PMC] add get_iter VTABLE function and tests to *IntegerArray
cotto authored
606
607 Parrot_PCCINVOKE(interp, iter, name, "P->", key);
608 PObj_get_FLAGS(key) |= KEY_integer_FLAG;
609
8d33429 @chromatic [PMC] Replaced vtable function calls to find size of fixed integer ar…
chromatic authored
610 GET_ATTR_size(INTERP, SELF, size);
611
612 if (size)
bd8aacd @cotto [PMC] add get_iter VTABLE function and tests to *IntegerArray
cotto authored
613 VTABLE_set_integer_native(INTERP, key, 0);
8d33429 @chromatic [PMC] Replaced vtable function calls to find size of fixed integer ar…
chromatic authored
614 else
615 VTABLE_set_integer_native(INTERP, key, -1);
bd8aacd @cotto [PMC] add get_iter VTABLE function and tests to *IntegerArray
cotto authored
616
617 return iter;
618 }
619
620 /*
621
6287ae3 add missing fixedintegerarray.freeze and .thaw
Leopold Toetsch authored
622 =item C<void visit(visit_info *info)>
623
624 This is used by freeze/thaw to visit the contents of the array.
625
626 C<*info> is the visit info, (see F<include/parrot/pmc_freeze.h>).
627
628 =item C<void freeze(visit_info *info)>
629
630 Used to archive the array.
631
632 =item C<void thaw(visit_info *info)>
633
634 Used to unarchive the array.
635
636 =cut
637
638 */
639
e5dead2 @cotto [pmc] update *IntegerArray to use ATTRs
cotto authored
640 /*VTABLE void visit(visit_info *info) {
6287ae3 add missing fixedintegerarray.freeze and .thaw
Leopold Toetsch authored
641 SUPER(info);
e5dead2 @cotto [pmc] update *IntegerArray to use ATTRs
cotto authored
642 }*/
6287ae3 add missing fixedintegerarray.freeze and .thaw
Leopold Toetsch authored
643
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
644 VTABLE void freeze(visit_info *info) {
6287ae3 add missing fixedintegerarray.freeze and .thaw
Leopold Toetsch authored
645 IMAGE_IO *io = info->image_io;
e5dead2 @cotto [pmc] update *IntegerArray to use ATTRs
cotto authored
646 INTVAL *int_array;
894d448 @chromatic [PMC] Minor cleanups and tidyings.
chromatic authored
647 INTVAL i, n;
6287ae3 add missing fixedintegerarray.freeze and .thaw
Leopold Toetsch authored
648
649 SUPER(info);
894d448 @chromatic [PMC] Minor cleanups and tidyings.
chromatic authored
650
8d33429 @chromatic [PMC] Replaced vtable function calls to find size of fixed integer ar…
chromatic authored
651 GET_ATTR_size(INTERP, SELF, n);
297024c @paultcochrane [pmc] Changed instances of io->vtable->whatever() to VTABLE_whatever(…
paultcochrane authored
652 VTABLE_push_integer(INTERP, io, n);
e5dead2 @cotto [pmc] update *IntegerArray to use ATTRs
cotto authored
653 GET_ATTR_int_array(INTERP, SELF, int_array);
894d448 @chromatic [PMC] Minor cleanups and tidyings.
chromatic authored
654
655 for (i = 0; i < n; ++i)
e5dead2 @cotto [pmc] update *IntegerArray to use ATTRs
cotto authored
656 VTABLE_push_integer(INTERP, io, int_array[i]);
6287ae3 add missing fixedintegerarray.freeze and .thaw
Leopold Toetsch authored
657 }
658
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
659 VTABLE void thaw(visit_info *info) {
6287ae3 add missing fixedintegerarray.freeze and .thaw
Leopold Toetsch authored
660
e5dead2 @cotto [pmc] update *IntegerArray to use ATTRs
cotto authored
661 Parrot_FixedIntegerArray_attributes *attrs =
662 mem_allocate_zeroed_typed(Parrot_FixedIntegerArray_attributes);
663 PMC_data(SELF) = attrs;
664
6287ae3 add missing fixedintegerarray.freeze and .thaw
Leopold Toetsch authored
665 if (info->extra_flags == EXTRA_IS_NULL) {
a35f6fd @petdance consting & localizing
petdance authored
666 IMAGE_IO * const io = info->image_io;
667 const INTVAL n = VTABLE_shift_integer(INTERP, io);
894d448 @chromatic [PMC] Minor cleanups and tidyings.
chromatic authored
668
e5dead2 @cotto [pmc] update *IntegerArray to use ATTRs
cotto authored
669 SET_ATTR_size(INTERP, SELF, 0);
670 SET_ATTR_int_array(INTERP, SELF, NULL);
894d448 @chromatic [PMC] Minor cleanups and tidyings.
chromatic authored
671
a35f6fd @petdance consting & localizing
petdance authored
672 if (n) {
673 INTVAL i;
e5dead2 @cotto [pmc] update *IntegerArray to use ATTRs
cotto authored
674 INTVAL *int_array;
894d448 @chromatic [PMC] Minor cleanups and tidyings.
chromatic authored
675
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored
676 SELF.set_integer_native(n);
e5dead2 @cotto [pmc] update *IntegerArray to use ATTRs
cotto authored
677 GET_ATTR_int_array(INTERP, SELF, int_array);
894d448 @chromatic [PMC] Minor cleanups and tidyings.
chromatic authored
678
a35f6fd @petdance consting & localizing
petdance authored
679 for (i = 0; i < n; ++i)
e5dead2 @cotto [pmc] update *IntegerArray to use ATTRs
cotto authored
680 int_array[i] = VTABLE_shift_integer(INTERP, io);
a35f6fd @petdance consting & localizing
petdance authored
681 }
6287ae3 add missing fixedintegerarray.freeze and .thaw
Leopold Toetsch authored
682 }
683 else
684 SUPER(info);
685 }
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored
686 }
687
688 /*
689
690 =back
691
692 =head1 SEE ALSO
693
1e8a4ab this patch adds some relevant 'push' ops to the resizable PMCs, descr…
Dan Sugalski authored
694 F<docs/pdds/pdd17_basic_types.pod>.
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored
695
696 =cut
697
698 */
699
700 /*
701 * Local variables:
72575ae @bschmalhofer #40481: [PATCH] C-code coda in pmc files
bschmalhofer authored
702 * c-file-style: "parrot"
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored
703 * End:
704 * vim: expandtab shiftwidth=4:
72575ae @bschmalhofer #40481: [PATCH] C-code coda in pmc files
bschmalhofer authored
705 */
Something went wrong with that request. Please try again.