本文整理汇总了C#中Rakudo.Runtime.ThreadContext类的典型用法代码示例。如果您正苦于以下问题:C# ThreadContext类的具体用法?C# ThreadContext怎么用?C# ThreadContext使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ThreadContext类属于Rakudo.Runtime命名空间,在下文中一共展示了ThreadContext类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: lllist_bind_at_pos
/// <summary>
/// Binds a value at a given positional index from a low level list
/// (something that uses the P6list representation).
/// </summary>
/// <param name="TC"></param>
/// <param name="LLList"></param>
/// <param name="Index"></param>
/// <returns></returns>
public static RakudoObject lllist_bind_at_pos(ThreadContext TC, RakudoObject LLList, RakudoObject IndexObj, RakudoObject Value)
{
if (LLList is P6list.Instance)
{
var Storage = ((P6list.Instance)LLList).Storage;
var Index = Ops.unbox_int(TC, IndexObj);
if (Index < Storage.Count)
{
Storage[Index] = Value;
}
else
{
// XXX Need some more efficient resizable array approach...
// Also this is no way thread safe.
while (Index > Storage.Count)
Storage.Add(null);
Storage.Add(Value);
}
return Value;
}
else
{
throw new Exception("Cannot use lllist_bind_at_pos if representation is not P6list");
}
}
示例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: create_dispatch_and_add_candidates
/// <summary>
/// Creates an instantiation of the dispatch routine (or proto, which may
/// serve as one) supplied and augments it with the provided candidates.
/// It relies on being passed the instantiation of the dispatcher from the
/// last outer scope that had an instantiation, and we thus take its
/// candidates. This may or may not hold up in the long run; it works out
/// in the Perl 6-y "you can make a new instance from any object" sense
/// though, and seems more likely to get the closure semantics right than
/// any of the other approaches I've considered so far.
/// </summary>
/// <param name="TC"></param>
/// <param name="ToInstantiate"></param>
/// <param name="ExtraDispatchees"></param>
/// <returns></returns>
public static RakudoObject create_dispatch_and_add_candidates(ThreadContext TC, RakudoObject ToInstantiate, RakudoObject ExtraDispatchees)
{
// Make sure we got the right things.
var Source = ToInstantiate as RakudoCodeRef.Instance;
var AdditionalDispatchList = ExtraDispatchees as P6list.Instance;
if (Source == null || AdditionalDispatchList == null)
throw new Exception("create_dispatch_and_add_candidates expects a RakudoCodeRef and a P6list");
// Clone all but SC (since it's a new object and doesn't live in any
// SC yet) and dispatchees (which we want to munge).
var NewDispatch = new RakudoCodeRef.Instance(Source.STable);
NewDispatch.Body = Source.Body;
NewDispatch.CurrentContext = Source.CurrentContext;
NewDispatch.Handlers = Source.Handlers;
NewDispatch.OuterBlock = Source.OuterBlock;
NewDispatch.OuterForNextInvocation = Source.OuterForNextInvocation;
NewDispatch.Sig = Source.Sig;
NewDispatch.StaticLexPad = Source.StaticLexPad;
// Take existing candidates and add new ones.
NewDispatch.Dispatchees = new RakudoObject[Source.Dispatchees.Length + AdditionalDispatchList.Storage.Count];
var i = 0;
for (int j = 0; j < Source.Dispatchees.Length; j++)
NewDispatch.Dispatchees[i++] = Source.Dispatchees[j];
for (int j = 0; j < AdditionalDispatchList.Storage.Count; j++)
NewDispatch.Dispatchees[i++] = AdditionalDispatchList.Storage[j];
return NewDispatch;
}
示例4: box_str
/// <summary>
/// Boxes a native string into its matching value type.
/// </summary>
/// <param name="Value"></param>
/// <returns></returns>
public static RakudoObject box_str(ThreadContext TC, string Value, RakudoObject To)
{
var REPR = To.STable.REPR;
var Result = REPR.instance_of(TC, To);
REPR.set_str(TC, Result, Value);
return Result;
}
示例5: 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;
}
示例6: is_dispatcher
/// <summary>
/// Checks if a routine is considered a dispatcher (that is, if it has a
/// candidate list).
/// </summary>
/// <param name="TC"></param>
/// <param name="Check"></param>
/// <returns></returns>
public static RakudoObject is_dispatcher(ThreadContext TC, RakudoObject Check)
{
var Checkee = Check as RakudoCodeRef.Instance;
if (Checkee != null && Checkee.Dispatchees != null)
return Ops.box_int(TC, 1, TC.DefaultBoolBoxType);
else
return Ops.box_int(TC, 0, TC.DefaultBoolBoxType);
}
示例7: 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;
}
示例8: lllist_get_at_pos
/// <summary>
/// Gets a value at a given positional index from a low level list
/// (something that uses the P6list representation).
/// </summary>
/// <param name="TC"></param>
/// <param name="LLList"></param>
/// <param name="Index"></param>
/// <returns></returns>
public static RakudoObject lllist_get_at_pos(ThreadContext TC, RakudoObject LLList, RakudoObject Index)
{
if (LLList is P6list.Instance)
{
return ((P6list.Instance)LLList).Storage[Ops.unbox_int(TC, Index)];
}
else
{
throw new Exception("Cannot use lllist_get_at_pos if representation is not P6list");
}
}
示例9: lllist_elems
/// <summary>
/// Gets the number of elements in a low level list (something that
/// uses the P6list representation).
/// </summary>
/// <param name="TC"></param>
/// <param name="LLList"></param>
/// <returns></returns>
public static RakudoObject lllist_elems(ThreadContext TC, RakudoObject LLList)
{
if (LLList is P6list.Instance)
{
return Ops.box_int(TC, ((P6list.Instance)LLList).Storage.Count, TC.DefaultIntBoxType);
}
else
{
throw new Exception("Cannot use lllist_elems if representation is not P6list");
}
}
示例10: load_module
/// <summary>
/// Loads a module (that is, some pre-compiled compilation unit that
/// was compiled using NQP). Expects the path minus an extension
/// (that is, the .dll will be added). Returns what the body of the
/// compilation unit evaluated to.
/// </summary>
/// <param name="TC"></param>
/// <param name="Path"></param>
/// <returns></returns>
public static RakudoObject load_module(ThreadContext TC, RakudoObject Path)
{
// Load the assembly and grab the first type in it.
var Assembly = AppDomain.CurrentDomain.Load(Ops.unbox_str(TC, Path));
var Class = Assembly.GetTypes()[0];
// Call the Load method, passing along the current thread context
// and the setting to use with it. What's returned is what the main
// body of the compilation unit evaluates to.
var Method = Class.GetMethod("Load", BindingFlags.NonPublic | BindingFlags.Static);
return (RakudoObject)Method.Invoke(null, new object[] { TC, TC.Domain.Setting });
}
示例11: get_dynamic
/// <summary>
/// Looks up a variable in the dynamic scope.
/// </summary>
/// <param name="C"></param>
/// <param name="Name"></param>
/// <returns></returns>
public static RakudoObject get_dynamic(ThreadContext TC, string Name)
{
var CurContext = TC.CurrentContext;
while (CurContext != null)
{
int Index;
if (CurContext.LexPad.SlotMapping.TryGetValue(Name, out Index))
return CurContext.LexPad.Storage[Index];
CurContext = CurContext.Caller;
}
throw new InvalidOperationException("No variable " + Name + " found in the dynamic scope");
}
示例12: bind_lex
/// <summary>
/// Binds the given value to a lexical variable of the given name.
/// </summary>
/// <param name="TC"></param>
/// <param name="name"></param>
/// <returns></returns>
public static RakudoObject bind_lex(ThreadContext TC, string Name, RakudoObject Value)
{
var CurContext = TC.CurrentContext;
while (CurContext != null)
{
int Index;
if (CurContext.LexPad.SlotMapping.TryGetValue(Name, out Index))
{
CurContext.LexPad.Storage[Index] = Value;
return Value;
}
CurContext = CurContext.Outer;
}
throw new InvalidOperationException("No variable " + Name + " found in the lexical scope");
}
示例13: multi_dispatch_over_lexical_candidates
/// <summary>
/// Entry point to multi-dispatch over the current dispatchee list.
/// </summary>
/// <param name="TC"></param>
/// <returns></returns>
public static RakudoObject multi_dispatch_over_lexical_candidates(ThreadContext TC)
{
var CurOuter = TC.CurrentContext;
while (CurOuter != null)
{
var CodeObj = CurOuter.StaticCodeObject;
if (CodeObj.Dispatchees != null)
{
var Candidate = MultiDispatch.MultiDispatcher.FindBestCandidate(TC,
CodeObj, CurOuter.Capture);
return Candidate.STable.Invoke(TC, Candidate, CurOuter.Capture);
}
CurOuter = CurOuter.Outer;
}
throw new Exception("Could not find dispatchee list!");
}
示例14: llmapping_get_at_key
/// <summary>
/// Gets a value at a given key from a low level mapping (something that
/// uses the P6mapping representation).
/// </summary>
/// <param name="TC"></param>
/// <param name="LLMapping"></param>
/// <param name="Key"></param>
/// <returns></returns>
public static RakudoObject llmapping_get_at_key(ThreadContext TC, RakudoObject LLMapping, RakudoObject Key)
{
if (LLMapping is P6mapping.Instance)
{
var Storage = ((P6mapping.Instance)LLMapping).Storage;
var StrKey = Ops.unbox_str(TC, Key);
if (Storage.ContainsKey(StrKey))
return Storage[StrKey];
else
return null;
}
else
{
throw new Exception("Cannot use llmapping_get_at_key if representation is not P6mapping");
}
}
示例15: llmapping_bind_at_key
/// <summary>
/// Binds a value at a given key from a low level mapping (something that
/// uses the P6mapping representation).
/// </summary>
/// <param name="TC"></param>
/// <param name="LLMapping"></param>
/// <param name="Key"></param>
/// <param name="Value"></param>
/// <returns></returns>
public static RakudoObject llmapping_bind_at_key(ThreadContext TC, RakudoObject LLMapping, RakudoObject Key, RakudoObject Value)
{
if (LLMapping is P6mapping.Instance)
{
var Storage = ((P6mapping.Instance)LLMapping).Storage;
var StrKey = Ops.unbox_str(TC, Key);
if (Storage.ContainsKey(StrKey))
Storage[StrKey] = Value;
else
Storage.Add(StrKey, Value);
return Value;
}
else
{
throw new Exception("Cannot use llmapping_bind_at_key if representation is not P6mapping");
}
}