Author: jonathan
Date: Tue Nov 11 14:30:52 2008
New Revision: 32567
Modified:
trunk/languages/perl6/src/parser/actions.pm
Log:
[rakudo] Set scope to $?FOO type variables to be lexical, and set up $?PACKAGE.
Gives wrong stringification for root namespace for now (should be Main), but
should be correct otherwise.
Modified: trunk/languages/perl6/src/parser/actions.pm
==============================================================================
--- trunk/languages/perl6/src/parser/actions.pm (original)
+++ trunk/languages/perl6/src/parser/actions.pm Tue Nov 11 14:30:52 2008
@@ -29,6 +29,9 @@
# Make sure we have the interpinfo constants.
$past.unshift( PAST::Op.new( :inline('.include "interpinfo.pasm"') ) );
+ # Set package.
+ $past.unshift(set_package_magical());
+
# Add code to load perl6.pbc if it's not already present
my $loadinit := $past.loadinit();
$loadinit.unshift(
@@ -1598,6 +1601,9 @@
# role_def.
my $past := $( $/{$key} );
+ # Set $?PACKAGE at the start of it.
+ $past.unshift(set_package_magical());
+
# Restore outer values in @?<magical> arrays
if $sym eq 'package' {
@?PACKAGE.shift();
@@ -2379,7 +2385,9 @@
}
else {
# Variable. [!:^] twigil should be kept in the name.
- if $twigil eq '!' || $twigil eq ':' || $twigil eq '^' { $name :=
$twigil ~ ~$name; }
+ if $twigil eq '!' || $twigil eq ':' || $twigil eq '^' || $twigil
eq '?' {
+ $name := $twigil ~ ~$name;
+ }
# All but subs should keep their sigils.
my $sigil := '';
@@ -2449,6 +2457,11 @@
}
}
+ # If we have the ? sigil, lexical scope.
+ if $twigil eq '?' {
+ $past.scope('lexical');
+ }
+
$past.viviself(container_type($sigil));
}
}
@@ -3532,6 +3545,25 @@
}
+# Returns the code to set $?PACKAGE to the current package.
+sub set_package_magical() {
+ return PAST::Op.new(
+ :pasttype('bind'),
+ PAST::Var.new(
+ :name('$?PACKAGE'),
+ :scope('lexical'),
+ :isdecl(1)
+ ),
+ PAST::Op.new(
+ :inline(
+ '$P0 = interpinfo .INTERPINFO_CURRENT_SUB',
+ '%r = $P0."get_namespace"()'
+ )
+ )
+ );
+}
+
+
# Local Variables:
# mode: cperl
# cperl-indent-level: 4