public override Expression Compile() { var left = LeftNode.Accept(Compiler); var right = RightNode.Accept(Compiler); if (left.NodeType == ExpressionType.Constant) { var value = (iObject)((ConstantExpression)left).Value; return(SelectBody(Object.ToBool(value), left, right)); } if (left.NodeType == ExpressionType.Parameter) { return(MakeCondition(CompilerUtils.ToBool(left), left, right)); } var leftVar = Variable(typeof(iObject)); return(Block( typeof(iObject), new[] { leftVar }, Assign(leftVar, left), MakeCondition(CompilerUtils.ToBool(leftVar), leftVar, right) )); }
private Expression ToBool(Expression condition) { condition = CompilerUtils.ToBool(condition); if (Node.Token.Type == kUNTIL || Node.Token.Type == kUNTIL_MOD) { condition = CompilerUtils.Negate(condition); } return(condition); }
private SwitchCase CompileWhen(SyntaxNode node) { var condition = node[0].Accept(Compiler); condition = CompilerUtils.ToBool(condition); var body = node[1].Accept(Compiler); return(SwitchCase(body, condition)); }
private Expression MakeCondition(Expression condition, Expression trueBody, Expression elseBody) { condition = CompilerUtils.ToBool(condition); if (Node.Token.Type == kUNLESS || Node.Token.Type == kUNLESS_MOD) { condition = CompilerUtils.Negate(condition); } return(Condition(condition, trueBody, elseBody, typeof(iObject))); }
private SwitchCase CompileWhen(SyntaxNode node, Expression caseValue, CallSite callSite) { var instance = node[0].Accept(Compiler); var arguments = NewArrayInit(typeof(iObject), caseValue); Expression condition = CallSite.Expressions.Call(Constant(callSite), instance, arguments); condition = CompilerUtils.ToBool(condition); var body = node[1].Accept(Compiler); return(SwitchCase(body, condition)); }
public Expression Compile(AssignCompiler component) { var getter = Variable(typeof(iObject), "getter"); var setter = component.Setter(component.Right); var condition = CompilerUtils.ToBool(getter); return(Block( typeof(iObject), new[] { getter }, Assign(getter, component.Getter), MakeCondition(condition, getter, setter) )); }
public override Expression Compile() { var condition = Operand.Accept(Compiler); if (condition.NodeType == ExpressionType.Constant) { var conditionValue = (iObject)((ConstantExpression)condition).Value; return(Object.ToBool(conditionValue) ? FalseClass.Expressions.Instance : TrueClass.Expressions.Instance); } condition = CompilerUtils.ToBool(condition); return(Condition( condition, FalseClass.Expressions.Instance, TrueClass.Expressions.Instance, typeof(iObject) )); }