Skip to content

Commit

Permalink
Showing 3 changed files with 19 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -31,7 +31,7 @@ public IntegerCastNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
}

public abstract int executeInteger(VirtualFrame frame, Object value);
public abstract int executeCastInt(Object value);

@Override
public abstract int executeInteger(VirtualFrame frame);
Original file line number Diff line number Diff line change
@@ -9,12 +9,15 @@
*/
package org.jruby.truffle.nodes.exceptions;

import com.oracle.truffle.api.CompilerDirectives;
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.object.DynamicObject;
import com.oracle.truffle.api.source.SourceSection;

import org.jruby.truffle.nodes.RubyNode;
import org.jruby.truffle.nodes.cast.IntegerCastNode;
import org.jruby.truffle.nodes.cast.IntegerCastNodeGen;
import org.jruby.truffle.runtime.RubyContext;
import org.jruby.truffle.runtime.backtrace.BacktraceFormatter;
import org.jruby.truffle.runtime.control.RaiseException;
@@ -24,6 +27,7 @@
public class TopLevelRaiseHandler extends RubyNode {

@Child private RubyNode body;
@Child private IntegerCastNode integerCastNode;

public TopLevelRaiseHandler(RubyContext context, SourceSection sourceSection, RubyNode body) {
super(context, sourceSection);
@@ -49,7 +53,7 @@ private void handleException(RaiseException e) {
final int status;

if (Layouts.BASIC_OBJECT.getLogicalClass(rubyException) == getContext().getCoreLibrary().getSystemExitClass()) {
status = (int) rubyException.get("@status", null);
status = castToInt(rubyException.get("@status", null));
} else {
status = 1;
BacktraceFormatter.createDefaultFormatter(getContext()).printBacktrace((DynamicObject) rubyException, Layouts.EXCEPTION.getBacktrace((DynamicObject) rubyException));
@@ -60,4 +64,12 @@ private void handleException(RaiseException e) {
System.exit(status);
}

private int castToInt(Object value) {
if (integerCastNode == null) {
CompilerDirectives.transferToInterpreter();
integerCastNode = insert(IntegerCastNodeGen.create(getContext(), getSourceSection(), null));
}
return integerCastNode.executeCastInt(value);
}

}
Original file line number Diff line number Diff line change
@@ -193,7 +193,7 @@ protected int getLimit(VirtualFrame frame) {
setupLimitCall();
setupLimitIntegerCast();

return limitIntegerCast.executeInteger(frame, limitCall.call(frame, getBigDecimalClass(), "limit", null));
return limitIntegerCast.executeCastInt(limitCall.call(frame, getBigDecimalClass(), "limit", null));
}

private void setupRoundModeCall() {
@@ -214,9 +214,8 @@ protected RoundingMode getRoundMode(VirtualFrame frame) {
setupRoundModeCall();
setupRoundModeIntegerCast();

return toRoundingMode(roundModeIntegerCast.executeInteger(frame,
// TODO (pitr 21-Jun-2015): read the actual constant
roundModeCall.call(frame, getBigDecimalClass(), "mode", null, 256)));
return toRoundingMode(roundModeIntegerCast.executeCastInt(// TODO (pitr 21-Jun-2015): read the actual constant
roundModeCall.call(frame, getBigDecimalClass(), "mode", null, 256)));
}

protected DynamicObject getBigDecimalClass() {
@@ -1233,7 +1232,7 @@ public Object divmodSpecial(VirtualFrame frame, DynamicObject a, DynamicObject b
setupLimitIntegerCast();

final int signA = aType == Type.POSITIVE_INFINITY ? 1 : -1;
final int signB = Integer.signum(signIntegerCast.executeInteger(frame, signCall.call(frame, b, "sign", null)));
final int signB = Integer.signum(signIntegerCast.executeCastInt(signCall.call(frame, b, "sign", null)));
final int sign = signA * signB; // is between -1 and 1, 0 when nan

final Type type = new Type[]{ Type.NEGATIVE_INFINITY, Type.NAN, Type.POSITIVE_INFINITY }[sign + 1];
@@ -1656,7 +1655,7 @@ public GetIntegerConstantNode(RubyContext context, SourceSection sourceSection)
@Specialization(guards = "isRubyModule(module)")
public int doInteger(VirtualFrame frame, DynamicObject module, String name) {
final Object value = readConstantNode.readConstant(frame, module, name);
return integerCastNode.executeInteger(frame, toIntNode.executeIntOrLong(frame, value));
return integerCastNode.executeCastInt(toIntNode.executeIntOrLong(frame, value));
}
}

0 comments on commit 875b70f

Please sign in to comment.