Skip to content
Browse files
[Truffle] Last of the while specs.
  • Loading branch information
chrisseaton committed Dec 4, 2014
1 parent 3f0df65 commit 70d736f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
@@ -1683,6 +1683,25 @@ public RubyNode visitOpAsgnAndNode(org.jruby.ast.OpAsgnAndNode node) {

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 += c into = + 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.