Set bitwise ops (|, &, ^) over set/frozenset; result frozen iff `a` is frozen. */ Union/intersection/symmetric-diff items; content membership lets alloc dedup distinct-handle equals.
(&self, a: Val, b: Val, op: OpCode)
| 160 | /* Set bitwise ops (|, &, ^) over set/frozenset; result frozen iff `a` is frozen. */ |
| 161 | // Union/intersection/symmetric-diff items; content membership lets alloc dedup distinct-handle equals. |
| 162 | fn set_binop_items(&self, a: Val, b: Val, op: OpCode) -> Result<Vec<Val>, VmErr> { |
| 163 | let (sa, sb) = match (self.clone_set_items(a), self.clone_set_items(b)) { |
| 164 | (Some(x), Some(y)) => (x, y), |
| 165 | _ => return Err(cold_runtime("set_binop on non-set operands")), |
| 166 | }; |
| 167 | Ok(match op { |
| 168 | OpCode::BitOr => sa.iter().chain(sb.iter()).copied().collect(), |
| 169 | OpCode::BitAnd => sa.iter().filter(|&&v| sb.contains(v, &self.heap)).copied().collect(), |
| 170 | OpCode::BitXor => sa.iter().filter(|&&v| !sb.contains(v, &self.heap)) |
| 171 | .chain(sb.iter().filter(|&&v| !sa.contains(v, &self.heap))).copied().collect(), |
| 172 | _ => return Err(cold_runtime("set_binop with non-bitwise opcode")), |
| 173 | }) |
| 174 | } |
| 175 | |
| 176 | pub(crate) fn set_binop_and_push(&mut self, a: Val, b: Val, op: OpCode) -> Result<(), VmErr> { |
| 177 | let items = self.set_binop_items(a, b, op)?; |
no test coverage detected