public static InstructionNode UncodifyInstructionFormat( int number, Var var) { if (number < 0) { throw new InvalidOperationException(); } InstructionNode fakeInstruction; if (number == 0) { fakeInstruction = new UnaryExpressionInstructionNode( var.ToString(), -1); } else if (number == 1 || number == 2) { fakeInstruction = new BinaryExpressionInstructionNode( var.ToString(), number == 1 ? "+" : "-"); } else { var codifiedLabel = number - 2; var label = UncodifyLabel(codifiedLabel); fakeInstruction = new ConditionalInstructionNode( var.ToString(), label.ToString(), -1); } return(fakeInstruction); }
public void Instruction() { var instruction = new BinaryExpressionInstructionNode("X", "+") { Label = new Label("A") }; AssertEqualCodified(instruction, 21); }
private static void StepBinaryExpression(BinaryExpressionInstructionNode binaryExpression) { var targetVar = GetTargetVar(binaryExpression.Var.Type); var index = GetNormalizedIndex(binaryExpression); switch (binaryExpression.Operator) { case BinaryExpressionInstructionNode.OperatorEnum.Increment: targetVar[index] += 1; break; case BinaryExpressionInstructionNode.OperatorEnum.Decrement: if (targetVar[index] > 0) { targetVar[index] -= 1; } break; default: throw new InvalidOperationException(); } }
public void DecrementBinaryExpressionInstructionFormat() { var instruction = new BinaryExpressionInstructionNode("X", "-"); AssertEqualCodifiedFormat(instruction, 2); }