Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

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