本文整理匯總了C#中ProtoCore.DSASM.StackValue.ToInteger方法的典型用法代碼示例。如果您正苦於以下問題:C# StackValue.ToInteger方法的具體用法?C# StackValue.ToInteger怎麽用?C# StackValue.ToInteger使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類ProtoCore.DSASM.StackValue
的用法示例。
在下文中一共展示了StackValue.ToInteger方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: RemoveKey
public bool RemoveKey(StackValue key)
{
if (key.IsNumeric)
{
long index = key.ToInteger().opdata;
if (index < 0)
{
index = index + VisibleSize;
}
if (index >= 0 && index < VisibleSize)
{
SetItemAt((int)index, StackValue.Null);
if (index == VisibleSize - 1)
{
VisibleSize -= 1;
}
return true;
}
}
else
{
if (Dict != null && Dict.ContainsKey(key))
{
Dict.Remove(key);
return true;
}
}
return false;
}
示例2: ContainsKey
/// <summary>
/// Returns true if array contain key or not.
/// </summary>
/// <param name="array"></param>
/// <param name="key"></param>
/// <param name="core"></param>
/// <returns></returns>
public bool ContainsKey(StackValue key)
{
if (key.IsNumeric)
{
int index = (int)key.ToInteger().IntegerValue;
if (index < 0)
{
index = index + Count;
}
return (index >= 0 && index < Count);
}
else
{
return Dict != null && Dict.ContainsKey(key);
}
}
示例3: ContainsKey
/// <summary>
/// Check if an array contain key
/// </summary>
/// <param name="array"></param>
/// <param name="key"></param>
/// <param name="core"></param>
/// <returns></returns>
public bool ContainsKey(StackValue key)
{
if (key.IsNumeric)
{
long index = key.ToInteger().opdata;
if (index < 0)
{
index = index + VisibleSize;
}
return (index >= 0 && index < VisibleSize);
}
else
{
return Dict != null && Dict.ContainsKey(key);
}
}
示例4: Coerce
//.........這裏部分代碼省略.........
}
}
if (sv.IsPointer)
{
StackValue ret = ClassCoerece(sv, targetType, runtimeCore);
return ret;
}
//If it's anything other than array, just create a new copy
switch (targetType.UID)
{
case (int)PrimitiveType.kInvalidType:
runtimeCore.RuntimeStatus.LogWarning(Runtime.WarningID.kInvalidType, Resources.kInvalidType);
return StackValue.Null;
case (int)PrimitiveType.kTypeBool:
return sv.ToBoolean(runtimeCore);
case (int)PrimitiveType.kTypeChar:
{
StackValue newSV = sv.ShallowClone();
newSV.metaData = new MetaData { type = (int)PrimitiveType.kTypeChar };
return newSV;
}
case (int)PrimitiveType.kTypeDouble:
return sv.ToDouble();
case (int)PrimitiveType.kTypeFunctionPointer:
if (sv.metaData.type != (int)PrimitiveType.kTypeFunctionPointer)
{
runtimeCore.RuntimeStatus.LogWarning(Runtime.WarningID.kTypeMismatch, Resources.kFailToConverToFunction);
return StackValue.Null;
}
return sv;
case (int)PrimitiveType.kTypeInt:
{
if (sv.metaData.type == (int)PrimitiveType.kTypeDouble)
{
//TODO(lukechurch): Once the API is improved (MAGN-5174)
//Replace this with a log entry notification
//core.RuntimeStatus.LogWarning(RuntimeData.WarningID.kTypeConvertionCauseInfoLoss, Resources.kConvertDoubleToInt);
}
return sv.ToInteger();
}
case (int)PrimitiveType.kTypeNull:
{
if (sv.metaData.type != (int)PrimitiveType.kTypeNull)
{
runtimeCore.RuntimeStatus.LogWarning(Runtime.WarningID.kTypeMismatch, Resources.kFailToConverToNull);
return StackValue.Null;
}
return sv;
}
case (int)PrimitiveType.kTypePointer:
{
if (sv.metaData.type != (int)PrimitiveType.kTypeNull)
{
runtimeCore.RuntimeStatus.LogWarning(Runtime.WarningID.kTypeMismatch, Resources.kFailToConverToPointer);
return StackValue.Null;
}
return sv;
}
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 = EncodingUtils.ConvertInt64ToCharacter(newSV.opdata);
newSV = StackValue.BuildString(ch.ToString(), rmem.Heap);
}
return newSV;
}
case (int)PrimitiveType.kTypeVar:
{
return sv;
}
case (int)PrimitiveType.kTypeArray:
{
var array = runtimeCore.Heap.ToHeapObject<DSArray>(sv);
return array.CopyArray(targetType, runtimeCore);
}
default:
if (sv.IsNull)
return StackValue.Null;
else
throw new NotImplementedException("Requested coercion not implemented");
}
throw new NotImplementedException("Requested coercion not implemented");
}
示例5: RemoveKey
/// <summary>
/// Remove a key from array. Return true if key exsits.
/// </summary>
/// <param name="key"></param>
/// <returns></returns>
public bool RemoveKey(StackValue key)
{
if (key.IsNumeric)
{
int index = (int)key.ToInteger().IntegerValue;
if (index < 0)
{
index = index + Count;
}
if (index >= 0 && index < Count)
{
SetValueAt(index, StackValue.Null);
if (index == Count - 1)
{
Count -= 1;
}
return true;
}
}
else
{
if (Dict != null && Dict.ContainsKey(key))
{
Dict.Remove(key);
return true;
}
}
return false;
}
示例6: GetValueAtIndex
public StackValue GetValueAtIndex(StackValue index, RuntimeCore runtimeCore)
{
int pos = Constants.kInvalidIndex;
if (index.IsNumeric)
{
pos = (int)index.ToInteger().IntegerValue;
return GetValueAtIndex(pos, runtimeCore);
}
else if (index.IsArrayKey)
{
StackValue array;
index.TryGetArrayKey(out array, out pos);
return GetValueAtIndex(pos, runtimeCore);
}
else
{
if (runtimeCore != null)
runtimeCore.RuntimeStatus.LogWarning(WarningID.InvalidIndexing, Resources.kInvalidArguments);
return StackValue.Null;
}
}
示例7: GetValueFromIndex
/// <summary>
/// = array[index].
///
/// Note this function doesn't support the replication of array indexing.
/// </summary>
/// <param name="index"></param>
/// <param name="core"></param>
/// <returns></returns>
public StackValue GetValueFromIndex(StackValue index, RuntimeCore runtimeCore)
{
if (index.IsNumeric)
{
index = index.ToInteger();
return GetValueFromIndex((int)index.IntegerValue, runtimeCore);
}
else if (index.IsArrayKey)
{
int fullIndex = Constants.kInvalidIndex;
StackValue array;
index.TryGetArrayKey(out array, out fullIndex);
if (Count > fullIndex)
{
return GetValueFromIndex(fullIndex, runtimeCore);
}
else
{
fullIndex = fullIndex - Count;
if (Dict != null && Dict.Count > fullIndex)
{
int count = 0;
foreach (var key in Dict.Keys)
{
if (count == fullIndex)
{
return Dict[key];
}
count = count + 1;
}
}
}
return StackValue.Null;
}
else
{
StackValue value = StackValue.Null;
if (Dict.TryGetValue(index, out value))
{
return value;
}
else
{
return StackValue.Null;
}
}
}
示例8: 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="index"></param>
/// <param name="value"></param>
/// <param name="core"></param>
/// <returns></returns>
public StackValue SetValueForIndex(StackValue index, StackValue value, RuntimeCore runtimeCore)
{
if (index.IsNumeric)
{
index = index.ToInteger();
return SetValueForIndex((int)index.IntegerValue, value, runtimeCore);
}
else
{
StackValue oldValue;
if (Dict.TryGetValue(index, out oldValue))
{
oldValue = StackValue.Null;
}
Dict[index] = value;
return oldValue;
}
}
示例9: 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(array.IsArray || array.IsString);
if (!array.IsArray && !array.IsString)
{
return StackValue.Null;
}
if (index.IsNumeric)
{
index = index.ToInteger();
return GetValueFromIndex(array, (int)index.opdata, core);
}
else if (index.IsArrayKey)
{
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 StackValue.Null;
}
else
{
HeapElement he = GetHeapElement(array, core);
StackValue value = StackValue.Null;
if (he.Dict != null && he.Dict.TryGetValue(index, out value))
{
return value;
}
else
{
return StackValue.Null;
}
}
}
示例10: 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(array.IsArray || array.IsString);
if (index.IsNumeric)
{
index = index.ToInteger();
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;
GCUtils.GCRetain(value, core);
if (he.Dict.TryGetValue(index, out oldValue))
{
GCUtils.GCRelease(oldValue, core);
}
else
{
oldValue = StackValue.Null;
GCUtils.GCRetain(index, core);
}
he.Dict[index] = value;
return oldValue;
}
}
示例11: RemoveKey
public static bool RemoveKey(StackValue array, StackValue key, Core core)
{
Validity.Assert(array.IsArray);
if (!array.IsArray)
{
return false;
}
HeapElement he = GetHeapElement(array, core);
if (key.IsNumeric)
{
long index = key.ToInteger().opdata;
if (index < 0)
{
index = index + he.VisibleSize;
}
if (index >= 0 && index < he.VisibleSize)
{
he.Stack[index] = StackValue.Null;
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;
}
示例12: 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(array.IsArray);
if (!array.IsArray)
{
return false;
}
HeapElement he = GetHeapElement(array, core);
if (key.IsNumeric)
{
long index = key.ToInteger().opdata;
if (index < 0)
{
index = index + he.VisibleSize;
}
return (index >= 0 && index < he.VisibleSize);
}
else
{
return he.Dict != null && he.Dict.ContainsKey(key);
}
}
示例13: GetValueFromIndex
/// <summary>
/// = array[index].
///
/// Note this function doesn't support the replication of array indexing.
/// </summary>
/// <param name="index"></param>
/// <param name="core"></param>
/// <returns></returns>
public StackValue GetValueFromIndex(StackValue index, RuntimeCore runtimeCore)
{
if (index.IsNumeric)
{
index = index.ToInteger();
return GetValueFromIndex((int)index.opdata, runtimeCore);
}
else if (index.IsArrayKey)
{
int fullIndex = (int)index.opdata;
if (VisibleSize > fullIndex)
{
return GetValueFromIndex(fullIndex, runtimeCore);
}
else
{
fullIndex = fullIndex - VisibleSize;
if (Dict != null && Dict.Count > fullIndex)
{
int count = 0;
foreach (var key in Dict.Keys)
{
if (count == fullIndex)
{
return Dict[key];
}
count = count + 1;
}
}
}
return StackValue.Null;
}
else
{
StackValue value = StackValue.Null;
if (Dict.TryGetValue(index, out value))
{
return value;
}
else
{
return StackValue.Null;
}
}
}
示例14: 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, RuntimeCore runtimeCore)
{
if (!array.IsArray)
return StackValue.Null;
if (index.IsNumeric)
{
index = index.ToInteger();
return SetValueForIndex(array, (int)index.opdata, value, runtimeCore);
}
else
{
HeapElement he = GetHeapElement(array, runtimeCore);
if (he.Dict == null)
{
he.Dict = new Dictionary<StackValue, StackValue>(new StackValueComparer(runtimeCore));
}
StackValue oldValue;
if (!he.Dict.TryGetValue(index, out oldValue))
{
oldValue = StackValue.Null;
}
he.Dict[index] = value;
return oldValue;
}
}
示例15: RemoveKey
public static bool RemoveKey(StackValue array, StackValue key, RuntimeCore runtimeCore)
{
if (!array.IsArray)
{
return false;
}
HeapElement he = GetHeapElement(array, runtimeCore);
if (key.IsNumeric)
{
long index = key.ToInteger().opdata;
if (index < 0)
{
index = index + he.VisibleSize;
}
if (index >= 0 && index < he.VisibleSize)
{
he.Stack[index] = StackValue.Null;
if (index == he.VisibleSize - 1)
{
he.VisibleSize -= 1;
}
return true;
}
}
else
{
if (he.Dict != null && he.Dict.ContainsKey(key))
{
he.Dict.Remove(key);
return true;
}
}
return false;
}