changed interp in pmc class to INTERP for unification
[parrot.git] / src / pmc / packfilefixuptable.pmc
blob5953d0efcec2de05481c89eca0ccdd4e9ccca9ca
1 /*
2 Copyright (C) 2001-2010, Parrot Foundation.
3 $Id$
5 =head1 NAME
7 src/pmc/packfilefixuptable.pmc - PackfileFixupTable PMC
9 =head1 DESCRIPTION
11 This class implements a PackfileFixupTable object, a segment of the .pbc
12 data file storing an array of PackfileFixupEntry PMCs.
14 See packfile.pmc for the toplevel Packfile interface, see packfilesegment.pmc
15 for the list of common methods every packfile segment pmc must implement; see
16 PDD13 for the design spec.
19 =head2 Methods
21 =over 4
23 =cut
27 /* HEADERIZER HFILE: none */
28 /* HEADERIZER BEGIN: static */
29 /* HEADERIZER END: static */
31 pmclass PackfileFixupTable auto_attrs extends PackfileSegment {
32     /* RPA of entries */
33     ATTR PMC *entries;
37 =item C<init>
39 Create empty PackfileFixupTable.
41 =cut
45     VTABLE void init() {
46         Parrot_PackfileFixupTable_attributes * attrs =
47                 PMC_data_typed(SELF, Parrot_PackfileFixupTable_attributes*);
49         attrs->entries = Parrot_pmc_new(INTERP, enum_class_ResizablePMCArray);
51         PObj_custom_mark_SET(SELF);
52     }
56 =item C<void mark()>
58 Marks the object as live.
60 =cut
64     VTABLE void mark() {
65         Parrot_PackfileFixupTable_attributes * attrs =
66                 PARROT_PACKFILEFIXUPTABLE(SELF);
68         Parrot_gc_mark_PMC_alive(INTERP, attrs->entries);
70         SUPER();
71     }
75 =item C<void set_pointer(void *pointer)>
77 Initialize from PackFile_FixupTable pointer.
79 =cut
83     VTABLE void set_pointer(void * pointer) {
84         Parrot_PackfileFixupTable_attributes * attrs =
85                 PARROT_PACKFILEFIXUPTABLE(SELF);
86         PackFile_FixupTable * table = (PackFile_FixupTable*)pointer;
88         PMC                 *entry;
89         PackFile_FixupEntry *val;
90         opcode_t             i;
92         VTABLE_set_integer_native(INTERP, attrs->entries, table->fixup_count);
94         for (i = 0; i < table->fixup_count; ++i) {
95             val = table->fixups + i;
96             entry = Parrot_pmc_new(INTERP, enum_class_PackfileFixupEntry);
97             VTABLE_set_pointer(INTERP, entry, (void*)val);
98             VTABLE_set_pmc_keyed_int(INTERP, attrs->entries, i, entry);
99         }
100     }
104 =item C<void *get_pointer()>
106 Create PackFile_FixupTable* from self.
108 =cut
111     VTABLE void *get_pointer() {
112         Parrot_PackfileFixupTable_attributes * attrs =
113                 PARROT_PACKFILEFIXUPTABLE(SELF);
114         PackFile_FixupTable * pftable =
115                 mem_gc_allocate_zeroed_typed(INTERP, PackFile_FixupTable);
116         PMC                 * entry;
117         PackFile_FixupEntry * val;
118         opcode_t              i;
120         pftable->base.type   = PF_FIXUP_SEG;
121         pftable->fixup_count = VTABLE_elements(INTERP, attrs->entries);
122         pftable->fixups      = mem_gc_allocate_n_typed(INTERP,
123                 pftable->fixup_count, PackFile_FixupEntry);
125         /* Copy all entries */
126         for (i = 0; i < pftable->fixup_count; ++i) {
127             entry = VTABLE_get_pmc_keyed_int(INTERP, attrs->entries, i);
128             val   = (PackFile_FixupEntry*)VTABLE_get_pointer(INTERP, entry);
129             pftable->fixups[i] = *val;
130             mem_gc_free(INTERP, val);
131         }
133         return pftable;
134     }
139 =item C<INTVAL elements()>
141 Get the number of elements in the array.
143 =cut
146     VTABLE INTVAL elements() {
147         return VTABLE_elements(INTERP,
148                 PARROT_PACKFILEFIXUPTABLE(SELF)->entries);
149     }
154 =item C<PMC *get_pmc_keyed_int(INTVAL index)>
156 Fetch the given PackfileFixupEntry PMC.
158 =cut
161     VTABLE PMC *get_pmc_keyed_int(INTVAL index)  {
162         return VTABLE_get_pmc_keyed_int(INTERP,
163             PARROT_PACKFILEFIXUPTABLE(SELF)->entries, index);
164     }
169 =item C<void set_pmc_keyed_int(INTVAL index, PMC *value)>
171 Store a PackfileFixupEntry PMC to the given slot.
173 =cut
176     VTABLE void set_pmc_keyed_int(INTVAL index, PMC *value)  {
177         VTABLE_set_pmc_keyed_int(INTERP,
178                 PARROT_PACKFILEFIXUPTABLE(SELF)->entries, index, value);
179     }
184 =item C<METHOD type()>
186 Set segment type.
188 =cut
192     METHOD type() {
193         RETURN(INTVAL PF_FIXUP_SEG);
194     }
199 =back
201 =cut
206  * Local variables:
207  *   c-file-style: "parrot"
208  * End:
209  * vim: expandtab shiftwidth=4:
210  */