Пример #1
0
        public void StringSplitIteratorIntoOutput_Execute_CorrectResult()
        {
            DfirRoot       function = DfirRoot.Create();
            FunctionalNode stringSliceToStringSplitIterator = new FunctionalNode(function.BlockDiagram, Signatures.StringSliceToStringSplitIteratorType);

            ConnectConstantToInputTerminal(stringSliceToStringSplitIterator.InputTerminals[0], DataTypes.StringSliceType.CreateImmutableReference(), "one two three", false);
            var loop = new Loop(function.BlockDiagram);
            LoopConditionTunnel loopCondition = CreateLoopConditionTunnel(loop);
            IterateTunnel       iterateTunnel = CreateIterateTunnel(loop);

            Wire.Create(function.BlockDiagram, stringSliceToStringSplitIterator.OutputTerminals[0], iterateTunnel.InputTerminals[0])
            .SetWireBeginsMutableVariable(true);
            FunctionalNode output = new FunctionalNode(loop.Diagram, Signatures.OutputType);

            Wire.Create(loop.Diagram, iterateTunnel.OutputTerminals[0], output.InputTerminals[0]);

            TestExecutionInstance executionInstance = CompileAndExecuteFunction(function);

            Assert.AreEqual("three", executionInstance.RuntimeServices.LastOutputValue);
        }
Пример #2
0
        public void FunctionNodeWithImmutableInOutParameter_SetVariableTypes_TrueVariableLifetimeInterruptsCorrectTypes()
        {
            NIType         signatureType  = Signatures.ImmutablePassthroughType;
            DfirRoot       dfirRoot       = DfirRoot.Create();
            FunctionalNode functionalNode = new FunctionalNode(dfirRoot.BlockDiagram, signatureType);

            ConnectConstantToInputTerminal(functionalNode.InputTerminals[0], PFTypes.Int32, false);
            var lifetimeVariableAssociation = new LifetimeVariableAssociation();

            RunSemanticAnalysisUpToSetVariableTypes(dfirRoot, null, null, lifetimeVariableAssociation);

            Lifetime lifetime = functionalNode.InputTerminals[0].GetTrueVariable().Lifetime;

            Assert.IsTrue(lifetime.IsBounded);
            VariableReference inputVariable = functionalNode.InputTerminals[0].GetFacadeVariable();
            IEnumerable <VariableReference> interruptedVariables = lifetimeVariableAssociation.GetVariablesInterruptedByLifetime(lifetime);

            Assert.AreEqual(1, interruptedVariables.Count());
            Assert.AreEqual(inputVariable, interruptedVariables.First());
        }
Пример #3
0
        public void BranchedWire_SetVariableTypes_AllSinkVariablesGetTypes()
        {
            NIType         signatureType = Signatures.MutablePassthroughType;
            DfirRoot       dfirRoot      = DfirRoot.Create();
            FunctionalNode firstSink     = new FunctionalNode(dfirRoot.BlockDiagram, signatureType),
                           secondSink    = new FunctionalNode(dfirRoot.BlockDiagram, signatureType);
            Constant constant            = Constant.Create(dfirRoot.BlockDiagram, 0, PFTypes.Int32);

            constant.OutputTerminal.WireTogether(firstSink.InputTerminals[0], SourceModelIdSource.NoSourceModelId);
            constant.OutputTerminal.WireTogether(secondSink.InputTerminals[0], SourceModelIdSource.NoSourceModelId);

            RunSemanticAnalysisUpToSetVariableTypes(dfirRoot);

            VariableReference firstSinkVariable = firstSink.InputTerminals[0].GetFacadeVariable();

            Assert.IsTrue(firstSinkVariable.Type.IsInt32());
            VariableReference secondSinkVariable = secondSink.InputTerminals[0].GetFacadeVariable();

            Assert.IsTrue(secondSinkVariable.Type.IsInt32());
        }
        public void OpenFileHandleAndWriteString_Execute_FileCreatedWithCorrectContents()
        {
            DfirRoot           function       = DfirRoot.Create();
            FunctionalNode     openFileHandle = new FunctionalNode(function.BlockDiagram, Signatures.OpenFileHandleType);
            string             filePath       = Path.Combine(TestContext.DeploymentDirectory, Path.GetRandomFileName());
            Constant           pathConstant   = ConnectStringConstantToInputTerminal(openFileHandle.InputTerminals[0], filePath);
            Frame              frame          = Frame.Create(function.BlockDiagram);
            UnwrapOptionTunnel unwrapOption   = new UnwrapOptionTunnel(frame);

            Wire.Create(function.BlockDiagram, openFileHandle.OutputTerminals[1], unwrapOption.InputTerminals[0]);
            FunctionalNode writeStringToFileHandle = new FunctionalNode(frame.Diagram, Signatures.WriteStringToFileHandleType);

            Wire.Create(frame.Diagram, unwrapOption.OutputTerminals[0], writeStringToFileHandle.InputTerminals[0]);
            const string data         = "data";
            Constant     dataConstant = ConnectStringConstantToInputTerminal(writeStringToFileHandle.InputTerminals[1], data);

            TestExecutionInstance executionInstance = CompileAndExecuteFunction(function);

            AssertFileExistsAndContainsExpectedData(filePath, data);
        }
Пример #5
0
        public void StructConstructorIntoStructFieldAccessor_Execute_FieldValuesAccessed()
        {
            DfirRoot function = DfirRoot.Create();
            var      structConstructorNode = new StructConstructorNode(function.BlockDiagram, StructType);

            ConnectConstantToInputTerminal(structConstructorNode.InputTerminals[0], NITypes.Int32, 5, false);
            ConnectConstantToInputTerminal(structConstructorNode.InputTerminals[1], NITypes.Boolean, true, false);
            var structFieldAccessor = new StructFieldAccessorNode(function.BlockDiagram, new string[] { "_0", "_1" });

            Wire.Create(function.BlockDiagram, structConstructorNode.OutputTerminals[0], structFieldAccessor.StructInputTerminal);
            FunctionalNode inspect0 = ConnectInspectToOutputTerminal(structFieldAccessor.OutputTerminals[0]);
            FunctionalNode inspect1 = ConnectInspectToOutputTerminal(structFieldAccessor.OutputTerminals[1]);

            TestExecutionInstance executionInstance = CompileAndExecuteFunction(function);

            byte[] inspectValue = executionInstance.GetLastValueFromInspectNode(inspect0);
            AssertByteArrayIsInt32(inspectValue, 5);
            inspectValue = executionInstance.GetLastValueFromInspectNode(inspect1);
            AssertByteArrayIsBoolean(inspectValue, true);
        }
Пример #6
0
        public void LockTunnel_SetVariableTypes_OutputLifetimeHasCorrectInterruptedVariables()
        {
            DfirRoot       function          = DfirRoot.Create();
            Frame          frame             = Frame.Create(function.BlockDiagram);
            var            lockTunnel        = CreateLockTunnel(frame);
            FunctionalNode createLockingCell = ConnectCreateLockingCellToInputTerminal(lockTunnel.InputTerminals[0]);

            ConnectConstantToInputTerminal(createLockingCell.InputTerminals[0], NITypes.Int32, false);
            var lifetimeAssociation = new LifetimeVariableAssociation();

            RunSemanticAnalysisUpToSetVariableTypes(function, null, null, lifetimeAssociation);

            VariableReference lockOutputVariable = lockTunnel.OutputTerminals[0].GetTrueVariable(),
                              lockInputVariable  = lockTunnel.InputTerminals[0].GetTrueVariable();
            Lifetime lifetime = lockOutputVariable.Lifetime;
            IEnumerable <VariableReference> interruptedVariables = lifetimeAssociation.GetVariablesInterruptedByLifetime(lifetime);

            Assert.AreEqual(1, interruptedVariables.Count());
            Assert.AreEqual(lockInputVariable, interruptedVariables.First());
        }
Пример #7
0
        public void FunctionNodeWithSelectReferenceSignatureAndSameLifetimeMutableReferencesWired_SetVariableTypes_SameLifetimeSetOnOutput()
        {
            NIType             signatureType  = Signatures.SelectReferenceType;
            DfirRoot           dfirRoot       = DfirRoot.Create();
            FunctionalNode     functionalNode = new FunctionalNode(dfirRoot.BlockDiagram, signatureType);
            ExplicitBorrowNode borrow         = ConnectExplicitBorrowToInputTerminals(BorrowMode.Mutable, functionalNode.InputTerminals[1], functionalNode.InputTerminals[2]);

            ConnectConstantToInputTerminal(borrow.InputTerminals[0], PFTypes.Int32, true);
            ConnectConstantToInputTerminal(borrow.InputTerminals[1], PFTypes.Int32, true);

            RunSemanticAnalysisUpToSetVariableTypes(dfirRoot);

            Terminal          inputTerminal          = functionalNode.InputTerminals[1];
            Lifetime          inputLifetime          = inputTerminal.GetTrueVariable().Lifetime;
            Terminal          outputTerminal         = functionalNode.OutputTerminals[1];
            VariableReference outputTerminalVariable = outputTerminal.GetTrueVariable();

            Assert.IsTrue(outputTerminalVariable.Type.IsMutableReferenceType());
            Assert.AreEqual(inputLifetime, outputTerminalVariable.Lifetime);
        }
Пример #8
0
        public void CreateParallelYieldPromisesAwaitAndSumResults_ExecutionFinishesAndSumReadFromInspect()
        {
            DfirRoot function   = DfirRoot.Create();
            var      yieldNode0 = new FunctionalNode(function.BlockDiagram, Signatures.YieldType);

            ConnectConstantToInputTerminal(yieldNode0.InputTerminals[0], NITypes.Int32, 5, false);
            var yieldNode1 = new FunctionalNode(function.BlockDiagram, Signatures.YieldType);

            ConnectConstantToInputTerminal(yieldNode1.InputTerminals[0], NITypes.Int32, 6, false);
            var add = new FunctionalNode(function.BlockDiagram, Signatures.DefinePureBinaryFunction("Add", NITypes.Int32, NITypes.Int32));

            Wire.Create(function.BlockDiagram, yieldNode0.OutputTerminals[0], add.InputTerminals[0]);
            Wire.Create(function.BlockDiagram, yieldNode1.OutputTerminals[0], add.InputTerminals[1]);
            FunctionalNode inspect = ConnectInspectToOutputTerminal(add.OutputTerminals[2]);

            TestExecutionInstance executionInstance = CompileAndExecuteFunction(function);

            byte[] inspectValue = executionInstance.GetLastValueFromInspectNode(inspect);
            AssertByteArrayIsInt32(inspectValue, 11);
        }
Пример #9
0
        public void BuildTupleAndDecomposeTupleAsMove_Execute_CorrectElementValues()
        {
            DfirRoot       function   = DfirRoot.Create();
            BuildTupleNode buildTuple = new BuildTupleNode(function.BlockDiagram, 2);

            ConnectConstantToInputTerminal(buildTuple.InputTerminals[0], NITypes.Int32, 1, false);
            ConnectConstantToInputTerminal(buildTuple.InputTerminals[1], NITypes.Boolean, true, false);
            var decomposeTuple = new DecomposeTupleNode(function.BlockDiagram, 2, DecomposeMode.Move);

            Wire.Create(function.BlockDiagram, buildTuple.OutputTerminals[0], decomposeTuple.InputTerminals[0]);
            FunctionalNode inspect0 = ConnectInspectToOutputTerminal(decomposeTuple.OutputTerminals[0]),
                           inspect1 = ConnectInspectToOutputTerminal(decomposeTuple.OutputTerminals[1]);

            TestExecutionInstance executionInstance = CompileAndExecuteFunction(function);

            byte[] inspectValue = executionInstance.GetLastValueFromInspectNode(inspect0);
            AssertByteArrayIsInt32(inspectValue, 1);
            inspectValue = executionInstance.GetLastValueFromInspectNode(inspect1);
            AssertByteArrayIsBoolean(inspectValue, true);
        }
Пример #10
0
        public void VariantConstructorsWithValidFields_Execute_CorrectVariantValue()
        {
            DfirRoot function = DfirRoot.Create();
            var      variantConstructorNodeInt = new VariantConstructorNode(function.BlockDiagram, VariantType, 0);

            ConnectConstantToInputTerminal(variantConstructorNodeInt.InputTerminals[0], NITypes.Int32, 5, false);
            FunctionalNode inspectInt = ConnectInspectToOutputTerminal(variantConstructorNodeInt.VariantOutputTerminal);
            var            variantConstructorNodeBool = new VariantConstructorNode(function.BlockDiagram, VariantType, 1);

            ConnectConstantToInputTerminal(variantConstructorNodeBool.InputTerminals[0], NITypes.Boolean, true, false);
            FunctionalNode inspectBool = ConnectInspectToOutputTerminal(variantConstructorNodeBool.VariantOutputTerminal);

            TestExecutionInstance executionInstance = CompileAndExecuteFunction(function);

            byte[] inspectIntValue = executionInstance.GetLastValueFromInspectNode(inspectInt);
            Assert.AreEqual((byte)0, inspectIntValue[0]);
            Assert.AreEqual(5, BitConverter.ToInt32(inspectIntValue, 1));
            byte[] inspectBoolValue = executionInstance.GetLastValueFromInspectNode(inspectBool);
            Assert.AreEqual((byte)1, inspectBoolValue[0]);
            Assert.AreEqual((byte)1, inspectBoolValue[1]);
        }
Пример #11
0
        public void PanickingUnwrapOptionInsideConditionalFrame_Execute_DownstreamOfFrameDoesNotExecute()
        {
            DfirRoot           function           = DfirRoot.Create();
            Frame              frame              = Frame.Create(function.BlockDiagram);
            UnwrapOptionTunnel unwrapOptionTunnel = CreateUnwrapOptionTunnel(frame);

            ConnectSomeOfIntegerToInputTerminal(unwrapOptionTunnel.InputTerminals[0], 0);
            FunctionalNode unwrap       = CreatePanickingUnwrapOption(frame.Diagram);
            Tunnel         outputTunnel = CreateOutputTunnel(frame);

            Wire.Create(frame.Diagram, unwrap.OutputTerminals[0], outputTunnel.InputTerminals[0]);
            Frame secondaryFrame = Frame.Create(function.BlockDiagram);
            UnwrapOptionTunnel secondaryUnwrapOption = CreateUnwrapOptionTunnel(secondaryFrame);

            Wire.Create(function.BlockDiagram, outputTunnel.OutputTerminals[0], secondaryUnwrapOption.InputTerminals[0]);
            ConnectOutputToOutputTerminal(secondaryUnwrapOption.OutputTerminals[0]);

            TestExecutionInstance executionInstance = CompileAndExecuteFunction(function);

            AssertNoOutput(executionInstance);
        }
Пример #12
0
        public void BranchedStringSliceWire_Execute_BothSinksHaveCorrectValues()
        {
            DfirRoot           function            = DfirRoot.Create();
            Constant           stringSliceConstant = Constant.Create(function.BlockDiagram, "test", DataTypes.StringSliceType.CreateImmutableReference());
            var                inspect1Node        = new FunctionalNode(function.BlockDiagram, Signatures.InspectType);
            ExplicitBorrowNode borrow1             = ConnectExplicitBorrowToInputTerminals(inspect1Node.InputTerminals[0]);
            var                inspect2Node        = new FunctionalNode(function.BlockDiagram, Signatures.InspectType);
            ExplicitBorrowNode borrow2             = ConnectExplicitBorrowToInputTerminals(inspect2Node.InputTerminals[0]);

            Wire.Create(function.BlockDiagram, stringSliceConstant.OutputTerminal, borrow1.InputTerminals[0], borrow2.InputTerminals[0]);

            TestExecutionInstance executionInstance = CompileAndExecuteFunction(function);

            const int stringSliceReferenceSize = 16;

            byte[] inspect1Value = executionInstance.GetLastValueFromInspectNode(inspect1Node);
            Assert.AreEqual(stringSliceReferenceSize, inspect1Value.Length);
            byte[] inspect2Value = executionInstance.GetLastValueFromInspectNode(inspect2Node);
            Assert.AreEqual(stringSliceReferenceSize, inspect2Value.Length);
            Assert.IsTrue(inspect1Value.Zip(inspect2Value, (a, b) => a == b).All(b => b));
        }
Пример #13
0
        public void LoopFollowedByLoop_GroupAsyncStates_SubsequentLoopStartsInPredecessorLoopTerminalGroup()
        {
            DfirRoot     function        = DfirRoot.Create();
            Loop         firstLoop       = new Loop(function.BlockDiagram);
            BorrowTunnel firstLoopBorrow = CreateBorrowTunnel(firstLoop, BorrowMode.Immutable);

            ConnectConstantToInputTerminal(firstLoopBorrow.InputTerminals[0], NITypes.Int32, false);
            TerminateLifetimeTunnel firstLoopTerminate = firstLoopBorrow.TerminateLifetimeTunnel;
            Loop   secondLoop = new Loop(function.BlockDiagram);
            Tunnel loopTunnel = CreateInputTunnel(secondLoop);

            Wire.Create(function.BlockDiagram, firstLoopTerminate.OutputTerminals[0], loopTunnel.InputTerminals[0]);

            IEnumerable <AsyncStateGroup> asyncStateGroups = GroupAsyncStates(function);

            string          terminalGroupName      = $"loop{firstLoop.UniqueId}_terminalGroup";
            AsyncStateGroup firstLoopTerminalGroup = asyncStateGroups.First(g => g.Label == terminalGroupName);
            AsyncStateGroup secondLoopInitialGroup = asyncStateGroups.First(g => g.GroupContainsStructureTraversalPoint(secondLoop, secondLoop.Diagram, StructureTraversalPoint.BeforeLeftBorderNodes));

            Assert.AreEqual(firstLoopTerminalGroup, secondLoopInitialGroup);
        }
Пример #14
0
        public void FrameWithUnwrapOptionTunnelAndNoInteriorAwaits_GroupAsyncStates_AllFrameAsyncStateGroupsInSameFunction()
        {
            DfirRoot           function        = DfirRoot.Create();
            Frame              frame           = Frame.Create(function.BlockDiagram);
            UnwrapOptionTunnel unwrapTunnel    = CreateUnwrapOptionTunnel(frame);
            FunctionalNode     someConstructor = ConnectSomeConstructorToInputTerminal(unwrapTunnel.InputTerminals[0]);

            ConnectConstantToInputTerminal(someConstructor.InputTerminals[0], NITypes.Int32, false);
            var output = new FunctionalNode(frame.Diagram, Signatures.OutputType);

            Wire.Create(frame.Diagram, unwrapTunnel.OutputTerminals[0], output.InputTerminals[0]);

            IEnumerable <AsyncStateGroup> asyncStateGroups = GroupAsyncStates(function);

            AsyncStateGroup frameInitialGroup        = asyncStateGroups.First(g => g.GroupContainsStructureTraversalPoint(frame, frame.Diagram, StructureTraversalPoint.BeforeLeftBorderNodes)),
                            frameDiagramInitialGroup = asyncStateGroups.First(g => g.GroupContainsNode(output)),
                            frameTerminalGroup       = asyncStateGroups.First(g => g.GroupContainsStructureTraversalPoint(frame, frame.Diagram, StructureTraversalPoint.AfterRightBorderNodes));

            Assert.AreEqual(frameInitialGroup.FunctionId, frameDiagramInitialGroup.FunctionId);
            Assert.AreEqual(frameInitialGroup.FunctionId, frameTerminalGroup.FunctionId);
        }
Пример #15
0
        public void UnwrapOptionTunnelWithNoneInput_Execute_FrameDoesNotExecute()
        {
            DfirRoot           function           = DfirRoot.Create();
            FunctionalNode     none               = new FunctionalNode(function.BlockDiagram, Signatures.NoneConstructorType);
            Frame              frame              = Frame.Create(function.BlockDiagram);
            UnwrapOptionTunnel unwrapOptionTunnel = new UnwrapOptionTunnel(frame);

            Wire.Create(function.BlockDiagram, none.OutputTerminals[0], unwrapOptionTunnel.InputTerminals[0]);
            BorrowTunnel borrowTunnel = CreateBorrowTunnel(frame, BorrowMode.Mutable);

            ConnectConstantToInputTerminal(borrowTunnel.InputTerminals[0], NITypes.Int32, true);
            FunctionalNode assign = new FunctionalNode(frame.Diagram, Signatures.AssignType);

            Wire.Create(frame.Diagram, borrowTunnel.OutputTerminals[0], assign.InputTerminals[0]);
            Wire.Create(frame.Diagram, unwrapOptionTunnel.OutputTerminals[0], assign.InputTerminals[1]);
            FunctionalNode inspect = ConnectInspectToOutputTerminal(borrowTunnel.TerminateLifetimeTunnel.OutputTerminals[0]);

            TestExecutionInstance executionInstance = CompileAndExecuteFunction(function);

            byte[] finalValue = executionInstance.GetLastValueFromInspectNode(inspect);
            AssertByteArrayIsInt32(finalValue, 0);
        }
Пример #16
0
        public void ExchangeValuesWithSomeAndNoneInput_Execute_CorrectFinalValues()
        {
            DfirRoot       function       = DfirRoot.Create();
            FunctionalNode exchangeValues = new FunctionalNode(function.BlockDiagram, Signatures.ExchangeValuesType);
            FunctionalNode some           = CreateInt32SomeConstructor(function.BlockDiagram, 5);
            Wire           someWire       = Wire.Create(function.BlockDiagram, some.OutputTerminals[0], exchangeValues.InputTerminals[0]);

            someWire.SetWireBeginsMutableVariable(true);
            FunctionalNode none     = new FunctionalNode(function.BlockDiagram, Signatures.NoneConstructorType);
            Wire           noneWire = Wire.Create(function.BlockDiagram, none.OutputTerminals[0], exchangeValues.InputTerminals[1]);

            noneWire.SetWireBeginsMutableVariable(true);
            FunctionalNode noneInspect = ConnectInspectToOutputTerminal(exchangeValues.OutputTerminals[0]);
            FunctionalNode someInspect = ConnectInspectToOutputTerminal(exchangeValues.OutputTerminals[1]);

            TestExecutionInstance executionInstance = CompileAndExecuteFunction(function);

            byte[] noneInspectValue = executionInstance.GetLastValueFromInspectNode(noneInspect);
            AssertByteArrayIsNoneInteger(noneInspectValue);
            byte[] someInspectValue = executionInstance.GetLastValueFromInspectNode(someInspect);
            AssertByteArrayIsSomeInteger(someInspectValue, 5);
        }
        public void StringReferenceConnectedToStringSliceReferenceInputTerminal_AutomaticNodeInsertion_BorrowNodeAndStringToSliceInserted()
        {
            DfirRoot           function          = DfirRoot.Create();
            FunctionalNode     outputStringOwner = new FunctionalNode(function.BlockDiagram, _outputOwnerStringSignature);
            ExplicitBorrowNode borrow            = new ExplicitBorrowNode(function.BlockDiagram, BorrowMode.Immutable, 1, true, true);

            Wire.Create(function.BlockDiagram, outputStringOwner.OutputTerminals[0], borrow.InputTerminals[0]);
            FunctionalNode concatString = new FunctionalNode(function.BlockDiagram, _stringSlicePassthroughSignature);

            Wire.Create(function.BlockDiagram, borrow.OutputTerminals[0], concatString.InputTerminals[0]);

            RunCompilationUpToAutomaticNodeInsertion(function);

            ExplicitBorrowNode reborrowNode  = AssertDiagramContainsNodeWithSources <ExplicitBorrowNode>(function.BlockDiagram, b => b != borrow, borrow.OutputTerminals[0]);
            FunctionalNode     stringToSlice = AssertDiagramContainsNodeWithSources <FunctionalNode>(function.BlockDiagram, f => f.Signature == Signatures.StringToSliceType, reborrowNode.OutputTerminals[0]);

            Assert.AreEqual(stringToSlice.OutputTerminals[0], concatString.InputTerminals[0].GetImmediateSourceTerminal());
            TerminateLifetimeNode innerTerminateLifetime = AssertDiagramContainsNodeWithSources <TerminateLifetimeNode>(function.BlockDiagram, concatString.OutputTerminals[0]);
            TerminateLifetimeNode outerTerminateLifetime = AssertDiagramContainsNodeWithSources <TerminateLifetimeNode>(function.BlockDiagram, t => t != innerTerminateLifetime, innerTerminateLifetime.OutputTerminals[0]);

            AssertDiagramContainsNodeWithSources <DropNode>(function.BlockDiagram, outerTerminateLifetime.OutputTerminals[0]);
        }
        public void BorrowNodeIntoBorrowNodeWithUnwiredOutput_AutomaticNodeInsertion_TwoTerminateLifetimeNodesInserted()
        {
            DfirRoot           function    = DfirRoot.Create();
            FunctionalNode     outputOwner = new FunctionalNode(function.BlockDiagram, _outputOwnerSignature);
            ExplicitBorrowNode outerBorrow = new ExplicitBorrowNode(function.BlockDiagram, BorrowMode.Immutable, 1, true, true);

            Wire.Create(function.BlockDiagram, outputOwner.OutputTerminals[0], outerBorrow.InputTerminals[0]);
            ExplicitBorrowNode innerBorrow = new ExplicitBorrowNode(function.BlockDiagram, BorrowMode.Immutable, 1, true, true);

            Wire.Create(function.BlockDiagram, outerBorrow.OutputTerminals[0], innerBorrow.InputTerminals[0]);

            RunCompilationUpToAutomaticNodeInsertion(function);

            var innerTerminateLifetime = function.BlockDiagram.Nodes.OfType <TerminateLifetimeNode>().FirstOrDefault(
                t => t.InputTerminals[0].GetImmediateSourceTerminal() == innerBorrow.OutputTerminals[0]);

            Assert.IsNotNull(innerTerminateLifetime);
            var outerTerminateLifetime = function.BlockDiagram.Nodes.OfType <TerminateLifetimeNode>().FirstOrDefault(
                t => t.InputTerminals[0].GetImmediateSourceTerminal() == innerTerminateLifetime.OutputTerminals[0]);

            Assert.IsNotNull(outerTerminateLifetime);
        }
Пример #19
0
        public void UnconsumedTupleVariable_AutomaticNodeInsertion_TupleIsMoveDecomposedAndElementsAreDropped()
        {
            DfirRoot       function   = DfirRoot.Create();
            BuildTupleNode buildTuple = new BuildTupleNode(function.BlockDiagram, 2);

            ConnectConstantToInputTerminal(buildTuple.InputTerminals[0], NITypes.Int32, false);
            ConnectConstantToInputTerminal(buildTuple.InputTerminals[1], NITypes.Boolean, false);

            RunCompilationUpToAutomaticNodeInsertion(function);

            DecomposeTupleNode decomposeTuple = AssertDiagramContainsNodeWithSources <DecomposeTupleNode>(function.BlockDiagram, buildTuple.OutputTerminals[0]);

            Assert.AreEqual(DecomposeMode.Move, decomposeTuple.DecomposeMode);
            AssertVariablesReferenceSame(buildTuple.OutputTerminals[0].GetTrueVariable(), decomposeTuple.InputTerminals[0].GetTrueVariable());
            Assert.AreEqual(2, decomposeTuple.OutputTerminals.Count);
            DropNode drop0 = AssertDiagramContainsNodeWithSources <DropNode>(function.BlockDiagram, decomposeTuple.OutputTerminals[0]);

            AssertDropInputVariableHasType(drop0, NITypes.Int32);
            DropNode drop1 = AssertDiagramContainsNodeWithSources <DropNode>(function.BlockDiagram, decomposeTuple.OutputTerminals[1]);

            AssertDropInputVariableHasType(drop1, NITypes.Boolean);
        }
Пример #20
0
        public void UnwrapOptionTunnelWithNoneInputAndOutputTunnel_Execute_OutputTunnelOutputsNoneValue()
        {
            DfirRoot function           = DfirRoot.Create();
            var      none               = new FunctionalNode(function.BlockDiagram, Signatures.NoneConstructorType);
            Frame    frame              = Frame.Create(function.BlockDiagram);
            var      unwrapOptionTunnel = new UnwrapOptionTunnel(frame);

            Wire.Create(function.BlockDiagram, none.OutputTerminals[0], unwrapOptionTunnel.InputTerminals[0]);
            var assign = new FunctionalNode(frame.Diagram, Signatures.AssignType);

            Wire.Create(frame.Diagram, unwrapOptionTunnel.OutputTerminals[0], assign.InputTerminals[0])
            .SetWireBeginsMutableVariable(true);
            ConnectConstantToInputTerminal(assign.InputTerminals[1], NITypes.Int32, false);
            Tunnel outputTunnel = CreateOutputTunnel(frame);

            ConnectConstantToInputTerminal(outputTunnel.InputTerminals[0], NITypes.Int32, false);
            FunctionalNode inspect = ConnectInspectToOutputTerminal(outputTunnel.OutputTerminals[0]);

            TestExecutionInstance executionInstance = CompileAndExecuteFunction(function);

            byte[] finalValue = executionInstance.GetLastValueFromInspectNode(inspect);
            AssertByteArrayIsNoneInteger(finalValue);
        }
Пример #21
0
        public void BranchedMutableWire_SetVariableTypes_AllSinkVariablesAreMutable()
        {
            NIType         signatureType = Signatures.MutablePassthroughType;
            DfirRoot       dfirRoot      = DfirRoot.Create();
            FunctionalNode firstSink     = new FunctionalNode(dfirRoot.BlockDiagram, signatureType),
                           secondSink    = new FunctionalNode(dfirRoot.BlockDiagram, signatureType);
            Constant constant            = Constant.Create(dfirRoot.BlockDiagram, 0, NITypes.Int32);

            constant.OutputTerminal.WireTogether(firstSink.InputTerminals[0], SourceModelIdSource.NoSourceModelId);
            constant.OutputTerminal.WireTogether(secondSink.InputTerminals[0], SourceModelIdSource.NoSourceModelId);
            Wire branchedWire = (Wire)constant.OutputTerminal.ConnectedTerminal.ParentNode;

            branchedWire.SetWireBeginsMutableVariable(true);

            RunSemanticAnalysisUpToSetVariableTypes(dfirRoot);

            VariableReference firstSinkVariable = firstSink.InputTerminals[0].GetFacadeVariable();

            Assert.IsTrue(firstSinkVariable.Mutable);
            VariableReference secondSinkVariable = secondSink.InputTerminals[0].GetFacadeVariable();

            Assert.IsTrue(secondSinkVariable.Mutable);
        }
Пример #22
0
        public void TerminateLifetimeOnLifetimeContainingVariablesConsumedByUnwrapOptionTunnel_SetVariableTypes_TerminateLifetimeHasNoError()
        {
            DfirRoot           function           = DfirRoot.Create();
            Frame              frame              = Frame.Create(function.BlockDiagram);
            UnwrapOptionTunnel unwrapOptionTunnel = new UnwrapOptionTunnel(frame);
            Tunnel             outputTunnel       = CreateOutputTunnel(frame);

            Wire.Create(frame.Diagram, unwrapOptionTunnel.OutputTerminals[0], outputTunnel.InputTerminals[0]);
            TerminateLifetimeNode terminateLifetime = new TerminateLifetimeNode(function.BlockDiagram, 1, 1);

            Wire.Create(function.BlockDiagram, outputTunnel.OutputTerminals[0], terminateLifetime.InputTerminals[0]);
            FunctionalNode someConstructor = new FunctionalNode(function.BlockDiagram, Signatures.SomeConstructorType);

            Wire.Create(function.BlockDiagram, someConstructor.OutputTerminals[0], unwrapOptionTunnel.InputTerminals[0]);
            ExplicitBorrowNode borrow = ConnectExplicitBorrowToInputTerminals(someConstructor.InputTerminals[0]);

            ConnectConstantToInputTerminal(borrow.InputTerminals[0], PFTypes.Int32, false);

            RunSemanticAnalysisUpToSetVariableTypes(function);

            Assert.AreEqual(TerminateLifetimeErrorState.NoError, terminateLifetime.ErrorState);
            Assert.AreEqual(1, terminateLifetime.OutputTerminals.Count);
        }
Пример #23
0
        public void UnwrapOptionTunnelWithNoneInputAndDroppableInputTunnel_Execute_DroppableValueIsDropped()
        {
            DfirRoot       function = DfirRoot.Create();
            FunctionalNode some     = CreateInt32SomeConstructor(function.BlockDiagram, 0);
            var            none     = new FunctionalNode(function.BlockDiagram, Signatures.NoneConstructorType);
            var            assign   = new FunctionalNode(function.BlockDiagram, Signatures.AssignType);

            Wire.Create(function.BlockDiagram, some.OutputTerminals[0], assign.InputTerminals[0])
            .SetWireBeginsMutableVariable(true);
            Wire.Create(function.BlockDiagram, none.OutputTerminals[0], assign.InputTerminals[1]);
            Frame frame = Frame.Create(function.BlockDiagram);
            var   unwrapOptionTunnel = new UnwrapOptionTunnel(frame);

            Wire.Create(function.BlockDiagram, assign.OutputTerminals[0], unwrapOptionTunnel.InputTerminals[0]);
            FunctionalNode createFakeDrop = CreateFakeDropWithId(function.BlockDiagram, 1);
            Tunnel         inputTunnel    = CreateInputTunnel(frame);

            Wire.Create(function.BlockDiagram, createFakeDrop.OutputTerminals[0], inputTunnel.InputTerminals[0]);

            TestExecutionInstance executionInstance = CompileAndExecuteFunction(function);

            Assert.IsTrue(executionInstance.RuntimeServices.DroppedFakeDropIds.Contains(1), "Expected FakeDrop value to be dropped.");
        }
Пример #24
0
        public void CreateNotifierPairDropNotifierWriterAndGetNotifierValue_Execute_ExecutionFinishesAndNoValueOutput()
        {
            DfirRoot function           = DfirRoot.Create();
            var      createNotifierPair = new FunctionalNode(function.BlockDiagram, Signatures.CreateNotifierPairType);
            var      getNotifierValue   = new FunctionalNode(function.BlockDiagram, Signatures.GetNotifierValueType);

            Wire.Create(function.BlockDiagram, createNotifierPair.OutputTerminals[0], getNotifierValue.InputTerminals[0]);
            FunctionalNode inspect = ConnectInspectToOutputTerminal(getNotifierValue.OutputTerminals[0]);
            // Create a frame that adds to the unwrapped value to coerce it to Int32, even though the value should be None
            Frame frame = Frame.Create(function.BlockDiagram);
            UnwrapOptionTunnel unwrapOption = new UnwrapOptionTunnel(frame);

            Wire.Create(function.BlockDiagram, inspect.OutputTerminals[0], unwrapOption.InputTerminals[0]);
            var add = new FunctionalNode(frame.Diagram, Signatures.DefinePureBinaryFunction("Add", NITypes.Int32, NITypes.Int32));

            Wire.Create(frame.Diagram, unwrapOption.OutputTerminals[0], add.InputTerminals[0]);
            ConnectConstantToInputTerminal(add.InputTerminals[1], NITypes.Int32, 0, false);

            TestExecutionInstance executionInstance = CompileAndExecuteFunction(function);

            byte[] inspectValue = executionInstance.GetLastValueFromInspectNode(inspect);
            AssertByteArrayIsNoneInteger(inspectValue);
        }
Пример #25
0
        public void LifetimeWithLiveVariablesOnMainAndNestedDiagrams_ValidateVariableUsages_TerminateLifetimeNodeHasCorrectInputTerminalCount()
        {
            var signatureBuilder = PFTypes.Factory.DefineFunction("outputString");

            Signatures.AddOutputParameter(signatureBuilder, PFTypes.String, "owner");
            NIType outputOwnerStringSignature = signatureBuilder.CreateType();

            DfirRoot           function     = DfirRoot.Create();
            var                outputString = new FunctionalNode(function.BlockDiagram, outputOwnerStringSignature);
            ExplicitBorrowNode borrow       = new ExplicitBorrowNode(function.BlockDiagram, BorrowMode.Immutable, 1, true, true);

            Wire.Create(function.BlockDiagram, outputString.OutputTerminals[0], borrow.InputTerminals[0]);
            Frame  outerFrame            = Frame.Create(function.BlockDiagram);
            Tunnel outerFrameInputTunnel = CreateInputTunnel(outerFrame);

            Wire.Create(function.BlockDiagram, borrow.OutputTerminals[0], outerFrameInputTunnel.InputTerminals[0]);
            Frame          innerFrame = Frame.Create(outerFrame.Diagram);
            Tunnel         innerFrameInputTunnel = CreateInputTunnel(innerFrame), innerFrameOutputTunnel = CreateOutputTunnel(innerFrame);
            FunctionalNode outerStringToSlice = new FunctionalNode(outerFrame.Diagram, Signatures.StringToSliceType);

            Wire.Create(outerFrame.Diagram, outerFrameInputTunnel.OutputTerminals[0], innerFrameInputTunnel.InputTerminals[0], outerStringToSlice.InputTerminals[0]);
            FunctionalNode innerStringToSlice = new FunctionalNode(innerFrame.Diagram, Signatures.StringToSliceType);

            Wire.Create(innerFrame.Diagram, innerFrameInputTunnel.OutputTerminals[0], innerStringToSlice.InputTerminals[0]);
            Wire.Create(innerFrame.Diagram, innerStringToSlice.OutputTerminals[0], innerFrameOutputTunnel.InputTerminals[0]);
            Tunnel outerFrameOutputTunnel = CreateOutputTunnel(outerFrame);

            Wire.Create(outerFrame.Diagram, outerStringToSlice.OutputTerminals[0], outerFrameOutputTunnel.InputTerminals[0]);
            TerminateLifetimeNode terminateLifetime = new TerminateLifetimeNode(function.BlockDiagram, 1, 1);

            Wire.Create(function.BlockDiagram, outerFrameOutputTunnel.OutputTerminals[0], terminateLifetime.InputTerminals[0]);

            RunSemanticAnalysisUpToValidation(function);

            Assert.AreEqual(2, terminateLifetime.InputTerminals.Count);
        }
Пример #26
0
        public void CreateSharedAndCloneAndDereferenceBothCopies_Execute_CorrectDereferencedValues()
        {
            DfirRoot       function     = DfirRoot.Create();
            FunctionalNode createShared = new FunctionalNode(function.BlockDiagram, Signatures.SharedCreateType);

            ConnectConstantToInputTerminal(createShared.InputTerminals[0], NITypes.Int32, 5, false);
            FunctionalNode createCopy = new FunctionalNode(function.BlockDiagram, Signatures.CreateCopyType);

            Wire.Create(function.BlockDiagram, createShared.OutputTerminals[0], createCopy.InputTerminals[0]);
            FunctionalNode getCellValue0 = new FunctionalNode(function.BlockDiagram, Signatures.SharedGetValueType),
                           getCellValue1 = new FunctionalNode(function.BlockDiagram, Signatures.SharedGetValueType);

            Wire.Create(function.BlockDiagram, createCopy.OutputTerminals[0], getCellValue0.InputTerminals[0]);
            Wire.Create(function.BlockDiagram, createCopy.OutputTerminals[1], getCellValue1.InputTerminals[0]);
            FunctionalNode inspect0 = ConnectInspectToOutputTerminal(getCellValue0.OutputTerminals[0]),
                           inspect1 = ConnectInspectToOutputTerminal(getCellValue1.OutputTerminals[0]);

            TestExecutionInstance executionInstance = CompileAndExecuteFunction(function);

            byte[] inspectValue = executionInstance.GetLastValueFromInspectNode(inspect0);
            AssertByteArrayIsInt32(inspectValue, 5);
            inspectValue = executionInstance.GetLastValueFromInspectNode(inspect1);
            AssertByteArrayIsInt32(inspectValue, 5);
        }
Пример #27
0
        public void PanickingMethodCallWithInputAndOutputThatPanicsIntoOutput_Execute_NoOutputValue()
        {
            using (FeatureToggleSupport.TemporarilyEnableFeature(RebarFeatureToggles.ParametersAndCalls))
            {
                string calleeName = "callee";
                NIType calleeType = DefineFunctionTypeWithOptionIntInAndIntOut(calleeName);
                CompilableDefinitionName calleeDefinitionName = CreateTestCompilableDefinitionName(calleeName);
                DfirRoot       calleeFunction     = calleeType.CreateFunctionFromSignature(calleeDefinitionName);
                DataAccessor   inputDataAccessor  = DataAccessor.Create(calleeFunction.BlockDiagram, calleeFunction.DataItems[0], Direction.Output);
                DataAccessor   outputDataAccessor = DataAccessor.Create(calleeFunction.BlockDiagram, calleeFunction.DataItems[1], Direction.Input);
                FunctionalNode unwrap             = new FunctionalNode(calleeFunction.BlockDiagram, Signatures.UnwrapOptionType);
                Wire.Create(calleeFunction.BlockDiagram, inputDataAccessor.Terminal, unwrap.InputTerminals[0]);
                Wire.Create(calleeFunction.BlockDiagram, unwrap.OutputTerminals[0], outputDataAccessor.Terminal);
                DfirRoot       callerFunction = DfirRoot.Create();
                var            methodCall     = new MethodCallNode(callerFunction.BlockDiagram, calleeDefinitionName, calleeType);
                FunctionalNode noneInteger    = CreateNoneOfOptionIntegerType(callerFunction.BlockDiagram);
                Wire.Create(callerFunction.BlockDiagram, noneInteger.OutputTerminals[0], methodCall.InputTerminals[0]);
                ConnectOutputToOutputTerminal(methodCall.OutputTerminals[0]);

                TestExecutionInstance executionInstance = CompileAndExecuteFunction(callerFunction, calleeFunction);

                AssertNoOutput(executionInstance);
            }
        }
Пример #28
0
        public void TerminateLifetimeOnLifetimeContainingVariablesConsumedByTunnel_SetVariableTypes_TerminateLifetimeHasNoError()
        {
            DfirRoot function = DfirRoot.Create();
            TerminateLifetimeNode terminateLifetime = new TerminateLifetimeNode(function.BlockDiagram, 1, 1);
            Frame          frame           = Frame.Create(function.BlockDiagram);
            Tunnel         inputTunnel1    = CreateInputTunnel(frame);
            Tunnel         inputTunnel2    = CreateInputTunnel(frame);
            Tunnel         outputTunnel    = CreateOutputTunnel(frame);
            FunctionalNode selectReference = new FunctionalNode(frame.Diagram, Signatures.SelectReferenceType);

            Wire.Create(frame.Diagram, inputTunnel1.OutputTerminals[0], selectReference.InputTerminals[1]);
            Wire.Create(frame.Diagram, inputTunnel2.OutputTerminals[0], selectReference.InputTerminals[2]);
            Wire.Create(frame.Diagram, selectReference.OutputTerminals[1], outputTunnel.InputTerminals[0]);
            Wire.Create(function.BlockDiagram, outputTunnel.OutputTerminals[0], terminateLifetime.InputTerminals[0]);
            ExplicitBorrowNode borrow = ConnectExplicitBorrowToInputTerminals(inputTunnel1.InputTerminals[0], inputTunnel2.InputTerminals[0]);

            ConnectConstantToInputTerminal(borrow.InputTerminals[0], PFTypes.Int32, false);
            ConnectConstantToInputTerminal(borrow.InputTerminals[1], PFTypes.Int32, false);

            RunSemanticAnalysisUpToSetVariableTypes(function);

            Assert.AreEqual(TerminateLifetimeErrorState.NoError, terminateLifetime.ErrorState);
            Assert.AreEqual(2, terminateLifetime.OutputTerminals.Count);
        }
 public void ExchangeValuesNode_FullyCompile()
 {
     DfirRoot       function       = DfirRoot.Create();
     FunctionalNode exchangeValues = new FunctionalNode(function.BlockDiagram, Signatures.ExchangeValuesType);
 }