fn opcode_divide_inner(
        &mut self, chunk: &Chunk, i: usize, v1: &Value, v2: &Value,
    ) -> i32 {
        match (&*v1, &*v2) {
            (Value::BigInt(n1), Value::BigInt(n2)) => {
                let n3 = Value::BigInt(n2 / n1);
                self.stack.push(Rc::new(RefCell::new(n3)));
                return 1;
            }
            (Value::BigInt(_), Value::Int(n2)) => {
                return self.opcode_divide_inner(chunk, i, v1, &int_to_bigint(*n2));
            }
            (Value::Int(n1), Value::BigInt(_)) => {
                return self.opcode_divide_inner(chunk, i, &int_to_bigint(*n1), v2);
            }
            (Value::Int(n1), Value::Int(n2)) => {
                self.stack.push(Rc::new(RefCell::new(divide_ints(*n1, *n2))));
                return 1;
            }
            (Value::Float(n1), Value::Float(n2)) => {
                self.stack
                    .push(Rc::new(RefCell::new(Value::Float(n2 / n1))));
                return 1;
            }
            (Value::BigInt(n1), Value::Float(_)) => {
                return self.opcode_divide_inner(chunk, i, &bigint_to_float(n1), v2);
            }
            (Value::Float(_), Value::BigInt(n2)) => {
                return self.opcode_divide_inner(chunk, i, v1, &bigint_to_float(n2));
            }
            (Value::Int(n1), Value::Float(_)) => {
                return self.opcode_divide_inner(chunk, i, &int_to_float(*n1), v2);
            }
            (Value::Float(_), Value::Int(n2)) => {
                return self.opcode_divide_inner(chunk, i, v1, &int_to_float(*n2));
            }
            (_, _) => {
                let n1_opt = v1.to_int();
                let n2_opt = v2.to_int();
                match (n1_opt, n2_opt) {
                    (Some(n1), Some(n2)) => {
                        self.stack.push(Rc::new(RefCell::new(divide_ints(n1, n2))));
                        return 1;
                    }
                    _ => {}
                }
                let n1_opt = v1.to_bigint();
                let n2_opt = v2.to_bigint();
                match (n1_opt, n2_opt) {
                    (Some(n1), Some(n2)) => {
                        self.stack.push(Rc::new(RefCell::new(
                            Value::BigInt(n2 / n1),
                        )));
                        return 1;
                    }
                    _ => {}
                }
                let n1_opt = v1.to_float();
                let n2_opt = v2.to_float();
                match (n1_opt, n2_opt) {
                    (Some(n1), Some(n2)) => {
                        self.stack.push(Rc::new(RefCell::new(
                            Value::Float(n2 / n1),
                        )));
                        return 1;
                    }
                    _ => {}
                }
                return 0;
            }
        }
    }
/// Helper function for dividing two values and placing the result
/// onto the stack.  Returns an integer indicating whether the
/// values were able to be divided.
Helper function for dividing two values and placing the result
onto the stack.  Returns an integer indicating whether the
values were able to be divided.
Helper function for dividing two values and placing the result onto the stack . Returns an integer indicating whether the values were able to be divided .
fn opcode_divide_inner(
        &mut self, chunk: &Chunk, i: usize, v1: &Value, v2: &Value,
    ) -> i32 {
        match (&*v1, &*v2) {
            (Value::BigInt(n1), Value::BigInt(n2)) => {
                let n3 = Value::BigInt(n2 / n1);
                self.stack.push(Rc::new(RefCell::new(n3)));
                return 1;
            }
            (Value::BigInt(_), Value::Int(n2)) => {
                return self.opcode_divide_inner(chunk, i, v1, &int_to_bigint(*n2));
            }
            (Value::Int(n1), Value::BigInt(_)) => {
                return self.opcode_divide_inner(chunk, i, &int_to_bigint(*n1), v2);
            }
            (Value::Int(n1), Value::Int(n2)) => {
                self.stack.push(Rc::new(RefCell::new(divide_ints(*n1, *n2))));
                return 1;
            }
            (Value::Float(n1), Value::Float(n2)) => {
                self.stack
                    .push(Rc::new(RefCell::new(Value::Float(n2 / n1))));
                return 1;
            }
            (Value::BigInt(n1), Value::Float(_)) => {
                return self.opcode_divide_inner(chunk, i, &bigint_to_float(n1), v2);
            }
            (Value::Float(_), Value::BigInt(n2)) => {
                return self.opcode_divide_inner(chunk, i, v1, &bigint_to_float(n2));
            }
            (Value::Int(n1), Value::Float(_)) => {
                return self.opcode_divide_inner(chunk, i, &int_to_float(*n1), v2);
            }
            (Value::Float(_), Value::Int(n2)) => {
                return self.opcode_divide_inner(chunk, i, v1, &int_to_float(*n2));
            }
            (_, _) => {
                let n1_opt = v1.to_int();
                let n2_opt = v2.to_int();
                match (n1_opt, n2_opt) {
                    (Some(n1), Some(n2)) => {
                        self.stack.push(Rc::new(RefCell::new(divide_ints(n1, n2))));
                        return 1;
                    }
                    _ => {}
                }
                let n1_opt = v1.to_bigint();
                let n2_opt = v2.to_bigint();
                match (n1_opt, n2_opt) {
                    (Some(n1), Some(n2)) => {
                        self.stack.push(Rc::new(RefCell::new(
                            Value::BigInt(n2 / n1),
                        )));
                        return 1;
                    }
                    _ => {}
                }
                let n1_opt = v1.to_float();
                let n2_opt = v2.to_float();
                match (n1_opt, n2_opt) {
                    (Some(n1), Some(n2)) => {
                        self.stack.push(Rc::new(RefCell::new(
                            Value::Float(n2 / n1),
                        )));
                        return 1;
                    }
                    _ => {}
                }
                return 0;
            }
        }
    }
fn opcode_divide_inner ( & mut self , chunk : & Chunk , i : usize , v1 : & Value , v2 : & Value , ) -> i32 { match ( & * v1 , & * v2 ) { ( Value :: BigInt ( n1 ) , Value :: BigInt ( n2 ) ) => { let n3 = Value :: BigInt ( n2 / n1 ) ; self . stack . push ( Rc :: new ( RefCell :: new ( n3 ) ) ) ; return 1 ; } ( Value :: BigInt ( _ ) , Value :: Int ( n2 ) ) => { return self . opcode_divide_inner ( chunk , i , v1 , & int_to_bigint ( * n2 ) ) ; } ( Value :: Int ( n1 ) , Value :: BigInt ( _ ) ) => { return self . opcode_divide_inner ( chunk , i , & int_to_bigint ( * n1 ) , v2 ) ; } ( Value :: Int ( n1 ) , Value :: Int ( n2 ) ) => { self . stack . push ( Rc :: new ( RefCell :: new ( divide_ints ( * n1 , * n2 ) ) ) ) ; return 1 ; } ( Value :: Float ( n1 ) , Value :: Float ( n2 ) ) => { self . stack . push ( Rc :: new ( RefCell :: new ( Value :: Float ( n2 / n1 ) ) ) ) ; return 1 ; } ( Value :: BigInt ( n1 ) , Value :: Float ( _ ) ) => { return self . opcode_divide_inner ( chunk , i , & bigint_to_float ( n1 ) , v2 ) ; } ( Value :: Float ( _ ) , Value :: BigInt ( n2 ) ) => { return self . opcode_divide_inner ( chunk , i , v1 , & bigint_to_float ( n2 ) ) ; } ( Value :: Int ( n1 ) , Value :: Float ( _ ) ) => { return self . opcode_divide_inner ( chunk , i , & int_to_float ( * n1 ) , v2 ) ; } ( Value :: Float ( _ ) , Value :: Int ( n2 ) ) => { return self . opcode_divide_inner ( chunk , i , v1 , & int_to_float ( * n2 ) ) ; } ( _ , _ ) => { let n1_opt = v1 . to_int ( ) ; let n2_opt = v2 . to_int ( ) ; match ( n1_opt , n2_opt ) { ( Some ( n1 ) , Some ( n2 ) ) => { self . stack . push ( Rc :: new ( RefCell :: new ( divide_ints ( n1 , n2 ) ) ) ) ; return 1 ; } _ => { } } let n1_opt = v1 . to_bigint ( ) ; let n2_opt = v2 . to_bigint ( ) ; match ( n1_opt , n2_opt ) { ( Some ( n1 ) , Some ( n2 ) ) => { self . stack . push ( Rc :: new ( RefCell :: new ( Value :: BigInt ( n2 / n1 ) , ) ) ) ; return 1 ; } _ => { } } let n1_opt = v1 . to_float ( ) ; let n2_opt = v2 . to_float ( ) ; match ( n1_opt , n2_opt ) { ( Some ( n1 ) , Some ( n2 ) ) => { self . stack . push ( Rc :: new ( RefCell :: new ( Value :: Float ( n2 / n1 ) , ) ) ) ; return 1 ; } _ => { } } return 0 ; } } }
Helper function for dividing two values and placing the result
onto the stack.
Helper function for dividing two values and placing the result onto the stack .
&mut self
chunk
&Chunk
i
usize
v1
&Value
v2
&Value