develooper Front page | perl.perl5.porters | Postings from November 2017

Signature parsing compiler functions

Thread Next
Paul "LeoNerd" Evans
November 14, 2017 00:44
Signature parsing compiler functions
Message ID:
Currently in the implementation of Future::AsyncAwait's syntax parsing,
I have to manually handle 'sub NAME { BLOCK }' parsing, because I need
to get at the optree before it's been checked and installed into the
CV, and no bits of perl API currently exist to let me do that.

As a result, what I currently do is special-case handling of two cases

  async sub NAME { BLOCK }   # as a statement
  async sub { BLOCK }        # as an expression

I specifically don't handle prototypes, attributes, or signatures at

While we're on the subject of signatures in other threads, I wonder if I
could ask for a little bit of extra API to help me here. What would be
very nice is a pair of functions whose prototypes might look something

  void *parse_signature(void);  /* returns a "cookie" */
  OP *gen_signature_unpack(void *cookie);

The idea here being that at the point in syntax where I might encounter
a signature I can just call the first, and if it returned a non-NULL
then when I'm about to parse the block I first call the second which
gives me the initial bit of optree which performs whatever steps are
necessary. The two can communicate via that void *cookie.

As-yet unanswered questions are whether these functions would need any
more arguments to tell them what to do, what implicit assumptions they
make about interpreter variables, and also how they handle errors - who
frees the cookie if we abort?

The addition of some functions of roughly this shape would be very
helpful to me to enabling async (named or anonymous) subs with
signatures, by offloading the parsing back to perl itself.

Paul "LeoNerd" Evans      |  |

Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About