Skip to content

Commit

Permalink
[Truffle] Clear $! when leaving a try-rescue-ensure block.
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisseaton committed Dec 29, 2014
1 parent fdfe94d commit 3792e0f
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
import com.oracle.truffle.api.nodes.*;
import com.oracle.truffle.api.utilities.*;
import org.jruby.truffle.nodes.*;
import org.jruby.truffle.nodes.literal.ObjectLiteralNode;
import org.jruby.truffle.nodes.methods.ExceptionTranslatingNode;
import org.jruby.truffle.nodes.objects.WriteInstanceVariableNode;
import org.jruby.truffle.runtime.*;
import org.jruby.truffle.runtime.control.*;

Expand All @@ -28,6 +30,7 @@ public class TryNode extends RubyNode {
@Child protected ExceptionTranslatingNode tryPart;
@Children final RescueNode[] rescueParts;
@Child protected RubyNode elsePart;
@Child protected WriteInstanceVariableNode clearExceptionVariableNode;

private final BranchProfile elseProfile = BranchProfile.create();
private final BranchProfile controlFlowProfile = BranchProfile.create();
Expand All @@ -38,6 +41,10 @@ public TryNode(RubyContext context, SourceSection sourceSection, ExceptionTransl
this.tryPart = tryPart;
this.rescueParts = rescueParts;
this.elsePart = elsePart;
clearExceptionVariableNode = new WriteInstanceVariableNode(context, sourceSection, "$!",
new ObjectLiteralNode(context, sourceSection, context.getCoreLibrary().getGlobalVariablesObject()),
new ObjectLiteralNode(context, sourceSection, context.getCoreLibrary().getNilObject()),
true);
}

@Override
Expand All @@ -60,6 +67,8 @@ public Object execute(VirtualFrame frame) {
} catch (RetryException e) {
continue;
}
} finally {
clearExceptionVariableNode.execute(frame);
}

elseProfile.enter();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public Object isDefined(VirtualFrame frame) {
if (isGlobal) {
final RubyBasicObject recieverValue = (RubyBasicObject) receiver.execute(frame);

if (readNode.getName().equals("$~")) {
if (readNode.getName().equals("$~") || readNode.getName().equals("$!")) {
return getContext().makeString("global-variable");
} else if (readNode.isSet(recieverValue)) {
if (readNode.execute(recieverValue) == getContext().getCoreLibrary().getNilObject()) {
Expand Down
1 change: 0 additions & 1 deletion spec/truffle/tags/language/predefined_tags.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
fails:Predefined global $! remains nil after a failed core class "checked" coercion against a class that defines method_missing
fails:Predefined global $_ is Thread-local

0 comments on commit 3792e0f

Please sign in to comment.