Skip to content

Commit

Permalink
Merge with latest master
Browse files Browse the repository at this point in the history
  • Loading branch information
enebo committed Mar 8, 2015
2 parents 089deb6 + 9dfb4fb commit 719d996
Show file tree
Hide file tree
Showing 82 changed files with 332 additions and 389 deletions.
6 changes: 4 additions & 2 deletions .travis.yml
Expand Up @@ -25,6 +25,7 @@ env:
- PHASE='-Ptest'
- PHASE='-Prake -Dtask=test:jruby'
- PHASE='-Prake -Dtask=test:mri'
- PHASE='-Prake -Dtask=test:mri:jit'
- PHASE='-Prake -Dtask=test:slow_suites'
- PHASE='-Prake -Dtask=test:tracing'
- PHASE='-Prake -Dtask=spec:ji'
Expand Down Expand Up @@ -62,14 +63,15 @@ matrix:
jdk: oraclejdk8
- env: COMMAND=test/check_versions.sh
jdk: oraclejdk8
- env: COMMAND=tool/truffle-findbugs.sh
jdk: oraclejdk8
fast_finish: true
allow_failures:
- env: PHASE='-Pcomplete'
- env: PHASE='-Pmain'
- env: PHASE='-Prake -Dtask=spec:jrubyc'
- env: PHASE='-Prake -Dtask=spec:profiler'
- env: COMMAND=tool/truffle-findbugs.sh
jdk: oraclejdk8
- env: PHASE='-Prake -Dtask=test:mri:jit'

branches:
only:
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/org/jruby/RubyComparable.java
Expand Up @@ -145,8 +145,8 @@ private static IRubyObject callCmpMethod(ThreadContext context, IRubyObject recv

return RubyBoolean.newBoolean(runtime, cmpint(context, result, recv, other) == 0);
} catch (RaiseException e) {
cmpFailed(context);
if (e.getException().kind_of_p(context, runtime.getStandardError()).isTrue()) {
cmpFailed(context);
// clear error info resulting from failure to compare (JRUBY-3292)
runtime.getGlobalVariables().set("$!", savedError);
return returnValueOnError;
Expand Down
38 changes: 29 additions & 9 deletions core/src/main/java/org/jruby/RubyNumeric.java
Expand Up @@ -459,20 +459,32 @@ protected final IRubyObject coerceBody(ThreadContext context, IRubyObject other)
*
*/
protected final RubyArray doCoerce(ThreadContext context, IRubyObject other, boolean err) {
Ruby runtime = context.runtime;
IRubyObject result;

IRubyObject savedError = context.runtime.getGlobalVariables().get("$!"); // Svae $!
IRubyObject savedError = runtime.getGlobalVariables().get("$!"); // Svae $!

if (!other.respondsTo("coerce")) {
if (err) {
coerceRescue(context, other);
}
return null;
}
try {
result = coerceBody(context, other);
} catch (RaiseException e) {
RubyWarnings warnings = context.runtime.getWarnings();
warnings.warn("Numerical comparison operators will no more rescue exceptions of #coerce");
warnings.warn("in the next release. Return nil in #coerce if the coercion is impossible.");
if (err) {
coerceFailed(context, other);
if (e.getException().kind_of_p(context, runtime.getStandardError()).isTrue()) {
RubyWarnings warnings = context.runtime.getWarnings();
warnings.warn("Numerical comparison operators will no more rescue exceptions of #coerce");
warnings.warn("in the next release. Return nil in #coerce if the coercion is impossible.");
if (err) {
coerceFailed(context, other);
}
context.runtime.getGlobalVariables().set("$!", savedError); // Restore $!
return null;
} else {
throw e;
}
context.runtime.getGlobalVariables().set("$!", savedError); // Restore $!
return null;
}

if (!(result instanceof RubyArray) || ((RubyArray) result).getLength() != 2) {
Expand All @@ -488,6 +500,14 @@ protected final RubyArray doCoerce(ThreadContext context, IRubyObject other, boo
return (RubyArray) result;
}

/** coerce_rescue
*
*/
protected final IRubyObject coerceRescue(ThreadContext context, IRubyObject other) {
coerceFailed(context, other);
return context.runtime.getNil();
}

/** coerce_failed
*
*/
Expand Down Expand Up @@ -528,7 +548,7 @@ protected final IRubyObject coerceBit(ThreadContext context, String method, IRub
protected final IRubyObject coerceCmp(ThreadContext context, String method, IRubyObject other) {
RubyArray ary = doCoerce(context, other, false);
if (ary == null) {
return context.runtime.getNil(); // MRI does it!
return context.nil; // MRI does it!
}
return (ary.eltInternal(0)).callMethod(context, method, ary.eltInternal(1));
}
Expand Down
10 changes: 5 additions & 5 deletions core/src/main/java/org/jruby/RubyRegexp.java
Expand Up @@ -83,8 +83,8 @@ public class RubyRegexp extends RubyObject implements ReOptions, EncodingCapable
private ByteList str = ByteList.EMPTY_BYTELIST;
private RegexpOptions options;

public static final int ARG_ENCODING_FIXED = 16;
public static final int ARG_ENCODING_NONE = 32;
public static final int ARG_ENCODING_FIXED = ReOptions.RE_FIXED;
public static final int ARG_ENCODING_NONE = ReOptions.RE_NONE;

public void setLiteral() {
options.setLiteral(true);
Expand Down Expand Up @@ -206,8 +206,8 @@ public static RubyClass createRegexpClass(Ruby runtime) {
regexpClass.defineConstant("EXTENDED", runtime.newFixnum(RE_OPTION_EXTENDED));
regexpClass.defineConstant("MULTILINE", runtime.newFixnum(RE_OPTION_MULTILINE));

regexpClass.defineConstant("FIXEDENCODING", runtime.newFixnum(ARG_ENCODING_FIXED));
regexpClass.defineConstant("NOENCODING", runtime.newFixnum(ARG_ENCODING_NONE));
regexpClass.defineConstant("FIXEDENCODING", runtime.newFixnum(RE_FIXED));
regexpClass.defineConstant("NOENCODING", runtime.newFixnum(RE_NONE));

regexpClass.defineAnnotatedMethods(RubyRegexp.class);
regexpClass.getSingletonClass().defineAlias("compile", "new");
Expand Down Expand Up @@ -2146,7 +2146,7 @@ public static void marshalTo(RubyRegexp regexp, MarshalStream output) throws jav

int options = regexp.pattern.getOptions() & EMBEDDABLE;

if (regexp.getOptions().isFixed()) options |= ARG_ENCODING_FIXED;
if (regexp.getOptions().isFixed()) options |= RE_FIXED;

output.writeByte(options);
}
Expand Down
4 changes: 2 additions & 2 deletions core/src/main/java/org/jruby/RubyString.java
Expand Up @@ -5165,7 +5165,7 @@ public IRubyObject lines20(ThreadContext context, Block block) {
return each_lineCommon19(context, block);
}
// FIXME: Inefficient; build array manually rather than via Enumerator
return enumeratorize(context.runtime, this, "lines").callMethod(context, "to_a");
return enumeratorize(context.runtime, this, "each_line").callMethod(context, "to_a");
}

@JRubyMethod(name = "lines")
Expand All @@ -5175,7 +5175,7 @@ public IRubyObject lines20(ThreadContext context, IRubyObject arg, Block block)
return each_lineCommon19(context, arg, block);
}
// FIXME: Inefficient; build array manually rather than via Enumerator
return enumeratorize(context.runtime, this, "lines", arg).callMethod(context, "to_a");
return enumeratorize(context.runtime, this, "each_line", arg).callMethod(context, "to_a");
}

private IRubyObject each_lineCommon19(ThreadContext context, Block block) {
Expand Down
Expand Up @@ -103,7 +103,7 @@ public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule claz
pre(context, self, name, block);

try {
return (IRubyObject)this.variable.invokeExact(context, method.getStaticScope(), self, args, block, implementationClass);
return (IRubyObject)this.variable.invokeExact(context, method.getStaticScope(), self, args, block, implementationClass, name);
} catch (Throwable t) {
Helpers.throwException(t);
// not reached
Expand All @@ -119,7 +119,7 @@ public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule claz
pre(context, self, name, block);

try {
return (IRubyObject)this.specific.invokeExact(context, method.getStaticScope(), self, block, implementationClass);
return (IRubyObject)this.specific.invokeExact(context, method.getStaticScope(), self, block, implementationClass, name);
} catch (Throwable t) {
Helpers.throwException(t);
// not reached
Expand All @@ -135,7 +135,7 @@ public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule claz
pre(context, self, name, block);

try {
return (IRubyObject)this.specific.invokeExact(context, method.getStaticScope(), self, arg0, block, implementationClass);
return (IRubyObject)this.specific.invokeExact(context, method.getStaticScope(), self, arg0, block, implementationClass, name);
} catch (Throwable t) {
Helpers.throwException(t);
// not reached
Expand All @@ -151,7 +151,7 @@ public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule claz
pre(context, self, name, block);

try {
return (IRubyObject)this.specific.invokeExact(context, method.getStaticScope(), self, arg0, arg1, block, implementationClass);
return (IRubyObject)this.specific.invokeExact(context, method.getStaticScope(), self, arg0, arg1, block, implementationClass, name);
} catch (Throwable t) {
Helpers.throwException(t);
// not reached
Expand All @@ -167,7 +167,7 @@ public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule claz
pre(context, self, name, block);

try {
return (IRubyObject)this.specific.invokeExact(context, method.getStaticScope(), self, arg0, arg1, arg2, block, implementationClass);
return (IRubyObject)this.specific.invokeExact(context, method.getStaticScope(), self, arg0, arg1, arg2, block, implementationClass, name);
} catch (Throwable t) {
Helpers.throwException(t);
// not reached
Expand Down
7 changes: 4 additions & 3 deletions core/src/main/java/org/jruby/ir/Compiler.java
Expand Up @@ -11,6 +11,7 @@
import org.jruby.ast.executable.ScriptAndCode;
import org.jruby.compiler.NotCompilableException;
import org.jruby.ir.interpreter.BeginEndInterpreterContext;
import org.jruby.ir.interpreter.Interpreter;
import org.jruby.ir.operands.IRException;
import org.jruby.ir.runtime.IRBreakJump;
import org.jruby.ir.targets.JVMVisitor;
Expand Down Expand Up @@ -55,7 +56,7 @@ protected ScriptAndCode execute(final Ruby runtime, final IRScriptBody scope, Cl
compiled = visitor.defineFromBytecode(scope, bytecode, classLoader);

Method compiledMethod = compiled.getMethod("__script__", ThreadContext.class,
StaticScope.class, IRubyObject.class, IRubyObject[].class, Block.class, RubyModule.class);
StaticScope.class, IRubyObject.class, IRubyObject[].class, Block.class, RubyModule.class, String.class);
_compiledHandle = MethodHandles.publicLookup().unreflect(compiledMethod);
} catch (NotCompilableException nce) {
throw nce;
Expand All @@ -69,7 +70,7 @@ protected ScriptAndCode execute(final Ruby runtime, final IRScriptBody scope, Cl
@Override
public IRubyObject __file__(ThreadContext context, IRubyObject self, IRubyObject[] args, Block block) {
try {
return (IRubyObject) compiledHandle.invokeWithArguments(context, scope.getStaticScope(), self, IRubyObject.NULL_ARRAY, block, self.getMetaClass());
return (IRubyObject) compiledHandle.invokeWithArguments(context, scope.getStaticScope(), self, IRubyObject.NULL_ARRAY, block, self.getMetaClass(), Interpreter.ROOT);
} catch (Throwable t) {
Helpers.throwException(t);
return null; // not reached
Expand Down Expand Up @@ -109,7 +110,7 @@ public IRubyObject load(ThreadContext context, IRubyObject self, boolean wrap) {

try {
// runBeginEndBlocks(ic.getBeginBlocks(), context, self, scope, null);
return (IRubyObject) compiledHandle.invokeWithArguments(context, sscope, self, IRubyObject.NULL_ARRAY, Block.NULL_BLOCK, currModule);
return (IRubyObject) compiledHandle.invokeWithArguments(context, sscope, self, IRubyObject.NULL_ARRAY, Block.NULL_BLOCK, currModule, Interpreter.ROOT);
} catch (IRBreakJump bj) {
throw IRException.BREAK_LocalJumpError.getException(context.runtime);
} catch (Throwable t) {
Expand Down
34 changes: 17 additions & 17 deletions core/src/main/java/org/jruby/ir/IRBuilder.java
Expand Up @@ -1379,21 +1379,21 @@ public Operand buildGetDefinition(Node node) {
case DASGNNODE: case GLOBALASGNNODE: case LOCALASGNNODE: case MULTIPLEASGNNODE:
case MULTIPLEASGN19NODE: case OPASGNNODE: case OPASGNANDNODE: case OPASGNORNODE:
case OPELEMENTASGNNODE: case INSTASGNNODE:
return new ConstantStringLiteral("assignment");
return new FrozenString("assignment");
case ORNODE: case ANDNODE:
return new ConstantStringLiteral("expression");
return new FrozenString("expression");
case FALSENODE:
return new ConstantStringLiteral("false");
return new FrozenString("false");
case LOCALVARNODE: case DVARNODE:
return new ConstantStringLiteral("local-variable");
return new FrozenString("local-variable");
case MATCH2NODE: case MATCH3NODE:
return new ConstantStringLiteral("method");
return new FrozenString("method");
case NILNODE:
return new ConstantStringLiteral("nil");
return new FrozenString("nil");
case SELFNODE:
return new ConstantStringLiteral("self");
return new FrozenString("self");
case TRUENODE:
return new ConstantStringLiteral("true");
return new FrozenString("true");
case DREGEXPNODE: case DSTRNODE: {
final Node dNode = node;

Expand All @@ -1402,7 +1402,7 @@ public Operand buildGetDefinition(Node node) {
public Operand run() {
build(dNode);
// always an expression as long as we get through here without an exception!
return new ConstantStringLiteral("expression");
return new FrozenString("expression");
}
};
// rescue block
Expand All @@ -1415,7 +1415,7 @@ public Operand run() {
Label doneLabel = getNewLabel();
Variable tmpVar = getValueInTemporaryVariable(v);
addInstr(BNEInstr.create(tmpVar, manager.getNil(), doneLabel));
addInstr(new CopyInstr(tmpVar, new ConstantStringLiteral("expression")));
addInstr(new CopyInstr(tmpVar, new FrozenString("expression")));
addInstr(new LabelInstr(doneLabel));

return tmpVar;
Expand All @@ -1432,7 +1432,7 @@ public Operand run() {
addInstr(BEQInstr.create(result, manager.getNil(), undefLabel));
}

addInstr(new CopyInstr(tmpVar, new ConstantStringLiteral("expression")));
addInstr(new CopyInstr(tmpVar, new FrozenString("expression")));
addInstr(new JumpInstr(doneLabel));
addInstr(new LabelInstr(undefLabel));
addInstr(new CopyInstr(tmpVar, manager.getNil()));
Expand Down Expand Up @@ -1483,7 +1483,7 @@ public Operand run() {
addInstr(new CopyInstr(tmpVar, manager.getNil()));
addInstr(new JumpInstr(doneLabel));
addInstr(new LabelInstr(defLabel));
addInstr(new CopyInstr(tmpVar, new ConstantStringLiteral("constant")));
addInstr(new CopyInstr(tmpVar, new FrozenString("constant")));
addInstr(new LabelInstr(doneLabel));
return tmpVar;
}
Expand All @@ -1506,7 +1506,7 @@ public Operand run() {
build(((Colon2Node)colon).getLeftNode()) : new ObjectClass();

Variable tmpVar = createTemporaryVariable();
addInstr(new RuntimeHelperCall(tmpVar, IS_DEFINED_CONSTANT_OR_METHOD, new Operand[] {v, new ConstantStringLiteral(name)}));
addInstr(new RuntimeHelperCall(tmpVar, IS_DEFINED_CONSTANT_OR_METHOD, new Operand[] {v, new FrozenString(name)}));
return tmpVar;
}
};
Expand Down Expand Up @@ -1603,7 +1603,7 @@ public Operand run() {
return protectCodeWithRescue(protectedCode, rescueBlock);
}
default:
return new ConstantStringLiteral("expression");
return new FrozenString("expression");
}
}

Expand All @@ -1621,13 +1621,13 @@ protected Variable buildDefinitionCheck(ResultInstr definedInstr, String defined
Label undefLabel = getNewLabel();
addInstr((Instr) definedInstr);
addInstr(BEQInstr.create(definedInstr.getResult(), manager.getFalse(), undefLabel));
return buildDefnCheckIfThenPaths(undefLabel, new ConstantStringLiteral(definedReturnValue));
return buildDefnCheckIfThenPaths(undefLabel, new FrozenString(definedReturnValue));
}

public Operand buildGetArgumentDefinition(final Node node, String type) {
if (node == null) return new StringLiteral(type);

Operand rv = new ConstantStringLiteral(type);
Operand rv = new FrozenString(type);
boolean failPathReqd = false;
Label failLabel = getNewLabel();
if (node instanceof ArrayNode) {
Expand Down Expand Up @@ -2343,7 +2343,7 @@ public Operand buildFlip(FlipNode flipNode) {
if (nearestNonClosureBuilder == null) {
Variable excType = createTemporaryVariable();
addInstr(new InheritanceSearchConstInstr(excType, new ObjectClass(), "NotImplementedError", false));
Variable exc = addResultInstr(CallInstr.create(createTemporaryVariable(), "new", excType, new Operand[] {new ConstantStringLiteral("Flip support currently broken")}, null));
Variable exc = addResultInstr(CallInstr.create(createTemporaryVariable(), "new", excType, new Operand[] {new FrozenString("Flip support currently broken")}, null));
addInstr(new ThrowExceptionInstr(exc));
return buildNil();
}
Expand Down
Expand Up @@ -94,7 +94,7 @@ public IRubyObject callHelper(ThreadContext context, StaticScope currScope, Dyna
return IRRuntimeHelpers.isDefinedCall(context, self, (IRubyObject) arg1, ((StringLiteral) operands[1]).getString());
case IS_DEFINED_CONSTANT_OR_METHOD:
return IRRuntimeHelpers.isDefinedConstantOrMethod(context, (IRubyObject) arg1,
((StringLiteral) operands[1]).getString());
((FrozenString) operands[1]).getString());
case IS_DEFINED_INSTANCE_VAR:
return IRRuntimeHelpers.isDefinedInstanceVar(context, (IRubyObject) arg1, ((StringLiteral) operands[1]).getString());
case IS_DEFINED_CLASS_VAR:
Expand Down
3 changes: 2 additions & 1 deletion core/src/main/java/org/jruby/ir/interpreter/Interpreter.java
Expand Up @@ -33,6 +33,7 @@
public class Interpreter extends IRTranslator<IRubyObject, IRubyObject> {
public static final Logger LOG = LoggerFactory.getLogger("Interpreter");
private static final IRubyObject[] EMPTY_ARGS = new IRubyObject[]{};
public static final String ROOT = "(root)";
static int interpInstrsCount = 0;

// we do not need instances of Interpreter
Expand Down Expand Up @@ -73,7 +74,7 @@ public static void runBeginBlocks(List<IRClosure> beBlocks, ThreadContext contex
protected IRubyObject execute(Ruby runtime, IRScriptBody irScope, IRubyObject self) {
BeginEndInterpreterContext ic = (BeginEndInterpreterContext) irScope.getInterpreterContext();
ThreadContext context = runtime.getCurrentContext();
String name = "(root)";
String name = ROOT;

if (IRRuntimeHelpers.isDebug()) LOG.info("Executing " + ic);

Expand Down

This file was deleted.

0 comments on commit 719d996

Please sign in to comment.