Skip to content

Commit

Permalink
Rework handling of '->' and '.' to be postfix
Browse files Browse the repository at this point in the history
  • Loading branch information
bacek committed Apr 12, 2011
1 parent 9e8d596 commit 0f9bcc2
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 9 deletions.
28 changes: 24 additions & 4 deletions compilers/opsc/src/Ops/Compiler/Actions.pm
Expand Up @@ -633,12 +633,22 @@ method circumfix:sym<( )> ($/) {
}

method postcircumfix:sym<[ ]> ($/) {
make PAST::Var.new(
$<EXPR>.ast,
:scope('keyed'),
);
make PAST::Var.new($<EXPR>.ast, :scope('keyed_int'));
}

method postcircumfix:sym<( )> ($/) {
make $<arglist>.ast;
}

method arglist($/) {
my $past := PAST::Op.new( :pasttype('call'), :node($/) );

if ($<arg>) {
$past.push($_.ast) for $<arg>;
}

make $past;
}

# For casting we just set "returns" of EXPR.
method prefix:sym<( )> ($/) {
Expand All @@ -647,6 +657,16 @@ method prefix:sym<( )> ($/) {
);
}

method postfix:sym«->» ($/) {
#<sym> <identifier> <O('%methodop :pirop<arrow>')>
make PAST::Var.new( ~$<identifier>, :scope('keyed_arrow'));
}

method postfix:sym«.» ($/) {
#<sym> <identifier> <O('%methodop :pirop<arrow>')>
make PAST::Var.new( ~$<identifier>, :scope('keyed_dotty'));
}

# Helper method for generating PAST::Val with opsize
method opsize () {
make PAST::Val.new(
Expand Down
13 changes: 9 additions & 4 deletions compilers/opsc/src/Ops/Compiler/Grammar.pm
Expand Up @@ -309,10 +309,15 @@ token postcircumfix:sym<[ ]> {
<O('%methodop')>
}

#token postfix:sym«->» { <sym> <identifier> <O('%methodop :pirop<arrow>')> }
#token postfix:sym«.» { <sym> <identifier> <O('%methodop :pirop<dotty>')> }
token infix:sym«->» { <sym> <O('%dotty :pirop<arrow>')> }
token infix:sym«.» { <sym> <O('%dotty :pirop<dotty>')> }
token postcircumfix:sym<( )> {
'(' <.ws> <arglist> ')'
<O('%methodop')>
}

token postfix:sym«->» { <sym> <identifier> <O('%methodop :pirop<arrow>')> }
token postfix:sym«.» { <sym> <identifier> <O('%methodop :pirop<dotty>')> }
#token infix:sym«->» { <sym> <O('%dotty :pirop<arrow>')> }
#token infix:sym«.» { <sym> <O('%dotty :pirop<dotty>')> }

# XXX Check precedence
token postfix:sym<--> { <sym> <O('%autoincrement :pirop<-->')> }
Expand Down
8 changes: 7 additions & 1 deletion compilers/opsc/src/Ops/Op.pm
Expand Up @@ -304,9 +304,15 @@ our multi method to_c(PAST::Var $var, %c) {
}
$res;
}
elsif $var.scope eq 'keyed' {
elsif $var.scope eq 'keyed_int' {
self.to_c($var[0], %c) ~ '[' ~ self.to_c($var[1], %c) ~ ']';
}
elsif $var.scope eq 'keyed_arrow' {
self.to_c($var[0], %c) ~ '->' ~ self.to_c($var[1], %c);
}
elsif $var.scope eq 'keyed_dotty' {
self.to_c($var[0], %c) ~ '.' ~ self.to_c($var[1], %c);
}
elsif $var.scope eq 'register' {
my $n := +$var.name;
%c<trans>.access_arg( self.arg_type($n - 1), $n, %c);
Expand Down

0 comments on commit 0f9bcc2

Please sign in to comment.