/
packfileannotation.pmc
209 lines (133 loc) · 3.95 KB
/
packfileannotation.pmc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
/*
Copyright (C) 2001-2011, Parrot Foundation.
=head1 NAME
src/pmc/packfileannotation.pmc - PackfileAnnotation PMC
=head1 DESCRIPTION
This class implements a PackfileAnnotation object. It is an element in the
PackfileAnnotations segment of the .pbc file. See PDD13 for a design spec.
=head2 Methods
=over 4
=cut
*/
/* HEADERIZER HFILE: none */
/* HEADERIZER BEGIN: static */
/* HEADERIZER END: static */
pmclass PackfileAnnotation auto_attrs {
ATTR STRING *name;
ATTR INTVAL offset;
ATTR INTVAL value_type;
/* This 3 attributes should be in single union. But Pmc2c isn't smart enough to handle it */
ATTR INTVAL int_value;
ATTR STRING *str_value;
ATTR PMC *pmc_value;
/*
=item C<init>
Create empty PackfileAnnotation.
=cut
*/
VTABLE void init() {
Parrot_PackfileAnnotation_attributes * const attrs =
PMC_data_typed(SELF, Parrot_PackfileAnnotation_attributes*);
PObj_custom_mark_SET(SELF);
PMC_data(SELF) = attrs;
}
/*
=item C<void mark()>
Marks the object as live.
=cut
*/
VTABLE void mark() {
const Parrot_PackfileAnnotation_attributes * const attrs =
PARROT_PACKFILEANNOTATION(SELF);
Parrot_gc_mark_STRING_alive(INTERP, attrs->name);
Parrot_gc_mark_STRING_alive(INTERP, attrs->str_value);
}
/*
=item C<INTVAL get_offset()>
Fetch the offset into the bytecode of the instruction that is being annotated.
=cut
*/
METHOD get_offset() {
const INTVAL offset = PARROT_PACKFILEANNOTATION(SELF)->offset;
RETURN(INTVAL offset);
}
/*
=item C<void set_offset(INTVAL offset)>
Set the offset into the bytecode of the instruction that is being annotated.
=cut
*/
METHOD set_offset(INTVAL offset) {
PARROT_PACKFILEANNOTATION(SELF)->offset = offset;
}
/*
=item C<STRING* get_name()>
Fetch the name of the annotation.
=cut
*/
METHOD get_name() {
STRING * const name = PARROT_PACKFILEANNOTATION(SELF)->name;
RETURN(STRING * name);
}
/*
=item C<void set_name(STRING* name)>
Set the name of the annotation.
=cut
*/
METHOD set_name(STRING * name) {
PARROT_PACKFILEANNOTATION(SELF)->name = name;
}
/*
=item C<INTVAL get_integer()>
Fetch the integer value of the annotation.
=cut
*/
VTABLE INTVAL get_integer() {
const Parrot_PackfileAnnotation_attributes * const attrs = PARROT_PACKFILEANNOTATION(SELF);
if (attrs->value_type != PF_ANNOTATION_KEY_TYPE_INT)
Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_INVALID_OPERATION,
"Trying to fetch wrong type of value from annotation");
return attrs->int_value;
}
/*
=item C<void set_integer_native(INTVAL value)>
Set the integer value of the annotation.
=cut
*/
VTABLE void set_integer_native(INTVAL value) {
Parrot_PackfileAnnotation_attributes * const attrs = PARROT_PACKFILEANNOTATION(SELF);
attrs->value_type = PF_ANNOTATION_KEY_TYPE_INT;
attrs->int_value = value;
}
/*
=item C<STRING * get_string()>
Fetch the string value of the annotation.
=cut
*/
VTABLE STRING * get_string() {
Parrot_PackfileAnnotation_attributes * const attrs = PARROT_PACKFILEANNOTATION(SELF);
if (attrs->value_type != PF_ANNOTATION_KEY_TYPE_STR)
Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_INVALID_OPERATION,
"Trying to fetch wrong type of value from annotation");
return attrs->str_value;
}
/*
=item C<void set_string_native(STRING * value)>
Set the string value of the annotation.
=cut
*/
VTABLE void set_string_native(STRING * value) {
Parrot_PackfileAnnotation_attributes * const attrs = PARROT_PACKFILEANNOTATION(SELF);
attrs->value_type = PF_ANNOTATION_KEY_TYPE_STR;
attrs->str_value = value;
}
}
/*
=back
=cut
*/
/*
* Local variables:
* c-file-style: "parrot"
* End:
* vim: expandtab shiftwidth=4 cinoptions='\:2=2' :
*/