Skip to content

HTTPS clone URL

Subversion checkout URL

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