2 Copyright (C) 2001-2010, Parrot Foundation.
7 src/pmc/packfilefixuptable.pmc - PackfileFixupTable PMC
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.
27 /* HEADERIZER HFILE: none */
28 /* HEADERIZER BEGIN: static */
29 /* HEADERIZER END: static */
31 pmclass PackfileFixupTable auto_attrs extends PackfileSegment {
39 Create empty PackfileFixupTable.
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);
58 Marks the object as live.
65 Parrot_PackfileFixupTable_attributes * attrs =
66 PARROT_PACKFILEFIXUPTABLE(SELF);
68 Parrot_gc_mark_PMC_alive(INTERP, attrs->entries);
75 =item C<void set_pointer(void *pointer)>
77 Initialize from PackFile_FixupTable pointer.
83 VTABLE void set_pointer(void * pointer) {
84 Parrot_PackfileFixupTable_attributes * attrs =
85 PARROT_PACKFILEFIXUPTABLE(SELF);
86 PackFile_FixupTable * table = (PackFile_FixupTable*)pointer;
89 PackFile_FixupEntry *val;
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);
104 =item C<void *get_pointer()>
106 Create PackFile_FixupTable* from self.
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);
117 PackFile_FixupEntry * val;
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);
139 =item C<INTVAL elements()>
141 Get the number of elements in the array.
146 VTABLE INTVAL elements() {
147 return VTABLE_elements(INTERP,
148 PARROT_PACKFILEFIXUPTABLE(SELF)->entries);
154 =item C<PMC *get_pmc_keyed_int(INTVAL index)>
156 Fetch the given PackfileFixupEntry PMC.
161 VTABLE PMC *get_pmc_keyed_int(INTVAL index) {
162 return VTABLE_get_pmc_keyed_int(INTERP,
163 PARROT_PACKFILEFIXUPTABLE(SELF)->entries, index);
169 =item C<void set_pmc_keyed_int(INTVAL index, PMC *value)>
171 Store a PackfileFixupEntry PMC to the given slot.
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);
184 =item C<METHOD type()>
193 RETURN(INTVAL PF_FIXUP_SEG);
207 * c-file-style: "parrot"
209 * vim: expandtab shiftwidth=4: