Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 460 lines (284 sloc) 7.849 kB
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored
1 /*
f149e74 @coke #39217 - copyright cleanup. (src/)
coke authored
2 Copyright (C) 2001-2003, The Perl Foundation.
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored
3 $Id$
4
5 =head1 NAME
6
f474cd7 @bschmalhofer [perl #38235] Rename (dyn)?classes to (dyn)?pmc
bschmalhofer authored
7 src/pmc/fixedfloatarray.pmc - fixed size array for floating point numbers only
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored
8
9 =head1 DESCRIPTION
10
6c8f30b @ambs 80 columns cuts in all pmcs
ambs authored
11 This class, FixedFloatArray, implements an array of fixed size, which
12 stored FLOATVALs, it uses Float PMCs to do all necessary conversions
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored
13
14 =head2 Functions
15
16 =over 4
17
18 =cut
19
20 */
21
22 #include "parrot/parrot.h"
23
24 pmclass FixedFloatArray need_ext does array {
7298186 @particle pmc: convert Fixed*Array and Resizable*Array internal_exceptions to r…
particle 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
3afde54 @particle [pmc] modify parenthesis in C files as per PDD07
particle authored
42 void init() {
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored
43 PMC_int_val(SELF) = 0;
44 PMC_data(SELF) = NULL;
45 }
46
47 /*
48
49 =item C<void morph(INTVAL type)>
50
f474cd7 @bschmalhofer [perl #38235] Rename (dyn)?classes to (dyn)?pmc
bschmalhofer authored
51 Const PMCs must have a C<morph()>.
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored
52
53 =cut
54
55 */
56
57 void morph(INTVAL type) {
58 SUPER(type);
59 }
60
61
62 /*
63
64 =item C<void destroy()>
65
66 Destroys the array.
67
68 =cut
69
70 */
71
3afde54 @particle [pmc] modify parenthesis in C files as per PDD07
particle authored
72 void destroy() {
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored
73 if (PMC_data(SELF))
74 mem_sys_free(PMC_data(SELF));
75 PMC_data(SELF) = NULL;
76 PMC_int_val(SELF) = 0;
77 }
78
79 /*
80
81 =item C<PMC *clone()>
82
83 Creates and returns a copy of the array.
84
85 =cut
86
87 */
88
95e3676 @Infinoid [pmc] PDD07-ize function signatures in src/pmc/[b-f]*.pmc
Infinoid authored
89 PMC *clone() {
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored
90 INTVAL size;
91 PMC * dest = pmc_new(INTERP, SELF->vtable->base_type);
7298186 @particle pmc: convert Fixed*Array and Resizable*Array internal_exceptions to r…
particle authored
92
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored
93 if (!PMC_data(SELF))
94 return dest;
95 size = PMC_int_val(SELF);
96 PMC_int_val(dest) = size;
7298186 @particle pmc: convert Fixed*Array and Resizable*Array internal_exceptions to r…
particle authored
97
3afde54 @particle [pmc] modify parenthesis in C files as per PDD07
particle authored
98 PMC_data(dest) = mem_sys_allocate(size * sizeof (FLOATVAL));
99 mem_sys_memcopy(PMC_data(dest), PMC_data(SELF), size*sizeof (FLOATVAL));
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored
100 PObj_active_destroy_SET(dest);
101 return dest;
102 }
103
104 /*
105
106 =item C<INTVAL get_bool()>
107
108 Returns whether the array has any elements (meaning been initialized, for a
109 fixed sized array).
110
111 =cut
112
113 */
3afde54 @particle [pmc] modify parenthesis in C files as per PDD07
particle authored
114 INTVAL get_bool() {
ae8baa5 @bschmalhofer DYNDYNSELF in the Fixed*Array PMC looks like a typo. Using SELF propably
bschmalhofer authored
115 INTVAL size = SELF.elements();
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored
116 return (INTVAL)(size != 0);
117 }
118
119 /*
120
121 =item C<INTVAL elements()>
122
123 =cut
124
125 */
126
3afde54 @particle [pmc] modify parenthesis in C files as per PDD07
particle authored
127 INTVAL elements() {
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored
128 return PMC_int_val(SELF);
129 }
130
131 /*
132
133 =item C<INTVAL get_integer()>
134
135 Returns the number of elements in the array.
136
137 =cut
138
139 */
140
3afde54 @particle [pmc] modify parenthesis in C files as per PDD07
particle authored
141 INTVAL get_integer() {
ae8baa5 @bschmalhofer DYNDYNSELF in the Fixed*Array PMC looks like a typo. Using SELF propably
bschmalhofer authored
142 return SELF.elements();
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored
143 }
144
145
146 /*
147
148 =item C<INTVAL get_integer_keyed_int(INTVAL key)>
149
150 Returns the integer value of the element at index C<key>.
151
152 =cut
153
154 */
155
3afde54 @particle [pmc] modify parenthesis in C files as per PDD07
particle authored
156 INTVAL get_integer_keyed_int(INTVAL key) {
6a54672 This patch adds Resizable*Array pmcs as the counterparts to Fixed*Array
Dan Sugalski authored
157 return (INTVAL)DYNSELF.get_number_keyed_int(key);
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored
158 }
159
160 /*
161
162 =item C<INTVAL get_integer_keyed(PMC *key)>
163
164 Returns the integer value of the element at index C<*key>.
165
166 =cut
167
168 */
169
95e3676 @Infinoid [pmc] PDD07-ize function signatures in src/pmc/[b-f]*.pmc
Infinoid authored
170 INTVAL get_integer_keyed(PMC *key) {
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored
171 /* simple int keys only */
172 INTVAL k = key_integer(INTERP, key);
6a54672 This patch adds Resizable*Array pmcs as the counterparts to Fixed*Array
Dan Sugalski authored
173 return DYNSELF.get_integer_keyed_int(k);
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored
174 }
175
176
177 /*
178
179 =item C<FLOATVAL get_number_keyed_int(INTVAL key)>
180
181 Returns the floating-point value of the element at index C<key>.
182
183 =cut
184
185 */
186
3afde54 @particle [pmc] modify parenthesis in C files as per PDD07
particle authored
187 FLOATVAL get_number_keyed_int(INTVAL key) {
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored
188 FLOATVAL *data;
189 if (key < 0 || key >= PMC_int_val(SELF))
7298186 @particle pmc: convert Fixed*Array and Resizable*Array internal_exceptions to r…
particle authored
190 real_exception(INTERP, NULL, E_IndexError,
d185452 @chromatic Standardize internal exception calls (James deBoer, james at huronbox…
chromatic authored
191 "FixedFloatArray: index out of bounds!");
7298186 @particle pmc: convert Fixed*Array and Resizable*Array internal_exceptions to r…
particle authored
192
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored
193 data = (FLOATVAL *)PMC_data(SELF);
194 return data[key];
195 }
196
197 /*
198
95e3676 @Infinoid [pmc] PDD07-ize function signatures in src/pmc/[b-f]*.pmc
Infinoid authored
199 =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
200
201 Returns the floating-point value of the element at index C<*key>.
202
203 =cut
204
205 */
206
95e3676 @Infinoid [pmc] PDD07-ize function signatures in src/pmc/[b-f]*.pmc
Infinoid authored
207 FLOATVAL get_number_keyed(PMC *key) {
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored
208 INTVAL k = key_integer(INTERP, key);
6a54672 This patch adds Resizable*Array pmcs as the counterparts to Fixed*Array
Dan Sugalski authored
209 return DYNSELF.get_number_keyed_int(k);
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored
210 }
211
212 /*
213
214 =item C<STRING *get_string_keyed_int(INTVAL key)>
215
216 Returns the Parrot string value of the element at index C<key>.
217
218 =cut
219
220 */
221
95e3676 @Infinoid [pmc] PDD07-ize function signatures in src/pmc/[b-f]*.pmc
Infinoid authored
222 STRING *get_string_keyed_int(INTVAL key) {
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored
223 PMC *temp;
6a54672 This patch adds Resizable*Array pmcs as the counterparts to Fixed*Array
Dan Sugalski authored
224 temp = DYNSELF.get_pmc_keyed_int(key);
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored
225 return VTABLE_get_string(INTERP, temp);
226 }
227
228 /*
229
230 =item C<STRING *get_string_keyed(PMC *key)>
231
232 Returns the Parrot string value of the element at index C<*key>.
233
234 =cut
235
236 */
237
95e3676 @Infinoid [pmc] PDD07-ize function signatures in src/pmc/[b-f]*.pmc
Infinoid authored
238 STRING *get_string_keyed(PMC *key) {
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored
239 INTVAL k = key_integer(INTERP, key);
6a54672 This patch adds Resizable*Array pmcs as the counterparts to Fixed*Array
Dan Sugalski authored
240 return DYNSELF.get_string_keyed_int(k);
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored
241 }
242
243
244 /*
245
246 =item C<PMC *get_pmc_keyed_int(INTVAL key)>
247
248 Returns the PMC value of the element at index C<key>.
249
250 =cut
251
252 */
253
95e3676 @Infinoid [pmc] PDD07-ize function signatures in src/pmc/[b-f]*.pmc
Infinoid authored
254 PMC *get_pmc_keyed_int(INTVAL key) {
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored
255 PMC *ret;
256 FLOATVAL val;
257
258 ret = pmc_new(INTERP, enum_class_Float);
6a54672 This patch adds Resizable*Array pmcs as the counterparts to Fixed*Array
Dan Sugalski authored
259 val = DYNSELF.get_number_keyed_int(key);
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored
260 VTABLE_set_number_native(INTERP, ret, val);
261 return ret;
262 }
263
264 /*
265
266 =item C<PMC *get_pmc_keyed(PMC *key)>
267
268 Returns the PMC value of the element at index C<*key>.
269
270 =cut
271
272 */
273
95e3676 @Infinoid [pmc] PDD07-ize function signatures in src/pmc/[b-f]*.pmc
Infinoid authored
274 PMC *get_pmc_keyed(PMC *key) {
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored
275 INTVAL k = key_integer(INTERP, key);
6a54672 This patch adds Resizable*Array pmcs as the counterparts to Fixed*Array
Dan Sugalski authored
276 return DYNSELF.get_pmc_keyed_int(k);
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored
277 }
278
279 /*
280
281 =item C<void set_integer_native(INTVAL size)>
282
283 Resizes the array to C<size> elements.
284
285 =cut
286
287 */
288
3afde54 @particle [pmc] modify parenthesis in C files as per PDD07
particle authored
289 void set_integer_native(INTVAL size) {
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored
290 if (PMC_int_val(SELF) || size < 1)
7298186 @particle pmc: convert Fixed*Array and Resizable*Array internal_exceptions to r…
particle authored
291 real_exception(INTERP, NULL, E_IndexError,
292 "FixedFloatArray: Can't resize!");
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored
293 PMC_int_val(SELF) = size;
3afde54 @particle [pmc] modify parenthesis in C files as per PDD07
particle authored
294 PMC_data(SELF) = mem_sys_allocate(size * sizeof (FLOATVAL));
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored
295 PObj_active_destroy_SET(SELF);
296 }
297
298 /*
299
300 =item C<void set_integer_keyed_int(INTVAL key, INTVAL value)>
301
302 Sets the integer value of the element at index C<key> to C<value>.
303
304 =cut
305
306 */
307
3afde54 @particle [pmc] modify parenthesis in C files as per PDD07
particle authored
308 void set_integer_keyed_int(INTVAL key, INTVAL value) {
6a54672 This patch adds Resizable*Array pmcs as the counterparts to Fixed*Array
Dan Sugalski authored
309 DYNSELF.set_number_keyed_int(key, (FLOATVAL)value);
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored
310 }
311
312 /*
313
314 =item C<void set_integer_keyed(PMC *key, INTVAL value)>
315
316 Sets the integer value of the element at index C<key> to C<value>.
317
318 =cut
319
320 */
321
3afde54 @particle [pmc] modify parenthesis in C files as per PDD07
particle authored
322 void set_integer_keyed(PMC *key, INTVAL value) {
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored
323 INTVAL k;
324 k = key_integer(INTERP, key);
6a54672 This patch adds Resizable*Array pmcs as the counterparts to Fixed*Array
Dan Sugalski authored
325 DYNSELF.set_integer_keyed_int(k, value);
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored
326 }
327
328 /*
329
330 =item C<void set_number_keyed_int(INTVAL key, FLOATVAL value)>
331
332 Sets the floating-point value of the element at index C<key> to
333 C<value>.
334
335 =cut
336
337 */
338
3afde54 @particle [pmc] modify parenthesis in C files as per PDD07
particle authored
339 void set_number_keyed_int(INTVAL key, FLOATVAL value) {
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored
340 FLOATVAL *data;
341 if (key < 0 || key >= PMC_int_val(SELF))
7298186 @particle pmc: convert Fixed*Array and Resizable*Array internal_exceptions to r…
particle authored
342 real_exception(INTERP, NULL, E_IndexError,
d185452 @chromatic Standardize internal exception calls (James deBoer, james at huronbox…
chromatic authored
343 "FixedFloatArray: index out of bounds!");
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored
344
345 data = (FLOATVAL*)PMC_data(SELF);
346 data[key] = value;
347 }
348
349 /*
350
351 =item C<void set_number_keyed(PMC *key, FLOATVAL value)>
352
353 Sets the floating-point value of the element at index C<key> to
354 C<value>.
355
356 =cut
357
358 */
359
360 void set_number_keyed(PMC *key, FLOATVAL value) {
361 INTVAL k;
362 k = key_integer(INTERP, key);
6a54672 This patch adds Resizable*Array pmcs as the counterparts to Fixed*Array
Dan Sugalski authored
363 DYNSELF.set_number_keyed_int(k, value);
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored
364 }
7298186 @particle pmc: convert Fixed*Array and Resizable*Array internal_exceptions to r…
particle authored
365
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored
366 /*
367
368 =item C<void set_string_keyed_int(INTVAL key, STRING *value)>
369
370 Sets the Parrot string value of the element at index C<key> to C<value>.
371
372 =cut
373
374 */
375
95e3676 @Infinoid [pmc] PDD07-ize function signatures in src/pmc/[b-f]*.pmc
Infinoid authored
376 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
377 FLOATVAL tempNum;
378 PMC *tempPMC;
379
380 tempPMC = pmc_new(INTERP, enum_class_Float);
381 VTABLE_set_string_native(INTERP, tempPMC, value);
382 tempNum = VTABLE_get_number(INTERP, tempPMC);
6a54672 This patch adds Resizable*Array pmcs as the counterparts to Fixed*Array
Dan Sugalski authored
383 DYNSELF.set_number_keyed_int(key, tempNum);
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored
384 }
385
386 /*
387
95e3676 @Infinoid [pmc] PDD07-ize function signatures in src/pmc/[b-f]*.pmc
Infinoid authored
388 =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
389
390 Sets the string value of the element at index C<key> to
391 C<value>.
392
393 =cut
394
395 */
396
95e3676 @Infinoid [pmc] PDD07-ize function signatures in src/pmc/[b-f]*.pmc
Infinoid authored
397 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
398 INTVAL k;
399 k = key_integer(INTERP, key);
6a54672 This patch adds Resizable*Array pmcs as the counterparts to Fixed*Array
Dan Sugalski authored
400 DYNSELF.set_string_keyed_int(k, value);
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored
401 }
402
403 /*
404
405 =item C<void set_pmc_keyed_int(INTVAL key, PMC *src)>
406
407 Sets the PMC value of the element at index C<key> to C<*src>.
408
409 =cut
410
411 */
412
95e3676 @Infinoid [pmc] PDD07-ize function signatures in src/pmc/[b-f]*.pmc
Infinoid authored
413 void set_pmc_keyed_int(INTVAL key, PMC *src) {
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored
414 FLOATVAL tempNum;
415 tempNum = VTABLE_get_number(INTERP, src);
6a54672 This patch adds Resizable*Array pmcs as the counterparts to Fixed*Array
Dan Sugalski authored
416 DYNSELF.set_number_keyed_int(key, tempNum);
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored
417 }
418
419 /*
420
95e3676 @Infinoid [pmc] PDD07-ize function signatures in src/pmc/[b-f]*.pmc
Infinoid authored
421 =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
422
423 Sets the string value of the element at index C<key> to
424 C<value>.
425
426 =cut
427
428 */
429
95e3676 @Infinoid [pmc] PDD07-ize function signatures in src/pmc/[b-f]*.pmc
Infinoid authored
430 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
431 INTVAL k;
432 k = key_integer(INTERP, key);
6a54672 This patch adds Resizable*Array pmcs as the counterparts to Fixed*Array
Dan Sugalski authored
433 DYNSELF.set_pmc_keyed_int(k, value);
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored
434 }
435
436 }
437
438 /*
439
440 =back
441
442 =head1 SEE ALSO
443
1e8a4ab this patch adds some relevant 'push' ops to the resizable PMCs, descr…
Dan Sugalski authored
444 F<docs/pdds/pdd17_basic_types.pod>.
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored
445
446 =head1 HISTORY
447
448 Initial version 2004.06.11 by Matt Fowles
449
450 =cut
451
452 */
453
454 /*
455 * Local variables:
72575ae @bschmalhofer #40481: [PATCH] C-code coda in pmc files
bschmalhofer authored
456 * c-file-style: "parrot"
4498fea This patch adds the above Fixed*Array classes. They are basic tests for
Dan Sugalski authored
457 * End:
458 * vim: expandtab shiftwidth=4:
72575ae @bschmalhofer #40481: [PATCH] C-code coda in pmc files
bschmalhofer authored
459 */
Something went wrong with that request. Please try again.