• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# AssociativeAST.BinaryExpressionNode类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中ProtoCore.AST.AssociativeAST.BinaryExpressionNode的典型用法代码示例。如果您正苦于以下问题:C# ProtoCore.AST.AssociativeAST.BinaryExpressionNode类的具体用法?C# ProtoCore.AST.AssociativeAST.BinaryExpressionNode怎么用?C# ProtoCore.AST.AssociativeAST.BinaryExpressionNode使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



ProtoCore.AST.AssociativeAST.BinaryExpressionNode类属于命名空间,在下文中一共展示了ProtoCore.AST.AssociativeAST.BinaryExpressionNode类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: TestRoundTrip_Assign02

        public void TestRoundTrip_Assign02()
        {
            //=================================
            // 1. Build AST 
            // 2. Execute AST and verify
            // 3. Convert AST to source
            // 4. Execute source and verify
            //=================================

            int result1 = 30;
            ExecutionMirror mirror = null;

            // 1. Build the AST tree
            ProtoCore.AST.AssociativeAST.BinaryExpressionNode assign = new ProtoCore.AST.AssociativeAST.BinaryExpressionNode(
                new ProtoCore.AST.AssociativeAST.IdentifierNode("a"),
                new ProtoCore.AST.AssociativeAST.BinaryExpressionNode(
                    new ProtoCore.AST.AssociativeAST.IntNode(10),
                    new ProtoCore.AST.AssociativeAST.IntNode(20),
                    ProtoCore.DSASM.Operator.add),
                ProtoCore.DSASM.Operator.assign);
            List<ProtoCore.AST.AssociativeAST.AssociativeNode> astList = new List<ProtoCore.AST.AssociativeAST.AssociativeNode>();
            astList.Add(assign);

            // 2. Execute AST and verify
            mirror = thisTest.RunASTSource(astList);
            Assert.IsTrue((Int64)mirror.GetValue("a").Payload == result1);

            // 3. Convert AST to source
            ProtoCore.CodeGenDS codegenDS = new ProtoCore.CodeGenDS(astList);
            string code = codegenDS.GenerateCode();

            // 4. Execute source and verify
            mirror = thisTest.RunScriptSource(code);
            Assert.IsTrue((Int64)mirror.GetValue("a").Payload == result1);
        }
开发者ID:limrzx,项目名称:Dynamo,代码行数:35,代码来源:RoundTripTests.cs


示例2: TestProtoASTExecute_Assign01

 public void TestProtoASTExecute_Assign01()
 {
     // Build the AST trees
     ProtoCore.AST.AssociativeAST.BinaryExpressionNode assign = new ProtoCore.AST.AssociativeAST.BinaryExpressionNode(
         new ProtoCore.AST.AssociativeAST.IdentifierNode("a"),
         new ProtoCore.AST.AssociativeAST.IntNode(10),
         ProtoCore.DSASM.Operator.assign);
     List<ProtoCore.AST.AssociativeAST.AssociativeNode> astList = new List<ProtoCore.AST.AssociativeAST.AssociativeNode>();
     astList.Add(assign);
     // Verify the results
     ExecutionMirror mirror = thisTest.RunASTSource(astList);
     thisTest.Verify("a", 10);
 }
开发者ID:sm6srw,项目名称:Dynamo,代码行数:13,代码来源:ProtoASTExecutionTests.cs


示例3: TestProtoASTExecute_Assign03

 public void TestProtoASTExecute_Assign03()
 {
     GraphToDSCompiler.GraphCompiler gc = GraphToDSCompiler.GraphCompiler.CreateInstance();
     /*b = 20;*/
     ProtoCore.AST.AssociativeAST.BinaryExpressionNode assign2 = new ProtoCore.AST.AssociativeAST.BinaryExpressionNode(
         new ProtoCore.AST.AssociativeAST.IdentifierNode("b"),
         new ProtoCore.AST.AssociativeAST.IntNode(20),
         ProtoCore.DSASM.Operator.assign);
     /*a = (b + 50)*(b + 20)*/
     ProtoCore.AST.AssociativeAST.BinaryExpressionNode assign1 = new ProtoCore.AST.AssociativeAST.BinaryExpressionNode(
         new ProtoCore.AST.AssociativeAST.IdentifierNode("a"),
         new ProtoCore.AST.AssociativeAST.BinaryExpressionNode(
             new ProtoCore.AST.AssociativeAST.BinaryExpressionNode(
                 new ProtoCore.AST.AssociativeAST.IdentifierNode("b"),
                 new ProtoCore.AST.AssociativeAST.IntNode(50),
                 ProtoCore.DSASM.Operator.add),
             new ProtoCore.AST.AssociativeAST.BinaryExpressionNode(
                 new ProtoCore.AST.AssociativeAST.IdentifierNode("b"),
                 new ProtoCore.AST.AssociativeAST.IntNode(20),
                 ProtoCore.DSASM.Operator.add),
             ProtoCore.DSASM.Operator.mul),
         ProtoCore.DSASM.Operator.assign);
     /*c = a - 200*/
     ProtoCore.AST.AssociativeAST.BinaryExpressionNode assign3 = new ProtoCore.AST.AssociativeAST.BinaryExpressionNode(
         new ProtoCore.AST.AssociativeAST.IdentifierNode("c"),
         new ProtoCore.AST.AssociativeAST.BinaryExpressionNode(
             new ProtoCore.AST.AssociativeAST.IdentifierNode("a"),
             new ProtoCore.AST.AssociativeAST.IntNode(200),
             ProtoCore.DSASM.Operator.sub),
         ProtoCore.DSASM.Operator.assign);
     /*d = b*/
     ProtoCore.AST.AssociativeAST.BinaryExpressionNode assign4 = new ProtoCore.AST.AssociativeAST.BinaryExpressionNode(
         new ProtoCore.AST.AssociativeAST.IdentifierNode("d"),
         new ProtoCore.AST.AssociativeAST.IdentifierNode("b"),
         ProtoCore.DSASM.Operator.assign);
     List<ProtoCore.AST.AssociativeAST.AssociativeNode> astList = new List<ProtoCore.AST.AssociativeAST.AssociativeNode>();
     astList.Add(assign2);
     astList.Add(assign1);
     astList.Add(assign3);
     astList.Add(assign4);
     ExecutionMirror mirror = thisTest.RunASTSource(astList);
     //a = 2800, c = 2600, d = b = 20
     Obj o = mirror.GetValue("a");
     Assert.IsTrue((Int64)o.Payload == 2800);
     o = mirror.GetValue("c");
     Assert.IsTrue((Int64)o.Payload == 2600);
     Obj p = mirror.GetValue("b");
     Assert.IsTrue((Int64)p.Payload == 20);
     o = mirror.GetValue("d");
     Assert.IsTrue((Int64)o.Payload == 20);
 }
开发者ID:RobertiF,项目名称:Dynamo,代码行数:51,代码来源:ProtoASTExecutionTests.cs


示例4: TestProtoASTExecute_Assign03

 public void TestProtoASTExecute_Assign03()
 {
     /*b = 20;*/
     ProtoCore.AST.AssociativeAST.BinaryExpressionNode assign2 = new ProtoCore.AST.AssociativeAST.BinaryExpressionNode(
         new ProtoCore.AST.AssociativeAST.IdentifierNode("b"),
         new ProtoCore.AST.AssociativeAST.IntNode(20),
         ProtoCore.DSASM.Operator.assign);
     /*a = (b + 50)*(b + 20)*/
     ProtoCore.AST.AssociativeAST.BinaryExpressionNode assign1 = new ProtoCore.AST.AssociativeAST.BinaryExpressionNode(
         new ProtoCore.AST.AssociativeAST.IdentifierNode("a"),
         new ProtoCore.AST.AssociativeAST.BinaryExpressionNode(
             new ProtoCore.AST.AssociativeAST.BinaryExpressionNode(
                 new ProtoCore.AST.AssociativeAST.IdentifierNode("b"),
                 new ProtoCore.AST.AssociativeAST.IntNode(50),
                 ProtoCore.DSASM.Operator.add),
             new ProtoCore.AST.AssociativeAST.BinaryExpressionNode(
                 new ProtoCore.AST.AssociativeAST.IdentifierNode("b"),
                 new ProtoCore.AST.AssociativeAST.IntNode(20),
                 ProtoCore.DSASM.Operator.add),
             ProtoCore.DSASM.Operator.mul),
         ProtoCore.DSASM.Operator.assign);
     /*c = a - 200*/
     ProtoCore.AST.AssociativeAST.BinaryExpressionNode assign3 = new ProtoCore.AST.AssociativeAST.BinaryExpressionNode(
         new ProtoCore.AST.AssociativeAST.IdentifierNode("c"),
         new ProtoCore.AST.AssociativeAST.BinaryExpressionNode(
             new ProtoCore.AST.AssociativeAST.IdentifierNode("a"),
             new ProtoCore.AST.AssociativeAST.IntNode(200),
             ProtoCore.DSASM.Operator.sub),
         ProtoCore.DSASM.Operator.assign);
     /*d = b*/
     ProtoCore.AST.AssociativeAST.BinaryExpressionNode assign4 = new ProtoCore.AST.AssociativeAST.BinaryExpressionNode(
         new ProtoCore.AST.AssociativeAST.IdentifierNode("d"),
         new ProtoCore.AST.AssociativeAST.IdentifierNode("b"),
         ProtoCore.DSASM.Operator.assign);
     List<ProtoCore.AST.AssociativeAST.AssociativeNode> astList = new List<ProtoCore.AST.AssociativeAST.AssociativeNode>();
     astList.Add(assign2);
     astList.Add(assign1);
     astList.Add(assign3);
     astList.Add(assign4);
     ExecutionMirror mirror = thisTest.RunASTSource(astList);
     //a = 2800, c = 2600, d = b = 20
     thisTest.Verify("a", 2800);
     thisTest.Verify("c", 2600);
     thisTest.Verify("b", 20);
     thisTest.Verify("d", 20);
 }
开发者ID:sm6srw,项目名称:Dynamo,代码行数:46,代码来源:ProtoASTExecutionTests.cs


示例5: TestProtoASTExecute_Assign02

        public void TestProtoASTExecute_Assign02()
        {
            // Build the AST tree
            ProtoCore.AST.AssociativeAST.BinaryExpressionNode assign = new ProtoCore.AST.AssociativeAST.BinaryExpressionNode(
                new ProtoCore.AST.AssociativeAST.IdentifierNode("a"),
                new ProtoCore.AST.AssociativeAST.BinaryExpressionNode(
                    new ProtoCore.AST.AssociativeAST.IntNode(10),
                    new ProtoCore.AST.AssociativeAST.IntNode(20),
                    ProtoCore.DSASM.Operator.add),
                ProtoCore.DSASM.Operator.assign);
            List<ProtoCore.AST.AssociativeAST.AssociativeNode> astList = new List<ProtoCore.AST.AssociativeAST.AssociativeNode>();
            astList.Add(assign);

            // Verify the results
            ExecutionMirror mirror = thisTest.RunASTSource(astList);
            Obj o = mirror.GetValue("a");
            Assert.IsTrue((Int64)o.Payload == 30);
        }
开发者ID:limrzx,项目名称:Dynamo,代码行数:18,代码来源:ProtoASTExecutionTests.cs


示例6: TestProtoASTExecute_Imperative_IfStatement02

            List<ProtoCore.AST.AssociativeAST.AssociativeNode> astList = new List<ProtoCore.AST.AssociativeAST.AssociativeNode>();
            astList.Add(assign);

            // Verify the results
            ExecutionMirror mirror = thisTest.RunASTSource(astList);
            Obj o = mirror.GetValue("a");
            Assert.IsTrue((Int64)o.Payload == 11);
        }

        [Test]
        public void TestProtoASTExecute_Imperative_IfStatement02()
        {
            //
            //  a = [Imperative]
            //  {
            //      b = 10;
            //      if (b > 10)
            //      {
            //          b = 11;
            //      }
            //      else
            //      {
            //          b = 12
            //      }
            //      return = b;
            //  }
            //

            List<ProtoCore.AST.ImperativeAST.ImperativeNode> imperativeList = new List<ProtoCore.AST.ImperativeAST.ImperativeNode>();

            // b = 10
            ProtoCore.AST.ImperativeAST.BinaryExpressionNode imperativeAssign = new ProtoCore.AST.ImperativeAST.BinaryExpressionNode(
                new ProtoCore.AST.ImperativeAST.IdentifierNode("b"),
                new ProtoCore.AST.ImperativeAST.IntNode(10),
                ProtoCore.DSASM.Operator.assign);
            imperativeList.Add(imperativeAssign);

            // if (b > 10)
            ProtoCore.AST.ImperativeAST.BinaryExpressionNode equality = new ProtoCore.AST.ImperativeAST.BinaryExpressionNode(
                new ProtoCore.AST.ImperativeAST.IdentifierNode("b"),
                new ProtoCore.AST.ImperativeAST.IntNode(10),
                ProtoCore.DSASM.Operator.gt);

            ProtoCore.AST.ImperativeAST.IfStmtNode ifNode = new ProtoCore.AST.ImperativeAST.IfStmtNode();
            ifNode.IfExprNode = equality;

            // if body
            // b = 11
            ProtoCore.AST.ImperativeAST.BinaryExpressionNode ifCodeBlockStmt = new ProtoCore.AST.ImperativeAST.BinaryExpressionNode(
                new ProtoCore.AST.ImperativeAST.IdentifierNode("b"),
                new ProtoCore.AST.ImperativeAST.IntNode(11),
                ProtoCore.DSASM.Operator.assign);
            List<ProtoCore.AST.ImperativeAST.ImperativeNode> ifCodeBlock = new List<ProtoCore.AST.ImperativeAST.ImperativeNode>();
            ifCodeBlock.Add(ifCodeBlockStmt);
            ifNode.IfBody = ifCodeBlock;

            // else body
            // b = 12
            ProtoCore.AST.ImperativeAST.BinaryExpressionNode elseCodeBlockStmt = new ProtoCore.AST.ImperativeAST.BinaryExpressionNode(
                new ProtoCore.AST.ImperativeAST.IdentifierNode("b"),
                new ProtoCore.AST.ImperativeAST.IntNode(12),
                ProtoCore.DSASM.Operator.assign);
            List<ProtoCore.AST.ImperativeAST.ImperativeNode> elseCodeBlock = new List<ProtoCore.AST.ImperativeAST.ImperativeNode>();
            elseCodeBlock.Add(elseCodeBlockStmt);
            ifNode.ElseBody = elseCodeBlock;

            imperativeList.Add(ifNode);

            // return = b
            ProtoCore.AST.ImperativeAST.BinaryExpressionNode returnStmt = new ProtoCore.AST.ImperativeAST.BinaryExpressionNode(
                new ProtoCore.AST.ImperativeAST.IdentifierNode("return"),
                new ProtoCore.AST.ImperativeAST.IdentifierNode("b"),
                ProtoCore.DSASM.Operator.assign);
            imperativeList.Add(returnStmt);


            // Build the language block
            ProtoCore.AST.ImperativeAST.CodeBlockNode imperativeCodeBlock = new ProtoCore.AST.ImperativeAST.CodeBlockNode();
            imperativeCodeBlock.Body = imperativeList;

            ProtoCore.AST.AssociativeAST.LanguageBlockNode langblock = new ProtoCore.AST.AssociativeAST.LanguageBlockNode();
            langblock.codeblock = new ProtoCore.LanguageCodeBlock(ProtoCore.Language.Imperative);
            langblock.CodeBlockNode = imperativeCodeBlock;


            // Build an assignment where the rhs is the imperative block
            ProtoCore.AST.AssociativeAST.BinaryExpressionNode assign = new ProtoCore.AST.AssociativeAST.BinaryExpressionNode(
                new ProtoCore.AST.AssociativeAST.IdentifierNode("a"),
                langblock,
                ProtoCore.DSASM.Operator.assign);
开发者ID:limrzx,项目名称:Dynamo,代码行数:90,代码来源:ProtoASTExecutionTests.cs


示例7: TestLocalizedStringInAST

            List<ProtoCore.AST.AssociativeAST.AssociativeNode> astList = new List<ProtoCore.AST.AssociativeAST.AssociativeNode>();
            astList.Add(assign);

            // Verify the results
            ExecutionMirror mirror = thisTest.RunASTSource(astList);
            Obj o = mirror.GetValue("a");
            Assert.IsTrue((Int64)o.Payload == 12);
        }

        [Test]
        public void TestLocalizedStringInAST()
        {
            // Build the AST tree
            ProtoCore.AST.AssociativeAST.BinaryExpressionNode assign = new ProtoCore.AST.AssociativeAST.BinaryExpressionNode(
开发者ID:limrzx,项目名称:Dynamo,代码行数:14,代码来源:ProtoASTExecutionTests.cs


示例8: TestCodegenDS_Imperative_IfStatement01

            // Generate the script
            ProtoCore.CodeGenDS codegen = new ProtoCore.CodeGenDS(astList);
            string code = codegen.GenerateCode();


            ExecutionMirror mirror = thisTest.RunScriptSource(code);
            Assert.IsTrue((Int64)mirror.GetValue("a").Payload == 10);
        }

        [Test]
        public void TestCodegenDS_Imperative_IfStatement01()
        {
            //
            //  a = [Imperative]
            //  {
            //      b = 10;
            //      if (b == 10)
            //      {
            //          b = 11;
            //      }
            //      return = b;
            //  }
            //

            List<ProtoCore.AST.ImperativeAST.ImperativeNode> imperativeList = new List<ProtoCore.AST.ImperativeAST.ImperativeNode>();

            // b = 10
            ProtoCore.AST.ImperativeAST.BinaryExpressionNode imperativeAssign = new ProtoCore.AST.ImperativeAST.BinaryExpressionNode(
                new ProtoCore.AST.ImperativeAST.IdentifierNode("b"),
                new ProtoCore.AST.ImperativeAST.IntNode(10),
                ProtoCore.DSASM.Operator.assign);
            imperativeList.Add(imperativeAssign);

            // if (b == 10)
            ProtoCore.AST.ImperativeAST.BinaryExpressionNode equality = new ProtoCore.AST.ImperativeAST.BinaryExpressionNode(
                new ProtoCore.AST.ImperativeAST.IdentifierNode("b"),
                new ProtoCore.AST.ImperativeAST.IntNode(10),
                ProtoCore.DSASM.Operator.eq);

            ProtoCore.AST.ImperativeAST.IfStmtNode ifNode = new ProtoCore.AST.ImperativeAST.IfStmtNode();
            ifNode.IfExprNode = equality;

            // b = 11
            ProtoCore.AST.ImperativeAST.BinaryExpressionNode ifCodeBlockStmt = new ProtoCore.AST.ImperativeAST.BinaryExpressionNode(
                new ProtoCore.AST.ImperativeAST.IdentifierNode("b"),
                new ProtoCore.AST.ImperativeAST.IntNode(11),
                ProtoCore.DSASM.Operator.assign);
            List<ProtoCore.AST.ImperativeAST.ImperativeNode> ifCodeBlock = new List<ProtoCore.AST.ImperativeAST.ImperativeNode>();
            ifCodeBlock.Add(ifCodeBlockStmt);
            ifNode.IfBody = ifCodeBlock;

            imperativeList.Add(ifNode);

            // return = b
            ProtoCore.AST.ImperativeAST.BinaryExpressionNode returnStmt = new ProtoCore.AST.ImperativeAST.BinaryExpressionNode(
                new ProtoCore.AST.ImperativeAST.IdentifierNode("return"),
                new ProtoCore.AST.ImperativeAST.IdentifierNode("b"),
                ProtoCore.DSASM.Operator.assign);
            imperativeList.Add(returnStmt);


            // Build the language block
            ProtoCore.AST.ImperativeAST.CodeBlockNode imperativeCodeBlock = new ProtoCore.AST.ImperativeAST.CodeBlockNode();
            imperativeCodeBlock.Body = imperativeList;

            ProtoCore.AST.AssociativeAST.LanguageBlockNode langblock = new ProtoCore.AST.AssociativeAST.LanguageBlockNode();
            langblock.codeblock = new ProtoCore.LanguageCodeBlock(ProtoCore.Language.Imperative);
            langblock.CodeBlockNode = imperativeCodeBlock;


            // Build an assignment where the rhs is the imperative block
            ProtoCore.AST.AssociativeAST.BinaryExpressionNode assign = new ProtoCore.AST.AssociativeAST.BinaryExpressionNode(
                new ProtoCore.AST.AssociativeAST.IdentifierNode("a"),
                langblock,
                ProtoCore.DSASM.Operator.assign);


            List<ProtoCore.AST.AssociativeAST.AssociativeNode> astList = new List<ProtoCore.AST.AssociativeAST.AssociativeNode>();
开发者ID:limrzx,项目名称:Dynamo,代码行数:78,代码来源:ProtoASTExecutionTests.cs


示例9: TestProtoASTExecute_Imperative_Assign01

            // Generate the script
            ProtoCore.CodeGenDS codegen = new ProtoCore.CodeGenDS(astList);
            string code = codegen.GenerateCode();


            ExecutionMirror mirror = thisTest.RunScriptSource(code);
            Assert.IsTrue((Int64)mirror.GetValue("a").Payload == 12);
        }

        [Test]
        public void TestProtoASTExecute_Imperative_Assign01()
        {
            //
            //  a = [Imperative]
            //  {
            //      return = 10;
            //  }
            //

            List<ProtoCore.AST.ImperativeAST.ImperativeNode> imperativeList = new List<ProtoCore.AST.ImperativeAST.ImperativeNode>();

            // return = 10
            ProtoCore.AST.ImperativeAST.BinaryExpressionNode imperativeAssign = new ProtoCore.AST.ImperativeAST.BinaryExpressionNode(
                new ProtoCore.AST.ImperativeAST.IdentifierNode("return"),
                new ProtoCore.AST.ImperativeAST.IntNode(10),
                ProtoCore.DSASM.Operator.assign);
            imperativeList.Add(imperativeAssign);


            // Build the language block
            ProtoCore.AST.ImperativeAST.CodeBlockNode imperativeCodeBlock = new ProtoCore.AST.ImperativeAST.CodeBlockNode();
            imperativeCodeBlock.Body = imperativeList;

            ProtoCore.AST.AssociativeAST.LanguageBlockNode langblock = new ProtoCore.AST.AssociativeAST.LanguageBlockNode();
            langblock.codeblock = new ProtoCore.LanguageCodeBlock(ProtoCore.Language.Imperative);
            langblock.CodeBlockNode = imperativeCodeBlock;


            // Build an assignment where the rhs is the imperative block
            ProtoCore.AST.AssociativeAST.BinaryExpressionNode assign = new ProtoCore.AST.AssociativeAST.BinaryExpressionNode(
                new ProtoCore.AST.AssociativeAST.IdentifierNode("a"),
                langblock,
                ProtoCore.DSASM.Operator.assign);
开发者ID:limrzx,项目名称:Dynamo,代码行数:43,代码来源:ProtoASTExecutionTests.cs


示例10: TestProtoASTExecute_FunctionDefAndCall_03

        public void TestProtoASTExecute_FunctionDefAndCall_03()
        {
            //  def add(a : int, b : int)
            //  {
            //    return = a + b;
            //  }
            //  
            //  x = add(2,3);

            ProtoCore.AST.AssociativeAST.CodeBlockNode cbn = new ProtoCore.AST.AssociativeAST.CodeBlockNode();


            // Build the function body
            ProtoCore.AST.AssociativeAST.BinaryExpressionNode returnExpr = new ProtoCore.AST.AssociativeAST.BinaryExpressionNode(
                new ProtoCore.AST.AssociativeAST.IdentifierNode("a"),
                new ProtoCore.AST.AssociativeAST.IdentifierNode("b"),
                ProtoCore.DSASM.Operator.add);

            ProtoCore.AST.AssociativeAST.BinaryExpressionNode returnNode = new ProtoCore.AST.AssociativeAST.BinaryExpressionNode(
                new ProtoCore.AST.AssociativeAST.IdentifierNode(ProtoCore.DSDefinitions.Keyword.Return),
                returnExpr,
                ProtoCore.DSASM.Operator.assign);

            cbn.Body.Add(returnNode);


            // Build the function definition foo
            const string functionName = "foo";
            ProtoCore.AST.AssociativeAST.FunctionDefinitionNode funcDefNode = new ProtoCore.AST.AssociativeAST.FunctionDefinitionNode();
            funcDefNode.Name = functionName;
            funcDefNode.FunctionBody = cbn;

            // build the args signature
            funcDefNode.Signature = new ProtoCore.AST.AssociativeAST.ArgumentSignatureNode();

            // Build arg1
            ProtoCore.AST.AssociativeAST.VarDeclNode arg1Decl = new ProtoCore.AST.AssociativeAST.VarDeclNode();
            arg1Decl.NameNode = new ProtoCore.AST.AssociativeAST.IdentifierNode("a");

            // Build the type of arg1
            ProtoCore.Type arg1Type = new ProtoCore.Type();
            arg1Type.Initialize();
            arg1Type.UID = (int)ProtoCore.PrimitiveType.Integer;
            arg1Type.Name = ProtoCore.DSDefinitions.Keyword.Int;
            arg1Decl.ArgumentType = arg1Type;
            funcDefNode.Signature.AddArgument(arg1Decl);

            // Build arg2
            ProtoCore.AST.AssociativeAST.VarDeclNode arg2Decl = new ProtoCore.AST.AssociativeAST.VarDeclNode();
            arg2Decl.NameNode = new ProtoCore.AST.AssociativeAST.IdentifierNode("b");

            // Build the type of arg2
            ProtoCore.Type arg2Type = new ProtoCore.Type();
            arg2Type.Initialize();
            arg2Type.UID = (int)ProtoCore.PrimitiveType.Integer;
            arg2Type.Name = ProtoCore.DSDefinitions.Keyword.Int;
            arg2Decl.ArgumentType = arg2Type;
            funcDefNode.Signature.AddArgument(arg2Decl);


            // Function Return type
            ProtoCore.Type returnType = new ProtoCore.Type();
            returnType.Initialize();
            returnType.UID = (int)ProtoCore.PrimitiveType.Var;
            returnType.Name = ProtoCore.DSDefinitions.Keyword.Var;
            funcDefNode.ReturnType = returnType;

            // Build the statement that calls the function foo
            ProtoCore.AST.AssociativeAST.FunctionCallNode functionCall = new ProtoCore.AST.AssociativeAST.FunctionCallNode();
            functionCall.Function = new ProtoCore.AST.AssociativeAST.IdentifierNode(functionName);


            List<ProtoCore.AST.AssociativeAST.AssociativeNode> astList = new List<ProtoCore.AST.AssociativeAST.AssociativeNode>();
            astList.Add(funcDefNode);

            // Function call
            // Function args
            List<ProtoCore.AST.AssociativeAST.AssociativeNode> args = new List<ProtoCore.AST.AssociativeAST.AssociativeNode>();
            args.Add(new ProtoCore.AST.AssociativeAST.IntNode(2));
            args.Add(new ProtoCore.AST.AssociativeAST.IntNode(3));
            functionCall.FormalArguments = args;

            // Call the function
            ProtoCore.AST.AssociativeAST.BinaryExpressionNode callstmt = new ProtoCore.AST.AssociativeAST.BinaryExpressionNode(
                new ProtoCore.AST.AssociativeAST.IdentifierNode("x"),
                functionCall,
                ProtoCore.DSASM.Operator.assign);
            astList.Add(callstmt);


            ExecutionMirror mirror = thisTest.RunASTSource(astList);
            Obj o = mirror.GetValue("x");
            Assert.IsTrue((Int64)o.Payload == 5);

        }
开发者ID:limrzx,项目名称:Dynamo,代码行数:95,代码来源:ProtoASTExecutionTests.cs


示例11: TestProtoASTExecute_ArrayIndex_RHS_Assign04

        public void TestProtoASTExecute_ArrayIndex_RHS_Assign04()
        {
            List<ProtoCore.AST.AssociativeAST.AssociativeNode> astList = new List<ProtoCore.AST.AssociativeAST.AssociativeNode>();

            // a = {1, 2, 3, 4};
            int[] input = { 1, 2, 3, 4 };
            ProtoCore.AST.AssociativeAST.BinaryExpressionNode declareNodeA = CreateDeclareArrayNode("a", input);
            astList.Add(declareNodeA);

            // b = 4;
            ProtoCore.AST.AssociativeAST.BinaryExpressionNode declareNodeB = new ProtoCore.AST.AssociativeAST.BinaryExpressionNode(
                new ProtoCore.AST.AssociativeAST.IdentifierNode("b"),
                new ProtoCore.AST.AssociativeAST.IntNode(5),
                ProtoCore.DSASM.Operator.assign);
            astList.Add(declareNodeB);

            // def foo(){
            //    return = -4;
            // }
            ProtoCore.AST.AssociativeAST.CodeBlockNode cbn = new ProtoCore.AST.AssociativeAST.CodeBlockNode();
            ProtoCore.AST.AssociativeAST.BinaryExpressionNode returnNode = new ProtoCore.AST.AssociativeAST.BinaryExpressionNode(
                new ProtoCore.AST.AssociativeAST.IdentifierNode(ProtoCore.DSDefinitions.Keyword.Return),
                new ProtoCore.AST.AssociativeAST.IntNode(-4),
                ProtoCore.DSASM.Operator.assign);
            cbn.Body.Add(returnNode);

            // Build the function definition foo
            const string functionName = "foo";
            ProtoCore.AST.AssociativeAST.FunctionDefinitionNode funcDefNode = new ProtoCore.AST.AssociativeAST.FunctionDefinitionNode() {
                Name = functionName,
                FunctionBody = cbn };

            // Function Return Type
            ProtoCore.Type returnType = new ProtoCore.Type();
            returnType.Initialize();
            returnType.UID = (int)ProtoCore.PrimitiveType.Var;
            returnType.Name = ProtoCore.DSDefinitions.Keyword.Var;
            funcDefNode.ReturnType = returnType;

            astList.Add(funcDefNode);

            // c = a[b + foo()];
            ProtoCore.AST.AssociativeAST.FunctionCallNode functionCall = new ProtoCore.AST.AssociativeAST.FunctionCallNode();
            functionCall.Function = new ProtoCore.AST.AssociativeAST.IdentifierNode(functionName);

            ProtoCore.AST.AssociativeAST.BinaryExpressionNode operation1 = new ProtoCore.AST.AssociativeAST.BinaryExpressionNode(
                new ProtoCore.AST.AssociativeAST.IdentifierNode("b"),
                functionCall,
                ProtoCore.DSASM.Operator.add);

            ProtoCore.AST.AssociativeAST.IdentifierNode nodeALHS = new ProtoCore.AST.AssociativeAST.IdentifierNode("a");
            nodeALHS.ArrayDimensions = new ProtoCore.AST.AssociativeAST.ArrayNode {
                Expr = operation1 };

            ProtoCore.AST.AssociativeAST.BinaryExpressionNode nodeALHSAssignment = new ProtoCore.AST.AssociativeAST.BinaryExpressionNode(
                new ProtoCore.AST.AssociativeAST.IdentifierNode("c"),
                nodeALHS,
                ProtoCore.DSASM.Operator.assign);

            astList.Add(nodeALHSAssignment);

            // Verify the results
            ExecutionMirror mirror = thisTest.RunASTSource(astList);
            Obj o = mirror.GetValue("c");
            Console.WriteLine(o.Payload);

            // expected: c = 2
            Assert.AreEqual(2, Convert.ToInt32(o.Payload));
        }
开发者ID:limrzx,项目名称:Dynamo,代码行数:69,代码来源:ProtoASTExecutionTests.cs


示例12: TestRoundTrip_ClassDecl_PropertyAccess_01

        public void TestRoundTrip_ClassDecl_PropertyAccess_01()
        {
            int result1 = 10;
            ExecutionMirror mirror = null;

            List<ProtoCore.AST.AssociativeAST.AssociativeNode> astList = new List<ProtoCore.AST.AssociativeAST.AssociativeNode>();

            // Create an exact copy of the AST list to pass to the source conversion
            // This needs to be done because the astlist to be run will be SSA'd on the AST execution run
            List<ProtoCore.AST.AssociativeAST.AssociativeNode> astListcopy= new List<ProtoCore.AST.AssociativeAST.AssociativeNode>();

            // 1. Build AST

            //  class bar
            //  {
            //       f : var;
            //  }
            //
            //  p = bar.bar();
            //  p.f = 10;
            //  a = p.f;


            // Create the class node AST
            ProtoCore.AST.AssociativeAST.ClassDeclNode classDefNode = new ProtoCore.AST.AssociativeAST.ClassDeclNode();
            classDefNode.ClassName = "bar";

            // Create the property AST
            ProtoCore.AST.AssociativeAST.VarDeclNode varDeclNode = new ProtoCore.AST.AssociativeAST.VarDeclNode();
            varDeclNode.Name = "f";
            varDeclNode.NameNode = new ProtoCore.AST.AssociativeAST.IdentifierNode("f");
            varDeclNode.ArgumentType = new ProtoCore.Type()
            {
                Name = "int",
                rank = 0,
                UID = (int)ProtoCore.PrimitiveType.Integer
            };
            classDefNode.Variables.Add(varDeclNode);

            astList.Add(classDefNode);
            astListcopy.Add(new ProtoCore.AST.AssociativeAST.ClassDeclNode(classDefNode));


            // p = bar.bar();
            ProtoCore.AST.AssociativeAST.FunctionCallNode constructorCall = new ProtoCore.AST.AssociativeAST.FunctionCallNode();
            constructorCall.Function = new ProtoCore.AST.AssociativeAST.IdentifierNode("bar");

            ProtoCore.AST.AssociativeAST.IdentifierListNode identListConstrcctorCall = new ProtoCore.AST.AssociativeAST.IdentifierListNode();
            identListConstrcctorCall.LeftNode = new ProtoCore.AST.AssociativeAST.IdentifierNode("bar");
            identListConstrcctorCall.RightNode = constructorCall;

            ProtoCore.AST.AssociativeAST.BinaryExpressionNode stmtInitClass = new ProtoCore.AST.AssociativeAST.BinaryExpressionNode(
                new ProtoCore.AST.AssociativeAST.IdentifierNode("p"),
                identListConstrcctorCall,
                ProtoCore.DSASM.Operator.assign);

            astList.Add(stmtInitClass);
            astListcopy.Add(new ProtoCore.AST.AssociativeAST.BinaryExpressionNode(stmtInitClass));


            //  p.f = 10;
            ProtoCore.AST.AssociativeAST.IdentifierListNode identListPropertySet = new ProtoCore.AST.AssociativeAST.IdentifierListNode();
            identListPropertySet.LeftNode = new ProtoCore.AST.AssociativeAST.IdentifierNode("p");
            identListPropertySet.RightNode = new ProtoCore.AST.AssociativeAST.IdentifierNode("f");

            ProtoCore.AST.AssociativeAST.BinaryExpressionNode stmtPropertySet = new ProtoCore.AST.AssociativeAST.BinaryExpressionNode(
                identListPropertySet,
                new ProtoCore.AST.AssociativeAST.IntNode(10),
                ProtoCore.DSASM.Operator.assign);

            astList.Add(stmtPropertySet);
            astListcopy.Add(new ProtoCore.AST.AssociativeAST.BinaryExpressionNode(stmtPropertySet));


            //  a = p.f; 
            ProtoCore.AST.AssociativeAST.IdentifierListNode identListPropertyAccess = new ProtoCore.AST.AssociativeAST.IdentifierListNode();
            identListPropertyAccess.LeftNode = new ProtoCore.AST.AssociativeAST.IdentifierNode("p");
            identListPropertyAccess.RightNode = new ProtoCore.AST.AssociativeAST.IdentifierNode("f");

            ProtoCore.AST.AssociativeAST.BinaryExpressionNode stmtPropertyAccess = new ProtoCore.AST.AssociativeAST.BinaryExpressionNode(
                new ProtoCore.AST.AssociativeAST.IdentifierNode("a"),
                identListPropertyAccess,
                ProtoCore.DSASM.Operator.assign);

            astList.Add(stmtPropertyAccess);
            astListcopy.Add(new ProtoCore.AST.AssociativeAST.BinaryExpressionNode(stmtPropertyAccess));



            // 2. Execute AST and verify
            mirror = thisTest.RunASTSource(astList);
            Assert.IsTrue((Int64)mirror.GetValue("a").Payload == result1);

            // 3. Convert AST to source
            ProtoCore.CodeGenDS codegenDS = new ProtoCore.CodeGenDS(astListcopy);
            string code = codegenDS.GenerateCode();

            // 4. Execute source and verify
            mirror = thisTest.RunScriptSource(code);
            Assert.IsTrue((Int64)mirror.GetValue("a").Payload == result1);
//.........这里部分代码省略.........
开发者ID:limrzx,项目名称:Dynamo,代码行数:101,代码来源:RoundTripTests.cs


示例13: TestCodeGenDS_Assign02

 public void TestCodeGenDS_Assign02()
 {
     // Build the AST tree
     ProtoCore.AST.AssociativeAST.BinaryExpressionNode assign = new ProtoCore.AST.AssociativeAST.BinaryExpressionNode(
         new ProtoCore.AST.AssociativeAST.IdentifierNode("a"),
         new ProtoCore.AST.AssociativeAST.BinaryExpressionNode(
             new ProtoCore.AST.AssociativeAST.IntNode(10),
             new ProtoCore.AST.AssociativeAST.IntNode(20),
             ProtoCore.DSASM.Operator.add),
         ProtoCore.DSASM.Operator.assign);
     List<ProtoCore.AST.AssociativeAST.AssociativeNode> astList = new List<ProtoCore.AST.AssociativeAST.AssociativeNode>();
     astList.Add(assign);
     // emit the DS code from the AST tree
     ProtoCore.CodeGenDS codegenDS = new ProtoCore.CodeGenDS(astList);
     string code = codegenDS.GenerateCode();
     // Verify the results
     ExecutionMirror mirror = thisTest.RunScriptSource(code);
     Obj o = mirror.GetValue("a");
     Assert.IsTrue((Int64)o.Payload == 30);
 }
开发者ID:limrzx,项目名称:Dynamo,代码行数:20,代码来源:ProtoASTExecutionTests.cs


示例14: TestProtoASTExecute_ArrayIndex_LHS_Assign05

        public void TestProtoASTExecute_ArrayIndex_LHS_Assign05()
        {
            List<ProtoCore.AST.AssociativeAST.AssociativeNode> astList = new List<ProtoCore.AST.AssociativeAST.AssociativeNode>();

            // a = { { 0, 1 }, { 3, 4, 5 } };
            int[] input1 = { 0, 1 };
            int[] input2 = { 3, 4, 5 };
            List<ProtoCore.AST.AssociativeAST.AssociativeNode> arrayList = new List<ProtoCore.AST.AssociativeAST.AssociativeNode>();
            arrayList.Add(CreateExprListNodeFromArray(input1));
            arrayList.Add(CreateExprListNodeFromArray(input2));

            ProtoCore.AST.AssociativeAST.ExprListNode arrayExpr = new ProtoCore.AST.AssociativeAST.ExprListNode { Exprs = arrayList };

            ProtoCore.AST.AssociativeAST.BinaryExpressionNode declareNodeA = new ProtoCore.AST.AssociativeAST.BinaryExpressionNode(
                new ProtoCore.AST.AssociativeAST.IdentifierNode("a"),
                arrayExpr,
                ProtoCore.DSASM.Operator.assign);

            astList.Add(declareNodeA);

            // b = 2;
            ProtoCore.AST.AssociativeAST.BinaryExpressionNode declareNodeB = new ProtoCore.AST.AssociativeAST.BinaryExpressionNode(
                new ProtoCore.AST.AssociativeAST.IdentifierNode("b"),
                new ProtoCore.AST.AssociativeAST.IntNode(2),
                ProtoCore.DSASM.Operator.assign);
            astList.Add(declareNodeB);

            // a[0][b] = b;
            ProtoCore.AST.AssociativeAST.IdentifierNode nodeALHS = new ProtoCore.AST.AssociativeAST.IdentifierNode("a");
            nodeALHS.ArrayDimensions = new ProtoCore.AST.AssociativeAST.ArrayNode
            {
                Expr = new ProtoCore.AST.AssociativeAST.IntNode(0),
                Type = new ProtoCore.AST.AssociativeAST.ArrayNode
                {
                    Expr = new ProtoCore.AST.AssociativeAST.IdentifierNode("b")
                }
            };

            ProtoCore.AST.AssociativeAST.BinaryExpressionNode nodeALHSAssignment = new ProtoCore.AST.AssociativeAST.BinaryExpressionNode(
                nodeALHS,
                new ProtoCore.AST.AssociativeAST.IdentifierNode("b"),
                ProtoCore.DSASM.Operator.assign);

            astList.Add(nodeALHSAssignment);

            // Verify the results
            ExecutionMirror mirror = thisTest.RunASTSource(astList);
            Obj o = mirror.GetValue("a");
            Console.WriteLine(o.Payload);

            int[] output1 = { 0, 1, 2 };
            int[] output2 = { 3, 4, 5 };

            // Result should be = { { 0, 1, 2 }, { 3, 4, 5 } };
            ProtoCore.DSASM.Mirror.DsasmArray result = o.Payload as ProtoCore.DSASM.Mirror.DsasmArray;
            Assert.IsNotNull( result );

            // First row of array = { 0, 1, 2 }
            ProtoCore.DSASM.Mirror.DsasmArray array1 = result.members[0].Payload as ProtoCore.DSASM.Mirror.DsasmArray;
            Assert.IsNotNull( array1 );
            for (int i = 0; i < output1.Length; i++)
                Assert.AreEqual(output1[i], Convert.ToInt32(array1.members[i].Payload));

            // Second row of array = { 3, 4, 5 }
            ProtoCore.DSASM.Mirror.DsasmArray array2 = (ProtoCore.DSASM.Mirror.DsasmArray)result.members[1].Payload;
            Assert.IsNotNull( array2 );
            for (int i = 0; i < output2.Length; i++)
                Assert.AreEqual(output2[i], Convert.ToInt32(array2.members[i].Payload));
        }
开发者ID:limrzx,项目名称:Dynamo,代码行数:69,代码来源:ProtoASTExecutionTests.cs


示例15: TestRoundTrip_FunctionDefAndCall_01

        public void TestRoundTrip_FunctionDefAndCall_01()
        {

            //=================================
            // 1. Build AST 
            // 2. Execute AST and verify
            // 3. Convert AST to source
            // 4. Execute source and verify
            //=================================
            int result1 = 20;
            ExecutionMirror mirror = null;



            // 1. Build the AST tree

            //  def foo()
            //  {
            //    b = 10;
            //    return = b + 10;
            //  }
            //  
            //  x = foo();
            ProtoCore.AST.AssociativeAST.CodeBlockNode cbn = new ProtoCore.AST.AssociativeAST.CodeBlockNode();


            // Build the function body
            ProtoCore.AST.AssociativeAST.BinaryExpressionNode assignment1 = new ProtoCore.AST.AssociativeAST.BinaryExpressionNode(
                new ProtoCore.AST.AssociativeAST.IdentifierNode("b"),
                new ProtoCore.AST.AssociativeAST.IntNode(10),
                ProtoCore.DSASM.Operator.assign);
            ProtoCore.AST.AssociativeAST.BinaryExpressionNode returnExpr = new ProtoCore.AST.AssociativeAST.BinaryExpressionNode(
                new ProtoCore.AST.AssociativeAST.IdentifierNode("b"),
                new ProtoCore.AST.AssociativeAST.IntNode(10),
                ProtoCore.DSASM.Operator.add);

            ProtoCore.AST.AssociativeAST.BinaryExpressionNode returnNode = new ProtoCore.AST.AssociativeAST.BinaryExpressionNode(
                new ProtoCore.AST.AssociativeAST.IdentifierNode(ProtoCore.DSDefinitions.Keyword.Return),
                returnExpr,
                ProtoCore.DSASM.Operator.assign);
            cbn.Body.Add(assignment1);
            cbn.Body.Add(returnNode);


            // Build the function definition foo
            const string functionName = "foo";
            ProtoCore.AST.AssociativeAST.FunctionDefinitionNode funcDefNode = new ProtoCore.AST.AssociativeAST.FunctionDefinitionNode();
            funcDefNode.Name = functionName;
            funcDefNode.FunctionBody = cbn;

            // Function Return type
            ProtoCore.Type returnType = new ProtoCore.Type();
            returnType.Initialize();
            returnType.UID = (int)ProtoCore.PrimitiveType.Var;
            returnType.Name = ProtoCore.DSDefinitions.Keyword.Var;
            funcDefNode.ReturnType = returnType;

            List<ProtoCore.AST.AssociativeAST.AssociativeNode> astList = new List<ProtoCore.AST.AssociativeAST.AssociativeNode>();
            astList.Add(funcDefNode);

            // Build the statement that calls the function foo
            ProtoCore.AST.AssociativeAST.FunctionCallNode functionCall = new ProtoCore.AST.AssociativeAST.FunctionCallNode();
            functionCall.Function = new ProtoCore.AST.AssociativeAST.IdentifierNode(functionName);

            ProtoCore.AST.AssociativeAST.BinaryExpressionNode callstmt = new ProtoCore.AST.AssociativeAST.BinaryExpressionNode(
                new ProtoCore.AST.AssociativeAST.IdentifierNode("x"),
                functionCall,
                ProtoCore.DSASM.Operator.assign);
            astList.Add(callstmt);


            // 2. Execute AST and verify
            mirror = thisTest.RunASTSource(astList);
            Assert.IsTrue((Int64)mirror.GetValue("x").Payload == result1);


            // 3. Convert AST to source
            ProtoCore.CodeGenDS codegenDS = new ProtoCore.CodeGenDS(astList);
            string code = codegenDS.GenerateCode();

            Console.WriteLine(code);

            // 4. Execute source and verify
            mirror = thisTest.RunScriptSource(code);
            Assert.IsTrue((Int64)mirror.GetValue("x").Payload == result1);

        }
开发者ID:limrzx,项目名称:Dynamo,代码行数:87,代码来源:RoundTripTests.cs


示例16: TestProtoASTExecute_Assign04

 public void TestProtoASTExecute_Assign04()
 {
     GraphToDSCompiler.GraphCompiler gc = GraphToDSCompiler.GraphCompiler.CreateInstance();
     /*b = 30*/
     ProtoCore.AST.AssociativeAST.BinaryExpressionNode nodeB = new ProtoCore.AST.AssociativeAST.BinaryExpressionNode(
         new ProtoCore.AST.AssociativeAST.IdentifierNode("b"),
         new ProtoCore.AST.AssociativeAST.IntNode(30),
         ProtoCore.DSASM.Operator.assign);
     /*a = (b - 10) * 20 + (b + 10) * (b - 20) */
     ProtoCore.AST.AssociativeAST.BinaryExpressionNode assignment =
         new ProtoCore.AST 

鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# AssociativeAST.CodeBlockNode类代码示例发布时间:2022-05-24
下一篇:
C# ProtoCore类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap