Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Perlito5 - perl6 - __PACKAGE__

  • Loading branch information...
commit 66a032752550968249cd624f7b79ea2979c1b261 1 parent b60f756
@fglock authored
Showing with 21 additions and 1 deletion.
  1. +9 −0 perlito5.pl
  2. +12 −1 src5/lib/Perlito5/Perl6/Emitter.pm
View
9 perlito5.pl
@@ -12363,6 +12363,7 @@ package Perlito5::AST::CompUnit;
my $pkg = {'name' => 'main', 'body' => []};
for my $stmt (@body) {
if (ref($stmt) eq 'Perlito5::AST::Apply' && $stmt->{'code'} eq 'package') {
+ $Perlito5::PKG_NAME = $stmt->{'namespace'};
push(@out, ['stmt' => ['keyword' => 'class'], ['bareword' => $pkg->{'name'}], ['block' => map {
$_->emit_perl6()
} @{$pkg->{'body'}}]])
@@ -12386,6 +12387,7 @@ package Perlito5::AST::CompUnit;
my $pkg = {'name' => 'main', 'body' => []};
for my $stmt (@body) {
if (ref($stmt) eq 'Perlito5::AST::Apply' && $stmt->{'code'} eq 'package') {
+ $Perlito5::PKG_NAME = $stmt->{'namespace'};
if (@{$pkg->{'body'}}) {
if ($pkg->{'name'} eq 'main') {
push(@out, map {
@@ -12552,6 +12554,9 @@ package Perlito5::AST::Proto;
{
sub Perlito5::AST::Proto::emit_perl6 {
my $self = $_[0];
+ if ($self->{'name'} eq '__PACKAGE__') {
+ return(['bareword' => $Perlito5::PKG_NAME])
+ }
return(['bareword' => $self->{'name'}])
}
}
@@ -12615,6 +12620,9 @@ package Perlito5::AST::Apply;
if ($code eq inf && !$self->{'namespace'}) {
return(['keyword' => 'Inf'])
}
+ if ($code eq '__PACKAGE__' && !$self->{'namespace'}) {
+ return(['bareword' => $Perlito5::PKG_NAME])
+ }
if ($code eq 'prefix:<$#>') {
return(['op' => 'infix:<.>', $self->{'arguments'}->[0]->emit_perl6(), ['keyword' => 'end']])
}
@@ -12680,6 +12688,7 @@ package Perlito5::AST::Apply;
return('tr!' . $self->{'arguments'}->[0]->{'buf'} . '!' . $self->{'arguments'}->[1]->{'buf'} . '!')
}
if ($self->{'code'} eq 'package') {
+ $Perlito5::PKG_NAME = $self->{'namespace'};
return(['stmt' => 'class', ['bareword' => $self->{'namespace'}]])
}
if ($code eq 'map' || $code eq 'grep' || $code eq 'sort') {
View
13 src5/lib/Perlito5/Perl6/Emitter.pm
@@ -82,6 +82,7 @@ package Perlito5::AST::CompUnit;
my $pkg = { name => 'main', body => [] };
for my $stmt (@body) {
if (ref($stmt) eq 'Perlito5::AST::Apply' && $stmt->{code} eq 'package') {
+ $Perlito5::PKG_NAME = $stmt->{namespace};
push @out, [ stmt => [ keyword => 'class'], [ bareword => $pkg->{name} ],
[ block => map { $_->emit_perl6() } @{ $pkg->{body} } ]
]
@@ -105,6 +106,7 @@ package Perlito5::AST::CompUnit;
my $pkg = { name => 'main', body => [] };
for my $stmt (@body) {
if (ref($stmt) eq 'Perlito5::AST::Apply' && $stmt->{code} eq 'package') {
+ $Perlito5::PKG_NAME = $stmt->{namespace};
if ( @{ $pkg->{body} } ) {
if ( $pkg->{name} eq 'main' ) {
push @out, map { $_->emit_perl6() } @{ $pkg->{body} }
@@ -316,6 +318,9 @@ package Perlito5::AST::Proto;
{
sub emit_perl6 {
my $self = $_[0];
+ if ($self->{name} eq '__PACKAGE__') {
+ return [ bareword => $Perlito5::PKG_NAME ];
+ }
return [ bareword => $self->{name} ];
}
}
@@ -397,6 +402,9 @@ package Perlito5::AST::Apply;
if ($code eq 'inf' && !$self->{namespace}) {
return [ keyword => 'Inf' ];
}
+ if ($code eq '__PACKAGE__' && !$self->{namespace}) {
+ return [ bareword => $Perlito5::PKG_NAME ];
+ }
if ($code eq 'prefix:<$#>') {
return [ op => 'infix:<.>', $self->{arguments}[0]->emit_perl6(), [ keyword => 'end' ] ];
}
@@ -479,7 +487,10 @@ package Perlito5::AST::Apply;
. '!';
}
- if ($self->{code} eq 'package') { return [ stmt => 'class', [ bareword => $self->{namespace} ] ] }
+ if ($self->{code} eq 'package') {
+ $Perlito5::PKG_NAME = $self->{namespace};
+ return [ stmt => 'class', [ bareword => $self->{namespace} ] ]
+ }
if ($code eq 'map' || $code eq 'grep' || $code eq 'sort') {
if ( $self->{special_arg} ) {

0 comments on commit 66a0327

Please sign in to comment.
Something went wrong with that request. Please try again.