當前位置: 首頁>>代碼示例>>C#>>正文


C# StackValue.AsInt方法代碼示例

本文整理匯總了C#中ProtoCore.DSASM.StackValue.AsInt方法的典型用法代碼示例。如果您正苦於以下問題:C# StackValue.AsInt方法的具體用法?C# StackValue.AsInt怎麽用?C# StackValue.AsInt使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在ProtoCore.DSASM.StackValue的用法示例。


在下文中一共展示了StackValue.AsInt方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: ContainsKey

        /// <summary>
        /// Check if an array contain key
        /// </summary>
        /// <param name="array"></param>
        /// <param name="key"></param>
        /// <param name="core"></param>
        /// <returns></returns>
        public static bool ContainsKey(StackValue array, StackValue key, Core core)
        {
            Validity.Assert(StackUtils.IsArray(array));
            if (!StackUtils.IsArray(array))
            {
                return false;
            }

            HeapElement he = GetHeapElement(array, core);
            if (StackUtils.IsNumeric(key))
            {
                long index = key.AsInt().opdata;
                if (index < 0)
                {
                    index = index + he.VisibleSize;
                }
                return (index >= 0 && index < he.VisibleSize);
            }
            else
            {
                return he.Dict != null && he.Dict.ContainsKey(key);
            }
        }
開發者ID:samuto,項目名稱:designscript,代碼行數:30,代碼來源:ArrayUtils.cs

示例2: Coerce


//.........這裏部分代碼省略.........
                    return sv.AsBoolean(core);

                case (int)PrimitiveType.kTypeChar:
                    {
                        StackValue newSV = sv.ShallowClone();
                        newSV.metaData = new MetaData { type = (int)PrimitiveType.kTypeChar };
                        return newSV;
                    }

                case (int)PrimitiveType.kTypeDouble:
                    return sv.AsDouble();

                case (int)PrimitiveType.kTypeFunctionPointer:
                    if (sv.metaData.type != (int)PrimitiveType.kTypeFunctionPointer)
                    {
                        core.RuntimeStatus.LogWarning(RuntimeData.WarningID.kTypeMismatch, ProtoCore.RuntimeData.WarningMessage.kFailToConverToFunction);
                        return StackUtils.BuildNull();
                    }
                    return sv.ShallowClone();

                case (int)PrimitiveType.kTypeHostEntityID:
                    {
                        StackValue newSV = sv.ShallowClone();
                        newSV.metaData = new MetaData { type = (int)PrimitiveType.kTypeHostEntityID };
                        return newSV;
                    }

                case (int)PrimitiveType.kTypeInt:
                    {
                        if (sv.metaData.type == (int)PrimitiveType.kTypeDouble)
                        {
                            core.RuntimeStatus.LogWarning(RuntimeData.WarningID.kTypeConvertionCauseInfoLoss, ProtoCore.RuntimeData.WarningMessage.kConvertDoubleToInt);
                        }
                        return sv.AsInt();
                    }

                case (int)PrimitiveType.kTypeNull:
                    {
                        if (sv.metaData.type != (int)PrimitiveType.kTypeNull)
                        {
                            core.RuntimeStatus.LogWarning(RuntimeData.WarningID.kTypeMismatch, ProtoCore.RuntimeData.WarningMessage.kFailToConverToNull);
                            return StackUtils.BuildNull();
                        }
                        return sv.ShallowClone();
                    }

                case (int)PrimitiveType.kTypePointer:
                    {
                        if (sv.metaData.type != (int)PrimitiveType.kTypeNull)
                        {
                            core.RuntimeStatus.LogWarning(RuntimeData.WarningID.kTypeMismatch, ProtoCore.RuntimeData.WarningMessage.kFailToConverToPointer);
                            return StackUtils.BuildNull();
                        }
                        StackValue ret = sv.ShallowClone();
                        return ret;
                    }

                case (int)PrimitiveType.kTypeString:
                    {

                        StackValue newSV = sv.ShallowClone();
                        newSV.metaData = new MetaData { type = (int)PrimitiveType.kTypeString };
                        if (sv.metaData.type == (int)PrimitiveType.kTypeChar)
                        {
                            char ch = ProtoCore.Utils.EncodingUtils.ConvertInt64ToCharacter(newSV.opdata);
                            newSV = StackUtils.BuildString(ch.ToString(), core.Heap);
開發者ID:junmendoza,項目名稱:designscript,代碼行數:67,代碼來源:Type.cs

示例3: SetValueForIndex

        /// <summary>
        /// array[index] = value. Here index can be any type. 
        /// 
        /// Note this function doesn't support the replication of array indexing.
        /// </summary>
        /// <param name="array"></param>
        /// <param name="index"></param>
        /// <param name="value"></param>
        /// <param name="core"></param>
        /// <returns></returns>
        public static StackValue SetValueForIndex(StackValue array, StackValue index, StackValue value, Core core)
        {
            Validity.Assert(StackUtils.IsArray(array) || StackUtils.IsString(array));

            if (StackUtils.IsNumeric(index))
            {
                index = index.AsInt();
                return SetValueForIndex(array, (int)index.opdata, value, core);
            }
            else
            {
                HeapElement he = GetHeapElement(array, core);
                if (he.Dict == null)
                {
                    he.Dict = new Dictionary<StackValue, StackValue>(new StackValueComparer(core));
                }

                StackValue oldValue;
                if (!he.Dict.TryGetValue(index, out oldValue))
                {
                    oldValue = StackUtils.BuildNull();
                }

                GCUtils.GCRetain(index, core);
                GCUtils.GCRetain(value, core);
                he.Dict[index] = value;

                return oldValue;
            }
        }
開發者ID:samuto,項目名稱:designscript,代碼行數:40,代碼來源:ArrayUtils.cs

示例4: RemoveKey

        public static bool RemoveKey(StackValue array, StackValue key, Core core)
        {
            Validity.Assert(StackUtils.IsArray(array));
            if (!StackUtils.IsArray(array))
            {
                return false;
            }

            HeapElement he = GetHeapElement(array, core);

            if (StackUtils.IsNumeric(key))
            {
                long index = key.AsInt().opdata;
                if (index < 0)
                {
                    index = index + he.VisibleSize;
                }

                if (index >= 0 && index < he.VisibleSize)
                {
                    StackValue oldValue = he.Stack[index];
                    he.Stack[index] = StackUtils.BuildNull();

                    if (index == he.VisibleSize - 1)
                    {
                        he.VisibleSize -= 1;
                    }
                    return true;
                }
            }
            else
            {
                if (he.Dict != null && he.Dict.ContainsKey(key))
                {
                    StackValue value = he.Dict[key];
                    GCUtils.GCRelease(key, core);
                    GCUtils.GCRelease(value, core);
                    he.Dict.Remove(key);
                    return true;
                }
            }

            return false;
        }
開發者ID:samuto,項目名稱:designscript,代碼行數:44,代碼來源:ArrayUtils.cs

示例5: GetValueFromIndex

        /// <summary>
        /// = array[index].
        /// 
        /// Note this function doesn't support the replication of array indexing.
        /// </summary>
        /// <param name="array"></param>
        /// <param name="index"></param>
        /// <param name="core"></param>
        /// <returns></returns>
        public static StackValue GetValueFromIndex(StackValue array, StackValue index, Core core)
        {
            Validity.Assert(StackUtils.IsArray(array) || StackUtils.IsString(array));
            if (!StackUtils.IsArray(array) && !StackUtils.IsString(array))
            {
                return StackUtils.BuildNull();
            }

            if (StackUtils.IsNumeric(index))
            {
                index = index.AsInt();
                return GetValueFromIndex(array, (int)index.opdata, core);
            }
            else if (index.optype == AddressType.ArrayKey)
            {
                int fullIndex = (int)index.opdata;
                HeapElement he = GetHeapElement(array, core);

                if (he.VisibleSize > fullIndex)
                {
                    return GetValueFromIndex(array, fullIndex, core);
                }
                else
                {
                    fullIndex = fullIndex - he.VisibleSize;
                    if (he.Dict != null && he.Dict.Count > fullIndex)
                    {
                        int count = 0;
                        foreach (var key in he.Dict.Keys)
                        {
                            if (count == fullIndex)
                            {
                                return he.Dict[key];
                            }
                            count = count + 1;
                        }
                    }
                }

                return StackUtils.BuildNull();
            }
            else
            {
                HeapElement he = GetHeapElement(array, core);
                StackValue value = StackUtils.BuildNull();

                if (he.Dict != null && he.Dict.TryGetValue(index, out value))
                {
                    return value;
                }
                else
                {
                    return StackUtils.BuildNull();
                }
            }
        }
開發者ID:samuto,項目名稱:designscript,代碼行數:65,代碼來源:ArrayUtils.cs


注:本文中的ProtoCore.DSASM.StackValue.AsInt方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。