Skip to content

Commit

Permalink
Unify private accessors and private methods
Browse files Browse the repository at this point in the history
$!foo is short for self!foo.  This makes $!Foo::bar and $other!private
work, and will eventually make $!method(20) work with no ambiguity.
  • Loading branch information
sorear committed Oct 4, 2010
1 parent 7aef582 commit 2fe5011
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 20 deletions.
28 changes: 15 additions & 13 deletions src/Metamodel.pm
Expand Up @@ -794,20 +794,22 @@ sub Op::Attribute::begin {
if $opensubs[-1]->augmenting;
$ns = $unit->deref($ns);
$ns->add_attribute($self->name);
my $nb = Metamodel::StaticSub->new(
unit => $unit,
outer => $opensubs[-1],
name => $self->name,
cur_pkg => $opensubs[-1]->cur_pkg,
returnable => 0,
class => 'Sub',
run_once => 0,
code => Op::GetSlot->new(name => $self->name,
object => Op::CgOp->new(optree => [ pos => 0 ])));
$opensubs[-1]->create_static_pad; # for protosub instance
$nb->strong_used(1);
$opensubs[-1]->add_my_sub($self->name . '!a', $nb);
my $r = $unit->make_ref($nb);
$ns->add_method('!', $self->name, $r);
if ($self->accessor) {
my $nb = Metamodel::StaticSub->new(
unit => $unit,
outer => $opensubs[-1],
name => $self->name,
cur_pkg => $opensubs[-1]->cur_pkg,
returnable => 0,
class => 'Sub',
run_once => 0,
code => Op::GetSlot->new(name => $self->name,
object => Op::CgOp->new(optree => [ pos => 0 ])));
$opensubs[-1]->create_static_pad; # for protosub instance
$nb->strong_used(1);
$opensubs[-1]->add_my_sub($self->name . '!a', $nb);
$ns->add_method('', $self->name, $unit->make_ref($nb));
}
}
Expand Down
10 changes: 3 additions & 7 deletions src/Niecza/Actions.pm
Expand Up @@ -1435,13 +1435,9 @@ sub do_variable_reference { my ($cl, $M, $v) = @_;

given ($v->{twigil}) {
when ('!') {
if ($v->{rest}) {
$M->sorry('$!Foo::bar syntax NYI');
return;
}

return Op::GetSlot->new(node($M), name => $v->{name},
object => Op::Lexical->new(name => 'self'));
return Op::CallMethod->new(node($M), name => $v->{name},
receiver => Op::Lexical->new(name => 'self'),
private => 1, ppath => $v->{rest});
}
when ('.') {
if ($v->{rest}) {
Expand Down

0 comments on commit 2fe5011

Please sign in to comment.