MCPcopy Create free account
hub / github.com/dylan-sutton-chavez/edge-python / mapping_to_kw_pairs

Method mapping_to_kw_pairs

compiler/src/modules/vm/helpers.rs:86–102  ·  view source on GitHub ↗

Materialise a mapping into (key_str, value) pairs for `**kwargs` spread. */

(&self, v: Val)

Source from the content-addressed store, hash-verified

84
85 /* Materialise a mapping into (key_str, value) pairs for `**kwargs` spread. */
86 pub(crate) fn mapping_to_kw_pairs(&self, v: Val) -> Result<Vec<(Val, Val)>, VmErr> {
87 if !v.is_heap() {
88 return Err(VmErr::Type("argument after ** must be a mapping"));
89 }
90 match self.heap.get(v) {
91 HeapObj::Dict(rc) => {
92 let entries: Vec<(Val, Val)> = rc.borrow().iter().collect();
93 for (k, _) in &entries {
94 if !k.is_heap() || !matches!(self.heap.get(*k), HeapObj::Str(_)) {
95 return Err(VmErr::Type("keywords must be strings"));
96 }
97 }
98 Ok(entries)
99 }
100 _ => Err(VmErr::Type("argument after ** must be a mapping")),
101 }
102 }
103
104 /* Seed slots with `undef()` so LoadName can detect unbound names via a u64 compare. */
105 pub(crate) fn fill_builtins(&self, names: &[String]) -> Vec<Val> {

Callers 1

dispatch_genericMethod · 0.80

Calls 5

is_heapMethod · 0.80
collectMethod · 0.80
borrowMethod · 0.80
getMethod · 0.45
iterMethod · 0.45

Tested by

no test coverage detected