Exemple #1
0
        public void T01_TestAllPassCondition()
        {
            ExecutionMirror mirror = thisTest.RunScript(@"..\\..\\..\\Scripts\\TD\\Imperative\\IfStatement\\T01_TestAllPassCondition.ds");

            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);
        }
Exemple #2
0
        public void ArrayRetrival2DJagged()
        {
            String code =
                @"
foo;
[Associative]
{
	foo = {{5}, 6};
}
";

            ProtoScript.Runners.ProtoScriptTestRunner fsr = new ProtoScript.Runners.ProtoScriptTestRunner();
            ExecutionMirror mirror = fsr.Execute(code, core);

            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);
        }
Exemple #3
0
        public void ArrayRetrival1DEmpty()
        {
            String code =
                @"
foo;
[Associative]
{
	foo = {};
}
";

            ProtoScript.Runners.ProtoScriptRunner fsr = new ProtoScript.Runners.ProtoScriptRunner();
            runtimeCore = fsr.Execute(code, core); ExecutionMirror mirror = runtimeCore.Mirror;
            ProtoCore.Lang.Obj o = mirror.GetValue("foo");
            ProtoCore.DSASM.Mirror.DsasmArray a = (ProtoCore.DSASM.Mirror.DsasmArray)o.Payload;
            Assert.IsTrue(a.members.Length == 0);
        }
Exemple #4
0
        public void ArrayRetrival1D()
        {
            String code =
                @"
foo;
[Associative]
{
	foo = {5};
}
"                                                      ;

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

            ProtoCore.DSASM.Mirror.DsasmArray a = (ProtoCore.DSASM.Mirror.DsasmArray)o.Payload;
            Assert.IsTrue(a.members.Length == 1);
            Assert.IsTrue((Int64)a.members[0].Payload == 5);
        }
        public void TestDynamicArray001()
        {
            String code =
                @"
local;
[Imperative]
{
    range = 1..10;
    local = {};
    c = 0;
    for(i in range)
    {
        local[c] = i + 1;
        c = c + 1;
    }
}
";
            ExecutionMirror mirror = thisTest.RunScriptSource(code);

            ProtoCore.Lang.Obj o = mirror.GetFirstValue("local");
            ProtoCore.DSASM.Mirror.DsasmArray arr = (ProtoCore.DSASM.Mirror.DsasmArray)o.Payload;
            Assert.IsTrue((Int64)arr.members[0].Payload == 2);
        }
Exemple #6
0
        // Verify for single object
        private static void VerifyInternal(object expectedObject, Obj dsObject, string dsVariable, List <int> indices)
        {
            if (expectedObject == null)
            {
                if (!dsObject.DsasmValue.IsNull)
                {
                    Assert.Fail(String.Format("\t{0}{1} is expected to be null, but it isn't.\n{2}", dsVariable,
                                              TestFrameWork.BuildIndicesString(indices), TestFrameWork.mErrorMessage));
                }
                return;
            }

            Type expectedType = expectedObject.GetType();

            if (dsObject.DsasmValue.IsNull && expectedObject != null)
            {
                Assert.Fail(String.Format("\tThe value of {0} was null, but wasn't expected to be.\n{1}", dsVariable, mErrorMessage));
            }
            else if (expectedObject is Int32 || expectedObject is Int64)
            {
                Int64 expectedValue = Convert.ToInt64(expectedObject);
                if (!(dsObject.Payload is long))
                {
                    Assert.Fail(String.Format("\t{0}{1} is expected to be {2}, but its actual value is not an integer. \n{2}", dsVariable,
                                              BuildIndicesString(indices), expectedValue, mErrorMessage));
                }
                else
                {
                    TestFrameWork.VerifyPodType(expectedValue, dsObject, dsVariable, indices);
                }
            }
            else if (expectedObject is Double)
            {
                Double expectedValue = Convert.ToDouble(expectedObject);
                if (!(dsObject.Payload is Double))
                {
                    Assert.Fail(String.Format("\t{0}{1} is expected to be {2}, but its actual value is not a double. \n{3}", dsVariable,
                                              BuildIndicesString(indices), expectedValue, mErrorMessage));
                }
                else
                {
                    try
                    {
                        Double dsValue = Convert.ToDouble(dsObject.Payload);

                        if (!MathUtils.Equals(expectedValue, dsValue))
                        {
                            Assert.Fail(String.Format("\t{0}{1} is expected to be {2}, but its actual value is {3}. \n{4}", dsVariable,
                                                      BuildIndicesString(indices), expectedValue, dsValue, mErrorMessage));
                        }
                    }
                    catch (System.InvalidCastException)
                    {
                        Assert.Fail(String.Format("\t{0}{1} is expected to be {2}, but its actual value can't be converted to Double. \n{3}", dsVariable,
                                                  BuildIndicesString(indices), expectedValue, mErrorMessage));
                    }
                }
            }
            else if (expectedObject is Boolean)
            {
                Boolean expectedValue = Convert.ToBoolean(expectedObject);
                if (!(dsObject.Payload is Boolean))
                {
                    Assert.Fail(String.Format("\t{0}{1} is expected to be {2}, but its actual type is not bool. \n{3}", dsVariable,
                                              BuildIndicesString(indices), expectedValue, mErrorMessage));
                }
                else
                {
                    TestFrameWork.VerifyPodType(expectedValue, dsObject, dsVariable, indices);
                }
            }
            else if (expectedObject is Char)
            {
                Char expectedValue = Convert.ToChar(expectedObject);

                if (!(dsObject.Payload is long))
                {
                    Assert.Fail(String.Format("\t{0}{1} is expected to be {2}, but its actual type is not char. \n{3}", dsVariable, BuildIndicesString(indices), expectedValue, mErrorMessage));
                }
                else
                {
                    try
                    {
                        Int64 utf8Encoding = Convert.ToInt64(dsObject.Payload);
                        Char  dsValue      = Convert.ToChar(utf8Encoding);

                        if (!expectedObject.Equals(dsValue))
                        {
                            Assert.Fail(String.Format("\t{0}{1} is expected to be {2}, but its actual value is {3}. \n{4}", dsVariable,
                                                      BuildIndicesString(indices), expectedValue, dsValue, mErrorMessage));
                        }
                    }
                    catch (System.InvalidCastException)
                    {
                        Assert.Fail(String.Format("\t{0}{1} is expected to be {2}, but its actual value can't be converted to Char. \n{3}", dsVariable,
                                                  BuildIndicesString(indices), expectedValue, mErrorMessage));
                    }
                }
            }
            else if (expectedObject is String)
            {
                string stringValue = dsObject.Payload as string;
                if (stringValue == null)
                {
                    Assert.Fail(String.Format("\t{0}{1} is expected to be a string, but its actual value is not a string\n{2}", dsVariable,
                                              BuildIndicesString(indices), mErrorMessage));
                }
                else if (!expectedObject.Equals(stringValue))
                {
                    Assert.Fail(String.Format("\t{0}{1} is expected to be a string \"{2}\", but its actual value is \"{3}\".\n{4}", dsVariable,
                                              BuildIndicesString(indices), expectedObject, stringValue, mErrorMessage));
                }
            }
            else if (typeof(IEnumerable).IsAssignableFrom(expectedType))
            {
                IEnumerable collection = expectedObject as IEnumerable;
                int         index      = 0;
                ProtoCore.DSASM.Mirror.DsasmArray dsArray = dsObject.Payload as ProtoCore.DSASM.Mirror.DsasmArray;
                if (dsArray == null)
                {
                    Assert.Fail(String.Format("{0}{1} is expected to be an array, but its actual value isn't an array.\n{2}", dsVariable,
                                              BuildIndicesString(indices), mErrorMessage));
                }
                foreach (var item in collection)
                {
                    indices.Add(index);
                    VerifyInternal(item, dsArray.members[index], dsVariable, indices);
                    indices.RemoveAt(indices.Count - 1);
                    ++index;
                }
            }
            else
            {
                Assert.Fail(string.Format("\tUnexpected object type.\n{0}", mErrorMessage));
            }
        }
        public bool CompareArrays(DsasmArray dsArray, List<Object> expected, System.Type type)
        {
            if (dsArray.members.Length != expected.Count)
                return false;

            for (int i = 0; i < dsArray.members.Length; ++i)
            {
                List<Object> subExpected = expected[i] as List<Object>;
                DsasmArray subArray = dsArray.members[i].Payload as DsasmArray;

                if ((subExpected != null) && (subArray != null)) {

                    if (!CompareArrays(subArray, subExpected, type))
                        return false;
                }
                else if ((subExpected == null) && (subArray == null))
                {
                    if (type == typeof(Int64))
                    {
                        if (Convert.ToInt64(dsArray.members[i].Payload) != Convert.ToInt64(expected[i]))
                            return false;
                    }
                    else if (type == typeof(Double))
                    {
                        // can't use Double.Episilion, according to msdn, it is smaller than most
                        // errors.
                        if (Math.Abs(Convert.ToDouble(dsArray.members[i].Payload) - Convert.ToDouble(expected[i])) > 0.000001)
                            return false;
                    }
                    else if (type == typeof(Boolean))
                    {
                        if (Convert.ToBoolean(dsArray.members[i].Payload) != Convert.ToBoolean(expected[i]))
                            return false;
                    }
                    else if (type == typeof(Char))
                    {
                        object payload = dsArray.members[i].Payload;
                        return ProtoCore.Utils.EncodingUtils.ConvertInt64ToCharacter(Convert.ToInt64(payload)) == Convert.ToChar(expected[i]);
                    }
                    else
                    {
                        throw new NotImplementedException("Test comparison not implemented: {EBAFAE6C-BCBF-42B8-B99C-49CFF989F0F0}");
                    }
                }
                else
                {
                    return false;
                }
            }
            return true;
        }
        public static Obj Unpack(StackValue val, Core core)
        {
            switch (val.optype)
            {
                case AddressType.ArrayPointer:
                    {
                        //It was a pointer that we pulled, so the value lives on the heap
                        Int64 ptr = val.opdata;

                        DsasmArray ret = new DsasmArray();
                        HeapElement hs = core.Heap.Heaplist[(int)ptr];

                        StackValue[] nodes = hs.Stack;
                        ret.members = new Obj[nodes.Length];

                        for (int i = 0; i < ret.members.Length; i++)
                        {
                            ret.members[i] = Unpack(nodes[i], core);
                        }

                        Obj retO = new Obj(val) { Payload = ret, Type = core.TypeSystem.BuildTypeObject((ret.members.Length > 0) ? core.TypeSystem.GetType(ret.members[0].Type.Name) : (int)ProtoCore.PrimitiveType.kTypeVar, true) };

                        return retO;
                    }
                case AddressType.Int:
                    {
                        Int64 data = val.opdata;
                        Obj o = new Obj(val) { Payload = data, Type = core.TypeSystem.BuildTypeObject(PrimitiveType.kTypeInt, false) };
                        return o;
                    }
                case AddressType.Boolean:
                    {
                        Obj o = new Obj(val) { Payload = val.opdata == 0 ? false : true, Type = core.TypeSystem.BuildTypeObject(PrimitiveType.kTypeBool, false) };
                        return o;
                    }
                case AddressType.Null:
                    {
                        Obj o = new Obj(val) { Payload = null, Type = core.TypeSystem.BuildTypeObject(PrimitiveType.kTypeNull, false) };
                        return o;
                    }
                case AddressType.Double:
                    {
                        double data = val.opdata_d;
                        Obj o = new Obj(val) { Payload = data, Type = core.TypeSystem.BuildTypeObject(PrimitiveType.kTypeDouble, false) };
                        return o;
                    }
                case AddressType.Char:
                    {
                        Int64 data = val.opdata;
                        Obj o = new Obj(val) { Payload = data, Type = core.TypeSystem.BuildTypeObject(PrimitiveType.kTypeChar, false) };
                        return o;
                    }
                case AddressType.Pointer:
                    {
                        Int64 data = val.opdata;
                        Obj o = new Obj(val) { Payload = data, Type = core.TypeSystem.BuildTypeObject((int)val.metaData.type, false) };
                        return o;
                    }
                case AddressType.DefaultArg:
                    {
                        Int64 data = val.opdata;
                        Obj o = new Obj(val) { Payload = data, Type = core.TypeSystem.BuildTypeObject(PrimitiveType.kTypeVar, false) };
                        return o;
                    }
                case AddressType.FunctionPointer:
                    {
                        Int64 data = val.opdata;
                        Obj o = new Obj(val) { Payload = data, Type = core.TypeSystem.BuildTypeObject(PrimitiveType.kTypeFunctionPointer, false) };
                        return o;
                    }
                default:
                    {
                        throw new NotImplementedException(string.Format("unknown datatype {0}", val.optype.ToString()));
                    }
            }
        }
        //@TODO(Luke): Add in the methods here that correspond to each of the internal datastructures in use by the executive
        //@TODO(Jun): if this method stays static, then the Heap needs to be referenced from a parameter
        /// <summary>
        /// Do the recursive unpacking of the data structure into mirror objects
        /// </summary>
        /// <param name="val"></param>
        /// <returns></returns>
        public static Obj Unpack(StackValue val, Heap heap, Core core, int type = (int)PrimitiveType.kTypePointer)
        {
            switch (val.optype)
            {
                case AddressType.ArrayPointer:
                case AddressType.String:
                    {
                        //It was a pointer that we pulled, so the value lives on the heap
                        Int64 ptr = val.opdata;

                        DsasmArray ret = new DsasmArray();

                        //Pull the item out of the heap

                        HeapElement hs = heap.Heaplist[(int)ptr];

                        StackValue[] nodes = hs.Stack;
                        ret.members = new Obj[hs.VisibleSize];

                        for (int i = 0; i < ret.members.Length; i++)
                        {
                            ret.members[i] = Unpack(nodes[i], heap, core, type);
                        }

                        // TODO Jun: ret.members[0] is hardcoded  and means we are assuming a homogenous collection
                        // How to handle mixed-type arrays?
                        Obj retO = new Obj(val) { Payload = ret, Type = core.TypeSystem.BuildTypeObject((ret.members.Length > 0) ? core.TypeSystem.GetType(ret.members[0].Type.Name) : (int)ProtoCore.PrimitiveType.kTypeVoid, true) };

                        return retO;
                    }
                case AddressType.Int:
                    {
                        Int64 data = val.opdata;
                        Obj o = new Obj(val) { Payload = data, Type = core.TypeSystem.BuildTypeObject(PrimitiveType.kTypeInt, false) };
                        return o;
                    }
                case AddressType.Boolean:
                    {
                        Int64 data = val.opdata;
                        Obj o = new Obj(val) { Payload = (data != 0), Type = core.TypeSystem.BuildTypeObject(PrimitiveType.kTypeBool, false) };
                        return o;
                    }

                case AddressType.Null:
                    {
                        Int64 data = val.opdata;
                        Obj o = new Obj(val) { Payload = null, Type = core.TypeSystem.BuildTypeObject(PrimitiveType.kTypeNull, false) };
                        return o;
                    }
                case AddressType.Char:
                    {
                        Int64 data = val.opdata;
                        Obj o = new Obj(val) { Payload = data, Type = core.TypeSystem.BuildTypeObject(PrimitiveType.kTypeChar, false) };
                        return o;
                    }
                case AddressType.Double:
                    {
                        double data = val.opdata_d;
                        Obj o = new Obj(val) { Payload = data, Type = core.TypeSystem.BuildTypeObject(PrimitiveType.kTypeDouble, false) };
                        return o;
                    }
                case AddressType.Pointer:
                    {
                        Int64 data = val.opdata;
                        Obj o = new Obj(val) { Payload = data, Type = core.TypeSystem.BuildTypeObject(type, false) };
                        return o;
                    }
                case AddressType.FunctionPointer:
                    {
                        Int64 data = val.opdata;
                        Obj o = new Obj(val) { Payload = data, Type = core.TypeSystem.BuildTypeObject(PrimitiveType.kTypeFunctionPointer, false) };
                        return o;
                    }
                case AddressType.Invalid:
                    {
                        return new Obj(val) {Payload = null};
                    }
                default:
                    {
                        throw new NotImplementedException(string.Format("unknown datatype {0}", val.optype.ToString()));
                    }
            }
        }
Exemple #10
0
        //@TODO(Luke): Add in the methods here that correspond to each of the internal datastructures in use by the executive
        //@TODO(Jun): if this method stays static, then the Heap needs to be referenced from a parameter
        /// <summary>
        /// Do the recursive unpacking of the data structure into mirror objects
        /// </summary>
        /// <param name="val"></param>
        /// <returns></returns>
        public static Obj Unpack(StackValue val, Heap heap, RuntimeCore runtimeCore, int type = (int)PrimitiveType.Pointer)
        {
            Executable exe = runtimeCore.DSExecutable;

            switch (val.optype)
            {
            case AddressType.ArrayPointer:
            {
                DsasmArray ret = new DsasmArray();

                //Pull the item out of the heap


                var array = heap.ToHeapObject <DSArray>(val);

                StackValue[] nodes = array.Values.ToArray();
                ret.members = new Obj[array.Count];
                for (int i = 0; i < ret.members.Length; i++)
                {
                    ret.members[i] = Unpack(nodes[i], heap, runtimeCore, type);
                }

                // TODO Jun: ret.members[0] is hardcoded  and means we are assuming a homogenous collection
                // How to handle mixed-type arrays?
                Obj retO = new Obj(val)
                {
                    Payload = ret,
                };

                return(retO);
            }

            case AddressType.String:
            {
                string str = heap.ToHeapObject <DSString>(val).Value;
                Obj    o   = new Obj(val)
                {
                    Payload = str,
                };
                return(o);
            }

            case AddressType.Int:
            {
                Obj o = new Obj(val)
                {
                    Payload = val.IntegerValue,
                };
                return(o);
            }

            case AddressType.Boolean:
            {
                Obj o = new Obj(val)
                {
                    Payload = val.BooleanValue,
                };
                return(o);
            }

            case AddressType.Null:
            {
                Obj o = new Obj(val)
                {
                    Payload = null,
                };
                return(o);
            }

            case AddressType.Char:
            {
                Obj o = new Obj(val)
                {
                    Payload = val.CharValue,
                };
                return(o);
            }

            case AddressType.Double:
            {
                Obj o = new Obj(val)
                {
                    Payload = val.DoubleValue,
                };
                return(o);
            }

            case AddressType.Pointer:
            {
                Obj o = new Obj(val)
                {
                    Payload = val.Pointer,
                };
                return(o);
            }

            case AddressType.FunctionPointer:
            {
                Obj o = new Obj(val)
                {
                    Payload = val.FunctionPointer,
                };
                return(o);
            }

            case AddressType.Invalid:
            {
                return(new Obj(val)
                    {
                        Payload = null
                    });
            }

            default:
            {
                throw new NotImplementedException(string.Format("unknown datatype {0}", val.optype.ToString()));
            }
            }
        }
Exemple #11
0
        //@TODO(Luke): Add in the methods here that correspond to each of the internal datastructures in use by the executive
        //@TODO(Jun): if this method stays static, then the Heap needs to be referenced from a parameter
        /// <summary>
        /// Do the recursive unpacking of the data structure into mirror objects
        /// </summary>
        /// <param name="val"></param>
        /// <returns></returns>
        public static Obj Unpack(StackValue val, Heap heap, RuntimeCore runtimeCore, int type = (int)PrimitiveType.Pointer) 
        {
            Executable exe = runtimeCore.DSExecutable;
            switch (val.optype)
            {
                case AddressType.ArrayPointer:
                    {
                        DsasmArray ret = new DsasmArray();

                        //Pull the item out of the heap


                        var array = heap.ToHeapObject<DSArray>(val);

                        StackValue[] nodes = array.Values.ToArray();
                        ret.members = new Obj[array.Count];
                        for (int i = 0; i < ret.members.Length; i++)
                        {
                            ret.members[i] = Unpack(nodes[i], heap, runtimeCore, type);
                        }

                        // TODO Jun: ret.members[0] is hardcoded  and means we are assuming a homogenous collection
                        // How to handle mixed-type arrays?
                        Obj retO = new Obj(val) 
                        { 
                            Payload = ret, 
                        };

                        return retO;
                    }
                case AddressType.String:
                    {
                        string str = heap.ToHeapObject<DSString>(val).Value;
                        Obj o = new Obj(val)
                        {
                            Payload = str,
                        };
                        return o;
                    }
                case AddressType.Int:
                    {
                        Obj o = new Obj(val) 
                        { 
                            Payload = val.IntegerValue, 
                        };
                        return o;
                    }
                case AddressType.Boolean:
                    {
                        Obj o = new Obj(val)
                        {
                            Payload = val.BooleanValue,
                        };
                        return o;
                    }

                case AddressType.Null:
                    {
                        Obj o = new Obj(val) 
                        { 
                            Payload = null, 
                        };
                        return o;
                    }
                case AddressType.Char:
                    {
                        Obj o = new Obj(val) 
                        {
                            Payload = val.CharValue, 
                        };
                        return o;
                    }
                case AddressType.Double:
                    {
                        Obj o = new Obj(val) 
                        { 
                            Payload = val.DoubleValue,
                        };
                        return o;
                    }
                case AddressType.Pointer:
                    {
                        Obj o = new Obj(val) 
                        { 
                            Payload = val.Pointer,
                        };
                        return o;
                    }
                case AddressType.FunctionPointer:
                    {
                        Obj o = new Obj(val) 
                        { 
                            Payload = val.FunctionPointer, 
                        };
                        return o;
                    }
                case AddressType.Invalid:
                    {
                        return new Obj(val) {Payload = null};
                    }
                default:
                    {
                        throw new NotImplementedException(string.Format("unknown datatype {0}", val.optype.ToString()));
                    }
            }

        }
Exemple #12
0
        public static Obj Unpack(StackValue val, RuntimeCore runtimeCore)
        {
            RuntimeMemory rmem = runtimeCore.RuntimeMemory;
            Executable exe = runtimeCore.DSExecutable;
            switch (val.optype)
            {
                case AddressType.ArrayPointer:
                    {
                        //It was a pointer that we pulled, so the value lives on the heap
                        DsasmArray ret = new DsasmArray();
                        var array = rmem.Heap.ToHeapObject<DSArray>(val);

                        StackValue[] nodes = array.VisibleItems.ToArray();
                        ret.members = new Obj[nodes.Length];

                        for (int i = 0; i < ret.members.Length; i++)
                        {
                            ret.members[i] = Unpack(nodes[i], runtimeCore);
                        }

                        Obj retO = new Obj(val) 
                        { 
                            Payload = ret,
                            Type = exe.TypeSystem.BuildTypeObject((ret.members.Length > 0) ? exe.TypeSystem.GetType(ret.members[0].Type.Name) : (int)ProtoCore.PrimitiveType.kTypeVar, Constants.kArbitraryRank)
                        };

                        return retO;
                    }
                case AddressType.Int:
                    {
                        Int64 data = val.opdata;
                        Obj o = new Obj(val) 
                        { 
                            Payload = data, 
                            Type = TypeSystem.BuildPrimitiveTypeObject(PrimitiveType.kTypeInt, 0) 
                        };
                        return o;
                    }
                case AddressType.Boolean:
                    {
                        Obj o = new Obj(val) 
                        { 
                            Payload = val.opdata == 0 ? false : true, 
                            Type = TypeSystem.BuildPrimitiveTypeObject(PrimitiveType.kTypeBool, 0) 
                        };
                        return o;
                    }
                case AddressType.Null:
                    {
                        Obj o = new Obj(val) 
                        { 
                            Payload = null, 
                            Type = TypeSystem.BuildPrimitiveTypeObject(PrimitiveType.kTypeNull, 0) 
                        };
                        return o;
                    }
                case AddressType.Double:
                    {
                        double data = val.RawDoubleValue;
                        Obj o = new Obj(val) 
                        { 
                            Payload = data, 
                            Type = TypeSystem.BuildPrimitiveTypeObject(PrimitiveType.kTypeDouble, 0) 
                        };
                        return o;
                    }
                case AddressType.Char:
                    {
                        Int64 data = val.opdata;
                        Obj o = new Obj(val) 
                        { 
                            Payload = data, 
                            Type = TypeSystem.BuildPrimitiveTypeObject(PrimitiveType.kTypeChar, 0) 
                        };
                        return o;
                    }
                case AddressType.Pointer:
                    {
                        Int64 data = val.opdata;
                        Obj o = new Obj(val) 
                        { 
                            Payload = data,
                            Type = exe.TypeSystem.BuildTypeObject(val.metaData.type, 0) 
                        };
                        return o;
                    }
                case AddressType.DefaultArg:
                    {
                        Int64 data = val.opdata;
                        Obj o = new Obj(val) 
                        { 
                            Payload = data, 
                            Type = TypeSystem.BuildPrimitiveTypeObject(PrimitiveType.kTypeVar, 0) 
                        };
                        return o;
                    }
                case AddressType.FunctionPointer:
                    {
                        Int64 data = val.opdata;
                        Obj o = new Obj(val) 
                        { 
                            Payload = data, 
                            Type = TypeSystem.BuildPrimitiveTypeObject(PrimitiveType.kTypeFunctionPointer, 0) 
                        };
                        return o;
                    }
                default:
                    {
                        throw new NotImplementedException(string.Format("unknown datatype {0}", val.optype.ToString()));
                    }
            }

        }
Exemple #13
0
        //@TODO(Luke): Add in the methods here that correspond to each of the internal datastructures in use by the executive
        //@TODO(Jun): if this method stays static, then the Heap needs to be referenced from a parameter
        /// <summary>
        /// Do the recursive unpacking of the data structure into mirror objects
        /// </summary>
        /// <param name="val"></param>
        /// <returns></returns>
        public static Obj Unpack(StackValue val, Heap heap, RuntimeCore runtimeCore, int type = (int)PrimitiveType.kTypePointer) 
        {
            Executable exe = runtimeCore.DSExecutable;
            switch (val.optype)
            {
                case AddressType.ArrayPointer:
                    {
                        DsasmArray ret = new DsasmArray();

                        //Pull the item out of the heap


                        var array = heap.ToHeapObject<DSArray>(val);

                        StackValue[] nodes = array.VisibleItems.ToArray();
                        ret.members = new Obj[array.VisibleSize];
                        for (int i = 0; i < ret.members.Length; i++)
                        {
                            ret.members[i] = Unpack(nodes[i], heap, runtimeCore, type);
                        }

                        // TODO Jun: ret.members[0] is hardcoded  and means we are assuming a homogenous collection
                        // How to handle mixed-type arrays?
                        Obj retO = new Obj(val) 
                        { 
                            Payload = ret, 
                            Type = exe.TypeSystem.BuildTypeObject(
                                        (ret.members.Length > 0)
                                        ? exe.TypeSystem.GetType(ret.members[0].Type.Name) 
                                        : (int)ProtoCore.PrimitiveType.kTypeVoid, Constants.kArbitraryRank) 
                        };

                        return retO;
                    }
                case AddressType.String:
                    {
                        string str = heap.ToHeapObject<DSString>(val).Value;
                        Obj o = new Obj(val)
                        {
                            Payload = str,
                            Type = TypeSystem.BuildPrimitiveTypeObject(PrimitiveType.kTypeString, 0)
                        };
                        return o;
                    }
                case AddressType.Int:
                    {
                        Int64 data = val.opdata;
                        Obj o = new Obj(val) 
                        { 
                            Payload = data, 
                            Type = TypeSystem.BuildPrimitiveTypeObject(PrimitiveType.kTypeInt, 0) 
                        };
                        return o;
                    }
                case AddressType.Boolean:
                    {
                        Int64 data = val.opdata;
                        Obj o = new Obj(val) 
                        { 
                            Payload = (data != 0), 
                            Type = TypeSystem.BuildPrimitiveTypeObject(PrimitiveType.kTypeBool, 0) 
                        };
                        return o;
                    }

                case AddressType.Null:
                    {
                        Obj o = new Obj(val) 
                        { 
                            Payload = null, 
                            Type = TypeSystem.BuildPrimitiveTypeObject(PrimitiveType.kTypeNull, 0) 
                        };
                        return o;
                    }
                case AddressType.Char:
                    {
                        Int64 data = val.opdata;
                        Obj o = new Obj(val) 
                        {
                            Payload = data, 
                            Type = TypeSystem.BuildPrimitiveTypeObject(PrimitiveType.kTypeChar, 0) 
                        };
                        return o;
                    }
                case AddressType.Double:
                    {
                        double data = val.RawDoubleValue;
                        Obj o = new Obj(val) 
                        { 
                            Payload = data, Type =
                            TypeSystem.BuildPrimitiveTypeObject(PrimitiveType.kTypeDouble, 0) 
                        };
                        return o;
                    }
                case AddressType.Pointer:
                    {
                        Int64 data = val.opdata;
                        Obj o = new Obj(val) 
                        { 
                            Payload = data,
                            Type = exe.TypeSystem.BuildTypeObject(type, 0) 
                        };
                        return o;
                    }
                case AddressType.FunctionPointer:
                    {
                        Int64 data = val.opdata;
                        Obj o = new Obj(val) 
                        { 
                            Payload = data, 
                            Type = TypeSystem.BuildPrimitiveTypeObject(PrimitiveType.kTypeFunctionPointer, 0) 
                        };
                        return o;
                    }
                case AddressType.Invalid:
                    {
                        return new Obj(val) {Payload = null};
                    }
                default:
                    {
                        throw new NotImplementedException(string.Format("unknown datatype {0}", val.optype.ToString()));
                    }
            }

        }
Exemple #14
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);
        }
        // Verify for single object
        private static void VerifyInternal(object expectedObject, Obj dsObject, string dsVariable, List <int> indices)
        {
            if (expectedObject == null)
            {
                if (dsObject.DsasmValue.optype != ProtoCore.DSASM.AddressType.Null)
                {
                    Assert.Fail(String.Format("\t{0}{1} is expected to be null, but it isn't.\n{2}", dsVariable, TestFrameWork.BuildIndicesString(indices), TestFrameWork.mErrorMessage));
                }
            }
            else if (dsObject.DsasmValue.optype == ProtoCore.DSASM.AddressType.Null && expectedObject != null)
            {
                Assert.Fail(String.Format("\tThe value of {0} was null, but wasn't expected to be.\n{1}", dsVariable, mErrorMessage));
            }
            else if (expectedObject is Int32 || expectedObject is Int64)
            {
                Int64 expectedValue = Convert.ToInt64(expectedObject);
                if (dsObject.Type.UID != (int)ProtoCore.PrimitiveType.kTypeInt)
                {
                    Assert.Fail(String.Format("\t{0}{1} is expected to be {2}, but its actual value is not an integer. \n{2}", dsVariable, BuildIndicesString(indices), expectedValue, mErrorMessage));
                }
                else
                {
                    TestFrameWork.VerifyPodType(expectedValue, dsObject, dsVariable, indices);
                }
            }
            else if (expectedObject is Double)
            {
                Double expectedValue = Convert.ToDouble(expectedObject);
                if (dsObject.Type.UID != (int)ProtoCore.PrimitiveType.kTypeDouble)
                {
                    Assert.Fail(String.Format("\t{0}{1} is expected to be {2}, but its actual value is not a double. \n{3}", dsVariable, BuildIndicesString(indices), expectedValue, mErrorMessage));
                }
                else
                {
                    try
                    {
                        Double dsValue = Convert.ToDouble(dsObject.Payload);

                        if (!MathUtils.Equals(expectedValue, dsValue))
                        {
                            Assert.Fail(String.Format("\t{0}{1} is expected to be {2}, but its actual value is {3}. \n{4}", dsVariable, BuildIndicesString(indices), expectedValue, dsValue, mErrorMessage));
                        }
                    }
                    catch (System.InvalidCastException)
                    {
                        Assert.Fail(String.Format("\t{0}{1} is expected to be {2}, but its actual value can't be converted to Double. \n{3}", dsVariable, BuildIndicesString(indices), expectedValue, mErrorMessage));
                    }
                }
            }
            else if (expectedObject is Boolean)
            {
                Boolean expectedValue = Convert.ToBoolean(expectedObject);
                if (dsObject.Type.UID != (int)ProtoCore.PrimitiveType.kTypeBool)
                {
                    Assert.Fail(String.Format("\t{0}{1} is expected to be {2}, but its actual type is not bool. \n{3}", dsVariable, BuildIndicesString(indices), expectedValue, mErrorMessage));
                }
                else
                {
                    TestFrameWork.VerifyPodType(expectedValue, dsObject, dsVariable, indices);
                }
            }
            else if (expectedObject is Char)
            {
                Char expectedValue = Convert.ToChar(expectedObject);

                if (dsObject.Type.UID != (int)ProtoCore.PrimitiveType.kTypeChar)
                {
                    Assert.Fail(String.Format("\t{0}{1} is expected to be {2}, but its actual type is not char. \n{3}", dsVariable, BuildIndicesString(indices), expectedValue, mErrorMessage));
                }
                else
                {
                    try
                    {
                        Int64 utf8Encoding = Convert.ToInt64(dsObject.Payload);
                        Char  dsValue      = EncodingUtils.ConvertInt64ToCharacter(utf8Encoding);

                        if (!expectedObject.Equals(dsValue))
                        {
                            Assert.Fail(String.Format("\t{0}{1} is expected to be {2}, but its actual value is {3}. \n{4}", dsVariable, BuildIndicesString(indices), expectedValue, dsValue, mErrorMessage));
                        }
                    }
                    catch (System.InvalidCastException)
                    {
                        Assert.Fail(String.Format("\t{0}{1} is expected to be {2}, but its actual value can't be converted to Char. \n{3}", dsVariable, BuildIndicesString(indices), expectedValue, mErrorMessage));
                    }
                }
            }
            else if (expectedObject is String)
            {
                char[]   chars = (expectedObject as String).ToCharArray();
                object[] objs  = new object[chars.Length];
                Array.Copy(chars, objs, chars.Length);

                ProtoCore.DSASM.Mirror.DsasmArray dsArray = dsObject.Payload as ProtoCore.DSASM.Mirror.DsasmArray;
                if (dsArray == null)
                {
                    Assert.Fail(String.Format("\t{0}{1} is expected to be a string, but its actual value is not a string\n{2}", dsVariable, BuildIndicesString(indices), mErrorMessage));
                }
                else if (chars.Count() != dsArray.members.Count())
                {
                    Assert.Fail(String.Format("\t{0}{1} is expected to be a string of length {2}, but its actual length is {3}.\n{4}", dsVariable, BuildIndicesString(indices), objs.Count(), dsArray.members.Count(), mErrorMessage));
                }
                else
                {
                    for (int i = 0; i < objs.Count(); ++i)
                    {
                        indices.Add(i);
                        TestFrameWork.VerifyInternal(objs[i], dsArray.members[i], dsVariable, indices);
                        indices.RemoveAt(indices.Count - 1);
                    }
                }

                // VerifyInternal(objs, dsObject, dsVariable, indices);
            }
            else if (expectedObject.GetType().IsArray)
            {
                object[] expectedArray = expectedObject as object[];
                ProtoCore.DSASM.Mirror.DsasmArray dsArray = dsObject.Payload as ProtoCore.DSASM.Mirror.DsasmArray;
                if (dsArray == null)
                {
                    Assert.Fail(String.Format("{0}{1} is expected to be an array, but its actual value isn't an array.\n{2}", dsVariable, BuildIndicesString(indices), mErrorMessage));
                }
                else if (expectedArray.Count() != dsArray.members.Count())
                {
                    Assert.Fail(String.Format("{0}{1} is expected to be an array of length {2}, but its actual length is {3}.\n{4}", dsVariable, BuildIndicesString(indices), expectedArray.Count(), dsArray.members.Count(), mErrorMessage));
                }
                else
                {
                    for (int i = 0; i < expectedArray.Count(); ++i)
                    {
                        indices.Add(i);
                        VerifyInternal(expectedArray[i], dsArray.members[i], dsVariable, indices);
                        indices.RemoveAt(indices.Count - 1);
                    }
                }
            }
            else
            {
                Assert.Fail(string.Format("\tUnexpected object type.\n{0}", mErrorMessage));
            }
        }