Skip to content

Instantly share code, notes, and snippets.

@otf
Created April 16, 2013 11:30
Show Gist options
  • Save otf/5395241 to your computer and use it in GitHub Desktop.
Save otf/5395241 to your computer and use it in GitHub Desktop.
最適化されたAndAlsoとOrElseを正しく解釈する
Instruction ConditionalBranch(Instruction instruction, Func<Expression, BinaryExpression> condition)
{
var val1 = stack.Pop();
var test = condition(val1);
var left = (Instruction)instruction.Operand;
var right = instruction.Next;
Instruction common = GetJoinPoint(left, right);
var rightExpression = Clone().Process(right, common);
var leftExpression = AdjustType(Clone().Process(left, common), rightExpression.Type);
var expression = BuildConditionalBranch(test, val1, leftExpression, rightExpression);
stack.Push(expression);
// ここをs追加
if (expression.NodeType == ExpressionType.AndAlso || expression.NodeType == ExpressionType.OrElse)
while (common.OpCode != OpCodes.Ret) common = common.Next;
// ここまで
return common;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment