示例#1
0
        private void EmitRangeExprNode(AST.AssociativeAST.RangeExprNode rangeExprNode)
        {
            Validity.Assert(null != rangeExprNode);
            if (rangeExprNode.FromNode is AST.AssociativeAST.IntNode)
            {
                EmitCode((rangeExprNode.FromNode as AST.AssociativeAST.IntNode).value);
            }
            else if (rangeExprNode.FromNode is AST.AssociativeAST.IdentifierNode)
            {
                EmitCode((rangeExprNode.FromNode as AST.AssociativeAST.IdentifierNode).Value);
            }
            EmitCode("..");

            if (rangeExprNode.ToNode is AST.AssociativeAST.IntNode)
            {
                EmitCode((rangeExprNode.ToNode as AST.AssociativeAST.IntNode).value);
            }
            else if (rangeExprNode.ToNode is AST.AssociativeAST.IdentifierNode)
            {
                EmitCode((rangeExprNode.ToNode as AST.AssociativeAST.IdentifierNode).Value);
            }

            if (rangeExprNode.StepNode != null)
            {
                EmitCode("..");
                if (rangeExprNode.stepoperator == ProtoCore.DSASM.RangeStepOperator.num)
                {
                    EmitCode("#");
                }
                if (rangeExprNode.StepNode is AST.AssociativeAST.IntNode)
                {
                    EmitCode((rangeExprNode.StepNode as AST.AssociativeAST.IntNode).value);
                }
                else if (rangeExprNode.StepNode is AST.AssociativeAST.IdentifierNode)
                {
                    EmitCode((rangeExprNode.StepNode as AST.AssociativeAST.IdentifierNode).Value);
                }
            }
        }
示例#2
0
        public void GraphILTest_ComplexWatch01()
        {
            // Build the AST trees
            // x = 1..10;
            ProtoCore.AST.AssociativeAST.RangeExprNode rangeExpr = new ProtoCore.AST.AssociativeAST.RangeExprNode();
            rangeExpr.FromNode = new ProtoCore.AST.AssociativeAST.IntNode(0);
            rangeExpr.ToNode = new ProtoCore.AST.AssociativeAST.IntNode(5);
            rangeExpr.StepNode = new ProtoCore.AST.AssociativeAST.IntNode(1);
            ProtoCore.AST.AssociativeAST.BinaryExpressionNode assign = new ProtoCore.AST.AssociativeAST.BinaryExpressionNode(
                new ProtoCore.AST.AssociativeAST.IdentifierNode("a"),
                rangeExpr,
                ProtoCore.DSASM.Operator.assign);
            List<ProtoCore.AST.AssociativeAST.AssociativeNode> astList = new List<ProtoCore.AST.AssociativeAST.AssociativeNode>();
            astList.Add(assign);

            // Instantiate GraphSyncData
            List<Subtree> addedList = new List<Subtree>();
            addedList.Add(new Subtree(astList, System.Guid.NewGuid()));
            GraphSyncData syncData = new GraphSyncData(null, addedList, null);

            // emit the DS code from the AST tree
            liveRunner = new ProtoScript.Runners.LiveRunner();
            liveRunner.UpdateGraph(syncData);

            ProtoCore.Mirror.RuntimeMirror mirror = liveRunner.InspectNodeValue("a");
            var collection = mirror.GetData().GetElements();
            Assert.IsTrue((Int64)collection[1].Data == 1);
        }
示例#3
0
文件: Parser.cs 项目: limrzx/Dynamo
	void Associative_RangeExpr(out ProtoCore.AST.AssociativeAST.AssociativeNode node) {
		Associative_ArithmeticExpression(out node);
		if (la.kind == 24) {
			ProtoCore.AST.AssociativeAST.RangeExprNode rnode = new ProtoCore.AST.AssociativeAST.RangeExprNode(); 
			rnode.From = node; NodeUtils.SetNodeStartLocation(rnode, node);
			bool hasRangeAmountOperator = false;
			
			Get();
			if (la.kind == 64) {
				Associative_rangeAmountOperator(out hasRangeAmountOperator);
			}
			rnode.HasRangeAmountOperator = hasRangeAmountOperator; 
			Associative_ArithmeticExpression(out node);
			rnode.To = node; 
			NodeUtils.SetNodeEndLocation(rnode, node);
			
			if (la.kind == 24) {
				RangeStepOperator op; 
				Get();
				Associative_rangeStepOperator(out op);
				rnode.StepOperator = op; 
				Associative_ArithmeticExpression(out node);
				rnode.Step = node;
				NodeUtils.SetNodeEndLocation(rnode, node);
				
			}
			node = rnode; 
		}
	}
        private void EmitRangeExpNode(Func node, out AssociativeNode outnode)
        {
            Validity.Assert(node != null);
            Validity.Assert(node.isRange);

            RangeExprNode rangeNode = new RangeExprNode();
            
            // Set FromNode, ToNode, stepOperator and StepNode for rangeNode
            Dictionary<int, Node> nodes = node.GetChildrenWithIndices();
            //int numParams = node.numParameters;

            AssociativeNode startNode = null;
            AssociativeNode endNode = null;
            AssociativeNode stepNode = null;

            if (nodes.Count >= 1)
            {                
                DFSTraverse(nodes[0], out startNode);
            }
            if (nodes.Count >= 2)
            {
                DFSTraverse(nodes[1], out endNode);
            }
            if (nodes.Count >= 3)
            {
                DFSTraverse(nodes[2], out stepNode);
            }
            rangeNode.FromNode = startNode;
            rangeNode.ToNode = endNode;
            rangeNode.StepNode = stepNode;
            
            if (node.Name == "Range.ByIncrementValue")
            {
                rangeNode.stepoperator = ProtoCore.DSASM.RangeStepOperator.stepsize;
            }
            else if (node.Name == "Range.ByIntervals")
            {
                rangeNode.stepoperator = ProtoCore.DSASM.RangeStepOperator.num;
            }
            else
            {
                rangeNode.stepoperator = ProtoCore.DSASM.RangeStepOperator.approxsize;
            }

            outnode = rangeNode;
            //outnode = CreateBinaryExpNode(node, rangeNode);
        }
示例#5
0
        void Associative_RangeExpr(out ProtoCore.AST.AssociativeAST.AssociativeNode node)
        {
            Associative_ArithmeticExpression(out node);
            if (la.kind == 21) {
            ProtoCore.AST.AssociativeAST.RangeExprNode rnode = new ProtoCore.AST.AssociativeAST.RangeExprNode();
            rnode.FromNode = node; NodeUtils.CopyNodeLocation(rnode, node);

            Get();
            Associative_ArithmeticExpression(out node);
            rnode.ToNode = node;
            if (la.kind == 21) {
                RangeStepOperator op;
                Get();
                Associative_rangeStepOperator(out op);
                rnode.stepoperator = op;
                Associative_ArithmeticExpression(out node);
                rnode.StepNode = node;
            }
            node = rnode;
            }
        }
示例#6
0
 public AssociativeNode GetAstNode(Dictionary<string, AssociativeNode> idLookup)
 {
     var rangeExpr = new RangeExprNode
     {
         FromNode = _start.GetAstNode(idLookup),
         ToNode = _end.GetAstNode(idLookup),
         StepNode = _step.GetAstNode(idLookup),
         stepoperator = GetRangeExpressionOperator()
     };
     return rangeExpr;
 }
示例#7
0
 public AssociativeNode GetAstNode(Dictionary<string, AssociativeNode> idLookup)
 {
     var rangeExpr = new RangeExprNode
     {
         FromNode = _start.GetAstNode(idLookup),
         ToNode = _count.GetAstNode(idLookup),
         StepNode = _step.GetAstNode(idLookup),
         HasRangeAmountOperator = true,
         stepoperator = RangeStepOperator.stepsize
     };
     return rangeExpr;
 }
示例#8
0
        public RangeExprNode(RangeExprNode rhs) : base(rhs)
        {
            FromNode = ProtoCore.Utils.NodeUtils.Clone(rhs.FromNode);
            ToNode = ProtoCore.Utils.NodeUtils.Clone(rhs.ToNode);

            // A step can be optional
            if (null != rhs.StepNode)
            {
                StepNode = ProtoCore.Utils.NodeUtils.Clone(rhs.StepNode);
            }
            stepoperator = rhs.stepoperator;
        }
示例#9
0
        public void GraphILTest_FFIClassUsage_03()
        {
            //
            //  a=2;
            //  tSSA_150=1..10;
            //  x= tSSA_150;
            //  tSSA_151=x;
            //  tSSA_152=a;
            //  tSSA_153=( tSSA_151+ tSSA_152);
            //  var_79153f69593b4fde9bb50646a1aaea96= tSSA_153;
            //  tSSA_154=Point.ByCoordinates(var_79153f69593b4fde9bb50646a1aaea96,a,a);
            //  var_347c1113204a4d15a22f7daf83bbe20e= tSSA_154;
            //

            //
            //  a=2;
            //  x=1..10;
            //  var_79153f69593b4fde9bb50646a1aaea96=(x+a);
            //  var_347c1113204a4d15a22f7daf83bbe20e=Point.ByCoordinates(var_79153f69593b4fde9bb50646a1aaea96,a,a);
            //

            ProtoScript.Runners.ILiveRunner liveRunner = new ProtoScript.Runners.LiveRunner();

            List<ProtoCore.AST.AssociativeAST.AssociativeNode> astList = new List<ProtoCore.AST.AssociativeAST.AssociativeNode>();
            //==============================================
            // Build the import Nodes
            //==============================================
            //ProtoCore.AST.AssociativeAST.ImportNode importNode = new ProtoCore.AST.AssociativeAST.ImportNode();
            //importNode.ModuleName = "ProtoGeometry.dll";
            //astList.Add(importNode);

            List<string> libs = new List<string>();
            libs.Add("ProtoGeometry.dll");
            liveRunner.ResetVMAndResyncGraph(libs);




            // Build the AST trees
            // a = 2
            ProtoCore.AST.AssociativeAST.BinaryExpressionNode assign1 = new ProtoCore.AST.AssociativeAST.BinaryExpressionNode(
                new ProtoCore.AST.AssociativeAST.IdentifierNode("a"),
                new ProtoCore.AST.AssociativeAST.IntNode(2),
                ProtoCore.DSASM.Operator.assign);
            astList.Add(assign1);


            // x = 1..10;
            ProtoCore.AST.AssociativeAST.RangeExprNode rangeExpr = new ProtoCore.AST.AssociativeAST.RangeExprNode();
            rangeExpr.FromNode = new ProtoCore.AST.AssociativeAST.IntNode(1);
            rangeExpr.ToNode = new ProtoCore.AST.AssociativeAST.IntNode(10);
            rangeExpr.StepNode = new ProtoCore.AST.AssociativeAST.IntNode(1);
            ProtoCore.AST.AssociativeAST.BinaryExpressionNode assign2 = new ProtoCore.AST.AssociativeAST.BinaryExpressionNode(
                new ProtoCore.AST.AssociativeAST.IdentifierNode("x"),
                rangeExpr,
                ProtoCore.DSASM.Operator.assign);
            astList.Add(assign2);

            // var_79153f69593b4fde9bb50646a1aaea96 = (x + a);
            ProtoCore.AST.AssociativeAST.BinaryExpressionNode assign3 = new ProtoCore.AST.AssociativeAST.BinaryExpressionNode(
                new ProtoCore.AST.AssociativeAST.IdentifierNode("dude"),
                new ProtoCore.AST.AssociativeAST.BinaryExpressionNode(
                    new ProtoCore.AST.AssociativeAST.IdentifierNode("x"),
                    new ProtoCore.AST.AssociativeAST.IdentifierNode("a"),
                    ProtoCore.DSASM.Operator.add),
                ProtoCore.DSASM.Operator.assign);

            astList.Add(assign3);




            //==============================================
            // Build the constructor call nodes
            // Point.ByCoordinates(10,10,10)
            //==============================================
            ProtoCore.AST.AssociativeAST.FunctionCallNode constructorCall = new ProtoCore.AST.AssociativeAST.FunctionCallNode();
            constructorCall.Function = new ProtoCore.AST.AssociativeAST.IdentifierNode("ByCoordinates");
            List<ProtoCore.AST.AssociativeAST.AssociativeNode> listArgs = new List<ProtoCore.AST.AssociativeAST.AssociativeNode>();
            listArgs.Add(new ProtoCore.AST.AssociativeAST.IdentifierNode("dude"));
            listArgs.Add(new ProtoCore.AST.AssociativeAST.IdentifierNode("a"));
            listArgs.Add(new ProtoCore.AST.AssociativeAST.IdentifierNode("a"));
            constructorCall.FormalArguments = listArgs;

            string className = "Point";
            ProtoCore.AST.AssociativeAST.IdentifierNode inode = new ProtoCore.AST.AssociativeAST.IdentifierNode(className);

            ProtoCore.AST.AssociativeAST.FunctionDotCallNode dotCall = ProtoCore.Utils.CoreUtils.GenerateCallDotNode(inode, constructorCall, liveRunner.Core);

            //==============================================
            // Build the binary expression 
            // p = Point.ByCoordinates(10,10,10)
            //==============================================
            ProtoCore.AST.AssociativeAST.BinaryExpressionNode stmt1 = new ProtoCore.AST.AssociativeAST.BinaryExpressionNode(
                new ProtoCore.AST.AssociativeAST.IdentifierNode("final"),
                dotCall,
                ProtoCore.DSASM.Operator.assign);
            astList.Add(stmt1);


            //==============================================
            // emit the DS code from the AST tree
            //==============================================

            // Instantiate GraphSyncData
            List<Subtree> addedList = new List<Subtree>();
            addedList.Add(new Subtree(astList, System.Guid.NewGuid()));
            GraphSyncData syncData = new GraphSyncData(null, addedList, null);

            // emit the DS code from the AST tree
            liveRunner.UpdateGraph(syncData);



        }