2 Copyright (C) 2001-2008, The Perl Foundation.
7 src/pmc/capture.pmc - Capture PMC
11 These are the vtable functions for the Capture PMC.
21 #include "parrot/parrot.h"
24 #define CAPTURE_DATA_SIZE 2
25 #define CAPTURE_array_CREATE(i, obj) \
26 if (!PARROT_CAPTURE(obj)->array) \
27 PARROT_CAPTURE(obj)->array = pmc_new((i), enum_class_ResizablePMCArray);
28 #define CAPTURE_hash_CREATE(i, obj) \
29 if (!PARROT_CAPTURE(obj)->hash) \
30 PARROT_CAPTURE(obj)->hash = pmc_new((i), enum_class_Hash);
32 pmclass Capture need_ext provides array provides hash {
40 Initializes the Capture instance.
42 =item C<void destroy()>
51 Parrot_Capture *capture = mem_allocate_typed(Parrot_Capture);
52 PMC_data(SELF) = capture;
53 capture->array = NULL;
55 PMC_int_val(SELF) = CAPTURE_DATA_SIZE;
56 PObj_active_destroy_SET(SELF);
57 PObj_data_is_PMC_array_SET(SELF);
60 VTABLE void destroy() {
61 if (PARROT_CAPTURE(SELF)) {
62 mem_sys_free(PARROT_CAPTURE(SELF));
63 PMC_data(SELF) = NULL;
66 PMC_int_val(SELF) = 0;
71 =item C<void set_number_keyed_int(INTVAL key, FLOATVAL value)>
73 =item C<void set_integer_keyed_int(INTVAL key, INTVAL value)>
75 =item C<void set_pmc_keyed_int(INTVAL key, PMC *value)>
77 =item C<void set_string_keyed_int(INTVAL key, STRING *value)>
79 Sets a value in the array component of the Capture.
85 VTABLE void set_number_keyed_int(INTVAL key, FLOATVAL value) {
86 CAPTURE_array_CREATE(INTERP, SELF);
87 VTABLE_set_number_keyed_int(INTERP, PARROT_CAPTURE(SELF)->array,
91 VTABLE void set_integer_keyed_int(INTVAL key, INTVAL value) {
92 CAPTURE_array_CREATE(INTERP, SELF);
93 VTABLE_set_integer_keyed_int(INTERP, PARROT_CAPTURE(SELF)->array,
97 VTABLE void set_pmc_keyed_int(INTVAL key, PMC *value) {
98 CAPTURE_array_CREATE(INTERP, SELF);
99 VTABLE_set_pmc_keyed_int(INTERP, PARROT_CAPTURE(SELF)->array,
103 VTABLE void set_string_keyed_int(INTVAL key, STRING *value) {
104 CAPTURE_array_CREATE(INTERP, SELF);
105 VTABLE_set_string_keyed_int(INTERP, PARROT_CAPTURE(SELF)->array,
111 =item C<FLOATVAL get_number_keyed_int(INTVAL key)>
113 =item C<INTVAL get_integer_keyed_int(INTVAL key)>
115 =item C<PMC *get_pmc_keyed_int(INTVAL key)>
117 =item C<STRING *get_string_keyed_int(INTVAL key)>
119 Retrieves a value in the array component of the Capture.
125 VTABLE FLOATVAL get_number_keyed_int(INTVAL key) {
126 CAPTURE_array_CREATE(INTERP, SELF);
127 return VTABLE_get_number_keyed_int(INTERP, PARROT_CAPTURE(SELF)->array,
131 VTABLE INTVAL get_integer_keyed_int(INTVAL key) {
132 CAPTURE_array_CREATE(INTERP, SELF);
133 return VTABLE_get_integer_keyed_int(INTERP, PARROT_CAPTURE(SELF)->array,
137 VTABLE PMC *get_pmc_keyed_int(INTVAL key) {
138 CAPTURE_array_CREATE(INTERP, SELF);
139 return VTABLE_get_pmc_keyed_int(INTERP, PARROT_CAPTURE(SELF)->array,
143 VTABLE STRING *get_string_keyed_int(INTVAL key) {
144 CAPTURE_array_CREATE(INTERP, SELF);
145 return VTABLE_get_string_keyed_int(INTERP, PARROT_CAPTURE(SELF)->array,
151 =item C<void push_float(FLOATVAL value)>
153 =item C<void push_integer(INTVAL value)>
155 =item C<void push_pmc(PMC *value)>
157 =item C<void push_string(STRING *value)>
159 Push a value onto the array component of the Capture.
161 =item C<void unshift_float(FLOATVAL value)>
163 =item C<void unshift_integer(INTVAL value)>
165 =item C<void unshift_pmc(PMC *value)>
167 =item C<void unshift_string(STRING *value)>
169 Unshift a value onto the array component of the Capture.
175 VTABLE void push_float(FLOATVAL value) {
176 CAPTURE_array_CREATE(INTERP, SELF);
177 VTABLE_push_float(INTERP, PARROT_CAPTURE(SELF)->array, value);
180 VTABLE void push_integer(INTVAL value) {
181 CAPTURE_array_CREATE(INTERP, SELF);
182 VTABLE_push_integer(INTERP, PARROT_CAPTURE(SELF)->array, value);
185 void push_pmc(PMC *value) {
186 CAPTURE_array_CREATE(INTERP, SELF);
187 VTABLE_push_pmc(INTERP, PARROT_CAPTURE(SELF)->array, value);
190 VTABLE void push_string(STRING *value) {
191 CAPTURE_array_CREATE(INTERP, SELF);
192 VTABLE_push_string(INTERP, PARROT_CAPTURE(SELF)->array, value);
195 VTABLE void unshift_float(FLOATVAL value) {
196 CAPTURE_array_CREATE(INTERP, SELF);
197 VTABLE_unshift_float(INTERP, PARROT_CAPTURE(SELF)->array, value);
200 VTABLE void unshift_integer(INTVAL value) {
201 CAPTURE_array_CREATE(INTERP, SELF);
202 VTABLE_unshift_integer(INTERP, PARROT_CAPTURE(SELF)->array, value);
205 void unshift_pmc(PMC *value) {
206 CAPTURE_array_CREATE(INTERP, SELF);
207 VTABLE_unshift_pmc(INTERP, PARROT_CAPTURE(SELF)->array, value);
210 VTABLE void unshift_string(STRING *value) {
211 CAPTURE_array_CREATE(INTERP, SELF);
212 VTABLE_unshift_string(INTERP, PARROT_CAPTURE(SELF)->array, value);
217 =item C<FLOATVAL pop_float()>
219 =item C<INTVAL pop_integer()>
221 =item C<PMC *pop_pmc()>
223 =item C<STRING *pop_string()>
225 Pop a value from the array component of the Capture.
227 =item C<FLOATVAL shift_float()>
229 =item C<INTVAL shift_integer()>
231 =item C<PMC *shift_pmc()>
233 =item C<STRING *shift_string()>
235 Shift a value from the array component of the Capture.
241 VTABLE FLOATVAL pop_float() {
242 CAPTURE_array_CREATE(INTERP, SELF);
243 return VTABLE_pop_float(INTERP, PARROT_CAPTURE(SELF)->array);
246 VTABLE INTVAL pop_integer() {
247 CAPTURE_array_CREATE(INTERP, SELF);
248 return VTABLE_pop_integer(INTERP, PARROT_CAPTURE(SELF)->array);
251 VTABLE PMC *pop_pmc() {
252 CAPTURE_array_CREATE(INTERP, SELF);
253 return VTABLE_pop_pmc(INTERP, PARROT_CAPTURE(SELF)->array);
256 VTABLE STRING *pop_string() {
257 CAPTURE_array_CREATE(INTERP, SELF);
258 return VTABLE_pop_string(INTERP, PARROT_CAPTURE(SELF)->array);
261 VTABLE FLOATVAL shift_float() {
262 CAPTURE_array_CREATE(INTERP, SELF);
263 return VTABLE_shift_float(INTERP, PARROT_CAPTURE(SELF)->array);
266 VTABLE INTVAL shift_integer() {
267 CAPTURE_array_CREATE(INTERP, SELF);
268 return VTABLE_shift_integer(INTERP, PARROT_CAPTURE(SELF)->array);
271 VTABLE PMC *shift_pmc() {
272 CAPTURE_array_CREATE(INTERP, SELF);
273 return VTABLE_shift_pmc(INTERP, PARROT_CAPTURE(SELF)->array);
276 VTABLE STRING *shift_string() {
277 CAPTURE_array_CREATE(INTERP, SELF);
278 return VTABLE_shift_string(INTERP, PARROT_CAPTURE(SELF)->array);
283 =item C<INTVAL elements()>
285 Return the number of elements in the array component of the Capture.
287 =item C<INTVAL defined_keyed_int(INTVAL key)>
289 Return true if element C<key> of the array component is defined.
291 =item C<INTVAL exists_keyed_int(INTVAL key)>
293 Return true if element C<key> of the array component exists.
295 =item C<void delete_keyed_int(INTVAL key)>
297 Delete the element corresponding to C<key> in the array component.
303 VTABLE INTVAL elements() {
304 if (!PARROT_CAPTURE(SELF)->array) return 0;
305 return VTABLE_elements(INTERP, PARROT_CAPTURE(SELF)->array);
308 VTABLE INTVAL defined_keyed_int(INTVAL key) {
309 if (!PARROT_CAPTURE(SELF)->array)
312 return VTABLE_defined_keyed_int(INTERP, PARROT_CAPTURE(SELF)->array,
316 VTABLE INTVAL exists_keyed_int(INTVAL key) {
317 if (!PARROT_CAPTURE(SELF)->array)
320 return VTABLE_exists_keyed_int(INTERP, PARROT_CAPTURE(SELF)->array,
324 VTABLE void delete_keyed_int(INTVAL key) {
325 if (PARROT_CAPTURE(SELF)->array)
326 VTABLE_delete_keyed_int(INTERP, PARROT_CAPTURE(SELF)->array, key);
331 =item C<void set_number_keyed(PMC *key, FLOATVAL value)>
333 =item C<void set_integer_keyed(PMC *key, INTVAL value)>
335 =item C<void set_pmc_keyed(PMC *key, PMC *value)>
337 =item C<void set_string_keyed(PMC *key, STRING *value)>
339 Sets a value in the hash component of the Capture.
345 VTABLE void set_number_keyed(PMC *key, FLOATVAL value) {
346 CAPTURE_hash_CREATE(INTERP, SELF);
347 VTABLE_set_number_keyed(INTERP, PARROT_CAPTURE(SELF)->hash, key, value);
350 VTABLE void set_integer_keyed(PMC *key, INTVAL value) {
351 CAPTURE_hash_CREATE(INTERP, SELF);
352 VTABLE_set_integer_keyed(INTERP, PARROT_CAPTURE(SELF)->hash,
356 VTABLE void set_pmc_keyed(PMC *key, PMC *value) {
357 CAPTURE_hash_CREATE(INTERP, SELF);
358 VTABLE_set_pmc_keyed(INTERP, PARROT_CAPTURE(SELF)->hash, key, value);
361 VTABLE void set_string_keyed(PMC *key, STRING *value) {
362 CAPTURE_hash_CREATE(INTERP, SELF);
363 VTABLE_set_string_keyed(INTERP, PARROT_CAPTURE(SELF)->hash, key, value);
368 =item C<FLOATVAL get_number_keyed(PMC *key)>
370 =item C<INTVAL get_integer_keyed(PMC *key)>
372 =item C<PMC *get_pmc_keyed(PMC *key)>
374 =item C<STRING *get_string_keyed(PMC *key)>
376 Retrieves a value from the hash component of the Capture.
382 VTABLE FLOATVAL get_number_keyed(PMC *key) {
383 CAPTURE_hash_CREATE(INTERP, SELF);
384 return VTABLE_get_number_keyed(INTERP, PARROT_CAPTURE(SELF)->hash, key);
387 VTABLE INTVAL get_integer_keyed(PMC *key) {
388 CAPTURE_hash_CREATE(INTERP, SELF);
389 return VTABLE_get_integer_keyed(INTERP, PARROT_CAPTURE(SELF)->hash,
393 VTABLE PMC *get_pmc_keyed(PMC *key) {
394 CAPTURE_hash_CREATE(INTERP, SELF);
395 return VTABLE_get_pmc_keyed(INTERP, PARROT_CAPTURE(SELF)->hash, key);
398 VTABLE STRING *get_string_keyed(PMC *key) {
399 CAPTURE_hash_CREATE(INTERP, SELF);
400 return VTABLE_get_string_keyed(INTERP, PARROT_CAPTURE(SELF)->hash, key);
405 =item C<INTVAL defined_keyed(PMC *key)>
407 Return true if element C<key> of the hash component is defined.
409 =item C<INTVAL exists_keyed(PMC *key)>
411 Return true if element C<key> of the hash component exists.
413 =item C<void delete_keyed(PMC *key)>
415 Delete the element corresponding to C<key> in the hash component.
421 VTABLE INTVAL defined_keyed(PMC *key) {
422 if (!PARROT_CAPTURE(SELF)->hash) return 0;
423 return VTABLE_defined_keyed(INTERP, PARROT_CAPTURE(SELF)->hash, key);
426 VTABLE INTVAL exists_keyed(PMC *key) {
427 if (!PARROT_CAPTURE(SELF)->hash) return 0;
428 return VTABLE_exists_keyed(INTERP, PARROT_CAPTURE(SELF)->hash, key);
431 VTABLE void delete_keyed(PMC *key) {
432 if (PARROT_CAPTURE(SELF)->hash)
433 VTABLE_delete_keyed(INTERP, PARROT_CAPTURE(SELF)->hash, key);
438 =item C<void set_pmc(PMC *capture)>
440 Set this capture to hold the value of another.
446 void set_pmc(PMC *capture) {
447 if (VTABLE_isa(INTERP, capture, CONST_STRING(INTERP, "Capture"))) {
448 PARROT_CAPTURE(SELF)->array = PARROT_CAPTURE(capture)->array;
449 PARROT_CAPTURE(SELF)->hash = PARROT_CAPTURE(capture)->hash;
452 real_exception(INTERP, NULL, INVALID_OPERATION,
453 "Can only set a capture to another capture.");
470 /* XXX: This workaround is for when we get here as
471 part of a subclass of Capture */
472 if (PObj_is_object_TEST(SELF)) {
473 STRING *classname = CONST_STRING(INTERP, "Capture");
474 PMC *classobj = Parrot_oo_get_class_str(INTERP, classname);
475 STRING *attribute = CONST_STRING(interp, "proxy");
476 capt = VTABLE_get_attr_keyed(interp, SELF, classobj, attribute);
479 CAPTURE_array_CREATE(INTERP, capt);
480 capt_array = PARROT_CAPTURE(capt)->array;
482 RETURN(PMC *capt_array);
488 /* XXX: This workaround is for when we get here as
489 part of a subclass of Capture */
490 if (PObj_is_object_TEST(SELF)) {
491 STRING *classname = CONST_STRING(INTERP, "Capture");
492 PMC *classobj = Parrot_oo_get_class_str(INTERP, classname);
493 STRING *attribute = CONST_STRING(interp, "proxy");
494 capt = VTABLE_get_attr_keyed(interp, SELF, classobj, attribute);
496 CAPTURE_hash_CREATE(INTERP, capt);
497 capt_hash = PARROT_CAPTURE(capt)->hash;
498 RETURN(PMC *capt_hash);
509 Initial version - Patrick Michaud 2006-11-03
517 * c-file-style: "parrot"
519 * vim: expandtab shiftwidth=4: