Skip to content
Permalink

Comparing changes

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

Open a pull request

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

Commits on Nov 14, 2014

  1. Copy the full SHA
    470b5ca View commit details
  2. [Truffle] Fix handling of the rest argument with post arguments.

    * Simplify too much indices computations by using negative indices.
    * Introduce an ArraySliceNode.
    eregon committed Nov 14, 2014
    Copy the full SHA
    a63029b View commit details
  3. [Truffle] Untag some new passing specs due to rest arg handling and b…

    …etter splat support.
    eregon committed Nov 14, 2014
    Copy the full SHA
    9e6c2be View commit details
Original file line number Diff line number Diff line change
@@ -9,6 +9,7 @@
*/
package org.jruby.truffle.nodes.core;

import com.oracle.truffle.api.dsl.ImportGuards;
import com.oracle.truffle.api.dsl.NodeChild;
import com.oracle.truffle.api.dsl.NodeChildren;
import com.oracle.truffle.api.dsl.Specialization;
@@ -20,6 +21,7 @@
import java.util.Arrays;

@NodeChildren({@NodeChild(value = "array", type = RubyNode.class)})
@ImportGuards(ArrayGuards.class)
public abstract class ArrayDropTailNode extends RubyNode {

final int index;
@@ -88,66 +90,4 @@ public RubyArray getHeadObject(RubyArray array) {
}
}

// TODO(CS): copied and pasted from ArrayCoreMethodNode - need a way to use statics from other classes in the DSL

protected boolean isNull(RubyArray array) {
return array.getStore() == null;
}

protected boolean isIntegerFixnum(RubyArray array) {
return array.getStore() instanceof int[];
}

protected boolean isLongFixnum(RubyArray array) {
return array.getStore() instanceof long[];
}

protected boolean isFloat(RubyArray array) {
return array.getStore() instanceof double[];
}

protected boolean isObject(RubyArray array) {
return array.getStore() instanceof Object[];
}

protected boolean isOtherNull(RubyArray array, RubyArray other) {
return other.getStore() == null;
}

protected boolean isOtherIntegerFixnum(RubyArray array, RubyArray other) {
return other.getStore() instanceof int[];
}

protected boolean isOtherLongFixnum(RubyArray array, RubyArray other) {
return other.getStore() instanceof long[];
}

protected boolean isOtherFloat(RubyArray array, RubyArray other) {
return other.getStore() instanceof double[];
}

protected boolean isOtherObject(RubyArray array, RubyArray other) {
return other.getStore() instanceof Object[];
}

protected boolean areBothNull(RubyArray a, RubyArray b) {
return a.getStore() == null && b.getStore() == null;
}

protected boolean areBothIntegerFixnum(RubyArray a, RubyArray b) {
return a.getStore() instanceof int[] && b.getStore() instanceof int[];
}

protected boolean areBothLongFixnum(RubyArray a, RubyArray b) {
return a.getStore() instanceof long[] && b.getStore() instanceof long[];
}

protected boolean areBothFloat(RubyArray a, RubyArray b) {
return a.getStore() instanceof double[] && b.getStore() instanceof double[];
}

protected boolean areBothObject(RubyArray a, RubyArray b) {
return a.getStore() instanceof Object[] && b.getStore() instanceof Object[];
}

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

import com.oracle.truffle.api.dsl.ImportGuards;
import com.oracle.truffle.api.source.SourceSection;
import com.oracle.truffle.api.dsl.NodeChild;
import com.oracle.truffle.api.dsl.NodeChildren;
@@ -21,6 +22,7 @@
import java.util.Arrays;

@NodeChildren({@NodeChild(value = "array", type = RubyNode.class)})
@ImportGuards(ArrayGuards.class)
public abstract class ArrayGetTailNode extends RubyNode {

final int index;
@@ -86,66 +88,4 @@ public RubyArray getTailObject(RubyArray array) {
}
}

// TODO(CS): copied and pasted from ArrayCoreMethodNode - need a way to use statics from other classes in the DSL

protected boolean isNull(RubyArray array) {
return array.getStore() == null;
}

protected boolean isIntegerFixnum(RubyArray array) {
return array.getStore() instanceof int[];
}

protected boolean isLongFixnum(RubyArray array) {
return array.getStore() instanceof long[];
}

protected boolean isFloat(RubyArray array) {
return array.getStore() instanceof double[];
}

protected boolean isObject(RubyArray array) {
return array.getStore() instanceof Object[];
}

protected boolean isOtherNull(RubyArray array, RubyArray other) {
return other.getStore() == null;
}

protected boolean isOtherIntegerFixnum(RubyArray array, RubyArray other) {
return other.getStore() instanceof int[];
}

protected boolean isOtherLongFixnum(RubyArray array, RubyArray other) {
return other.getStore() instanceof long[];
}

protected boolean isOtherFloat(RubyArray array, RubyArray other) {
return other.getStore() instanceof double[];
}

protected boolean isOtherObject(RubyArray array, RubyArray other) {
return other.getStore() instanceof Object[];
}

protected boolean areBothNull(RubyArray a, RubyArray b) {
return a.getStore() == null && b.getStore() == null;
}

protected boolean areBothIntegerFixnum(RubyArray a, RubyArray b) {
return a.getStore() instanceof int[] && b.getStore() instanceof int[];
}

protected boolean areBothLongFixnum(RubyArray a, RubyArray b) {
return a.getStore() instanceof long[] && b.getStore() instanceof long[];
}

protected boolean areBothFloat(RubyArray a, RubyArray b) {
return a.getStore() instanceof double[] && b.getStore() instanceof double[];
}

protected boolean areBothObject(RubyArray a, RubyArray b) {
return a.getStore() instanceof Object[] && b.getStore() instanceof Object[];
}

}
Original file line number Diff line number Diff line change
@@ -23,6 +23,7 @@
* class.
*/
@NodeChildren({@NodeChild(value = "array", type = RubyNode.class)})
@ImportGuards(ArrayGuards.class)
public abstract class ArrayIndexNode extends RubyNode {

final int index;
@@ -119,66 +120,4 @@ public Object getObject(RubyArray array) {
}
}

// TODO(CS): copied and pasted from ArrayCoreMethodNode - need a way to use statics from other classes in the DSL

protected boolean isNull(RubyArray array) {
return array.getStore() == null;
}

protected boolean isIntegerFixnum(RubyArray array) {
return array.getStore() instanceof int[];
}

protected boolean isLongFixnum(RubyArray array) {
return array.getStore() instanceof long[];
}

protected boolean isFloat(RubyArray array) {
return array.getStore() instanceof double[];
}

protected boolean isObject(RubyArray array) {
return array.getStore() instanceof Object[];
}

protected boolean isOtherNull(RubyArray array, RubyArray other) {
return other.getStore() == null;
}

protected boolean isOtherIntegerFixnum(RubyArray array, RubyArray other) {
return other.getStore() instanceof int[];
}

protected boolean isOtherLongFixnum(RubyArray array, RubyArray other) {
return other.getStore() instanceof long[];
}

protected boolean isOtherFloat(RubyArray array, RubyArray other) {
return other.getStore() instanceof double[];
}

protected boolean isOtherObject(RubyArray array, RubyArray other) {
return other.getStore() instanceof Object[];
}

protected boolean areBothNull(RubyArray a, RubyArray b) {
return a.getStore() == null && b.getStore() == null;
}

protected boolean areBothIntegerFixnum(RubyArray a, RubyArray b) {
return a.getStore() instanceof int[] && b.getStore() instanceof int[];
}

protected boolean areBothLongFixnum(RubyArray a, RubyArray b) {
return a.getStore() instanceof long[] && b.getStore() instanceof long[];
}

protected boolean areBothFloat(RubyArray a, RubyArray b) {
return a.getStore() instanceof double[] && b.getStore() instanceof double[];
}

protected boolean areBothObject(RubyArray a, RubyArray b) {
return a.getStore() instanceof Object[] && b.getStore() instanceof Object[];
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
/*
* Copyright (c) 2013, 2014 Oracle and/or its affiliates. All rights reserved. This
* code is released under a tri EPL/GPL/LGPL license. You can use it,
* redistribute it and/or modify it under the terms of the:
*
* Eclipse Public License version 1.0
* GNU General Public License version 2
* GNU Lesser General Public License version 2.1
*/
package org.jruby.truffle.nodes.core;

import com.oracle.truffle.api.dsl.ImportGuards;
import com.oracle.truffle.api.dsl.NodeChild;
import com.oracle.truffle.api.dsl.NodeChildren;
import com.oracle.truffle.api.dsl.Specialization;
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 java.util.Arrays;

@NodeChildren({@NodeChild(value = "array", type = RubyNode.class)})
@ImportGuards(ArrayGuards.class)
public abstract class ArraySliceNode extends RubyNode {

final int from; // positive
final int to; // negative, exclusive

public ArraySliceNode(RubyContext context, SourceSection sourceSection, int from, int to) {
super(context, sourceSection);
assert from >= 0;
assert to <= 0;
this.from = from;
this.to = to;
}

public ArraySliceNode(ArraySliceNode prev) {
super(prev);
from = prev.from;
to = prev.to;
}

@Specialization(guards = "isNull")
public RubyArray sliceNull(RubyArray array) {
notDesignedForCompilation();

return new RubyArray(getContext().getCoreLibrary().getArrayClass());
}

@Specialization(guards = "isIntegerFixnum")
public RubyArray sliceIntegerFixnum(RubyArray array) {
notDesignedForCompilation();
final int to = array.getSize() + this.to;

if (from >= to) {
return new RubyArray(getContext().getCoreLibrary().getArrayClass());
} else {
return new RubyArray(getContext().getCoreLibrary().getArrayClass(), Arrays.copyOfRange((int[]) array.getStore(), from, to), to - from);
}
}

@Specialization(guards = "isLongFixnum")
public RubyArray sliceLongFixnum(RubyArray array) {
notDesignedForCompilation();
final int to = array.getSize() + this.to;

if (from >= to) {
return new RubyArray(getContext().getCoreLibrary().getArrayClass());
} else {
return new RubyArray(getContext().getCoreLibrary().getArrayClass(), Arrays.copyOfRange((long[]) array.getStore(), from, to), to - from);
}
}

@Specialization(guards = "isFloat")
public RubyArray sliceFloat(RubyArray array) {
notDesignedForCompilation();
final int to = array.getSize() + this.to;

if (from >= to) {
return new RubyArray(getContext().getCoreLibrary().getArrayClass());
} else {
return new RubyArray(getContext().getCoreLibrary().getArrayClass(), Arrays.copyOfRange((double[]) array.getStore(), from, to), to - from);
}
}

@Specialization(guards = "isObject")
public RubyArray sliceObject(RubyArray array) {
notDesignedForCompilation();
final int to = array.getSize() + this.to;

if (from >= to) {
return new RubyArray(getContext().getCoreLibrary().getArrayClass());
} else {
return new RubyArray(getContext().getCoreLibrary().getArrayClass(), Arrays.copyOfRange((Object[]) array.getStore(), from, to), to - from);
}
}

}
Original file line number Diff line number Diff line change
@@ -9,10 +9,8 @@
*/
package org.jruby.truffle.nodes.methods.arguments;

import com.oracle.truffle.api.*;
import com.oracle.truffle.api.source.*;
import com.oracle.truffle.api.frame.*;
import com.oracle.truffle.api.nodes.*;
import org.jruby.truffle.nodes.*;
import org.jruby.truffle.runtime.*;

@@ -21,19 +19,19 @@
*/
public class ReadPostArgumentNode extends RubyNode {

private final int indexFromEnd;
private final int negativeIndex;

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

@Override
public Object execute(VirtualFrame frame) {
notDesignedForCompilation();

int count = RubyArguments.getUserArgumentsCount(frame.getArguments());
final int effectiveIndex = count - 1 - indexFromEnd;
final int effectiveIndex = count + negativeIndex;
assert effectiveIndex < count;
return RubyArguments.getUserArgument(frame.getArguments(), effectiveIndex);
}
Loading