Skip to content

Commit 87b9356

Browse files
committed
Merge branch 'master' into truffle-head
2 parents 80340fe + 92e4062 commit 87b9356

File tree

219 files changed

+4859
-1625
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

219 files changed

+4859
-1625
lines changed

COPYING

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -105,13 +105,14 @@ lib/ruby/1.9, and lib/ruby/site_ruby/1.8/rubygems*.
105105
The "yecht" library is Copyright (c) 2009-2011 Ola Bini, and released
106106
under the MIT license.
107107

108-
The Rubinius API implementation in core/src/main/ruby/jruby/truffle/core/rubinius/api
109-
and core/src/main/java/org/jruby/truffle/runtime/rubinius is copyright (c) 2011,
110-
Evan Phoenix, and released under the 3-clause BSD license.
111-
112-
The Rubinius core library implementation in core/src/main/ruby/jruby/truffle/core/rubinius/kernel
113-
is copyright (c) 2007-2014, Evan Phoenix and contributors, and released under
114-
the 3-clause BSD license.
108+
The Rubinius API implementation in truffle/src/main/ruby/core/rubinius/api
109+
is copyright (c) 2011, Evan Phoenix, and released under the 3-clause BSD license.
110+
111+
The Rubinius core library implementation
112+
in truffle/src/main/ruby/core/rubinius/bootstrap
113+
and truffle/src/main/ruby/core/rubinius/common is
114+
copyright (c) 2007-2014, Evan Phoenix and contributors,
115+
and released under the 3-clause BSD license.
115116

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

antlib/extra.xml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ build jruby-complete.jar
2525
<env key='GEM_PATH' value='lib/ruby/gems/shared'/>
2626
<arg value='-Djruby.home=uri:classloader://META-INF/jruby.home'/>
2727
<arg value='-cp'/>
28-
<arg value='core/target/test-classes:test/target/test-classes:lib/jruby.jar:maven/jruby-stdlib/target/jruby-stdlib-1.7.19-SNAPSHOT.jar'/>
28+
<arg value='core/target/test-classes:test/target/test-classes:lib/jruby.jar:maven/jruby-stdlib/target/jruby-stdlib-1.7.20-SNAPSHOT.jar'/>
2929
<arg value='org.jruby.Main'/>
3030
<arg value='-I.:test/externals/ruby1.9:test/externals/ruby1.9/ruby'/>
3131
<arg value='-r./test/ruby19_env.rb'/>
@@ -137,7 +137,7 @@ build jruby-complete.jar
137137
<env key='GEM_PATH' value='lib/ruby/gems/shared'/>
138138
<arg value='-Djruby.home=uri:classloader://META-INF/jruby.home'/>
139139
<arg value='-cp'/>
140-
<arg value='core/target/test-classes:test/target/test-classes:maven/jruby-complete/target/jruby-complete-1.7.19-SNAPSHOT.jar'/>
140+
<arg value='core/target/test-classes:test/target/test-classes:maven/jruby-complete/target/jruby-complete-1.7.20-SNAPSHOT.jar'/>
141141
<arg value='org.jruby.Main'/>
142142
<arg value='-I.:test/externals/ruby1.9:test/externals/ruby1.9/ruby'/>
143143
<arg value='-r./test/ruby19_env.rb'/>
@@ -153,7 +153,7 @@ build jruby-complete.jar
153153
<env key='GEM_PATH' value='lib/ruby/gems/shared'/>
154154
<arg value='-Djruby.home=uri:classloader://META-INF/jruby.home'/>
155155
<arg value='-cp'/>
156-
<arg value='core/target/test-classes:test/target/test-classes:lib/jruby.jar:maven/jruby-stdlib/target/jruby-stdlib-1.7.19-SNAPSHOT.jar'/>
156+
<arg value='core/target/test-classes:test/target/test-classes:lib/jruby.jar:maven/jruby-stdlib/target/jruby-stdlib-1.7.20-SNAPSHOT.jar'/>
157157
<arg value='org.jruby.Main'/>
158158
<arg value='-I.:test/externals/ruby1.9:test/externals/ruby1.9/ruby'/>
159159
<arg value='-r./test/ruby19_env.rb'/>
@@ -169,7 +169,7 @@ build jruby-complete.jar
169169
<env key='GEM_PATH' value='lib/ruby/gems/shared'/>
170170
<arg value='-Djruby.home=uri:classloader://META-INF/jruby.home'/>
171171
<arg value='-cp'/>
172-
<arg value='core/target/test-classes:test/target/test-classes:lib/jruby.jar:maven/jruby-stdlib/target/jruby-stdlib-1.7.19-SNAPSHOT.jar'/>
172+
<arg value='core/target/test-classes:test/target/test-classes:lib/jruby.jar:maven/jruby-stdlib/target/jruby-stdlib-1.7.20-SNAPSHOT.jar'/>
173173
<arg value='org.jruby.Main'/>
174174
<arg value='-I.:test/externals/ruby1.9:test/externals/ruby1.9/ruby'/>
175175
<arg value='-r./test/ruby19_env.rb'/>
@@ -461,7 +461,7 @@ build jruby-complete.jar
461461
<env key='GEM_PATH' value='lib/ruby/gems/shared'/>
462462
<arg value='-Djruby.home=uri:classloader://META-INF/jruby.home'/>
463463
<arg value='-cp'/>
464-
<arg value='core/target/test-classes:test/target/test-classes:maven/jruby-complete/target/jruby-complete-1.7.19-SNAPSHOT.jar'/>
464+
<arg value='core/target/test-classes:test/target/test-classes:maven/jruby-complete/target/jruby-complete-1.7.20-SNAPSHOT.jar'/>
465465
<arg value='org.jruby.Main'/>
466466
<arg value='-I.:test/externals/ruby1.9:test/externals/ruby1.9/ruby'/>
467467
<arg value='-r./test/ruby19_env.rb'/>
@@ -515,4 +515,4 @@ build jruby-complete.jar
515515
<!--arg value='-v'/-->
516516
</exec>
517517
</target>
518-
<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>
518+
<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>

core/src/main/java/org/jruby/RubyDir.java

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,9 @@ private static IRubyObject asRubyStringList(Ruby runtime, List<ByteList> dirs) {
178178
}
179179

180180
private static String getCWD(Ruby runtime) {
181+
if (runtime.getCurrentDirectory().startsWith("uri:")) {
182+
return runtime.getCurrentDirectory();
183+
}
181184
try {
182185
return new org.jruby.util.NormalizedFile(runtime.getCurrentDirectory()).getCanonicalPath();
183186
} catch (Exception e) {
@@ -297,17 +300,22 @@ public static IRubyObject chdir(ThreadContext context, IRubyObject recv, IRubyOb
297300
RubyFile.get_path(context, args[0]) : getHomeDirectoryPath(context);
298301
String adjustedPath = RubyFile.adjustRootPathOnWindows(runtime, path.asJavaString(), null);
299302
checkDirIsTwoSlashesOnWindows(runtime, adjustedPath);
300-
JRubyFile dir = getDir(runtime, adjustedPath, true);
301-
String realPath;
303+
String realPath = null;
302304
String oldCwd = runtime.getCurrentDirectory();
305+
if (adjustedPath.startsWith("uri:")){
306+
realPath = adjustedPath;
307+
}
308+
else {
309+
JRubyFile dir = getDir(runtime, adjustedPath, true);
303310

304-
// We get canonical path to try and flatten the path out.
305-
// a dir '/subdir/..' should return as '/'
306-
// cnutter: Do we want to flatten path out?
307-
try {
308-
realPath = dir.getCanonicalPath();
309-
} catch (IOException e) {
310-
realPath = dir.getAbsolutePath();
311+
// We get canonical path to try and flatten the path out.
312+
// a dir '/subdir/..' should return as '/'
313+
// cnutter: Do we want to flatten path out?
314+
try {
315+
realPath = dir.getCanonicalPath();
316+
} catch (IOException e) {
317+
realPath = dir.getAbsolutePath();
318+
}
311319
}
312320

313321
IRubyObject result = null;
@@ -317,7 +325,7 @@ public static IRubyObject chdir(ThreadContext context, IRubyObject recv, IRubyOb
317325
try {
318326
result = block.yield(context, path);
319327
} finally {
320-
getDir(runtime, oldCwd, true); // ENEBO: Needed in case exception is thrown???
328+
getDir(runtime, oldCwd, true); // needed in case the block deleted the oldCwd
321329
runtime.setCurrentDirectory(oldCwd);
322330
}
323331
} else {

core/src/main/java/org/jruby/RubyString.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5804,11 +5804,17 @@ public static ByteList encodeBytelist(CharSequence value, Encoding encoding) {
58045804
public Object toJava(Class target) {
58055805
if (target.isAssignableFrom(String.class)) {
58065806
return decodeString();
5807-
} else if (target.isAssignableFrom(ByteList.class)) {
5807+
}
5808+
if (target.isAssignableFrom(ByteList.class)) {
58085809
return value;
5809-
} else {
5810-
return super.toJava(target);
58115810
}
5811+
if (target == Character.class || target == Character.TYPE) {
5812+
if ( strLength() != 1 ) {
5813+
throw getRuntime().newArgumentError("could not coerce string of length " + strLength() + " (!= 1) into a char");
5814+
}
5815+
return decodeString().charAt(0);
5816+
}
5817+
return super.toJava(target);
58125818
}
58135819

58145820
/**

core/src/main/java/org/jruby/RubyStruct.java

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -547,37 +547,37 @@ public IRubyObject call(IRubyObject obj, boolean recur) {
547547
private IRubyObject inspectStruct(final ThreadContext context, boolean recur) {
548548
Ruby runtime = context.runtime;
549549
RubyArray member = __member__();
550-
ByteList buffer = new ByteList("#<struct ".getBytes());
550+
RubyString buffer = RubyString.newString(getRuntime(), new ByteList("#<struct ".getBytes()));
551551
String cpath = getMetaClass().getRealClass().getName();
552552
char first = cpath.charAt(0);
553553

554554
if (recur || first != '#') {
555-
buffer.append(cpath.getBytes());
556-
buffer.append(' ');
555+
buffer.cat(cpath.getBytes());
556+
buffer.cat(' ');
557557
}
558558

559559
if (recur) {
560-
buffer.append(":...>".getBytes());
561-
return runtime.newString(buffer);
560+
buffer.cat(":...>".getBytes());
561+
return buffer.dup();
562562
}
563563

564564
for (int i = 0,k=member.getLength(); i < k; i++) {
565565
if (i > 0) {
566-
buffer.append(',').append(' ');
566+
buffer.cat(',').cat(' ');
567567
}
568568
RubySymbol slot = (RubySymbol)member.eltInternal(i);
569569
String name = slot.toString();
570570
if (IdUtil.isLocal(name) || IdUtil.isConstant(name)) {
571-
buffer.append(RubyString.objAsString(context, slot).getByteList());
571+
buffer.cat19(RubyString.objAsString(context, slot));
572572
} else {
573-
buffer.append(((RubyString) slot.inspect(context)).getByteList());
573+
buffer.cat19(((RubyString) slot.inspect(context)));
574574
}
575-
buffer.append('=');
576-
buffer.append(inspect(context, values[i]).getByteList());
575+
buffer.cat('=');
576+
buffer.cat19(inspect(context, values[i]));
577577
}
578578

579-
buffer.append('>');
580-
return getRuntime().newString(buffer); // OBJ_INFECT
579+
buffer.cat('>');
580+
return buffer.dup(); // OBJ_INFECT
581581
}
582582

583583
@JRubyMethod(name = {"inspect", "to_s"})

core/src/main/java/org/jruby/ext/bigdecimal/RubyBigDecimal.java

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -877,7 +877,7 @@ private IRubyObject op_quo19_20(ThreadContext context, IRubyObject other) {
877877
int len = value.precision() + preciseOther.value.precision();
878878
int pow = len / 4;
879879
int precision = (pow + 1) * 4 * 2;
880-
880+
881881
return op_div(context, preciseOther, getRuntime().newFixnum(precision));
882882
}
883883

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

932-
MathContext mathContext = new MathContext(scale, getRoundingMode(context.runtime));
933-
return new RubyBigDecimal(context.runtime,
934-
value.divide(val.value, mathContext)).setResult(scale);
932+
if (isZero()) {
933+
return newZero(getRuntime(), zeroSign * val.value.signum());
934+
}
935+
936+
if (scale == 0) {
937+
// MRI behavior: "If digits is 0, the result is the same as the / operator."
938+
return op_quo(context, other);
939+
} else {
940+
MathContext mathContext = new MathContext(scale, getRoundingMode(context.runtime));
941+
return new RubyBigDecimal(getRuntime(),
942+
value.divide(val.value, mathContext)).setResult(scale);
943+
}
935944
}
936945

937946
@JRubyMethod(name = "div")
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
package org.jruby.internal.runtime.methods;
2+
3+
import java.util.ArrayList;
4+
import java.util.List;
5+
import org.jruby.RubyModule;
6+
import org.jruby.ir.IRScope;
7+
import org.jruby.ir.interpreter.InterpreterContext;
8+
import org.jruby.ir.runtime.IRRuntimeHelpers;
9+
import org.jruby.runtime.Block;
10+
import org.jruby.runtime.ThreadContext;
11+
import org.jruby.runtime.Visibility;
12+
import org.jruby.runtime.builtin.IRubyObject;
13+
14+
/**
15+
* Created by enebo on 2/6/15.
16+
*/
17+
public class InterpretedIRBodyMethod extends InterpretedIRMethod {
18+
public InterpretedIRBodyMethod(IRScope method, RubyModule implementationClass) {
19+
super(method, Visibility.PUBLIC, implementationClass);
20+
21+
this.box.callCount = -1;
22+
}
23+
24+
@Override
25+
public List<String[]> getParameterList() {
26+
return new ArrayList<String[]>();
27+
}
28+
29+
@Override
30+
public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule clazz, String name, IRubyObject[] args, Block block) {
31+
return call(context, self, clazz, name, block);
32+
}
33+
34+
@Override
35+
public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule clazz, String name, Block block) {
36+
if (IRRuntimeHelpers.isDebug()) doDebug();
37+
38+
InterpreterContext ic = ensureInstrsReady();
39+
return ic.engine.interpret(context, self, ic, getImplementationClass().getMethodLocation(), name, block, null);
40+
}
41+
42+
@Override
43+
public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule clazz, String name, IRubyObject arg0, Block block) {
44+
return call(context, self, clazz, name, block);
45+
}
46+
47+
@Override
48+
public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule clazz, String name, IRubyObject arg0, IRubyObject arg1, Block block) {
49+
return call(context, self, clazz, name, block);
50+
}
51+
52+
@Override
53+
public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule clazz, String name, IRubyObject arg0, IRubyObject arg1, IRubyObject arg2, Block block) {
54+
return call(context, self, clazz, name, block);
55+
}
56+
57+
@Override
58+
public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule clazz, String name, IRubyObject[] args) {
59+
return call(context, self, clazz, name, Block.NULL_BLOCK);
60+
}
61+
62+
@Override
63+
public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule clazz, String name) {
64+
return call(context, self, clazz, name, Block.NULL_BLOCK);
65+
}
66+
67+
@Override
68+
public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule clazz, String name, IRubyObject arg0) {
69+
return call(context, self, clazz, name, Block.NULL_BLOCK);
70+
}
71+
72+
@Override
73+
public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule clazz, String name, IRubyObject arg0, IRubyObject arg1) {
74+
return call(context, self, clazz, name, Block.NULL_BLOCK);
75+
}
76+
77+
@Override
78+
public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule clazz, String name, IRubyObject arg0, IRubyObject arg1, IRubyObject arg2) {
79+
return call(context, self, clazz, name, Block.NULL_BLOCK);
80+
}
81+
}

core/src/main/java/org/jruby/internal/runtime/methods/InterpretedIRMetaClassBody.java

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,17 @@
11
package org.jruby.internal.runtime.methods;
22

3-
import java.util.ArrayList;
4-
import java.util.List;
5-
63
import org.jruby.RubyModule;
7-
import org.jruby.ir.*;
8-
import org.jruby.ir.interpreter.Interpreter;
4+
import org.jruby.ir.IRScope;
95
import org.jruby.ir.interpreter.InterpreterContext;
106
import org.jruby.ir.runtime.IRRuntimeHelpers;
117
import org.jruby.runtime.Block;
128
import org.jruby.runtime.DynamicScope;
139
import org.jruby.runtime.ThreadContext;
14-
import org.jruby.runtime.Visibility;
1510
import org.jruby.runtime.builtin.IRubyObject;
1611

17-
public class InterpretedIRMetaClassBody extends InterpretedIRMethod {
12+
public class InterpretedIRMetaClassBody extends InterpretedIRBodyMethod {
1813
public InterpretedIRMetaClassBody(IRScope metaClassBody, RubyModule implementationClass) {
19-
super(metaClassBody, Visibility.PUBLIC, implementationClass);
20-
}
21-
22-
public List<String[]> getParameterList() {
23-
return new ArrayList<String[]>();
14+
super(metaClassBody, implementationClass);
2415
}
2516

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

4637
@Override
47-
public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule clazz, String name, IRubyObject[] args, Block block) {
38+
public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule clazz, String name, Block block) {
4839
DynamicMethodBox box = this.box;
4940
if (box.callCount >= 0) tryJit(context, box);
5041
DynamicMethod actualMethod = box.actualMethod;
51-
if (actualMethod != null) return actualMethod.call(context, self, clazz, name, args, block);
42+
if (actualMethod != null) return actualMethod.call(context, self, clazz, name, block);
5243

5344
InterpreterContext ic = ensureInstrsReady();
5445

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

5748
if (ic.hasExplicitCallProtocol()) {
58-
return Interpreter.INTERPRET_METHOD(context, this, self, name, args, block);
49+
return ic.engine.interpret(context, self, ic, getImplementationClass().getMethodLocation(), name, block, null);
5950
} else {
6051
try {
6152
pre(ic, context, self, name, block);
6253

63-
return Interpreter.INTERPRET_METHOD(context, this, self, name, args, block);
54+
return ic.engine.interpret(context, self, ic, getImplementationClass().getMethodLocation(), name, block, null);
6455
} finally {
6556
post(ic, context);
6657
}

0 commit comments

Comments
 (0)