Skip to content

Commit

Permalink
Showing 36 changed files with 207 additions and 180 deletions.
Original file line number Diff line number Diff line change
@@ -13,9 +13,9 @@
import com.oracle.truffle.api.source.SourceSection;
import com.oracle.truffle.api.utilities.BranchProfile;
import org.jruby.truffle.nodes.RubyNode;
import org.jruby.truffle.nodes.core.array.ArrayNodes;
import org.jruby.truffle.runtime.RubyArguments;
import org.jruby.truffle.runtime.RubyContext;
import org.jruby.truffle.runtime.core.RubyArray;
import org.jruby.truffle.runtime.core.RubyClass;
import org.jruby.truffle.runtime.core.RubyHash;
import org.jruby.truffle.runtime.array.ArrayUtils;
@@ -59,16 +59,16 @@ public Object execute(VirtualFrame frame) {

if (startIndex == 0) {
final Object[] arguments = RubyArguments.extractUserArguments(frame.getArguments());
return new RubyArray(arrayClass, arguments, length);
return ArrayNodes.createArray(arrayClass, arguments, length);
} else {
if (startIndex >= endIndex) {
noArgumentsLeftProfile.enter();
return new RubyArray(arrayClass);
return ArrayNodes.createEmptyArray(arrayClass);
} else {
subsetOfArgumentsProfile.enter();
final Object[] arguments = RubyArguments.extractUserArguments(frame.getArguments());
// TODO(CS): risk here of widening types too much - always going to be Object[] - does seem to be something that does happen
return new RubyArray(arrayClass, ArrayUtils.extractRange(arguments, startIndex, endIndex), length);
return ArrayNodes.createArray(arrayClass, ArrayUtils.extractRange(arguments, startIndex, endIndex), length);
}
}
}
Original file line number Diff line number Diff line change
@@ -82,7 +82,7 @@ public RubyArray cast(RubyArray array) {
public Object cast(Object nil) {
switch (nilBehavior) {
case EMPTY_ARRAY:
return new RubyArray(getContext().getCoreLibrary().getArrayClass());
return ArrayNodes.createEmptyArray(getContext().getCoreLibrary().getArrayClass());

case ARRAY_WITH_NIL:
return ArrayNodes.fromObject(getContext().getCoreLibrary().getArrayClass(), nil());
Original file line number Diff line number Diff line change
@@ -64,7 +64,7 @@ public SplatCastNode(RubyContext context, SourceSection sourceSection, NilBehavi
public RubyArray splat(Object nil) {
switch (nilBehavior) {
case EMPTY_ARRAY:
return new RubyArray(getContext().getCoreLibrary().getArrayClass());
return ArrayNodes.createEmptyArray(getContext().getCoreLibrary().getArrayClass());

case ARRAY_WITH_NIL:
return ArrayNodes.fromObject(getContext().getCoreLibrary().getArrayClass(), nil());
Original file line number Diff line number Diff line change
@@ -20,6 +20,7 @@

import org.jruby.truffle.nodes.cast.BooleanCastNode;
import org.jruby.truffle.nodes.cast.BooleanCastNodeGen;
import org.jruby.truffle.nodes.core.array.ArrayNodes;
import org.jruby.truffle.nodes.dispatch.CallDispatchHeadNode;
import org.jruby.truffle.nodes.dispatch.DispatchHeadNodeFactory;
import org.jruby.truffle.runtime.RubyContext;
@@ -535,7 +536,7 @@ public RubyArray coerce(RubyBasicObject a, int b) {
// TODO (eregon, 16 Feb. 2015): This is NOT spec, but let's try to see if we can make it work.
// b is converted to a Bignum here in other implementations.
Object[] store = new Object[] { b, a };
return new RubyArray(getContext().getCoreLibrary().getArrayClass(), store, store.length);
return ArrayNodes.createArray(getContext().getCoreLibrary().getArrayClass(), store, store.length);
}

@Specialization
@@ -545,15 +546,15 @@ public RubyArray coerce(RubyBasicObject a, long b) {
// TODO (eregon, 16 Feb. 2015): This is NOT spec, but let's try to see if we can make it work.
// b is converted to a Bignum here in other implementations.
Object[] store = new Object[] { b, a };
return new RubyArray(getContext().getCoreLibrary().getArrayClass(), store, store.length);
return ArrayNodes.createArray(getContext().getCoreLibrary().getArrayClass(), store, store.length);
}

@Specialization(guards = "isRubyBignum(b)")
public RubyArray coerce(RubyBasicObject a, RubyBasicObject b) {
CompilerDirectives.transferToInterpreter();

Object[] store = new Object[] { b, a };
return new RubyArray(getContext().getCoreLibrary().getArrayClass(), store, store.length);
return ArrayNodes.createArray(getContext().getCoreLibrary().getArrayClass(), store, store.length);
}

}
Original file line number Diff line number Diff line change
@@ -243,7 +243,7 @@ public LocalVariablesNode(RubyContext context, SourceSection sourceSection) {
@TruffleBoundary
@Specialization
public RubyArray localVariables(RubyBinding binding) {
final RubyArray array = new RubyArray(getContext().getCoreLibrary().getArrayClass());
final RubyArray array = ArrayNodes.createEmptyArray(getContext().getCoreLibrary().getArrayClass());

MaterializedFrame frame = binding.getFrame();

Original file line number Diff line number Diff line change
@@ -21,6 +21,7 @@
import org.jcodings.util.Hash;
import org.jruby.truffle.nodes.coerce.ToStrNode;
import org.jruby.truffle.nodes.coerce.ToStrNodeGen;
import org.jruby.truffle.nodes.core.array.ArrayNodes;
import org.jruby.truffle.nodes.dispatch.CallDispatchHeadNode;
import org.jruby.truffle.nodes.dispatch.DispatchHeadNodeFactory;
import org.jruby.truffle.runtime.RubyContext;
@@ -278,7 +279,7 @@ public RubyArray list() {

final RubyEncoding[] encodings = RubyEncoding.cloneEncodingList();

return new RubyArray(getContext().getCoreLibrary().getArrayClass(), encodings, encodings.length);
return ArrayNodes.createArray(getContext().getCoreLibrary().getArrayClass(), encodings, encodings.length);
}
}

Original file line number Diff line number Diff line change
@@ -15,6 +15,7 @@
import com.oracle.truffle.api.utilities.BranchProfile;

import org.jruby.truffle.nodes.RubyNode;
import org.jruby.truffle.nodes.core.array.ArrayNodes;
import org.jruby.truffle.runtime.RubyContext;
import org.jruby.truffle.runtime.control.RaiseException;
import org.jruby.truffle.runtime.core.RubyArray;
@@ -108,13 +109,13 @@ private RubyArray divMod(long a, long b) {

if (integerDiv instanceof Long && ((long) integerDiv) >= Integer.MIN_VALUE && ((long) integerDiv) <= Integer.MAX_VALUE && mod >= Integer.MIN_VALUE && mod <= Integer.MAX_VALUE) {
useFixnumPairProfile.enter();
return new RubyArray(getContext().getCoreLibrary().getArrayClass(), new int[]{(int) (long) integerDiv, (int) mod}, 2);
return ArrayNodes.createArray(getContext().getCoreLibrary().getArrayClass(), new int[]{(int) (long) integerDiv, (int) mod}, 2);
} else if (integerDiv instanceof Long) {
useObjectPairProfile.enter();
return new RubyArray(getContext().getCoreLibrary().getArrayClass(), new Object[]{integerDiv, mod}, 2);
return ArrayNodes.createArray(getContext().getCoreLibrary().getArrayClass(), new Object[]{integerDiv, mod}, 2);
} else {
useObjectPairProfile.enter();
return new RubyArray(getContext().getCoreLibrary().getArrayClass(), new Object[]{
return ArrayNodes.createArray(getContext().getCoreLibrary().getArrayClass(), new Object[]{
fixnumOrBignumQuotient.fixnumOrBignum((BigInteger) integerDiv),
mod}, 2);
}
@@ -140,7 +141,7 @@ private RubyArray divMod(double a, double b) {
mod += b;
}

return new RubyArray(getContext().getCoreLibrary().getArrayClass(), new Object[]{
return ArrayNodes.createArray(getContext().getCoreLibrary().getArrayClass(), new Object[]{
fixnumOrBignumQuotient.fixnumOrBignum(div),
mod}, 2);
}
@@ -160,7 +161,7 @@ private RubyArray divMod(BigInteger a, BigInteger b) {
bigIntegerResults[1] = b.add(bigIntegerResults[1]);
}

return new RubyArray(getContext().getCoreLibrary().getArrayClass(), new Object[]{
return ArrayNodes.createArray(getContext().getCoreLibrary().getArrayClass(), new Object[]{
fixnumOrBignumQuotient.fixnumOrBignum(bigIntegerResults[0]),
fixnumOrBignumRemainder.fixnumOrBignum(bigIntegerResults[1])}, 2);
}
Original file line number Diff line number Diff line change
@@ -14,14 +14,14 @@
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.source.SourceSection;
import com.oracle.truffle.api.utilities.BranchProfile;
import org.jruby.truffle.nodes.core.array.ArrayNodes;
import org.jruby.truffle.nodes.methods.UnsupportedOperationBehavior;
import org.jruby.truffle.runtime.RubyContext;
import org.jruby.truffle.runtime.NotProvided;
import org.jruby.truffle.runtime.control.NextException;
import org.jruby.truffle.runtime.control.RedoException;
import org.jruby.truffle.runtime.core.RubyArray;
import org.jruby.truffle.runtime.core.RubyBasicObject;
import org.jruby.truffle.runtime.core.RubyBignum;
import org.jruby.truffle.runtime.core.RubyProc;

import java.math.BigInteger;
@@ -143,7 +143,7 @@ public RubyArray times(VirtualFrame frame, int n, NotProvided block) {
array[i] = i;
}

return new RubyArray(getContext().getCoreLibrary().getArrayClass(), array, n);
return ArrayNodes.createArray(getContext().getCoreLibrary().getArrayClass(), array, n);
}

@Specialization
Original file line number Diff line number Diff line change
@@ -330,7 +330,7 @@ public RubyArray callerLocations(int omit, int length) {
locations[n] = ThreadBacktraceLocationNodes.createRubyThreadBacktraceLocation(threadBacktraceLocationClass, activation);
}

return new RubyArray(getContext().getCoreLibrary().getArrayClass(), locations, locations.length);
return ArrayNodes.createArray(getContext().getCoreLibrary().getArrayClass(), locations, locations.length);
}
}

@@ -907,7 +907,7 @@ public RubyArray instanceVariables(RubyBasicObject self) {

Arrays.sort(instanceVariableNames);

final RubyArray array = new RubyArray(getContext().getCoreLibrary().getArrayClass());
final RubyArray array = ArrayNodes.createEmptyArray(getContext().getCoreLibrary().getArrayClass());

for (Object name : instanceVariableNames) {
if (name instanceof String) {
@@ -1007,7 +1007,7 @@ public LocalVariablesNode(RubyContext context, SourceSection sourceSection) {
public RubyArray localVariables() {
CompilerDirectives.transferToInterpreter();

final RubyArray array = new RubyArray(getContext().getCoreLibrary().getArrayClass());
final RubyArray array = ArrayNodes.createEmptyArray(getContext().getCoreLibrary().getArrayClass());

for (Object name : Truffle.getRuntime().getCallerFrame().getFrame(FrameInstance.FrameAccess.READ_ONLY, false).getFrameDescriptor().getIdentifiers()) {
if (name instanceof String) {
@@ -1540,7 +1540,7 @@ public RubyArray singletonMethods(VirtualFrame frame, Object self, boolean inclu
RubyClass metaClass = metaClassNode.executeMetaClass(frame, self);

if (!metaClass.isSingleton()) {
return new RubyArray(getContext().getCoreLibrary().getArrayClass());
return ArrayNodes.createEmptyArray(getContext().getCoreLibrary().getArrayClass());
}

CompilerDirectives.transferToInterpreter();
Original file line number Diff line number Diff line change
@@ -61,7 +61,7 @@ public Object getIndex(RubyMatchData matchData, int index, int length) {
final Object[] values = matchData.getValues();
final int normalizedIndex = ArrayNodes.normalizeIndex(values.length, index);
final Object[] store = Arrays.copyOfRange(values, normalizedIndex, normalizedIndex + length);
return new RubyArray(getContext().getCoreLibrary().getArrayClass(), store, length);
return ArrayNodes.createArray(getContext().getCoreLibrary().getArrayClass(), store, length);
}

@Specialization
@@ -118,7 +118,7 @@ public Object getIndex(VirtualFrame frame, RubyMatchData matchData, RubyRange.In
final int length = exclusiveEnd - normalizedIndex;

final Object[] store = Arrays.copyOfRange(values, normalizedIndex, normalizedIndex + length);
return new RubyArray(getContext().getCoreLibrary().getArrayClass(), store, length);
return ArrayNodes.createArray(getContext().getCoreLibrary().getArrayClass(), store, length);
}

}
Original file line number Diff line number Diff line change
@@ -16,6 +16,7 @@
import com.oracle.truffle.api.source.SourceSection;
import org.jruby.RubyMath;
import org.jruby.truffle.nodes.RubyNode;
import org.jruby.truffle.nodes.core.array.ArrayNodes;
import org.jruby.truffle.nodes.dispatch.CallDispatchHeadNode;
import org.jruby.truffle.nodes.dispatch.DispatchHeadNodeFactory;
import org.jruby.truffle.nodes.dispatch.MissingBehavior;
@@ -25,7 +26,6 @@
import org.jruby.truffle.runtime.control.RaiseException;
import org.jruby.truffle.runtime.core.RubyArray;
import org.jruby.truffle.runtime.core.RubyBasicObject;
import org.jruby.truffle.runtime.core.RubyBignum;

@CoreClass(name = "Math")
public abstract class MathNodes {
@@ -360,7 +360,7 @@ public RubyArray frexp(double a) {
for (; mantissa >= 1.0; mantissa *= 0.5, exponent +=1) { }
}

return new RubyArray(getContext().getCoreLibrary().getArrayClass(), new Object[]{sign * mantissa, exponent}, 2);
return ArrayNodes.createArray(getContext().getCoreLibrary().getArrayClass(), new Object[]{sign * mantissa, exponent}, 2);
}

@Fallback
@@ -589,7 +589,7 @@ public RubyArray lgamma(double a) {

final RubyMath.NemesLogGamma l = new RubyMath.NemesLogGamma(a);

return new RubyArray(getContext().getCoreLibrary().getArrayClass(), new Object[]{l.value, l.sign}, 2);
return ArrayNodes.createArray(getContext().getCoreLibrary().getArrayClass(), new Object[]{l.value, l.sign}, 2);
}

@Fallback
Original file line number Diff line number Diff line change
@@ -748,7 +748,7 @@ public ClassVariablesNode(RubyContext context, SourceSection sourceSection) {
public RubyArray getClassVariables(RubyModule module) {
CompilerDirectives.transferToInterpreter();

final RubyArray array = new RubyArray(module.getContext().getCoreLibrary().getArrayClass());
final RubyArray array = ArrayNodes.createEmptyArray(module.getContext().getCoreLibrary().getArrayClass());

for (String variable : ModuleOperations.getAllClassVariables(module).keySet()) {
ArrayNodes.slowPush(array, RubySymbol.newSymbol(module.getContext(), variable));
Original file line number Diff line number Diff line change
@@ -15,6 +15,7 @@
import com.oracle.truffle.api.source.SourceSection;
import com.oracle.truffle.api.utilities.BranchProfile;
import org.jruby.truffle.nodes.core.array.ArrayBuilderNode;
import org.jruby.truffle.nodes.core.array.ArrayNodes;
import org.jruby.truffle.runtime.RubyContext;
import org.jruby.truffle.runtime.NotProvided;
import org.jruby.truffle.runtime.control.NextException;
@@ -62,7 +63,7 @@ public RubyArray collect(VirtualFrame frame, RubyRange.IntegerFixnumRange range,
}
}

return new RubyArray(getContext().getCoreLibrary().getArrayClass(), arrayBuilder.finish(store, length), length);
return ArrayNodes.createGeneralArray(getContext().getCoreLibrary().getArrayClass(), arrayBuilder.finish(store, length), length);
}

}
@@ -410,15 +411,15 @@ public RubyArray toA(RubyRange.IntegerFixnumRange range) {
final int length = range.getExclusiveEnd() - begin;

if (length < 0) {
return new RubyArray(getContext().getCoreLibrary().getArrayClass());
return ArrayNodes.createEmptyArray(getContext().getCoreLibrary().getArrayClass());
} else {
final int[] values = new int[length];

for (int n = 0; n < length; n++) {
values[n] = begin + n;
}

return new RubyArray(getContext().getCoreLibrary().getArrayClass(), values, length);
return ArrayNodes.createArray(getContext().getCoreLibrary().getArrayClass(), values, length);
}
}

Original file line number Diff line number Diff line change
@@ -684,7 +684,7 @@ public RubyArray bytes(RubyString string) {
store[n] = ((int) bytes[n]) & 0xFF;
}

return new RubyArray(getContext().getCoreLibrary().getArrayClass(), store, bytes.length);
return ArrayNodes.createArray(getContext().getCoreLibrary().getArrayClass(), store, bytes.length);
}

}
@@ -1742,7 +1742,7 @@ public RubyString scan(VirtualFrame frame, RubyString string, RubyRegexp regexp,
}

final Object[] captures = ((RubyMatchData) matchData).getCaptures();
yield(frame, block, new RubyArray(context.getCoreLibrary().getArrayClass(), captures, captures.length));
yield(frame, block, ArrayNodes.createArray(context.getCoreLibrary().getArrayClass(), captures, captures.length));

lastGoodMatchData = matchData;
end = StringSupport.positionEndForScan(string.getByteList(), matcher, encoding, p, range);
Original file line number Diff line number Diff line change
@@ -70,7 +70,7 @@ public AllSymbolsNode(RubyContext context, SourceSection sourceSection) {
@TruffleBoundary
@Specialization
public RubyArray allSymbols() {
final RubyArray array = new RubyArray(getContext().getCoreLibrary().getArrayClass());
final RubyArray array = ArrayNodes.createEmptyArray(getContext().getCoreLibrary().getArrayClass());

for (RubySymbol s : getContext().getSymbolTable().allSymbols()) {
ArrayNodes.slowPush(array, s);
Original file line number Diff line number Diff line change
@@ -279,7 +279,7 @@ public RubyHash coverageResult() {

for (Map.Entry<Source, Long[]> source : getContext().getCoverageTracker().getCounts().entrySet()) {
final Object[] store = lineCountsStore(source.getValue());
final RubyArray array = new RubyArray(getContext().getCoreLibrary().getArrayClass(), store, store.length);
final RubyArray array = ArrayNodes.createArray(getContext().getCoreLibrary().getArrayClass(), store, store.length);
keyValues.add(new KeyValue(getContext().makeString(source.getKey().getPath()), array));
}

Original file line number Diff line number Diff line change
@@ -61,7 +61,7 @@ private RubyArray executeSingle(VirtualFrame frame, Object store, int length) {
store = arrayBuilderNode.append(store, length, childObject);
length++;
}
return new RubyArray(getContext().getCoreLibrary().getArrayClass(), arrayBuilderNode.finish(store, length), length);
return ArrayNodes.createGeneralArray(getContext().getCoreLibrary().getArrayClass(), arrayBuilderNode.finish(store, length), length);
}

@ExplodeLoop
@@ -83,7 +83,7 @@ private RubyArray executeRubyArray(VirtualFrame frame, Object store, int length)
}
}

return new RubyArray(getContext().getCoreLibrary().getArrayClass(), arrayBuilderNode.finish(store, length), length);
return ArrayNodes.createGeneralArray(getContext().getCoreLibrary().getArrayClass(), arrayBuilderNode.finish(store, length), length);
}

@ExplodeLoop
Loading

0 comments on commit 74d26f9

Please sign in to comment.