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

Commits on Mar 9, 2015

  1. Copy the full SHA
    7686c0f View commit details
  2. Copy the full SHA
    92a0e1f View commit details
  3. Copy the full SHA
    4602a0e View commit details
  4. Copy the full SHA
    a5776f1 View commit details
  5. Copy the full SHA
    0dfca1e View commit details
  6. Copy the full SHA
    b2e4287 View commit details
2 changes: 0 additions & 2 deletions spec/truffle/tags/core/string/gsub_tags.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
fails:String#gsub with pattern and replacement treats \+ as an empty string if there was no captures
fails:String#gsub with pattern and replacement replaces \k named backreferences with the regexp's corresponding capture
fails:String#gsub with pattern and Hash uses the hash's value set from default_proc for missing keys
fails:String#gsub! with pattern and Hash uses the hash's value set from default_proc for missing keys
fails:String#gsub with pattern and block sets $~ for access from the block
fails:String#gsub with pattern and block restores $~ after leaving the block
passes:String#gsub with pattern and block converts the block's return value to a string using to_s
6 changes: 0 additions & 6 deletions spec/truffle/tags/core/string/hex_tags.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1 @@
fails:String#hex treats leading characters of self as a string of hex digits
fails:String#hex does not accept a sequence of underscores as part of a number
fails:String#hex takes an optional sign
fails:String#hex takes an optional 0x
fails:String#hex requires that the sign is in front of the 0x if present
fails:String#hex returns 0 on error
fails:String#hex returns 0 if sequence begins with underscore
17 changes: 0 additions & 17 deletions spec/truffle/tags/core/string/oct_tags.txt

This file was deleted.

2 changes: 0 additions & 2 deletions spec/truffle/tags/core/string/sub_tags.txt
Original file line number Diff line number Diff line change
@@ -2,5 +2,3 @@ fails:String#sub with pattern, replacement treats \+ as an empty string if there
fails:String#sub with pattern and block sets $~ for access from the block
fails:String#sub! with pattern and block sets $~ for access from the block
fails:String#sub! with pattern and block raises a RuntimeError if the string is modified while substituting
fails:String#sub with pattern and Hash uses the hash's value set from default_proc for missing keys
fails:String#sub! with pattern and Hash uses the hash's value set from default_proc for missing keys
16 changes: 0 additions & 16 deletions spec/truffle/tags/core/string/to_i_tags.txt
Original file line number Diff line number Diff line change
@@ -1,20 +1,4 @@
fails:String#to_i returns 0 for strings with leading underscores
fails:String#to_i ignores underscores in between the digits
fails:String#to_i ignores leading whitespaces
fails:String#to_i ignores subsequent invalid characters
fails:String#to_i returns 0 if self is no valid integer-representation
fails:String#to_i interprets leading characters as a number in the given base
fails:String#to_i auto-detects base 8 via leading 0 when base = 0
fails:String#to_i auto-detects base 2 via 0b when base = 0
fails:String#to_i auto-detects base 10 via 0d when base = 0
fails:String#to_i auto-detects base 8 via 0o when base = 0
fails:String#to_i auto-detects base 16 via 0x when base = 0
fails:String#to_i auto-detects base 10 with no base specifier when base = 0
fails:String#to_i doesn't handle foreign base specifiers when base is > 0
fails:String#to_i tries to convert the base to an integer using to_int
fails:String#to_i requires that the sign if any appears before the base specifier
fails:String#to_i returns a Fixnum for long strings with trailing spaces
fails:String#to_i returns a Fixnum for long strings with leading spaces
fails:String#to_i with bases parses a String in base 2
fails:String#to_i with bases parses a String in base 3
fails:String#to_i with bases parses a String in base 4
1 change: 0 additions & 1 deletion spec/truffle/tags/core/string/to_r_tags.txt

This file was deleted.

Original file line number Diff line number Diff line change
@@ -57,6 +57,7 @@
import org.jruby.truffle.runtime.control.RaiseException;
import org.jruby.truffle.runtime.core.*;
import org.jruby.util.ByteList;
import org.jruby.util.ConvertBytes;
import org.jruby.util.StringSupport;

import java.util.Arrays;
@@ -544,4 +545,34 @@ public RubyString stringPattern(RubyClass stringClass, int size, RubyString stri

}

@RubiniusPrimitive(name = "string_to_inum")
public static abstract class StringToInumPrimitiveNode extends RubiniusPrimitiveNode {

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

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

@Specialization
public Object stringToInum(RubyString string, int fixBase, boolean strict) {
notDesignedForCompilation();

try {
final org.jruby.RubyInteger result = ConvertBytes.byteListToInum19(getContext().getRuntime(),
string.getBytes(),
fixBase,
strict);

return getContext().toTruffle(result);

} catch (org.jruby.exceptions.RaiseException e) {
throw new RaiseException(getContext().toTruffle(e.getException(), this));
}
}

}

}
13 changes: 11 additions & 2 deletions truffle/src/main/java/org/jruby/truffle/runtime/RubyContext.java
Original file line number Diff line number Diff line change
@@ -40,6 +40,7 @@
import org.jruby.util.cli.Options;

import java.io.File;
import java.math.BigInteger;
import java.util.Locale;
import java.util.Random;
import java.util.concurrent.atomic.AtomicLong;
@@ -377,12 +378,20 @@ public Object toTruffle(IRubyObject object) {
final long value = ((org.jruby.RubyFixnum) object).getLongValue();

if (value < Integer.MIN_VALUE || value > Integer.MAX_VALUE) {
throw new UnsupportedOperationException();
if (value < Long.MIN_VALUE || value > Long.MAX_VALUE) {
throw new UnsupportedOperationException();
}

return value;
}

return (int) value;
} else if (object instanceof org.jruby.RubyFloat) {
return ((org.jruby.RubyFloat) object).getDoubleValue();
} else if (object instanceof org.jruby.RubyBignum) {
final BigInteger value = ((org.jruby.RubyBignum) object).getBigIntegerValue();

return new RubyBignum(coreLibrary.getBignumClass(), value);
} else if (object instanceof org.jruby.RubyString) {
return toTruffle((org.jruby.RubyString) object);
} else if (object instanceof org.jruby.RubySymbol) {
@@ -400,7 +409,7 @@ public Object toTruffle(IRubyObject object) {
} else if (object instanceof org.jruby.RubyException) {
return toTruffle((org.jruby.RubyException) object, null);
} else {
throw object.getRuntime().newRuntimeError("cannot pass " + object.inspect() + " to Truffle");
throw object.getRuntime().newRuntimeError("cannot pass " + object.inspect() + " (" + object.getClass().getName() + ") to Truffle");
}
}

Original file line number Diff line number Diff line change
@@ -108,7 +108,7 @@ public RubyRootNode parse(RubyContext context, Source source, Encoding defaultEn
try {
node = (org.jruby.ast.RootNode) parser.parse(source.getName(), source.getCode().getBytes(StandardCharsets.UTF_8), new ManyVarsDynamicScope(staticScope), parserConfiguration);
} catch (org.jruby.exceptions.RaiseException e) {
String message = e.getException().message.asJavaString();
String message = e.getException().getMessage().asJavaString();

if (message == null) {
message = "(no message)";
31 changes: 31 additions & 0 deletions truffle/src/main/ruby/core/rubinius/common/string.rb
Original file line number Diff line number Diff line change
@@ -32,6 +32,22 @@ def include?(needle)
!!find_string(StringValue(needle), 0)
end

def oct
to_inum(-8, false)
end

# Treats leading characters from <i>self</i> as a string of hexadecimal digits
# (with an optional sign and an optional <code>0x</code>) and returns the
# corresponding number. Zero is returned on error.
#
# "0x0a".hex #=> 10
# "-1234".hex #=> -4660
# "0".hex #=> 0
# "wombat".hex #=> 0
def hex
to_inum(16, false)
end

def chars
if block_given?
each_char do |char|
@@ -85,6 +101,16 @@ def to_r
Rationalizer.new(self).convert
end

def to_i(base=10)
base = Rubinius::Type.coerce_to base, Integer, :to_int

if base < 0 || base == 1 || base > 36
raise ArgumentError, "illegal radix #{base}"
end

to_inum(base, false)
end

def each_line(sep=$/)
return to_enum(:each_line, sep) unless block_given?

@@ -613,6 +639,11 @@ def start_with?(*prefixes)
false
end

def to_inum(base, check)
Rubinius.primitive :string_to_inum
raise ArgumentError, "invalid value for Integer"
end

def self.try_convert(obj)
Rubinius::Type.try_convert obj, String, :to_str
end