diff --git a/dotnet/runtime/Runtime/Ops.cs b/dotnet/runtime/Runtime/Ops.cs index 6790564..0561d5c 100644 --- a/dotnet/runtime/Runtime/Ops.cs +++ b/dotnet/runtime/Runtime/Ops.cs @@ -586,12 +586,11 @@ public static RakudoObject lllist_bind_at_pos(ThreadContext TC, RakudoObject LLL } /// - /// 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). /// /// /// - /// /// public static RakudoObject lllist_elems(ThreadContext TC, RakudoObject LLList) { @@ -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"); } } + + /// + /// Gets a value at a given key from a low level mapping (something that + /// uses the P6mapping representation). + /// + /// + /// + /// + /// + 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"); + } + } + + /// + /// Binds a value at a given key from a low level mapping (something that + /// uses the P6mapping representation). + /// + /// + /// + /// + /// + /// + 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"); + } + } + + /// + /// Gets the number of elements in a low level mapping (something that + /// uses the P6mapping representation). + /// + /// + /// + /// + 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"); + } + } } }