Skip to content

Commit

Permalink
Showing 38 changed files with 167 additions and 173 deletions.
1 change: 1 addition & 0 deletions spec/ruby/core/string/byteslice_spec.rb
Original file line number Diff line number Diff line change
@@ -22,6 +22,7 @@
"\u3042".byteslice(1).should == "\x81".force_encoding("UTF-8")
"\u3042".byteslice(1, 2).should == "\x81\x82".force_encoding("UTF-8")
"\u3042".byteslice(1..2).should == "\x81\x82".force_encoding("UTF-8")
"\u3042".byteslice(-1).should == "\x82".force_encoding("UTF-8")
end
end
end
Original file line number Diff line number Diff line change
@@ -168,7 +168,7 @@ private static RubyRootNode makeGenericMethod(RubyContext context, MethodDetails
final List<RubyNode> argumentsNodes = new ArrayList<>();

if (needsCallerFrame) {
argumentsNodes.add(new ReadCallerFrameNode(context, sourceSection));
argumentsNodes.add(new ReadCallerFrameNode());
}

// Do not use needsSelf=true in module functions, it is either the module/class or the instance.
@@ -190,7 +190,7 @@ private static RubyRootNode makeGenericMethod(RubyContext context, MethodDetails
}

for (int n = 0; n < arity.getPreRequired() + arity.getOptional(); n++) {
RubyNode readArgumentNode = new ReadPreArgumentNode(context, sourceSection, n, MissingArgumentBehavior.UNDEFINED);
RubyNode readArgumentNode = new ReadPreArgumentNode(n, MissingArgumentBehavior.UNDEFINED);

if (ArrayUtils.contains(method.lowerFixnumParameters(), n)) {
readArgumentNode = FixnumLowerNodeGen.create(context, sourceSection, readArgumentNode);
@@ -203,11 +203,11 @@ private static RubyRootNode makeGenericMethod(RubyContext context, MethodDetails
argumentsNodes.add(readArgumentNode);
}
if (method.rest()) {
argumentsNodes.add(new ReadRemainingArgumentsNode(context, sourceSection, arity.getPreRequired() + arity.getOptional()));
argumentsNodes.add(new ReadRemainingArgumentsNode(arity.getPreRequired() + arity.getOptional()));
}

if (method.needsBlock()) {
argumentsNodes.add(new ReadBlockNode(context, sourceSection, NotProvided.INSTANCE));
argumentsNodes.add(new ReadBlockNode(NotProvided.INSTANCE));
}

final RubyNode methodNode;
Original file line number Diff line number Diff line change
@@ -2105,7 +2105,7 @@ public MaxBlock(RubyContext context) {

callTarget = Truffle.getRuntime().createCallTarget(new RubyRootNode(context, sourceSection, null, sharedMethodInfo, MaxBlockNodeFactory.create(context, sourceSection, new RubyNode[]{
new ReadDeclarationVariableNode(context, sourceSection, LocalVariableType.FRAME_LOCAL, 1, frameSlot),
new ReadPreArgumentNode(context, sourceSection, 0, MissingArgumentBehavior.RUNTIME_ERROR)
new ReadPreArgumentNode(0, MissingArgumentBehavior.RUNTIME_ERROR)
}), false));
}

@@ -2223,7 +2223,7 @@ public MinBlock(RubyContext context) {

callTarget = Truffle.getRuntime().createCallTarget(new RubyRootNode(context, sourceSection, null, sharedMethodInfo, MinBlockNodeFactory.create(context, sourceSection, new RubyNode[]{
new ReadDeclarationVariableNode(context, sourceSection, LocalVariableType.FRAME_LOCAL, 1, frameSlot),
new ReadPreArgumentNode(context, sourceSection, 0, MissingArgumentBehavior.RUNTIME_ERROR)
new ReadPreArgumentNode(0, MissingArgumentBehavior.RUNTIME_ERROR)
}), false));
}

Original file line number Diff line number Diff line change
@@ -13,11 +13,12 @@
import com.oracle.truffle.api.profiles.ConditionProfile;
import com.oracle.truffle.api.source.SourceSection;
import org.jruby.truffle.RubyContext;
import org.jruby.truffle.language.RubyBaseNode;
import org.jruby.truffle.language.RubyNode;
import org.jruby.truffle.language.dispatch.CallDispatchHeadNode;
import org.jruby.truffle.language.dispatch.DispatchHeadNodeFactory;

public class HashNode extends RubyNode {
public class HashNode extends RubyBaseNode {

@Child private CallDispatchHeadNode hashNode;

@@ -41,9 +42,4 @@ public int hash(VirtualFrame frame, Object key) {
}
}

@Override
public Object execute(VirtualFrame frame) {
throw new UnsupportedOperationException();
}

}
Original file line number Diff line number Diff line change
@@ -17,11 +17,12 @@
import org.jruby.truffle.core.Layouts;
import org.jruby.truffle.core.basicobject.BasicObjectNodes;
import org.jruby.truffle.core.basicobject.BasicObjectNodesFactory;
import org.jruby.truffle.language.RubyBaseNode;
import org.jruby.truffle.language.RubyNode;
import org.jruby.truffle.language.dispatch.CallDispatchHeadNode;
import org.jruby.truffle.language.dispatch.DispatchHeadNodeFactory;

public class LookupEntryNode extends RubyNode {
public class LookupEntryNode extends RubyBaseNode {

@Child HashNode hashNode;
@Child CallDispatchHeadNode eqlNode;
@@ -63,9 +64,4 @@ public HashLookupResult lookup(VirtualFrame frame, DynamicObject hash, Object ke
return new HashLookupResult(hashed, index, previousEntry, null);
}

@Override
public Object execute(VirtualFrame frame) {
throw new UnsupportedOperationException();
}

}
Original file line number Diff line number Diff line change
@@ -432,7 +432,7 @@ public DynamicObject generateAccessor(VirtualFrame frame, DynamicObject module,
if (isGetter) {
accessInstanceVariable = new ReadInstanceVariableNode(getContext(), sourceSection, ivar, self);
} else {
ReadPreArgumentNode readArgument = new ReadPreArgumentNode(getContext(), sourceSection, 0, MissingArgumentBehavior.RUNTIME_ERROR);
ReadPreArgumentNode readArgument = new ReadPreArgumentNode(0, MissingArgumentBehavior.RUNTIME_ERROR);
accessInstanceVariable = new WriteInstanceVariableNode(getContext(), sourceSection, ivar, self, readArgument);
}
final RubyNode sequence = Translator.sequence(getContext(), sourceSection, Arrays.asList(checkArity, accessInstanceVariable));
Original file line number Diff line number Diff line change
@@ -17,12 +17,13 @@
import org.jruby.truffle.RubyContext;
import org.jruby.truffle.core.CoreLibrary;
import org.jruby.truffle.core.Layouts;
import org.jruby.truffle.language.RubyBaseNode;
import org.jruby.truffle.language.RubyNode;

import java.math.BigDecimal;
import java.math.BigInteger;

public class FixnumOrBignumNode extends RubyNode {
public class FixnumOrBignumNode extends RubyBaseNode {

private static final BigInteger LONG_MIN_BIGINT = BigInteger.valueOf(Long.MIN_VALUE);
private static final BigInteger LONG_MAX_BIGINT = BigInteger.valueOf(Long.MAX_VALUE);
@@ -76,8 +77,4 @@ private static BigInteger doubleToBigInteger(double value) {
return new BigDecimal(value).toBigInteger();
}

public Object execute(VirtualFrame frame) {
throw new UnsupportedOperationException();
}

}
Original file line number Diff line number Diff line change
@@ -16,12 +16,13 @@
import com.oracle.truffle.api.source.SourceSection;
import org.jruby.truffle.RubyContext;
import org.jruby.truffle.core.Layouts;
import org.jruby.truffle.language.RubyBaseNode;
import org.jruby.truffle.language.RubyNode;
import org.jruby.truffle.language.control.RaiseException;

import java.math.BigInteger;

public class GeneralDivModNode extends RubyNode {
public class GeneralDivModNode extends RubyBaseNode {

@Child private FixnumOrBignumNode fixnumOrBignumQuotient;
@Child private FixnumOrBignumNode fixnumOrBignumRemainder;
@@ -172,9 +173,4 @@ public DynamicObject create(BigInteger value) {
return Layouts.BIGNUM.createBignum(coreLibrary().getBignumFactory(), value);
}

@Override
public Object execute(VirtualFrame frame) {
throw new UnsupportedOperationException();
}

}
Original file line number Diff line number Diff line change
@@ -449,7 +449,8 @@ public IOSeekPrimitiveNode(RubyContext context, SourceSection sourceSection) {
@Specialization
public int seek(VirtualFrame frame, DynamicObject io, int amount, int whence) {
final int fd = Layouts.IO.getDescriptor(io);
return ensureSuccessful(posix().lseek(fd, amount, whence));
// TODO (pitr-ch 15-Apr-2016): should it have ensureSuccessful too?
return posix().lseek(fd, amount, whence);
}

}
Original file line number Diff line number Diff line change
@@ -42,17 +42,17 @@ public RubyNode createCallPrimitiveNode(RubyContext context, SourceSection sourc
return new CallRubiniusPrimitiveNode(context, sourceSection,
MethodNodesFactory.CallNodeFactory.create(context, sourceSection, new RubyNode[] {
new ObjectLiteralNode(context, sourceSection, method),
new ReadAllArgumentsNode(context, sourceSection),
new ReadBlockNode(context, sourceSection, NotProvided.INSTANCE)
new ReadAllArgumentsNode(),
new ReadBlockNode(NotProvided.INSTANCE)
}), returnID);
}

@Override
public RubyNode createInvokePrimitiveNode(RubyContext context, SourceSection sourceSection, RubyNode[] arguments) {
return MethodNodesFactory.CallNodeFactory.create(context, sourceSection, new RubyNode[] {
new ObjectLiteralNode(context, sourceSection, method),
new ObjectArrayNode(context, sourceSection, arguments),
new ReadBlockNode(context, sourceSection, NotProvided.INSTANCE)
new ObjectArrayNode(arguments),
new ReadBlockNode(NotProvided.INSTANCE)
});
}

Original file line number Diff line number Diff line change
@@ -55,7 +55,7 @@ public RubyNode createCallPrimitiveNode(RubyContext context, SourceSection sourc
}

for (int n = 0; n < argumentsCount; n++) {
RubyNode readArgumentNode = new ReadPreArgumentNode(context, sourceSection, n, MissingArgumentBehavior.UNDEFINED);
RubyNode readArgumentNode = new ReadPreArgumentNode(n, MissingArgumentBehavior.UNDEFINED);
arguments.add(transformArgument(readArgumentNode, n));
}

@@ -91,7 +91,7 @@ public RubyNode createInvokePrimitiveNode(RubyContext context, SourceSection sou

private RubyNode transformArgument(RubyNode argument, int n) {
if (ArrayUtils.contains(annotation.lowerFixnumParameters(), n)) {
return FixnumLowerNodeGen.create(argument.getContext(), argument.getSourceSection(), argument);
return FixnumLowerNodeGen.create(null, null, argument);
} else {
return argument;
}
Original file line number Diff line number Diff line change
@@ -87,12 +87,16 @@
import org.jruby.truffle.core.encoding.EncodingNodes;
import org.jruby.truffle.core.encoding.EncodingOperations;
import org.jruby.truffle.core.rope.CodeRange;
import org.jruby.truffle.core.rope.ConcatRope;
import org.jruby.truffle.core.rope.LeafRope;
import org.jruby.truffle.core.rope.RepeatingRope;
import org.jruby.truffle.core.rope.Rope;
import org.jruby.truffle.core.rope.RopeBuffer;
import org.jruby.truffle.core.rope.RopeConstants;
import org.jruby.truffle.core.rope.RopeNodes;
import org.jruby.truffle.core.rope.RopeNodesFactory;
import org.jruby.truffle.core.rope.RopeOperations;
import org.jruby.truffle.core.rope.SubstringRope;
import org.jruby.truffle.core.string.StringGuards;
import org.jruby.truffle.core.string.StringOperations;
import org.jruby.truffle.language.NotProvided;
@@ -342,14 +346,14 @@ public Object stringByteSubstring(DynamicObject string, int index, int length,
}

final Rope rope = rope(string);
final int stringLength = rope.characterLength();
final int normalizedIndex = StringOperations.normalizeIndex(stringLength, index);
final int stringByteLength = rope.byteLength();
final int normalizedIndex = StringOperations.normalizeIndex(stringByteLength, index);

if (indexOutOfBoundsProfile.profile(normalizedIndex < 0 || normalizedIndex > rope.byteLength())) {
if (indexOutOfBoundsProfile.profile(normalizedIndex < 0 || normalizedIndex > stringByteLength)) {
return nil();
}

if (lengthTooLongProfile.profile(normalizedIndex + length > rope.byteLength())) {
if (lengthTooLongProfile.profile(normalizedIndex + length > stringByteLength)) {
length = rope.byteLength() - normalizedIndex;
}

@@ -1681,65 +1685,93 @@ public StringSubstringPrimitiveNode(RubyContext context, SourceSection sourceSec

public abstract Object execute(VirtualFrame frame, DynamicObject string, int beg, int len);

@Specialization(guards = { "len >= 0" , "isSingleByteOptimizable(string)" })
@Specialization(guards = "!indexTriviallyOutOfBounds(string, beg, len)")
public Object stringSubstring(DynamicObject string, int beg, int len,
@Cached("createBinaryProfile()") ConditionProfile emptyStringProfile,
@Cached("createBinaryProfile()") ConditionProfile tooLargeBeginProfile,
@Cached("createBinaryProfile()") ConditionProfile negativeBeginProfile,
@Cached("createBinaryProfile()") ConditionProfile stillNegativeBeginProfile,
@Cached("createBinaryProfile()") ConditionProfile tooLargeTotalProfile,
@Cached("createBinaryProfile()") ConditionProfile negativeLengthProfile,
@Cached("createBinaryProfile()") ConditionProfile mutableRopeProfile) {
// Taken from org.jruby.RubyString#substr19.
@Cached("createBinaryProfile()") ConditionProfile negativeIndexProfile,
@Cached("createBinaryProfile()") ConditionProfile stillNegativeIndexProfile,
@Cached("createBinaryProfile()") ConditionProfile tooLargeTotalProfile,
@Cached("createBinaryProfile()") ConditionProfile singleByteOptimizableProfile,
@Cached("createBinaryProfile()") ConditionProfile mutableRopeProfile,
@Cached("createBinaryProfile()") ConditionProfile foundSingleByteOptimizableDescendentProfile) {
final Rope rope = rope(string);
if (emptyStringProfile.profile(rope.isEmpty())) {
len = 0;
}

final int length = rope.byteLength();
if (tooLargeBeginProfile.profile(beg > length)) {
return nil();
}

if (negativeBeginProfile.profile(beg < 0)) {
beg += length;
int index = beg;
int length = len;
if (negativeIndexProfile.profile(index < 0)) {
index += rope.characterLength();

if (stillNegativeBeginProfile.profile(beg < 0)) {
if (stillNegativeIndexProfile.profile(index < 0)) {
return nil();
}
}

if (tooLargeTotalProfile.profile((beg + len) > length)) {
len = length - beg;
if (tooLargeTotalProfile.profile(index + length > rope.characterLength())) {
length = rope.characterLength() - index;
}

if (negativeLengthProfile.profile(len <= 0)) {
len = 0;
beg = 0;
}
if (singleByteOptimizableProfile.profile((length == 0) || rope.isSingleByteOptimizable())) {
if (mutableRopeProfile.profile(rope instanceof RopeBuffer)) {
return makeBuffer(string, index, length);
}

return makeRope(string, rope, index, length);
} else {
final Rope searched = searchForSingleByteOptimizableDescendant(rope, index, length);

if (mutableRopeProfile.profile(rope instanceof RopeBuffer)) {
return makeBuffer(string, beg, len);
if (foundSingleByteOptimizableDescendentProfile.profile(searched.isSingleByteOptimizable())) {
return makeRope(string, searched, index, length);
}

return stringSubstringMultitByte(string, index, length);
}
}

@TruffleBoundary
private Rope searchForSingleByteOptimizableDescendant(Rope base, int index, int length) {
// If we've found something that's single-byte optimizable, we can halt the search. Taking a substring of
// a single byte optimizable rope is a fast operation.
if (base.isSingleByteOptimizable()) {
return base;
}

if (base instanceof LeafRope) {
return base;
} else if (base instanceof SubstringRope) {
final SubstringRope substringRope = (SubstringRope) base;
return searchForSingleByteOptimizableDescendant(substringRope.getChild(), index + substringRope.getOffset(), length);
} else if (base instanceof ConcatRope) {
final ConcatRope concatRope = (ConcatRope) base;
final Rope left = concatRope.getLeft();
final Rope right = concatRope.getRight();

if (index < left.byteLength()) {
return searchForSingleByteOptimizableDescendant(left, index, length);
} else if (index >= left.byteLength()) {
return searchForSingleByteOptimizableDescendant(right, index - left.byteLength(), length);
} else {
return concatRope;
}
} else if (base instanceof RepeatingRope) {
final RepeatingRope repeatingRope = (RepeatingRope) base;

return makeRope(string, beg, len);
if (index + length < repeatingRope.getChild().byteLength()) {
return searchForSingleByteOptimizableDescendant(repeatingRope.getChild(), index, length);
} else {
return repeatingRope;
}
} else {
CompilerDirectives.transferToInterpreter();
throw new UnsupportedOperationException("Don't know how to traverse rope type: " + base.getClass().getName());
}
}

@TruffleBoundary
@Specialization(guards = { "len >= 0", "!isSingleByteOptimizable(string)" })
public Object stringSubstring(DynamicObject string, int beg, int len) {
private Object stringSubstringMultitByte(DynamicObject string, int beg, int len) {
// Taken from org.jruby.RubyString#substr19 & org.jruby.RubyString#multibyteSubstr19.

final Rope rope = rope(string);
final int length = rope.byteLength();

if (rope.isEmpty()) {
len = 0;
}

if ((beg + len) > length) {
len = length - beg;
}
final boolean isMutableRope = rope instanceof RopeBuffer;

final Encoding enc = rope.getEncoding();
int p;
@@ -1761,7 +1793,12 @@ public Object stringSubstring(DynamicObject string, int beg, int len) {
if (p == -1) {
return nil();
}
return makeRope(string, p - s, e - p);

if (isMutableRope) {
return makeBuffer(string, p - s, e - p);
}

return makeRope(string, rope, p - s, e - p);
} else {
beg += rope.characterLength();
if (beg < 0) {
@@ -1792,15 +1829,26 @@ public Object stringSubstring(DynamicObject string, int beg, int len) {
} else {
len = StringSupport.offset(enc, bytes, p, end, len);
}
return makeRope(string, p - s, len);

if (isMutableRope) {
return makeBuffer(string, p - s, len);
}

return makeRope(string, rope, p - s, len);
}

@Specialization(guards = "len < 0")
@Specialization(guards = "indexTriviallyOutOfBounds(string, beg, len)")
public Object stringSubstringNegativeLength(DynamicObject string, int beg, int len) {
return nil();
}

private DynamicObject makeRope(DynamicObject string, int beg, int len) {
protected static boolean indexTriviallyOutOfBounds(DynamicObject string, int index, int length) {
assert RubyGuards.isRubyString(string);

return (length < 0) || (index > rope(string).characterLength());
}

private DynamicObject makeRope(DynamicObject string, Rope rope, int beg, int len) {
assert RubyGuards.isRubyString(string);

if (allocateNode == null) {
@@ -1820,7 +1868,7 @@ private DynamicObject makeRope(DynamicObject string, int beg, int len) {

final DynamicObject ret = allocateNode.allocate(
Layouts.BASIC_OBJECT.getLogicalClass(string),
makeSubstringNode.executeMake(rope(string), beg, len),
makeSubstringNode.executeMake(rope, beg, len),
null);

taintResultNode.maybeTaint(string, ret);
@@ -1831,11 +1879,6 @@ private DynamicObject makeRope(DynamicObject string, int beg, int len) {
private DynamicObject makeBuffer(DynamicObject string, int beg, int len) {
assert RubyGuards.isRubyString(string);

if (!StringGuards.isSingleByteOptimizable(string)) {
CompilerDirectives.transferToInterpreter();
throw new RaiseException(getContext().getCoreExceptions().internalError("Taking the substring of MBC rope buffer is not currently supported", this));
}

final RopeBuffer buffer = (RopeBuffer) rope(string);

if (allocateNode == null) {
Original file line number Diff line number Diff line change
@@ -433,7 +433,7 @@ public Object getIndex(VirtualFrame frame, DynamicObject string, int index, Obje
final int stringLength = rope.characterLength();
int normalizedIndex = StringOperations.normalizeIndex(stringLength, index);

if (normalizedIndex < 0 || normalizedIndex >= rope.byteLength()) {
if (normalizedIndex < 0 || normalizedIndex >= rope.characterLength()) {
outOfBounds.enter();
return nil();
} else {
@@ -1825,12 +1825,17 @@ public SizeNode(RubyContext context, SourceSection sourceSection) {

@Specialization
public int size(DynamicObject string,
@Cached("createBinaryProfile()") ConditionProfile mutableRopeProfile) {
@Cached("createBinaryProfile()") ConditionProfile ropeBufferProfile,
@Cached("createBinaryProfile()") ConditionProfile isSingleByteOptimizableRopeBufferProfile) {
final Rope rope = rope(string);

if (mutableRopeProfile.profile(rope instanceof RopeBuffer)) {
// TODO (nirvdrum 11-Mar-16): This response is only correct for CR_7BIT. Mutable ropes have not been updated for multi-byte characters.
return ((RopeBuffer) rope).getByteList().realSize();
if (ropeBufferProfile.profile(rope instanceof RopeBuffer)) {
if (isSingleByteOptimizableRopeBufferProfile.profile(rope.isSingleByteOptimizable())) {
return ((RopeBuffer) rope).getByteList().realSize();
} else {
final ByteList byteList = ((RopeBuffer) rope).getByteList();
return RopeOperations.strLength(rope.getEncoding(), byteList.unsafeBytes(), byteList.begin(), byteList.realSize());
}
} else {
return rope.characterLength();
}
Original file line number Diff line number Diff line change
@@ -50,7 +50,6 @@ public RubyBaseNode() {
}

public RubyBaseNode(RubyContext context, SourceSection sourceSection) {
assert context != null;
this.context = context;
this.sourceSection = sourceSection;
}
Original file line number Diff line number Diff line change
@@ -11,8 +11,6 @@

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.RubyContext;
import org.jruby.truffle.core.Layouts;
import org.jruby.truffle.language.RubyNode;

@@ -22,9 +20,7 @@ public class ArrayIsAtLeastAsLargeAsNode extends RubyNode {

@Child private RubyNode child;

public ArrayIsAtLeastAsLargeAsNode(RubyContext context, SourceSection sourceSection,
int requiredSize, RubyNode child) {
super(context, sourceSection);
public ArrayIsAtLeastAsLargeAsNode(int requiredSize, RubyNode child) {
this.requiredSize = requiredSize;
this.child = child;
}
Original file line number Diff line number Diff line change
@@ -11,8 +11,6 @@

import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.profiles.BranchProfile;
import com.oracle.truffle.api.source.SourceSection;
import org.jruby.truffle.RubyContext;
import org.jruby.truffle.language.RubyNode;
import org.jruby.truffle.language.control.RaiseException;
import org.jruby.truffle.language.methods.Arity;
@@ -23,8 +21,7 @@ public class CheckArityNode extends RubyNode {

private final BranchProfile checkFailedProfile = BranchProfile.create();

public CheckArityNode(RubyContext context, SourceSection sourceSection, Arity arity) {
super(context, sourceSection);
public CheckArityNode(Arity arity) {
this.arity = arity;
}

Original file line number Diff line number Diff line change
@@ -35,7 +35,7 @@ public class CheckKeywordArityNode extends RubyNode {
public CheckKeywordArityNode(RubyContext context, SourceSection sourceSection, Arity arity) {
super(context, sourceSection);
this.arity = arity;
readUserKeywordsHashNode = new ReadUserKeywordsHashNode(context, sourceSection, arity.getRequired());
readUserKeywordsHashNode = new ReadUserKeywordsHashNode(arity.getRequired());
}

@Override
Original file line number Diff line number Diff line change
@@ -10,17 +10,14 @@
package org.jruby.truffle.language.arguments;

import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.source.SourceSection;
import org.jruby.truffle.RubyContext;
import org.jruby.truffle.language.RubyNode;
import org.jruby.truffle.language.control.RaiseException;

public class MissingKeywordArgumentNode extends RubyNode {

private final String name;

public MissingKeywordArgumentNode(RubyContext context, SourceSection sourceSection, String name) {
super(context, sourceSection);
public MissingKeywordArgumentNode(String name) {
this.name = name;
}

Original file line number Diff line number Diff line change
@@ -11,16 +11,13 @@

import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.nodes.ExplodeLoop;
import com.oracle.truffle.api.source.SourceSection;
import org.jruby.truffle.RubyContext;
import org.jruby.truffle.language.RubyNode;

public class ObjectArrayNode extends RubyNode {

@Children private final RubyNode[] nodes;

public ObjectArrayNode(RubyContext context, SourceSection sourceSection, RubyNode[] nodes) {
super(context, sourceSection);
public ObjectArrayNode(RubyNode[] nodes) {
this.nodes = nodes;
}

Original file line number Diff line number Diff line change
@@ -16,10 +16,6 @@

public class ReadAllArgumentsNode extends RubyNode {

public ReadAllArgumentsNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
}

@Override
public Object[] executeObjectArray(VirtualFrame frame) {
return RubyArguments.getArguments(frame);
Original file line number Diff line number Diff line change
@@ -12,8 +12,6 @@
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.object.DynamicObject;
import com.oracle.truffle.api.profiles.ConditionProfile;
import com.oracle.truffle.api.source.SourceSection;
import org.jruby.truffle.RubyContext;
import org.jruby.truffle.language.RubyNode;

public class ReadBlockNode extends RubyNode {
@@ -22,8 +20,7 @@ public class ReadBlockNode extends RubyNode {

private final ConditionProfile blockProfile = ConditionProfile.createBinaryProfile();

public ReadBlockNode(RubyContext context, SourceSection sourceSection, Object valueIfAbsent) {
super(context, sourceSection);
public ReadBlockNode(Object valueIfAbsent) {
this.valueIfAbsent = valueIfAbsent;
}

Original file line number Diff line number Diff line change
@@ -11,19 +11,13 @@

import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.profiles.ConditionProfile;
import com.oracle.truffle.api.source.SourceSection;
import org.jruby.truffle.RubyContext;
import org.jruby.truffle.language.NotProvided;
import org.jruby.truffle.language.RubyNode;

public class ReadCallerFrameNode extends RubyNode {

private final ConditionProfile callerFrameProfile = ConditionProfile.createBinaryProfile();

public ReadCallerFrameNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
}

@Override
public Object execute(VirtualFrame frame) {
final Object callerFrame = RubyArguments.getCallerFrame(frame);
Original file line number Diff line number Diff line change
@@ -33,7 +33,7 @@ public ReadKeywordArgumentNode(RubyContext context, SourceSection sourceSection,
super(context, sourceSection);
this.name = name;
this.defaultValue = defaultValue;
readUserKeywordsHashNode = new ReadUserKeywordsHashNode(context, sourceSection, minimum);
readUserKeywordsHashNode = new ReadUserKeywordsHashNode(minimum);
}

@Override
Original file line number Diff line number Diff line change
@@ -37,7 +37,7 @@ public ReadKeywordRestArgumentNode(RubyContext context, SourceSection sourceSect
int minimum, String[] excludedKeywords) {
super(context, sourceSection);
this.excludedKeywords = excludedKeywords;
readUserKeywordsHashNode = new ReadUserKeywordsHashNode(context, sourceSection, minimum);
readUserKeywordsHashNode = new ReadUserKeywordsHashNode(minimum);
}

@Override
Original file line number Diff line number Diff line change
@@ -45,7 +45,7 @@ public ReadOptionalArgumentNode(RubyContext context, SourceSection sourceSection
this.reduceMinimumWhenNoKWargs = reduceMinimumWhenNoKWargs;

if (reduceMinimumWhenNoKWargs) {
readUserKeywordsHashNode = new ReadUserKeywordsHashNode(context, sourceSection, requiredForKWArgs);
readUserKeywordsHashNode = new ReadUserKeywordsHashNode(requiredForKWArgs);
}
}

Original file line number Diff line number Diff line change
@@ -10,16 +10,13 @@
package org.jruby.truffle.language.arguments;

import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.source.SourceSection;
import org.jruby.truffle.RubyContext;
import org.jruby.truffle.language.RubyNode;

public class ReadPostArgumentNode extends RubyNode {

private final int indexFromCount;

public ReadPostArgumentNode(RubyContext context, SourceSection sourceSection, int indexFromCount) {
super(context, sourceSection);
public ReadPostArgumentNode(int indexFromCount) {
this.indexFromCount = indexFromCount;
}

Original file line number Diff line number Diff line change
@@ -12,8 +12,6 @@
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.profiles.BranchProfile;
import com.oracle.truffle.api.profiles.ValueProfile;
import com.oracle.truffle.api.source.SourceSection;
import org.jruby.truffle.RubyContext;
import org.jruby.truffle.language.NotProvided;
import org.jruby.truffle.language.RubyNode;

@@ -26,9 +24,8 @@ public class ReadPreArgumentNode extends RubyNode {

private final ValueProfile argumentValueProfile = ValueProfile.createEqualityProfile();

public ReadPreArgumentNode(RubyContext context, SourceSection sourceSection, int index,
public ReadPreArgumentNode(int index,
MissingArgumentBehavior missingArgumentBehavior) {
super(context, sourceSection);
this.index = index;
this.missingArgumentBehavior = missingArgumentBehavior;
}
Original file line number Diff line number Diff line change
@@ -11,17 +11,14 @@

import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.profiles.ConditionProfile;
import com.oracle.truffle.api.source.SourceSection;
import org.jruby.truffle.RubyContext;
import org.jruby.truffle.language.RubyNode;

public class ReadRemainingArgumentsNode extends RubyNode {

private final int start;
private final ConditionProfile remainingArguments = ConditionProfile.createBinaryProfile();

public ReadRemainingArgumentsNode(RubyContext context, SourceSection sourceSection, int start) {
super(context, sourceSection);
public ReadRemainingArgumentsNode(int start) {
this.start = start;
}

Original file line number Diff line number Diff line change
@@ -39,7 +39,7 @@ public ReadRestArgumentNode(RubyContext context, SourceSection sourceSection, in
this.keywordArguments = keywordArguments;

if (keywordArguments) {
readUserKeywordsHashNode = new ReadUserKeywordsHashNode(context, sourceSection, minimumForKWargs);
readUserKeywordsHashNode = new ReadUserKeywordsHashNode(minimumForKWargs);
}
}

Original file line number Diff line number Diff line change
@@ -12,8 +12,6 @@
import com.oracle.truffle.api.CompilerDirectives;
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.profiles.ConditionProfile;
import com.oracle.truffle.api.source.SourceSection;
import org.jruby.truffle.RubyContext;
import org.jruby.truffle.language.RubyGuards;
import org.jruby.truffle.language.RubyNode;

@@ -24,8 +22,7 @@ public class ReadUserKeywordsHashNode extends RubyNode {
private final ConditionProfile notEnoughArgumentsProfile = ConditionProfile.createBinaryProfile();
private final ConditionProfile lastArgumentIsHashProfile = ConditionProfile.createBinaryProfile();

public ReadUserKeywordsHashNode(RubyContext context, SourceSection sourceSection, int minArgumentCount) {
super(context, sourceSection);
public ReadUserKeywordsHashNode(int minArgumentCount) {
this.minArgumentCount = minArgumentCount;
}

Original file line number Diff line number Diff line change
@@ -12,8 +12,6 @@
import com.oracle.truffle.api.CompilerDirectives;
import com.oracle.truffle.api.frame.FrameSlot;
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.source.SourceSection;
import org.jruby.truffle.RubyContext;
import org.jruby.truffle.core.Layouts;
import org.jruby.truffle.language.RubyNode;
import org.jruby.truffle.language.locals.ReadFrameSlotNode;
@@ -28,8 +26,7 @@ public class RunBlockKWArgsHelperNode extends RubyNode {

private final Object kwrestName;

public RunBlockKWArgsHelperNode(RubyContext context, SourceSection sourceSection, FrameSlot arrayFrameSlot, Object kwrestName) {
super(context, sourceSection);
public RunBlockKWArgsHelperNode(FrameSlot arrayFrameSlot, Object kwrestName) {
readArrayNode = ReadFrameSlotNodeGen.create(arrayFrameSlot);
writeArrayNode = WriteFrameSlotNodeGen.create(arrayFrameSlot);
this.kwrestName = kwrestName;
Original file line number Diff line number Diff line change
@@ -12,8 +12,6 @@
import com.oracle.truffle.api.CompilerDirectives;
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.profiles.BranchProfile;
import com.oracle.truffle.api.source.SourceSection;
import org.jruby.truffle.RubyContext;
import org.jruby.truffle.language.RubyGuards;
import org.jruby.truffle.language.RubyNode;
import org.jruby.truffle.language.dispatch.RespondToNode;
@@ -25,8 +23,7 @@ public class ShouldDestructureNode extends RubyNode {

private final BranchProfile checkIsArrayProfile = BranchProfile.create();

public ShouldDestructureNode(RubyContext context, SourceSection sourceSection, RubyNode readArrayNode) {
super(context, sourceSection);
public ShouldDestructureNode(RubyNode readArrayNode) {
this.readArrayNode = readArrayNode;
}

Original file line number Diff line number Diff line change
@@ -2294,7 +2294,7 @@ public RubyNode visitMultipleAsgnNode(org.jruby.ast.MultipleAsgnNode node) {

final RubyNode assignPost =
new IfElseNode(context, sourceSection,
new ArrayIsAtLeastAsLargeAsNode(context, sourceSection, node.getPreCount() + node.getPostCount(), environment.findLocalVarNode(tempName, sourceSection)),
new ArrayIsAtLeastAsLargeAsNode(node.getPreCount() + node.getPostCount(), environment.findLocalVarNode(tempName, sourceSection)),
atLeastAsLarge,
smaller);

@@ -2434,7 +2434,7 @@ public RubyNode visitMultipleAsgnNode(org.jruby.ast.MultipleAsgnNode node) {

final RubyNode assignPost =
new IfElseNode(context, sourceSection,
new ArrayIsAtLeastAsLargeAsNode(context, sourceSection, node.getPreCount() + node.getPostCount(), environment.findLocalVarNode(tempName, sourceSection)),
new ArrayIsAtLeastAsLargeAsNode(node.getPreCount() + node.getPostCount(), environment.findLocalVarNode(tempName, sourceSection)),
atLeastAsLarge,
smaller);

Original file line number Diff line number Diff line change
@@ -123,8 +123,8 @@ public RubyNode visitArgsNode(org.jruby.ast.ArgsNode node) {
}

sequence.add(new IfNode(context, sourceSection,
new ArrayIsAtLeastAsLargeAsNode(context, sourceSection, node.getPreCount() + node.getPostCount(), loadArray(sourceSection)),
new RunBlockKWArgsHelperNode(context, sourceSection, arraySlotStack.peek().getArraySlot(), keyRestNameOrNil)));
new ArrayIsAtLeastAsLargeAsNode(node.getPreCount() + node.getPostCount(), loadArray(sourceSection)),
new RunBlockKWArgsHelperNode(arraySlotStack.peek().getArraySlot(), keyRestNameOrNil)));
}

final int preCount = node.getPreCount();
@@ -218,7 +218,7 @@ public RubyNode visitArgsNode(org.jruby.ast.ArgsNode node) {
if (useArray()) {
if (node.getPreCount() == 0 || node.hasRestArg()) {
sequence.add(new IfElseNode(context, sourceSection,
new ArrayIsAtLeastAsLargeAsNode(context, sourceSection, node.getPreCount() + node.getPostCount(), loadArray(sourceSection)),
new ArrayIsAtLeastAsLargeAsNode(node.getPreCount() + node.getPostCount(), loadArray(sourceSection)),
notNilAtLeastAsLarge,
notNilSmaller));
} else {
@@ -285,7 +285,7 @@ public RubyNode visitKeywordArgNode(org.jruby.ast.KeywordArgNode node) {
if (asgnNode.getValueNode() instanceof RequiredKeywordArgumentValueNode) {
/* This isn't a true default value - it's a marker to say there isn't one. This actually makes sense;
* the semantic action of executing this node is to report an error, and we do the same thing. */
defaultValue = new MissingKeywordArgumentNode(context, sourceSection, name);
defaultValue = new MissingKeywordArgumentNode(name);
} else {
defaultValue = translateNodeOrNil(sourceSection, asgnNode.getValueNode());
}
@@ -311,9 +311,9 @@ private RubyNode readArgument(SourceSection sourceSection) {
return PrimitiveArrayNodeFactory.read(context, sourceSection, loadArray(sourceSection), index);
} else {
if (state == State.PRE) {
return new ReadPreArgumentNode(context, sourceSection, index, isProc ? MissingArgumentBehavior.NIL : MissingArgumentBehavior.RUNTIME_ERROR);
return new ReadPreArgumentNode(index, isProc ? MissingArgumentBehavior.NIL : MissingArgumentBehavior.RUNTIME_ERROR);
} else if (state == State.POST) {
return new ReadPostArgumentNode(context, sourceSection, -index);
return new ReadPostArgumentNode(-index);
} else {
throw new IllegalStateException();
}
@@ -346,7 +346,7 @@ public RubyNode visitRestArgNode(org.jruby.ast.RestArgNode node) {
public RubyNode visitBlockArgNode(org.jruby.ast.BlockArgNode node) {
final SourceSection sourceSection = translate(node.getPosition());

final RubyNode readNode = new ReadBlockNode(context, sourceSection, context.getCoreLibrary().getNilObject());
final RubyNode readNode = new ReadBlockNode(context.getCoreLibrary().getNilObject());
final FrameSlot slot = methodBodyTranslator.getEnvironment().getFrameDescriptor().findFrameSlot(node.getName());
return new WriteLocalVariableNode(context, sourceSection, slot, readNode);
}
@@ -412,7 +412,7 @@ private RubyNode translateLocalAssignment(ISourcePosition sourcePosition, String
if (useArray()) {
// TODO CS 10-Jan-16 we should really hoist this check, or see if Graal does it for us
readNode = new IfElseNode(context, sourceSection,
new ArrayIsAtLeastAsLargeAsNode(context, sourceSection, minimum, loadArray(sourceSection)),
new ArrayIsAtLeastAsLargeAsNode(minimum, loadArray(sourceSection)),
PrimitiveArrayNodeFactory.read(context, sourceSection, loadArray(sourceSection), index),
defaultValue);
} else {
@@ -588,7 +588,7 @@ public RubyNode visitMultipleAsgnNode(MultipleAsgnNode node) {
new IsNilNode(context, sourceSection, new ReadLocalVariableNode(context, sourceSection, LocalVariableType.FRAME_LOCAL, arraySlot)),
nil,
new IfElseNode(context, sourceSection,
new ArrayIsAtLeastAsLargeAsNode(context, sourceSection, node.getPreCount() + node.getPostCount(), new ReadLocalVariableNode(context, sourceSection, LocalVariableType.FRAME_LOCAL, arraySlot)),
new ArrayIsAtLeastAsLargeAsNode(node.getPreCount() + node.getPostCount(), new ReadLocalVariableNode(context, sourceSection, LocalVariableType.FRAME_LOCAL, arraySlot)),
notNilAtLeastAsLarge,
notNilSmaller))));
}
Original file line number Diff line number Diff line change
@@ -95,7 +95,7 @@ public BlockDefinitionNode compileBlockNode(SourceSection sourceSection, String

final RubyNode preludeProc;
if (shouldConsiderDestructuringArrayArg(arity)) {
final RubyNode readArrayNode = new ReadPreArgumentNode(context, sourceSection, 0, MissingArgumentBehavior.RUNTIME_ERROR);
final RubyNode readArrayNode = new ReadPreArgumentNode(0, MissingArgumentBehavior.RUNTIME_ERROR);
final RubyNode castArrayNode = ArrayCastNodeGen.create(context, sourceSection, readArrayNode);

final FrameSlot arraySlot = environment.declareVar(environment.allocateLocalTemp("destructure"));
@@ -105,7 +105,7 @@ public BlockDefinitionNode compileBlockNode(SourceSection sourceSection, String
destructureArgumentsTranslator.pushArraySlot(arraySlot);
final RubyNode newDestructureArguments = argsNode.accept(destructureArgumentsTranslator);

final RubyNode shouldDestructure = new ShouldDestructureNode(context, sourceSection, readArrayNode);
final RubyNode shouldDestructure = new ShouldDestructureNode(readArrayNode);

final RubyNode arrayWasNotNil = sequence(context, sourceSection, Arrays.asList(writeArrayNode, new NotNode(context, sourceSection, new IsNilNode(context, sourceSection, new ReadLocalVariableNode(context, sourceSection, LocalVariableType.FRAME_LOCAL, arraySlot)))));

@@ -361,7 +361,7 @@ private RubyNode executeOrInheritBlock(SourceSection sourceSection, RubyNode blo
if (blockNode != null) {
return blockNode;
} else {
return new ReadBlockNode(context, sourceSection, context.getCoreLibrary().getNilObject());
return new ReadBlockNode(context.getCoreLibrary().getNilObject());
}
}

Original file line number Diff line number Diff line change
@@ -95,7 +95,7 @@ public RubyNode visitOptArgNode(org.jruby.ast.OptArgNode node) {
@Override
public RubyNode visitMultipleAsgnNode(org.jruby.ast.MultipleAsgnNode node) {
final SourceSection sourceSection = translate(node.getPosition());
return new ReadPreArgumentNode(context, sourceSection, index, MissingArgumentBehavior.NIL);
return new ReadPreArgumentNode(index, MissingArgumentBehavior.NIL);
}

@Override
Original file line number Diff line number Diff line change
@@ -72,6 +72,10 @@ public static SourceSection enclosing(SourceSection base, SourceSection... sourc
int endLine = base.getEndLine();

for (SourceSection sourceSection : sourceSections) {
if (sourceSection == null) {
continue;
}

startLine = Math.min(startLine, sourceSection.getStartLine());

final int nodeEndLine;
@@ -169,7 +173,7 @@ protected RubyNode translateNodeOrNil(SourceSection sourceSection, org.jruby.ast

public static RubyNode createCheckArityNode(RubyContext context, SourceSection sourceSection, Arity arity) {
if (!arity.acceptsKeywords()) {
return new CheckArityNode(context, sourceSection, arity);
return new CheckArityNode(arity);
} else {
return new CheckKeywordArityNode(context, sourceSection, arity);
}
Original file line number Diff line number Diff line change
@@ -173,7 +173,7 @@ public RubyRootNode parse(RubyContext context, Source source, Encoding defaultEn

for (int n = 0; n < argumentNames.length; n++) {
final String name = argumentNames[n];
final RubyNode readNode = new ReadPreArgumentNode(context, sourceSection, n, MissingArgumentBehavior.NIL);
final RubyNode readNode = new ReadPreArgumentNode(n, MissingArgumentBehavior.NIL);
final FrameSlot slot = environment.getFrameDescriptor().findFrameSlot(name);
sequence.add(new WriteLocalVariableNode(context, sourceSection, slot, readNode));
}

0 comments on commit b152edd

Please sign in to comment.