OVERVIEW ^

This is a build directory for custom PMCs with a sample foo.pmc providing the Foo PMC class.

CREATING A DYNAMIC PMC ^

  1. Edit/create your foo.pmc source - For details on creating PMCs, see "classes/genclass.pl" in ..
  2. There are some differences you have to be aware of when creating dynamic PMCs.

    When declaring the dynamic pmc, you must specify the dynpmc flag, as in:

            pmclass TclString extends tclobject dynpmc { ... }

    Note that regular (non-dynamic) PMCs have a type id enum_class_PMCNAME, but dynamic PMCs obviously cannot use the same thing. Instead, a dynamically-chosen value is assigned at runtime - so, when you refer to the type of the class , you must dynamically determine the PMC type. So, while perlscalar (a builtin) has the luxury of knowing at compile time what the class number of its child PerlString is, for example:

            if (type == enum_class_PerlString) {

    A dynamic PMC such as tclobject must instead perform a runtime lookup of its corresponding TclString PMC, resulting in the more complicated:

            if (type == pmc_type(
                    interpreter,
                    string_from_cstring(interpreter, "TclString", 9))
               )

    Finally, if you have a group of PMCs that are interdependent, use the group GROUPNAME syntax to trigger a group library to built. You will use the group name as the name of the library to load using the PASM op loadlib.

            pmclass Match extends PerlHash dynpmc group match_group { ... }

    and then in your .imc or .pasm file:

            loadlib $P0, "match_group"
  3. edit ../config/gen/makefiles/dynclasses.in and append your PMC(s) to the build target.
  4.         $ make
            $ make shared
            $ cd dynclasses; make
  5. Try the sample dynamic class, Foo. Note that the numbers listed here will change over time.
  6.         $ ./parrot dynclasses/dynfoo.pasm
            ok 1
            41
            ok 2
            42
  7. There are two other similar test files: dynmatch.pasm and dyntcl.pasm. They do pretty much the same thing as dynfoo, but they load in PMC group libraries instead of a standalone PMC library.
  8. If anything changes inside parrot, be sure to:

            $ cd dynclasses; make clean


parrot