Skip to content

Commit 737fd97

Browse files
committed
Get ++ and -- back in place; since we don't have a container model, it really maps down to binding and stuff. Dubious, but removing it will probably cause riots...
1 parent 4660299 commit 737fd97

File tree

4 files changed

+84
-17
lines changed

4 files changed

+84
-17
lines changed

src/NQPQ/Actions.pm

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1449,18 +1449,6 @@ class NQP::Actions is HLL::Actions {
14491449

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

1452-
method postfix:sym<++>($/) {
1453-
make PAST::Op.new( :name('postfix:<++>'),
1454-
:inline(' clone %r, %0', ' inc %0'),
1455-
:pasttype('inline') );
1456-
}
1457-
1458-
method postfix:sym<-->($/) {
1459-
make PAST::Op.new( :name('postfix:<-->'),
1460-
:inline(' clone %r, %0', ' dec %0'),
1461-
:pasttype('inline') );
1462-
}
1463-
14641452
method prefix:sym<make>($/) {
14651453
make QAST::Op.new(
14661454
QAST::Var.new( :name('$/'), :scope('contextual') ),

src/NQPQ/Grammar.pm

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -661,12 +661,11 @@ grammar NQP::Grammar is HLL::Grammar {
661661

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

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

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

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

src/NQPQ/Ops.pm

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
my $ops := QAST::Compiler.operations();
2+
3+
$ops.add_hll_op('nqp', 'preinc', -> $qastcomp, $op {
4+
my $var := $op[0];
5+
unless nqp::istype($var, QAST::Var) {
6+
nqp::die("Pre-increment can only work on a variable");
7+
}
8+
$qastcomp.as_post(QAST::Op.new(
9+
:op('bind'),
10+
$var,
11+
QAST::Op.new(
12+
:op('add_n'),
13+
$var,
14+
QAST::IVal.new( :value(1) )
15+
)));
16+
});
17+
18+
$ops.add_hll_op('nqp', 'predec', -> $qastcomp, $op {
19+
my $var := $op[0];
20+
unless nqp::istype($var, QAST::Var) {
21+
nqp::die("Pre-decrement can only work on a variable");
22+
}
23+
$qastcomp.as_post(QAST::Op.new(
24+
:op('bind'),
25+
$var,
26+
QAST::Op.new(
27+
:op('sub_n'),
28+
$var,
29+
QAST::IVal.new( :value(1) )
30+
)));
31+
});
32+
33+
$ops.add_hll_op('nqp', 'postinc', -> $qastcomp, $op {
34+
my $var := $op[0];
35+
my $tmp := QAST::Op.unique('tmp');
36+
unless nqp::istype($var, QAST::Var) {
37+
nqp::die("Post-increment can only work on a variable");
38+
}
39+
$qastcomp.as_post(QAST::Stmt.new(
40+
:resultchild(0),
41+
QAST::Op.new(
42+
:op('bind'),
43+
QAST::Var.new( :name($tmp), :scope('local'), :decl('var') ),
44+
$var
45+
),
46+
QAST::Op.new(
47+
:op('bind'),
48+
$var,
49+
QAST::Op.new(
50+
:op('add_n'),
51+
QAST::Var.new( :name($tmp), :scope('local') ),
52+
QAST::IVal.new( :value(1) )
53+
)
54+
)));
55+
});
56+
57+
$ops.add_hll_op('nqp', 'postdec', -> $qastcomp, $op {
58+
my $var := $op[0];
59+
my $tmp := QAST::Op.unique('tmp');
60+
unless nqp::istype($var, QAST::Var) {
61+
nqp::die("Post-decrement can only work on a variable");
62+
}
63+
$qastcomp.as_post(QAST::Stmt.new(
64+
:resultchild(0),
65+
QAST::Op.new(
66+
:op('bind'),
67+
QAST::Var.new( :name($tmp), :scope('local'), :decl('var') ),
68+
$var
69+
),
70+
QAST::Op.new(
71+
:op('bind'),
72+
$var,
73+
QAST::Op.new(
74+
:op('sub_n'),
75+
QAST::Var.new( :name($tmp), :scope('local') ),
76+
QAST::IVal.new( :value(1) )
77+
)
78+
)));
79+
});

tools/build/Makefile.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,7 @@ NQPQ_EXE = nqpq$(EXE)
175175
NQPQ_SOURCES = \
176176
src/NQPQ/World.pm \
177177
src/NQPQ/Grammar.pm \
178+
src/NQPQ/Ops.pm \
178179
src/NQPQ/Actions.pm \
179180
src/NQPQ/Compiler.pm \
180181

0 commit comments

Comments
 (0)