Skip to content

Commit

Permalink
Add Block variants of push/pop frame/binding instructions
Browse files Browse the repository at this point in the history
* These haven't been hooked up with the interpreter, JIT, or
  IR generation passes yet.

* These instructions will very likely be added as part of the
  AddCallProtocolInstructions pass.

* More specialized instructions are needed for getting the
  call protocol code to work for blocks.
subbuss committed Nov 27, 2015
1 parent e8c7942 commit c6dd87a
Showing 5 changed files with 119 additions and 3 deletions.
9 changes: 6 additions & 3 deletions core/src/main/java/org/jruby/ir/IRVisitor.java
Original file line number Diff line number Diff line change
@@ -86,14 +86,17 @@ private void error(Object object) {
public void OneOperandArgNoBlockCallInstr(OneOperandArgNoBlockCallInstr oneOperandArgNoBlockCallInstr) { error(oneOperandArgNoBlockCallInstr); }
public void OptArgMultipleAsgnInstr(OptArgMultipleAsgnInstr optargmultipleasgninstr) { error(optargmultipleasgninstr); }
public void PopBindingInstr(PopBindingInstr popbindinginstr) { error(popbindinginstr); }
public void PopMethodFrameInstr(PopMethodFrameInstr popframeinstr) { error(popframeinstr); }
public void PopBlockFrameInstr(PopBlockFrameInstr instr) { error(instr); }
public void PopMethodFrameInstr(PopMethodFrameInstr instr) { error(instr); }
public void ProcessModuleBodyInstr(ProcessModuleBodyInstr processmodulebodyinstr) { error(processmodulebodyinstr); }
public void PutClassVariableInstr(PutClassVariableInstr putclassvariableinstr) { error(putclassvariableinstr); }
public void PutConstInstr(PutConstInstr putconstinstr) { error(putconstinstr); }
public void PutFieldInstr(PutFieldInstr putfieldinstr) { error(putfieldinstr); }
public void PutGlobalVarInstr(PutGlobalVarInstr putglobalvarinstr) { error(putglobalvarinstr); }
public void PushMethodBindingInstr(PushMethodBindingInstr pushbindinginstr) { error(pushbindinginstr); }
public void PushMethodFrameInstr(PushMethodFrameInstr pushframeinstr) { error(pushframeinstr); }
public void PushBlockBindingInstr(PushBlockBindingInstr instr) { error(instr); }
public void PushBlockFrameInstr(PushBlockFrameInstr instr) { error(instr); }
public void PushMethodBindingInstr(PushMethodBindingInstr instr) { error(instr); }
public void PushMethodFrameInstr(PushMethodFrameInstr instr) { error(instr); }
public void RaiseArgumentErrorInstr(RaiseArgumentErrorInstr raiseargumenterrorinstr) { error(raiseargumenterrorinstr); }
public void RaiseRequiredKeywordArgumentErrorInstr(RaiseRequiredKeywordArgumentError instr) { error(instr); }
public void ReifyClosureInstr(ReifyClosureInstr reifyclosureinstr) { error(reifyclosureinstr); }
3 changes: 3 additions & 0 deletions core/src/main/java/org/jruby/ir/Operation.java
Original file line number Diff line number Diff line change
@@ -207,6 +207,9 @@ public enum Operation {
PUSH_METHOD_FRAME(OpFlags.f_is_book_keeping_op | OpFlags.f_has_side_effect),
PUSH_METHOD_BINDING(OpFlags.f_is_book_keeping_op | OpFlags.f_has_side_effect),
POP_METHOD_FRAME(OpFlags.f_is_book_keeping_op | OpFlags.f_has_side_effect),
PUSH_BLOCK_FRAME(OpFlags.f_is_book_keeping_op | OpFlags.f_has_side_effect),
PUSH_BLOCK_BINDING(OpFlags.f_is_book_keeping_op | OpFlags.f_has_side_effect),
POP_BLOCK_FRAME(OpFlags.f_is_book_keeping_op | OpFlags.f_has_side_effect),
POP_BINDING(OpFlags.f_is_book_keeping_op | OpFlags.f_has_side_effect),
TOGGLE_BACKTRACE(OpFlags.f_is_book_keeping_op | OpFlags.f_has_side_effect);

Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package org.jruby.ir.instructions;

import org.jruby.ir.IRVisitor;
import org.jruby.ir.Operation;
import org.jruby.ir.operands.Operand;
import org.jruby.ir.persistence.IRReaderDecoder;
import org.jruby.ir.persistence.IRWriterEncoder;
import org.jruby.ir.transformations.inlining.CloneInfo;
import org.jruby.ir.transformations.inlining.SimpleCloneInfo;

public class PopBlockFrameInstr extends OneOperandInstr implements FixedArityInstr {
public PopBlockFrameInstr(Operand frame) {
super(Operation.POP_BLOCK_FRAME, frame);
}

public Operand getFrame() {
return getOperand1();
}

@Override
public Instr clone(CloneInfo ii) {
return ii instanceof SimpleCloneInfo ? this : NopInstr.NOP; // FIXME: Is this correct
}

@Override
public void encode(IRWriterEncoder e) {
super.encode(e);
e.encode(getFrame());
}

public static PopBlockFrameInstr decode(IRReaderDecoder d) {
return new PopBlockFrameInstr(d.decodeOperand());
}

@Override
public void visit(IRVisitor visitor) {
visitor.PopBlockFrameInstr(this);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package org.jruby.ir.instructions;

import org.jruby.ir.IRVisitor;
import org.jruby.ir.Operation;
import org.jruby.ir.operands.Operand;
import org.jruby.ir.persistence.IRWriterEncoder;
import org.jruby.ir.persistence.IRReaderDecoder;
import org.jruby.ir.transformations.inlining.CloneInfo;

public class PushBlockBindingInstr extends NoOperandInstr implements FixedArityInstr {
public PushBlockBindingInstr() {
super(Operation.PUSH_BLOCK_BINDING);
}

@Override
public Instr clone(CloneInfo ii) {
return this; // FIXME: This has to be wrong if pop_binding is conditionally noop'ing on inline
}

public static PushBlockBindingInstr decode(IRReaderDecoder d) {
return new PushBlockBindingInstr();
}

@Override
public void visit(IRVisitor visitor) {
visitor.PushBlockBindingInstr(this);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package org.jruby.ir.instructions;

import org.jruby.ir.IRVisitor;
import org.jruby.ir.Operation;
import org.jruby.ir.operands.Operand;
import org.jruby.ir.operands.Variable;
import org.jruby.ir.persistence.IRReaderDecoder;
import org.jruby.ir.persistence.IRWriterEncoder;
import org.jruby.ir.transformations.inlining.CloneInfo;
import org.jruby.ir.transformations.inlining.SimpleCloneInfo;

public class PushBlockFrameInstr extends NoOperandResultBaseInstr implements FixedArityInstr {
private final String frameName;

public PushBlockFrameInstr(Variable result, String frameName) {
super(Operation.PUSH_BLOCK_FRAME, result);
this.frameName = frameName;
}

public String getFrameName() {
return frameName;
}

@Override
public Instr clone(CloneInfo ii) {
return ii instanceof SimpleCloneInfo ? this : NopInstr.NOP; // FIXME: Is this correct?
}

public static PushBlockFrameInstr decode(IRReaderDecoder d) {
return new PushBlockFrameInstr(d.decodeVariable(), d.decodeString());
}

@Override
public void encode(IRWriterEncoder e) {
super.encode(e);
e.encode(getFrameName());
}

@Override
public void visit(IRVisitor visitor) {
visitor.PushBlockFrameInstr(this);
}
}

0 comments on commit c6dd87a

Please sign in to comment.