Operand packs kw<<8 | pos; keep counts distinct.
(&mut self, op: u16)
| 105 | |
| 106 | // Operand packs kw<<8 | pos; keep counts distinct. |
| 107 | pub fn call_dict(&mut self, op: u16) -> Result<(), VmErr> { |
| 108 | let pos = (op & 0xFF) as usize; |
| 109 | let kw = (op >> 8) as usize; |
| 110 | if pos > 1 { |
| 111 | return Err(cold_type("dict expected at most 1 argument")); |
| 112 | } |
| 113 | // Keyword pairs sit above the positional source. |
| 114 | let kw_flat = self.pop_n(kw * 2)?; |
| 115 | let mut dm = if pos == 1 { |
| 116 | let src = self.pop()?; |
| 117 | self.dict_from_source(src)? |
| 118 | } else { |
| 119 | DictMap::with_capacity(kw) |
| 120 | }; |
| 121 | for pair in kw_flat.chunks(2) { dm.insert(pair[0], pair[1], &self.heap); } |
| 122 | self.alloc_and_push_dict(dm) |
| 123 | } |
| 124 | |
| 125 | // dict(mapping) copies; dict(iterable) builds from pairs. |
| 126 | fn dict_from_source(&mut self, src: Val) -> Result<DictMap, VmErr> { |
no test coverage detected