Skip to content

Commit

Permalink
Showing 45 changed files with 334 additions and 314 deletions.
12 changes: 7 additions & 5 deletions truffle/src/main/java/org/jruby/truffle/nodes/RubyNode.java
Original file line number Diff line number Diff line change
@@ -159,6 +159,8 @@ public RubyString executeRubyString(VirtualFrame frame) throws UnexpectedResultE
}
}

// If you try to make this RubyBasicObject things break in the DSL

public RubyArray executeRubyArray(VirtualFrame frame) throws UnexpectedResultException {
final Object value = execute(frame);

@@ -271,23 +273,23 @@ protected RubyString createString(ByteList bytes) {
return StringNodes.createString(getContext().getCoreLibrary().getStringClass(), bytes);
}

protected RubyArray createEmptyArray() {
protected RubyBasicObject createEmptyArray() {
return ArrayNodes.createEmptyArray(getContext().getCoreLibrary().getArrayClass());
}

protected RubyArray createArray(int[] store, int size) {
protected RubyBasicObject createArray(int[] store, int size) {
return ArrayNodes.createArray(getContext().getCoreLibrary().getArrayClass(), store, size);
}

protected RubyArray createArray(long[] store, int size) {
protected RubyBasicObject createArray(long[] store, int size) {
return ArrayNodes.createArray(getContext().getCoreLibrary().getArrayClass(), store, size);
}

protected RubyArray createArray(double[] store, int size) {
protected RubyBasicObject createArray(double[] store, int size) {
return ArrayNodes.createArray(getContext().getCoreLibrary().getArrayClass(), store, size);
}

protected RubyArray createArray(Object[] store, int size) {
protected RubyBasicObject createArray(Object[] store, int size) {
return ArrayNodes.createArray(getContext().getCoreLibrary().getArrayClass(), store, size);
}

Original file line number Diff line number Diff line change
@@ -69,12 +69,12 @@ public RubyBasicObject cast(double value) {
}

@Specialization(guards = "isRubyBignum(value)")
public RubyBasicObject cast(RubyBasicObject value) {
public RubyBasicObject castBignum(RubyBasicObject value) {
return nil();
}

@Specialization
public RubyArray cast(RubyArray array) {
@Specialization(guards = "isRubyArray(array)")
public RubyBasicObject castArray(RubyBasicObject array) {
return array;
}

@@ -97,7 +97,7 @@ public Object cast(Object nil) {
}
}

@Specialization(guards = {"!isNil(object)", "!isRubyArray(object)"})
@Specialization(guards = {"!isNil(object)", "!isRubyBignum(object)", "!isRubyArray(object)"})
public Object cast(VirtualFrame frame, RubyBasicObject object) {
final Object result = toArrayNode.call(frame, object, "to_ary", null, new Object[]{});

Original file line number Diff line number Diff line change
@@ -17,7 +17,6 @@
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.core.RubyArray;
import org.jruby.truffle.runtime.core.RubyBasicObject;

@NodeChild(value = "child", type = RubyNode.class)
Original file line number Diff line number Diff line change
@@ -77,8 +77,8 @@ public RubyBasicObject splat(Object nil) {
}
}

@Specialization
public RubyArray splat(VirtualFrame frame, RubyArray array) {
@Specialization(guards = "isRubyArray(array)")
public RubyBasicObject splat(VirtualFrame frame, RubyBasicObject array) {
// TODO(cs): is it necessary to dup here in all cases?
// It is needed at least for [*ary] (parsed as just a SplatNode) and b = *ary.
return dup.executeDup(frame, array);
Original file line number Diff line number Diff line change
@@ -14,12 +14,13 @@
import com.oracle.truffle.api.dsl.Specialization;
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.source.SourceSection;
import org.jruby.truffle.nodes.RubyGuards;
import org.jruby.truffle.nodes.RubyNode;
import org.jruby.truffle.nodes.dispatch.CallDispatchHeadNode;
import org.jruby.truffle.nodes.dispatch.DispatchHeadNodeFactory;
import org.jruby.truffle.runtime.RubyContext;
import org.jruby.truffle.runtime.control.RaiseException;
import org.jruby.truffle.runtime.core.RubyArray;
import org.jruby.truffle.runtime.core.RubyBasicObject;


@NodeChild(value = "child", type = RubyNode.class)
@@ -31,13 +32,13 @@ public ToAryNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
}

@Specialization
public RubyArray coerceRubyArray(RubyArray rubyArray) {
return rubyArray;
@Specialization(guards = "isRubyArray(array)")
public RubyBasicObject coerceRubyArray(RubyBasicObject array) {
return array;
}

@Specialization(guards = "!isRubyArray(object)")
public RubyArray coerceObject(VirtualFrame frame, Object object) {
public RubyBasicObject coerceObject(VirtualFrame frame, Object object) {
if (toAryNode == null) {
CompilerDirectives.transferToInterpreter();
toAryNode = insert(DispatchHeadNodeFactory.createMethodCall(getContext()));
@@ -57,8 +58,8 @@ public RubyArray coerceObject(VirtualFrame frame, Object object) {
throw e;
}
}
if (coerced instanceof RubyArray) {
return (RubyArray) coerced;
if (RubyGuards.isRubyArray(coerced)) {
return (RubyBasicObject) coerced;
} else {
CompilerDirectives.transferToInterpreter();

Original file line number Diff line number Diff line change
@@ -24,7 +24,10 @@
import org.jruby.truffle.runtime.NotProvided;
import org.jruby.truffle.runtime.RubyContext;
import org.jruby.truffle.runtime.control.RaiseException;
import org.jruby.truffle.runtime.core.*;
import org.jruby.truffle.runtime.core.RubyBasicObject;
import org.jruby.truffle.runtime.core.RubyBignum;
import org.jruby.truffle.runtime.core.RubyClass;
import org.jruby.truffle.runtime.core.RubyString;

import java.math.BigInteger;
import java.util.EnumSet;
@@ -528,7 +531,7 @@ public CoerceNode(RubyContext context, SourceSection sourceSection) {
}

@Specialization
public RubyArray coerce(RubyBasicObject a, int b) {
public RubyBasicObject coerce(RubyBasicObject a, int b) {
CompilerDirectives.transferToInterpreter();

// TODO (eregon, 16 Feb. 2015): This is NOT spec, but let's try to see if we can make it work.
@@ -538,7 +541,7 @@ public RubyArray coerce(RubyBasicObject a, int b) {
}

@Specialization
public RubyArray coerce(RubyBasicObject a, long b) {
public RubyBasicObject coerce(RubyBasicObject a, long b) {
CompilerDirectives.transferToInterpreter();

// TODO (eregon, 16 Feb. 2015): This is NOT spec, but let's try to see if we can make it work.
@@ -548,7 +551,7 @@ public RubyArray coerce(RubyBasicObject a, long b) {
}

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

Object[] store = new Object[] { b, a };
@@ -568,12 +571,12 @@ public DivModNode(RubyContext context, SourceSection sourceSection) {
}

@Specialization
public RubyArray divMod(RubyBasicObject a, long b) {
public RubyBasicObject divMod(RubyBasicObject a, long b) {
return divModNode.execute(getBigIntegerValue(a), b);
}

@Specialization(guards = "isRubyBignum(b)")
public RubyArray divMod(RubyBasicObject a, RubyBasicObject b) {
public RubyBasicObject divMod(RubyBasicObject a, RubyBasicObject b) {
return divModNode.execute(getBigIntegerValue(a), getBigIntegerValue(b));
}

Original file line number Diff line number Diff line change
@@ -27,7 +27,7 @@
import org.jruby.truffle.runtime.RubyContext;
import org.jruby.truffle.runtime.ThreadLocalObject;
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.RubyBinding;
import org.jruby.truffle.runtime.core.RubyProc;
import org.jruby.truffle.runtime.core.RubySymbol;
@@ -241,8 +241,8 @@ public LocalVariablesNode(RubyContext context, SourceSection sourceSection) {

@TruffleBoundary
@Specialization
public RubyArray localVariables(RubyBinding binding) {
final RubyArray array = createEmptyArray();
public RubyBasicObject localVariables(RubyBinding binding) {
final RubyBasicObject array = createEmptyArray();

MaterializedFrame frame = binding.getFrame();

Original file line number Diff line number Diff line change
@@ -273,7 +273,7 @@ public ListNode(RubyContext context, SourceSection sourceSection) {
}

@Specialization
public RubyArray list() {
public RubyBasicObject list() {
CompilerDirectives.transferToInterpreter();

final RubyEncoding[] encodings = RubyEncoding.cloneEncodingList();
Original file line number Diff line number Diff line change
@@ -21,7 +21,6 @@
import org.jruby.truffle.runtime.NotProvided;
import org.jruby.truffle.runtime.RubyContext;
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.RubyString;

@@ -258,17 +257,17 @@ public DivModNode(RubyContext context, SourceSection sourceSection) {
}

@Specialization
public RubyArray divMod(double a, long b) {
public RubyBasicObject divMod(double a, long b) {
return divModNode.execute(a, b);
}

@Specialization
public RubyArray divMod(double a, double b) {
public RubyBasicObject divMod(double a, double b) {
return divModNode.execute(a, b);
}

@Specialization(guards = "isRubyBignum(b)")
public RubyArray divMod(double a, RubyBasicObject b) {
public RubyBasicObject divMod(double a, RubyBasicObject b) {
return divModNode.execute(a, BignumNodes.getBigIntegerValue(b));
}

Original file line number Diff line number Diff line change
@@ -16,7 +16,6 @@
import org.jruby.truffle.nodes.RubyNode;
import org.jruby.truffle.runtime.RubyContext;
import org.jruby.truffle.runtime.control.RaiseException;
import org.jruby.truffle.runtime.core.RubyArray;
import org.jruby.truffle.runtime.core.RubyBasicObject;

import java.math.BigInteger;
@@ -39,35 +38,35 @@ public GeneralDivModNode(RubyContext context, SourceSection sourceSection) {
fixnumOrBignumRemainder = new FixnumOrBignumNode(context, sourceSection);
}

public RubyArray execute(long a, long b) {
public RubyBasicObject execute(long a, long b) {
return divMod(a, b);
}

public RubyArray execute(long a, BigInteger b) {
public RubyBasicObject execute(long a, BigInteger b) {
return divMod(BigInteger.valueOf(a), b);
}

public RubyArray execute(long a, double b) {
public RubyBasicObject execute(long a, double b) {
return divMod(a, b);
}

public RubyArray execute(BigInteger a, long b) {
public RubyBasicObject execute(BigInteger a, long b) {
return divMod(a, BigInteger.valueOf(b));
}

public RubyArray execute(BigInteger a, BigInteger b) {
public RubyBasicObject execute(BigInteger a, BigInteger b) {
return divMod(a, b);
}

public RubyArray execute(double a, long b) {
public RubyBasicObject execute(double a, long b) {
return divMod(a, b);
}

public RubyArray execute(double a, BigInteger b) {
public RubyBasicObject execute(double a, BigInteger b) {
return divMod(a, b.doubleValue());
}

public RubyArray execute(double a, double b) {
public RubyBasicObject execute(double a, double b) {
return divMod(a, b);
}

@@ -77,7 +76,7 @@ public RubyArray execute(double a, double b) {
*/

@TruffleBoundary
private RubyArray divMod(long a, long b) {
private RubyBasicObject divMod(long a, long b) {
if (b == 0) {
bZeroProfile.enter();
throw new ArithmeticException("divide by zero");
@@ -120,7 +119,7 @@ private RubyArray divMod(long a, long b) {
}

@TruffleBoundary
private RubyArray divMod(double a, double b) {
private RubyBasicObject divMod(double a, double b) {
if (b == 0) {
bZeroProfile.enter();
throw new ArithmeticException("divide by zero");
@@ -145,7 +144,7 @@ private RubyArray divMod(double a, double b) {
}

@TruffleBoundary
private RubyArray divMod(BigInteger a, BigInteger b) {
private RubyBasicObject divMod(BigInteger a, BigInteger b) {
if (b.signum() == 0) {
bZeroProfile.enter();
throw new ArithmeticException("divide by zero");
Original file line number Diff line number Diff line change
@@ -19,7 +19,6 @@
import org.jruby.truffle.runtime.RubyContext;
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.RubyProc;

@@ -135,7 +134,7 @@ public TimesNode(RubyContext context, SourceSection sourceSection) {
}

@Specialization
public RubyArray times(VirtualFrame frame, int n, NotProvided block) {
public RubyBasicObject times(VirtualFrame frame, int n, NotProvided block) {
final int[] array = new int[n];

for (int i = 0; i < n; i++) {
Original file line number Diff line number Diff line change
@@ -302,18 +302,18 @@ public CallerLocationsNode(RubyContext context, SourceSection sourceSection) {
}

@Specialization
public RubyArray callerLocations(NotProvided omit, NotProvided length) {
public RubyBasicObject callerLocations(NotProvided omit, NotProvided length) {
return callerLocations(1, -1);
}

@Specialization
public RubyArray callerLocations(int omit, NotProvided length) {
public RubyBasicObject callerLocations(int omit, NotProvided length) {
return callerLocations(omit, -1);
}

@TruffleBoundary
@Specialization
public RubyArray callerLocations(int omit, int length) {
public RubyBasicObject callerLocations(int omit, int length) {
final RubyClass threadBacktraceLocationClass = getContext().getCoreLibrary().getThreadBacktraceLocationClass();

final Backtrace backtrace = RubyCallStack.getBacktrace(this, 1 + omit, true);
@@ -901,14 +901,14 @@ public InstanceVariablesNode(RubyContext context, SourceSection sourceSection) {
}

@Specialization
public RubyArray instanceVariables(RubyBasicObject self) {
public RubyBasicObject instanceVariables(RubyBasicObject self) {
CompilerDirectives.transferToInterpreter();

final Object[] instanceVariableNames = RubyBasicObject.getFieldNames(self);

Arrays.sort(instanceVariableNames);

final RubyArray array = createEmptyArray();
final RubyBasicObject array = createEmptyArray();

for (Object name : instanceVariableNames) {
if (name instanceof String) {
@@ -1005,10 +1005,10 @@ public LocalVariablesNode(RubyContext context, SourceSection sourceSection) {
}

@Specialization
public RubyArray localVariables() {
public RubyBasicObject localVariables() {
CompilerDirectives.transferToInterpreter();

final RubyArray array = createEmptyArray();
final RubyBasicObject array = createEmptyArray();

for (Object name : Truffle.getRuntime().getCallerFrame().getFrame(FrameInstance.FrameAccess.READ_ONLY, false).getFrameDescriptor().getIdentifiers()) {
if (name instanceof String) {
21 changes: 10 additions & 11 deletions truffle/src/main/java/org/jruby/truffle/nodes/core/MathNodes.java
Original file line number Diff line number Diff line change
@@ -23,7 +23,6 @@
import org.jruby.truffle.runtime.NotProvided;
import org.jruby.truffle.runtime.RubyContext;
import org.jruby.truffle.runtime.control.RaiseException;
import org.jruby.truffle.runtime.core.RubyArray;
import org.jruby.truffle.runtime.core.RubyBasicObject;

@CoreClass(name = "Math")
@@ -323,22 +322,22 @@ public FrExpNode(RubyContext context, SourceSection sourceSection) {
}

@Specialization
public RubyArray frexp(int a) {
public RubyBasicObject frexp(int a) {
return frexp((double) a);
}

@Specialization
public RubyArray frexp(long a) {
public RubyBasicObject frexp(long a) {
return frexp((double) a);
}

@Specialization(guards = "isRubyBignum(a)")
public RubyArray frexp(RubyBasicObject a) {
public RubyBasicObject frexp(RubyBasicObject a) {
return frexp(BignumNodes.getBigIntegerValue(a).doubleValue());
}

@Specialization
public RubyArray frexp(double a) {
public RubyBasicObject frexp(double a) {
// Copied from RubyMath - see copyright notices there

double mantissa = a;
@@ -363,7 +362,7 @@ public RubyArray frexp(double a) {
}

@Fallback
public RubyArray frexp(VirtualFrame frame, Object a) {
public RubyBasicObject frexp(VirtualFrame frame, Object a) {
if (isANode.executeIsA(frame, a, getContext().getCoreLibrary().getNumericClass())) {
try {
return frexp(floatNode.callFloat(frame, a, "to_f", null));
@@ -563,22 +562,22 @@ public LGammaNode(RubyContext context, SourceSection sourceSection) {
}

@Specialization
public RubyArray lgamma(int a) {
public RubyBasicObject lgamma(int a) {
return lgamma((double) a);
}

@Specialization
public RubyArray lgamma(long a) {
public RubyBasicObject lgamma(long a) {
return lgamma((double) a);
}

@Specialization(guards = "isRubyBignum(a)")
public RubyArray lgamma(RubyBasicObject a) {
public RubyBasicObject lgamma(RubyBasicObject a) {
return lgamma(BignumNodes.getBigIntegerValue(a).doubleValue());
}

@Specialization
public RubyArray lgamma(double a) {
public RubyBasicObject lgamma(double a) {
// Copied from RubyMath - see copyright notices there

if (a < 0 && Double.isInfinite(a)) {
@@ -592,7 +591,7 @@ public RubyArray lgamma(double a) {
}

@Fallback
public RubyArray lgamma(VirtualFrame frame, Object a) {
public RubyBasicObject lgamma(VirtualFrame frame, Object a) {
if (isANode.executeIsA(frame, a, getContext().getCoreLibrary().getNumericClass())) {
try {
return lgamma(floatNode.callFloat(frame, a, "to_f", null));
Original file line number Diff line number Diff line change
@@ -192,7 +192,7 @@ public ParametersNode(RubyContext context, SourceSection sourceSection) {

@TruffleBoundary
@Specialization
public RubyArray parameters(RubyBasicObject method) {
public RubyBasicObject parameters(RubyBasicObject method) {
final ArgsNode argsNode = getMethod(method).getSharedMethodInfo().getParseTree().findFirstChild(ArgsNode.class);

final ArgumentDescriptor[] argsDesc = Helpers.argsNodeToArgumentDescriptors(argsNode);
Original file line number Diff line number Diff line change
@@ -739,10 +739,10 @@ public ClassVariablesNode(RubyContext context, SourceSection sourceSection) {
}

@Specialization
public RubyArray getClassVariables(RubyModule module) {
public RubyBasicObject getClassVariables(RubyModule module) {
CompilerDirectives.transferToInterpreter();

final RubyArray array = ArrayNodes.createEmptyArray(module.getContext().getCoreLibrary().getArrayClass());
final RubyBasicObject 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
@@ -18,7 +18,6 @@
import org.jruby.truffle.runtime.ModuleOperations;
import org.jruby.truffle.runtime.NotProvided;
import org.jruby.truffle.runtime.RubyContext;
import org.jruby.truffle.runtime.core.RubyArray;
import org.jruby.truffle.runtime.core.RubyBasicObject;
import org.jruby.truffle.runtime.core.RubyClass;
import org.jruby.truffle.runtime.core.RubyProc;
Original file line number Diff line number Diff line change
@@ -162,7 +162,7 @@ public ParametersNode(RubyContext context, SourceSection sourceSection) {

@TruffleBoundary
@Specialization
public RubyArray parameters(RubyProc proc) {
public RubyBasicObject parameters(RubyProc proc) {
final ArgsNode argsNode = proc.getSharedMethodInfo().getParseTree().findFirstChild(ArgsNode.class);

final ArgumentDescriptor[] argsDesc = Helpers.argsNodeToArgumentDescriptors(argsNode);
Original file line number Diff line number Diff line change
@@ -20,15 +20,13 @@
import org.jruby.truffle.runtime.RubyContext;
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.RubyProc;
import org.jruby.truffle.runtime.core.RubyRange;

@CoreClass(name = "Range")
public abstract class RangeNodes {



@CoreMethod(names = {"collect", "map"}, needsBlock = true, lowerFixnumSelf = true)
public abstract static class CollectNode extends YieldingCoreMethodNode {

@@ -40,7 +38,7 @@ public CollectNode(RubyContext context, SourceSection sourceSection) {
}

@Specialization
public RubyArray collect(VirtualFrame frame, RubyRange.IntegerFixnumRange range, RubyProc block) {
public RubyBasicObject collect(VirtualFrame frame, RubyRange.IntegerFixnumRange range, RubyProc block) {
final int begin = range.getBegin();
final int exclusiveEnd = range.getExclusiveEnd();
final int length = exclusiveEnd - begin;
@@ -406,7 +404,7 @@ public ToANode(RubyContext context, SourceSection sourceSection) {
}

@Specialization
public RubyArray toA(RubyRange.IntegerFixnumRange range) {
public RubyBasicObject toA(RubyRange.IntegerFixnumRange range) {
final int begin = range.getBegin();
final int length = range.getExclusiveEnd() - begin;

Original file line number Diff line number Diff line change
@@ -787,7 +787,7 @@ public BytesNode(RubyContext context, SourceSection sourceSection) {
}

@Specialization
public RubyArray bytes(RubyString string) {
public RubyBasicObject bytes(RubyString string) {
final byte[] bytes = getByteList(string).bytes();

final int[] store = new int[bytes.length];
Original file line number Diff line number Diff line change
@@ -69,8 +69,8 @@ public AllSymbolsNode(RubyContext context, SourceSection sourceSection) {

@TruffleBoundary
@Specialization
public RubyArray allSymbols() {
final RubyArray array = createEmptyArray();
public RubyBasicObject allSymbols() {
final RubyBasicObject array = createEmptyArray();

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

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

Original file line number Diff line number Diff line change
@@ -198,7 +198,7 @@ public ParametersNode(RubyContext context, SourceSection sourceSection) {

@TruffleBoundary
@Specialization
public RubyArray parameters(RubyBasicObject method) {
public RubyBasicObject parameters(RubyBasicObject method) {
final ArgsNode argsNode = getMethod(method).getSharedMethodInfo().getParseTree().findFirstChild(ArgsNode.class);

final ArgumentDescriptor[] argsDesc = Helpers.argsNodeToArgumentDescriptors(argsNode);
Original file line number Diff line number Diff line change
@@ -17,6 +17,7 @@
import org.jruby.truffle.runtime.array.ArrayMirror;
import org.jruby.truffle.runtime.array.ArrayUtils;
import org.jruby.truffle.runtime.core.RubyArray;
import org.jruby.truffle.runtime.core.RubyBasicObject;

import java.util.Arrays;

@@ -39,57 +40,57 @@ public AppendManyNode(RubyContext context, SourceSection sourceSection) {
// TODO CS 12-May-15 differentiate between null and empty but possibly having enough space

@Specialization(guards = "isEmptyArray(array)")
public RubyArray appendManyEmpty(RubyArray array, int otherSize, int[] other) {
public RubyBasicObject appendManyEmpty(RubyArray array, int otherSize, int[] other) {
ArrayNodes.setStore(array, Arrays.copyOf(other, otherSize), otherSize);
return array;
}

@Specialization(guards = "isEmptyArray(array)")
public RubyArray appendManyEmpty(RubyArray array, int otherSize, long[] other) {
public RubyBasicObject appendManyEmpty(RubyArray array, int otherSize, long[] other) {
ArrayNodes.setStore(array, Arrays.copyOf(other, otherSize), otherSize);
return array;
}

@Specialization(guards = "isEmptyArray(array)")
public RubyArray appendManyEmpty(RubyArray array, int otherSize, double[] other) {
public RubyBasicObject appendManyEmpty(RubyArray array, int otherSize, double[] other) {
ArrayNodes.setStore(array, Arrays.copyOf(other, otherSize), otherSize);
return array;
}

@Specialization(guards = "isEmptyArray(array)")
public RubyArray appendManyEmpty(RubyArray array, int otherSize, Object[] other) {
public RubyBasicObject appendManyEmpty(RubyArray array, int otherSize, Object[] other) {
ArrayNodes.setStore(array, Arrays.copyOf(other, otherSize), otherSize);
return array;
}

// Append of the correct type

@Specialization(guards = "isIntArray(array)")
public RubyArray appendManySameType(RubyArray array, int otherSize, int[] other,
public RubyBasicObject appendManySameType(RubyArray array, int otherSize, int[] other,
@Cached("createBinaryProfile()") ConditionProfile extendProfile) {
appendManySameTypeGeneric(array, ArrayMirror.reflect((int[]) ArrayNodes.getStore(array)),
otherSize, ArrayMirror.reflect(other), extendProfile);
return array;
}

@Specialization(guards = "isLongArray(array)")
public RubyArray appendManySameType(RubyArray array, int otherSize, long[] other,
public RubyBasicObject appendManySameType(RubyArray array, int otherSize, long[] other,
@Cached("createBinaryProfile()") ConditionProfile extendProfile) {
appendManySameTypeGeneric(array, ArrayMirror.reflect((long[]) ArrayNodes.getStore(array)),
otherSize, ArrayMirror.reflect(other), extendProfile);
return array;
}

@Specialization(guards = "isDoubleArray(array)")
public RubyArray appendManySameType(RubyArray array, int otherSize, double[] other,
public RubyBasicObject appendManySameType(RubyArray array, int otherSize, double[] other,
@Cached("createBinaryProfile()") ConditionProfile extendProfile) {
appendManySameTypeGeneric(array, ArrayMirror.reflect((double[]) ArrayNodes.getStore(array)),
otherSize, ArrayMirror.reflect(other), extendProfile);
return array;
}

@Specialization(guards = "isObjectArray(array)")
public RubyArray appendManySameType(RubyArray array, int otherSize, Object[] other,
public RubyBasicObject appendManySameType(RubyArray array, int otherSize, Object[] other,
@Cached("createBinaryProfile()") ConditionProfile extendProfile) {
appendManySameTypeGeneric(array, ArrayMirror.reflect((Object[]) ArrayNodes.getStore(array)),
otherSize, ArrayMirror.reflect(other), extendProfile);
@@ -117,21 +118,21 @@ public void appendManySameTypeGeneric(RubyArray array, ArrayMirror storeMirror,
// Append something else into an Object[]

@Specialization(guards = "isObjectArray(array)")
public RubyArray appendManyBoxIntoObject(RubyArray array, int otherSize, int[] other,
public RubyBasicObject appendManyBoxIntoObject(RubyArray array, int otherSize, int[] other,
@Cached("createBinaryProfile()") ConditionProfile extendProfile) {
appendManyBoxIntoObjectGeneric(array, otherSize, ArrayMirror.reflect(other), extendProfile);
return array;
}

@Specialization(guards = "isObjectArray(array)")
public RubyArray appendManyBoxIntoObject(RubyArray array, int otherSize, long[] other,
public RubyBasicObject appendManyBoxIntoObject(RubyArray array, int otherSize, long[] other,
@Cached("createBinaryProfile()") ConditionProfile extendProfile) {
appendManyBoxIntoObjectGeneric(array, otherSize, ArrayMirror.reflect(other), extendProfile);
return array;
}

@Specialization(guards = "isObjectArray(array)")
public RubyArray appendManyBoxIntoObject(RubyArray array, int otherSize, double[] other,
public RubyBasicObject appendManyBoxIntoObject(RubyArray array, int otherSize, double[] other,
@Cached("createBinaryProfile()") ConditionProfile extendProfile) {
appendManyBoxIntoObjectGeneric(array, otherSize, ArrayMirror.reflect(other), extendProfile);
return array;
@@ -158,7 +159,7 @@ public void appendManyBoxIntoObjectGeneric(RubyArray array, int otherSize, Array
// Append forcing a generalization from int[] to long[]

@Specialization(guards = "isIntArray(array)")
public RubyArray appendManyLongIntoInteger(RubyArray array, int otherSize, long[] other) {
public RubyBasicObject appendManyLongIntoInteger(RubyArray array, int otherSize, long[] other) {
final int oldSize = ArrayNodes.getSize(array);
final int newSize = oldSize + otherSize;

@@ -174,49 +175,49 @@ public RubyArray appendManyLongIntoInteger(RubyArray array, int otherSize, long[
// Append forcing a generalization to Object[]

@Specialization(guards = "isIntArray(array)")
public RubyArray appendManyGeneralizeIntegerDouble(RubyArray array, int otherSize, double[] other) {
public RubyBasicObject appendManyGeneralizeIntegerDouble(RubyArray array, int otherSize, double[] other) {
appendManyGeneralizeGeneric(array, ArrayMirror.reflect((int[]) ArrayNodes.getStore(array)),
otherSize, ArrayMirror.reflect(other));
return array;
}

@Specialization(guards = "isIntArray(array)")
public RubyArray appendManyGeneralizeIntegerDouble(RubyArray array, int otherSize, Object[] other) {
public RubyBasicObject appendManyGeneralizeIntegerDouble(RubyArray array, int otherSize, Object[] other) {
appendManyGeneralizeGeneric(array, ArrayMirror.reflect((int[]) ArrayNodes.getStore(array)),
otherSize, ArrayMirror.reflect(other));
return array;
}

@Specialization(guards = "isLongArray(array)")
public RubyArray appendManyGeneralizeLongDouble(RubyArray array, int otherSize, double[] other) {
public RubyBasicObject appendManyGeneralizeLongDouble(RubyArray array, int otherSize, double[] other) {
appendManyGeneralizeGeneric(array, ArrayMirror.reflect((long[]) ArrayNodes.getStore(array)),
otherSize, ArrayMirror.reflect(other));
return array;
}

@Specialization(guards = "isLongArray(array)")
public RubyArray appendManyGeneralizeLongDouble(RubyArray array, int otherSize, Object[] other) {
public RubyBasicObject appendManyGeneralizeLongDouble(RubyArray array, int otherSize, Object[] other) {
appendManyGeneralizeGeneric(array, ArrayMirror.reflect((long[]) ArrayNodes.getStore(array)),
otherSize, ArrayMirror.reflect(other));
return array;
}

@Specialization(guards = "isDoubleArray(array)")
public RubyArray appendManyGeneralizeDoubleInteger(RubyArray array, int otherSize, int[] other) {
public RubyBasicObject appendManyGeneralizeDoubleInteger(RubyArray array, int otherSize, int[] other) {
appendManyGeneralizeGeneric(array, ArrayMirror.reflect((double[]) ArrayNodes.getStore(array)),
otherSize, ArrayMirror.reflect(other));
return array;
}

@Specialization(guards = "isDoubleArray(array)")
public RubyArray appendManyGeneralizeDoubleLong(RubyArray array, int otherSize, long[] other) {
public RubyBasicObject appendManyGeneralizeDoubleLong(RubyArray array, int otherSize, long[] other) {
appendManyGeneralizeGeneric(array, ArrayMirror.reflect((double[]) ArrayNodes.getStore(array)),
otherSize, ArrayMirror.reflect(other));
return array;
}

@Specialization(guards = "isDoubleArray(array)")
public RubyArray appendManyGeneralizeDoubleObject(RubyArray array, int otherSize, Object[] other) {
public RubyBasicObject appendManyGeneralizeDoubleObject(RubyArray array, int otherSize, Object[] other) {
appendManyGeneralizeGeneric(array, ArrayMirror.reflect((double[]) ArrayNodes.getStore(array)),
otherSize, ArrayMirror.reflect(other));
return array;
Original file line number Diff line number Diff line change
@@ -17,6 +17,7 @@
import org.jruby.truffle.runtime.array.ArrayMirror;
import org.jruby.truffle.runtime.array.ArrayUtils;
import org.jruby.truffle.runtime.core.RubyArray;
import org.jruby.truffle.runtime.core.RubyBasicObject;

@NodeChildren({
@NodeChild("array"),
@@ -36,54 +37,54 @@ public AppendOneNode(RubyContext context, SourceSection sourceSection) {
// TODO CS 12-May-15 differentiate between null and empty but possibly having enough space

@Specialization(guards = "isEmptyArray(array)")
public RubyArray appendOneEmpty(RubyArray array, int value) {
public RubyBasicObject appendOneEmpty(RubyArray array, int value) {
ArrayNodes.setStore(array, new int[]{value}, 1);
return array;
}

@Specialization(guards = "isEmptyArray(array)")
public RubyArray appendOneEmpty(RubyArray array, long value) {
public RubyBasicObject appendOneEmpty(RubyArray array, long value) {
ArrayNodes.setStore(array, new long[]{value}, 1);
return array;
}

@Specialization(guards = "isEmptyArray(array)")
public RubyArray appendOneEmpty(RubyArray array, double value) {
public RubyBasicObject appendOneEmpty(RubyArray array, double value) {
ArrayNodes.setStore(array, new double[]{value}, 1);
return array;
}

@Specialization(guards = "isEmptyArray(array)")
public RubyArray appendOneEmpty(RubyArray array, Object value) {
public RubyBasicObject appendOneEmpty(RubyArray array, Object value) {
ArrayNodes.setStore(array, new Object[]{value}, 1);
return array;
}

// Append of the correct type

@Specialization(guards = "isIntArray(array)")
public RubyArray appendOneSameType(RubyArray array, int value,
public RubyBasicObject appendOneSameType(RubyArray array, int value,
@Cached("createBinaryProfile()") ConditionProfile extendProfile) {
appendOneSameTypeGeneric(array, ArrayMirror.reflect((int[]) ArrayNodes.getStore(array)), value, extendProfile);
return array;
}

@Specialization(guards = "isLongArray(array)")
public RubyArray appendOneSameType(RubyArray array, long value,
public RubyBasicObject appendOneSameType(RubyArray array, long value,
@Cached("createBinaryProfile()") ConditionProfile extendProfile) {
appendOneSameTypeGeneric(array, ArrayMirror.reflect((long[]) ArrayNodes.getStore(array)), value, extendProfile);
return array;
}

@Specialization(guards = "isDoubleArray(array)")
public RubyArray appendOneSameType(RubyArray array, double value,
public RubyBasicObject appendOneSameType(RubyArray array, double value,
@Cached("createBinaryProfile()") ConditionProfile extendProfile) {
appendOneSameTypeGeneric(array, ArrayMirror.reflect((double[]) ArrayNodes.getStore(array)), value, extendProfile);
return array;
}

@Specialization(guards = "isObjectArray(array)")
public RubyArray appendOneSameType(RubyArray array, Object value,
public RubyBasicObject appendOneSameType(RubyArray array, Object value,
@Cached("createBinaryProfile()") ConditionProfile extendProfile) {
appendOneSameTypeGeneric(array, ArrayMirror.reflect((Object[]) ArrayNodes.getStore(array)), value, extendProfile);
return array;
@@ -108,7 +109,7 @@ public void appendOneSameTypeGeneric(RubyArray array, ArrayMirror storeMirror, O
// Append forcing a generalization from int[] to long[]

@Specialization(guards = "isIntArray(array)")
public RubyArray appendOneLongIntoInteger(RubyArray array, long value) {
public RubyBasicObject appendOneLongIntoInteger(RubyArray array, long value) {
final int oldSize = ArrayNodes.getSize(array);
final int newSize = oldSize + 1;

@@ -123,19 +124,19 @@ public RubyArray appendOneLongIntoInteger(RubyArray array, long value) {
// Append forcing a generalization to Object[]

@Specialization(guards = {"isIntArray(array)", "!isInteger(value)", "!isLong(value)"})
public RubyArray appendOneGeneralizeInteger(RubyArray array, Object value) {
public RubyBasicObject appendOneGeneralizeInteger(RubyArray array, Object value) {
appendOneGeneralizeGeneric(array, ArrayMirror.reflect((int[]) ArrayNodes.getStore(array)), value);
return array;
}

@Specialization(guards = {"isLongArray(array)", "!isInteger(value)", "!isLong(value)"})
public RubyArray appendOneGeneralizeLong(RubyArray array, Object value) {
public RubyBasicObject appendOneGeneralizeLong(RubyArray array, Object value) {
appendOneGeneralizeGeneric(array, ArrayMirror.reflect((long[]) ArrayNodes.getStore(array)), value);
return array;
}

@Specialization(guards = {"isDoubleArray(array)", "!isDouble(value)"})
public RubyArray appendOneGeneralizeDouble(RubyArray array, Object value) {
public RubyBasicObject appendOneGeneralizeDouble(RubyArray array, Object value) {
appendOneGeneralizeGeneric(array, ArrayMirror.reflect((double[]) ArrayNodes.getStore(array)), value);
return array;
}
Original file line number Diff line number Diff line change
@@ -16,6 +16,7 @@
import org.jruby.truffle.nodes.RubyNode;
import org.jruby.truffle.runtime.RubyContext;
import org.jruby.truffle.runtime.core.RubyArray;
import org.jruby.truffle.runtime.core.RubyBasicObject;

/**
* Concatenate arrays.
@@ -36,7 +37,7 @@ public ArrayConcatNode(RubyContext context, SourceSection sourceSection, RubyNod
}

@Override
public RubyArray execute(VirtualFrame frame) {
public RubyBasicObject execute(VirtualFrame frame) {
Object store = arrayBuilderNode.start();
int length = 0;
if (children.length == 1) {
Original file line number Diff line number Diff line change
@@ -19,6 +19,7 @@
import org.jruby.truffle.runtime.RubyContext;
import org.jruby.truffle.runtime.array.ArrayUtils;
import org.jruby.truffle.runtime.core.RubyArray;
import org.jruby.truffle.runtime.core.RubyBasicObject;

@NodeChildren({@NodeChild(value = "array", type = RubyNode.class)})
@ImportStatic(ArrayGuards.class)
@@ -32,14 +33,14 @@ public ArrayDropTailNode(RubyContext context, SourceSection sourceSection, int i
}

@Specialization(guards = "isNullArray(array)")
public RubyArray getHeadNull(RubyArray array) {
public RubyBasicObject getHeadNull(RubyArray array) {
CompilerDirectives.transferToInterpreter();

return createEmptyArray();
}

@Specialization(guards = "isIntArray(array)")
public RubyArray getHeadIntegerFixnum(RubyArray array) {
public RubyBasicObject getHeadIntegerFixnum(RubyArray array) {
CompilerDirectives.transferToInterpreter();

if (index >= ArrayNodes.getSize(array)) {
@@ -50,7 +51,7 @@ public RubyArray getHeadIntegerFixnum(RubyArray array) {
}

@Specialization(guards = "isLongArray(array)")
public RubyArray geHeadLongFixnum(RubyArray array) {
public RubyBasicObject geHeadLongFixnum(RubyArray array) {
CompilerDirectives.transferToInterpreter();

if (index >= ArrayNodes.getSize(array)) {
@@ -62,7 +63,7 @@ public RubyArray geHeadLongFixnum(RubyArray array) {
}

@Specialization(guards = "isDoubleArray(array)")
public RubyArray getHeadFloat(RubyArray array) {
public RubyBasicObject getHeadFloat(RubyArray array) {
CompilerDirectives.transferToInterpreter();

if (index >= ArrayNodes.getSize(array)) {
@@ -74,7 +75,7 @@ public RubyArray getHeadFloat(RubyArray array) {
}

@Specialization(guards = "isObjectArray(array)")
public RubyArray getHeadObject(RubyArray array) {
public RubyBasicObject getHeadObject(RubyArray array) {
CompilerDirectives.transferToInterpreter();

if (index >= ArrayNodes.getSize(array)) {
Original file line number Diff line number Diff line change
@@ -17,7 +17,7 @@
import com.oracle.truffle.api.source.SourceSection;
import org.jruby.truffle.nodes.RubyNode;
import org.jruby.truffle.runtime.RubyContext;
import org.jruby.truffle.runtime.core.RubyArray;
import org.jruby.truffle.runtime.core.RubyBasicObject;

import java.util.Arrays;

@@ -32,30 +32,30 @@ public ArrayDupNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
}

public abstract RubyArray executeDup(VirtualFrame frame, RubyArray array);
public abstract RubyBasicObject executeDup(VirtualFrame frame, RubyBasicObject array);

@Specialization(guards = "isNullArray(from)")
public RubyArray dupNull(RubyArray from) {
@Specialization(guards = {"isRubyArray(from)", "isNullArray(from)"})
public RubyBasicObject dupNull(RubyBasicObject from) {
return createEmptyArray();
}

@Specialization(guards = "isIntArray(from)")
public RubyArray dupIntegerFixnum(RubyArray from) {
@Specialization(guards = {"isRubyArray(from)", "isIntArray(from)"})
public RubyBasicObject dupIntegerFixnum(RubyBasicObject from) {
return createArray(Arrays.copyOf((int[]) ArrayNodes.getStore(from), ArrayNodes.getSize(from)), ArrayNodes.getSize(from));
}

@Specialization(guards = "isLongArray(from)")
public RubyArray dupLongFixnum(RubyArray from) {
@Specialization(guards = {"isRubyArray(from)", "isLongArray(from)"})
public RubyBasicObject dupLongFixnum(RubyBasicObject from) {
return createArray(Arrays.copyOf((long[]) ArrayNodes.getStore(from), ArrayNodes.getSize(from)), ArrayNodes.getSize(from));
}

@Specialization(guards = "isDoubleArray(from)")
public RubyArray dupFloat(RubyArray from) {
@Specialization(guards = {"isRubyArray(from)", "isDoubleArray(from)"})
public RubyBasicObject dupFloat(RubyBasicObject from) {
return createArray(Arrays.copyOf((double[]) ArrayNodes.getStore(from), ArrayNodes.getSize(from)), ArrayNodes.getSize(from));
}

@Specialization(guards = "isObjectArray(from)")
public RubyArray dupObject(RubyArray from) {
@Specialization(guards = {"isRubyArray(from)", "isObjectArray(from)"})
public RubyBasicObject dupObject(RubyBasicObject from) {
return createArray(Arrays.copyOf((Object[]) ArrayNodes.getStore(from), ArrayNodes.getSize(from)), ArrayNodes.getSize(from));
}

Original file line number Diff line number Diff line change
@@ -19,6 +19,7 @@
import org.jruby.truffle.runtime.RubyContext;
import org.jruby.truffle.runtime.array.ArrayUtils;
import org.jruby.truffle.runtime.core.RubyArray;
import org.jruby.truffle.runtime.core.RubyBasicObject;

@NodeChildren({@NodeChild(value = "array", type = RubyNode.class)})
@ImportStatic(ArrayGuards.class)
@@ -32,14 +33,14 @@ public ArrayGetTailNode(RubyContext context, SourceSection sourceSection, int in
}

@Specialization(guards = "isNullArray(array)")
public RubyArray getTailNull(RubyArray array) {
public RubyBasicObject getTailNull(RubyArray array) {
CompilerDirectives.transferToInterpreter();

return createEmptyArray();
}

@Specialization(guards = "isIntArray(array)")
public RubyArray getTailIntegerFixnum(RubyArray array) {
public RubyBasicObject getTailIntegerFixnum(RubyArray array) {
CompilerDirectives.transferToInterpreter();

if (index >= ArrayNodes.getSize(array)) {
@@ -50,7 +51,7 @@ public RubyArray getTailIntegerFixnum(RubyArray array) {
}

@Specialization(guards = "isLongArray(array)")
public RubyArray getTailLongFixnum(RubyArray array) {
public RubyBasicObject getTailLongFixnum(RubyArray array) {
CompilerDirectives.transferToInterpreter();

if (index >= ArrayNodes.getSize(array)) {
@@ -61,7 +62,7 @@ public RubyArray getTailLongFixnum(RubyArray array) {
}

@Specialization(guards = "isDoubleArray(array)")
public RubyArray getTailFloat(RubyArray array) {
public RubyBasicObject getTailFloat(RubyArray array) {
CompilerDirectives.transferToInterpreter();

if (index >= ArrayNodes.getSize(array)) {
@@ -72,7 +73,7 @@ public RubyArray getTailFloat(RubyArray array) {
}

@Specialization(guards = "isObjectArray(array)")
public RubyArray getTailObject(RubyArray array) {
public RubyBasicObject getTailObject(RubyArray array) {
CompilerDirectives.transferToInterpreter();

if (index >= ArrayNodes.getSize(array)) {
Original file line number Diff line number Diff line change
@@ -9,35 +9,42 @@
*/
package org.jruby.truffle.nodes.core.array;

import org.jruby.truffle.runtime.core.RubyArray;
import org.jruby.truffle.nodes.RubyGuards;
import org.jruby.truffle.runtime.core.RubyBasicObject;

public class ArrayGuards {

// Storage strategies

public static boolean isNullArray(RubyArray array) {
public static boolean isNullArray(RubyBasicObject array) {
assert RubyGuards.isRubyArray(array);
return ArrayNodes.getStore(array) == null;
}

public static boolean isIntArray(RubyArray array) {
public static boolean isIntArray(RubyBasicObject array) {
assert RubyGuards.isRubyArray(array);
return ArrayNodes.getStore(array) instanceof int[];
}

public static boolean isLongArray(RubyArray array) {
public static boolean isLongArray(RubyBasicObject array) {
assert RubyGuards.isRubyArray(array);
return ArrayNodes.getStore(array) instanceof long[];
}

public static boolean isDoubleArray(RubyArray array) {
public static boolean isDoubleArray(RubyBasicObject array) {
assert RubyGuards.isRubyArray(array);
return ArrayNodes.getStore(array) instanceof double[];
}

public static boolean isObjectArray(RubyArray array) {
public static boolean isObjectArray(RubyBasicObject array) {
assert RubyGuards.isRubyArray(array);
return ArrayNodes.getStore(array) instanceof Object[];
}

// Higher level properties

public static boolean isEmptyArray(RubyArray array) {
public static boolean isEmptyArray(RubyBasicObject array) {
assert RubyGuards.isRubyArray(array);
return ArrayNodes.getSize(array) == 0;
}

Original file line number Diff line number Diff line change
@@ -90,7 +90,7 @@ public EmptyArrayLiteralNode(RubyContext context, SourceSection sourceSection, R

@Override
public RubyArray executeRubyArray(VirtualFrame frame) {
return createEmptyArray();
return (RubyArray) createEmptyArray();
}

}
@@ -114,7 +114,7 @@ public RubyArray executeRubyArray(VirtualFrame frame) {
}
}

return createArray(executedValues, values.length);
return (RubyArray) createArray(executedValues, values.length);
}

private RubyArray makeGeneric(VirtualFrame frame,
@@ -149,7 +149,7 @@ public RubyArray executeRubyArray(VirtualFrame frame) {
}
}

return createArray(executedValues, values.length);
return (RubyArray) createArray(executedValues, values.length);
}

private RubyArray makeGeneric(VirtualFrame frame,
@@ -184,7 +184,7 @@ public RubyArray executeRubyArray(VirtualFrame frame) {
}
}

return createArray(executedValues, values.length);
return (RubyArray) createArray(executedValues, values.length);
}

private RubyArray makeGeneric(VirtualFrame frame,
@@ -215,7 +215,7 @@ public RubyArray executeRubyArray(VirtualFrame frame) {
executedValues[n] = values[n].execute(frame);
}

return createArray(executedValues, values.length);
return (RubyArray) createArray(executedValues, values.length);
}

}
244 changes: 122 additions & 122 deletions truffle/src/main/java/org/jruby/truffle/nodes/core/array/ArrayNodes.java

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -15,6 +15,7 @@
import org.jruby.truffle.nodes.RubyNode;
import org.jruby.truffle.runtime.RubyContext;
import org.jruby.truffle.runtime.core.RubyArray;
import org.jruby.truffle.runtime.core.RubyBasicObject;

public class ArrayPushNode extends RubyNode {

@@ -36,7 +37,7 @@ public Object execute(VirtualFrame frame) {

final RubyArray originalArray = (RubyArray) arrayObject;

final RubyArray newArray = createArray(ArrayNodes.slowToArray(originalArray), ArrayNodes.getSize(originalArray));
final RubyBasicObject newArray = createArray(ArrayNodes.slowToArray(originalArray), ArrayNodes.getSize(originalArray));
ArrayNodes.slowPush(newArray, pushed.execute(frame));
return newArray;
}
Original file line number Diff line number Diff line change
@@ -57,7 +57,7 @@ public RubyBasicObject readNegativeLength(RubyArray array, int index, int length
@Specialization(
guards={"indexInBounds(array, index)", "lengthPositive(length)", "isNullArray(array)"}
)
public RubyArray readNull(RubyArray array, int index, int length) {
public RubyBasicObject readNull(RubyArray array, int index, int length) {
return ArrayNodes.createEmptyArray(array.getLogicalClass());
}

@@ -66,31 +66,31 @@ public RubyArray readNull(RubyArray array, int index, int length) {
@Specialization(
guards={"indexInBounds(array, index)", "lengthPositive(length)", "endInBounds(array, index, length)", "isIntArray(array)"}
)
public RubyArray readIntInBounds(RubyArray array, int index, int length) {
public RubyBasicObject readIntInBounds(RubyArray array, int index, int length) {
return ArrayNodes.createArray(array.getLogicalClass(),
Arrays.copyOfRange((int[]) ArrayNodes.getStore(array), index, index + length), length);
}

@Specialization(
guards={"indexInBounds(array, index)", "lengthPositive(length)", "endInBounds(array, index, length)", "isLongArray(array)"}
)
public RubyArray readLongInBounds(RubyArray array, int index, int length) {
public RubyBasicObject readLongInBounds(RubyArray array, int index, int length) {
return ArrayNodes.createArray(array.getLogicalClass(),
Arrays.copyOfRange((long[]) ArrayNodes.getStore(array), index, index + length), length);
}

@Specialization(
guards={"indexInBounds(array, index)", "lengthPositive(length)", "endInBounds(array, index, length)", "isDoubleArray(array)"}
)
public RubyArray readDoubleInBounds(RubyArray array, int index, int length) {
public RubyBasicObject readDoubleInBounds(RubyArray array, int index, int length) {
return ArrayNodes.createArray(array.getLogicalClass(),
Arrays.copyOfRange((double[]) ArrayNodes.getStore(array), index, index + length), length);
}

@Specialization(
guards={"indexInBounds(array, index)", "lengthPositive(length)", "endInBounds(array, index, length)", "isObjectArray(array)"}
)
public RubyArray readObjectInBounds(RubyArray array, int index, int length) {
public RubyBasicObject readObjectInBounds(RubyArray array, int index, int length) {
return ArrayNodes.createArray(array.getLogicalClass(),
Arrays.copyOfRange((Object[]) ArrayNodes.getStore(array), index, index + length), length);
}
@@ -100,7 +100,7 @@ public RubyArray readObjectInBounds(RubyArray array, int index, int length) {
@Specialization(
guards={"indexInBounds(array, index)", "lengthPositive(length)", "!endInBounds(array, index, length)", "isIntArray(array)"}
)
public RubyArray readIntOutOfBounds(RubyArray array, int index, int length) {
public RubyBasicObject readIntOutOfBounds(RubyArray array, int index, int length) {
final int clampedLength = Math.min(ArrayNodes.getSize(array), index + length) - index;

return ArrayNodes.createArray(array.getLogicalClass(),
@@ -110,7 +110,7 @@ public RubyArray readIntOutOfBounds(RubyArray array, int index, int length) {
@Specialization(
guards={"indexInBounds(array, index)", "lengthPositive(length)", "!endInBounds(array, index, length)", "isLongArray(array)"}
)
public RubyArray readLongOutOfBounds(RubyArray array, int index, int length) {
public RubyBasicObject readLongOutOfBounds(RubyArray array, int index, int length) {
final int clampedLength = Math.min(ArrayNodes.getSize(array), index + length) - index;

return ArrayNodes.createArray(array.getLogicalClass(),
@@ -120,7 +120,7 @@ public RubyArray readLongOutOfBounds(RubyArray array, int index, int length) {
@Specialization(
guards={"indexInBounds(array, index)", "lengthPositive(length)", "!endInBounds(array, index, length)", "isDoubleArray(array)"}
)
public RubyArray readDoubleOutOfBounds(RubyArray array, int index, int length) {
public RubyBasicObject readDoubleOutOfBounds(RubyArray array, int index, int length) {
final int clampedLength = Math.min(ArrayNodes.getSize(array), index + length) - index;

return ArrayNodes.createArray(array.getLogicalClass(),
@@ -130,7 +130,7 @@ public RubyArray readDoubleOutOfBounds(RubyArray array, int index, int length) {
@Specialization(
guards={"indexInBounds(array, index)", "lengthPositive(length)", "!endInBounds(array, index, length)", "isObjectArray(array)"}
)
public RubyArray readObjectOutOfBounds(RubyArray array, int index, int length) {
public RubyBasicObject readObjectOutOfBounds(RubyArray array, int index, int length) {
final int clampedLength = Math.min(ArrayNodes.getSize(array), index + length) - index;

return ArrayNodes.createArray(array.getLogicalClass(),
Original file line number Diff line number Diff line change
@@ -19,6 +19,7 @@
import org.jruby.truffle.runtime.RubyContext;
import org.jruby.truffle.runtime.array.ArrayUtils;
import org.jruby.truffle.runtime.core.RubyArray;
import org.jruby.truffle.runtime.core.RubyBasicObject;

@NodeChildren({@NodeChild(value = "array", type = RubyNode.class)})
@ImportStatic(ArrayGuards.class)
@@ -36,14 +37,14 @@ public ArraySliceNode(RubyContext context, SourceSection sourceSection, int from
}

@Specialization(guards = "isNullArray(array)")
public RubyArray sliceNull(RubyArray array) {
public RubyBasicObject sliceNull(RubyArray array) {
CompilerDirectives.transferToInterpreter();

return createEmptyArray();
}

@Specialization(guards = "isIntArray(array)")
public RubyArray sliceIntegerFixnum(RubyArray array) {
public RubyBasicObject sliceIntegerFixnum(RubyArray array) {
CompilerDirectives.transferToInterpreter();
final int to = ArrayNodes.getSize(array) + this.to;

@@ -55,7 +56,7 @@ public RubyArray sliceIntegerFixnum(RubyArray array) {
}

@Specialization(guards = "isLongArray(array)")
public RubyArray sliceLongFixnum(RubyArray array) {
public RubyBasicObject sliceLongFixnum(RubyArray array) {
CompilerDirectives.transferToInterpreter();
final int to = ArrayNodes.getSize(array) + this.to;

@@ -67,7 +68,7 @@ public RubyArray sliceLongFixnum(RubyArray array) {
}

@Specialization(guards = "isDoubleArray(array)")
public RubyArray sliceFloat(RubyArray array) {
public RubyBasicObject sliceFloat(RubyArray array) {
CompilerDirectives.transferToInterpreter();
final int to = ArrayNodes.getSize(array) + this.to;

@@ -79,7 +80,7 @@ public RubyArray sliceFloat(RubyArray array) {
}

@Specialization(guards = "isObjectArray(array)")
public RubyArray sliceObject(RubyArray array) {
public RubyBasicObject sliceObject(RubyArray array) {
CompilerDirectives.transferToInterpreter();
final int to = ArrayNodes.getSize(array) + this.to;

Original file line number Diff line number Diff line change
@@ -19,6 +19,7 @@
import org.jruby.truffle.runtime.RubyContext;
import org.jruby.truffle.runtime.array.ArrayUtils;
import org.jruby.truffle.runtime.core.RubyArray;
import org.jruby.truffle.runtime.core.RubyBasicObject;

@NodeChildren({
@NodeChild(value="array", type=RubyNode.class),
@@ -38,15 +39,15 @@ public GeneralizeArrayNode(RubyContext context, SourceSection sourceSection) {
@Specialization(
guards={"isNullArray(array)"}
)
public RubyArray generalizeNull(RubyArray array, int requiredCapacity) {
public RubyBasicObject generalizeNull(RubyArray array, int requiredCapacity) {
ArrayNodes.setStore(array, new Object[requiredCapacity], ArrayNodes.getSize(array));
return array;
}

@Specialization(
guards={"isIntArray(array)"}
)
public RubyArray generalizeInt(RubyArray array, int requiredCapacity) {
public RubyBasicObject generalizeInt(RubyArray array, int requiredCapacity) {
final int[] intStore = (int[]) ArrayNodes.getStore(array);
ArrayNodes.setStore(array, ArrayUtils.boxExtra(intStore, requiredCapacity - intStore.length), ArrayNodes.getSize(array));
return array;
@@ -55,7 +56,7 @@ public RubyArray generalizeInt(RubyArray array, int requiredCapacity) {
@Specialization(
guards={"isLongArray(array)"}
)
public RubyArray generalizeLong(RubyArray array, int requiredCapacity) {
public RubyBasicObject generalizeLong(RubyArray array, int requiredCapacity) {
final long[] intStore = (long[]) ArrayNodes.getStore(array);
ArrayNodes.setStore(array, ArrayUtils.boxExtra(intStore, requiredCapacity - intStore.length), ArrayNodes.getSize(array));
return array;
@@ -64,7 +65,7 @@ public RubyArray generalizeLong(RubyArray array, int requiredCapacity) {
@Specialization(
guards={"isDoubleArray(array)"}
)
public RubyArray generalizeDouble(RubyArray array, int requiredCapacity) {
public RubyBasicObject generalizeDouble(RubyArray array, int requiredCapacity) {
final double[] intStore = (double[]) ArrayNodes.getStore(array);
ArrayNodes.setStore(array, ArrayUtils.boxExtra(intStore, requiredCapacity - intStore.length), ArrayNodes.getSize(array));
return array;
Original file line number Diff line number Diff line change
@@ -25,7 +25,6 @@
import org.jruby.truffle.runtime.NotProvided;
import org.jruby.truffle.runtime.RubyContext;
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.RubyString;

@@ -455,17 +454,17 @@ public DivModNode(RubyContext context, SourceSection sourceSection) {
}

@Specialization
public RubyArray divMod(long a, long b) {
public RubyBasicObject divMod(long a, long b) {
return divModNode.execute(a, b);
}

@Specialization(guards = "isRubyBignum(b)")
public RubyArray divMod(long a, RubyBasicObject b) {
public RubyBasicObject divMod(long a, RubyBasicObject b) {
return divModNode.execute(a, BignumNodes.getBigIntegerValue(b));
}

@Specialization
public RubyArray divMod(long a, double b) {
public RubyBasicObject divMod(long a, double b) {
return divModNode.execute(a, b);
}

Original file line number Diff line number Diff line change
@@ -9,6 +9,7 @@
*/
package org.jruby.truffle.nodes.core.hash;

import org.jruby.truffle.nodes.RubyGuards;
import org.jruby.truffle.runtime.core.RubyBasicObject;
import org.jruby.truffle.runtime.hash.Entry;

@@ -17,33 +18,40 @@ public abstract class HashGuards {
// Storage strategies

public static boolean isNullHash(RubyBasicObject hash) {
assert RubyGuards.isRubyHash(hash);
return HashNodes.getStore(hash) == null;
}

public static boolean isPackedHash(RubyBasicObject hash) {
assert RubyGuards.isRubyHash(hash);
// Can't do instanceof Object[] due to covariance
return !(isNullHash(hash) || isBucketHash(hash));
}

public static boolean isBucketHash(RubyBasicObject hash) {
assert RubyGuards.isRubyHash(hash);
return HashNodes.getStore(hash) instanceof Entry[];
}

// Higher level properties

public static boolean isEmptyHash(RubyBasicObject hash) {
assert RubyGuards.isRubyHash(hash);
return HashNodes.getSize(hash) == 0;
}

public static boolean isCompareByIdentity(RubyBasicObject hash) {
assert RubyGuards.isRubyHash(hash);
return HashNodes.isCompareByIdentity(hash);
}

public static boolean hasDefaultValue(RubyBasicObject hash) {
assert RubyGuards.isRubyHash(hash);
return HashNodes.getDefaultValue(hash) != null;
}

public static boolean hasDefaultBlock(RubyBasicObject hash) {
assert RubyGuards.isRubyHash(hash);
return HashNodes.getDefaultBlock(hash) != null;
}

Original file line number Diff line number Diff line change
@@ -895,15 +895,15 @@ public MapNode(RubyContext context, SourceSection sourceSection) {
}

@Specialization(guards = "isNullHash(hash)")
public RubyArray mapNull(VirtualFrame frame, RubyBasicObject hash, RubyProc block) {
public RubyBasicObject mapNull(VirtualFrame frame, RubyBasicObject hash, RubyProc block) {
assert HashOperations.verifyStore(hash);

return createEmptyArray();
}

@ExplodeLoop
@Specialization(guards = "isPackedHash(hash)")
public RubyArray mapPackedArray(VirtualFrame frame, RubyBasicObject hash, RubyProc block) {
public RubyBasicObject mapPackedArray(VirtualFrame frame, RubyBasicObject hash, RubyProc block) {
assert HashOperations.verifyStore(hash);

final Object[] store = (Object[]) getStore(hash);
@@ -935,12 +935,12 @@ public RubyArray mapPackedArray(VirtualFrame frame, RubyBasicObject hash, RubyPr
}

@Specialization(guards = "isBucketHash(hash)")
public RubyArray mapBuckets(VirtualFrame frame, RubyBasicObject hash, RubyProc block) {
public RubyBasicObject mapBuckets(VirtualFrame frame, RubyBasicObject hash, RubyProc block) {
CompilerDirectives.transferToInterpreter();

assert HashOperations.verifyStore(hash);

final RubyArray array = createEmptyArray();
final RubyBasicObject array = createEmptyArray();

for (KeyValue keyValue : HashOperations.verySlowToKeyValues(hash)) {
ArrayNodes.slowPush(array, yield(frame, block, keyValue.getKey(), keyValue.getValue()));
Original file line number Diff line number Diff line change
@@ -19,7 +19,6 @@
import org.jruby.truffle.nodes.dispatch.DoesRespondDispatchHeadNode;
import org.jruby.truffle.nodes.dispatch.MissingBehavior;
import org.jruby.truffle.runtime.RubyContext;
import org.jruby.truffle.runtime.core.RubyArray;
import org.jruby.truffle.runtime.core.RubyBasicObject;

import java.math.BigInteger;
@@ -42,17 +41,17 @@ public FixnumCoercePrimitiveNode(RubyContext context, SourceSection sourceSectio
}

@Specialization
public RubyArray coerce(int a, int b) {
public RubyBasicObject coerce(int a, int b) {
return createArray(new int[]{b, a}, 2);
}

@Specialization
public RubyArray coerce(long a, int b) {
public RubyBasicObject coerce(long a, int b) {
return createArray(new long[]{b, a}, 2);
}

@Specialization(guards = "!isInteger(b)")
public RubyArray coerce(int a, Object b) {
public RubyBasicObject coerce(int a, Object b) {
return null; // Primitive failure
}

Original file line number Diff line number Diff line change
@@ -18,7 +18,7 @@
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;
import org.jruby.truffle.runtime.core.RubyBasicObject;

import java.util.Locale;

@@ -36,7 +36,7 @@ public FloatDToAPrimitiveNode(RubyContext context, SourceSection sourceSection)

@TruffleBoundary
@Specialization
public RubyArray dToA(double value) {
public RubyBasicObject dToA(double value) {
String string = String.format(Locale.ENGLISH, "%.9f", value);

if (string.toLowerCase(Locale.ENGLISH).contains("e")) {
Original file line number Diff line number Diff line change
@@ -629,7 +629,7 @@ private static int max(int[] values) {
return max;
}

private RubyArray getSetObjects(Object[] objects, int[] fds, FDSet set) {
private RubyBasicObject getSetObjects(Object[] objects, int[] fds, FDSet set) {
final Object[] setObjects = new Object[objects.length];
int setFdsCount = 0;

Original file line number Diff line number Diff line change
@@ -22,7 +22,10 @@
import org.jruby.truffle.runtime.DebugOperations;
import org.jruby.truffle.runtime.RubyContext;
import org.jruby.truffle.runtime.control.RaiseException;
import org.jruby.truffle.runtime.core.*;
import org.jruby.truffle.runtime.core.RubyBasicObject;
import org.jruby.truffle.runtime.core.RubyClass;
import org.jruby.truffle.runtime.core.RubyString;
import org.jruby.truffle.runtime.core.RubyTime;
import org.jruby.util.RubyDateFormatter;

/**
@@ -153,7 +156,7 @@ public TimeDecomposePrimitiveNode(RubyContext context, SourceSection sourceSecti

@TruffleBoundary
@Specialization
public RubyArray timeDecompose(RubyTime time) {
public RubyBasicObject timeDecompose(RubyTime time) {
final DateTime dateTime = time.getDateTime();
final int sec = dateTime.getSecondOfMinute();
final int min = dateTime.getMinuteOfHour();
Original file line number Diff line number Diff line change
@@ -378,7 +378,7 @@ public TimesNode(RubyContext context, SourceSection sourceSection) {
}

@Specialization
public RubyArray times() {
public RubyBasicObject times() {
// Copied from org/jruby/RubyProcess.java - see copyright and license information there

Times tms = posix().times();
Original file line number Diff line number Diff line change
@@ -133,7 +133,7 @@ public class CoreLibrary {
private final RubyClass threadErrorClass;
private final RubyClass ioBufferClass;

private final RubyArray argv;
private final RubyBasicObject argv;
private final RubyBasicObject globalVariablesObject;
private final RubyBasicObject mainObject;
private final RubyBasicObject nilObject;
@@ -1279,20 +1279,20 @@ public RubyModule getKernelModule() {
return kernelModule;
}

public RubyArray getArgv() {
public RubyBasicObject getArgv() {
return argv;
}

public RubyBasicObject getGlobalVariablesObject() {
return globalVariablesObject;
}

public RubyArray getLoadPath() {
return (RubyArray) globalVariablesObject.getInstanceVariable("$LOAD_PATH");
public RubyBasicObject getLoadPath() {
return (RubyBasicObject) globalVariablesObject.getInstanceVariable("$LOAD_PATH");
}

public RubyArray getLoadedFeatures() {
return (RubyArray) globalVariablesObject.getInstanceVariable("$LOADED_FEATURES");
public RubyBasicObject getLoadedFeatures() {
return (RubyBasicObject) globalVariablesObject.getInstanceVariable("$LOADED_FEATURES");
}

public RubyBasicObject getMainObject() {
Original file line number Diff line number Diff line change
@@ -45,12 +45,10 @@ public class RubyRegexp extends RubyBasicObject {
@CompilationFinal private ByteList source;
@CompilationFinal private RegexpOptions options;


public RubyRegexp(RubyClass regexpClass) {
super(regexpClass);
}


public RubyRegexp(Node currentNode, RubyClass regexpClass, ByteList regex, RegexpOptions options) {
this(regexpClass);
this.options = options;
@@ -407,7 +405,7 @@ public Object scan(RubyString string) {
setThread("$~", lastGoodMatchData);
return strings.toArray(new RubyString[strings.size()]);
} else {
final List<RubyArray> allMatches = new ArrayList<>();
final List<RubyBasicObject> allMatches = new ArrayList<>();

while (true) {
Object matchData = matchCommon(string, false, true, matcher, p + end, stringBytes.length);

0 comments on commit 9b8d6f2

Please sign in to comment.