Skip to content

Commit

Permalink
Showing 6 changed files with 61 additions and 4 deletions.
22 changes: 19 additions & 3 deletions core/src/main/java/org/jruby/ir/instructions/BSwitchInstr.java
Original file line number Diff line number Diff line change
@@ -5,6 +5,8 @@
import org.jruby.ir.Operation;
import org.jruby.ir.operands.Label;
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.parser.StaticScope;
import org.jruby.runtime.DynamicScope;
@@ -76,6 +78,22 @@ public Instr clone(CloneInfo info) {
return new BSwitchInstr(jumps, operand, rubyCase, targets, elseTarget);
}

@Override
public void encode(IRWriterEncoder e) {
super.encode(e);
e.encode(jumps);
e.encode(operand);
e.encode(rubyCase);
e.encode(targets); // FXXXX
e.encode(elseTarget);
}

public static BSwitchInstr decode(IRReaderDecoder d) {
return new BSwitchInstr(d.decodeIntArray(), d.decodeOperand(), d.decodeLabel(), d.decodeLabelArray(), d.decodeLabel());
}



@Override
public int interpretAndGetNewIPC(ThreadContext context, DynamicScope currDynScope, StaticScope currScope, IRubyObject self, Object[] temp, int ipc) {
Object result = operand.retrieve(context, self, currScope, currDynScope, temp);
@@ -104,9 +122,7 @@ public void visit(IRVisitor visitor) {
public Label[] getJumpTargets() {
Label[] jumpTargets = new Label[targets.length + 2];
jumpTargets[0] = rubyCase;
for (int i = 0; i < targets.length; i++) {
jumpTargets[i + 1] = targets[i];
}
System.arraycopy(targets, 0, jumpTargets, 1, targets.length);
jumpTargets[jumpTargets.length - 1] = elseTarget;
return jumpTargets;
}
Original file line number Diff line number Diff line change
@@ -31,12 +31,15 @@
public interface IRReaderDecoder {
public String decodeString();
public String[] decodeStringArray();
public int[] decodeIntArray();
public Instr decodeInstr();
public IRScopeType decodeIRScopeType();
public StaticScope.Type decodeStaticScopeType();
public Operation decodeOperation();
public Operand decodeOperand();
public List<Operand> decodeOperandList();
public Label decodeLabel();
public Label[] decodeLabelArray();
public Operand[] decodeOperandArray();
public OperandType decodeOperandType();
public boolean decodeBoolean();
@@ -50,7 +53,6 @@ public interface IRReaderDecoder {
public long decodeLong();
public double decodeDouble();
public float decodeFloat();
public Label decodeLabel();
public RubyEvent decodeRubyEvent();
public Signature decodeSignature();

22 changes: 22 additions & 0 deletions core/src/main/java/org/jruby/ir/persistence/IRReaderStream.java
Original file line number Diff line number Diff line change
@@ -111,6 +111,17 @@ public Label decodeLabel() {
return (Label) decodeOperand();
}

@Override
public Label[] decodeLabelArray() {
int size = decodeInt();
Label[] labels = new Label[size];
for (int i = 0; i < size; i++) {
labels[i] = decodeLabel();
}

return labels;
}

@Override
public RubyEvent decodeRubyEvent() {
return RubyEvent.fromOrdinal(decodeInt());
@@ -152,6 +163,16 @@ public String[] decodeStringArray() {
return array;
}

@Override
public int[] decodeIntArray() {
int size = decodeInt();
int[] ints = new int[size];
for (int i = 0; i < size; i++) {
ints[i] = decodeInt();
}
return ints;
}

private Map<String, Operand> vars = null;

@Override
@@ -192,6 +213,7 @@ public Instr decodeInstr() {
case ATTR_ASSIGN: return AttrAssignInstr.decode(this);
case B_FALSE: return BFalseInstr.decode(this);
case B_NIL: return BNilInstr.decode(this);
case B_SWITCH: return BSwitchInstr.decode(this);
case B_TRUE: return BTrueInstr.decode(this);
case B_UNDEF: return BUndefInstr.decode(this);
case BACKTICK_STRING: return BacktickInstr.decode(this);
Original file line number Diff line number Diff line change
@@ -11,6 +11,7 @@
import org.jruby.ir.IRScopeType;
import org.jruby.ir.Operation;
import org.jruby.ir.instructions.Instr;
import org.jruby.ir.operands.Label;
import org.jruby.ir.operands.Operand;
import org.jruby.ir.operands.OperandType;
import org.jruby.parser.StaticScope;
@@ -105,6 +106,11 @@ public void encode(char value) {
public void encode(int value) {
}

@Override
public void encode(int[] value) {

}

@Override
public void encode(long value) {
}
Original file line number Diff line number Diff line change
@@ -5,6 +5,7 @@
import org.jruby.ir.IRScopeType;
import org.jruby.ir.Operation;
import org.jruby.ir.instructions.Instr;
import org.jruby.ir.operands.Label;
import org.jruby.ir.operands.Operand;
import org.jruby.ir.operands.OperandType;
import org.jruby.parser.StaticScope.Type;
@@ -39,6 +40,7 @@ public interface IRWriterEncoder {
public void encode(byte value);
public void encode(char value);
public void encode(int value);
public void encode(int[] value);
public void encode(long value);
public void encode(double value);
public void encode(float value);
Original file line number Diff line number Diff line change
@@ -11,6 +11,7 @@
import org.jruby.ir.IRScopeType;
import org.jruby.ir.Operation;
import org.jruby.ir.instructions.Instr;
import org.jruby.ir.operands.Label;
import org.jruby.ir.operands.Operand;
import org.jruby.ir.operands.OperandType;
import org.jruby.parser.StaticScope;
@@ -97,6 +98,14 @@ public void encode(int value) {
}
}

@Override
public void encode(int[] value) {
encode(value.length);
for (int i = 0; i < value.length; i++) {
encode(value[i]);
}
}

@Override
public void encode(long value) {
if (value >= 0 && value <= 127) {

0 comments on commit 8692680

Please sign in to comment.