Exemplo n.º 1
0
        public ForLoopNode() : base(NodeType.FlowControl)
        {
            this.Name = "For Loop";

            LoopBodyFlow = new CodeGenListInputViewModel <IStatement>(PortType.Execution)
            {
                Name = "Loop Body"
            };
            this.Inputs.Add(LoopBodyFlow);

            LoopEndFlow = new CodeGenListInputViewModel <IStatement>(PortType.Execution)
            {
                Name = "Loop End"
            };
            this.Inputs.Add(LoopEndFlow);

            FirstIndex = new CodeGenInputViewModel <ITypedExpression <int> >(PortType.Integer)
            {
                Name = "First Index"
            };
            this.Inputs.Add(FirstIndex);

            LastIndex = new CodeGenInputViewModel <ITypedExpression <int> >(PortType.Integer)
            {
                Name = "Last Index"
            };
            this.Inputs.Add(LastIndex);

            CurrentIndex = new CodeGenOutputViewModel <VariableReference <int> >(PortType.Integer)
            {
                Name = "Current Index"
            };
            this.Outputs.Add(CurrentIndex);

            var loopBodyChanged = LoopBodyFlow.Values.Changed.Select(_ => Unit.Default).StartWith(Unit.Default);
            var loopEndChanged  = LoopEndFlow.Values.Changed.Select(_ => Unit.Default).StartWith(Unit.Default);

            FlowIn = new CodeGenOutputViewModel <IStatement>(PortType.Execution)
            {
                Name  = "",
                Value = Observable.CombineLatest(loopBodyChanged, loopEndChanged, FirstIndex.ValueChanged, LastIndex.ValueChanged,
                                                 (bodyChange, endChange, firstI, lastI) => (BodyChange: bodyChange, EndChange: endChange, FirstI: firstI, LastI: lastI))
                        .Select(v => new ForLoop
                {
                    LoopBody   = new StatementSequence(LoopBodyFlow.Values),
                    LoopEnd    = new StatementSequence(LoopEndFlow.Values),
                    LowerBound = v.FirstI ?? new IntLiteral {
                        Value = 0
                    },
                    UpperBound = v.LastI ?? new IntLiteral {
                        Value = 1
                    }
                })
            };
            this.Outputs.Add(FlowIn);
        }
    }
Exemplo n.º 2
0
        public ForLoopNode() : base(NodeType.FlowControl)
        {
            var boundsGroup = new EndpointGroup("Bounds");

            var controlFlowGroup = new EndpointGroup("Control Flow");

            var controlFlowInputsGroup = new EndpointGroup(controlFlowGroup);

            this.Name = "For Loop";

            LoopBodyFlow = new CodeGenListInputViewModel <IStatement>(PortType.Execution)
            {
                Name  = "Loop Body",
                Group = controlFlowInputsGroup
            };
            this.Inputs.Add(LoopBodyFlow);

            LoopEndFlow = new CodeGenListInputViewModel <IStatement>(PortType.Execution)
            {
                Name  = "Loop End",
                Group = controlFlowInputsGroup
            };
            this.Inputs.Add(LoopEndFlow);


            FirstIndex = new CodeGenInputViewModel <ITypedExpression <int> >(PortType.Integer)
            {
                Name  = "First Index",
                Group = boundsGroup
            };
            this.Inputs.Add(FirstIndex);

            LastIndex = new CodeGenInputViewModel <ITypedExpression <int> >(PortType.Integer)
            {
                Name  = "Last Index",
                Group = boundsGroup
            };
            this.Inputs.Add(LastIndex);

            ForLoop value = new ForLoop();

            var loopBodyChanged = LoopBodyFlow.Values.Connect().Select(_ => Unit.Default).StartWith(Unit.Default);
            var loopEndChanged  = LoopEndFlow.Values.Connect().Select(_ => Unit.Default).StartWith(Unit.Default);

            FlowIn = new CodeGenOutputViewModel <IStatement>(PortType.Execution)
            {
                Name  = "",
                Value = Observable.CombineLatest(loopBodyChanged, loopEndChanged, FirstIndex.ValueChanged, LastIndex.ValueChanged,
                                                 (bodyChange, endChange, firstI, lastI) => (BodyChange: bodyChange, EndChange: endChange, FirstI: firstI, LastI: lastI))
                        .Select(v => {
                    value.LoopBody   = new StatementSequence(LoopBodyFlow.Values.Items);
                    value.LoopEnd    = new StatementSequence(LoopEndFlow.Values.Items);
                    value.LowerBound = v.FirstI ?? new IntLiteral {
                        Value = 0
                    };
                    value.UpperBound = v.LastI ?? new IntLiteral {
                        Value = 1
                    };
                    return(value);
                }),
                Group = controlFlowGroup
            };
            this.Outputs.Add(FlowIn);

            CurrentIndex = new CodeGenOutputViewModel <ITypedExpression <int> >(PortType.Integer)
            {
                Name  = "Current Index",
                Value = Observable.Return(new VariableReference <int> {
                    LocalVariable = value.CurrentIndex
                })
            };
            this.Outputs.Add(CurrentIndex);
        }
    }