On Mon, Jul 24, 2006 at 01:03:41PM -0700, Chip Salzenberg wrote: > On Wed, Jul 12, 2006 at 10:25:43AM -0700, Allison Randal wrote: > > It occurs to me, after thinking about it overnight, that the .loadlib > > directive shouldn't operate at :immediate time, but at :init time, > > because it's more common to want a library to load when you run the code > > than to load only when you compile the code. > > > > Which leaves us with :immediate for the rare cases when you really want > > to load a library at compile time. > > Oddly enough, while :init is obviously a good thing, it does not exist.
However, as discussed briefly at Sunday's hackathon, it would be really nice if we had some sort of pragma (I propose :init) that indicates a subroutine is to be executed whenever the sub is loaded, whether that occurs via a load_bytecode or because a module is being run directly from parrot. Background: Currently we have :main, :load, and :immediate pragmas. A sub marked ":main" is executed when a .pir or .pbc file is called directly from the parrot command line, but are not automatically called when that file is obtained via load_bytecode. A sub marked ":load" is executed when a .pir or .pbc file is called via load_bytecode, but not when the .pir/.pbc is loaded from the command line. I'd like there to be an :init pragma to mark subs that are to be executed anytime the file is loaded. In the case of loading from the command line, the :init subs should be executed prior to the :main sub. (Currently the .pir/.pbc files I write work around this by explicitly calling the :load subs from the :main one. While this is workable when there's just one such sub, it requires a bit more work when the .pir or .pbc is being produced from several (often generated) sources.) Note that :init as I've proposed is not the same as writing ":main :load", since only one :main sub is executed (whereas there could be multiple :init subs). Pm