Since I'm working on this now, I figure I'd best give everyone a heads-up
as to what I'm doing.

Right now, I'm working on loading PMCs, both dynamic and static, and the
initialization sequence they go through. I know we've got some of this
down already, but adding in MMD and the need to initialize tables and
potentially defer things for later class loading means I'm needing to
wedge things in, so the whole process seems like it ought to be
documented. Once any issues with this design are cleared up, we'll do
that. :)

Firstly, we're adding a new method INIT to the .pmc file. *If* it exists
when the .pmc source is parsed, it will be called as the very last action
of the initialization routine. It gets two parameters, the interpreter and
the number assigned to the pmc class. It may do whatever the heck you
want, though generally I expect they'll install MMD functions.

Next, the sequence of loading.

Right now there's a load_pmc op, which goes along with the load_opcode_lib
and loadlib ops. I'd like to unify that--I'm not too thrilled with having
three different "load this external C library and call custom routine X",
so... we're not going to do that. We are, instead, going to toss
load_opcode_lib and load_pmc, and ramp back to a single loadlib opcode.
All loadlib does is use the dynamic loading facilities of the platform to
load in the library.

When we load a library, the bytecode should probe for and, if it exists,
call Parrot_lib_load_%s, where %s is the library name. It takes a single
parameter, the interpreter, and returns a PMC representing the library
that we can query later.

The bytecode should also probe for and, if it exists, call
Parrot_lib_init_%s, where %s is the library name. This takes two
parameters, the interpreter and the PMC that _lib_load_ returned, and
returns a single PMC that represents the per-thread data for the library.

If, and only if, Parrot_lib_init_%s exists, then the bytecode should call
the thread_register op, which I'll add. This takes two parameters, the
_init routine PMC and the _load returned PMC, and stores it away. Whenever
this interpreter is cloned, the function will be called and passed in the
new interpreter and the _load PMC, so the library can do per-thread
initialization.

All registration of opcode libraries, PMCs, and whatnot should be done
from within the _load routine. If a library has a dozen different PMCs,
well... great. Load 'em all in. We don't do any filtering or whatnot here
(I think) just calling it and letting it do its thing. If we want to
define some sort of language conventions, great, we can do that.

I'm definitely up for the argument that this should all be in a single op,
and that loadlib should load up the library and conditionally call the two
functions, as well as doing only-once checking so the libs don't get
multiply loaded. If you want to make a case, well, now'd be a good time
for that.

I'll get to the PMC registration bit in another message.

                                                Dan

Reply via email to