当前位置: 首页>>代码示例>>C#>>正文


C# StackValue类代码示例

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


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

示例1: CopyIsACopy

        public void CopyIsACopy()
        {
            var stack = new StackValue();

            var zedObject = new object();
            InvokeDelegate(stack, "PUSH", zedObject);
            var firstObject = new object();
            InvokeDelegate(stack, "PUSH", firstObject);
            var secondObject = new object();
            InvokeDelegate(stack, "PUSH", secondObject);
            var thirdObject = "third";
            InvokeDelegate(stack, "PUSH", thirdObject);

            var length = InvokeDelegate(stack, "LENGTH");
            Assert.AreEqual(4,length);

            var copy = InvokeDelegate(stack, "COPY") as StackValue;
            Assert.AreNotSame(stack, copy);

            var copyLength = InvokeDelegate(copy, "LENGTH");
            Assert.AreEqual(4,copyLength);

            object popped = InvokeDelegate(copy, "POP");
            Assert.AreEqual(thirdObject, popped);

            InvokeDelegate(copy, "CLEAR");

            copyLength = InvokeDelegate(copy, "LENGTH");
            Assert.AreEqual(0,copyLength);

            length = InvokeDelegate(stack, "LENGTH");
            Assert.AreEqual(4,length);
        }
开发者ID:Whitecaribou,项目名称:KOS,代码行数:33,代码来源:StackValueTest.cs

示例2: Repack

        public static StackValue Repack(Obj obj, ProtoCore.DSASM.Heap heap)
        {
            if (obj.Type.IsIndexable)
            {
                //Unpack each of the elements
                DsasmArray arr = (DsasmArray)obj.Payload;

                StackValue[] sv = new StackValue[arr.members.Length];

                //recurse over the array
                for (int i = 0; i < sv.Length; i++)
                    sv[i] = Repack(arr.members[i], heap);

                int size = sv.Length;

                lock (heap.cslock)
                {
                    int ptr = heap.Allocate(size);
                    ++heap.Heaplist[ptr].Refcount;
                    for (int n = size - 1; n >= 0; --n)
                    {
                        heap.Heaplist[ptr].Stack[n] = sv[n];
                    }

                    StackValue overallSv = StackUtils.BuildArrayPointer(ptr);

                    return overallSv;
                }
            }

            // For non-arrays, there is nothing to repack so just return the original stackvalue
            return obj.DsasmValue;
        }
开发者ID:Benglin,项目名称:designscript,代码行数:33,代码来源:ExecutionMirror.cs

示例3: CanClear

        public void CanClear()
        {
            var stack = new StackValue();

            InvokeDelegate(stack, "PUSH", new ScalarIntValue(1));
            InvokeDelegate(stack, "PUSH", new ScalarIntValue(2));

            var length = InvokeDelegate(stack, "LENGTH");
            Assert.AreEqual(new ScalarIntValue(2),length);
            InvokeDelegate(stack, "CLEAR");
            length = InvokeDelegate(stack, "LENGTH");
            Assert.AreEqual(new ScalarIntValue(0),length);
        }
开发者ID:CalebJ2,项目名称:KOS,代码行数:13,代码来源:StackValueTest.cs

示例4: CanClear

        public void CanClear()
        {
            var stack = new StackValue();

            InvokeDelegate(stack, "PUSH", 1);
            InvokeDelegate(stack, "PUSH", new object());

            var length = InvokeDelegate(stack, "LENGTH");
            Assert.AreEqual(2,length);
            InvokeDelegate(stack, "CLEAR");
            length = InvokeDelegate(stack, "LENGTH");
            Assert.AreEqual(0,length);
        }
开发者ID:Whitecaribou,项目名称:KOS,代码行数:13,代码来源:StackValueTest.cs

示例5: StackValueDeref

        public StackValueDeref(StackValue pointer)
        {
            ValueType = StackValueType.Unknown;
            ProcessedValue = false;

            if (pointer is StackValuePointerBase)
            {
                Pointer = pointer as StackValuePointerBase;
            }
            else
            {
                UnknownPointer = pointer;
            }
        }
开发者ID:tjhorner,项目名称:gtaivtools,代码行数:14,代码来源:StackValueDeref.cs

示例6: CanSerializeStacks

        public void CanSerializeStacks()
        {
            var stack = new StackValue();
            var nested = new StackValue();

            stack.Push(new StringValue("item1"));
            stack.Push(new ScalarIntValue(2));
            stack.Push(nested);

            nested.Push(new StringValue("nested1"));

            StackValue deserialized = Deserialize(Serialize(stack)) as StackValue;

            Assert.AreEqual(new StringValue("nested1"), (deserialized.Pop() as StackValue).Pop());
            Assert.AreEqual(new ScalarIntValue(2), deserialized.Pop());
            Assert.AreEqual(new StringValue("item1"), deserialized.Pop());
        }
开发者ID:CalebJ2,项目名称:KOS,代码行数:17,代码来源:JSONFormatterTest.cs

示例7: CanTestContains

        public void CanTestContains()
        {
            var stack = new StackValue();

            var zedObject = new StringValue("abc");
            InvokeDelegate(stack, "PUSH", zedObject);
            var firstObject = ScalarIntValue.One;
            InvokeDelegate(stack, "PUSH", firstObject);
            var secondObject = ScalarIntValue.Two;
            var thirdObject = new ScalarIntValue(4);

            var length = InvokeDelegate(stack, "LENGTH");
            Assert.AreEqual(ScalarIntValue.Two, length);

            Assert.IsTrue((BooleanValue)InvokeDelegate(stack, "CONTAINS", zedObject));
            Assert.IsTrue((BooleanValue)InvokeDelegate(stack, "CONTAINS", firstObject));
            Assert.IsFalse((BooleanValue)InvokeDelegate(stack, "CONTAINS", secondObject));
            Assert.IsFalse((BooleanValue)InvokeDelegate(stack, "CONTAINS", thirdObject));
        }
开发者ID:CalebJ2,项目名称:KOS,代码行数:19,代码来源:StackValueTest.cs

示例8: CanPushPopItem

        public void CanPushPopItem()
        {
            var stack = new StackValue();
            Assert.IsNotNull(stack);
            var length = InvokeDelegate(stack, "LENGTH");
            Assert.AreEqual(new ScalarIntValue(0), length);

            InvokeDelegate(stack, "PUSH", new StringValue("value1"));
            InvokeDelegate(stack, "PUSH", new StringValue("value2"));

            length = InvokeDelegate(stack, "LENGTH");
            Assert.AreEqual(ScalarIntValue.Two, length);

            object popped = InvokeDelegate(stack, "POP");
            Assert.AreEqual(new StringValue("value2"), popped);

            popped = InvokeDelegate(stack, "POP");
            Assert.AreEqual(new StringValue("value1"), popped);

            length = InvokeDelegate(stack, "LENGTH");
            Assert.AreEqual(ScalarIntValue.Zero, length);
        }
开发者ID:CalebJ2,项目名称:KOS,代码行数:22,代码来源:StackValueTest.cs

示例9: CanPushPopItem

        public void CanPushPopItem()
        {
            var stack = new StackValue();
            Assert.IsNotNull(stack);
            var length = InvokeDelegate(stack, "LENGTH");
            Assert.AreEqual(0,length);

            InvokeDelegate(stack, "PUSH", "value1");
            InvokeDelegate(stack, "PUSH", "value2");

            length = InvokeDelegate(stack, "LENGTH");
            Assert.AreEqual(2,length);

            object popped = InvokeDelegate(stack, "POP");
            Assert.AreEqual("value2", popped);

            popped = InvokeDelegate(stack, "POP");
            Assert.AreEqual("value1", popped);

            length = InvokeDelegate(stack, "LENGTH");
            Assert.AreEqual(0, length);
        }
开发者ID:Whitecaribou,项目名称:KOS,代码行数:22,代码来源:StackValueTest.cs

示例10: GetFirstNameFromValue

        public string GetFirstNameFromValue(StackValue v)
        {
            if (v.optype != AddressType.Pointer)
                throw new ArgumentException("SV to highlight must be a pointer");

            ProtoCore.DSASM.Executable exe = MirrorTarget.rmem.Executable;

            List<SymbolNode> symNodes = new List<SymbolNode>();

            foreach (SymbolTable symTable in exe.runtimeSymbols)
            {
                foreach (SymbolNode symNode in symTable.symbolList.Values)
                {
                    symNodes.Add(symNode);
                }

            }

            int index = MirrorTarget.rmem.Stack.FindIndex(0, value => value.opdata == v.opdata);

            List<SymbolNode> matchingNodes = symNodes.FindAll(value => value.index == index);

            if (matchingNodes.Count > 0)
                return matchingNodes[0].name;
            else
            {
                return null;
            }
        }
开发者ID:Benglin,项目名称:designscript,代码行数:29,代码来源:ExecutionMirror.cs

示例11: GetStringValue

 public string GetStringValue(StackValue val, Heap heap, int langblock, bool forPrint = false)
 {
     return GetStringValue(val, heap, langblock, -1, -1, forPrint);
 }
开发者ID:Benglin,项目名称:designscript,代码行数:4,代码来源:ExecutionMirror.cs

示例12: GetClassTrace

        public string GetClassTrace(StackValue val, Heap heap, int langblock, bool forPrint)
        {
            if (!formatParams.ContinueOutputTrace())
                return "...";

            ClassTable classTable = MirrorTarget.rmem.Executable.classTable;

            int classtype = (int)val.metaData.type;
            if (classtype < 0 || (classtype >= classTable.ClassNodes.Count))
            {
                formatParams.RestoreOutputTraceDepth();
                return string.Empty;
            }

            ClassNode classnode = classTable.ClassNodes[classtype];
            if (classnode.IsImportedClass)
            {
                var helper = DLLFFIHandler.GetModuleHelper(FFILanguage.CSharp);
                var marshaller = helper.GetMarshaller(core);
                var strRep = marshaller.GetStringValue(val);
                formatParams.RestoreOutputTraceDepth();
                return strRep;
            }
            else
            {
                int ptr = (int)val.opdata;
                HeapElement hs = heap.Heaplist[ptr];

                List<string> visibleProperties = null;
                if (null != propertyFilter)
                {
                    if (!propertyFilter.TryGetValue(classnode.name, out visibleProperties))
                        visibleProperties = null;
                }

                StringBuilder classtrace = new StringBuilder();
                if (classnode.symbols != null && classnode.symbols.symbolList.Count > 0)
                {
                    bool firstPropertyDisplayed = false;
                    for (int n = 0; n < hs.VisibleSize; ++n)
                    {
                        SymbolNode symbol = classnode.symbols.symbolList[n];
                        string propName = symbol.name;

                        if ((null != visibleProperties) && visibleProperties.Contains(propName) == false)
                            continue; // This property is not to be displayed.

                        if (false != firstPropertyDisplayed)
                            classtrace.Append(", ");

                        string propValue = "";
                        if (symbol.isStatic)
                        {
                            StackValue opSymbol = new StackValue();
                            opSymbol.opdata = symbol.symbolTableIndex;
                            opSymbol.optype = AddressType.StaticMemVarIndex;

                            StackValue staticProp = this.core.Rmem.GetStackData(langblock, (int)opSymbol.opdata, Constants.kGlobalScope);
                            propValue = GetStringValue(staticProp, heap, langblock, forPrint);
                        }
                        else
                        {
                            propValue = GetStringValue(hs.Stack[symbol.index], heap, langblock, forPrint);
                        }
                        classtrace.Append(string.Format("{0} = {1}", propName, propValue));
                        firstPropertyDisplayed = true;
                    }
                }
                else
                {
                    for (int n = 0; n < hs.VisibleSize; ++n)
                    {
                        if (0 != n)
                            classtrace.Append(", ");

                        classtrace.Append(GetStringValue(hs.Stack[n], heap, langblock, forPrint));
                    }
                }

                formatParams.RestoreOutputTraceDepth();
                if (classtype >= (int)ProtoCore.PrimitiveType.kMaxPrimitives)
                    if (forPrint)
                        return (string.Format("{0}{{{1}}}", classnode.name, classtrace.ToString()));
                    else
                    {
                        string tempstr =  (string.Format("{0}({1})", classnode.name, classtrace.ToString()));
                        return tempstr;
                    }

                return classtrace.ToString();
            }
        }
开发者ID:Benglin,项目名称:designscript,代码行数:92,代码来源:ExecutionMirror.cs

示例13: GetDebugValue

        public Obj GetDebugValue(string name)
        {
            int classcope;
            int block = core.GetCurrentBlockId();

            RuntimeMemory rmem = core.Rmem;
            SymbolNode symbol;
            int index = GetSymbolIndex(name, out classcope, ref block, out symbol);
            StackValue sv = new StackValue();
            if (symbol.functionIndex == -1 && classcope != Constants.kInvalidIndex)
                sv = rmem.GetMemberData(index, classcope);
            else
                sv = rmem.GetStackData(block, index, classcope);

            if (sv.optype == AddressType.Invalid)
                throw new UninitializedVariableException { Name = name };

            return Unpack(sv);
        }
开发者ID:Benglin,项目名称:designscript,代码行数:19,代码来源:ExecutionMirror.cs

示例14: Unpack

        //@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()));
                    }
            }
        }
开发者ID:Benglin,项目名称:designscript,代码行数:90,代码来源:ExecutionMirror.cs

示例15: GetClassTrace

        public string GetClassTrace(StackValue val, Heap heap, int langblock, bool forPrint)
        {
            if (!formatParams.ContinueOutputTrace())
                return "...";

            RuntimeMemory rmem = MirrorTarget.rmem;
            Executable exe = MirrorTarget.exe;
            ClassTable classTable = MirrorTarget.RuntimeCore.DSExecutable.classTable;

            int classtype = val.metaData.type;
            if (classtype < 0 || (classtype >= classTable.ClassNodes.Count))
            {
                formatParams.RestoreOutputTraceDepth();
                return string.Empty;
            }

            ClassNode classnode = classTable.ClassNodes[classtype];
            if (classnode.IsImportedClass)
            {
                var helper = DLLFFIHandler.GetModuleHelper(FFILanguage.CSharp);
                var marshaller = helper.GetMarshaller(runtimeCore);
                var strRep = marshaller.GetStringValue(val);
                formatParams.RestoreOutputTraceDepth();
                return strRep;
            }
            else
            {
                var obj = heap.ToHeapObject<DSObject>(val);

                List<string> visibleProperties = null;
                if (null != propertyFilter)
                {
                    if (!propertyFilter.TryGetValue(classnode.Name, out visibleProperties))
                        visibleProperties = null;
                }

                StringBuilder classtrace = new StringBuilder();
                if (classnode.Symbols != null && classnode.Symbols.symbolList.Count > 0)
                {
                    bool firstPropertyDisplayed = false;
                    for (int n = 0; n < obj.Count; ++n)
                    {
                        SymbolNode symbol = classnode.Symbols.symbolList[n];
                        string propName = symbol.name;

                        if ((null != visibleProperties) && visibleProperties.Contains(propName) == false)
                            continue; // This property is not to be displayed.

                        if (firstPropertyDisplayed)
                            classtrace.Append(", ");

                        string propValue = "";
                        if (symbol.isStatic)
                        {
                            var staticSymbol = exe.runtimeSymbols[langblock].symbolList[symbol.symbolTableIndex];
                            StackValue staticProp = rmem.GetSymbolValue(staticSymbol);
                            propValue = GetStringValue(staticProp, heap, langblock, forPrint);
                        }
                        else
                        {
                            propValue = GetStringValue(obj.GetValueFromIndex(symbol.index, runtimeCore), heap, langblock, forPrint);
                        }
                        classtrace.Append(string.Format("{0} = {1}", propName, propValue));
                        firstPropertyDisplayed = true;
                    }
                }
                else
                {
                    var stringValues = obj.Values.Select(x => GetStringValue(x, heap, langblock, forPrint))
                                                      .ToList();

                    for (int n = 0; n < stringValues.Count(); ++n)
                    {
                        if (0 != n)
                            classtrace.Append(", ");

                        classtrace.Append(stringValues[n]);
                    }
                }

                formatParams.RestoreOutputTraceDepth();
                if (classtype >= (int)ProtoCore.PrimitiveType.MaxPrimitive)
                    if (forPrint)
                        return (string.Format("{0}{{{1}}}", classnode.Name, classtrace.ToString()));
                    else
                    {
                        string tempstr =  (string.Format("{0}({1})", classnode.Name, classtrace.ToString()));
                        return tempstr;
                    }

                return classtrace.ToString();
            }
        }
开发者ID:YanmengLi,项目名称:Dynamo,代码行数:93,代码来源:ExecutionMirror.cs


注:本文中的StackValue类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。