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: 1e98cb5eda3a
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: a7a7d7fa43d6
Choose a head ref
  • 4 commits
  • 2 files changed
  • 1 contributor

Commits on Nov 19, 2014

  1. Copy the full SHA
    bcddb48 View commit details
  2. [Truffle] Implement Float#<=>.

    eregon committed Nov 19, 2014
    Copy the full SHA
    045a034 View commit details
  3. Copy the full SHA
    3703364 View commit details
  4. Copy the full SHA
    a7a7d7f View commit details
Showing with 77 additions and 7 deletions.
  1. +60 −7 core/src/main/java/org/jruby/truffle/nodes/core/ArrayNodes.java
  2. +17 −0 core/src/main/java/org/jruby/truffle/nodes/core/FloatNodes.java
67 changes: 60 additions & 7 deletions core/src/main/java/org/jruby/truffle/nodes/core/ArrayNodes.java
Original file line number Diff line number Diff line change
@@ -1765,53 +1765,81 @@ public boolean includeObject(VirtualFrame frame, RubyArray array, Object value)
}

@CoreMethod(names = "initialize", needsBlock = true, required = 1, optional = 1)
public abstract static class InitializeNode extends ArrayCoreMethodNode {
@ImportGuards(ArrayGuards.class)
public abstract static class InitializeNode extends YieldingCoreMethodNode {

@Child protected ArrayBuilderNode arrayBuilder;

public InitializeNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
arrayBuilder = new ArrayBuilderNode.UninitializedArrayBuilderNode(context);
}

public InitializeNode(InitializeNode prev) {
super(prev);
arrayBuilder = prev.arrayBuilder;
}

@Specialization
public RubyArray initialize(RubyArray array, int size, UndefinedPlaceholder defaultValue) {
return initialize(array, size, getContext().getCoreLibrary().getNilObject());
public RubyArray initialize(RubyArray array, int size, UndefinedPlaceholder defaultValue, UndefinedPlaceholder block) {
return initialize(array, size, getContext().getCoreLibrary().getNilObject(), block);
}

@Specialization
public RubyArray initialize(RubyArray array, int size, int defaultValue) {
public RubyArray initialize(RubyArray array, int size, int defaultValue, UndefinedPlaceholder block) {
final int[] store = new int[size];
Arrays.fill(store, defaultValue);
array.setStore(store, size);
return array;
}

@Specialization
public RubyArray initialize(RubyArray array, int size, long defaultValue) {
public RubyArray initialize(RubyArray array, int size, long defaultValue, UndefinedPlaceholder block) {
final long[] store = new long[size];
Arrays.fill(store, defaultValue);
array.setStore(store, size);
return array;
}

@Specialization
public RubyArray initialize(RubyArray array, int size, double defaultValue) {
public RubyArray initialize(RubyArray array, int size, double defaultValue, UndefinedPlaceholder block) {
final double[] store = new double[size];
Arrays.fill(store, defaultValue);
array.setStore(store, size);
return array;
}

@Specialization
public RubyArray initialize(RubyArray array, int size, Object defaultValue) {
public RubyArray initialize(RubyArray array, int size, Object defaultValue, UndefinedPlaceholder block) {
final Object[] store = new Object[size];
Arrays.fill(store, defaultValue);
array.setStore(store, size);
return array;
}

@Specialization
public RubyArray initialize(VirtualFrame frame, RubyArray array, int size, UndefinedPlaceholder defaultValue, RubyProc block) {
Object store = arrayBuilder.start(size);

int count = 0;
try {
for (int n = 0; n < size; n++) {
if (CompilerDirectives.inInterpreter()) {
count++;
}

store = arrayBuilder.append(store, n, yield(frame, block, n));
}
} finally {
if (CompilerDirectives.inInterpreter()) {
((RubyRootNode) getRootNode()).reportLoopCountThroughBlocks(count);
}
}

array.setStore(arrayBuilder.finish(store, size), size);
return array;
}

}

@CoreMethod(names = "initialize_copy", visibility = Visibility.PRIVATE, required = 1)
@@ -2168,6 +2196,31 @@ public RubyArray mapLongFixnum(VirtualFrame frame, RubyArray array, RubyProc blo
return new RubyArray(getContext().getCoreLibrary().getArrayClass(), arrayBuilder.finish(mappedStore, arraySize), arraySize);
}

@Specialization(guards = "isFloat")
public RubyArray mapFloat(VirtualFrame frame, RubyArray array, RubyProc block) {
final double[] store = (double[]) array.getStore();
final int arraySize = array.getSize();
Object mappedStore = arrayBuilder.start(arraySize);

int count = 0;

try {
for (int n = 0; n < array.getSize(); n++) {
if (CompilerDirectives.inInterpreter()) {
count++;
}

mappedStore = arrayBuilder.append(mappedStore, n, yield(frame, block, store[n]));
}
} finally {
if (CompilerDirectives.inInterpreter()) {
((RubyRootNode) getRootNode()).reportLoopCountThroughBlocks(count);
}
}

return new RubyArray(getContext().getCoreLibrary().getArrayClass(), arrayBuilder.finish(mappedStore, arraySize), arraySize);
}

@Specialization(guards = "isObject")
public RubyArray mapObject(VirtualFrame frame, RubyArray array, RubyProc block) {
final Object[] store = (Object[]) array.getStore();
17 changes: 17 additions & 0 deletions core/src/main/java/org/jruby/truffle/nodes/core/FloatNodes.java
Original file line number Diff line number Diff line change
@@ -368,6 +368,23 @@ public boolean equal(double a, BigInteger b) {
}
}

@CoreMethod(names = "<=>", required = 1)
public abstract static class CompareNode extends CoreMethodNode {

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

public CompareNode(CompareNode prev) {
super(prev);
}

@Specialization
public int compare(double a, double b) {
return Double.compare(a, b);
}
}

@CoreMethod(names = ">=", required = 1)
public abstract static class GreaterEqualNode extends CoreMethodNode {