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

Method set_binop_items

compiler/src/modules/vm/ops.rs:162–174  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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)?;

Callers 2

set_binop_and_pushMethod · 0.80
set_iop_and_pushMethod · 0.80

Calls 5

cold_runtimeFunction · 0.85
clone_set_itemsMethod · 0.80
collectMethod · 0.80
iterMethod · 0.45
containsMethod · 0.45

Tested by

no test coverage detected