2 Copyright (C) 2001-2008, Parrot Foundation.
7 src/pmc/packfileannotation.pmc - PackfileAnnotation PMC
11 This class implements a PackfileAnnotation object. It is an element in the
12 PackfileAnnotations segment of the .pbc file. See PDD13 for a design spec.
22 pmclass PackfileAnnotation auto_attrs {
25 ATTR INTVAL value_type;
26 /* This 3 attributes should be in single union. But Pmc2c isn't smart enough to handle it */
27 ATTR INTVAL int_value;
28 ATTR FLOATVAL num_value;
29 ATTR STRING *str_value;
35 Create empty PackfileAnnotation.
42 Parrot_PackfileAnnotation_attributes * attrs =
43 PMC_data_typed(SELF, Parrot_PackfileAnnotation_attributes*);
45 PObj_custom_mark_SET(SELF);
46 PMC_data(SELF) = attrs;
53 Marks the object as live.
60 Parrot_PackfileAnnotation_attributes * attrs =
61 PARROT_PACKFILEANNOTATION(SELF);
63 Parrot_gc_mark_STRING_alive(interp, attrs->name);
64 Parrot_gc_mark_STRING_alive(interp, attrs->str_value);
70 =item C<INTVAL get_offset()>
72 Fetch the offset into the bytecode of the instruction that is being annotated.
78 INTVAL offset = PARROT_PACKFILEANNOTATION(SELF)->offset;
79 RETURN(INTVAL offset);
85 =item C<void set_offset(INTVAL offset)>
87 Set the offset into the bytecode of the instruction that is being annotated.
92 METHOD set_offset(INTVAL offset) {
93 PARROT_PACKFILEANNOTATION(SELF)->offset = offset;
99 =item C<STRING* get_name()>
101 Fetch the name of the annotation.
107 STRING * name = PARROT_PACKFILEANNOTATION(SELF)->name;
108 RETURN(STRING * name);
114 =item C<void set_name(STRING* name)>
116 Set the name of the annotation.
121 METHOD set_name(STRING * name) {
122 PARROT_PACKFILEANNOTATION(SELF)->name = name;
128 =item C<INTVAL get_integer()>
130 Fetch the integer value of the annotation.
135 VTABLE INTVAL get_integer() {
136 Parrot_PackfileAnnotation_attributes * attrs = PARROT_PACKFILEANNOTATION(SELF);
137 if (attrs->value_type != PF_ANNOTATION_KEY_TYPE_INT)
138 Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_INVALID_OPERATION,
139 "Trying to fetch wrong type of value from annotation");
140 return attrs->int_value;
146 =item C<void set_integer_native(INTVAL value)>
148 Set the integer value of the annotation.
153 VTABLE void set_integer_native(INTVAL value) {
154 Parrot_PackfileAnnotation_attributes * attrs = PARROT_PACKFILEANNOTATION(SELF);
155 attrs->value_type = PF_ANNOTATION_KEY_TYPE_INT;
156 attrs->int_value = value;
161 =item C<STRING * get_string()>
163 Fetch the string value of the annotation.
168 VTABLE STRING * get_string() {
169 Parrot_PackfileAnnotation_attributes * attrs = PARROT_PACKFILEANNOTATION(SELF);
170 if (attrs->value_type != PF_ANNOTATION_KEY_TYPE_STR)
171 Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_INVALID_OPERATION,
172 "Trying to fetch wrong type of value from annotation");
173 return attrs->str_value;
179 =item C<void set_string_native(STRING * value)>
181 Set the string value of the annotation.
186 VTABLE void set_string_native(STRING * value) {
187 Parrot_PackfileAnnotation_attributes * attrs = PARROT_PACKFILEANNOTATION(SELF);
188 attrs->value_type = PF_ANNOTATION_KEY_TYPE_STR;
189 attrs->str_value = value;
194 =item C<INTVAL get_number()>
196 Fetch the float value of the annotation.
201 VTABLE FLOATVAL get_number() {
202 Parrot_PackfileAnnotation_attributes * attrs = PARROT_PACKFILEANNOTATION(SELF);
203 if (attrs->value_type != PF_ANNOTATION_KEY_TYPE_NUM)
204 Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_INVALID_OPERATION,
205 "Trying to fetch wrong type of value from annotation");
206 return attrs->num_value;
212 =item C<void set_number_native(INTVAL value)>
214 Set the float value of the annotation.
219 VTABLE void set_number_native(FLOATVAL value) {
220 Parrot_PackfileAnnotation_attributes * attrs = PARROT_PACKFILEANNOTATION(SELF);
221 attrs->value_type = PF_ANNOTATION_KEY_TYPE_NUM;
222 attrs->num_value = value;
236 * c-file-style: "parrot"
238 * vim: expandtab shiftwidth=4: