develooper Front page | perl.perl5.porters | Postings from July 2009

Rvalue given() blocks

Thread Next
From:
Vincent Pit
Date:
July 19, 2009 15:18
Subject:
Rvalue given() blocks
Message ID:
4A639B88.4000003@profvince.com
Just as the title says, this patch makes given() blocks return values,
with the following rules :
- if an explicit break is encountered, return an empty list ;
- if a when/default clause is true (and doesn't contain an explicit
break), return the value of the last evaluated expression of the block ;
- if all conditions were false, return the value of the last evaluated
expression of the block.
I've also made when/default not return anything (unlike 'if' and
'unless' which returns the value of the condition).

Regarding the implementation, I added 'switch' to the 'term' rule. This
made the YYLAST value increase a lot :

-#define YYLAST   2061
+#define YYLAST   2446

I'm not a bison specialist, so I'd like to know if there isn't some kind
of heavy penalty hidden there.

Then I made scalar()/list() correctly propagate into given/when OPs.
There's very little run-time changes. pp_leavegiven() was just taught to
correctly set the stack pointer. It also mimics pp_leavetry() to make
sure that all the stack elements are correctly tainted/mortalized.

Vincent.

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About