Skip to content

Commit

Permalink
Merge branch 'master' into truffle-head
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisseaton committed Nov 19, 2014
2 parents 2517489 + a7a7d7f commit 506c427
Show file tree
Hide file tree
Showing 28 changed files with 318 additions and 88 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Expand Up @@ -49,6 +49,7 @@ matrix:
jdk: openjdk7
- env: TARGET='-Pj2ee'
jdk: oraclejdk7
- script: test/check_versions.sh
fast_finish: true
allow_failures:
- env: TARGET='-Pcomplete'
Expand Down
2 changes: 1 addition & 1 deletion VERSION
@@ -1 +1 @@
9.0.0.0.dev-SNAPSHOT
9.0.0.0-SNAPSHOT
2 changes: 1 addition & 1 deletion core/pom.xml
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>org.jruby</groupId>
<artifactId>jruby-parent</artifactId>
<version>9.0.0.0.dev-SNAPSHOT</version>
<version>9.0.0.0-SNAPSHOT</version>
</parent>
<artifactId>jruby-core</artifactId>
<name>JRuby Core</name>
Expand Down
6 changes: 4 additions & 2 deletions core/src/main/java/org/jruby/RubyFileStat.java
Expand Up @@ -122,15 +122,17 @@ private void setup(int fileno) {
}

private void setup(String filename, boolean lstat) {
Ruby runtime = getRuntime();

if (Platform.IS_WINDOWS && filename.length() == 2
&& filename.charAt(1) == ':' && Character.isLetter(filename.charAt(0))) {
filename += "/";
}

file = JRubyFile.createResource(getRuntime().getPosix(), getRuntime().getCurrentDirectory(), filename);
file = JRubyFile.createResource(runtime.getPosix(), runtime.getCurrentDirectory(), filename);
stat = lstat ? file.lstat() : file.stat();

if (stat == null) throw getRuntime().newErrnoFromInt(getRuntime().getPosix().errno());
if (stat == null) throw runtime.newErrnoFromInt(runtime.getPosix().errno(), filename);
}

public IRubyObject initialize(IRubyObject fname, Block unusedBlock) {
Expand Down
6 changes: 1 addition & 5 deletions core/src/main/java/org/jruby/RubyModule.java
Expand Up @@ -1190,11 +1190,7 @@ public DynamicMethod searchMethodInner(String name) {

// The local method resolution logic. Overridden in IncludedModuleWrapper for recursion.
protected DynamicMethod searchMethodCommon(String name) {
DynamicMethod method = getMethods().get(name);

if (method != null) return method;

return superClass == null ? null : superClass.searchMethodInner(name);
return getMethods().get(name);
}

public void invalidateCacheDescendants() {
Expand Down
24 changes: 16 additions & 8 deletions core/src/main/java/org/jruby/RubyTime.java
Expand Up @@ -46,6 +46,7 @@
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.jcodings.specific.USASCIIEncoding;
import org.joda.time.DateTime;
import org.joda.time.DateTimeZone;
import org.joda.time.format.DateTimeFormat;
Expand Down Expand Up @@ -92,10 +93,10 @@ public class RubyTime extends RubyObject {
// the legacy TZ format in order to convert it to the newer format
// understood by Java API.
private static final Pattern TZ_PATTERN
= Pattern.compile("([^-\\+\\d]+)?([\\+-]?)(\\d+)(?::(\\d+))?(?::\\d+)?");
= Pattern.compile("([^-\\+\\d]+)?([\\+-]?)(\\d+)(?::(\\d+))?(?::(\\d+))?");

private static final Pattern TIME_OFFSET_PATTERN
= Pattern.compile("([\\+-])(\\d\\d):(\\d\\d)");
= Pattern.compile("([\\+-])(\\d\\d):(\\d\\d)(?::(\\d\\d))?");

private static final ByteList TZ_STRING = ByteList.create("TZ");

Expand Down Expand Up @@ -169,13 +170,14 @@ private static DateTimeZone parseTZString(Ruby runtime, String zone) {
String sign = tzMatcher.group(2);
String hours = tzMatcher.group(3);
String minutes = tzMatcher.group(4);
String seconds= tzMatcher.group(5);

if (zoneName == null) {
zoneName = "";
}

// Sign is reversed in legacy TZ notation
return getTimeZoneFromHHMM(runtime, zoneName, sign.equals("-"), hours, minutes);
return getTimeZoneFromHHMM(runtime, zoneName, sign.equals("-"), hours, minutes, seconds);
} else {
if (LONG_TZNAME.containsKey(upZone)) {
zone = LONG_TZNAME.get(upZone);
Expand Down Expand Up @@ -228,7 +230,8 @@ public static DateTimeZone getTimeZoneFromUtcOffset(Ruby runtime, IRubyObject ut
String sign = offsetMatcher.group(1);
String hours = offsetMatcher.group(2);
String minutes = offsetMatcher.group(3);
dtz = getTimeZoneFromHHMM(runtime, "", !sign.equals("-"), hours, minutes);
String seconds = offsetMatcher.group(4);
dtz = getTimeZoneFromHHMM(runtime, "", !sign.equals("-"), hours, minutes, seconds);
} else {
IRubyObject numericOffset = numExact(runtime, utcOffset);
int newOffset = (int)Math.round(numericOffset.convertToFloat().getDoubleValue() * 1000);
Expand Down Expand Up @@ -292,18 +295,23 @@ private static void exactTypeError(Ruby runtime, IRubyObject received) {
String.format("Can't convert %s into an exact number", received.getMetaClass().getRealClass()));
}

private static DateTimeZone getTimeZoneFromHHMM(Ruby runtime, String name, boolean positive, String hours, String minutes) {
private static DateTimeZone getTimeZoneFromHHMM(Ruby runtime, String name, boolean positive, String hours, String minutes, String seconds) {
int h = Integer.parseInt(hours);
int m = 0;
int s = 0;
if (minutes != null) {
m = Integer.parseInt(minutes);
}

if (seconds != null) {
s = Integer.parseInt(seconds);
}

if (h > 23 || m > 59) {
throw runtime.newArgumentError("utc_offset out of range");
}

int offset = (positive ? +1 : -1) * ((h * 60) + m) * 60 * 1000;
int offset = (positive ? +1 : -1) * ((h * 3600) + m * 60 + s) * 1000;
return timeZoneWithOffset(name, offset);
}

Expand Down Expand Up @@ -683,7 +691,7 @@ public RubyString asctime() {
simpleDateFormat = TWO_DAY_CTIME_FORMATTER;
}
String result = simpleDateFormat.print(dt);
return getRuntime().newString(result);
return RubyString.newString(getRuntime(), result, USASCIIEncoding.INSTANCE);
}

@Override
Expand Down Expand Up @@ -716,7 +724,7 @@ private IRubyObject inspectCommon(DateTimeFormatter formatter, DateTimeFormatter
result = simpleDateFormat.print(invertedDT);
}

return getRuntime().newString(result);
return RubyString.newString(getRuntime(), result, USASCIIEncoding.INSTANCE);
}

@JRubyMethod
Expand Down
67 changes: 60 additions & 7 deletions core/src/main/java/org/jruby/truffle/nodes/core/ArrayNodes.java
Expand Up @@ -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)
Expand Down Expand Up @@ -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();
Expand Down
17 changes: 17 additions & 0 deletions core/src/main/java/org/jruby/truffle/nodes/core/FloatNodes.java
Expand Up @@ -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 {

Expand Down
Expand Up @@ -1829,6 +1829,11 @@ public RubyNode visitPreExeNode(PreExeNode node) {
return node.getBodyNode().accept(this);
}

@Override
public RubyNode visitPostExeNode(PostExeNode node) {
return node.getBodyNode().accept(this);
}

@Override
public RubyNode visitRedoNode(org.jruby.ast.RedoNode node) {
return new RedoNode(context, translate(node.getPosition()));
Expand Down
15 changes: 5 additions & 10 deletions core/src/main/java/org/jruby/util/RubyDateFormatter.java
Expand Up @@ -619,16 +619,11 @@ private String formatZone(int colons, int value, RubyTimeOutputFormatter formatt
after = ":" + mm + ":" + ss;
break;
case 3: // %:::z -> +hh[:mm[:ss]]
if (minutes == 0) {
if (seconds == 0) { // +hh
defaultWidth = 3;
after = "";
} else { // +hh:mm
return formatZone(1, value, formatter);
}
} else { // +hh:mm:ss
return formatZone(2, value, formatter);
}
StringBuilder sb = new StringBuilder();
if (minutes != 0 || seconds != 0) sb.append(":").append(mm);
if (seconds != 0) sb.append(":").append(ss);
after = sb.toString();
defaultWidth = after.length() + 3;
break;
}

Expand Down
4 changes: 2 additions & 2 deletions lib/pom.xml
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>org.jruby</groupId>
<artifactId>jruby-parent</artifactId>
<version>9.0.0.0.dev-SNAPSHOT</version>
<version>9.0.0.0-SNAPSHOT</version>
</parent>
<artifactId>jruby-lib</artifactId>
<packaging>pom</packaging>
Expand All @@ -20,7 +20,7 @@
<dependency>
<groupId>org.jruby</groupId>
<artifactId>jruby-core</artifactId>
<version>9.0.0.0.dev-SNAPSHOT</version>
<version>9.0.0.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>rubygems</groupId>
Expand Down
2 changes: 1 addition & 1 deletion maven/jruby-complete/pom.xml
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>org.jruby</groupId>
<artifactId>jruby-artifacts</artifactId>
<version>9.0.0.0.dev-SNAPSHOT</version>
<version>9.0.0.0-SNAPSHOT</version>
</parent>
<artifactId>jruby-complete</artifactId>
<packaging>bundle</packaging>
Expand Down
6 changes: 1 addition & 5 deletions maven/jruby-dist/pom.rb
Expand Up @@ -79,10 +79,6 @@

plugin( :invoker )

build do
final_name "#{model.artifact_id}-#{version.sub(/-SNAPSHOT/, '')}"
end

# for the release we do some extra IT by unzipping a source dist file
# and run the $ mvn -Pall from there and check a few things to be in place.
# add check for SNAPSHOT version in any of the modules !!!!
Expand Down Expand Up @@ -136,7 +132,7 @@

revision = `git show`.gsub( /\n.*|commit /, '' )

basefile = "#{ctx.project.build.directory}/#{ctx.project.artifactId}-#{ctx.project.version}-src".sub(/-SNAPSHOT/, '')
basefile = "#{ctx.project.build.directory}/#{ctx.project.artifactId}-#{ctx.project.version}-src"

FileUtils.cd( File.join( ctx.project.basedir.to_s, '..', '..' ) ) do
[ 'tar', 'zip' ].each do |format|
Expand Down
3 changes: 1 addition & 2 deletions maven/jruby-dist/pom.xml
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>org.jruby</groupId>
<artifactId>jruby-artifacts</artifactId>
<version>9.0.0.0.dev-SNAPSHOT</version>
<version>9.0.0.0-SNAPSHOT</version>
</parent>
<artifactId>jruby-dist</artifactId>
<packaging>pom</packaging>
Expand All @@ -27,7 +27,6 @@
</dependency>
</dependencies>
<build>
<finalName>jruby-dist-9.0.0.0.dev</finalName>
<plugins>
<plugin>
<groupId>de.saumya.mojo</groupId>
Expand Down
2 changes: 1 addition & 1 deletion maven/jruby-jars/jruby-jars.gemspec
Expand Up @@ -7,7 +7,7 @@ require 'rexml/xpath'
version = File.read( File.join( File.dirname(File.expand_path(__FILE__)), '..', '..', 'VERSION' ) ).strip

# this regexp can be refined to work with pre, rc1, rc2 and such cases
ruby_version = version.sub( /-SNAPSHOT$/, '.dev' ).sub( /.dev.dev/, '.dev' )
ruby_version = version.sub( /-SNAPSHOT$/, '.snapshot' )

File.open( 'lib/jruby-jars/version.rb', 'w' ) do |f|
f.print <<EOF
Expand Down

0 comments on commit 506c427

Please sign in to comment.