Skip to content

Commit

Permalink
Change OperandTypes to be distinct between boxed and unboxed values. …
Browse files Browse the repository at this point in the history
…Added rest of changes to IRVisitor so persistence encoding is working again (reading still broken)
  • Loading branch information
enebo authored and lucasallan committed Feb 7, 2014
1 parent 8c28f74 commit a9a43e2
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 25 deletions.
2 changes: 1 addition & 1 deletion core/src/main/java/org/jruby/ir/operands/Boolean.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public class Boolean extends ImmutableLiteral {
public static final Boolean FALSE = new Boolean(false);

public Boolean(boolean truthy) {
super(OperandType.BOOLEAN_LITERAL);
super(OperandType.BOOLEAN);

this.truthy = truthy;
}
Expand Down
7 changes: 4 additions & 3 deletions core/src/main/java/org/jruby/ir/operands/OperandType.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,14 @@ public enum OperandType {
BACKREF((byte) '\\'),
BACKTICK_STRING((byte) '`'),
BIGNUM((byte) 'B'),
BOOLEAN_LITERAL((byte) 'b'),
BOOLEAN((byte) 'b'),
LOCAL_VARIABLE((byte) 'l'), // Also applicable for ClosureLocalVariable
COMPOUND_ARRAY((byte) 'c'),
COMPOUND_STRING((byte) '"'),
CURRENT_SCOPE((byte) 's'),
DYNAMIC_SYMBOL((byte) 'd'),
FIXNUM((byte) 'f'),
UNBOXED_FIXNUM((byte) 'j'),
FLOAT((byte) 'F'),
UNBOXED_FLOAT((byte) 'J'),
GLOBAL_VARIABLE((byte) '$'),
HASH((byte) '{'),
IR_EXCEPTION((byte) '!'),
Expand All @@ -41,6 +39,9 @@ public enum OperandType {
SVALUE((byte) 'V'),
SYMBOL((byte) ':'),
TEMPORARY_VARIABLE((byte) 't'),
UNBOXED_BOOLEAN((byte) 'v'),
UNBOXED_FIXNUM((byte) 'j'),
UNBOXED_FLOAT((byte) 'J'),
UNDEFINED_VALUE((byte) 'u'),
UNEXECUTABLE_NIL((byte) 'n'),
WRAPPED_IR_CLOSURE((byte) 'w'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public class UnboxedBoolean extends ImmutableLiteral {
public static final UnboxedBoolean FALSE = new UnboxedBoolean(false);

public UnboxedBoolean(boolean truthy) {
super(OperandType.BOOLEAN_LITERAL);
super(OperandType.UNBOXED_BOOLEAN);

this.truthy = truthy;
}
Expand Down
6 changes: 1 addition & 5 deletions core/src/main/java/org/jruby/ir/operands/UnboxedFixnum.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,10 @@ public class UnboxedFixnum extends ImmutableLiteral {
final public long value;

public UnboxedFixnum(long val) {
super(OperandType.FIXNUM);
super(OperandType.UNBOXED_FIXNUM);
value = val;
}

public UnboxedFixnum(BigInteger val) {
this(val.longValue());
}

@Override
public Object createCacheObject(ThreadContext context) {
return context.runtime.newFixnum(value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public Operand decode(OperandType type) {
case BACKREF: return new Backref(d.decodeChar());
case BACKTICK_STRING: return new BacktickString(d.decodeOperandList());
case BIGNUM: return new Bignum(new BigInteger(d.decodeString()));
case BOOLEAN_LITERAL: return new UnboxedBoolean(d.decodeBoolean());
case BOOLEAN: return new UnboxedBoolean(d.decodeBoolean());
case COMPOUND_ARRAY: return new CompoundArray(d.decodeOperand(), d.decodeOperand(), d.decodeBoolean());
case COMPOUND_STRING: return decodeCompoundString();
case CURRENT_SCOPE: return new CurrentScope(d.decodeScope());
Expand Down
44 changes: 31 additions & 13 deletions core/src/main/java/org/jruby/ir/persistence/OperandEncoderMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@
import org.jruby.ir.operands.Backref;
import org.jruby.ir.operands.BacktickString;
import org.jruby.ir.operands.Bignum;
import org.jruby.ir.operands.Boolean;
import org.jruby.ir.operands.ClosureLocalVariable;
import org.jruby.ir.operands.CompoundArray;
import org.jruby.ir.operands.CompoundString;
import org.jruby.ir.operands.CurrentScope;
import org.jruby.ir.operands.DynamicSymbol;
import org.jruby.ir.operands.Fixnum;
import org.jruby.ir.operands.Float;
import org.jruby.ir.operands.GlobalVariable;
import org.jruby.ir.operands.Hash;
import org.jruby.ir.operands.IRException;
Expand All @@ -35,10 +37,14 @@
import org.jruby.ir.operands.StandardError;
import org.jruby.ir.operands.StringLiteral;
import org.jruby.ir.operands.Symbol;
import org.jruby.ir.operands.TemporaryBooleanVariable;
import org.jruby.ir.operands.TemporaryClosureVariable;
import org.jruby.ir.operands.TemporaryFloatVariable;
import org.jruby.ir.operands.TemporaryFixnumVariable;
import org.jruby.ir.operands.TemporaryLocalVariable;
import org.jruby.ir.operands.TemporaryVariable;
import org.jruby.ir.operands.UnboxedFixnum;
import org.jruby.ir.operands.UnboxedFloat;
import org.jruby.ir.operands.UndefinedValue;
import org.jruby.ir.operands.UnexecutableNil;
import org.jruby.ir.operands.WrappedIRClosure;
Expand Down Expand Up @@ -82,9 +88,7 @@ public void encode(Operand operand) {
}
@Override public void Bignum(Bignum bignum) { encoder.encode(bignum.value.toString()); }

@Override public void Boolean(org.jruby.ir.operands.Boolean booleanliteral) { encoder.encode(booleanliteral.isTrue()); }

@Override public void UnboxedBoolean(org.jruby.ir.operands.UnboxedBoolean booleanliteral) { encoder.encode(booleanliteral.isTrue()); }
@Override public void Boolean(Boolean booleanliteral) { encoder.encode(booleanliteral.isTrue()); }

@Override public void ClosureLocalVariable(ClosureLocalVariable variable) {
// We can refigure out closure scope it is in.
Expand Down Expand Up @@ -123,11 +127,7 @@ public void encode(Operand operand) {

@Override public void Fixnum(Fixnum fixnum) { encoder.encode(fixnum.value); }

@Override public void Float(org.jruby.ir.operands.Float flote) { encoder.encode(flote.value); }

@Override public void UnboxedFixnum(UnboxedFixnum fixnum) { encoder.encode(fixnum.value); }

@Override public void UnboxedFloat(org.jruby.ir.operands.UnboxedFloat flote) { encoder.encode(flote.value); }
@Override public void Float(Float flote) { encoder.encode(flote.value); }

@Override public void GlobalVariable(GlobalVariable variable) { encoder.encode(variable.getName()); }

Expand Down Expand Up @@ -190,28 +190,46 @@ public void encode(Operand operand) {

@Override public void Symbol(Symbol symbol) { encoder.encode(symbol.getName()); }

@Override public void TemporaryBooleanVariable(TemporaryBooleanVariable variable) {
encoder.encode((byte) variable.getType().ordinal());
encoder.encode(((TemporaryLocalVariable) variable).getOffset());
}

@Override public void TemporaryFixnumVariable(TemporaryFixnumVariable variable) {
encoder.encode((byte) variable.getType().ordinal());
encoder.encode(variable.getOffset());
}

@Override public void TemporaryFloatVariable(TemporaryFloatVariable variable) {
encoder.encode((byte) variable.getType().ordinal());
encoder.encode(variable.getOffset());
}

@Override public void TemporaryLocalVariable(TemporaryLocalVariable variable) {
TemporaryVariable(variable);
encoder.encode((byte) variable.getType().ordinal());
encoder.encode(variable.getOffset());
}

@Override public void TemporaryVariable(TemporaryVariable variable) {
encoder.encode((byte) variable.getType().ordinal());

switch(variable.getType()) {
case CLOSURE:
encoder.encode(((TemporaryClosureVariable) variable).getClosureId());
encoder.encode(((TemporaryClosureVariable) variable).getOffset());
break;

case FLOAT:
case FIXNUM:
case LOCAL:
case CURRENT_MODULE:
case CURRENT_SCOPE:
encoder.encode(((TemporaryLocalVariable) variable).getOffset());
break;
}
}

@Override public void UnboxedBoolean(org.jruby.ir.operands.UnboxedBoolean booleanliteral) { encoder.encode(booleanliteral.isTrue()); }

@Override public void UnboxedFixnum(UnboxedFixnum fixnum) { encoder.encode(fixnum.value); }

@Override public void UnboxedFloat(UnboxedFloat flote) { encoder.encode(flote.value); }

@Override public void UndefinedValue(UndefinedValue undefinedvalue) {} // No data

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ public Operand createOperandWithParameters(final String operandName, final List<
return createBacktickString(parametersIterator);
case BIGNUM:
return createBignum(parametersIterator);
case BOOLEAN_LITERAL:
case BOOLEAN:
return createBooleanLiteral(parametersIterator);
case COMPOUND_ARRAY:
return createCompoundArray(parametersIterator);
Expand Down

0 comments on commit a9a43e2

Please sign in to comment.