> On Tue, Nov 11, 2008 at 11:03:09PM -0600, Chris Dolan wrote:
>> I'm thinking ahead to the Parrot equivalent of Perl::Critic, which I
>> hope will someday be able to analyze arbitrary .pbc files.  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?
>
> I'm having trouble understanding "anonymous methods invented by
> the compiler" in this context, probably because in a Perl 6
> sense I don't think of inner blocks as being "invented" by the
> compiler.  They're right there in the code where the programmer
> wrote them.
>
> Perhaps you could clarify what you mean by "inner block" here?
>
> Pm

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';
   }

The former results in a trivial entry in the call graph (exactly one
caller) while the latter can cause arbitrarily complexity in the call
graph.  So, a static analysis tool has to work much harder on the latter. 
I thought it would be a useful shortcut if the compiler would add a flag
to help distinguish the two cases, so I wouldn't have to include the first
example above in the call graph at all.

Chris

Reply via email to