Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: jruby/jruby
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 3baa2ca37286
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 7ee7b94b4857
Choose a head ref
  • 2 commits
  • 2 files changed
  • 1 contributor

Commits on Dec 2, 2014

  1. Copy the full SHA
    24155ec View commit details
  2. Copy the full SHA
    7ee7b94 View commit details
Original file line number Diff line number Diff line change
@@ -17,6 +17,8 @@
import com.oracle.truffle.api.dsl.*;
import com.oracle.truffle.api.frame.VirtualFrame;
import org.jruby.runtime.Visibility;
import org.jruby.truffle.nodes.RubyNode;
import org.jruby.truffle.nodes.cast.BooleanCastNodeFactory;
import org.jruby.truffle.nodes.dispatch.Dispatch;
import org.jruby.truffle.nodes.dispatch.DispatchHeadNode;
import org.jruby.truffle.nodes.yield.YieldDispatchHeadNode;
@@ -39,9 +41,15 @@ public NotNode(NotNode prev) {
super(prev);
}

@CreateCast("arguments") public RubyNode[] createCast(RubyNode[] arguments) {
return new RubyNode[] {
BooleanCastNodeFactory.create(getContext(), getSourceSection(), arguments[0])
};
}

@Specialization
public boolean not(Object value) {
return !getContext().getCoreLibrary().isTruthy(value);
public boolean not(boolean value) {
return !value;
}

}
Original file line number Diff line number Diff line change
@@ -12,13 +12,16 @@
import com.oracle.truffle.api.*;
import com.oracle.truffle.api.source.*;
import com.oracle.truffle.api.frame.*;
import org.jruby.truffle.nodes.cast.BooleanCastNode;
import org.jruby.truffle.nodes.cast.BooleanCastNodeFactory;
import org.jruby.truffle.nodes.yield.*;
import org.jruby.truffle.runtime.*;
import org.jruby.truffle.runtime.core.*;

public abstract class YieldingCoreMethodNode extends CoreMethodNode {

@Child protected YieldDispatchHeadNode dispatchNode;
@Child protected BooleanCastNode booleanCastNode;

public YieldingCoreMethodNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
@@ -30,12 +33,20 @@ public YieldingCoreMethodNode(YieldingCoreMethodNode prev) {
dispatchNode = prev.dispatchNode;
}

private boolean booleanCast(VirtualFrame frame, Object value) {
if (booleanCastNode == null) {
CompilerDirectives.transferToInterpreterAndInvalidate();
booleanCastNode = insert(BooleanCastNodeFactory.create(getContext(), getSourceSection(), null));
}
return booleanCastNode.executeBoolean(frame, value);
}

public Object yield(VirtualFrame frame, RubyProc block, Object... arguments) {
return dispatchNode.dispatch(frame, block, arguments);
}

public boolean yieldIsTruthy(VirtualFrame frame, RubyProc block, Object... arguments) {
return getContext().getCoreLibrary().isTruthy(yield(frame, block, arguments));
return booleanCast(frame, yield(frame, block, arguments));
}

}