Skip to content

Commit

Permalink
Move CheckForLJE out of runtimehelpers. No result instr
Browse files Browse the repository at this point in the history
  • Loading branch information
enebo committed Feb 3, 2015
1 parent fae1f9f commit a10fccc
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 18 deletions.
6 changes: 3 additions & 3 deletions core/src/main/java/org/jruby/ir/IRBuilder.java
Expand Up @@ -3179,10 +3179,10 @@ public Operand buildReturn(ReturnNode returnNode) {
// If 'm' is a block scope, a return returns from the closest enclosing method.
// If this happens to be a module body, the runtime throws a local jump error if the
// closure is a proc. If the closure is a lambda, then this becomes a normal return.
IRMethod m = scope.getNearestMethod();
addInstr(new RuntimeHelperCall(null, CHECK_FOR_LJE, new Operand[] { m == null ? manager.getTrue() : manager.getFalse() }));
boolean maybeLambda = scope.getNearestMethod() == null;
addInstr(new CheckForLJEInstr(maybeLambda));
retVal = processEnsureRescueBlocks(retVal);
addInstr(new NonlocalReturnInstr(retVal, m == null ? "--none--" : m.getName()));
addInstr(new NonlocalReturnInstr(retVal, maybeLambda ? "--none--" : scope.getNearestMethod().getName()));
} else if (scope.isModuleBody()) {
IRMethod sm = scope.getNearestMethod();

Expand Down
1 change: 1 addition & 0 deletions core/src/main/java/org/jruby/ir/IRVisitor.java
Expand Up @@ -49,6 +49,7 @@ private void error(Object object) {
public void CallInstr(CallInstr callinstr) { error(callinstr); }
public void CheckArgsArrayArityInstr(CheckArgsArrayArityInstr checkargsarrayarityinstr) { error(checkargsarrayarityinstr); }
public void CheckArityInstr(CheckArityInstr checkarityinstr) { error(checkarityinstr); }
public void CheckForLJEInstr(CheckForLJEInstr checkforljeinstr) { error(checkforljeinstr); }
public void ClassSuperInstr(ClassSuperInstr classsuperinstr) { error(classsuperinstr); }
public void ConstMissingInstr(ConstMissingInstr constmissinginstr) { error(constmissinginstr); }
public void CopyInstr(CopyInstr copyinstr) { error(copyinstr); }
Expand Down
1 change: 1 addition & 0 deletions core/src/main/java/org/jruby/ir/Operation.java
Expand Up @@ -151,6 +151,7 @@ public enum Operation {
BACKTICK_STRING(OpFlags.f_can_raise_exception),
CHECK_ARGS_ARRAY_ARITY(OpFlags.f_can_raise_exception),
CHECK_ARITY(OpFlags.f_is_book_keeping_op | OpFlags.f_can_raise_exception),
CHECK_FOR_LJE(OpFlags.f_has_side_effect | OpFlags.f_can_raise_exception),
CLASS_VAR_MODULE(0),
COPY(0),
GET_ENCODING(0),
Expand Down
38 changes: 38 additions & 0 deletions core/src/main/java/org/jruby/ir/instructions/CheckForLJEInstr.java
@@ -0,0 +1,38 @@
package org.jruby.ir.instructions;

import org.jruby.ir.IRVisitor;
import org.jruby.ir.Operation;
import org.jruby.ir.runtime.IRRuntimeHelpers;
import org.jruby.ir.transformations.inlining.CloneInfo;
import org.jruby.runtime.Block;
import org.jruby.runtime.DynamicScope;
import org.jruby.runtime.ThreadContext;

/**
*/
public class CheckForLJEInstr extends Instr {
private boolean maybeLambda;

public CheckForLJEInstr(boolean maybeLambda) {
super(Operation.CHECK_FOR_LJE, EMPTY_OPERANDS);

this.maybeLambda = maybeLambda;
}

public boolean maybeLambda() {
return maybeLambda;
}

@Override
public Instr clone(CloneInfo info) {
return new CheckForLJEInstr(maybeLambda);
}

public void visit(IRVisitor visitor) {
visitor.CheckForLJEInstr(this);
}

public void check(ThreadContext context, DynamicScope dynamicScope, Block.Type blockType) {
IRRuntimeHelpers.checkForLJE(context, dynamicScope, maybeLambda, blockType);
}
}
Expand Up @@ -23,7 +23,7 @@ public enum Methods {
HANDLE_PROPAGATE_BREAK, HANDLE_NONLOCAL_RETURN, HANDLE_BREAK_AND_RETURNS_IN_LAMBDA,
IS_DEFINED_BACKREF, IS_DEFINED_NTH_REF, IS_DEFINED_GLOBAL, IS_DEFINED_INSTANCE_VAR,
IS_DEFINED_CLASS_VAR, IS_DEFINED_SUPER, IS_DEFINED_METHOD, IS_DEFINED_CALL,
IS_DEFINED_CONSTANT_OR_METHOD, MERGE_KWARGS(), CHECK_FOR_LJE
IS_DEFINED_CONSTANT_OR_METHOD, MERGE_KWARGS
}

Methods helperMethod;
Expand Down Expand Up @@ -81,9 +81,6 @@ public IRubyObject callHelper(ThreadContext context, StaticScope currScope, Dyna
return IRRuntimeHelpers.isDefinedNthRef(context, (int) ((Fixnum) operands[0]).getValue());
case IS_DEFINED_GLOBAL:
return IRRuntimeHelpers.isDefinedGlobal(context, ((StringLiteral) operands[0]).getString());
case CHECK_FOR_LJE:
IRRuntimeHelpers.checkForLJE(context, currDynScope, ((Boolean)operands[0]).isTrue(), blockType);
return null;
}

Object arg1 = operands[0].retrieve(context, self, currScope, currDynScope, temp);
Expand Down
10 changes: 6 additions & 4 deletions core/src/main/java/org/jruby/ir/interpreter/Interpreter.java
Expand Up @@ -441,13 +441,15 @@ private static void processOtherOp(ThreadContext context, Instr instr, Operation

case RUNTIME_HELPER: {
RuntimeHelperCall rhc = (RuntimeHelperCall)instr;
result = rhc.callHelper(context, currScope, currDynScope, self, temp, blockType);
if (rhc.getResult() != null) {
setResult(temp, currDynScope, rhc.getResult(), result);
}
setResult(temp, currDynScope, rhc.getResult(),
rhc.callHelper(context, currScope, currDynScope, self, temp, blockType));
break;
}

case CHECK_FOR_LJE:
((CheckForLJEInstr) instr).check(context, currDynScope, blockType);
break;

case BOX_FLOAT: {
RubyFloat f = context.runtime.newFloat(getFloatArg(floats, ((BoxFloatInstr)instr).getValue()));
setResult(temp, currDynScope, ((BoxInstr)instr).getResult(), f);
Expand Down
16 changes: 9 additions & 7 deletions core/src/main/java/org/jruby/ir/targets/JVMVisitor.java
Expand Up @@ -875,6 +875,15 @@ public void CheckArityInstr(CheckArityInstr checkarityinstr) {
}

@Override
public void CheckForLJEInstr(CheckForLJEInstr checkForljeinstr) {
jvmMethod().loadContext();
jvmLoadLocal(DYNAMIC_SCOPE);
jvmAdapter().ldc(checkForljeinstr.maybeLambda());
jvmMethod().loadBlockType();
jvmAdapter().invokestatic(p(IRRuntimeHelpers.class), "checkForLJE", sig(void.class, ThreadContext.class, DynamicScope.class, boolean.class, Block.Type.class));
}

@Override
public void ClassSuperInstr(ClassSuperInstr classsuperinstr) {
String name = classsuperinstr.getName();
Operand[] args = classsuperinstr.getCallArgs();
Expand Down Expand Up @@ -1725,13 +1734,6 @@ public void RuntimeHelperCall(RuntimeHelperCall runtimehelpercall) {
jvmAdapter().invokestatic(p(IRRuntimeHelpers.class), "mergeKeywordArguments", sig(IRubyObject.class, ThreadContext.class, IRubyObject.class, IRubyObject.class));
jvmStoreLocal(runtimehelpercall.getResult());
break;
case CHECK_FOR_LJE:
jvmMethod().loadContext();
jvmLoadLocal(DYNAMIC_SCOPE);
jvmAdapter().ldc(((Boolean)runtimehelpercall.getArgs()[0]).isTrue());
jvmMethod().loadBlockType();
jvmAdapter().invokestatic(p(IRRuntimeHelpers.class), "checkForLJE", sig(void.class, ThreadContext.class, DynamicScope.class, boolean.class, Block.Type.class));
break;
default:
throw new NotCompilableException("Unknown IR runtime helper method: " + runtimehelpercall.getHelperMethod() + "; INSTR: " + this);
}
Expand Down

0 comments on commit a10fccc

Please sign in to comment.