On Wed, Nov 12, 2008 at 12:53:24PM -0600, Chris Dolan wrote: > > On Tue, Nov 11, 2008 at 11:03:09PM -0600, Chris Dolan wrote: > >> One problem I foresee is that there seems to be no way to > >> distinguish anonymous subs ("my $f = sub { 1 };") from inner > >> blocks. Both compile down to something like this: > >> > >> .sub "_block16" :anon :lexid("23") :outer("21") > >> > >> Would it be feasible to add a new PIR adverb to mark anonymous methods > >> invented by the compiler so we can easily tell them apart from anonymous > >> methods invented by the programmer? > > > > Perhaps you could clarify what you mean by "inner block" here? > > Sorry, I'm having trouble finding the right vocabulary. The following > should make more sense: > > Both of the following code snippets result in a PIR .sub that is annotated > as :anon > > if True { say 'Hello'; } > vs. > my $f = { say 'Hello'; }
Ah. In Perl 6 the first is called a "bare block"; in PCT we call it an "immediate block". So, it sounds like you're wanting a way to distinguish immediate blocks from other types of blocks. It would be no problem to have PCT add a flag to subs generated from immediate blocks, but we'd have to modify PIR (IMCC) to be able to recognize the new flag and attach it to the Sub somehow. A slightly different approach would be to have PCT generate :load/:init code to attach a property to the Sub PMC at runtime... but I suspect that might not help as much with static analysis of a .pbc file, since the property wouldn't be present until after the .pbc itself is loaded. And with the current design of Parrot there are other properties (e.g., signature) that don't get attached to blocks until after the module is loaded. So, perhaps what we need is a way in PIR to attach compile-time properties to blocks. But that's really a Parrot design question more than a Rakudo/PCT question, so perhaps we should re-post this question and thread to the parrot-dev list. Thanks! Pm