Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Refactor our handling of attribute initializers. The RHS should becom…
…e an anonymous method. This should get us in line with the spec, and resolves at least RT#65346.
  • Loading branch information
jnthn committed May 20, 2009
1 parent 6229131 commit f62aa0f
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/classes/Object.pir
Expand Up @@ -323,6 +323,7 @@ the object's type and address.
unless null $P0 goto attrinit_assign
$P0 = attrhash['init_value']
if null $P0 goto attrinit_loop
$P0 = $P0(candidate, attr)
attrinit_assign:
'infix:='(attr, $P0)
goto attrinit_loop
Expand Down
25 changes: 24 additions & 1 deletion src/parser/actions.pm
Expand Up @@ -1695,6 +1695,7 @@ method scope_declarator($/) {
$?METACLASS, $var.name(), $var<itype> );
if $type { $type.named('type'); $has.push($type); }
if $init_value {
$init_value := make_attr_init_closure($init_value);
$init_value.named('init_value');
$has.push($init_value);
}
Expand Down Expand Up @@ -2491,6 +2492,8 @@ method EXPR($/, $key) {
my $past;

if $lhs<scopedecl> eq 'attribute' {
# Need to transform RHS into an anonymous method.
$rhs := make_attr_init_closure($rhs);
$rhs.named('init_value');
our $?METACLASS;
$past := PAST::Op.new( :name('!meta_attribute'),
Expand Down Expand Up @@ -3141,7 +3144,27 @@ sub add_optoken($block, $match) {
}
$name;
}



sub make_attr_init_closure($init_value) {
# Need to not just build the closure, but new_closure it; otherwise, we
# run into trouble if our initialization value involves a parameter from
# a parametric role.
PAST::Op.new(
:inline('%r = newclosure %0'),
PAST::Block.new(
:blocktype('method'),
PAST::Stmts.new(
PAST::Var.new( :name('$_'), :scope('parameter') ),
PAST::Op.new( :pasttype('bind'),
PAST::Var.new( :name('self'), :scope('lexical'), :isdecl(1) ),
PAST::Var.new( :name('self'), :scope('register') )
)
),
PAST::Stmts.new( $init_value )
)
);
}

# Local Variables:
# mode: cperl
Expand Down

0 comments on commit f62aa0f

Please sign in to comment.