Skip to content

Commit 30aca70

Browse files
committed
[truffle] Implement postinc and postdec ops
1 parent 90a3587 commit 30aca70

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

nqp-truffle.nqp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,23 @@ class QAST::OperationsTruffle {
179179
add_simple_op($math-op ~ '_i', $INT, [$INT, $INT]);
180180
}
181181

182+
for <postinc postdec> -> $op {
183+
add_op($op, sub ($comp, $node, :$want) {
184+
my $old_value := $comp.as_truffle($node[0], :want($INT));
185+
my str $action := $op eq 'postinc' ?? 'add_i' !! 'sub_i';
186+
my $do_action := $comp.as_truffle(
187+
QAST::Op.new(
188+
:op('bind'),
189+
$node[0],
190+
QAST::Op.new(:op($action),$node[0],QAST::IVal.new(:value(1)))
191+
),
192+
:want($VOID)
193+
);
194+
195+
TAST.new($INT, ['old-int-value', $old_value.tree, $do_action.tree]);
196+
});
197+
}
198+
182199
# explicit takeclosure is used by the JVM backend we no-op it.
183200
add_op('takeclosure', sub ($comp, $node, :$want) {
184201
$comp.as_truffle($node[0], :want($want));
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package org.perl6.nqp.truffle.nodes.expression;
2+
import com.oracle.truffle.api.frame.VirtualFrame;
3+
import com.oracle.truffle.api.nodes.NodeInfo;
4+
import org.perl6.nqp.truffle.nodes.NQPNode;
5+
import org.perl6.nqp.dsl.Deserializer;
6+
7+
@NodeInfo(shortName = "old-int-value")
8+
public final class NQPOldIntValueNode extends NQPNode {
9+
@Child private NQPNode oldValueNode;
10+
@Child private NQPNode bindNewValueNode;
11+
12+
@Deserializer("old-int-value")
13+
public NQPOldIntValueNode(NQPNode oldValueNode, NQPNode bindNewValueNode) {
14+
this.oldValueNode = oldValueNode;
15+
this.bindNewValueNode = bindNewValueNode;
16+
}
17+
18+
@Override
19+
public long executeInt(VirtualFrame frame) {
20+
long oldValue = this.oldValueNode.executeInt(frame);
21+
this.bindNewValueNode.execute(frame);
22+
return oldValue;
23+
}
24+
}

0 commit comments

Comments
 (0)