Ejemplo n.º 1
0
 /// <summary>
 /// Validates the watch content with the source nodes output.
 /// </summary>
 /// <param name="watch">WatchViewModel of the watch node</param>
 /// <param name="sourceNode">NodeModel for source to watch node</param>
 public void AssertWatchContent(WatchViewModel watch, NodeModel sourceNode)
 {
     string var = sourceNode.GetAstIdentifierForOutputIndex(0).Name;
     RuntimeMirror mirror = null;
     Assert.DoesNotThrow(() => mirror = ViewModel.Model.EngineController.GetMirror(var));
     Assert.IsNotNull(mirror);
     AssertWatchContent(watch, mirror.GetData());
 }
Ejemplo n.º 2
0
        protected override void BuildAstForPartialMultiOutput(
            NodeModel model, AssociativeNode rhs, List<AssociativeNode> resultAst)
        {
            base.BuildAstForPartialMultiOutput(model, rhs, resultAst);

            var emptyList = AstFactory.BuildExprList(new List<AssociativeNode>());
            var previewIdInit = AstFactory.BuildAssignment(model.AstIdentifierForPreview, emptyList);

            resultAst.Add(previewIdInit);
            resultAst.AddRange(
                Definition.ReturnKeys.Select(
                    (rtnKey, idx) =>
                        AstFactory.BuildAssignment(
                            AstFactory.BuildIdentifier(
                                model.AstIdentifierForPreview.Name,
                                AstFactory.BuildStringNode(rtnKey)),
                            model.GetAstIdentifierForOutputIndex(idx))));
        }
Ejemplo n.º 3
0
 /// <summary>
 ///     Produces AST for a partial function application of a multi-output function.
 /// </summary>
 /// <param name="model">NodeModel to produce AST for.</param>
 /// <param name="rhs">AST representing the partial application. This will need to be used to assign all output port identifiers.</param>
 /// <param name="resultAst">Result accumulator: add all new output AST to this list.</param>
 protected virtual void BuildAstForPartialMultiOutput(
     NodeModel model, AssociativeNode rhs, List<AssociativeNode> resultAst)
 {
     var missingAmt =
         Enumerable.Range(0, model.InPortData.Count).Count(x => !model.HasInput(x));
     var tmp =
         AstFactory.BuildIdentifier("__partial_" + model.GUID.ToString().Replace('-', '_'));
     resultAst.Add(AstFactory.BuildAssignment(tmp, rhs));
     resultAst.AddRange(
         (Definition.ReturnKeys ?? Enumerable.Empty<string>()).Select(
             AstFactory.BuildStringNode)
             .Select(
                 (rtnKey, index) =>
                     AstFactory.BuildAssignment(
                         model.GetAstIdentifierForOutputIndex(index),
                         AstFactory.BuildFunctionObject(
                             "__ComposeBuffered",
                             3,
                             new[] { 0, 1 },
                             new List<AssociativeNode>
                             {
                                 AstFactory.BuildExprList(
                                     new List<AssociativeNode>
                                     {
                                         AstFactory.BuildFunctionObject(
                                             "__GetOutput",
                                             2,
                                             new[] { 1 },
                                             new List<AssociativeNode>
                                             {
                                                 AstFactory.BuildNullNode(),
                                                 rtnKey
                                             }),
                                         tmp
                                     }),
                                 AstFactory.BuildIntNode(missingAmt),
                                 AstFactory.BuildNullNode()
                             }))));
 }
Ejemplo n.º 4
0
 protected override void AssignIdentifiersForFunctionCall(
     NodeModel model, AssociativeNode rhs, List<AssociativeNode> resultAst)
 {
     if (model.OutPortData.Count == 1)
     {
         resultAst.Add(AstFactory.BuildAssignment(model.AstIdentifierForPreview, rhs));
         resultAst.Add(
             AstFactory.BuildAssignment(
                 model.GetAstIdentifierForOutputIndex(0),
                 model.AstIdentifierForPreview));
     }
     else
         base.AssignIdentifiersForFunctionCall(model, rhs, resultAst);
 }
Ejemplo n.º 5
0
        /// <summary>
        ///     Produces AST that assigns all necessary Identifiers for the given NodeModel from
        ///     the produced function call AST.
        /// </summary>
        /// <param name="model">Model to produce AST for.</param>
        /// <param name="rhs">AST for the function call. This will need to be used to assign all output port identifiers.</param>
        /// <param name="resultAst">Result accumulator: add all new output AST to this list.</param>
        protected virtual void AssignIdentifiersForFunctionCall(NodeModel model, AssociativeNode rhs, List<AssociativeNode> resultAst)
        {
            resultAst.Add(AstFactory.BuildAssignment(model.AstIdentifierForPreview, rhs));

            var keys = Definition.ReturnKeys ?? Enumerable.Empty<string>();
            resultAst.AddRange(
                from item in keys.Zip(Enumerable.Range(0, keys.Count()), (key, idx) => new { key, idx })
                let outputIdentiferNode = model.GetAstIdentifierForOutputIndex(item.idx)
                let outputIdentifier = outputIdentiferNode.ToString()
                let getValueCall = AstFactory.BuildFunctionCall(
                    BuiltInMethods.GetMethodName(BuiltInMethods.MethodID.kTryGetValueFromNestedDictionaries),
                    new List<AssociativeNode> {model.AstIdentifierForPreview, AstFactory.BuildStringNode(item.key)})
                select
                AstFactory.BuildAssignment(outputIdentiferNode, getValueCall));
        }
Ejemplo n.º 6
0
 /// <summary>
 ///     Produces AST that assigns all necessary Identifiers for the given NodeModel from
 ///     the produced function call AST.
 /// </summary>
 /// <param name="model">Model to produce AST for.</param>
 /// <param name="rhs">AST for the function call. This will need to be used to assign all output port identifiers.</param>
 /// <param name="resultAst">Result accumulator: add all new output AST to this list.</param>
 protected virtual void AssignIdentifiersForFunctionCall(NodeModel model, AssociativeNode rhs, List<AssociativeNode> resultAst)
 {
     resultAst.Add(AstFactory.BuildAssignment(model.AstIdentifierForPreview, rhs));
     resultAst.AddRange(
         (from item in
                 (Definition.ReturnKeys ?? Enumerable.Empty<string>()).Select(
                     (key, idx) => new { key, idx })
             let outputIdentiferNode = model.GetAstIdentifierForOutputIndex(item.idx)
             let outputIdentifier = outputIdentiferNode.ToString()
             let thisIdentifierNode =
             AstFactory.BuildIdentifier(
                 model.AstIdentifierForPreview.Name,
                 AstFactory.BuildStringNode(item.key))
             let thisIdentifier = thisIdentifierNode.ToString()
             where !string.Equals(outputIdentifier, thisIdentifier)
             select
             AstFactory.BuildAssignment(outputIdentiferNode, thisIdentifierNode)));
 }