Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
make "eval BLOCK" work, this sets $@
  • Loading branch information
FROGGS committed Mar 30, 2013
1 parent 4041e53 commit d3afde4
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions lib/Perl6/P5Actions.pm
Expand Up @@ -1130,6 +1130,45 @@ class Perl6::P5Actions is HLL::Actions does STDActions {
make QAST::Op.new( :op('call'), $<sblock>.ast );
}

method statement_prefix:sym<eval>($/) {
$DEBUG && say("statement_prefix:sym<eval>($/)");
my $block := QAST::Op.new(:op<call>, $<block>.ast); # XXX should be immediate
make QAST::Op.new(
:op('handle'),

# Success path puts Any into $! and evaluates to the block.
QAST::Stmt.new(
:resultchild(0),
$block,
QAST::Op.new(
:op('p6store'),
QAST::Var.new( :name<$!>, :scope<lexical> ),
QAST::Var.new( :name<Any>, :scope<lexical> )
)
),

# On failure, capture the exception object into $!.
'CATCH', QAST::Stmts.new(
QAST::Op.new(
:op('p6store'),
QAST::Var.new(:name<$!>, :scope<lexical>),
QAST::Op.new(
:name<&EXCEPTION>, :op<call>,
QAST::Op.new( :op('exception') )
),
),
QAST::VM.new(
pirop => 'perl6_invoke_catchhandler 1PP',
QAST::Op.new( :op('null') ),
QAST::Op.new( :op('exception') )
),
QAST::WVal.new(
:value( $*W.find_symbol(['Nil']) ),
),
)
)
}

method statement_prefix:sym<gather>($/) {
$DEBUG && say("statement_prefix:sym<gather>($/)");
my $past := block_closure($<sblock>.ast);
Expand Down Expand Up @@ -1292,6 +1331,7 @@ class Perl6::P5Actions is HLL::Actions does STDActions {

method special_variable:sym<$@>($/) {
$DEBUG && say("special_variable:sym<\$@>($/)");
make QAST::Var.new( :name('$!'), :scope('lexical') )
}

method special_variable:sym<$#>($/) {
Expand Down

0 comments on commit d3afde4

Please sign in to comment.