本文整理汇总了C#中ProtoCore.Lang.Obj类的典型用法代码示例。如果您正苦于以下问题:C# Obj类的具体用法?C# Obj怎么用?C# Obj使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Obj类属于ProtoCore.Lang命名空间,在下文中一共展示了Obj类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: UnpackToList
private List<Obj> UnpackToList(ExecutionMirror mirror, Obj obj)
{
if (obj == null || !obj.DsasmValue.IsArray)
return null;
return mirror.MirrorTarget.rmem.Heap.ToHeapObject<DSArray>(obj.DsasmValue).Values.Select(x => mirror.Unpack(x)).ToList();
}
示例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;
}
示例3: GetArrayElements
// traverse an array Obj return its member
public List<Obj> GetArrayElements(Obj obj)
{
if ( obj == null || !obj.DsasmValue.IsArray)
return null;
return core.Heap.GetHeapElement(obj.DsasmValue).Stack.Select(x => Unpack(x)).ToList();
}
示例4: GetWatchValue
public Obj GetWatchValue()
{
int count = MirrorTarget.Core.watchStack.Count;
int n = MirrorTarget.Core.watchSymbolList.FindIndex(x => { return string.Equals(x.name, Constants.kWatchResultVar); });
if (n < 0 || n >= count)
{
core.watchSymbolList.Clear();
return new Obj { Payload = null };
}
Obj retVal = null;
try
{
StackValue sv = MirrorTarget.Core.watchStack[n];
if (sv.optype != AddressType.Invalid)
{
retVal = Unpack(MirrorTarget.Core.watchStack[n], MirrorTarget.rmem.Heap, core);
}
else
{
retVal = new Obj { Payload = null };
}
}
catch
{
retVal = new Obj { Payload = null };
}
finally
{
core.watchSymbolList.Clear();
}
return retVal;
}
示例5: GetProperties
// traverse an class type object to get its property
public Dictionary<string, Obj> GetProperties(Obj obj, bool excludeStatic = false)
{
if (obj == null || obj.DsasmValue.optype != AddressType.Pointer)
return null;
Dictionary<string, Obj> ret = new Dictionary<string, Obj>();
int classIndex = (int)obj.DsasmValue.metaData.type;
Dictionary<int,SymbolNode> symbolList = core.ClassTable.ClassNodes[classIndex].symbols.symbolList;
StackValue[] svs = core.Heap.Heaplist[(int)obj.DsasmValue.opdata].Stack;
int index = 0;
for (int ix = 0; ix < svs.Length; ++ix)
{
if (excludeStatic && symbolList[ix].isStatic)
continue;
string name = symbolList[ix].name;
StackValue val = svs[index];
// check if the members are primitive type
if (val.optype == AddressType.Pointer &&
core.Heap.Heaplist[(int)val.opdata].Stack.Length == 1 &&
core.Heap.Heaplist[(int)val.opdata].Stack[0].optype != AddressType.Pointer &&
core.Heap.Heaplist[(int)val.opdata].Stack[0].optype != AddressType.ArrayPointer)
val = core.Heap.Heaplist[(int)val.opdata].Stack[0];
ret[name] = Unpack(val);
index++;
}
return ret;
}
示例6: GetArrayElementCount
public int GetArrayElementCount(Obj obj)
{
if (obj == null || obj.DsasmValue.optype != AddressType.ArrayPointer)
return 0;
return core.Heap.Heaplist[(int)obj.DsasmValue.opdata].VisibleSize;
}
示例7: Unpack
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()));
}
}
}
示例8: GetStringValue
// TODO: Implement this to recurse through expressions in watch window and running expression interpreter for each of their sub-types - pratapa
internal static void GetStringValue(Obj obj, ProtoCore.DSASM.Mirror.ExecutionMirror mirror)
{
switch (obj.DsasmValue.optype)
{
case AddressType.ArrayPointer:
{
List<Obj> ol = mirror.GetArrayElements(obj);
foreach (Obj o in ol)
{
GetStringValue(o, mirror);
}
return;
}
case AddressType.Pointer:
{
Dictionary<string, Obj> os = mirror.GetProperties(obj);
for (int i = 0; i < os.Count; ++i)
{
}
return;
}
default:
return;
}
}
示例9: GetPropertyNames
public List<string> GetPropertyNames(Obj obj)
{
if (obj == null || !obj.DsasmValue.IsPointer)
return null;
List<string> ret = new List<string>();
int classIndex = obj.DsasmValue.metaData.type;
StackValue[] svs = MirrorTarget.rmem.Heap.ToHeapObject<DSObject>(obj.DsasmValue).VisibleItems.ToArray();
for (int ix = 0; ix < svs.Length; ++ix)
{
string propertyName = runtimeCore.DSExecutable.classTable.ClassNodes[classIndex].symbols.symbolList[ix].name;
ret.Add(propertyName);
}
return ret;
}
示例10: Unpack
// this method is used for the IDE to query object values
// Copy from the the existing Unpack with some modifications
// 1: It is a non-static method so there is no need to pass the core and heap
// 2: It does not traverse the array, array traverse is done in method GetArrayElement
// 3: The payload for boolean and null is changed to Boolean and null type in .NET, such that the watch windows can directly call ToString()
// to print the value, otherwize for boolean it will print either 0 or 1, for null it will print 0
public Obj Unpack(StackValue val)
{
Obj obj = null;
switch (val.optype)
{
case AddressType.Pointer:
obj = new Obj(val)
{
Payload = val.Pointer,
Type = TypeSystem.BuildPrimitiveTypeObject(PrimitiveType.Pointer, 0)
};
break;
case AddressType.ArrayPointer:
obj = new Obj(val)
{
Payload = val.ArrayPointer,
Type =
TypeSystem.BuildPrimitiveTypeObject(PrimitiveType.Array, Constants.kArbitraryRank)
};
break;
case AddressType.Int:
obj = new Obj(val)
{
Payload = val.IntegerValue,
Type = TypeSystem.BuildPrimitiveTypeObject(PrimitiveType.Integer, 0)
};
break;
case AddressType.Boolean:
obj = new Obj(val)
{
Payload = val.BooleanValue,
Type = TypeSystem.BuildPrimitiveTypeObject(PrimitiveType.Bool, 0)
};
break;
case AddressType.Double:
obj = new Obj(val)
{
Payload = val.DoubleValue,
Type = TypeSystem.BuildPrimitiveTypeObject(PrimitiveType.Double, 0)
};
break;
case AddressType.Null:
obj = new Obj(val)
{
Payload = null,
Type = TypeSystem.BuildPrimitiveTypeObject(PrimitiveType.Null, 0)
};
break;
case AddressType.FunctionPointer:
obj = new Obj(val)
{
Payload = val.FunctionPointer,
Type = TypeSystem.BuildPrimitiveTypeObject(PrimitiveType.FunctionPointer, 0)
};
break;
case AddressType.String:
obj = new Obj(val)
{
Payload = val.StringPointer,
Type = TypeSystem.BuildPrimitiveTypeObject(PrimitiveType.String, Constants.kPrimitiveSize)
};
break;
case AddressType.Char:
obj = new Obj(val)
{
Payload = val.CharValue,
Type = TypeSystem.BuildPrimitiveTypeObject(PrimitiveType.Char, 0)
};
break;
}
return obj;
}
示例11: GetArrayElements
//
// TODO Jun: Integrate this helper function into the reflection system
private List<Obj> GetArrayElements(ProtoCore.Mirror.RuntimeMirror mirror, StackValue svArrayPointer)
{
Assert.IsTrue(svArrayPointer.optype == ProtoCore.DSASM.AddressType.ArrayPointer);
Obj array = new Obj(svArrayPointer);
return mirror.GetUtils().GetArrayElements(array);
}
示例12: GetPropertyNames
public List<string> GetPropertyNames(Obj obj)
{
if (obj == null || !obj.DsasmValue.IsPointer)
return null;
List<string> ret = new List<string>();
int classIndex = obj.DsasmValue.metaData.type;
StackValue[] svs = core.Heap.GetHeapElement(obj.DsasmValue).Stack;
for (int ix = 0; ix < svs.Length; ++ix)
{
string propertyName = core.ClassTable.ClassNodes[classIndex].symbols.symbolList[ix].name;
ret.Add(propertyName);
}
return ret;
}
示例13: GetProperties
// traverse an class type object to get its property
public Dictionary<string, Obj> GetProperties(Obj obj, bool excludeStatic = false)
{
if (obj == null || !obj.DsasmValue.IsPointer)
return null;
Dictionary<string, Obj> ret = new Dictionary<string, Obj>();
int classIndex = obj.DsasmValue.metaData.type;
IDictionary<int,SymbolNode> symbolList = core.ClassTable.ClassNodes[classIndex].symbols.symbolList;
StackValue[] svs = core.Heap.GetHeapElement(obj.DsasmValue).Stack;
int index = 0;
for (int ix = 0; ix < svs.Length; ++ix)
{
if (excludeStatic && symbolList[ix].isStatic)
continue;
string name = symbolList[ix].name;
StackValue val = svs[index];
// check if the members are primitive type
if (val.IsPointer)
{
var heapElement = core.Heap.GetHeapElement(val);
if (heapElement.Stack.Length == 1 &&
!heapElement.Stack[0].IsPointer &&
!heapElement.Stack[0].IsArray)
{
val = heapElement.Stack[0];
}
}
ret[name] = Unpack(val);
index++;
}
return ret;
}
示例14: Unpack
// this method is used for the IDE to query object values
// Copy from the the existing Unpack with some modifications
// 1: It is a non-static method so there is no need to pass the core and heap
// 2: It does not traverse the array, array traverse is done in method GetArrayElement
// 3: The payload for boolean and null is changed to Boolean and null type in .NET, such that the watch windows can directly call ToString()
// to print the value, otherwize for boolean it will print either 0 or 1, for null it will print 0
public Obj Unpack(StackValue val)
{
Obj obj = null;
switch (val.optype)
{
case AddressType.Pointer:
obj = new Obj(val)
{
Payload = val.Pointer,
};
break;
case AddressType.ArrayPointer:
obj = new Obj(val)
{
Payload = val.ArrayPointer,
};
break;
case AddressType.Int:
obj = new Obj(val)
{
Payload = val.IntegerValue,
};
break;
case AddressType.Boolean:
obj = new Obj(val)
{
Payload = val.BooleanValue,
};
break;
case AddressType.Double:
obj = new Obj(val)
{
Payload = val.DoubleValue,
};
break;
case AddressType.Null:
obj = new Obj(val)
{
Payload = null,
};
break;
case AddressType.FunctionPointer:
obj = new Obj(val)
{
Payload = val.FunctionPointer,
};
break;
case AddressType.String:
obj = new Obj(val)
{
Payload = val.StringPointer,
};
break;
case AddressType.Char:
obj = new Obj(val)
{
Payload = val.CharValue,
};
break;
}
return obj;
}
示例15: 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, 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;
//.........这里部分代码省略.........