Exemplo n.º 1
0
        private IfBranch(IExpression condition, IEnumerable <IExpression> body, IfBranch next)
        {
            this.condition = condition;
            // we have to postpone calculating read-mode because the last instruction can be function call
            // and it is resolved only after finding its target
            if (!body.Any())
            {
                body = new[] { UnitLiteral.Create() }
            }
            ;
            this.Body = Block.Create((block) => block.Instructions.Last().ReadMode, body);
            this.Next = next;

            this.attachPostConstructor();

            this.flow = Later.Create(() => this.IsElse
                ? ExecutionFlow.CreateElse(Body, Next) : ExecutionFlow.CreateFork(Condition, Body, Next));
        }
Exemplo n.º 2
0
        private BoolOperator(OpMode mode, IExpression lhs, IExpression rhs)
            : base(ExpressionReadMode.ReadRequired)
        {
            this.Mode = mode;
            this.lhs  = lhs;
            this.rhs  = rhs;

            this.attachPostConstructor();

            this.flow = Later.Create(() =>
            {
                switch (this.Mode)
                {
                case OpMode.And: return(ExecutionFlow.CreateFork(Lhs, Rhs, null));

                case OpMode.Or: return(ExecutionFlow.CreateFork(Lhs, null, Rhs));

                default: throw new InvalidOperationException();
                }
            });
        }