[svn:parrot] r38389 - in branches/pmc_pct/compilers/nqp: bootstrap src/Grammar t
bacek at svn.parrot.org
bacek at svn.parrot.org
Tue Apr 28 09:59:54 UTC 2009
Author: bacek
Date: Tue Apr 28 09:59:53 2009
New Revision: 38389
URL: https://trac.parrot.org/parrot/changeset/38389
Log:
[nqp] Reimplement self as lexical. pmichaud++ for explanations
Added:
branches/pmc_pct/compilers/nqp/t/29-self.t
Modified:
branches/pmc_pct/compilers/nqp/bootstrap/actions.pm
branches/pmc_pct/compilers/nqp/src/Grammar/Actions.pir
Modified: branches/pmc_pct/compilers/nqp/bootstrap/actions.pm
==============================================================================
--- branches/pmc_pct/compilers/nqp/bootstrap/actions.pm Tue Apr 28 08:49:34 2009 (r38388)
+++ branches/pmc_pct/compilers/nqp/bootstrap/actions.pm Tue Apr 28 09:59:53 2009 (r38389)
@@ -339,6 +339,8 @@
my $params := $past[0];
if $<declarator> eq 'method' {
$past.blocktype('method');
+ unshift $past, PAST::Op.new('inline'=>'.lex "self", self',
+ 'pasttype'=>'inline');
}
for $<signature>[0] {
my $parameter := $($_<parameter>);
@@ -703,7 +705,12 @@
method noun($/, $key) {
- make $($/{$key});
+ if $key eq 'self' {
+ make PAST::Var.new('name'=>'self', 'node'=>$/);
+ }
+ else {
+ make $($/{$key});
+ }
}
##.sub 'noun' :method
## .param pmc match
Modified: branches/pmc_pct/compilers/nqp/src/Grammar/Actions.pir
==============================================================================
--- branches/pmc_pct/compilers/nqp/src/Grammar/Actions.pir Tue Apr 28 08:49:34 2009 (r38388)
+++ branches/pmc_pct/compilers/nqp/src/Grammar/Actions.pir Tue Apr 28 09:59:53 2009 (r38389)
@@ -377,6 +377,7 @@
## my $params := $past[0];
## if $<declarator> eq 'method' {
## $past.blocktype('method');
+## $past.push(PAST::Op.new('inline'=>'.lex 'self', self);
## }
## for $<signature>[0] {
## my $parameter := $($_<parameter>);
@@ -400,6 +401,9 @@
$S0 = match['declarator']
if $S0 != 'method' goto add_signature
past.'blocktype'('method')
+ $P3 = get_hll_global ['PAST'], 'Op'
+ $P4 = $P3.'new'('inline'=>' .lex "self", self', 'pasttype'=>'inline')
+ unshift past, $P4
add_signature:
$P0 = match['signature']
$P0 = $P0[0]
@@ -738,7 +742,12 @@
## method noun($/, $key) {
-## make $($/{$key});
+## if $key eq 'self' {
+## make PAST::Var.new('name'=>'self', 'node'=>$/);
+## }
+## else {
+## make $($/{$key});
+## }
## }
.sub 'noun' :method
.param pmc match
@@ -750,8 +759,8 @@
match.'!make'($P1)
.return()
make_self:
- $P9 = get_hll_global ['PAST'], 'Op'
- $P1 = $P9.'new'('inline'=>' %r = self', 'pasttype'=>'inline', 'node'=>$P0)
+ $P9 = get_hll_global ['PAST'], 'Var'
+ $P1 = $P9.'new'('scope'=>'lexical', 'name'=>'self', 'node'=>$P0)
match.'!make'($P1)
.end
Added: branches/pmc_pct/compilers/nqp/t/29-self.t
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ branches/pmc_pct/compilers/nqp/t/29-self.t Tue Apr 28 09:59:53 2009 (r38389)
@@ -0,0 +1,28 @@
+#!./parrot nqp.pbc
+
+plan(3);
+
+class Foo {
+ method foo() { 1 };
+
+ method uno() {
+ self.foo();
+ };
+
+ method des() {
+ if 1 {
+ self.foo();
+ }
+ };
+
+ method tres($a) {
+ if 1 {
+ self.foo();
+ }
+ };
+};
+
+ok(Foo.new.uno, "Can access self within method");
+ok(Foo.new.des, "Can access self within sub-block");
+ok(Foo.new.tres(42), "Can access self within method with signature");
+
More information about the parrot-commits
mailing list