Pairs elements from N iterables into tuples, truncating to the shortest. */
(&mut self, op: u16)
| 267 | |
| 268 | /* Pairs elements from N iterables into tuples, truncating to the shortest. */ |
| 269 | pub fn call_zip(&mut self, op: u16) -> Result<(), VmErr> { |
| 270 | let mut iters: Vec<Vec<Val>> = Vec::with_capacity(op as usize); |
| 271 | let mut vals = Vec::with_capacity(op as usize); |
| 272 | for _ in 0..op { vals.push(self.pop()?); } |
| 273 | vals.reverse(); |
| 274 | for v in vals { iters.push(self.extract_iter(v, false)?); } |
| 275 | let len = iters.iter().map(|v| v.len()).min().unwrap_or(0); |
| 276 | let mut pairs: Vec<Val> = Vec::with_capacity(len); |
| 277 | for i in 0..len { |
| 278 | let tuple: Vec<Val> = iters.iter().map(|v| v[i]).collect(); |
| 279 | let t = self.heap.alloc(HeapObj::Tuple(tuple))?; |
| 280 | pairs.push(t); |
| 281 | } |
| 282 | self.alloc_and_push_list(pairs) |
| 283 | } |
| 284 | |
| 285 | // TypeError for a non-iterable operand. |
| 286 | fn not_iterable(&self, o: Val) -> VmErr { |
no test coverage detected