Catch rogue returns in top-level

This commit is contained in:
madmaurice 2021-04-08 21:47:57 +02:00
parent 8bdc8232f9
commit f50550f882

View file

@ -428,7 +428,20 @@ sub parser_prog {
return sub {
my $ctx = shift;
my $result;
$result = $_->($ctx) foreach (@steps);
eval {
$result = $_->($ctx) foreach (@steps);
};
if ($@)
{
if(my $type = ref($@))
{
if($type =~ /^return::(.*)$/)
{
die "return from block $1 outside of any block named $1";
}
}
die "$@";
}
return $result;
}
}
@ -545,7 +558,7 @@ sub create_block {
if ($@)
{
if (ref($@) eq "BLOCK::$blockname")
if (ref($@) eq "return::$blockname")
{
return $@->{retval};
}
@ -563,7 +576,7 @@ sub return_from_block {
my $blockname = shift;
my $retval = shift;
die bless({ retval => $retval }, "BLOCK::$blockname");
die bless({ retval => $retval }, "return::$blockname");
}
sub gen_macro_let {