Historically Parrot has considered a compiler to be an
invokable subroutine, such that the canonical sequence for
compiling something is:

    .local string perl6_source
    .local pmc perl6_compiler
    perl6_compiler = compreg 'Perl6'
    $P0 = perl6_compiler(perl6_source)

However, pdd21_namespaces.pod says that compilers have
methods such as 'parse_name', 'get_namespace', and 'load_library'
(see the section titled "Compiler PMC API").

Recognizing that much of the details about compilers are still to
be specced, the naive version of my question is:  "How do we get 
those API methods (and possibly other compiler-specific methods)
attached to the compiler sub?"  

Or, in claiming that compilers have an API, should we instead
say that the canonical compilation sequence is to use compreg
to obtain a compiler object (not an invokable sub), and then
compile the source via a 'compile' method on the compiler object?
For example:

    perl6_compiler = compreg 'Perl6'
    $P0 = perl6_compiler.'compile'(perl6_source)

In asking the above questions I'm purposely avoiding, because Parrot
doesn't seem to support it yet, the possibility that the object
obtained via compreg is both invokable in its own right (like a sub)
and has methods attached to it.  I'm simply curious as to how we
conceptually model "compilers" in Parrot -- are they really like
subroutines or are they more traditional 'objects' that provide
a method-based interface for invoking a compilation.

Opinions welcome.  Personally I think I favor the "a compiler is
an object with a 'compile' method" model, and that C<compreg> gives
us back a compiler object as opposed to a subroutine-like thing.

Thanks in advance,

Pm

Reply via email to