Skip to content
Newer
Older
100644 684 lines (433 sloc) 13.3 KB
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored Jun 12, 2004
1 /*
3158c1c @mikehh fix codetest failure - there should be at least one space between a C…
mikehh authored Jun 10, 2010
2 Copyright (C) 2001-2010, Parrot Foundation.
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored Jun 12, 2004
3 $Id$
4
5 =head1 NAME
6
f474cd7 @bschmalhofer [perl #38235] Rename (dyn)?classes to (dyn)?pmc
bschmalhofer authored Jan 18, 2006
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 Jun 12, 2004
8
9 =head1 DESCRIPTION
10
894d448 @chromatic [PMC] Minor cleanups and tidyings.
chromatic authored Sep 4, 2007
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 Jun 12, 2004
13
14 =cut
15
16 */
17
6bdd5f9 @petdance headerizer now runs on PMC files
petdance authored Mar 28, 2010
18 /* HEADERIZER HFILE: none */
19 /* HEADERIZER BEGIN: static */
4927d8a @NotFound make FIA sort method half-usable
NotFound authored Jun 10, 2010
20 /* Don't modify between HEADERIZER BEGIN / HEADERIZER END. Your changes will be lost. */
21
f9cca7d @petdance consting and annotating
petdance authored Jun 30, 2010
22 PARROT_PURE_FUNCTION
23 static int auxcmpfunc(ARGIN(const INTVAL *i), ARGIN(const INTVAL *j))
24 __attribute__nonnull__(1)
25 __attribute__nonnull__(2);
26
27 #define ASSERT_ARGS_auxcmpfunc __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
28 PARROT_ASSERT_ARG(i) \
29 , PARROT_ASSERT_ARG(j))
4927d8a @NotFound make FIA sort method half-usable
NotFound authored Jun 10, 2010
30 /* Don't modify between HEADERIZER BEGIN / HEADERIZER END. Your changes will be lost. */
6bdd5f9 @petdance headerizer now runs on PMC files
petdance authored Mar 28, 2010
31 /* HEADERIZER END: static */
32
4927d8a @NotFound make FIA sort method half-usable
NotFound authored Jun 10, 2010
33
6b81760 @Whiteknight [pmc] we don't need need_ext anymore, so BALEETED
Whiteknight authored Aug 23, 2009
34 pmclass FixedIntegerArray auto_attrs provides array {
e5dead2 @cotto [pmc] update *IntegerArray to use ATTRs
cotto authored Jan 27, 2009
35 ATTR INTVAL size; /* number of INTVALs stored in this array */
36 ATTR INTVAL * int_array; /* INTVALs are stored here */
d1f7c98 JIT/i386 ord_i_s*
Leopold Toetsch authored Mar 22, 2005
37
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored Jun 12, 2004
38 /*
39
ac9988d @NotFound some cleaning of FIA: put METHOD after vtable functions and fix and i…
NotFound authored Aug 12, 2010
40 =head2 Vtable functions
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored Jun 12, 2004
41
42 =over 4
43
44 =item C<void init()>
45
46 Initializes the array.
47
48 =cut
49
50 */
51
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored Mar 11, 2008
52 VTABLE void init() {
4591dbb @chromatic [HLL] Fixed two compilation-breaking typos accidentally committed in …
chromatic authored Sep 3, 2009
53 PObj_custom_destroy_SET(SELF);
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored Jun 12, 2004
54 }
55
56 /*
57
714df2a @tewk VTABLE_init_int commented out tests
tewk authored Mar 10, 2010
58 =item C<void init_int(INTVAL size)>
59
60 Initializes the array.
61
62 =cut
63
64 */
65
66 VTABLE void init_int(INTVAL size) {
4d64842 @leto [t][TT#1509] Prevent core dumps by preventing negative length array c…
leto authored Mar 11, 2010
67 if (size < 0)
26914e1 changed interp in pmc class to INTERP for unification
Jimmy Zhuo authored May 5, 2010
68 Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_OUT_OF_BOUNDS,
4d64842 @leto [t][TT#1509] Prevent core dumps by preventing negative length array c…
leto authored Mar 11, 2010
69 _("FixedIntegerArray: Cannot set array size to a negative number (%d)"), size);
714df2a @tewk VTABLE_init_int commented out tests
tewk authored Mar 10, 2010
70 SET_ATTR_size(INTERP, SELF, size);
71 SET_ATTR_int_array(INTERP, SELF, mem_gc_allocate_n_typed(INTERP, size, INTVAL));
72 PObj_custom_destroy_SET(SELF);
73 }
74
75 /*
76
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored Jun 12, 2004
77 =item C<void destroy()>
78
79 Destroys the array.
80
81 =cut
82
83 */
84
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored Mar 11, 2008
85 VTABLE void destroy() {
e5dead2 @cotto [pmc] update *IntegerArray to use ATTRs
cotto authored Jan 27, 2009
86 INTVAL* int_array;
87 GET_ATTR_int_array(INTERP, SELF, int_array);
88 if (int_array)
4833868 @bacek Merge branch 'sys_mem' into trunk
bacek authored Feb 22, 2010
89 Parrot_gc_free_memory_chunk(INTERP, int_array);
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored Jun 12, 2004
90 }
91
92 /*
93
94 =item C<PMC *clone()>
95
96 Creates and returns a copy of the array.
97
98 =cut
99
100 */
101
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored Mar 11, 2008
102 VTABLE PMC *clone() {
9822a24 var_args 8 - verify signature during bytecode creation
Leopold Toetsch authored Jun 14, 2005
103 /* a quick hack to create a clone in the constant PMC arena
104 * this is needed for the call signatures
105 *
106 * a better way would be probably to supply a flag to the clone
107 * vtable
108 */
109
e5dead2 @cotto [pmc] update *IntegerArray to use ATTRs
cotto authored Jan 27, 2009
110 INTVAL * int_array;
111 PMC * const dest =
a35f6fd @petdance consting & localizing
petdance authored Feb 9, 2008
112 PObj_constant_TEST(SELF)
dc5a60b @Whiteknight finish the bulk of the conversions, parrot builds
Whiteknight authored Feb 16, 2010
113 ? Parrot_pmc_new_constant(INTERP, SELF->vtable->base_type)
083213a @Whiteknight start rename of pmc_new to Parrot_pmc_new
Whiteknight authored Feb 16, 2010
114 : Parrot_pmc_new(INTERP, SELF->vtable->base_type);
894d448 @chromatic [PMC] Minor cleanups and tidyings.
chromatic authored Sep 4, 2007
115
e5dead2 @cotto [pmc] update *IntegerArray to use ATTRs
cotto authored Jan 27, 2009
116 GET_ATTR_int_array(INTERP, SELF, int_array);
8d33429 @chromatic [PMC] Replaced vtable function calls to find size of fixed integer ar…
chromatic authored May 1, 2009
117
e5dead2 @cotto [pmc] update *IntegerArray to use ATTRs
cotto authored Jan 27, 2009
118 if (int_array) {
42f27d4 @NotFound clean FIA.clone
NotFound authored Apr 24, 2010
119 INTVAL size;
8d33429 @chromatic [PMC] Replaced vtable function calls to find size of fixed integer ar…
chromatic authored May 1, 2009
120 GET_ATTR_size(INTERP, SELF, size);
42f27d4 @NotFound clean FIA.clone
NotFound authored Apr 24, 2010
121 {
122 INTVAL * const dest_int_array = mem_gc_allocate_n_typed(INTERP,
123 size, INTVAL);
124 mem_copy_n_typed(dest_int_array, int_array,
125 size, INTVAL);
126 SET_ATTR_int_array(INTERP, dest, dest_int_array);
127 }
e5dead2 @cotto [pmc] update *IntegerArray to use ATTRs
cotto authored Jan 27, 2009
128 SET_ATTR_size(INTERP, dest, size);
4591dbb @chromatic [HLL] Fixed two compilation-breaking typos accidentally committed in …
chromatic authored Sep 3, 2009
129 PObj_custom_destroy_SET(dest);
a35f6fd @petdance consting & localizing
petdance authored Feb 9, 2008
130 }
894d448 @chromatic [PMC] Minor cleanups and tidyings.
chromatic authored Sep 4, 2007
131
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored Jun 12, 2004
132 return dest;
133 }
134
135 /*
136
137 =item C<INTVAL get_bool()>
138
139 Returns whether the array has any elements (meaning been initialized, for a
140 fixed sized array).
141
142 =cut
143
144 */
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored Mar 11, 2008
145 VTABLE INTVAL get_bool() {
8d33429 @chromatic [PMC] Replaced vtable function calls to find size of fixed integer ar…
chromatic authored May 1, 2009
146 INTVAL size;
147 GET_ATTR_size(INTERP, SELF, size);
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored Jun 12, 2004
148 return (INTVAL)(size != 0);
149 }
150
151 /*
152
153 =item C<INTVAL elements()>
154
155 =cut
156
157 */
158
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored Mar 11, 2008
159 VTABLE INTVAL elements() {
8d33429 @chromatic [PMC] Replaced vtable function calls to find size of fixed integer ar…
chromatic authored May 1, 2009
160 INTVAL size;
161 GET_ATTR_size(INTERP, SELF, size);
162
163 return size;
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored Jun 12, 2004
164 }
165
166 /*
167
168 =item C<INTVAL get_integer()>
169
170 Returns the number of elements in the array.
171
172 =cut
173
174 */
175
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored Mar 11, 2008
176 VTABLE INTVAL get_integer() {
8d33429 @chromatic [PMC] Replaced vtable function calls to find size of fixed integer ar…
chromatic authored May 1, 2009
177 INTVAL size;
178 GET_ATTR_size(INTERP, SELF, size);
179 return size;
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored Jun 12, 2004
180 }
181
182
183 /*
184
185 =item C<INTVAL get_integer_keyed_int(INTVAL key)>
186
187 Returns the integer value of the element at index C<key>.
188
189 =cut
190
191 */
192
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored Mar 11, 2008
193 VTABLE INTVAL get_integer_keyed_int(INTVAL key) {
e5dead2 @cotto [pmc] update *IntegerArray to use ATTRs
cotto authored Jan 27, 2009
194 INTVAL *int_array;
8d33429 @chromatic [PMC] Replaced vtable function calls to find size of fixed integer ar…
chromatic authored May 1, 2009
195 INTVAL size;
894d448 @chromatic [PMC] Minor cleanups and tidyings.
chromatic authored Sep 4, 2007
196
8d33429 @chromatic [PMC] Replaced vtable function calls to find size of fixed integer ar…
chromatic authored May 1, 2009
197 GET_ATTR_size(INTERP, SELF, size);
198
199 if (key < 0 || key >= size)
26914e1 changed interp in pmc class to INTERP for unification
Jimmy Zhuo authored May 5, 2010
200 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 Dec 12, 2004
201 "FixedIntegerArray: index out of bounds!");
d1f7c98 JIT/i386 ord_i_s*
Leopold Toetsch authored Mar 22, 2005
202
e5dead2 @cotto [pmc] update *IntegerArray to use ATTRs
cotto authored Jan 27, 2009
203 GET_ATTR_int_array(INTERP, SELF, int_array);
204 return int_array[key];
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored Jun 12, 2004
205 }
206
207 /*
208
209 =item C<INTVAL get_integer_keyed(PMC *key)>
210
211 Returns the integer value of the element at index C<*key>.
212
213 =cut
214
215 */
216
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored Mar 11, 2008
217 VTABLE INTVAL get_integer_keyed(PMC *key) {
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored Jun 12, 2004
218 /* simple int keys only */
757f3a8 @chromatic [PMC] Replaced all uses of key_integer() outside of Key PMC and src/k…
chromatic authored May 8, 2009
219 const INTVAL k = VTABLE_get_integer(INTERP, key);
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored Mar 11, 2008
220 return SELF.get_integer_keyed_int(k);
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored Jun 12, 2004
221 }
222
223
224 /*
225
226 =item C<FLOATVAL get_number_keyed_int(INTVAL key)>
227
228 Returns the floating-point value of the element at index C<key>.
229
230 =cut
231
232 */
233
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored Mar 11, 2008
234 VTABLE FLOATVAL get_number_keyed_int(INTVAL key) {
235 const INTVAL i = SELF.get_integer_keyed_int(key);
8275ff5 @chromatic [PMC] Fixed a couple of casting warnings of function return values.
chromatic authored Aug 18, 2007
236 return (FLOATVAL)i;
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored Jun 12, 2004
237 }
238
239 /*
240
95e3676 @Infinoid [pmc] PDD07-ize function signatures in src/pmc/[b-f]*.pmc
Infinoid authored Aug 9, 2007
241 =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 Jun 12, 2004
242
243 Returns the floating-point value of the element at index C<*key>.
244
245 =cut
246
247 */
248
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored Mar 11, 2008
249 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 May 8, 2009
250 const INTVAL k = VTABLE_get_integer(INTERP, key);
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored Mar 11, 2008
251 return SELF.get_number_keyed_int(k);
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored Jun 12, 2004
252 }
253
254 /*
255
256 =item C<STRING *get_string_keyed_int(INTVAL key)>
257
258 Returns the Parrot string value of the element at index C<key>.
259
260 =cut
261
262 */
263
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored Mar 11, 2008
264 VTABLE STRING *get_string_keyed_int(INTVAL key) {
265 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 Jun 12, 2004
266 return VTABLE_get_string(INTERP, temp);
267 }
bf41b66 @particle [PDD07]: ws cleanup in src/, src/dynpmc/, and src/pmc/
particle authored Oct 25, 2006
268
5a67dac @tewk Add get_repr to fixedintegerarray and integer
tewk authored Oct 18, 2006
269 /*
270
271 =item C<STRING *get_repr()>
272
273 Returns the Parrot string representation C<key>.
274
275 =cut
276
277 */
278
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored Mar 11, 2008
279 VTABLE STRING *get_repr() {
a35f6fd @petdance consting & localizing
petdance authored Feb 9, 2008
280 STRING *res = CONST_STRING(INTERP, "[ ");
8d33429 @chromatic [PMC] Replaced vtable function calls to find size of fixed integer ar…
chromatic authored May 1, 2009
281 INTVAL n;
894d448 @chromatic [PMC] Minor cleanups and tidyings.
chromatic authored Sep 4, 2007
282 INTVAL j;
5a67dac @tewk Add get_repr to fixedintegerarray and integer
tewk authored Oct 18, 2006
283
8d33429 @chromatic [PMC] Replaced vtable function calls to find size of fixed integer ar…
chromatic authored May 1, 2009
284 GET_ATTR_size(INTERP, SELF, n);
285
5a67dac @tewk Add get_repr to fixedintegerarray and integer
tewk authored Oct 18, 2006
286 for (j = 0; j < n; ++j) {
a35f6fd @petdance consting & localizing
petdance authored Feb 9, 2008
287 PMC * const val = SELF.get_pmc_keyed_int(j);
9b0f14a @bacek Everybody freeze! Immutable strings enters the building.
bacek authored Apr 21, 2010
288 res = Parrot_str_concat(INTERP, res, VTABLE_get_repr(INTERP, val));
894d448 @chromatic [PMC] Minor cleanups and tidyings.
chromatic authored Sep 4, 2007
289
5a67dac @tewk Add get_repr to fixedintegerarray and integer
tewk authored Oct 18, 2006
290 if (j < n - 1)
9b0f14a @bacek Everybody freeze! Immutable strings enters the building.
bacek authored Apr 21, 2010
291 res = Parrot_str_concat(INTERP, res, CONST_STRING(INTERP, ", "));
5a67dac @tewk Add get_repr to fixedintegerarray and integer
tewk authored Oct 18, 2006
292 }
894d448 @chromatic [PMC] Minor cleanups and tidyings.
chromatic authored Sep 4, 2007
293
9b0f14a @bacek Everybody freeze! Immutable strings enters the building.
bacek authored Apr 21, 2010
294 res = Parrot_str_concat(INTERP, res, CONST_STRING(INTERP, " ]"));
5a67dac @tewk Add get_repr to fixedintegerarray and integer
tewk authored Oct 18, 2006
295 return res;
296 }
297
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored Jun 12, 2004
298
299 /*
300
301 =item C<STRING *get_string_keyed(PMC *key)>
302
303 Returns the Parrot string value of the element at index C<*key>.
304
305 =cut
306
307 */
308
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored Mar 11, 2008
309 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 May 8, 2009
310 const INTVAL k = VTABLE_get_integer(INTERP, key);
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored Mar 11, 2008
311 return SELF.get_string_keyed_int(k);
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored Jun 12, 2004
312 }
313
314
315 /*
316
317 =item C<PMC *get_pmc_keyed_int(INTVAL key)>
318
319 Returns the PMC value of the element at index C<key>.
320
321 =cut
322
323 */
324
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored Mar 11, 2008
325 VTABLE PMC *get_pmc_keyed_int(INTVAL key) {
326 const INTVAL val = SELF.get_integer_keyed_int(key);
75d112f @NotFound implement Integer vtable init_int and use it in several places where …
NotFound authored May 1, 2010
327 PMC * const ret = Parrot_pmc_new_init_int(INTERP, enum_class_Integer, val);
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored Jun 12, 2004
328 return ret;
329 }
330
331 /*
332
333 =item C<PMC *get_pmc_keyed(PMC *key)>
334
335 Returns the PMC value of the element at index C<*key>.
336
337 =cut
338
339 */
340
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored Mar 11, 2008
341 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 May 8, 2009
342 const INTVAL k = VTABLE_get_integer(INTERP, key);
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored Mar 11, 2008
343 return SELF.get_pmc_keyed_int(k);
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored Jun 12, 2004
344 }
345
346 /*
347
348 =item C<void set_integer_native(INTVAL size)>
349
350 Resizes the array to C<size> elements.
351
352 =cut
353
354 */
355
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored Mar 11, 2008
356 VTABLE void set_integer_native(INTVAL size) {
e5dead2 @cotto [pmc] update *IntegerArray to use ATTRs
cotto authored Jan 27, 2009
357 INTVAL *int_array;
8d33429 @chromatic [PMC] Replaced vtable function calls to find size of fixed integer ar…
chromatic authored May 1, 2009
358 INTVAL cur_size;
359
360 GET_ATTR_size(INTERP, SELF, cur_size);
361
362 if (cur_size || size < 1)
2255840 @allisonrandal [pdd17pmc] Merging the pdd25cx branch into trunk for r26555 to r29949.
allisonrandal authored Aug 2, 2008
363 Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_OUT_OF_BOUNDS,
d1f7c98 JIT/i386 ord_i_s*
Leopold Toetsch authored Mar 22, 2005
364 "FixedIntegerArray: Can't resize!");
2255840 @allisonrandal [pdd17pmc] Merging the pdd25cx branch into trunk for r26555 to r29949.
allisonrandal authored Aug 2, 2008
365
e5dead2 @cotto [pmc] update *IntegerArray to use ATTRs
cotto authored Jan 27, 2009
366 SET_ATTR_size(INTERP, SELF, size);
367 GET_ATTR_int_array(INTERP, SELF, int_array);
7a96a21 @bschmalhofer [codingstd] tabs.t and trailing_space.t
bschmalhofer authored Jan 28, 2009
368 SET_ATTR_int_array(INTERP, SELF,
4833868 @bacek Merge branch 'sys_mem' into trunk
bacek authored Feb 22, 2010
369 mem_gc_realloc_n_typed(INTERP, int_array, size, INTVAL));
4591dbb @chromatic [HLL] Fixed two compilation-breaking typos accidentally committed in …
chromatic authored Sep 3, 2009
370 PObj_custom_destroy_SET(SELF);
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored Jun 12, 2004
371 }
372
373 /*
374
375 =item C<void set_integer_keyed_int(INTVAL key, INTVAL value)>
376
377 Sets the integer value of the element at index C<key> to C<value>.
378
379 =cut
380
381 */
382
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored Mar 11, 2008
383 VTABLE void set_integer_keyed_int(INTVAL key, INTVAL value) {
e5dead2 @cotto [pmc] update *IntegerArray to use ATTRs
cotto authored Jan 27, 2009
384 INTVAL *int_array;
8d33429 @chromatic [PMC] Replaced vtable function calls to find size of fixed integer ar…
chromatic authored May 1, 2009
385 INTVAL size;
894d448 @chromatic [PMC] Minor cleanups and tidyings.
chromatic authored Sep 4, 2007
386
8d33429 @chromatic [PMC] Replaced vtable function calls to find size of fixed integer ar…
chromatic authored May 1, 2009
387 GET_ATTR_size(INTERP, SELF, size);
388
389 if (key < 0 || key >= size)
26914e1 changed interp in pmc class to INTERP for unification
Jimmy Zhuo authored May 5, 2010
390 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 Dec 12, 2004
391 "FixedIntegerArray: index out of bounds!");
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored Jun 12, 2004
392
e5dead2 @cotto [pmc] update *IntegerArray to use ATTRs
cotto authored Jan 27, 2009
393 GET_ATTR_int_array(INTERP, SELF, int_array);
394 int_array[key] = value;
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored Jun 12, 2004
395 }
396
397 /*
398
399 =item C<void set_integer_keyed(PMC *key, INTVAL value)>
400
401 Sets the integer value of the element at index C<key> to C<value>.
402
403 =cut
404
405 */
406
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored Mar 11, 2008
407 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 May 8, 2009
408 const INTVAL k = VTABLE_get_integer(INTERP, key);
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored Mar 11, 2008
409 SELF.set_integer_keyed_int(k, value);
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored Jun 12, 2004
410 }
411
412 /*
413
414 =item C<void set_number_keyed_int(INTVAL key, FLOATVAL value)>
415
894d448 @chromatic [PMC] Minor cleanups and tidyings.
chromatic authored Sep 4, 2007
416 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 Jun 12, 2004
417
418 =cut
419
420 */
421
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored Mar 11, 2008
422 VTABLE void set_number_keyed_int(INTVAL key, FLOATVAL value) {
423 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 Jun 12, 2004
424 }
425
426 /*
427
428 =item C<void set_number_keyed(PMC *key, FLOATVAL value)>
429
894d448 @chromatic [PMC] Minor cleanups and tidyings.
chromatic authored Sep 4, 2007
430 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 Jun 12, 2004
431
432 =cut
433
434 */
435
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored Mar 11, 2008
436 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 May 8, 2009
437 const INTVAL k = VTABLE_get_integer(INTERP, key);
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored Mar 11, 2008
438 SELF.set_number_keyed_int(k, value);
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored Jun 12, 2004
439 }
d1f7c98 JIT/i386 ord_i_s*
Leopold Toetsch authored Mar 22, 2005
440
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored Jun 12, 2004
441 /*
442
443 =item C<void set_string_keyed_int(INTVAL key, STRING *value)>
444
445 Sets the Parrot string value of the element at index C<key> to C<value>.
446
447 =cut
448
449 */
450
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored Mar 11, 2008
451 VTABLE void set_string_keyed_int(INTVAL key, STRING *value) {
06e2d1e @NotFound avoid a temporary PMC in FPA set_string_keyed_int
NotFound authored Apr 30, 2010
452 const INTVAL tempInt = Parrot_str_to_int(INTERP, value);
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored Mar 11, 2008
453 SELF.set_integer_keyed_int(key, tempInt);
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored Jun 12, 2004
454 }
455
456 /*
457
95e3676 @Infinoid [pmc] PDD07-ize function signatures in src/pmc/[b-f]*.pmc
Infinoid authored Aug 9, 2007
458 =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 Jun 12, 2004
459
894d448 @chromatic [PMC] Minor cleanups and tidyings.
chromatic authored Sep 4, 2007
460 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 Jun 12, 2004
461
462 =cut
463
464 */
465
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored Mar 11, 2008
466 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 May 8, 2009
467 const INTVAL k = VTABLE_get_integer(INTERP, key);
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored Mar 11, 2008
468 SELF.set_string_keyed_int(k, value);
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored Jun 12, 2004
469 }
470
471 /*
472
473 =item C<void set_pmc_keyed_int(INTVAL key, PMC *src)>
474
475 Sets the PMC value of the element at index C<key> to C<*src>.
476
477 =cut
478
479 */
480
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored Mar 11, 2008
481 VTABLE void set_pmc_keyed_int(INTVAL key, PMC *src) {
a35f6fd @petdance consting & localizing
petdance authored Feb 9, 2008
482 const INTVAL tempInt = VTABLE_get_integer(INTERP, src);
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored Mar 11, 2008
483 SELF.set_integer_keyed_int(key, tempInt);
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored Jun 12, 2004
484 }
485
486 /*
487
95e3676 @Infinoid [pmc] PDD07-ize function signatures in src/pmc/[b-f]*.pmc
Infinoid authored Aug 9, 2007
488 =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 Jun 12, 2004
489
894d448 @chromatic [PMC] Minor cleanups and tidyings.
chromatic authored Sep 4, 2007
490 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 Jun 12, 2004
491
492 =cut
493
494 */
495
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored Mar 11, 2008
496 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 May 8, 2009
497 const INTVAL k = VTABLE_get_integer(INTERP, key);
59661f1 @allisonrandal [pdd17pmc] Merging the pdd17pmc branch into trunk (r24435 to r26307).
allisonrandal authored Mar 11, 2008
498 SELF.set_pmc_keyed_int(k, value);
499 }
500
6287ae3 add missing fixedintegerarray.freeze and .thaw
Leopold Toetsch authored Jul 3, 2005
501 /*
502
0c38764 @bacek [core] Implement FixedIntegerArray.is_equal
bacek authored Sep 20, 2009
503 =item C<INTVAL is_equal(PMC *value)>
504
505 The C<==> operation. Compares two array to hold equal elements.
506
507 =cut
508
509 */
510
511 VTABLE INTVAL is_equal(PMC *value) {
512 INTVAL j, n;
513
514 if (value->vtable->base_type != SELF->vtable->base_type)
515 return 0;
516
517 n = SELF.elements();
518
519 if (VTABLE_elements(INTERP, value) != n)
520 return 0;
521
522 for (j = 0; j < n; ++j) {
f9cca7d @petdance consting and annotating
petdance authored Jun 30, 2010
523 const INTVAL item1 = SELF.get_integer_keyed_int(j);
524 const INTVAL item2 = VTABLE_get_integer_keyed_int(INTERP, value, j);
0c38764 @bacek [core] Implement FixedIntegerArray.is_equal
bacek authored Sep 20, 2009
525
526 if (item1 != item2)
527 return 0;
528 }
529
530 return 1;
531 }
532
533 /*
534
bd8aacd @cotto [PMC] add get_iter VTABLE function and tests to *IntegerArray
cotto authored Mar 22, 2009
535 =item C<PMC *get_iter()>
536
537 Return a new Iterator for this PMC.
538
539 =cut
540
541 */
542
543 VTABLE PMC *get_iter() {
083213a @Whiteknight start rename of pmc_new to Parrot_pmc_new
Whiteknight authored Feb 16, 2010
544 return Parrot_pmc_new_init(INTERP, enum_class_ArrayIterator, SELF);
bd8aacd @cotto [PMC] add get_iter VTABLE function and tests to *IntegerArray
cotto authored Mar 22, 2009
545 }
546
547 /*
548
b101f2c @darbelo Merge pmc_freeze_with_pmcs into trunk.
darbelo authored Feb 2, 2010
549 =item C<void visit(PMC *info)>
6287ae3 add missing fixedintegerarray.freeze and .thaw
Leopold Toetsch authored Jul 3, 2005
550
551 This is used by freeze/thaw to visit the contents of the array.
552
553 C<*info> is the visit info, (see F<include/parrot/pmc_freeze.h>).
554
b101f2c @darbelo Merge pmc_freeze_with_pmcs into trunk.
darbelo authored Feb 2, 2010
555 =item C<void freeze(PMC *info)>
6287ae3 add missing fixedintegerarray.freeze and .thaw
Leopold Toetsch authored Jul 3, 2005
556
557 Used to archive the array.
558
b101f2c @darbelo Merge pmc_freeze_with_pmcs into trunk.
darbelo authored Feb 2, 2010
559 =item C<void thaw(PMC *info)>
6287ae3 add missing fixedintegerarray.freeze and .thaw
Leopold Toetsch authored Jul 3, 2005
560
561 Used to unarchive the array.
562
563 =cut
564
565 */
566
b101f2c @darbelo Merge pmc_freeze_with_pmcs into trunk.
darbelo authored Feb 2, 2010
567 /*VTABLE void visit(PMC *info) {
6287ae3 add missing fixedintegerarray.freeze and .thaw
Leopold Toetsch authored Jul 3, 2005
568 SUPER(info);
e5dead2 @cotto [pmc] update *IntegerArray to use ATTRs
cotto authored Jan 27, 2009
569 }*/
6287ae3 add missing fixedintegerarray.freeze and .thaw
Leopold Toetsch authored Jul 3, 2005
570
b101f2c @darbelo Merge pmc_freeze_with_pmcs into trunk.
darbelo authored Feb 2, 2010
571 VTABLE void freeze(PMC *info) {
e5dead2 @cotto [pmc] update *IntegerArray to use ATTRs
cotto authored Jan 27, 2009
572 INTVAL *int_array;
894d448 @chromatic [PMC] Minor cleanups and tidyings.
chromatic authored Sep 4, 2007
573 INTVAL i, n;
6287ae3 add missing fixedintegerarray.freeze and .thaw
Leopold Toetsch authored Jul 3, 2005
574
575 SUPER(info);
894d448 @chromatic [PMC] Minor cleanups and tidyings.
chromatic authored Sep 4, 2007
576
8d33429 @chromatic [PMC] Replaced vtable function calls to find size of fixed integer ar…
chromatic authored May 1, 2009
577 GET_ATTR_size(INTERP, SELF, n);
4c43475 @plobsing merge branch pmc_freeze_cleanup
plobsing authored Jan 13, 2010
578 VTABLE_push_integer(INTERP, info, n);
e5dead2 @cotto [pmc] update *IntegerArray to use ATTRs
cotto authored Jan 27, 2009
579 GET_ATTR_int_array(INTERP, SELF, int_array);
894d448 @chromatic [PMC] Minor cleanups and tidyings.
chromatic authored Sep 4, 2007
580
581 for (i = 0; i < n; ++i)
4c43475 @plobsing merge branch pmc_freeze_cleanup
plobsing authored Jan 13, 2010
582 VTABLE_push_integer(INTERP, info, int_array[i]);
6287ae3 add missing fixedintegerarray.freeze and .thaw
Leopold Toetsch authored Jul 3, 2005
583 }
584
b101f2c @darbelo Merge pmc_freeze_with_pmcs into trunk.
darbelo authored Feb 2, 2010
585 VTABLE void thaw(PMC *info) {
4c43475 @plobsing merge branch pmc_freeze_cleanup
plobsing authored Jan 13, 2010
586 INTVAL n;
e5dead2 @cotto [pmc] update *IntegerArray to use ATTRs
cotto authored Jan 27, 2009
587
4c43475 @plobsing merge branch pmc_freeze_cleanup
plobsing authored Jan 13, 2010
588 SUPER(info);
894d448 @chromatic [PMC] Minor cleanups and tidyings.
chromatic authored Sep 4, 2007
589
4c43475 @plobsing merge branch pmc_freeze_cleanup
plobsing authored Jan 13, 2010
590 SET_ATTR_size(INTERP, SELF, 0);
591 SET_ATTR_int_array(INTERP, SELF, NULL);
894d448 @chromatic [PMC] Minor cleanups and tidyings.
chromatic authored Sep 4, 2007
592
4c43475 @plobsing merge branch pmc_freeze_cleanup
plobsing authored Jan 13, 2010
593 if ((n = VTABLE_shift_integer(INTERP, info))) {
594 INTVAL i;
595 INTVAL *int_array;
894d448 @chromatic [PMC] Minor cleanups and tidyings.
chromatic authored Sep 4, 2007
596
4c43475 @plobsing merge branch pmc_freeze_cleanup
plobsing authored Jan 13, 2010
597 SELF.set_integer_native(n);
598 GET_ATTR_int_array(INTERP, SELF, int_array);
894d448 @chromatic [PMC] Minor cleanups and tidyings.
chromatic authored Sep 4, 2007
599
4c43475 @plobsing merge branch pmc_freeze_cleanup
plobsing authored Jan 13, 2010
600 for (i = 0; i < n; ++i)
601 int_array[i] = VTABLE_shift_integer(INTERP, info);
6287ae3 add missing fixedintegerarray.freeze and .thaw
Leopold Toetsch authored Jul 3, 2005
602 }
603 }
ac9988d @NotFound some cleaning of FIA: put METHOD after vtable functions and fix and i…
NotFound authored Aug 12, 2010
604
605 /*
606
607 =back
608
609 =head2 Methods
610
611 =over 4
612
613 =item C<PMC *sort()>
614
615 Sort the array and return self.
616
617 =cut
618
619 */
620
621 METHOD sort(PMC *cmp_func :optional) {
622 UINTVAL n;
623 INTVAL size;
624
625 GET_ATTR_size(INTERP, SELF, size);
626 n = (UINTVAL)size;
627
628 if (n > 1) {
629 INTVAL *int_array;
630 GET_ATTR_int_array(INTERP, SELF, int_array);
631 if (PMC_IS_NULL(cmp_func))
632 qsort(int_array, n, sizeof (INTVAL),
633 (int (*)(const void *, const void*))auxcmpfunc);
634 else
635 Parrot_quicksort(INTERP, (void**)int_array, n, cmp_func);
636 }
637 RETURN(PMC *SELF);
638 }
639
640 }
641
642 /*
643
644 =back
645
cbe2617 @jkeenan Correct spelling error in POD.
jkeenan authored Aug 14, 2010
646 =head2 Auxiliary functions
ac9988d @NotFound some cleaning of FIA: put METHOD after vtable functions and fix and i…
NotFound authored Aug 12, 2010
647
648 =over 4
649
650 =item C<static int auxcmpfunc(const INTVAL *i, const INTVAL *j)>
651
652 INTVAL compare function for qsort usage.
653
654 =cut
655
656 */
657
658 PARROT_PURE_FUNCTION
659 static int
660 auxcmpfunc(ARGIN(const INTVAL *i), ARGIN(const INTVAL *j))
661 {
662 ASSERT_ARGS(auxcmpfunc)
663 return *i - *j;
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored Jun 12, 2004
664 }
665
666 /*
667
668 =back
669
670 =head1 SEE ALSO
671
1e8a4ab this patch adds some relevant 'push' ops to the resizable PMCs, descr…
Dan Sugalski authored Oct 19, 2004
672 F<docs/pdds/pdd17_basic_types.pod>.
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored Jun 12, 2004
673
674 =cut
675
676 */
677
678 /*
679 * Local variables:
72575ae @bschmalhofer #40481: [PATCH] C-code coda in pmc files
bschmalhofer authored Oct 9, 2006
680 * c-file-style: "parrot"
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored Jun 12, 2004
681 * End:
682 * vim: expandtab shiftwidth=4:
72575ae @bschmalhofer #40481: [PATCH] C-code coda in pmc files
bschmalhofer authored Oct 9, 2006
683 */
Something went wrong with that request. Please try again.