Example #1
0
        public void InheritanceTest01()
        {
            String code =
                @"

	class RigidBody
	{
        id : var;
        velocity : var;

        constructor RigidBody(objID : int, vel : double)
        {
            id = objID;
            velocity = vel;
        }

        def GetVelocity : double(drag : int)
        {
            return = velocity * drag;
        }
    }

    class Particle extends RigidBody
	{
        lifetime : var;

        constructor Particle(objID : int, vel : double, life : double)
        {
            id = objID;
            velocity = vel;
            lifetime = life;
        }
    }
 
 
    // TODO Jun: Fix defect, allow statements (or maybe just preprocs?) before a class decl

    // Define some constants
    kRigidBodyID    = 0; 
    kParticleID     = 1;

    kGravityCoeff   = 9.8;

       
    //================================
    // Simulate physical object 1
    //================================

    // Construct a base rigid body
    rb = RigidBody.RigidBody(kRigidBodyID, kGravityCoeff);
    rbVelocity = rb.GetVelocity(2);


    
    //================================
    // Simulate physical object 2
    //================================
    
    // Construct a particle that inherits from a rigid body
    kLifetime = 0.25;
    p = Particle.Particle(kParticleID, kGravityCoeff, kLifetime);
    lt = p.lifetime;
    particleVelocity = rb.GetVelocity(4);


";

            ExecutionMirror mirror = thisTest.RunScriptSource(code);

            Assert.IsTrue((double)mirror.GetValue("rbVelocity").Payload == 19.6);
            Assert.IsTrue((double)mirror.GetValue("lt").Payload == 0.25);
            Assert.IsTrue((double)mirror.GetValue("particleVelocity").Payload == 39.2);
        }
Example #2
0
        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.kTypeInt
            };
            classDefNode.varlist.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);
        }
Example #3
0
        public void T19_BasicIfElseTestingWithNumbers()
        {
            string          src    = @"a;
b;
c;
d;
[Imperative]
{
    a = 0;
    b = 0;
    c = 0;
    d = 0;
    if(1)
	{
		a = 1;
	}
	else
	{
		a = 2;
	}
	
	
	if(0)
	{
		b = 1;
	}
	else
	{
		b = 2;
	}
	
	if(0)
	{
		c = 1;
	}
	elseif(1)
	{
		c = 3;
	}
	
	if(0)
	{
		d = 1;
	}
	elseif(0)
	{
		d = 2;
	}
	else
	{
		d = 4;
	}
		
} 
 
 ";
            ExecutionMirror mirror = thisTest.RunScriptSource(src);

            Assert.IsTrue((Int64)mirror.GetValue("a").Payload == 1);
            Assert.IsTrue((Int64)mirror.GetValue("b").Payload == 2);
            Assert.IsTrue((Int64)mirror.GetValue("c").Payload == 3);
            Assert.IsTrue((Int64)mirror.GetValue("d").Payload == 4);
        }
Example #4
0
        public void T20_BasicIfElseTestingWithNumbers()
        {
            string          src    = @"a;
b;
c;
d;
e;
f;
[Imperative]
{
    a = 0;
    b = 0;
    c = 0;
    d = 0;
    e = 0;
    f = 0;
    if(1.5)
	{
		a = 1;
	}
	else
	{
		a = 2;
	}
	
	
	if(-1)
	{
		b = 1;
	}
	else
	{
		b = 2;
	}
	
	if(0)
	{
		c = 1;
	}
	elseif(20)
	{
		c = 3;
	}
	
	if(0)
	{
		d = 1;
	}
	elseif(0)
	{
		d = 2;
	}
	else
	{
		d = 4;
	}
	
	if(true)
	{
		e = 5;
	}
	
	if(false)
	{
		f = 1;
	}
	else
	{
		f = 6;
	}
		
} 
 
 ";
            ExecutionMirror mirror = thisTest.RunScriptSource(src);

            Assert.IsTrue((Int64)mirror.GetValue("a").Payload == 1);
            Assert.IsTrue((Int64)mirror.GetValue("b").Payload == 1);
            Assert.IsTrue((Int64)mirror.GetValue("c").Payload == 3);
            Assert.IsTrue((Int64)mirror.GetValue("d").Payload == 4);
            Assert.IsTrue((Int64)mirror.GetValue("e").Payload == 5);
            Assert.IsTrue((Int64)mirror.GetValue("f").Payload == 6);
        }
Example #5
0
        public void T10_TestInFunctionScope()
        {
            ExecutionMirror mirror = thisTest.RunScript(@"..\\..\\..\\Scripts\\TD\\Associative\\Assignment\\T10_TestInFunctionScope.ds");

            Assert.IsTrue((double)mirror.GetValue("test").Payload == 4.5);
        }
Example #6
0
        public void T26_Defect_1450854()
        {
            ExecutionMirror mirror = thisTest.RunScript(@"..\\..\\..\\Scripts\\TD\\Imperative\\Assignment\\T26_Defect_1450854.ds");

            Assert.IsTrue((Int64)mirror.GetValue("c").Payload == 3);
        }
Example #7
0
        public void T45__Defect_1452423_5()
        {
            ExecutionMirror mirror = thisTest.RunScript(@"..\\..\\..\\Scripts\\TD\\Imperative\\Assignment\\T45__Defect_1452423_5.ds");

            Assert.IsTrue(mirror.GetValue("a").DsasmValue.optype == ProtoCore.DSASM.AddressType.Null);
        }
Example #8
0
        //Test "RemoveDuplicate()"
        public void BIM30_RemoveDuplicate()
        {
            String code =
                @"
import(""FFITarget.dll"");
pt1 = ClassFunctionality.ClassFunctionality(0, 0, 0);
pt2 = ClassFunctionality.ClassFunctionality(0, 0, 1);
class C
{
    x : int;
    y : ClassFunctionality;
    constructor(p : int, q : ClassFunctionality)
    {
        x = p;
        y = q;
    }
}
a = {null,20,30,null,20,15,true,true,5,false};
b = {1,2,3,4,9,4,2,5,6,7,8,7,1,0,2};
c1 = C.C(1, pt1);
c2 = C.C(2, pt2);
c3 = C.C(1, pt1);
c4 = C.C(2, pt2);
rda = RemoveDuplicates(a);
rdb = RemoveDuplicates(b);
rdc = RemoveDuplicates({c1,c2,c3,c4});
rdd = RemoveDuplicates({{1,2,{5,{6}}}, {1,2,{5,6}}, {1,2,{5,{6}}}});
rde = RemoveDuplicates({""hello2"", ""hello"", 'r', ""hello2"", 's', 's', ""hello"", ' '});
rdf = RemoveDuplicates({});
rdg = RemoveDuplicates(1);
rdh = RemoveDuplicates({{c1,c2,c3},{c3,c2,c1},{c1,c2},{c2,c3,c1},{c3,c2,c1}});
p = rda[3];
q = rdb[4];
l = rdc[0];
z = l.x;
m1 = rdc[1].y.IntVal;
m2 = rdd[0][2][0];
m3 = rde[4];
m4 = rdh[2][1].x;
res1 = Count(rda);
res2 = Count(rdb);
res3 = Count(rdc);
res4 = Count(rdd);
res5 = Count(rde);
res6 = Count(rdf);
res7 = Count(rdh);
"                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    ;
            ExecutionMirror mirror = thisTest.RunScriptSource(code);

            Assert.IsTrue((Int64)mirror.GetValue("p").Payload == 15);
            Assert.IsTrue((Int64)mirror.GetValue("q").Payload == 9);
            Assert.IsTrue((Int64)mirror.GetValue("z").Payload == 1);
            thisTest.Verify("m1", 1);
            thisTest.Verify("m2", 5);
            thisTest.Verify("m3", ' ');
            thisTest.Verify("m4", 1);
            thisTest.Verify("res1", 7);
            thisTest.Verify("res2", 10);
            thisTest.Verify("res3", 2);
            thisTest.Verify("res4", 2);
            thisTest.Verify("res5", 5);
            thisTest.Verify("res6", 0);
            thisTest.Verify("res7", 3);
            thisTest.Verify("rdg", 1);
        }
Example #9
0
        public void T38_Defect_1449928()
        {
            ExecutionMirror mirror = thisTest.RunScript(@"..\\..\\..\\Scripts\\TD\\Imperative\\Assignment\\T38_Defect_1449928.ds");

            Assert.IsTrue((double)mirror.GetValue("c").Payload == -0.33333333333333331);
        }
Example #10
0
        public void T43__Defect_1452423_3()
        {
            ExecutionMirror mirror = thisTest.RunScript(@"..\\..\\..\\Scripts\\TD\\Imperative\\Assignment\\T43__Defect_1452423_3.ds");

            Assert.IsTrue((Int64)mirror.GetValue("b").Payload == 1);
        }
Example #11
0
        public void T35_Defect_1450727_2()
        {
            ExecutionMirror mirror = thisTest.RunScript(@"..\\..\\..\\Scripts\\TD\\Imperative\\Assignment\\T35_Defect_1450727_2.ds");

            Assert.IsTrue((double)mirror.GetValue("z").Payload == -8.1);
        }
Example #12
0
        public void T02_SampleTestUsingCodeFromExternalFile()
        {
            ExecutionMirror mirror = thisTest.RunScript(@"..\\..\\..\\Scripts\\TD\\Imperative\\Assignment\\T02_SampleTestUsingCodeFromExternalFile.ds");

            Assert.IsTrue((Int64)mirror.GetValue("variable").Payload == 5);
        }
Example #13
0
        public void T32_Defect_1449877_2()
        {
            ExecutionMirror mirror = thisTest.RunScript(@"..\\..\\..\\Scripts\\TD\\Imperative\\Assignment\\T32_Defect_1449877_2.ds");

            Assert.IsTrue((Int64)mirror.GetValue("d").Payload == 2);
        }
Example #14
0
        public void TestRoundTrip_ClassDecl_MemFunctionCall_01()
        {
            int             result1 = 20;
            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
            //       def foo (b:int)
            //       {
            //           b = 10;
            //           return = b + 10;
            //       }
            //  }
            //
            //  p = bar.bar();
            //  a = p.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.kTypeVar;
            returnType.Name        = ProtoCore.DSDefinitions.Keyword.Var;
            funcDefNode.ReturnType = returnType;

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

            // Add the member function 'foo'
            classDefNode.funclist.Add(funcDefNode);


            // 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.kTypeInt
            };
            classDefNode.varlist.Add(varDeclNode);


            // Add the constructed class AST
            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));


            //  a = p.f;
            ProtoCore.AST.AssociativeAST.FunctionCallNode functionCall = new ProtoCore.AST.AssociativeAST.FunctionCallNode();
            functionCall.Function = new ProtoCore.AST.AssociativeAST.IdentifierNode("foo");

            ProtoCore.AST.AssociativeAST.IdentifierListNode identListFunctionCall = new ProtoCore.AST.AssociativeAST.IdentifierListNode();
            identListFunctionCall.LeftNode  = new ProtoCore.AST.AssociativeAST.IdentifierNode("p");
            identListFunctionCall.RightNode = functionCall;

            ProtoCore.AST.AssociativeAST.BinaryExpressionNode stmtPropertyAccess = new ProtoCore.AST.AssociativeAST.BinaryExpressionNode(
                new ProtoCore.AST.AssociativeAST.IdentifierNode("a"),
                identListFunctionCall,
                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);
        }
Example #15
0
        public void T47_TestBooleanOperationOnNull()
        {
            ExecutionMirror mirror = thisTest.RunScript(@"..\\..\\..\\Scripts\\TD\\Imperative\\Assignment\\T47_TestBooleanOperationOnNull.ds");

            Assert.IsTrue((Int64)mirror.GetValue("d").Payload == 0);
        }
Example #16
0
        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.kTypeVar;
            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);
        }
Example #17
0
        public void T07_TestOutsideBlock()
        {
            ExecutionMirror mirror = thisTest.RunScript(@"..\\..\\..\\Scripts\\TD\\Imperative\\Assignment\\T07_TestOutsideBlock.ds");

            Assert.IsTrue((Int64)mirror.GetValue("b").Payload == 2);
        }
Example #18
0
        public void T67_Defect_1467597()
        {
            ExecutionMirror mirror = thisTest.RunScript(@"..\\..\\..\\Scripts\\TD\\Associative\\Assignment\\InstanceMethod_test_1.ds");

            Assert.IsTrue((Int64)mirror.GetValue("otherVar").Payload == 26);
        }
Example #19
0
        public void T01_TestAllPassCondition()
        {
            string          src    = @"x;
y;
z;
[Imperative]
{
 a1 = 2 ;
 a2 = -1;
 a3 = 101;
 a4 = 0;
 
 b1 = 1.0;
 b2 = 0.0;
 b3 = 0.1;
 b4 = -101.99;
 b5 = 10.0009;
 
 c1 = { 0, 1, 2, 3};
 c2 = { 1, 0.2};
 c3 = { 0, 1.4, true };
 c4 = {{0,1}, {2,3 } };
 
 x = {0, 0, 0, 0};
 if(a1 == 2 ) // pass condition
 {
     x[0] = 1;
 }  
 if(a2 <= -1 )  // pass condition
 {
     x[1] = 1;
 }
 if(a3 >= 101 )  // pass condition
 {
     x[2] = 1;
 }
 if(a4 == 0 )  // pass condition
 {
     x[3] = 1;
 }
 
 
 y = {0, 0, 0, 0, 0};
 if(b1 == 1.0 ) // pass condition
 {
     y[0] = 1;
 }  
 if(b2 <= 0.0 )  // pass condition
 {
     y[1] = 1;
 }
 if(b3 >= 0.1 )  // pass condition
 {
     y[2] = 1;
 }
 if(b4 == -101.99 )  // pass condition
 {
     y[3] = 1;
 }
 if(b5 == 10.0009 )  // pass condition
 {
     y[4] = 1;
 }
 
 
 z = {0, 0, 0, 0};
 if(c1[0] == 0 ) // pass condition
 {
     z[0] = 1;
 }  
 if(c2[1] <= 0.2 )  // pass condition
 {
     z[1] = 1;
 }
 if(c3[2] == true )  // pass condition
 {
     z[2] = 1;
 }
  if(c4[0][0] == 0 )  // pass condition
 {
     z[3] = 1;
 }
 
}";
            ExecutionMirror mirror = thisTest.RunScriptSource(src);
            Object          o      = mirror.GetValue("x").Payload;

            ProtoCore.DSASM.Mirror.DsasmArray x = (ProtoCore.DSASM.Mirror.DsasmArray)o;
            Assert.IsTrue((Int64)x.members[0].Payload == 1);
            Assert.IsTrue((Int64)x.members[1].Payload == 1);
            Assert.IsTrue((Int64)x.members[2].Payload == 1);
            Assert.IsTrue((Int64)x.members[3].Payload == 1);
            Object o1 = mirror.GetValue("y").Payload;

            ProtoCore.DSASM.Mirror.DsasmArray y = (ProtoCore.DSASM.Mirror.DsasmArray)o1;
            Assert.IsTrue((Int64)y.members[0].Payload == 1);
            Assert.IsTrue((Int64)y.members[1].Payload == 1);
            Assert.IsTrue((Int64)y.members[2].Payload == 1);
            Assert.IsTrue((Int64)y.members[3].Payload == 1);
            Assert.IsTrue((Int64)y.members[4].Payload == 1);
            Object o2 = mirror.GetValue("z").Payload;

            ProtoCore.DSASM.Mirror.DsasmArray z = (ProtoCore.DSASM.Mirror.DsasmArray)o2;
            Assert.IsTrue((Int64)z.members[0].Payload == 1);
            Assert.IsTrue((Int64)z.members[1].Payload == 1);
            Assert.IsTrue((Int64)z.members[2].Payload == 1);
            Assert.IsTrue((Int64)z.members[3].Payload == 1);
        }
Example #20
0
        public void T11_TestInClassScope()
        {
            ExecutionMirror mirror = thisTest.RunScript(@"..\\..\\..\\Scripts\\TD\\Associative\\Assignment\\T11_TestInClassScope.ds");

            Assert.IsTrue((Int64)mirror.GetValue("b1").Payload == 2);
        }
Example #21
0
        public void T15_TestInRecursiveFunctionScope()
        {
            ExecutionMirror mirror = thisTest.RunScript(@"..\\..\\..\\Scripts\\TD\\Imperative\\Assignment\\T15_TestInRecursiveFunctionScope.ds");

            Assert.IsTrue((Int64)mirror.GetValue("val").Payload == 120);
        }