コード例 #1
0
        public void InitializeVectorAndSumWithSliceIterator_Execute_CorrectSumValue()
        {
            DfirRoot       function         = DfirRoot.Create();
            FunctionalNode initializeVector = CreateInitializeVectorWithIntegerConstants(function.BlockDiagram, 4, 4);
            FunctionalNode vectorToSlice    = new FunctionalNode(function.BlockDiagram, Signatures.VectorToSliceType);

            Wire.Create(function.BlockDiagram, initializeVector.OutputTerminals[0], vectorToSlice.InputTerminals[0]);
            FunctionalNode sliceToIterator = new FunctionalNode(function.BlockDiagram, Signatures.SliceToIteratorType);

            Wire.Create(function.BlockDiagram, vectorToSlice.OutputTerminals[0], sliceToIterator.InputTerminals[0]);
            Loop loop = new Loop(function.BlockDiagram);

            CreateLoopConditionTunnel(loop);
            IterateTunnel iterateTunnel = CreateIterateTunnel(loop);
            BorrowTunnel  borrowTunnel  = CreateBorrowTunnel(loop, BorrowMode.Mutable);

            ConnectConstantToInputTerminal(borrowTunnel.InputTerminals[0], NITypes.Int32, 0, true);
            Wire.Create(function.BlockDiagram, sliceToIterator.OutputTerminals[0], iterateTunnel.InputTerminals[0])
            .SetWireBeginsMutableVariable(true);
            FunctionalNode accumulateAdd = new FunctionalNode(loop.Diagrams[0], Signatures.DefineMutatingBinaryFunction("AccumulateAdd", NITypes.Int32));

            Wire.Create(loop.Diagrams[0], borrowTunnel.OutputTerminals[0], accumulateAdd.InputTerminals[0]);
            Wire.Create(loop.Diagrams[0], iterateTunnel.OutputTerminals[0], accumulateAdd.InputTerminals[1]);
            FunctionalNode inspectNode = ConnectInspectToOutputTerminal(borrowTunnel.TerminateLifetimeTunnel.OutputTerminals[0]);

            TestExecutionInstance executionInstance = CompileAndExecuteFunction(function);

            byte[] inspectValue = executionInstance.GetLastValueFromInspectNode(inspectNode);
            AssertByteArrayIsInt32(inspectValue, 16);
        }
コード例 #2
0
        public void SumItemsFromRangeIterator_Execute_CorrectFinalResult()
        {
            DfirRoot            function        = DfirRoot.Create();
            Loop                loop            = new Loop(function.BlockDiagram);
            LoopConditionTunnel conditionTunnel = CreateLoopConditionTunnel(loop);
            IterateTunnel       iterateTunnel   = CreateIterateTunnel(loop);
            FunctionalNode      range           = new FunctionalNode(function.BlockDiagram, Signatures.RangeType);
            Wire                rangeWire       = Wire.Create(function.BlockDiagram, range.OutputTerminals[0], iterateTunnel.InputTerminals[0]);

            rangeWire.SetWireBeginsMutableVariable(true);
            Constant       lowConstant        = ConnectConstantToInputTerminal(range.InputTerminals[0], NITypes.Int32, 0, false);
            Constant       highConstant       = ConnectConstantToInputTerminal(range.InputTerminals[1], NITypes.Int32, 10, false);
            BorrowTunnel   borrow             = CreateBorrowTunnel(loop, BorrowMode.Mutable);
            Constant       accumulateConstant = ConnectConstantToInputTerminal(borrow.InputTerminals[0], NITypes.Int32, 0, true);
            FunctionalNode accumulateAdd      = new FunctionalNode(loop.Diagram, Signatures.DefineMutatingBinaryFunction("AccumulateAdd", NITypes.Int32));

            Wire.Create(loop.Diagram, borrow.OutputTerminals[0], accumulateAdd.InputTerminals[0]);
            Wire.Create(loop.Diagram, iterateTunnel.OutputTerminals[0], accumulateAdd.InputTerminals[1]);
            FunctionalNode inspect = ConnectInspectToOutputTerminal(borrow.TerminateLifetimeTunnel.OutputTerminals[0]);

            TestExecutionInstance executionInstance = CompileAndExecuteFunction(function);

            byte[] inspectValue = executionInstance.GetLastValueFromInspectNode(inspect);
            AssertByteArrayIsInt32(inspectValue, 45);
        }
コード例 #3
0
        public void FillVectorEnoughToGrowItThenRemoveAllElements_Execute_AllElementsPreservedAndRemoved()
        {
            DfirRoot function     = DfirRoot.Create();
            var      createVector = new FunctionalNode(function.BlockDiagram, Signatures.VectorCreateType);
            Loop     firstLoop    = new Loop(function.BlockDiagram);

            CreateLoopConditionTunnel(firstLoop);
            BorrowTunnel firstLoopBorrowTunnel = CreateBorrowTunnel(firstLoop, BorrowMode.Mutable);

            Wire.Create(function.BlockDiagram, createVector.OutputTerminals[0], firstLoopBorrowTunnel.InputTerminals[0])
            .SetWireBeginsMutableVariable(true);
            IterateTunnel iterateTunnel  = CreateRangeAndIterateTunnel(firstLoop, 1, 7);
            var           appendToVector = new FunctionalNode(firstLoop.Diagram, Signatures.VectorAppendType);

            Wire.Create(firstLoop.Diagram, firstLoopBorrowTunnel.OutputTerminals[0], appendToVector.InputTerminals[0]);
            Wire.Create(firstLoop.Diagram, iterateTunnel.OutputTerminals[0], appendToVector.InputTerminals[1]);
            Loop secondLoop = new Loop(function.BlockDiagram);

            CreateLoopConditionTunnel(secondLoop);
            BorrowTunnel secondLoopBorrowTunnel = CreateBorrowTunnel(secondLoop, BorrowMode.Mutable);

            Wire.Create(function.BlockDiagram, firstLoopBorrowTunnel.TerminateLifetimeTunnel.OutputTerminals[0], secondLoopBorrowTunnel.InputTerminals[0]);
            CreateRangeAndIterateTunnel(secondLoop, 1, 7);
            var removeLastFromVector = new FunctionalNode(secondLoop.Diagram, Signatures.VectorRemoveLastType);

            Wire.Create(secondLoop.Diagram, secondLoopBorrowTunnel.OutputTerminals[0], removeLastFromVector.InputTerminals[0]);
            BorrowTunnel resultBorrowTunnel = CreateBorrowTunnel(secondLoop, BorrowMode.Mutable);

            ConnectConstantToInputTerminal(resultBorrowTunnel.InputTerminals[0], NITypes.Int32, 0, true);
            Frame unwrapFrame = Frame.Create(secondLoop.Diagram);
            UnwrapOptionTunnel unwrapTunnel = CreateUnwrapOptionTunnel(unwrapFrame);

            Wire.Create(secondLoop.Diagram, removeLastFromVector.OutputTerminals[1], unwrapTunnel.InputTerminals[0]);
            Tunnel inputTunnel = CreateInputTunnel(unwrapFrame);

            Wire.Create(secondLoop.Diagram, resultBorrowTunnel.OutputTerminals[0], inputTunnel.InputTerminals[0]);
            var accumulateAdd = new FunctionalNode(unwrapFrame.Diagram, Signatures.DefineMutatingBinaryFunction("AccumulateAdd", NITypes.Int32));

            Wire.Create(unwrapFrame.Diagram, inputTunnel.OutputTerminals[0], accumulateAdd.InputTerminals[0]);
            Wire.Create(unwrapFrame.Diagram, unwrapTunnel.OutputTerminals[0], accumulateAdd.InputTerminals[1]);
            FunctionalNode inspect = ConnectInspectToOutputTerminal(resultBorrowTunnel.TerminateLifetimeTunnel.OutputTerminals[0]);

            TestExecutionInstance executionInstance = CompileAndExecuteFunction(function);

            byte[] inspectValue = executionInstance.GetLastValueFromInspectNode(inspect);
            AssertByteArrayIsInt32(inspectValue, 21);
        }
コード例 #4
0
 public void AccumulateDivideTwoI32s_Execute_CorrectResultValue()
 {
     TestMutatingBinaryI32Operation(Signatures.DefineMutatingBinaryFunction("AccumulateDivide", PFTypes.Int32), 6, 5, 1);
 }
コード例 #5
0
ファイル: Functions.cs プロジェクト: rebarlang/rebar
 protected MutatingBinaryPrimitive(BinaryPrimitiveOps binaryOp)
     : base(Signatures.DefineMutatingBinaryFunction("Accumulate" + binaryOp.ToString(), binaryOp.GetExpectedInputType()))
 {
 }
コード例 #6
0
 public void AccumulateXorTwoBooleans_Execute_CorrectResultValue()
 {
     TestMutatingBinaryBooleanOperation(Signatures.DefineMutatingBinaryFunction("AccumulateXor", NITypes.Boolean), true, false, true);
 }
コード例 #7
0
 public void AccumulateMultiplyTwoI32s_Execute_CorrectResultValue()
 {
     TestMutatingBinaryI32Operation(Signatures.DefineMutatingBinaryFunction("AccumulateMultiply", NITypes.Int32), 6, 5, 30);
 }