Ejemplo n.º 1
0
        public void RedefineWithFunctions03()
        {
            String code =
@"
class C
{
    mx : var;
    constructor C()
    {
        mx = 10;
    }
    def f(a : int)
    {
        mx = a + 1;
        return = mx;
    }
}
x = 10;
p = C.C();
x = p.f(x);
";
            ProtoScript.Runners.ProtoScriptRunner fsr = new ProtoScript.Runners.ProtoScriptRunner();
            runtimeCore = fsr.Execute(code, core); ExecutionMirror mirror = runtimeCore.Mirror;
            Assert.IsTrue((Int64)mirror.GetValue("x").Payload == 11);
        }
Ejemplo n.º 2
0
 protected int ExecuteAndVerify(String code, ValidationData[] data, Dictionary<string, Object> context, out int nErrors)
 {
     ProtoCore.Core core = Setup();
     ProtoScript.Runners.ProtoScriptRunner fsr = new ProtoScript.Runners.ProtoScriptRunner();
     ProtoCore.CompileTime.Context compileContext = new ProtoCore.CompileTime.Context(code, context);
     ProtoCore.RuntimeCore runtimeCore = null;
     ExecutionMirror mirror = fsr.Execute(compileContext, core, out runtimeCore);
     int nWarnings = runtimeCore.RuntimeStatus.WarningCount;
     nErrors = core.BuildStatus.ErrorCount;
     if (data == null)
     {
         runtimeCore.Cleanup();
         return nWarnings + nErrors;
     }
     TestFrameWork thisTest = new TestFrameWork();
     foreach (var item in data)
     {
         if (item.ExpectedValue == null)
         {
             object nullOb = null;
             TestFrameWork.Verify(mirror, item.ValueName, nullOb, item.BlockIndex);
         }
         else
         {
             TestFrameWork.Verify(mirror, item.ValueName, item.ExpectedValue, item.BlockIndex);
         }
     }
     runtimeCore.Cleanup();
     return nWarnings + nErrors;
 }
Ejemplo n.º 3
0
        public void GetUpcastChainTest()
        {
            String code =
@"class A {}
class B extends A {}
class C extends B {}
";
            ProtoScript.Runners.ProtoScriptRunner fsr = new ProtoScript.Runners.ProtoScriptRunner();
            ProtoCore.RuntimeCore runtimeCore = null;
            runtimeCore = fsr.Execute(code, core); ExecutionMirror mirror = runtimeCore.Mirror;
            int idA = core.ClassTable.IndexOf("A");
            int idB = core.ClassTable.IndexOf("B");
            int idC = core.ClassTable.IndexOf("C");
            ClassNode cnA = core.ClassTable.ClassNodes[idA];
            ClassNode cnB = core.ClassTable.ClassNodes[idB];
            ClassNode cnC = core.ClassTable.ClassNodes[idC];
            List<int> idsA = ClassUtils.GetClassUpcastChain(cnA, runtimeCore);
            List<int> idsB = ClassUtils.GetClassUpcastChain(cnB, runtimeCore);
            List<int> idsC = ClassUtils.GetClassUpcastChain(cnC, runtimeCore);
            Assert.IsTrue(idsA.Count == 2);
            Assert.IsTrue(idsA.Contains(idA));

            Assert.IsTrue(idsB.Count == 3);
            Assert.IsTrue(idsB.Contains(idA));
            Assert.IsTrue(idsB.Contains(idB));
            Assert.IsTrue(idsC.Count == 4);
            Assert.IsTrue(idsC.Contains(idA));
            Assert.IsTrue(idsC.Contains(idB));
            Assert.IsTrue(idsC.Contains(idC));
        }
Ejemplo n.º 4
0
            ProtoScript.Runners.ProtoScriptRunner fsr = new ProtoScript.Runners.ProtoScriptRunner();
            fsr.Execute(
@"
[Associative]
{
    a = [Imperative]
        {
Ejemplo n.º 5
0
        public void RedefineWithFunctions03()
        {
            String code =
@"
class C
{
    mx : var;
    constructor C()
Ejemplo n.º 6
0
    }
    def f(a : int)
    {
        mx = a + 1;
        return = mx;
    }
}
x = 10;
Ejemplo n.º 7
0
            runtimeCore = fsr.Execute(code, core); ExecutionMirror mirror = runtimeCore.Mirror;
            Assert.IsTrue((Int64)mirror.GetValue("x").Payload == 123);
            Assert.IsTrue((Int64)mirror.GetValue("y").Payload == 345);
        }

        [Test]
        [Category("DSDefinedClass_Ported")]
        public void SimpleMethodOverload2()
Ejemplo n.º 8
0
 ExecutionMirror mirror = thisTest.RunScriptSource(code);
 thisTest.Verify("f0", false);
 thisTest.Verify("f1", false);
 thisTest.Verify("f2", false);
 thisTest.Verify("f3", false);
 thisTest.Verify("t0", true);
 thisTest.Verify("t1", true);
 thisTest.Verify("t2", true);
        public void T0000_sample()
        {
            String code =
@"
x = 1;
";
            ProtoScript.Runners.ProtoScriptRunner fsr = new ProtoScript.Runners.ProtoScriptRunner();
            String errmsg = "";
            ExecutionMirror mirror = thisTest.VerifyRunScriptSource(code, errmsg);
Ejemplo n.º 10
0
test = foo( x<1>,y<2> );
";
            ProtoScript.Runners.ProtoScriptRunner fsr = new ProtoScript.Runners.ProtoScriptRunner();
            String errmsg = "";
            ExecutionMirror mirror = thisTest.VerifyRunScriptSource(code, errmsg);
            thisTest.Verify("test", new Object[] { new Object[] { 2, 3 }, new Object[] { 3, 4 } });
        }

        [Test]
Ejemplo n.º 11
0
            String code =
@"
def foo(a,b)
{
    return = a + b;
}
x = {0,1};
y = {2,3};
test = foo( x<1>,y<2> );
Ejemplo n.º 12
0
        public void TestDS()
        {
            String code =
@"
size;
[Imperative]
{
	size = 5;
}
Ejemplo n.º 13
0
@"def f1(i : int, k : int)
{
return = i + k;
}
def f2(i : int, k : int)
{
return = i - k;
}
x = 12;
Ejemplo n.º 14
0
        public void PreClarifyPreParseBracket001()
        {
            String code =
@"x;
[Associative]
{
 a = {1001,1002};    
 // This is failing the pre-parse. 
 // Probably has somthing to do with convertingthe language blocks into binary exprs
Ejemplo n.º 15
0
	def f()
	{
		return = 123;
	}
    def f(a : int)
    {
        return = a;
	}
    x = f();
Ejemplo n.º 16
0
            ProtoScript.Runners.ProtoScriptRunner fsr = new ProtoScript.Runners.ProtoScriptRunner();
            runtimeCore = fsr.Execute(code, core); ExecutionMirror mirror = runtimeCore.Mirror;
            Assert.IsTrue((Int64)mirror.GetValue("x").Payload == 123);
            Assert.IsTrue((Int64)mirror.GetValue("y").Payload == 345);
        }

        [Test]
        [Category("DSDefinedClass_Ported")]
        public void SimpleMethodOverload1()
Ejemplo n.º 17
0
        public void LiteralRetrival()
        {
            String code =
@"
foo;
[Associative]
{
	foo = 5;
}
Ejemplo n.º 18
0
        return = 0;
	}
	x = 10;
    y = 40;
	n = scale();
	n = scale(10);
";
            ProtoScript.Runners.ProtoScriptRunner fsr = new ProtoScript.Runners.ProtoScriptRunner();
            runtimeCore = fsr.Execute(code, core); ExecutionMirror mirror = runtimeCore.Mirror;
Ejemplo n.º 19
0
        public void SimpleAssignment()
        {
            String code =
@"
	fx : var;
	fy : var;
	fx = 123;
	fy = 345;
	
Ejemplo n.º 20
0
     });
 }
 [Test]
 public void ParserFailTest2()
 {
     ProtoScript.Runners.ProtoScriptRunner fsr = new ProtoScript.Runners.ProtoScriptRunner();
     //@TODO: What exception should this throw
     Assert.Throws(typeof(ProtoCore.Exceptions.CompileErrorsOccured), () =>
     {
         fsr.Execute(
Ejemplo n.º 21
0
    b = 4;
}
", core, out runtimeCore);
        }
        [Test]
        public void TestMultLanguageImperativeAssociative()
        {
            ProtoScript.Runners.ProtoScriptRunner fsr = new ProtoScript.Runners.ProtoScriptRunner();
            fsr.Execute(
@"
Ejemplo n.º 22
0
", core);
        }
    }

    [TestFixture]
    class MultiLangNegitiveTests : ProtoTestBase
    {
        //Negitive Tests with distortions of the Language def block
        [Test]
        public void ParserFailTest1()
Ejemplo n.º 23
0
 public void SimpleExpr()
 {
     ProtoScript.Runners.ProtoScriptRunner fsr = new ProtoScript.Runners.ProtoScriptRunner();
     runtimeCore = fsr.Execute(
                 @"
                 [Associative]
                 {
                     a = 10;
                 }
                 ", core);
 }
Ejemplo n.º 24
0
            ExecutionMirror mirror = fsr.Execute(code, core, out runtimeCore);
            Obj o = mirror.GetValue("foo");
            Assert.IsTrue((Int64)o.Payload == 5);
        }

        [Test]
        public void ArrayRetrival1D()
        {
            String code =
@"
foo;
Ejemplo n.º 25
0
        public void TestSingleLanguageImperative()
        {
            ProtoScript.Runners.ProtoScriptRunner fsr = new ProtoScript.Runners.ProtoScriptRunner();
            runtimeCore = fsr.Execute(
@"
[Imperative]
{
    a = 3;
    b = 4;
}
", core);
        }
Ejemplo n.º 26
0
        public void RedefineWithFunctions01()
        {
            String code =
@"
def f(i : int)
{
    return = i + 1;
}
x = 1000;
x = f(x);
";
            ProtoScript.Runners.ProtoScriptRunner fsr = new ProtoScript.Runners.ProtoScriptRunner();
            runtimeCore = fsr.Execute(code, core); ExecutionMirror mirror = runtimeCore.Mirror;
            Assert.IsTrue((Int64)mirror.GetValue("x").Payload == 1001);
        }
Ejemplo n.º 27
0
 public void SimpleFuncDef()
 {
     ProtoScript.Runners.ProtoScriptRunner fsr = new ProtoScript.Runners.ProtoScriptRunner();
     runtimeCore = fsr.Execute(
                 @"
                 [Associative]
                 {
                     def foo : int (b : int)
                     {
                         return = 2;
                     }
                     x = foo(2);
                 }
                 ", core);
 }
Ejemplo n.º 28
0
        public void TestMultLanguageImperativeAssociative()
        {
            ProtoScript.Runners.ProtoScriptRunner fsr = new ProtoScript.Runners.ProtoScriptRunner();
            runtimeCore = fsr.Execute(
@"
[Imperative]
{
    [Associative]
    {
        return= 5;
    }
    b = 4;
}
", core);
        }
Ejemplo n.º 29
0
        public void StackValueDiffTestDefect()
        {
            String code =
@"[Imperative]
{
	a = 1;
    b = 1.0;
}
";
            ProtoScript.Runners.ProtoScriptRunner fsr = new ProtoScript.Runners.ProtoScriptRunner();
            ProtoCore.RuntimeCore runtimeCore = null;
            runtimeCore = fsr.Execute(code, core); ExecutionMirror mirror = runtimeCore.Mirror;
            StackValue svA = mirror.GetRawFirstValue("a");
            StackValue svB = mirror.GetRawFirstValue("b");
            Assert.IsTrue(svA.metaData.type != svB.metaData.type);
        }
Ejemplo n.º 30
0
        public void TwoSimpleExprInModifierStack()
        {
            ProtoScript.Runners.ProtoScriptRunner fsr = new ProtoScript.Runners.ProtoScriptRunner();
            ExecutionMirror mirror = fsr.Execute(
                        @"
a;
                        [Associative]
                        {
                            a = 
                                {
                                    10;
                                    20;
                                }
                        }
                        ", core, out runtimeCore);
            Assert.IsTrue((Int64)mirror.GetValue("a", 0).Payload == 20);
        }
Ejemplo n.º 31
0
        public void SimpleCtorResolution04()
        {
            String code =
                @"
class Sample
{
    mx : var;
    constructor Create()
    {}
        
    constructor Create(intval : int)
    {}
        
    constructor Create(doubleval : double)
    {
        mx = doubleval;
    }
        
    constructor Create(intval : int, doubleval : double)
    {}
}
    
//    default ctor
s1 = Sample.Create();
    
//    ctor with int
s2 = Sample.Create(1);
    
//    ctor with double
s3 = Sample.Create(1.0);
    
//    ctor with int and double
s4 = Sample.Create(1, 1.0);
d = s3.mx;
"                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      ;

            ProtoScript.Runners.ProtoScriptRunner fsr = new ProtoScript.Runners.ProtoScriptRunner();
            runtimeCore = fsr.Execute(code, core); ExecutionMirror mirror = runtimeCore.Mirror;
            Assert.IsTrue((double)mirror.GetValue("d").Payload == 1);
        }
Ejemplo n.º 32
0
        public void TestArrayRankJagged()
        {
            String code =
                @"
a;b;c;d;e;
[Imperative]
{
	a = {1,{2},3};
    b = {1.0, {2.0, 3.0, 3.0}};
    c = {1.0, {2.0, {9}}};
    d = {{1}, {}, {1}};
    e = {{1, 2, 3}, {1, {2}, 3}, {{{1}}, 2, 3}};
}
";

            ProtoScript.Runners.ProtoScriptRunner fsr = new ProtoScript.Runners.ProtoScriptRunner();
            ProtoCore.RuntimeCore runtimeCore         = null;
            runtimeCore = fsr.Execute(code, core); ExecutionMirror mirror = runtimeCore.Mirror;
            StackValue svA = mirror.GetRawFirstValue("a");
            StackValue svB = mirror.GetRawFirstValue("b");
            StackValue svC = mirror.GetRawFirstValue("c");
            StackValue svD = mirror.GetRawFirstValue("d");
            StackValue svE = mirror.GetRawFirstValue("e");
            var        a   = ProtoCore.Utils.ArrayUtils.GetMaxRankForArray(svA, runtimeCore);

            Assert.IsTrue(a == 2);
            var b = ProtoCore.Utils.ArrayUtils.GetMaxRankForArray(svB, runtimeCore);

            Assert.IsTrue(b == 2);
            var c = ProtoCore.Utils.ArrayUtils.GetMaxRankForArray(svC, runtimeCore);

            Assert.IsTrue(c == 3);
            var d = ProtoCore.Utils.ArrayUtils.GetMaxRankForArray(svD, runtimeCore);

            Assert.IsTrue(d == 2);
            var e = ProtoCore.Utils.ArrayUtils.GetMaxRankForArray(svE, runtimeCore);

            Assert.IsTrue(e == 4);
            // Assert.IsTrue((Int64)o.Payload == 5);
        }
Ejemplo n.º 33
0
        public void ModifierStackWithArrayAndFunctionReplication()
        {
            ProtoScript.Runners.ProtoScriptRunner fsr = new ProtoScript.Runners.ProtoScriptRunner();
            runtimeCore = fsr.Execute(
                @"ainit;afirst;b;
                         [Associative]
                         {
	                         def foo : int(x : int)
	                         {
		                        a = x+2;
		                        return = a;
	                         }
                             b = 
                                 {
                                     {1,2,3} => ainit;
                                     foo(ainit) => afirst;
                                 }
                         }
                        ", core);
            ExecutionMirror mirror = runtimeCore.Mirror;
            Obj             o      = mirror.GetValue("ainit");
            List <Obj>      os     = mirror.GetArrayElements(o);

            Assert.IsTrue(os.Count == 3);
            Assert.IsTrue((Int64)os[0].Payload == 1);
            Assert.IsTrue((Int64)os[1].Payload == 2);
            Assert.IsTrue((Int64)os[2].Payload == 3);
            o  = mirror.GetValue("afirst");
            os = mirror.GetArrayElements(o);
            Assert.IsTrue(os.Count == 3);
            Assert.IsTrue((Int64)os[0].Payload == 3);
            Assert.IsTrue((Int64)os[1].Payload == 4);
            Assert.IsTrue((Int64)os[2].Payload == 5);
            o  = mirror.GetValue("b");
            os = mirror.GetArrayElements(o);
            Assert.IsTrue(os.Count == 3);
            Assert.IsTrue((Int64)os[0].Payload == 3);
            Assert.IsTrue((Int64)os[1].Payload == 4);
            Assert.IsTrue((Int64)os[2].Payload == 5);
        }
Ejemplo n.º 34
0
        public void TestMethodOverloadArray()
        {
            string code =
                @"
                def execute(a : var)
                { 
                    return = -1; 
                }
                def execute(arr : var[])
                {
                    return = 2;
                }
                arr = {1, 2, 3};
                val = execute(arr);
                "                                                                                                                                                                                                                                                                                                                 ;

            ProtoScript.Runners.ProtoScriptRunner fsr = new ProtoScript.Runners.ProtoScriptRunner();
            ExecutionMirror mirror = fsr.Execute(code, core, out runtimeCore);

            Assert.IsTrue((Int64)mirror.GetValue("val").Payload == 2);
            Assert.IsTrue(core.BuildStatus.WarningCount == 0);
        }
Ejemplo n.º 35
0
        public void SimpleMethodOverload1()
        {
            String code =
                @"
	def f()
	{
		return = 123;
	}
    def f(a : int)
    {
        return = a;
	}

    x = f();
    y = f(345);
"                                                                                                                                ;

            ProtoScript.Runners.ProtoScriptRunner fsr = new ProtoScript.Runners.ProtoScriptRunner();
            runtimeCore = fsr.Execute(code, core); ExecutionMirror mirror = runtimeCore.Mirror;
            Assert.IsTrue((Int64)mirror.GetValue("x").Payload == 123);
            Assert.IsTrue((Int64)mirror.GetValue("y").Payload == 345);
        }
Ejemplo n.º 36
0
        public void ModifierStackWithName()
        {
            ProtoScript.Runners.ProtoScriptRunner fsr = new ProtoScript.Runners.ProtoScriptRunner();
            runtimeCore = fsr.Execute(
                @"
a;ainit;
                        [Associative]
                        {
                            a = 
                                {
                                2 => ainit;
                                +4;
                                -3;
                                *2;
                                 }
                        }
                        ", core);
            ExecutionMirror mirror = runtimeCore.Mirror;

            thisTest.Verify("ainit", 2);
            thisTest.Verify("a", 6);
        }
Ejemplo n.º 37
0
        public void TestMethodWithArrayInput2()
        {
            string code = @"
                            class A
                            {
                            }
                            class B extends A
                            {
                            }
                            def Test(arr : A[])
                            {
                                    return = 123;
                            }
                            a = {B.B(), A.A(), B.B()};
                            val = Test(a);
                            "                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       ;

            ProtoScript.Runners.ProtoScriptRunner fsr = new ProtoScript.Runners.ProtoScriptRunner();
            runtimeCore = fsr.Execute(code, core); ExecutionMirror mirror = runtimeCore.Mirror;
            Assert.IsTrue((Int64)mirror.GetValue("val").Payload == 123);
            Assert.IsTrue(core.BuildStatus.WarningCount == 0);
        }
Ejemplo n.º 38
0
        public void NestedBlockInFunction01()
        {
            String code =
                @"
def f : int (p : int)
{
    loc = 32;
	s = [Imperative]
	{
        n = loc + p;
        return = n;
	}
	return = s;
}
a = f(16);	
    
"                                                                                                                                                          ;

            ProtoScript.Runners.ProtoScriptRunner fsr = new ProtoScript.Runners.ProtoScriptRunner();
            runtimeCore = fsr.Execute(code, core); ExecutionMirror mirror = runtimeCore.Mirror;
            Assert.IsTrue((Int64)mirror.GetValue("a").Payload == 48);
        }
Ejemplo n.º 39
0
        public void ArrayRetrival2DJagged()
        {
            String code =
                @"
foo;
[Associative]
{
	foo = {{5}, 6};
}
";

            ProtoScript.Runners.ProtoScriptRunner fsr = new ProtoScript.Runners.ProtoScriptRunner();
            runtimeCore = fsr.Execute(code, core); ExecutionMirror mirror = runtimeCore.Mirror;
            Obj o = mirror.GetValue("foo");

            ProtoCore.DSASM.Mirror.DsasmArray a = (ProtoCore.DSASM.Mirror.DsasmArray)o.Payload;
            Assert.IsTrue(a.members.Length == 2);
            ProtoCore.DSASM.Mirror.DsasmArray a2 = (ProtoCore.DSASM.Mirror.DsasmArray)((a.members[0]).Payload);
            Assert.IsTrue(a2.members.Length == 1);
            Assert.IsTrue((Int64)a2.members[0].Payload == 5);
            Assert.IsTrue((Int64)a.members[1].Payload == 6);
        }
Ejemplo n.º 40
0
        public void ModifierStackWithName()
        {
            ProtoScript.Runners.ProtoScriptRunner fsr = new ProtoScript.Runners.ProtoScriptRunner();
            runtimeCore = fsr.Execute(
                @"
a;ainit;
                        [Associative]
                        {
                            a = 
                                {
                                2 => ainit;
                                +4;
                                -3;
                                *2;
                                 }
                        }
                        ", core);
            ExecutionMirror mirror = runtimeCore.Mirror;

            Assert.IsTrue((Int64)mirror.GetValue("ainit", 0).Payload == 2);
            Assert.IsTrue((Int64)mirror.GetValue("a", 0).Payload == 6);
        }
Ejemplo n.º 41
0
        public void Nestedblocks_Inside_1467358()
        {
            string code = @"
                             def foo()
                                {
                                    t = [Imperative]
                                    {
                                        t1 = [Associative]
                                        {
                                            t2 = 6;
                                            return = t2;
                                        }
                                        return = t1;
                                    }
                                    return = t;
                                }
                                def foo2()
                                {
                                    t = [Associative]
                                    {
                                        t1 = [Imperative]
                                        {
                                            t2 = 6;
                                            return = t2;
                                        }
                                        return = t1;
                                    }
                                    return = t;
                                }
                                p1 = foo(); // expected 6, got null
                                p2 = foo2(); // expected 6, got 6
"                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 ;

            ProtoScript.Runners.ProtoScriptRunner fsr = new ProtoScript.Runners.ProtoScriptRunner();
            ExecutionMirror mirror = fsr.Execute(code, core, out runtimeCore);

            Assert.IsTrue((Int64)mirror.GetValue("p1").Payload == 6);
            Assert.IsTrue((Int64)mirror.GetValue("p2").Payload == 6);
        }
Ejemplo n.º 42
0
        public void ModifierStackWithTwoNames()
        {
            ProtoScript.Runners.ProtoScriptRunner fsr = new ProtoScript.Runners.ProtoScriptRunner();
            ExecutionMirror mirror = fsr.Execute(
                @"
a;a@init;a@first;
                        [Associative]
                        {
                            a = 
                                {
                                    3 => a@init;
                                    +1 => a@first;
                                    +a@first;
                                    *2;
                                }
                        }
                        ", core, out runtimeCore);

            Assert.IsTrue((Int64)mirror.GetValue("a@init", 0).Payload == 3);
            Assert.IsTrue((Int64)mirror.GetValue("a@first", 0).Payload == 4);
            Assert.IsTrue((Int64)mirror.GetValue("a", 0).Payload == 16);
        }
Ejemplo n.º 43
0
        public void TestArrayRankSimple()
        {
            String code =
                @"a;b;c;d;e;
[Imperative]
{
	a = [1,2,3];
    b = [1.0, 2.0, 3.0, 3.0];
    c = [1.0, 2.0, 9];
    d = [[1], [1], [1]];
    e = [[1, 2, 3], [1, 2, 3], [1, 2, 3]];
}
";

            ProtoScript.Runners.ProtoScriptRunner fsr = new ProtoScript.Runners.ProtoScriptRunner();
            ProtoCore.RuntimeCore runtimeCore         = null;
            runtimeCore = fsr.Execute(code, core); ExecutionMirror mirror = runtimeCore.Mirror;
            StackValue svA = mirror.GetRawFirstValue("a");
            StackValue svB = mirror.GetRawFirstValue("b");
            StackValue svC = mirror.GetRawFirstValue("c");
            StackValue svD = mirror.GetRawFirstValue("d");
            StackValue svE = mirror.GetRawFirstValue("e");
            var        a   = ProtoCore.Utils.ArrayUtils.GetMaxRankForArray(svA, runtimeCore);

            Assert.IsTrue(a == 1);
            var b = ProtoCore.Utils.ArrayUtils.GetMaxRankForArray(svB, runtimeCore);

            Assert.IsTrue(b == 1);
            var c = ProtoCore.Utils.ArrayUtils.GetMaxRankForArray(svC, runtimeCore);

            Assert.IsTrue(c == 1);
            var d = ProtoCore.Utils.ArrayUtils.GetMaxRankForArray(svD, runtimeCore);

            Assert.IsTrue(d == 2);
            var e = ProtoCore.Utils.ArrayUtils.GetMaxRankForArray(svE, runtimeCore);

            Assert.IsTrue(e == 2);
            // Assert.IsTrue((Int64)o.Payload == 5);
        }
Ejemplo n.º 44
0
        public void IsArrayTest()
        {
            String code =
                @"a;b;c;
[Imperative]
{
	a = [1,2,3];
    b = 1;
    c = a;
}
";

            ProtoScript.Runners.ProtoScriptRunner fsr = new ProtoScript.Runners.ProtoScriptRunner();
            ProtoCore.RuntimeCore runtimeCore         = null;
            runtimeCore = fsr.Execute(code, core); ExecutionMirror mirror = runtimeCore.Mirror;
            StackValue svA = mirror.GetRawFirstValue("a");
            StackValue svB = mirror.GetRawFirstValue("b");
            StackValue svC = mirror.GetRawFirstValue("c");

            Assert.IsTrue(svA.IsArray);
            Assert.IsTrue(!svB.IsArray);
            Assert.IsTrue(svC.IsArray);
        }
Ejemplo n.º 45
0
        public void T22_Defect_1467166_3()
        {
            String code =
@"
def foo()
{
    return null;
}
i = [Imperative] 
{
   x1 = null == null ? 1 : 0;
   x2 = null != null ? 1 : 0;
   x3 = null == a ? 1 : 0;
   x4 = foo2(1) == a ? 1 : 0;
   x5 = foo() == null ? 1 : 0;
   return [x1, x2, x3, x4, x5];
}
";
            ProtoScript.Runners.ProtoScriptRunner fsr = new ProtoScript.Runners.ProtoScriptRunner();
            String errmsg = "";
            ExecutionMirror mirror = thisTest.VerifyRunScriptSource(code, errmsg);
            thisTest.Verify("i", new[] {1, 0, 1, 1, 1});
        }
Ejemplo n.º 46
0
        public void ModifierStackWithTwoNames()
        {
            ProtoScript.Runners.ProtoScriptRunner fsr = new ProtoScript.Runners.ProtoScriptRunner();
            runtimeCore = fsr.Execute(
                @"
a;ainit;afirst;
                        [Associative]
                        {
                            a = 
                                {
                                    3 => ainit;
                                    +1 => afirst;
                                    +afirst;
                                    *2;
                                }
                        }
                        ", core);
            ExecutionMirror mirror = runtimeCore.Mirror;

            thisTest.Verify("ainit", 3);
            thisTest.Verify("afirst", 4);
            thisTest.Verify("a", 16);
        }
Ejemplo n.º 47
0
        public void TestMethodOverlaodAndArrayInput4()
        {
            string code =
                @"
                class A
                {
                }
                class B extends A
                {
                    static def execute(b : B)
                    { 
                        return = -1; 
                    }
                    def execute(arr : B[])
                    {
                        return = 2;
                    }
                }
                class C extends B
                {
                }
                arr = {C.C(), B.B(), C.C()};
                val = B.execute(arr);
                val1 = val[0];
                val2 = val[1];
                val3 = val[2];
                "                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       ;

            ProtoScript.Runners.ProtoScriptRunner fsr = new ProtoScript.Runners.ProtoScriptRunner();
            ExecutionMirror mirror = fsr.Execute(code, core, out runtimeCore);

            Assert.IsTrue((Int64)mirror.GetValue("val1").Payload == -1);
            Assert.IsTrue((Int64)mirror.GetValue("val2").Payload == -1);
            Assert.IsTrue((Int64)mirror.GetValue("val3").Payload == -1);
            Assert.IsTrue(core.BuildStatus.WarningCount == 0);
        }
Ejemplo n.º 48
0
        public void EmbeddedTest002()
        {
            String code =
                @"
x;
[Associative]
{
	x = 
    { 
        0 => xfirst;
    }
    [Imperative]
    {
        x = x + 5;
    }
}
"                                                                                                                                ;

            ProtoScript.Runners.ProtoScriptRunner fsr = new ProtoScript.Runners.ProtoScriptRunner();
            runtimeCore = fsr.Execute(code, core); ExecutionMirror mirror = runtimeCore.Mirror;
            Obj o = mirror.GetValue("x");

            Assert.IsTrue((Int64)o.Payload == 5);
        }
Ejemplo n.º 49
0
        public void EmbeddedTest004()
        {
            // Tracked by http://adsk-oss.myjetbrains.com/youtrack/issue/MAGN-1580
            String code =
                @"x;
[Associative]
{
	x = {
        0 => x@first;
        +1 => x@second;
}
    [Imperative]
    {
        x@first = x + 5;
    }
}
"                                                                                                                                                    ;

            ProtoScript.Runners.ProtoScriptRunner fsr = new ProtoScript.Runners.ProtoScriptRunner();
            runtimeCore = fsr.Execute(code, core); ExecutionMirror mirror = runtimeCore.Mirror;
            Obj o = mirror.GetValue("x");

            Assert.IsTrue((Int64)o.Payload == 7); //0 => x@first, 1 x@second, 6 -> x@first 7 -> x@second
        }
Ejemplo n.º 50
0
        public void ModifierStackWithArrayAndFunction2()
        {
            ProtoScript.Runners.ProtoScriptRunner fsr = new ProtoScript.Runners.ProtoScriptRunner();
            ExecutionMirror mirror = fsr.Execute(
                @"b;a@init;a@first;
                         [Associative]
                         {
	                         def foo : int(x : int)
	                         {
		                        a = x+2;
		                        return = a;
	                         }
                             b = 
                                 {
                                     8 => a@init;
                                     foo(a@init) => a@first;
                                 }
                         }
                        ", core, out runtimeCore);

            Assert.IsTrue((Int64)mirror.GetValue("a@init", 0).Payload == 8);
            Assert.IsTrue((Int64)mirror.GetValue("a@first", 0).Payload == 10);
            Assert.IsTrue((Int64)mirror.GetValue("b", 0).Payload == 10);
        }
Ejemplo n.º 51
0
        public void Defect_TestArrayGetCommonSuperType()
        {
            String code =
                @"
class A{};
class B extends A{};
class C extends A{};
class D extends C{};
a =A.A();
b = B.B();
c = C.C();
d = D.D();
//ba:A = B.B();
//ca:A = C.C();
//dc:C = D.D();
tABC = [ a, b, c ];
tABD = [ a, b, d ];
tACD = [ a, c, d ];
tBCD = [ b, c, d ];
tAB = [ a, b ];
tAD = [ a, d ];
tBC = [ b, c ];
tBD = [ b, d ];
tCD = [ c, d ];
";

            ProtoScript.Runners.ProtoScriptRunner fsr = new ProtoScript.Runners.ProtoScriptRunner();
            ProtoCore.RuntimeCore runtimeCore         = null;
            runtimeCore = fsr.Execute(code, core); ExecutionMirror mirror = runtimeCore.Mirror;
            StackValue svABC = mirror.GetRawFirstValue("tABC");

            ClassNode superABC = ArrayUtils.GetGreatestCommonSubclassForArray(svABC, runtimeCore);

            Assert.IsTrue(superABC.Name == "A");
            StackValue svABD    = mirror.GetRawFirstValue("tABD");
            ClassNode  superABD = ArrayUtils.GetGreatestCommonSubclassForArray(svABD, runtimeCore);

            Assert.IsTrue(superABD.Name == "A");
            StackValue svACD    = mirror.GetRawFirstValue("tACD");
            ClassNode  superACD = ArrayUtils.GetGreatestCommonSubclassForArray(svACD, runtimeCore);

            Assert.IsTrue(superABD.Name == "A");
            StackValue svBCD    = mirror.GetRawFirstValue("tBCD");
            ClassNode  superBCD = ArrayUtils.GetGreatestCommonSubclassForArray(svBCD, runtimeCore);

            Assert.IsTrue(superBCD.Name == "A");
            StackValue svAB    = mirror.GetRawFirstValue("tAB");
            ClassNode  superAB = ArrayUtils.GetGreatestCommonSubclassForArray(svAB, runtimeCore);

            Assert.IsTrue(superAB.Name == "A");
            StackValue svAD    = mirror.GetRawFirstValue("tAD");
            ClassNode  superAD = ArrayUtils.GetGreatestCommonSubclassForArray(svAD, runtimeCore);

            Assert.IsTrue(superAD.Name == "A");
            StackValue svBC    = mirror.GetRawFirstValue("tBC");
            ClassNode  superBC = ArrayUtils.GetGreatestCommonSubclassForArray(svBC, runtimeCore);

            Assert.IsTrue(superBC.Name == "A");
            StackValue svBD    = mirror.GetRawFirstValue("tBD");
            ClassNode  superBD = ArrayUtils.GetGreatestCommonSubclassForArray(svBD, runtimeCore);

            Assert.IsTrue(superBD.Name == "A");
            StackValue svCD    = mirror.GetRawFirstValue("tCD");
            ClassNode  superCD = ArrayUtils.GetGreatestCommonSubclassForArray(svCD, runtimeCore);

            Assert.IsTrue(superCD.Name == "C");
        }
Ejemplo n.º 52
0
        public void TestArrayGetCommonSuperType()
        {
            String code =
                @"
class A {}
class B extends A {}
class C extends B {}
tAAA = [A.A(), A.A(), A.A()];
tAAB = [A.A(), A.A(), B.B()];
tAAC = [A.A(), A.A(), C.C()];
tABA = [A.A(), B.B(), A.A()];
tABB = [A.A(), B.B(), B.B()];
tABC = [A.A(), B.B(), C.C()];
tACA = [A.A(), C.C(), A.A()];
tACB = [A.A(), C.C(), B.B()];
tACC = [A.A(), C.C(), C.C()];
//---
tBAA = [B.B(), A.A(), A.A()];
tBAB = [B.B(), A.A(), B.B()];
tBAC = [B.B(), A.A(), C.C()];
tBBA = [B.B(), B.B(), A.A()];
tBBB = [B.B(), B.B(), B.B()];
tBBC = [B.B(), B.B(), C.C()];
tBCA = [B.B(), C.C(), A.A()];
tBCB = [B.B(), C.C(), B.B()];
tBCC = [B.B(), C.C(), C.C()];
//---
tCAA = [C.C(), A.A(), A.A()];
tCAB = [C.C(), A.A(), B.B()];
tCAC = [C.C(), A.A(), C.C()];
tCBA = [C.C(), B.B(), A.A()];
tCBB = [C.C(), B.B(), B.B()];
tCBC = [C.C(), B.B(), C.C()];
tCCA = [C.C(), C.C(), A.A()];
tCCB = [C.C(), C.C(), B.B()];
tCCC = [C.C(), C.C(), C.C()];
";

            ProtoScript.Runners.ProtoScriptRunner fsr = new ProtoScript.Runners.ProtoScriptRunner();
            ProtoCore.RuntimeCore runtimeCore         = null;
            runtimeCore = fsr.Execute(code, core); ExecutionMirror mirror = runtimeCore.Mirror;
            StackValue svAAA    = mirror.GetRawFirstValue("tAAA");
            ClassNode  superAAA = ArrayUtils.GetGreatestCommonSubclassForArray(svAAA, runtimeCore);

            Assert.IsTrue(superAAA.Name == "A");
            StackValue svAAB    = mirror.GetRawFirstValue("tAAB");
            ClassNode  superAAB = ArrayUtils.GetGreatestCommonSubclassForArray(svAAB, runtimeCore);

            Assert.IsTrue(superAAB.Name == "A");
            StackValue svAAC    = mirror.GetRawFirstValue("tAAC");
            ClassNode  superAAC = ArrayUtils.GetGreatestCommonSubclassForArray(svAAC, runtimeCore);

            Assert.IsTrue(superAAC.Name == "A");
            StackValue svABA    = mirror.GetRawFirstValue("tABA");
            ClassNode  superABA = ArrayUtils.GetGreatestCommonSubclassForArray(svABA, runtimeCore);

            Assert.IsTrue(superABA.Name == "A");
            StackValue svABB    = mirror.GetRawFirstValue("tABB");
            ClassNode  superABB = ArrayUtils.GetGreatestCommonSubclassForArray(svABB, runtimeCore);

            Assert.IsTrue(superABB.Name == "A");
            StackValue svABC    = mirror.GetRawFirstValue("tABC");
            ClassNode  superABC = ArrayUtils.GetGreatestCommonSubclassForArray(svABC, runtimeCore);

            Assert.IsTrue(superABC.Name == "A");
            StackValue svACA    = mirror.GetRawFirstValue("tACA");
            ClassNode  superACA = ArrayUtils.GetGreatestCommonSubclassForArray(svACA, runtimeCore);

            Assert.IsTrue(superACA.Name == "A");
            StackValue svACB    = mirror.GetRawFirstValue("tACB");
            ClassNode  superACB = ArrayUtils.GetGreatestCommonSubclassForArray(svACB, runtimeCore);

            Assert.IsTrue(superACB.Name == "A");
            StackValue svACC    = mirror.GetRawFirstValue("tACC");
            ClassNode  superACC = ArrayUtils.GetGreatestCommonSubclassForArray(svACC, runtimeCore);

            Assert.IsTrue(superACC.Name == "A");
            //----
            StackValue svBAA    = mirror.GetRawFirstValue("tBAA");
            ClassNode  superBAA = ArrayUtils.GetGreatestCommonSubclassForArray(svBAA, runtimeCore);

            Assert.IsTrue(superBAA.Name == "A");
            StackValue svBAB    = mirror.GetRawFirstValue("tBAB");
            ClassNode  superBAB = ArrayUtils.GetGreatestCommonSubclassForArray(svBAB, runtimeCore);

            Assert.IsTrue(superBAB.Name == "A");
            StackValue svBAC    = mirror.GetRawFirstValue("tBAC");
            ClassNode  superBAC = ArrayUtils.GetGreatestCommonSubclassForArray(svBAC, runtimeCore);

            Assert.IsTrue(superBAC.Name == "A");
            StackValue svBBA    = mirror.GetRawFirstValue("tBBA");
            ClassNode  superBBA = ArrayUtils.GetGreatestCommonSubclassForArray(svBBA, runtimeCore);

            Assert.IsTrue(superBBA.Name == "A");
            StackValue svBBB    = mirror.GetRawFirstValue("tBBB");
            ClassNode  superBBB = ArrayUtils.GetGreatestCommonSubclassForArray(svBBB, runtimeCore);

            Assert.IsTrue(superBBB.Name == "B");
            StackValue svBBC    = mirror.GetRawFirstValue("tBBC");
            ClassNode  superBBC = ArrayUtils.GetGreatestCommonSubclassForArray(svBBC, runtimeCore);

            Assert.IsTrue(superBBC.Name == "B");
            StackValue svBCA    = mirror.GetRawFirstValue("tBCA");
            ClassNode  superBCA = ArrayUtils.GetGreatestCommonSubclassForArray(svBCA, runtimeCore);

            Assert.IsTrue(superBCA.Name == "A");
            StackValue svBCB    = mirror.GetRawFirstValue("tBCB");
            ClassNode  superBCB = ArrayUtils.GetGreatestCommonSubclassForArray(svBCB, runtimeCore);

            Assert.IsTrue(superBCB.Name == "B");
            StackValue svBCC    = mirror.GetRawFirstValue("tBCC");
            ClassNode  superBCC = ArrayUtils.GetGreatestCommonSubclassForArray(svBCC, runtimeCore);

            Assert.IsTrue(superBCC.Name == "B");
            //----
            StackValue svCAA    = mirror.GetRawFirstValue("tCAA");
            ClassNode  superCAA = ArrayUtils.GetGreatestCommonSubclassForArray(svCAA, runtimeCore);

            Assert.IsTrue(superCAA.Name == "A");
            StackValue svCAB    = mirror.GetRawFirstValue("tCAB");
            ClassNode  superCAB = ArrayUtils.GetGreatestCommonSubclassForArray(svCAB, runtimeCore);

            Assert.IsTrue(superCAB.Name == "A");
            StackValue svCAC    = mirror.GetRawFirstValue("tCAC");
            ClassNode  superCAC = ArrayUtils.GetGreatestCommonSubclassForArray(svCAC, runtimeCore);

            Assert.IsTrue(superCAC.Name == "A");
            StackValue svCBA    = mirror.GetRawFirstValue("tCBA");
            ClassNode  superCBA = ArrayUtils.GetGreatestCommonSubclassForArray(svCBA, runtimeCore);

            Assert.IsTrue(superCBA.Name == "A");
            StackValue svCBB    = mirror.GetRawFirstValue("tCBB");
            ClassNode  superCBB = ArrayUtils.GetGreatestCommonSubclassForArray(svCBB, runtimeCore);

            Assert.IsTrue(superCBB.Name == "B");
            StackValue svCBC    = mirror.GetRawFirstValue("tCBC");
            ClassNode  superCBC = ArrayUtils.GetGreatestCommonSubclassForArray(svCBC, runtimeCore);

            Assert.IsTrue(superCBC.Name == "B");
            StackValue svCCA    = mirror.GetRawFirstValue("tCCA");
            ClassNode  superCCA = ArrayUtils.GetGreatestCommonSubclassForArray(svCCA, runtimeCore);

            Assert.IsTrue(superCCA.Name == "A");
            StackValue svCCB    = mirror.GetRawFirstValue("tCCB");
            ClassNode  superCCB = ArrayUtils.GetGreatestCommonSubclassForArray(svCCB, runtimeCore);

            Assert.IsTrue(superCCB.Name == "B");
            StackValue svCCC    = mirror.GetRawFirstValue("tCCC");
            ClassNode  superCCC = ArrayUtils.GetGreatestCommonSubclassForArray(svCCC, runtimeCore);

            Assert.IsTrue(superCCC.Name == "C");
        }
Ejemplo n.º 53
0
        public bool RunScript(string dsPath)
        {
            if (string.IsNullOrEmpty(GeometryFactoryName))
            {
                throw new Exception("GeometryFactory not set!");
            }

            if (string.IsNullOrEmpty(PersistenceManagerName))
            {
                throw new Exception("PersistenceManager not set!");
            }

            if (!File.Exists(dsPath))
            {
                throw new FileNotFoundException(dsPath + " Does not exist");
            }

            bool success = false;

            System.IO.StringWriter stringStream = new StringWriter();
            executionLog = new StringBuilder();
            ProtoCore.Core        core        = null;
            ProtoCore.RuntimeCore runtimeCore = null;
            try
            {
                var    options          = new ProtoCore.Options();
                string assemblyLocation = System.Reflection.Assembly.GetExecutingAssembly().Location;
                string incDir           = Path.GetDirectoryName(assemblyLocation);
                options.IncludeDirectories.Add(incDir);

                core = new ProtoCore.Core(options);
                core.BuildStatus.SetStream(stringStream);
                core.Options.RootModulePathName = ProtoCore.Utils.FileUtils.GetFullPathName(dsPath);
                core.Compilers.Add(ProtoCore.Language.kAssociative, new ProtoAssociative.Compiler(core));
                core.Compilers.Add(ProtoCore.Language.kImperative, new ProtoImperative.Compiler(core));

                core.Configurations.Add(Autodesk.DesignScript.Interfaces.ConfigurationKeys.GeometryFactory, GeometryFactoryName);
                core.Configurations.Add(Autodesk.DesignScript.Interfaces.ConfigurationKeys.PersistentManager, PersistenceManagerName);
                ProtoScript.Runners.ProtoScriptRunner fsr = new ProtoScript.Runners.ProtoScriptRunner();

                ExecutionMirror mirror = fsr.LoadAndExecute(dsPath, core, out runtimeCore);
                executionLog.AppendLine("Script executed successfully.");

                executionLog.AppendLine();
                executionLog.AppendLine("=================================CoreDump=================================");
                string coreDump = null;
                try
                {
                    coreDump = mirror.GetCoreDump();
                    executionLog.AppendLine();
                    executionLog.AppendLine(coreDump);
                    success = true;
                }
                catch (System.Exception ex)
                {
                    executionLog.AppendLine(ex.Message);
                    executionLog.AppendLine(ex.StackTrace);

                    success = false;
                }
                finally
                {
                    executionLog.AppendLine("=================================CoreDump=================================");
                }
            }
            catch (System.Exception ex)
            {
                success = false;
                executionLog.AppendLine("Fail to execute script.");
                executionLog.AppendLine("Exceptions:");
                executionLog.AppendLine(ex.Message);
                executionLog.AppendLine("StackTrace:");
                executionLog.AppendLine(ex.StackTrace);
            }
            finally
            {
                if (core != null)
                {
                    core.BuildStatus.SetStream(null);
                    runtimeCore.Cleanup();
                }
            }

            return(success);
        }