Skip to content

Commit

Permalink
Simplify IR for yield instruction
Browse files Browse the repository at this point in the history
  • Loading branch information
subbuss committed Apr 1, 2011
1 parent 3d0cf62 commit ba933b7
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 17 deletions.
19 changes: 14 additions & 5 deletions src/org/jruby/compiler/ir/IRBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -1669,11 +1669,15 @@ public Operand buildDefn(MethodDefNode node, IRScope s) { // Instance method
}

public Operand buildDefs(DefsNode node, IRScope s) { // Class method
System.out.println("defs scope is: " + s.getName() + "; lexical parent is: " + s.getLexicalParent().getName() + "; nearest module is: " + s.getNearestModule().getName());
Operand container = build(node.getReceiverNode(), s);
IRMethod method = defineNewMethod(node, s, container, false);
// ENEBO: Can all metaobjects be used for this? closure?
if (container instanceof MetaObject) {
((IRModule) ((MetaObject) container).getScope()).addMethod(method);
//if (container instanceof MetaObject) {
// ((IRModule) ((MetaObject) container).getScope()).addMethod(method);
//}
if (s.getLexicalParent() instanceof IRModule) {
((IRModule)s.getLexicalParent()).addMethod(method);
}
s.addInstr(new DefineClassMethodInstr(container, method));
return Nil.NIL;
Expand Down Expand Up @@ -2841,6 +2845,10 @@ public Operand buildSymbol(SymbolNode node, IRScope s) {
}

public Operand buildToAry(ToAryNode node, IRScope s) {
// FIXME: Two possibilities
// 1. Make this a TO_ARY IR instruction to enable optimization
// 2. Alternatively make this a regular call which would be subject to inlining
// if these utility methods are implemented as ruby ir code.
Operand array = build(node.getValue(), s);
return generateJRubyUtilityCall(s, MethAddr.TO_ARY, array, new Operand[]{});
}
Expand Down Expand Up @@ -2938,6 +2946,7 @@ public Operand buildXStr(XStrNode node, IRScope m) {
return new BacktickString(new StringLiteral(node.getValue()));
}

/*
private List<Operand> setupYieldArgs(Node args, IRScope s) {
List<Operand> argsList = new ArrayList<Operand>();
if (args != null) {
Expand All @@ -2948,11 +2957,11 @@ private List<Operand> setupYieldArgs(Node args, IRScope s) {
return argsList;
}
*/

public Operand buildYield(YieldNode node, IRScope s) {
List<Operand> args = setupYieldArgs(node.getArgsNode(), s);
Variable ret = s.getNewTemporaryVariable();
s.addInstr(new YieldInstr(ret, args.toArray(new Operand[args.size()])));
Variable ret = s.getNewTemporaryVariable();
s.addInstr(new YieldInstr(ret, build(node.getArgsNode(), s)));
return ret;
}

Expand Down
16 changes: 4 additions & 12 deletions src/org/jruby/compiler/ir/instructions/YieldInstr.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,20 @@
import org.jruby.interpreter.InterpreterContext;
import org.jruby.runtime.builtin.IRubyObject;

public class YieldInstr extends MultiOperandInstr {
public class YieldInstr extends OneOperandInstr {
// SSS FIXME: Correct? Where does closure arg come from?
public YieldInstr(Variable result, Operand[] args) {
super(Operation.YIELD, result, args);
public YieldInstr(Variable result, Operand arg) {
super(Operation.YIELD, result, arg);
}

public boolean isRubyInternalsCall() {
return false;
}

public boolean isStaticCallTarget() {
return false;
}

public Instr cloneForInlining(InlinerInfo ii) {
return this; // This is just a placeholder during inlining.
}

@Interp
@Override
public Label interpret(InterpreterContext interp, IRubyObject self) {
Object resultValue = interp.getBlock().call(interp.getContext(), prepareArguments(getOperands(), interp));
Object resultValue = interp.getBlock().call(interp.getContext(), (IRubyObject)getArg().retrieve(interp));
getResult().store(interp, resultValue);
return null;
}
Expand Down

0 comments on commit ba933b7

Please sign in to comment.