Skip to content

Commit

Permalink
[dotnet] Three ops for working with P6mapping.
Browse files Browse the repository at this point in the history
  • Loading branch information
jnthn committed Oct 19, 2010
1 parent 017a5ef commit bae7cdf
Showing 1 changed file with 73 additions and 3 deletions.
76 changes: 73 additions & 3 deletions dotnet/runtime/Runtime/Ops.cs
Expand Up @@ -586,12 +586,11 @@ public static RakudoObject lllist_bind_at_pos(ThreadContext TC, RakudoObject LLL
}

/// <summary>
/// Binds a value at a given positional index from a low level list
/// (something that uses the P6list representation).
/// 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>
/// <param name="Index"></param>
/// <returns></returns>
public static RakudoObject lllist_elems(ThreadContext TC, RakudoObject LLList)
{
Expand All @@ -604,5 +603,76 @@ public static RakudoObject lllist_elems(ThreadContext TC, RakudoObject LLList)
throw new Exception("Cannot use lllist_elems if representation is not P6list");
}
}

/// <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");
}
}

/// <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");
}
}

/// <summary>
/// Gets the number of elements in a low level mapping (something that
/// uses the P6mapping representation).
/// </summary>
/// <param name="TC"></param>
/// <param name="LLMapping"></param>
/// <returns></returns>
public static RakudoObject llmapping_elems(ThreadContext TC, RakudoObject LLMapping)
{
if (LLMapping is P6mapping.Instance)
{
return Ops.box_int(TC, ((P6mapping.Instance)LLMapping).Storage.Count, TC.DefaultIntBoxType);
}
else
{
throw new Exception("Cannot use llmapping_elems if representation is not P6mapping");
}
}
}
}

0 comments on commit bae7cdf

Please sign in to comment.