Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Get ++ and -- back in place; since we don't have a container model, i…
…t really maps down to binding and stuff. Dubious, but removing it will probably cause riots...
  • Loading branch information
jnthn committed Aug 7, 2012
1 parent 4660299 commit 737fd97
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 17 deletions.
12 changes: 0 additions & 12 deletions src/NQPQ/Actions.pm
Expand Up @@ -1449,18 +1449,6 @@ class NQP::Actions is HLL::Actions {

method postfix:sym<.>($/) { make $<dotty>.ast; }

method postfix:sym<++>($/) {
make PAST::Op.new( :name('postfix:<++>'),
:inline(' clone %r, %0', ' inc %0'),
:pasttype('inline') );
}

method postfix:sym<-->($/) {
make PAST::Op.new( :name('postfix:<-->'),
:inline(' clone %r, %0', ' dec %0'),
:pasttype('inline') );
}

method prefix:sym<make>($/) {
make QAST::Op.new(
QAST::Var.new( :name('$/'), :scope('contextual') ),
Expand Down
9 changes: 4 additions & 5 deletions src/NQPQ/Grammar.pm
Expand Up @@ -661,12 +661,11 @@ grammar NQP::Grammar is HLL::Grammar {

token postfix:sym<.> { <dotty> <O('%methodop')> }

token prefix:sym<++> { <sym> <O('%autoincrement, :pirop<inc>')> }
token prefix:sym<--> { <sym> <O('%autoincrement, :pirop<dec>')> }
token prefix:sym<++> { <sym> <O('%autoincrement, :op<preinc>')> }
token prefix:sym<--> { <sym> <O('%autoincrement, :op<predec>')> }

# see Actions.pm for postfix:<++> and postfix:<-->
token postfix:sym<++> { <sym> <O('%autoincrement')> }
token postfix:sym<--> { <sym> <O('%autoincrement')> }
token postfix:sym<++> { <sym> <O('%autoincrement, :op<postinc>')> }
token postfix:sym<--> { <sym> <O('%autoincrement, :op<postdec>')> }

token infix:sym<**> { <sym> <O('%exponentiation, :op<pow_n>')> }

Expand Down
79 changes: 79 additions & 0 deletions src/NQPQ/Ops.pm
@@ -0,0 +1,79 @@
my $ops := QAST::Compiler.operations();

$ops.add_hll_op('nqp', 'preinc', -> $qastcomp, $op {
my $var := $op[0];
unless nqp::istype($var, QAST::Var) {
nqp::die("Pre-increment can only work on a variable");
}
$qastcomp.as_post(QAST::Op.new(
:op('bind'),
$var,
QAST::Op.new(
:op('add_n'),
$var,
QAST::IVal.new( :value(1) )
)));
});

$ops.add_hll_op('nqp', 'predec', -> $qastcomp, $op {
my $var := $op[0];
unless nqp::istype($var, QAST::Var) {
nqp::die("Pre-decrement can only work on a variable");
}
$qastcomp.as_post(QAST::Op.new(
:op('bind'),
$var,
QAST::Op.new(
:op('sub_n'),
$var,
QAST::IVal.new( :value(1) )
)));
});

$ops.add_hll_op('nqp', 'postinc', -> $qastcomp, $op {
my $var := $op[0];
my $tmp := QAST::Op.unique('tmp');
unless nqp::istype($var, QAST::Var) {
nqp::die("Post-increment can only work on a variable");
}
$qastcomp.as_post(QAST::Stmt.new(
:resultchild(0),
QAST::Op.new(
:op('bind'),
QAST::Var.new( :name($tmp), :scope('local'), :decl('var') ),
$var
),
QAST::Op.new(
:op('bind'),
$var,
QAST::Op.new(
:op('add_n'),
QAST::Var.new( :name($tmp), :scope('local') ),
QAST::IVal.new( :value(1) )
)
)));
});

$ops.add_hll_op('nqp', 'postdec', -> $qastcomp, $op {
my $var := $op[0];
my $tmp := QAST::Op.unique('tmp');
unless nqp::istype($var, QAST::Var) {
nqp::die("Post-decrement can only work on a variable");
}
$qastcomp.as_post(QAST::Stmt.new(
:resultchild(0),
QAST::Op.new(
:op('bind'),
QAST::Var.new( :name($tmp), :scope('local'), :decl('var') ),
$var
),
QAST::Op.new(
:op('bind'),
$var,
QAST::Op.new(
:op('sub_n'),
QAST::Var.new( :name($tmp), :scope('local') ),
QAST::IVal.new( :value(1) )
)
)));
});
1 change: 1 addition & 0 deletions tools/build/Makefile.in
Expand Up @@ -175,6 +175,7 @@ NQPQ_EXE = nqpq$(EXE)
NQPQ_SOURCES = \
src/NQPQ/World.pm \
src/NQPQ/Grammar.pm \
src/NQPQ/Ops.pm \
src/NQPQ/Actions.pm \
src/NQPQ/Compiler.pm \

Expand Down

0 comments on commit 737fd97

Please sign in to comment.