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

Commits on Oct 14, 2014

  1. Copy the full SHA
    d787a8d View commit details
  2. Copy the full SHA
    37049ba View commit details
  3. Copy the full SHA
    1b2d9c1 View commit details
  4. Copy the full SHA
    0a16107 View commit details
42 changes: 22 additions & 20 deletions core/src/main/java/org/jruby/truffle/nodes/core/ArrayNodes.java
Original file line number Diff line number Diff line change
@@ -3083,20 +3083,21 @@ public RubyArray sortNull(RubyArray array) {
public RubyArray sortVeryShortIntegerFixnum(VirtualFrame frame, RubyArray array) {
final int[] store = (int[]) array.getStore();

// Insertion sort

final int size = array.getSize();

for (int i = 1; i < RubyContext.ARRAYS_SMALL; i++) {
// Selection sort - written very carefully to allow PE

for (int i = 0; i < RubyContext.ARRAYS_SMALL; i++) {
if (i < size) {
final int x = store[i];
int j = i;
// TODO(CS): node for this cast
while (j > 0 && (int) compareDispatchNode.call(frame, store[j - 1], "<=>", null, x) > 0) {
store[j] = store[j - 1];
j--;
for (int j = i + 1; j < RubyContext.ARRAYS_SMALL; j++) {
if (j < size) {
if ((int) compareDispatchNode.call(frame, store[j], "<=>", null, store[i]) < 0) {
final int temp = store[j];
store[j] = store[i];
store[i] = temp;
}
}
}
store[j] = x;
}
}

@@ -3118,20 +3119,21 @@ public RubyArray sortIntegerFixnum(VirtualFrame frame, RubyArray array) {
public RubyArray sortVeryShortLongFixnum(VirtualFrame frame, RubyArray array) {
final long[] store = (long[]) array.getStore();

// Insertion sort

final int size = array.getSize();

for (int i = 1; i < RubyContext.ARRAYS_SMALL; i++) {
// Selection sort - written very carefully to allow PE

for (int i = 0; i < RubyContext.ARRAYS_SMALL; i++) {
if (i < size) {
final long x = store[i];
int j = i;
// TODO(CS): node for this cast
while (j > 0 && (int) compareDispatchNode.call(frame, store[j - 1], "<=>", null, x) > 0) {
store[j] = store[j - 1];
j--;
for (int j = i + 1; j < RubyContext.ARRAYS_SMALL; j++) {
if (j < size) {
if ((int) compareDispatchNode.call(frame, store[j], "<=>", null, store[i]) < 0) {
final long temp = store[j];
store[j] = store[i];
store[i] = temp;
}
}
}
store[j] = x;
}
}

Original file line number Diff line number Diff line change
@@ -16,6 +16,7 @@
import org.jruby.truffle.runtime.core.*;
import org.jruby.truffle.runtime.methods.MethodLike;

import java.util.Arrays;
import java.util.Iterator;

/**
@@ -56,13 +57,7 @@ public static RubyProc getBlock(Object[] arguments) {
}

public static Object[] extractUserArguments(Object[] arguments) {
final Object[] userArguments = new Object[arguments.length - RUNTIME_ARGUMENT_COUNT];

for (int n = 0; n < userArguments.length; n++) {
userArguments[n] = arguments[RUNTIME_ARGUMENT_COUNT + n];
}

return userArguments;
return Arrays.copyOfRange(arguments, RUNTIME_ARGUMENT_COUNT, arguments.length);
}

public static Object[] concatUserArguments(Object o, Object[] arguments) {
4 changes: 4 additions & 0 deletions test/pom.rb
Original file line number Diff line number Diff line change
@@ -173,6 +173,8 @@
'<arg value="-Xparser.warn.argument_prefix=false" />' +
'<arg value="-T" />' +
'<arg value="-J-ea" />' +
'<arg value="-T" />' +
'<arg value="-J-Xmx2G" />' +
'<arg value="--config" />' +
'<arg value="spec/truffle/truffle.mspec" />' +
'<arg value="--excl-tag" />' +
@@ -221,6 +223,8 @@
'<arg value="-Xparser.warn.argument_prefix=false" />' +
'<arg value="-T" />' +
'<arg value="-J-ea" />' +
'<arg value="-T" />' +
'<arg value="-J-Xmx2G" />' +
'<arg value="--config" />' +
'<arg value="spec/truffle/truffle.mspec" />' +
'<arg value="--excl-tag" />' +
4 changes: 4 additions & 0 deletions test/pom.xml
Original file line number Diff line number Diff line change
@@ -317,6 +317,8 @@
<arg value="-Xparser.warn.argument_prefix=false" />
<arg value="-T" />
<arg value="-J-ea" />
<arg value="-T" />
<arg value="-J-Xmx2G" />
<arg value="--config" />
<arg value="spec/truffle/truffle.mspec" />
<arg value="--excl-tag" />
@@ -375,6 +377,8 @@
<arg value="-Xparser.warn.argument_prefix=false" />
<arg value="-T" />
<arg value="-J-ea" />
<arg value="-T" />
<arg value="-J-Xmx2G" />
<arg value="--config" />
<arg value="spec/truffle/truffle.mspec" />
<arg value="--excl-tag" />
18 changes: 18 additions & 0 deletions test/truffle/pe/core/array_pe.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
PETests.tests do

describe "A small Array" do

example "indexed by a constant" do
array = [3, 1, 2]
truffle_assert_constant array[1]
end

example "sorted and indexed" do
array = [3, 1, 2]
sorted = array.sort
truffle_assert_constant sorted[1]
end

end

end
61 changes: 60 additions & 1 deletion test/truffle/pe/core/fixnum_pe.rb
Original file line number Diff line number Diff line change
@@ -4,14 +4,73 @@

example "literal" do
truffle_assert_constant 14
truffle_assert_constant 0xffffffffffff
end

describe "#+" do

example "a Fixnum" do
truffle_assert_constant 14 + 2
end

counter_example "a Bignum" do
truffle_assert_constant 14 + 0xfffffffffffffffffffffffffffffff
end

example "a Float" do
truffle_assert_constant 14 + 2.0
end

counter_example "rand" do
truffle_assert_constant 14 + rand
end

end

describe "#*" do

example "a Fixnum" do
truffle_assert_constant 14 * 2
end

counter_example "a Bignum" do
truffle_assert_constant 14 * 0xfffffffffffffffffffffffffffffff
end

example "a Float" do
truffle_assert_constant 14 * 2.0
end

counter_example "rand" do
truffle_assert_constant 14 * rand
end

end

describe "#/" do

example "a Fixnum" do
truffle_assert_constant 14 / 2
end

example "a Bignum" do
truffle_assert_constant 14 / 0xfffffffffffffffffffffffffffffff
end

example "a Float" do
truffle_assert_constant 14 / 2.0
end

counter_example "rand" do
truffle_assert_constant 14 / rand
end

end

describe "#<=>" do

example "a Fixnum" do
truffle_assert_constant 14 <=> 2
end

end

62 changes: 61 additions & 1 deletion test/truffle/pe/core/float_pe.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,70 @@
PETests.tests do

describe "A Fixnum" do
describe "A Float" do

example "literal" do
truffle_assert_constant 14.2
end

describe "#+" do

example "a Fixnum" do
truffle_assert_constant 14.0 + 2
end

counter_example "a Bignum" do
truffle_assert_constant 14.0 + 0xfffffffffffffffffffffffffffffff
end

example "a Float" do
truffle_assert_constant 14.0 + 2.0
end

counter_example "rand" do
truffle_assert_constant 14.0 + rand
end

end

describe "#*" do

example "a Fixnum" do
truffle_assert_constant 14.0 * 2
end

counter_example "a Bignum" do
truffle_assert_constant 14.0 * 0xfffffffffffffffffffffffffffffff
end

example "a Float" do
truffle_assert_constant 14.0 * 2.0
end

counter_example "rand" do
truffle_assert_constant 14.0 * rand
end

end

describe "#/" do

example "a Fixnum" do
truffle_assert_constant 14.0 / 2
end

counter_example "a Bignum" do
truffle_assert_constant 14.0 / 0xfffffffffffffffffffffffffffffff
end

example "a Float" do
truffle_assert_constant 14.0 / 2.0
end

counter_example "rand" do
truffle_assert_constant 14.0 / rand
end

end

end

18 changes: 18 additions & 0 deletions test/truffle/pe/core/hash_pe.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
PETests.tests do

describe "A small Hash" do

example "indexed by a constant" do
hash = {a: 0, b: 1, c: 2}
truffle_assert_constant hash[:b]
end

example "mapped to an Array and indexed by a constant" do
hash = {a: 0, b: 1, c: 2}
array = hash.map { |k, v| v }
truffle_assert_constant array[0]
end

end

end
8 changes: 8 additions & 0 deletions test/truffle/pe/core/symbol_pe.rb
Original file line number Diff line number Diff line change
@@ -5,6 +5,14 @@
example "literal" do
truffle_assert_constant :foo
end

example "#== a Symbol" do
truffle_assert_constant :foo == :foo
end

example "#!= a Symbol" do
truffle_assert_constant :foo != :bar
end

end

38 changes: 38 additions & 0 deletions test/truffle/pe/language/metaprogramming_pe.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
module MetaprogrammingFixtures

class MethodMissing

def method_missing(method, *args)
14
end

end

class ClassWithExistingMethod

def existing_method(a)
a
end

end

end

PETests.tests do

example "A call that results in #method_missing" do
method_missing = MetaprogrammingFixtures::MethodMissing.new
truffle_assert_constant method_missing.does_not_exist
end

example "#respond_to? on a method that does exist" do
object_with_existing_method = MetaprogrammingFixtures::ClassWithExistingMethod.new
truffle_assert_constant object_with_existing_method.respond_to? :existing_method
end

example "#send on a method that exists using a symbol" do
object_with_existing_method = MetaprogrammingFixtures::ClassWithExistingMethod.new
truffle_assert_constant object_with_existing_method.send(:existing_method, 14)
end

end
37 changes: 37 additions & 0 deletions test/truffle/pe/macro/pushing_pixels_pe.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
module PushingPixelsFixtures

module Foo
extend self

def foo(a, b, c)
hash = {a: a, b: b, c: c}
array = hash.map { |k, v| v }
x = array[0]
y = [a, b, c].sort[1]
x + y
end

end

class Bar

def method_missing(method, *args)
if Foo.respond_to?(method)
Foo.send(method, *args)
else
0
end
end

end

end

PETests.tests do

example "A set of constants used in a literal hash, mapped to an array, indexed, used in an array literal, sorted, indexed, and added, all via method_missing, respond_to? and send" do
bar = PushingPixelsFixtures::Bar.new
truffle_assert_constant bar.foo(14, 8, 6)
end

end
Loading