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 Feb 10, 2015
2 parents 80340fe + 92e4062 commit 87b9356
Show file tree
Hide file tree
Showing 219 changed files with 4,859 additions and 1,625 deletions.
15 changes: 8 additions & 7 deletions COPYING
Expand Up @@ -105,13 +105,14 @@ lib/ruby/1.9, and lib/ruby/site_ruby/1.8/rubygems*.
The "yecht" library is Copyright (c) 2009-2011 Ola Bini, and released
under the MIT license.

The Rubinius API implementation in core/src/main/ruby/jruby/truffle/core/rubinius/api
and core/src/main/java/org/jruby/truffle/runtime/rubinius is copyright (c) 2011,
Evan Phoenix, and released under the 3-clause BSD license.

The Rubinius core library implementation in core/src/main/ruby/jruby/truffle/core/rubinius/kernel
is copyright (c) 2007-2014, Evan Phoenix and contributors, and released under
the 3-clause BSD license.
The Rubinius API implementation in truffle/src/main/ruby/core/rubinius/api
is copyright (c) 2011, Evan Phoenix, and released under the 3-clause BSD license.

The Rubinius core library implementation
in truffle/src/main/ruby/core/rubinius/bootstrap
and truffle/src/main/ruby/core/rubinius/common is
copyright (c) 2007-2014, Evan Phoenix and contributors,
and released under the 3-clause BSD license.

The complete text of the Eclipse Public License is as follows:

Expand Down
12 changes: 6 additions & 6 deletions antlib/extra.xml
Expand Up @@ -25,7 +25,7 @@ build jruby-complete.jar
<env key='GEM_PATH' value='lib/ruby/gems/shared'/>
<arg value='-Djruby.home=uri:classloader://META-INF/jruby.home'/>
<arg value='-cp'/>
<arg value='core/target/test-classes:test/target/test-classes:lib/jruby.jar:maven/jruby-stdlib/target/jruby-stdlib-1.7.19-SNAPSHOT.jar'/>
<arg value='core/target/test-classes:test/target/test-classes:lib/jruby.jar:maven/jruby-stdlib/target/jruby-stdlib-1.7.20-SNAPSHOT.jar'/>
<arg value='org.jruby.Main'/>
<arg value='-I.:test/externals/ruby1.9:test/externals/ruby1.9/ruby'/>
<arg value='-r./test/ruby19_env.rb'/>
Expand Down Expand Up @@ -137,7 +137,7 @@ build jruby-complete.jar
<env key='GEM_PATH' value='lib/ruby/gems/shared'/>
<arg value='-Djruby.home=uri:classloader://META-INF/jruby.home'/>
<arg value='-cp'/>
<arg value='core/target/test-classes:test/target/test-classes:maven/jruby-complete/target/jruby-complete-1.7.19-SNAPSHOT.jar'/>
<arg value='core/target/test-classes:test/target/test-classes:maven/jruby-complete/target/jruby-complete-1.7.20-SNAPSHOT.jar'/>
<arg value='org.jruby.Main'/>
<arg value='-I.:test/externals/ruby1.9:test/externals/ruby1.9/ruby'/>
<arg value='-r./test/ruby19_env.rb'/>
Expand All @@ -153,7 +153,7 @@ build jruby-complete.jar
<env key='GEM_PATH' value='lib/ruby/gems/shared'/>
<arg value='-Djruby.home=uri:classloader://META-INF/jruby.home'/>
<arg value='-cp'/>
<arg value='core/target/test-classes:test/target/test-classes:lib/jruby.jar:maven/jruby-stdlib/target/jruby-stdlib-1.7.19-SNAPSHOT.jar'/>
<arg value='core/target/test-classes:test/target/test-classes:lib/jruby.jar:maven/jruby-stdlib/target/jruby-stdlib-1.7.20-SNAPSHOT.jar'/>
<arg value='org.jruby.Main'/>
<arg value='-I.:test/externals/ruby1.9:test/externals/ruby1.9/ruby'/>
<arg value='-r./test/ruby19_env.rb'/>
Expand All @@ -169,7 +169,7 @@ build jruby-complete.jar
<env key='GEM_PATH' value='lib/ruby/gems/shared'/>
<arg value='-Djruby.home=uri:classloader://META-INF/jruby.home'/>
<arg value='-cp'/>
<arg value='core/target/test-classes:test/target/test-classes:lib/jruby.jar:maven/jruby-stdlib/target/jruby-stdlib-1.7.19-SNAPSHOT.jar'/>
<arg value='core/target/test-classes:test/target/test-classes:lib/jruby.jar:maven/jruby-stdlib/target/jruby-stdlib-1.7.20-SNAPSHOT.jar'/>
<arg value='org.jruby.Main'/>
<arg value='-I.:test/externals/ruby1.9:test/externals/ruby1.9/ruby'/>
<arg value='-r./test/ruby19_env.rb'/>
Expand Down Expand Up @@ -461,7 +461,7 @@ build jruby-complete.jar
<env key='GEM_PATH' value='lib/ruby/gems/shared'/>
<arg value='-Djruby.home=uri:classloader://META-INF/jruby.home'/>
<arg value='-cp'/>
<arg value='core/target/test-classes:test/target/test-classes:maven/jruby-complete/target/jruby-complete-1.7.19-SNAPSHOT.jar'/>
<arg value='core/target/test-classes:test/target/test-classes:maven/jruby-complete/target/jruby-complete-1.7.20-SNAPSHOT.jar'/>
<arg value='org.jruby.Main'/>
<arg value='-I.:test/externals/ruby1.9:test/externals/ruby1.9/ruby'/>
<arg value='-r./test/ruby19_env.rb'/>
Expand Down Expand Up @@ -515,4 +515,4 @@ build jruby-complete.jar
<!--arg value='-v'/-->
</exec>
</target>
<target description='test using jruby-complete or jruby-core/jruby-stdlib jars' name='test-jruby-jars' depends='mvn,test-jruby-jars-jruby.1.9,test-jruby-complete-slow,test-jruby-jars-objectspace,test-jruby-jars-mri.1.9,test-jruby-complete-rubicon.1.9'/></project>
<target description='test using jruby-complete or jruby-core/jruby-stdlib jars' name='test-jruby-jars' depends='mvn,test-jruby-jars-jruby.1.9,test-jruby-complete-slow,test-jruby-jars-objectspace,test-jruby-jars-mri.1.9,test-jruby-complete-rubicon.1.9'/></project>
28 changes: 18 additions & 10 deletions core/src/main/java/org/jruby/RubyDir.java
Expand Up @@ -178,6 +178,9 @@ private static IRubyObject asRubyStringList(Ruby runtime, List<ByteList> dirs) {
}

private static String getCWD(Ruby runtime) {
if (runtime.getCurrentDirectory().startsWith("uri:")) {
return runtime.getCurrentDirectory();
}
try {
return new org.jruby.util.NormalizedFile(runtime.getCurrentDirectory()).getCanonicalPath();
} catch (Exception e) {
Expand Down Expand Up @@ -297,17 +300,22 @@ public static IRubyObject chdir(ThreadContext context, IRubyObject recv, IRubyOb
RubyFile.get_path(context, args[0]) : getHomeDirectoryPath(context);
String adjustedPath = RubyFile.adjustRootPathOnWindows(runtime, path.asJavaString(), null);
checkDirIsTwoSlashesOnWindows(runtime, adjustedPath);
JRubyFile dir = getDir(runtime, adjustedPath, true);
String realPath;
String realPath = null;
String oldCwd = runtime.getCurrentDirectory();
if (adjustedPath.startsWith("uri:")){
realPath = adjustedPath;
}
else {
JRubyFile dir = getDir(runtime, adjustedPath, true);

// We get canonical path to try and flatten the path out.
// a dir '/subdir/..' should return as '/'
// cnutter: Do we want to flatten path out?
try {
realPath = dir.getCanonicalPath();
} catch (IOException e) {
realPath = dir.getAbsolutePath();
// We get canonical path to try and flatten the path out.
// a dir '/subdir/..' should return as '/'
// cnutter: Do we want to flatten path out?
try {
realPath = dir.getCanonicalPath();
} catch (IOException e) {
realPath = dir.getAbsolutePath();
}
}

IRubyObject result = null;
Expand All @@ -317,7 +325,7 @@ public static IRubyObject chdir(ThreadContext context, IRubyObject recv, IRubyOb
try {
result = block.yield(context, path);
} finally {
getDir(runtime, oldCwd, true); // ENEBO: Needed in case exception is thrown???
getDir(runtime, oldCwd, true); // needed in case the block deleted the oldCwd
runtime.setCurrentDirectory(oldCwd);
}
} else {
Expand Down
12 changes: 9 additions & 3 deletions core/src/main/java/org/jruby/RubyString.java
Expand Up @@ -5804,11 +5804,17 @@ public static ByteList encodeBytelist(CharSequence value, Encoding encoding) {
public Object toJava(Class target) {
if (target.isAssignableFrom(String.class)) {
return decodeString();
} else if (target.isAssignableFrom(ByteList.class)) {
}
if (target.isAssignableFrom(ByteList.class)) {
return value;
} else {
return super.toJava(target);
}
if (target == Character.class || target == Character.TYPE) {
if ( strLength() != 1 ) {
throw getRuntime().newArgumentError("could not coerce string of length " + strLength() + " (!= 1) into a char");
}
return decodeString().charAt(0);
}
return super.toJava(target);
}

/**
Expand Down
24 changes: 12 additions & 12 deletions core/src/main/java/org/jruby/RubyStruct.java
Expand Up @@ -547,37 +547,37 @@ public IRubyObject call(IRubyObject obj, boolean recur) {
private IRubyObject inspectStruct(final ThreadContext context, boolean recur) {
Ruby runtime = context.runtime;
RubyArray member = __member__();
ByteList buffer = new ByteList("#<struct ".getBytes());
RubyString buffer = RubyString.newString(getRuntime(), new ByteList("#<struct ".getBytes()));
String cpath = getMetaClass().getRealClass().getName();
char first = cpath.charAt(0);

if (recur || first != '#') {
buffer.append(cpath.getBytes());
buffer.append(' ');
buffer.cat(cpath.getBytes());
buffer.cat(' ');
}

if (recur) {
buffer.append(":...>".getBytes());
return runtime.newString(buffer);
buffer.cat(":...>".getBytes());
return buffer.dup();
}

for (int i = 0,k=member.getLength(); i < k; i++) {
if (i > 0) {
buffer.append(',').append(' ');
buffer.cat(',').cat(' ');
}
RubySymbol slot = (RubySymbol)member.eltInternal(i);
String name = slot.toString();
if (IdUtil.isLocal(name) || IdUtil.isConstant(name)) {
buffer.append(RubyString.objAsString(context, slot).getByteList());
buffer.cat19(RubyString.objAsString(context, slot));
} else {
buffer.append(((RubyString) slot.inspect(context)).getByteList());
buffer.cat19(((RubyString) slot.inspect(context)));
}
buffer.append('=');
buffer.append(inspect(context, values[i]).getByteList());
buffer.cat('=');
buffer.cat19(inspect(context, values[i]));
}

buffer.append('>');
return getRuntime().newString(buffer); // OBJ_INFECT
buffer.cat('>');
return buffer.dup(); // OBJ_INFECT
}

@JRubyMethod(name = {"inspect", "to_s"})
Expand Down
17 changes: 13 additions & 4 deletions core/src/main/java/org/jruby/ext/bigdecimal/RubyBigDecimal.java
Expand Up @@ -877,7 +877,7 @@ private IRubyObject op_quo19_20(ThreadContext context, IRubyObject other) {
int len = value.precision() + preciseOther.value.precision();
int pow = len / 4;
int precision = (pow + 1) * 4 * 2;

return op_div(context, preciseOther, getRuntime().newFixnum(precision));
}

Expand Down Expand Up @@ -929,9 +929,18 @@ public IRubyObject op_div(ThreadContext context, IRubyObject other, IRubyObject
// MRI behavior: "If digits is 0, the result is the same as the / operator."
if (scale == 0) return op_quo(context, other);

MathContext mathContext = new MathContext(scale, getRoundingMode(context.runtime));
return new RubyBigDecimal(context.runtime,
value.divide(val.value, mathContext)).setResult(scale);
if (isZero()) {
return newZero(getRuntime(), zeroSign * val.value.signum());
}

if (scale == 0) {
// MRI behavior: "If digits is 0, the result is the same as the / operator."
return op_quo(context, other);
} else {
MathContext mathContext = new MathContext(scale, getRoundingMode(context.runtime));
return new RubyBigDecimal(getRuntime(),
value.divide(val.value, mathContext)).setResult(scale);
}
}

@JRubyMethod(name = "div")
Expand Down
@@ -0,0 +1,81 @@
package org.jruby.internal.runtime.methods;

import java.util.ArrayList;
import java.util.List;
import org.jruby.RubyModule;
import org.jruby.ir.IRScope;
import org.jruby.ir.interpreter.InterpreterContext;
import org.jruby.ir.runtime.IRRuntimeHelpers;
import org.jruby.runtime.Block;
import org.jruby.runtime.ThreadContext;
import org.jruby.runtime.Visibility;
import org.jruby.runtime.builtin.IRubyObject;

/**
* Created by enebo on 2/6/15.
*/
public class InterpretedIRBodyMethod extends InterpretedIRMethod {
public InterpretedIRBodyMethod(IRScope method, RubyModule implementationClass) {
super(method, Visibility.PUBLIC, implementationClass);

this.box.callCount = -1;
}

@Override
public List<String[]> getParameterList() {
return new ArrayList<String[]>();
}

@Override
public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule clazz, String name, IRubyObject[] args, Block block) {
return call(context, self, clazz, name, block);
}

@Override
public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule clazz, String name, Block block) {
if (IRRuntimeHelpers.isDebug()) doDebug();

InterpreterContext ic = ensureInstrsReady();
return ic.engine.interpret(context, self, ic, getImplementationClass().getMethodLocation(), name, block, null);
}

@Override
public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule clazz, String name, IRubyObject arg0, Block block) {
return call(context, self, clazz, name, block);
}

@Override
public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule clazz, String name, IRubyObject arg0, IRubyObject arg1, Block block) {
return call(context, self, clazz, name, block);
}

@Override
public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule clazz, String name, IRubyObject arg0, IRubyObject arg1, IRubyObject arg2, Block block) {
return call(context, self, clazz, name, block);
}

@Override
public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule clazz, String name, IRubyObject[] args) {
return call(context, self, clazz, name, Block.NULL_BLOCK);
}

@Override
public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule clazz, String name) {
return call(context, self, clazz, name, Block.NULL_BLOCK);
}

@Override
public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule clazz, String name, IRubyObject arg0) {
return call(context, self, clazz, name, Block.NULL_BLOCK);
}

@Override
public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule clazz, String name, IRubyObject arg0, IRubyObject arg1) {
return call(context, self, clazz, name, Block.NULL_BLOCK);
}

@Override
public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule clazz, String name, IRubyObject arg0, IRubyObject arg1, IRubyObject arg2) {
return call(context, self, clazz, name, Block.NULL_BLOCK);
}
}
@@ -1,26 +1,17 @@
package org.jruby.internal.runtime.methods;

import java.util.ArrayList;
import java.util.List;

import org.jruby.RubyModule;
import org.jruby.ir.*;
import org.jruby.ir.interpreter.Interpreter;
import org.jruby.ir.IRScope;
import org.jruby.ir.interpreter.InterpreterContext;
import org.jruby.ir.runtime.IRRuntimeHelpers;
import org.jruby.runtime.Block;
import org.jruby.runtime.DynamicScope;
import org.jruby.runtime.ThreadContext;
import org.jruby.runtime.Visibility;
import org.jruby.runtime.builtin.IRubyObject;

public class InterpretedIRMetaClassBody extends InterpretedIRMethod {
public class InterpretedIRMetaClassBody extends InterpretedIRBodyMethod {
public InterpretedIRMetaClassBody(IRScope metaClassBody, RubyModule implementationClass) {
super(metaClassBody, Visibility.PUBLIC, implementationClass);
}

public List<String[]> getParameterList() {
return new ArrayList<String[]>();
super(metaClassBody, implementationClass);
}

protected void post(InterpreterContext ic, ThreadContext context) {
Expand All @@ -44,23 +35,23 @@ protected void pre(InterpreterContext ic, ThreadContext context, IRubyObject sel
}

@Override
public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule clazz, String name, IRubyObject[] args, Block block) {
public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule clazz, String name, Block block) {
DynamicMethodBox box = this.box;
if (box.callCount >= 0) tryJit(context, box);
DynamicMethod actualMethod = box.actualMethod;
if (actualMethod != null) return actualMethod.call(context, self, clazz, name, args, block);
if (actualMethod != null) return actualMethod.call(context, self, clazz, name, block);

InterpreterContext ic = ensureInstrsReady();

if (IRRuntimeHelpers.isDebug()) doDebug();

if (ic.hasExplicitCallProtocol()) {
return Interpreter.INTERPRET_METHOD(context, this, self, name, args, block);
return ic.engine.interpret(context, self, ic, getImplementationClass().getMethodLocation(), name, block, null);
} else {
try {
pre(ic, context, self, name, block);

return Interpreter.INTERPRET_METHOD(context, this, self, name, args, block);
return ic.engine.interpret(context, self, ic, getImplementationClass().getMethodLocation(), name, block, null);
} finally {
post(ic, context);
}
Expand Down

0 comments on commit 87b9356

Please sign in to comment.