Skip to content

Commit

Permalink
Implement $!foo syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
sorear committed Jul 19, 2010
1 parent 1070301 commit 5ea3202
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 9 deletions.
32 changes: 23 additions & 9 deletions Niecza/Actions.pm
Expand Up @@ -28,6 +28,7 @@ sub AUTOLOAD {
sub ws { }
sub vws { }
sub unv { }
sub begid { }
sub comment { }
sub comment__S_Sharp { }
sub spacey { }
Expand Down Expand Up @@ -464,19 +465,32 @@ sub term__S_QuestionQuestionQuestion { my ($cl, $M) = @_;

sub variable { my ($cl, $M) = @_;
my $sigil = $M->{sigil} ? $M->{sigil}->Str : substr($M->Str, 0, 1);
if ($M->{twigil}[0]) {
$M->sorry("Twigils NYI");
return;
}
my $twigil = $M->{twigil}[0] ? $M->{twigil}[0]{sym} : '';

if (!$M->{desigilname}) {
$M->sorry("Non-simple variables NYI");
return;
}
my $sl = $sigil . $M->{desigilname}{_ast};
$M->{_ast} = {
term => Op::Lexical->new(name => $sl),
decl_slot => $sl,
};

my $sl = $sigil . $twigil . $M->{desigilname}{_ast};

given ($twigil) {
when ('!') {
$M->{_ast} = {
term => Op::GetSlot->new(name => $M->{desigilname}{_ast},
object => Op::Lexical->new(name => 'self')),
};
}
when ('') {
$M->{_ast} = {
term => Op::Lexical->new(name => $sl),
decl_slot => $sl,
};
}
default {
$M->sorry("Unhandled twigil $twigil");
}
}
}

sub param_sep {}
Expand Down
17 changes: 17 additions & 0 deletions Op.pm
Expand Up @@ -111,6 +111,23 @@ use CgOp;
no Moose;
}

{
package Op::GetSlot;
use Moose;
extends 'Op';

has object => (isa => 'Op', is => 'ro', required => 1);
has name => (isa => 'Str', is => 'ro', required => 1);

sub code {
my ($self, $body) = @_;
CgOp::varattr($self->name, CgOp::fetch($self->object->code($body)));
}

__PACKAGE__->meta->make_immutable;
no Moose;
}

# or maybe we should provide Op::Let and let Actions do the desugaring?
{
package Op::CallMetaMethod;
Expand Down

0 comments on commit 5ea3202

Please sign in to comment.