diff --git a/lib/Minilisp.pm b/lib/Minilisp.pm index dec835d..f0bfa5d 100644 --- a/lib/Minilisp.pm +++ b/lib/Minilisp.pm @@ -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 {