本文整理汇总了C#中RakudoObject类的典型用法代码示例。如果您正苦于以下问题:C# RakudoObject类的具体用法?C# RakudoObject怎么用?C# RakudoObject使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
RakudoObject类属于命名空间,在下文中一共展示了RakudoObject类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: instance_of
/// <summary>
/// Create an instance of the given object.
/// </summary>
/// <param name="WHAT"></param>
/// <returns></returns>
public override RakudoObject instance_of(ThreadContext TC, RakudoObject WHAT)
{
var Object = new KnowHOWInstance(WHAT.STable);
Object.Methods = new Dictionary<string, RakudoObject>();
Object.Attributes = new List<RakudoObject>();
return Object;
}
示例2: bind_attribute
/// <summary>
///
/// </summary>
/// <param name="Object"></param>
/// <param name="ClassHandle"></param>
/// <param name="Name"></param>
/// <param name="Value"></param>
public override void bind_attribute(ThreadContext TC, RakudoObject Object, RakudoObject ClassHandle, string Name, RakudoObject Value)
{
var I = (Instance)Object;
// Try the slot allocation first.
Dictionary<string, int> ClassAllocation;
int Position;
if (SlotAllocation != null && SlotAllocation.TryGetValue(ClassHandle, out ClassAllocation))
if (ClassAllocation.TryGetValue(Name, out Position))
{
I.SlotStorage[Position] = Value;
return;
}
// Fall back to the spill storage.
if (I.SpillStorage == null)
I.SpillStorage = new Dictionary<RakudoObject, Dictionary<string, RakudoObject>>();
if (!I.SpillStorage.ContainsKey(ClassHandle))
I.SpillStorage.Add(ClassHandle, new Dictionary<string, RakudoObject>());
var ClassStore = I.SpillStorage[ClassHandle];
if (ClassStore.ContainsKey(Name))
ClassStore[Name] = Value;
else
ClassStore.Add(Name, Value);
}
示例3: get_attribute
/// <summary>
/// Gets the attribute with the given value.
/// </summary>
/// <param name="ClassHandle"></param>
/// <param name="Name"></param>
/// <returns></returns>
public override RakudoObject get_attribute(ThreadContext TC, RakudoObject Object, RakudoObject ClassHandle, string Name)
{
// If no storage ever allocated, trivially no value. Otherwise,
// return what we find.
var I = (Instance)Object;
if (I.Storage == null || !I.Storage.ContainsKey(ClassHandle))
return null;
var ClassStore = I.Storage[ClassHandle];
return ClassStore.ContainsKey(Name) ? ClassStore[Name] : null;
}
示例4: bind_attribute
/// <summary>
/// Binds an attribute to the given value.
/// </summary>
/// <param name="Object"></param>
/// <param name="ClassHandle"></param>
/// <param name="Name"></param>
/// <param name="Value"></param>
public override void bind_attribute(ThreadContext TC, RakudoObject Object, RakudoObject ClassHandle, string Name, RakudoObject Value)
{
// If no storage at all, allocate some.
var I = (Instance)Object;
if (I.Storage == null)
I.Storage = new Dictionary<RakudoObject, Dictionary<string, RakudoObject>>();
if (!I.Storage.ContainsKey(ClassHandle))
I.Storage.Add(ClassHandle, new Dictionary<string, RakudoObject>());
// Now stick in the name slot for the class storage, creating if it
// needed.
var ClassStore = I.Storage[ClassHandle];
if (ClassStore.ContainsKey(Name))
ClassStore[Name] = Value;
else
ClassStore.Add(Name, Value);
}
示例5: bind_attribute_with_hint
/// <summary>
/// Bind the attribute, using the hint if possible.
/// </summary>
/// <param name="Object"></param>
/// <param name="ClassHandle"></param>
/// <param name="Name"></param>
/// <param name="Hint"></param>
/// <param name="Value"></param>
public override void bind_attribute_with_hint(ThreadContext TC, RakudoObject Object, RakudoObject ClassHandle, string Name, int Hint, RakudoObject Value)
{
var I = (Instance)Object;
if (Hint < I.SlotStorage.Length)
{
I.SlotStorage[Hint] = Value;
}
else if ((Hint = hint_for(TC, ClassHandle, Name)) != Hints.NO_HINT && Hint < I.SlotStorage.Length)
{
I.SlotStorage[Hint] = Value;
}
else
{
if (I.SpillStorage == null)
I.SpillStorage = new Dictionary<RakudoObject, Dictionary<string, RakudoObject>>();
if (!I.SpillStorage.ContainsKey(ClassHandle))
I.SpillStorage.Add(ClassHandle, new Dictionary<string, RakudoObject>());
var ClassStore = I.SpillStorage[ClassHandle];
if (ClassStore.ContainsKey(Name))
ClassStore[Name] = Value;
else
ClassStore.Add(Name, Value);
}
}
示例6: get_attribute_with_hint
public override RakudoObject get_attribute_with_hint(ThreadContext TC, RakudoObject Object, RakudoObject ClassHandle, string Name, int Hint)
{
throw new InvalidOperationException("Native captures cannot store additional attributes.");
}
示例7: defined
/// <summary>
/// Determines if the representation is defined or not.
/// </summary>
/// <param name="Obj"></param>
/// <returns></returns>
public override bool defined(ThreadContext TC, RakudoObject O)
{
var Obj = (Instance)O;
return Obj.Positionals != null || Obj.Nameds != null;
}
示例8: get_num
public override double get_num(ThreadContext TC, RakudoObject Object)
{
throw new NotImplementedException();
}
示例9: defined
/// <summary>
/// Checks if the object is defined, which boils down to "is
/// this a type object", which in trun means "did we allocate
/// any storage".
/// </summary>
/// <param name="Object"></param>
/// <returns></returns>
public override bool defined(ThreadContext TC, RakudoObject Object)
{
return ((Instance)Object).Storage != null;
}
示例10: set_str
public override void set_str(ThreadContext TC, RakudoObject Object, string Value)
{
throw new InvalidOperationException("This type of representation cannot box a native string");
}
示例11: instance_of
/// <summary>
/// Allocates and returns a new object based upon the type object
/// supplied.
/// </summary>
/// <param name="HOW"></param>
/// <returns></returns>
public override RakudoObject instance_of(ThreadContext TC, RakudoObject WHAT)
{
var Object = new Instance(WHAT.STable);
Object.Storage = new Dictionary<RakudoObject, Dictionary<string, RakudoObject>>();
return Object;
}
示例12: bind_attribute_with_hint
public override void bind_attribute_with_hint(ThreadContext TC, RakudoObject Object, RakudoObject ClassHandle, string Name, int Hint, RakudoObject Value)
{
throw new InvalidOperationException("Boxed native types cannot store additional attributes.");
}
示例13: SetupKnowHOWAttribute
/// <summary>
/// Sets up the KnowHOWAttribute object/class, which actually is a
/// KnowHOW.
/// </summary>
/// <returns></returns>
public static RakudoObject SetupKnowHOWAttribute(RakudoObject KnowHOW)
{
// Create a new HOW instance.
var HOW = KnowHOW.STable.REPR.instance_of(null, KnowHOW) as KnowHOWREPR.KnowHOWInstance;
// We base the attribute on P6str, since we just want to store an
// attribute name for now.
var KnowHOWAttribute = REPRRegistry.get_REPR_by_name("P6str").type_object_for(null, HOW);
// Add methods new and Str.
HOW.Methods.Add("new", CodeObjectUtility.WrapNativeMethod((TC, Code, Cap) =>
{
var WHAT = CaptureHelper.GetPositional(Cap, 0).STable.WHAT;
var Name = Ops.unbox_str(TC, CaptureHelper.GetNamed(Cap, "name"));
return Ops.box_str(TC, Name, WHAT);
}));
HOW.Methods.Add("name", CodeObjectUtility.WrapNativeMethod((TC, Code, Cap) =>
{
var self = CaptureHelper.GetPositional(Cap, 0);
return Ops.box_str(TC, Ops.unbox_str(TC, self), TC.DefaultStrBoxType);
}));
return KnowHOWAttribute;
}
示例14: set_str
public override void set_str(ThreadContext TC, RakudoObject Object, string Value)
{
throw new NotImplementedException();
}
示例15: set_num
public override void set_num(ThreadContext TC, RakudoObject Object, double Value)
{
throw new NotImplementedException();
}