Skip to content
Permalink
Browse files
[Truffle] Last of the while specs.
  • Loading branch information
chrisseaton committed Dec 4, 2014
1 parent 3f0df65 commit 70d736f28c6aa8e5318b2d06eefd83e03d48290f
Showing with 19 additions and 2 deletions.
  1. +19 −0 core/src/main/java/org/jruby/truffle/translator/BodyTranslator.java
  2. +0 −2 spec/truffle/tags/language/while_tags.txt
@@ -1683,6 +1683,25 @@ public RubyNode visitOpAsgnAndNode(org.jruby.ast.OpAsgnAndNode node) {

@Override
public RubyNode visitOpAsgnNode(org.jruby.ast.OpAsgnNode node) {
if (node.getOperatorName() == "||") {
// Why does this ||= come through as a visitOpAsgnNode and not a visitOpAsgnOrNode?

final String temp = environment.allocateLocalTemp("opassign");
final org.jruby.ast.Node writeReceiverToTemp = new org.jruby.ast.LocalAsgnNode(node.getPosition(), temp, 0, node.getReceiverNode());
final org.jruby.ast.Node readReceiverFromTemp = new org.jruby.ast.LocalVarNode(node.getPosition(), 0, temp);

final org.jruby.ast.Node readMethod = new CallNode(node.getPosition(), readReceiverFromTemp, node.getVariableName(), null, null);
final org.jruby.ast.Node writeMethod = new CallNode(node.getPosition(), readReceiverFromTemp, node.getVariableName() + "=", buildArrayNode(node.getPosition(),
node.getValueNode()), null);

final SourceSection sourceSection = translate(node.getPosition());

RubyNode lhs = readMethod.accept(this);
RubyNode rhs = writeMethod.accept(this);

return new AssignmentWrapperNode(context, sourceSection, SequenceNode.sequence(context, sourceSection, writeReceiverToTemp.accept(this), new OrNode(context, sourceSection, lhs, rhs)));
}

/*
* We're going to de-sugar a.foo += c into a.foo = a.foo + c. Note that we can't evaluate a
* more than once, so we put it into a temporary, and we're doing something more like:

This file was deleted.

0 comments on commit 70d736f

Please sign in to comment.