Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Implement parsing for $*foo $?foo $:foo $^foo
  • Loading branch information
sorear committed Jul 26, 2010
1 parent 66bfe9b commit 28d41aa
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 0 deletions.
1 change: 1 addition & 0 deletions CodeGen.pm
Expand Up @@ -48,6 +48,7 @@ use 5.010;
{ pos => [f => 'LValue[]'],
lex => [f => 'Dictionary<string,object>'] },

'Kernel.ContextHelper' => [m => 'Variable'],
'Kernel.StrP' => [f => 'IP6'],
'Kernel.Global' => [f => 'Variable'],
'Kernel.PackageLookup' => [c => 'Variable'],
Expand Down
22 changes: 22 additions & 0 deletions Niecza/Actions.pm
Expand Up @@ -705,6 +705,12 @@ sub term__S_lambda { my ($cl, $M) = @_;
sub do_variable_reference { my ($cl, $M, $v) = @_;
my $sl = $v->{sigil} . $v->{twigil} . $v->{name};

if (@{ $v->{rest} } && $v->{twigil} =~ /[*=~?^:]/) {
$M->sorry("Twigil " . $v->{twigil} . " cannot be used with " .
"qualified names");
return;
}

given ($v->{twigil}) {
when ('!') {
if (@{ $v->{rest} }) {
Expand All @@ -715,6 +721,22 @@ sub do_variable_reference { my ($cl, $M, $v) = @_;
return Op::GetSlot->new(name => $v->{name},
object => Op::Lexical->new(name => 'self'));
}
when ('.') {
if (@{ $v->{rest} }) {
$M->sorry('$.Foo::bar syntax NYI');
return;
}

return Op::CallMethod->new(name => $v->{name},
receiver => Op::Lexical->new(name => 'self'));
}
# These are just ordinary lexicals at run time
when ({ '^' => 1, ":" => 1, "?" => 1}) {
return Op::Lexical->new(name => $sl);
}
when ('*') {
return Op::ContextVar->new(name => $sl);
}
when ('') {
if (@{ $v->{rest} }) {
return Op::PackageVar->new(path => $v->{rest}, name => $sl,
Expand Down
16 changes: 16 additions & 0 deletions Op.pm
Expand Up @@ -710,6 +710,22 @@ use CgOp;
no Moose;
}

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

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

sub code {
my ($self, $body) = @_;
CgOp::rawscall('Kernel.ContextHelper', CgOp::clr_string($self->name));
}

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

{
package Op::PackageVar;
use Moose;
Expand Down

0 comments on commit 28d41aa

Please sign in to comment.