Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

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