A bit more detail on the conversion process for a PMC:

1) Find the core data of the PMC, and convert it into a series of ATTR
statement at the beginning of the "pmclass" block. So, if the PMC uses
only 'PMC_int_val', create a single entry: 'ATTR INTVAL integer_data;'
(Pick a meaningful name, and add a comment at the end of the line
explaining what it is. A good example is src/pmc/eventhandler.pmc.)

If the core data of the PMC is a whole struct stored in PMC_data, you
can directly copy the body of that struct into the .pmc file, and just
prepend ATTR to each line.

2) Change any calls to PMC_int_val (or whatever macro the particular PMC
uses) to 'GET_ATTR_integer_data' or 'SET_ATTR_integer_data' (the
lower-case half of the accessor macros matches the name you gave the
attribute in the 'ATTR' declaration.) If your attribute is a
PMC/STRING/INTVAL/FLOATVAL type, the accessor is generated to correctly
set/retrieve the native type directly. These macros must be used on a
separate line, and can't be embedded within other C code on a line. See
src/pmc/exporter.pmc for an example. So this is correct:

GET_ATTR_ns_src(interp, SELF, tmp_ns_src);

but this is wrong:

tmp_ns_src = GET_ATTR_ns_src(interp, SELF);

3) Change 'init' and 'init_pmc' to initialize the auto-generated struct
instead of whatever initialization it was doing before. For example, if
it was previously setting a default value in PMC_int_val, it now needs
to allocate a struct of the appropriate type (the autogenerated structe
is always named Parrot_<PMCname>, so the Exporter PMC has a struct named
Parrot_Exporter), store that struct in PMC_data, and then set default
values on the struct. See src/pmc/exporter.pmc for a good example of
'init'. 

4) Any place you need to directly access the core struct of the PMC, use
the accessor macro for the PMC's struct. It is named the same as the
struct but in all caps (for example, the Exporter PMC's accessor macro
for the core data struct used like 'Parrot_Exporter *core_struct =
PARROT_EXPORTER(SELF);').

5) Change 'destroy' to destroy PMC_data.

6) Change 'mark' to mark any PMC elements of the core data struct.

7) Check 'freeze'/'thaw' and related vtable entries for direct access to
old data elements and update it to the new data elements.

That should get you 90-95% of the way there. Rebuild the PMC (make sure
the src/pmc/pmc_<PMCname>.h header file for the PMC was regenerated to
include the Parrot_<PMCname> struct GETATTR and SETATTR macros). Check
for compile errors and test failures. If the cause of any errors isn't
immediately obvious, check with allison or chromatic.

Allison

Reply via email to