Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into update_stdlib
Browse files Browse the repository at this point in the history
  • Loading branch information
headius committed Nov 5, 2014
2 parents ce7e292 + eb95b6e commit a0f3839
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 46 deletions.
32 changes: 13 additions & 19 deletions core/src/main/java/org/jruby/ir/IRBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,7 @@ public Operand buildLambda(LambdaNode node, IRScope s) {
// can be U_NIL if the node is an if node with returns in both branches.
if (closureRetVal != U_NIL) closureBuilder.addInstr(closure, new ReturnInstr(closureRetVal));

handleBreakAndReturnsInLambdas(closure);
closureBuilder.handleBreakAndReturnsInLambdas(closure);

Variable lambda = s.createTemporaryVariable();
WrappedIRClosure lambdaBody = new WrappedIRClosure(closure.getSelf(), closure);
Expand Down Expand Up @@ -1447,31 +1447,25 @@ public Operand run() {
addInstr(scope, new LabelInstr(doneLabel));
return tmpVar;
}
case COLON3NODE: case COLON2NODE: {
// SSS FIXME: Is there a reason to do this all with low-level IR?
// Can't this all be folded into a Java method that would be part
// of the runtime library, which then can be used by buildDefinitionCheck method above?
// This runtime library would be used both by the interpreter & the compiled code!

final Colon3Node colon = (Colon3Node) node;
final String name = colon.getName();
case COLON3NODE:
return addResultInstr(scope, new RuntimeHelperCall(scope.createTemporaryVariable(), IS_DEFINED_CONSTANT_OR_METHOD,
new Operand[] {new ObjectClass(), new ConstantStringLiteral(((Colon3Node) node).getName())}));
case COLON2NODE: {
final Colon2Node colon = (Colon2Node) node;
final ConstantStringLiteral name = new ConstantStringLiteral(colon.getName());
final Variable errInfo = scope.createTemporaryVariable();

// store previous exception for restoration if we rescue something
addInstr(scope, new GetErrorInfoInstr(errInfo));
// Complicated case where LHS can be an expression - (eval "Foo")::Bar
addInstr(scope, new GetErrorInfoInstr(errInfo)); // store previous exception for restoration if we rescue something

CodeBlock protectedCode = new CodeBlock() {
public Operand run() {
Operand v = colon instanceof Colon2Node ?
build(((Colon2Node)colon).getLeftNode(), scope) : new ObjectClass();

Variable tmpVar = scope.createTemporaryVariable();
addInstr(scope, new RuntimeHelperCall(tmpVar, IS_DEFINED_CONSTANT_OR_METHOD, new Operand[] {v, new ConstantStringLiteral(name)}));
return tmpVar;
Operand lhs = build(colon.getLeftNode(), scope);
return addResultInstr(scope, new RuntimeHelperCall(scope.createTemporaryVariable(),
IS_DEFINED_CONSTANT_OR_METHOD, new Operand[] {lhs, name}));
}
};

// rescue block
CodeBlock rescueBlock = new CodeBlock() {
public Operand run() {
// Nothing to do -- ignore the exception, and restore stashed error info!
Expand All @@ -1480,7 +1474,7 @@ public Operand run() {
}
};

// Try verifying definition, and if we get an JumpException exception, process it with the rescue block above
// Try verifying definition, and if we get an JumpException exception, process it with the rescue block above
return protectCodeWithRescue(scope, protectedCode, rescueBlock);
}
case FCALLNODE: {
Expand Down
52 changes: 25 additions & 27 deletions core/src/main/java/org/jruby/runtime/IRBlockBody.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,30 +80,29 @@ public IRubyObject yieldSpecific(ThreadContext context, Binding binding, Type ty
public IRubyObject yieldSpecific(ThreadContext context, IRubyObject arg0, Binding binding, Type type) {
if (arg0 instanceof RubyArray) {
// Unwrap the array arg
IRubyObject[] args;
if (type == Type.LAMBDA) {
args = ((RubyArray)arg0).toJavaArray();
arity().checkArity(context.runtime, args);
} else {
args = IRRuntimeHelpers.convertValueIntoArgArray(context, arg0, arity, true);
}
IRubyObject[] args = IRRuntimeHelpers.convertValueIntoArgArray(context, arg0, arity, true);

// FIXME: arity error is aginst new args but actual error shows arity of original args.
if (type == Type.LAMBDA) arity().checkArity(context.runtime, args);

return commonYieldPath(context, args, null, binding, type, Block.NULL_BLOCK);
} else {
return yield(context, arg0, binding, type);
}
}

private IRubyObject yieldSpecificMultiArgsCommon(ThreadContext context, IRubyObject[] args, Binding binding, Type type) {
if (type == Type.LAMBDA) {
arity().checkArity(context.runtime, args);
} else {
int blockArity = arity().getValue();
if (blockArity == 0) {
args = IRubyObject.NULL_ARRAY; // discard args
} else if (blockArity == 1) {
args = new IRubyObject[] { RubyArray.newArrayNoCopy(context.runtime, args) };
}


int blockArity = arity().getValue();
if (blockArity == 0) {
args = IRubyObject.NULL_ARRAY; // discard args
} else if (blockArity == 1) {
args = new IRubyObject[] { RubyArray.newArrayNoCopy(context.runtime, args) };
}

if (type == Type.LAMBDA) arity().checkArity(context.runtime, args);

return commonYieldPath(context, args, null, binding, type, Block.NULL_BLOCK);
}

Expand All @@ -120,21 +119,20 @@ public IRubyObject yieldSpecific(ThreadContext context, IRubyObject arg0, IRubyO
@Override
public IRubyObject doYield(ThreadContext context, IRubyObject value, Binding binding, Type type) {
IRubyObject[] args;
if (type == Type.LAMBDA) {

int blockArity = arity().getValue();
if (blockArity >= -1 && blockArity <= 1) {
args = new IRubyObject[] { value };
arity().checkArity(context.runtime, args);
} else {
int blockArity = arity().getValue();
if (blockArity >= -1 && blockArity <= 1) {
args = new IRubyObject[] { value };
} else {
IRubyObject val0 = Helpers.aryToAry(value);
if (!(val0 instanceof RubyArray)) {
throw context.runtime.newTypeError(value.getType().getName() + "#to_ary should return Array");
}
args = ((RubyArray)val0).toJavaArray();
IRubyObject val0 = Helpers.aryToAry(value);
if (!(val0 instanceof RubyArray)) {
throw context.runtime.newTypeError(value.getType().getName() + "#to_ary should return Array");
}
args = ((RubyArray)val0).toJavaArray();
}

if (type == Type.LAMBDA) arity().checkArity(context.runtime, args);

return commonYieldPath(context, args, null, binding, type, Block.NULL_BLOCK);
}

Expand Down

0 comments on commit a0f3839

Please sign in to comment.