(
&mut self,
instruction: Instruction,
arg: OpArg,
constants: &Constants<ConstantData>,
names: &[String],
)
| 193 | } |
| 194 | |
| 195 | fn process_instruction( |
| 196 | &mut self, |
| 197 | instruction: Instruction, |
| 198 | arg: OpArg, |
| 199 | constants: &Constants<ConstantData>, |
| 200 | names: &[String], |
| 201 | ) -> ControlFlow<()> { |
| 202 | match instruction { |
| 203 | Instruction::Resume { .. } | Instruction::Cache | Instruction::NotTaken => { |
| 204 | // No-op for JIT tests |
| 205 | } |
| 206 | Instruction::LoadConst { consti } => { |
| 207 | self.stack.push(constants[consti.get(arg)].clone().into()) |
| 208 | } |
| 209 | Instruction::LoadName { namei } => self |
| 210 | .stack |
| 211 | .push(StackValue::String(names[namei.get(arg) as usize].clone())), |
| 212 | Instruction::StoreName { namei } => { |
| 213 | let idx = namei.get(arg); |
| 214 | self.locals |
| 215 | .insert(names[idx as usize].clone(), self.stack.pop().unwrap()); |
| 216 | } |
| 217 | Instruction::StoreAttr { .. } => { |
| 218 | // Do nothing except throw away the stack values |
| 219 | self.stack.pop().unwrap(); |
| 220 | self.stack.pop().unwrap(); |
| 221 | } |
| 222 | Instruction::BuildMap { count } => { |
| 223 | let mut map = HashMap::new(); |
| 224 | for _ in 0..count.get(arg) { |
| 225 | let value = self.stack.pop().unwrap(); |
| 226 | let name = if let Some(StackValue::String(name)) = self.stack.pop() { |
| 227 | Wtf8Buf::from(name) |
| 228 | } else { |
| 229 | unimplemented!("no string keys isn't yet supported in py_function!") |
| 230 | }; |
| 231 | map.insert(name, value); |
| 232 | } |
| 233 | self.stack.push(StackValue::Map(map)); |
| 234 | } |
| 235 | Instruction::MakeFunction => { |
| 236 | let code = if let Some(StackValue::Code(code)) = self.stack.pop() { |
| 237 | code |
| 238 | } else { |
| 239 | panic!("Expected function code") |
| 240 | }; |
| 241 | // Other attributes will be set by SET_FUNCTION_ATTRIBUTE |
| 242 | self.stack.push(StackValue::Function(Function { |
| 243 | code, |
| 244 | annotations: HashMap::new(), // empty annotations, will be set later if needed |
| 245 | })); |
| 246 | } |
| 247 | Instruction::SetFunctionAttribute { flag } => { |
| 248 | // Stack: [..., attr_value, func] -> [..., func] |
| 249 | let func = if let Some(StackValue::Function(func)) = self.stack.pop() { |
| 250 | func |
| 251 | } else { |
| 252 | panic!("Expected function on stack for SET_FUNCTION_ATTRIBUTE") |
no test coverage detected