| Store | Cart

[perl #123009] expose functions for creating blocks and local variables

From: Father Chrysostomos via RT <perl...@perl.org>
Sun, 19 Oct 2014 17:05:44 -0700
On Sun Oct 19 14:48:15 2014, mauke- wrote:
> On Sun Oct 19 07:04:15 2014, sprout wrote:> > On Sun Oct 19 01:46:40 2014, mauke- wrote:> > >> > > What's missing:> > > - newDEFSVOP (for generating the $_ in 'do_stuff_with($_) for> > > @values')> > > - intro_my (for declaring lexical variables)> > > - block_start (for opening a block)> > > - block_end (for closing a block)> > >> > > It would be nice if those functions (or an equivalent API) could be> > > made public.> >> > We usually don’t apify these without tests.  Would you be willing to> > provide tests (using XS::APItest)?> > I don't know where to start with this. In fact, I'm not entirely sure> what those functions even do.

Well, that makes two of us. :-)

OK, I do know a bit more than that.  block_start arranges for hints to be restored on block exit and also handles pad sequence numbers, to make sure ‘my’ variables go out of scope and that ‘my’ variables declared in the containing statement (e.g., my $x, do{...}) don’t accidentally become visible inside the block.

block_end is passed the return value of block_start (the savestack index) and the body of the block itself.  It handles compile-time scope exit and returns the block, possibly modified.  (Part of what it does is to call scalarseq on the body of the block, but I don’t understand what scalarseq does.)

intro_my is sufficiently described by its documentation in perlintern.pod:

"Introduce" my variables to visible status.  This is called during parsing
at the end of each statement to make lexical variables visible to
subsequent statements.

> I basically just cargo-culted their> usage from what the perl compiler itself does. (And a test should> probably also include interesting corner cases - no idea what those> would look like here.)

Edge cases are icing on the cake.  They are not necessary to get something into the API.

Some simplified code stolen from Function::Parameters would do.

-- 

Father Chrysostomos


---
via perlbug:  queue: perl5 status: open
https://rt.perl.org/Ticket/Display.html?id=123009

Recent Messages in this Thread
perl...@perl.org Oct 19, 2014 08:46 am
Father Chrysostomos via RT Oct 19, 2014 02:04 pm
perl...@perl.org Oct 19, 2014 09:48 pm
perl...@perl.org Oct 24, 2014 11:32 pm
perl...@perl.org Oct 26, 2014 10:49 am
Leon Timmermans Oct 28, 2014 11:41 pm
Father Chrysostomos via RT Oct 29, 2014 01:05 am
Father Chrysostomos via RT Oct 25, 2014 12:53 am
Father Chrysostomos via RT Oct 25, 2014 04:28 am
perl...@perl.org Oct 25, 2014 12:17 pm
Father Chrysostomos via RT Oct 25, 2014 01:59 pm
Father Chrysostomos via RT Oct 25, 2014 06:58 pm
perl...@perl.org Oct 25, 2014 07:00 pm
perl...@perl.org Oct 25, 2014 07:55 pm
Father Chrysostomos via RT Oct 25, 2014 08:14 pm
Father Chrysostomos via RT Oct 25, 2014 08:06 pm
Father Chrysostomos via RT Oct 20, 2014 12:05 am
perl...@perl.org Oct 20, 2014 07:00 pm
Father Chrysostomos via RT Oct 26, 2014 07:43 pm
Messages in this thread