本文整理汇总了C#中RuntimeCore类的典型用法代码示例。如果您正苦于以下问题:C# RuntimeCore类的具体用法?C# RuntimeCore怎么用?C# RuntimeCore使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
RuntimeCore类属于命名空间,在下文中一共展示了RuntimeCore类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ConvertToString
public static StackValue ConvertToString(StackValue sv, RuntimeCore runtimeCore, ProtoCore.Runtime.RuntimeMemory rmem)
{
StackValue returnSV;
//TODO: Change Execution mirror class to have static methods, so that an instance does not have to be created
ProtoCore.DSASM.Mirror.ExecutionMirror mirror = new DSASM.Mirror.ExecutionMirror(new ProtoCore.DSASM.Executive(runtimeCore), runtimeCore);
returnSV = ProtoCore.DSASM.StackValue.BuildString(mirror.GetStringValue(sv, runtimeCore.RuntimeMemory.Heap, 0, true), runtimeCore.RuntimeMemory.Heap);
return returnSV;
}
示例2: CompareString
public static int CompareString(StackValue s1, StackValue s2, RuntimeCore runtimeCore)
{
if (!s1.IsString || !s2.IsString)
return Constants.kInvalidIndex;
if (s1.Equals(s2))
return 0;
string str1 = runtimeCore.RuntimeMemory.Heap.ToHeapObject<DSString>(s1).Value;
string str2 = runtimeCore.RuntimeMemory.Heap.ToHeapObject<DSString>(s2).Value;
return string.Compare(str1, str2);
}
示例3: GetUpcastCountTo
/// <summary>
/// Returns the number of upcasts that need to be performed to turn a class into another class in its upcast chain
/// </summary>
/// <param name="from"></param>
/// <param name="to"></param>
/// <param name="core"></param>
/// <returns></returns>
public static int GetUpcastCountTo(ClassNode from, ClassNode to, RuntimeCore runtimeCore)
{
int toID = runtimeCore.DSExecutable.classTable.ClassNodes.IndexOf(to);
List<int> upcastChain = GetClassUpcastChain(from, runtimeCore);
if (!upcastChain.Contains(toID))
return int.MaxValue;
return upcastChain.IndexOf(toID);
}
示例4: GetElementsAtLevel
private static List<ElementAtLevel> GetElementsAtLevel(StackValue argument, int level, List<int> indices, bool recordIndices, RuntimeCore runtimeCore)
{
var array = runtimeCore.Heap.ToHeapObject<DSArray>(argument);
if (array == null)
{
return new List<ElementAtLevel>();
}
int count = array.Values.Count();
if (level == 0)
{
return array.Values.Zip(Enumerable.Range(0, count), (v, i) =>
{
if (recordIndices)
{
var newIndices = new List<int>(indices);
newIndices.Add(i);
return new ElementAtLevel(v, newIndices);
}
else
{
return new ElementAtLevel(v);
}
}).ToList();
}
else
{
return array.Values.Zip(Enumerable.Range(0, count), (v, i) =>
{
if (recordIndices)
{
var newIndices = new List<int>(indices);
newIndices.Add(i);
return GetElementsAtLevel(v, level - 1, newIndices, recordIndices, runtimeCore);
}
else
{
return GetElementsAtLevel(v, level - 1, new List<int>(), recordIndices, runtimeCore);
}
}).SelectMany(vs => vs).ToList();
}
}
示例5: GetClassUpcastChain
/// <summary>
/// Returns the list of classes that this can be upcast to
/// It includes the class itself
/// </summary>
/// <param name="cn"></param>
/// <param name="core"></param>
/// <returns></returns>
public static List<int> GetClassUpcastChain(ClassNode cn, RuntimeCore runtimeCore)
{
List<int> ret = new List<int>();
//@TODO: Replace this with an ID
ret.Add(runtimeCore.DSExecutable.classTable.ClassNodes.IndexOf(cn));
ClassNode target = cn;
while (target.Base != Constants.kInvalidIndex)
{
ret.Add(target.Base);
target = runtimeCore.DSExecutable.classTable.ClassNodes[target.Base];
}
if (!ret.Contains((int)(PrimitiveType.Var)))
ret.Add((int)PrimitiveType.Var);
return ret;
}
示例6: GetClassUpcastChain
/// <summary>
/// Returns the list of classes that this can be upcast to
/// It includes the class itself
/// </summary>
/// <param name="cn"></param>
/// <param name="core"></param>
/// <returns></returns>
public static List<int> GetClassUpcastChain(ClassNode cn, RuntimeCore runtimeCore)
{
List<int> ret = new List<int>();
//@TODO: Replace this with an ID
ret.Add(runtimeCore.DSExecutable.classTable.ClassNodes.IndexOf(cn));
ClassNode target = cn;
while (target.Bases.Count > 0)
{
Validity.Assert(target.Bases.Count == 1, "Multiple Inheritence not yet supported, {F5DDC58D-F721-4319-854A-622175AC43F8}");
ret.Add(target.Bases[0]);
target = runtimeCore.DSExecutable.classTable.ClassNodes[target.Bases[0]];
}
if (!ret.Contains((int)(PrimitiveType.Var)))
ret.Add((int)PrimitiveType.Var);
return ret;
}
示例7: Executive
public Executive(RuntimeCore runtimeCore, bool isFep = false)
{
IsExplicitCall = false;
Validity.Assert(runtimeCore != null);
this.runtimeCore = runtimeCore;
enableLogging = runtimeCore.Options.Verbose;
exe = runtimeCore.DSExecutable;
istream = null;
fepRun = isFep;
Properties = new InterpreterProperties();
rmem = runtimeCore.RuntimeMemory;
// Execute DS View VM Log
//
debugFlags = (int)DebugFlags.ENABLE_LOG;
bounceType = CallingConvention.BounceType.Implicit;
deferedGraphNodes = new List<AssociativeGraph.GraphNode>();
}
示例8: RecursiveProtectGetMaxReductionDepth
/// <summary>
/// This computes the max depth to which the element can be reduced
/// It contains a protected envelope
/// </summary>
/// <param name="sv"></param>
/// <param name="core"></param>
/// <param name="depthCount"></param>
/// <returns></returns>
private static int RecursiveProtectGetMaxReductionDepth(StackValue sv, RuntimeCore runtimeCore, int depthCount)
{
Validity.Assert(depthCount < 1000,
"StackOverflow protection trap. This is almost certainly a VM cycle-in-array bug. {0B530165-2E38-431D-88D9-56B0636364CD}");
//PERF(Luke): Could be non-recursive
if (!sv.IsArray)
return 0;
int maxReduction = 0;
//De-ref the sv
var array = runtimeCore.Heap.ToHeapObject<DSArray>(sv);
foreach (var subSv in array.VisibleItems)
{
maxReduction = Math.Max(maxReduction, RecursiveProtectGetMaxReductionDepth(subSv, runtimeCore, depthCount + 1));
}
return 1 + maxReduction;
}
示例9: BuildReplicationCombinations
public static List<List<ReplicationInstruction>> BuildReplicationCombinations(List<ReplicationInstruction> providedControl, List<StackValue> formalParams, RuntimeCore runtimeCore)
{
//@TODO: Performance hint - this should really be done with a yield-generator unless the parrallelism is useful
//@ROSO: This is not generating a minimal set
//First build a list of reducible parameters
List<int> reducibles = new List<int>();
int maxDepth = 0;
for (int i = 0; i < formalParams.Count; i++)
{
int itemMaxDepth = GetMaxReductionDepth(formalParams[i], runtimeCore);
if (itemMaxDepth > 0)
reducibles.Add(i);
maxDepth = maxDepth + itemMaxDepth;
}
if (providedControl.Count > maxDepth)
{
throw new ReplicationCaseNotCurrentlySupported(
string.Format(Resources.MaxDimensionExceeded, "{1EC8AF3C-48D6-4582-999E-ADBCBF9155D1}"));
}
else
{
//Reduce the available reducions by the amount that we've been instructed to
maxDepth -= providedControl.Count;
}
List<List<int>> cleanedReductions = new List<List<int>>();
if (maxDepth > 0)
{
List<List<int>> reductions = new List<List<int>>();
for (int i = 0; i <= maxDepth; i++)
reductions.AddRange(BuildAllocation(formalParams.Count, maxDepth));
if (providedControl.Count > 0)
{
//The add in the reductions associated with the provided controls.
//The silly copy-ctoring here is to avoid the issues of modifying a collection with an iterator on it
List<List<int>> completedReductions = new List<List<int>>();
List<ReplicationInstruction> reversedControl = new List<ReplicationInstruction>();
reversedControl.AddRange(providedControl);
reversedControl.Reverse();
foreach (List<int> reduction in reductions)
{
List<int> reducitonList = new List<int>();
reducitonList.AddRange(reduction);
foreach (ReplicationInstruction ri in reversedControl)
{
if (!ri.Zipped)
reducitonList[ri.CartesianIndex] = reducitonList[ri.CartesianIndex] + 1;
else
{
foreach (int i in ri.ZipIndecies)
reducitonList[i] = reducitonList[i] + 1;
}
}
completedReductions.Add(reducitonList);
}
reductions = completedReductions;
}
foreach (List<int> list in reductions)
{
bool append = true;
for (int i = 0; i < list.Count; i++)
if (list[i] > GetMaxReductionDepth(formalParams[i], runtimeCore))
{
append = false;
break;
}
int acc = 0;
for (int i = 0; i < list.Count; i++)
acc += list[i];
//We must be reducing something
if (acc == 0)
append = false;
//.........这里部分代码省略.........
示例10: ComputeReducedParamsSuperset
public static List<List<StackValue>> ComputeReducedParamsSuperset(List<StackValue> formalParams, List<ReplicationInstruction> replicationInstructions, RuntimeCore runtimeCore)
{
//Compute the reduced Type args
List<List<StackValue>> reducedParams = new List<List<StackValue>>();
List<StackValue> basicList = new List<StackValue>();
//Copy the types so unaffected ones get copied back directly
foreach (StackValue sv in formalParams)
basicList.Add(sv);
reducedParams.Add(basicList);
foreach (ReplicationInstruction ri in replicationInstructions)
if (ri.Zipped)
{
foreach (int index in ri.ZipIndecies)
{
//This should generally be a collection, so we need to do a one phase unboxing
StackValue target = basicList[index];
StackValue reducedSV = StackValue.Null;
if (target.IsArray)
{
//Array arr = formalParams[index].Payload as Array;
var array = runtimeCore.Heap.ToHeapObject<DSArray>(basicList[index]);
//The elements of the array are still type structures
if (array.VisibleSize == 0)
reducedSV = StackValue.Null;
else
{
var arrayStats = ArrayUtils.GetTypeExamplesForLayer(basicList[index], runtimeCore).Values;
List<List<StackValue>> clonedList = new List<List<StackValue>>();
foreach (List<StackValue> list in reducedParams)
clonedList.Add(list);
reducedParams.Clear();
foreach (StackValue sv in arrayStats)
{
foreach (List<StackValue> lst in clonedList)
{
List<StackValue> newArgs = new List<StackValue>();
newArgs.AddRange(lst);
newArgs[index] = sv;
reducedParams.Add(newArgs);
}
}
}
}
else
{
System.Console.WriteLine("WARNING: Replication unbox requested on Singleton. Trap: 437AD20D-9422-40A3-BFFD-DA4BAD7F3E5F");
reducedSV = target;
}
//reducedType.IsIndexable = false;
//reducedParamTypes[index] = reducedSV;
}
}
else
{
//This should generally be a collection, so we need to do a one phase unboxing
int index = ri.CartesianIndex;
//This should generally be a collection, so we need to do a one phase unboxing
StackValue target = basicList[index];
StackValue reducedSV = StackValue.Null;
if (target.IsArray)
{
//Array arr = formalParams[index].Payload as Array;
var array = runtimeCore.Heap.ToHeapObject<DSArray>(basicList[index]);
//It is a collection, so cast it to an array and pull the type of the first element
//@TODO(luke): Deal with sparse arrays, if the first element is null this will explode
//The elements of the array are still type structures
if (array.VisibleSize == 0)
reducedSV = StackValue.Null;
else
{
var arrayStats = ArrayUtils.GetTypeExamplesForLayer(basicList[index], runtimeCore).Values;
List<List<StackValue>> clonedList = new List<List<StackValue>>();
foreach (List<StackValue> list in reducedParams)
clonedList.Add(list);
//.........这里部分代码省略.........
示例11: AddStackValueString
/// <summary>
/// Performs addition on 2 StackValues
/// This is used by the VM when adding strings
/// </summary>
/// <param name="sv1"></param>
/// <param name="sv2"></param>
/// <returns></returns>
public static StackValue AddStackValueString(StackValue sv1, StackValue sv2, RuntimeCore runtimeCore)
{
Validity.Assert(sv1.IsString || sv2.IsString);
if (sv1.IsString && sv2.IsString)
{
return StringUtils.ConcatString(sv2, sv1, runtimeCore);
}
else if (sv1.IsString || sv2.IsString)
{
StackValue newSV;
if (sv1.IsNull || sv2.IsNull)
{
return StackValue.BuildNull();
}
else if (sv1.IsString)
{
newSV = StringUtils.ConvertToString(sv2, runtimeCore, runtimeCore.RuntimeMemory);
return StringUtils.ConcatString(newSV, sv1, runtimeCore);
}
else if (sv2.IsString)
{
newSV = StringUtils.ConvertToString(sv1, runtimeCore, runtimeCore.RuntimeMemory);
return StringUtils.ConcatString(sv2, newSV, runtimeCore);
}
}
return StackValue.BuildNull();
}
示例12: GetTypeStatisticsForArray
/// <summary>
/// Generate type statistics for the whole array
/// </summary>
/// <param name="array"></param>
/// <param name="core"></param>
/// <returns></returns>
public static Dictionary<ClassNode, int> GetTypeStatisticsForArray(StackValue array, RuntimeCore runtimeCore)
{
if (!array.IsArray)
{
Dictionary<ClassNode, int> ret = new Dictionary<ClassNode, int>();
ret.Add(runtimeCore.DSExecutable.classTable.ClassNodes[array.metaData.type], 1);
return ret;
}
Dictionary<ClassNode, int> usageFreq = new Dictionary<ClassNode, int>();
//This is the element on the heap that manages the data structure
var dsArray = runtimeCore.Heap.ToHeapObject<DSArray>(array);
foreach (var sv in dsArray.Values)
{
if (sv.IsArray)
{
//Recurse
Dictionary<ClassNode, int> subLayer = GetTypeStatisticsForArray(sv, runtimeCore);
foreach (ClassNode cn in subLayer.Keys)
{
if (!usageFreq.ContainsKey(cn))
usageFreq.Add(cn, 0);
usageFreq[cn] = usageFreq[cn] + subLayer[cn];
}
}
else
{
ClassNode cn = runtimeCore.DSExecutable.classTable.ClassNodes[sv.metaData.type];
if (!usageFreq.ContainsKey(cn))
usageFreq.Add(cn, 0);
usageFreq[cn] = usageFreq[cn] + 1;
}
}
return usageFreq;
}
示例13: GetGreatestCommonSubclassForArray
/// <summary>
/// If an empty array is passed, the result will be null
/// if there are instances, but they share no common supertype the result will be var
/// </summary>
/// <param name="array"></param>
/// <param name="core"></param>
/// <returns></returns>
public static ClassNode GetGreatestCommonSubclassForArray(StackValue array, RuntimeCore runtimeCore)
{
if (!array.IsArray)
throw new ArgumentException("The stack value provided was not an array");
Dictionary<ClassNode, int> typeStats = GetTypeStatisticsForArray(array, runtimeCore);
//@PERF: This could be improved with a
List<List<int>> chains = new List<List<int>>();
HashSet<int> commonTypeIDs = new HashSet<int>();
foreach (ClassNode cn in typeStats.Keys)
{
List<int> chain = ClassUtils.GetClassUpcastChain(cn, runtimeCore);
//Now add in the other conversions - as we don't have a common superclass yet
//@TODO(Jun): Remove this hack when we have a proper casting structure
foreach (int id in cn.CoerceTypes.Keys)
if (!chain.Contains(id))
chain.Add((id));
chains.Add(chain);
foreach (int nodeId in chain)
commonTypeIDs.Add(nodeId);
}
//Remove nulls if they exist
{
if (commonTypeIDs.Contains(
(int)PrimitiveType.kTypeNull))
commonTypeIDs.Remove((int)PrimitiveType.kTypeNull);
List<List<int>> nonNullChains = new List<List<int>>();
foreach (List<int> chain in chains)
{
if (chain.Contains((int)PrimitiveType.kTypeNull))
chain.Remove((int)PrimitiveType.kTypeNull);
if (chain.Count > 0)
nonNullChains.Add(chain);
}
chains = nonNullChains;
}
//Contract the hashset so that it contains only the nodes present in all chains
//@PERF: this is very inefficent
{
foreach (List<int> chain in chains)
{
commonTypeIDs.IntersectWith(chain);
}
}
//No common subtypes
if (commonTypeIDs.Count == 0)
return null;
if (commonTypeIDs.Count == 1)
return runtimeCore.DSExecutable.classTable.ClassNodes[commonTypeIDs.First()];
List<int> lookupChain = chains[0];
//Insertion sort the IDs, we may only have a partial ordering on them.
List<int> orderedTypes = new List<int>();
foreach (int typeToInsert in commonTypeIDs)
{
bool inserted = false;
for (int i = 0; i < orderedTypes.Count; i++)
{
int orderedType = orderedTypes[i];
if (lookupChain.IndexOf(typeToInsert) < lookupChain.IndexOf(orderedType))
{
inserted = true;
orderedTypes.Insert(i, typeToInsert);
break;
}
//.........这里部分代码省略.........
示例14: GetTypeExamplesForLayer
public static Dictionary<int, StackValue> GetTypeExamplesForLayer(StackValue array, RuntimeCore runtimeCore)
{
if (!array.IsArray)
{
Dictionary<int, StackValue> ret = new Dictionary<int, StackValue>();
ret.Add(array.metaData.type, array);
return ret;
}
Dictionary<int, StackValue> usageFreq = new Dictionary<int, StackValue>();
//This is the element on the heap that manages the data structure
var dsArray = runtimeCore.Heap.ToHeapObject<DSArray>(array);
foreach (var sv in dsArray.Values)
{
if (!usageFreq.ContainsKey(sv.metaData.type))
usageFreq.Add(sv.metaData.type, sv);
}
return usageFreq;
}
示例15: GetConversionChain
/// <summary>
/// For a class node using single inheritence, get the chain of inheritences
/// </summary>
/// <param name="cn"></param>
/// <param name="core"></param>
/// <returns></returns>
public static List<int> GetConversionChain(ClassNode cn, RuntimeCore runtimeCore)
{
List<int> ret = new List<int>();
/*
//@TODO: Replace this with an ID
ret.Add(core.classTable.list.IndexOf(cn));
ClassNode target = cn;
while (target.baseList.Count > 0)
{
Validity.Assert(target.baseList.Count == 1, "Multiple Inheritence not yet supported, {F5DDC58D-F721-4319-854A-622175AC43F8}");
ret.Add(cn.baseList[0]);
target = core.classTable.list[cn.baseList[0]];
}
*/
List<int> coercableTypes = new List<int>();
foreach (int typeID in cn.CoerceTypes.Keys)
{
bool inserted = false;
for (int i = 0; i < coercableTypes.Count; i++)
{
if (cn.CoerceTypes[typeID] < cn.CoerceTypes[coercableTypes[i]])
{
inserted = true;
coercableTypes.Insert(typeID, i);
break;
}
}
if (!inserted)
coercableTypes.Add(typeID);
}
coercableTypes.Add(runtimeCore.DSExecutable.classTable.ClassNodes.IndexOf(cn));
ret.AddRange(coercableTypes);
return ret;
}