pub fn core_gnth(
        &mut self,
        scopes: &mut Vec<RefCell<HashMap<String, Rc<RefCell<Value>>>>>,
        global_functions: &mut RefCell<HashMap<String, Chunk>>,
        prev_local_vars_stacks: &mut Vec<Rc<RefCell<Vec<Rc<RefCell<Value>>>>>>,
        chunk: &Chunk, i: usize, line_col: (u32, u32),
        running: Arc<AtomicBool>,
    ) -> i32 {
        if self.stack.len() < 2 {
            print_error(chunk, i, "gnth requires two arguments");
            return 0;
        }

        let index_rr = self.stack.pop().unwrap();
        let index_rrb = index_rr.borrow();
        let index_int_opt = index_rrb.to_int();

        match index_int_opt {
            Some(mut index) => {
                while index >= 0 {
                    let dup_res = self.opcode_dup(chunk, i);
                    if dup_res == 0 {
                        return 0;
                    }
                    let shift_res = self.opcode_shift(
                        scopes,
                        global_functions,
                        prev_local_vars_stacks,
                        chunk,
                        i,
                        line_col,
                        running.clone(),
                    );
                    if shift_res == 0 {
                        return 0;
                    }
                    if index == 0 {
                        self.stack.remove(self.stack.len() - 2);
                        break;
                    } else {
                        self.stack.pop();
                        index = index - 1;
                    }
                }
            }
            _ => {
                print_error(chunk, i, "second gnth argument must be integer");
                return 0;
            }
        }
        return 1;
    }
/// Takes a generator and an index as its arguments.  Gets the
/// element at the given index from the generator and places it
/// onto the stack.
Takes a generator and an index as its arguments.  Gets the
element at the given index from the generator and places it
onto the stack.
Takes a generator and an index as its arguments . Gets the element at the given index from the generator and places it onto the stack .
pub fn core_gnth(
        &mut self,
        scopes: &mut Vec<RefCell<HashMap<String, Rc<RefCell<Value>>>>>,
        global_functions: &mut RefCell<HashMap<String, Chunk>>,
        prev_local_vars_stacks: &mut Vec<Rc<RefCell<Vec<Rc<RefCell<Value>>>>>>,
        chunk: &Chunk, i: usize, line_col: (u32, u32),
        running: Arc<AtomicBool>,
    ) -> i32 {
        if self.stack.len() < 2 {
            print_error(chunk, i, "gnth requires two arguments");
            return 0;
        }
        let index_rr = self.stack.pop().unwrap();
        let index_rrb = index_rr.borrow();
        let index_int_opt = index_rrb.to_int();
        match index_int_opt {
            Some(mut index) => {
                while index >= 0 {
                    let dup_res = self.opcode_dup(chunk, i);
                    if dup_res == 0 {
                        return 0;
                    }
                    let shift_res = self.opcode_shift(
                        scopes,
                        global_functions,
                        prev_local_vars_stacks,
                        chunk,
                        i,
                        line_col,
                        running.clone(),
                    );
                    if shift_res == 0 {
                        return 0;
                    }
                    if index == 0 {
                        self.stack.remove(self.stack.len() - 2);
                        break;
                    } else {
                        self.stack.pop();
                        index = index - 1;
                    }
                }
            }
            _ => {
                print_error(chunk, i, "second gnth argument must be integer");
                return 0;
            }
        }
        return 1;
    }
pub fn core_gnth ( & mut self , scopes : & mut Vec < RefCell < HashMap < String , Rc < RefCell < Value > > > > > , global_functions : & mut RefCell < HashMap < String , Chunk > > , prev_local_vars_stacks : & mut Vec < Rc < RefCell < Vec < Rc < RefCell < Value > > > > > > , chunk : & Chunk , i : usize , line_col : ( u32 , u32 ) , running : Arc < AtomicBool > , ) -> i32 { if self . stack . len ( ) < 2 { print_error ( chunk , i , " " ) ; return 0 ; } let index_rr = self . stack . pop ( ) . unwrap ( ) ; let index_rrb = index_rr . borrow ( ) ; let index_int_opt = index_rrb . to_int ( ) ; match index_int_opt { Some ( mut index ) => { while index >= 0 { let dup_res = self . opcode_dup ( chunk , i ) ; if dup_res == 0 { return 0 ; } let shift_res = self . opcode_shift ( scopes , global_functions , prev_local_vars_stacks , chunk , i , line_col , running . clone ( ) , ) ; if shift_res == 0 { return 0 ; } if index == 0 { self . stack . remove ( self . stack . len ( ) - 2 ) ; break ; } else { self . stack . pop ( ) ; index = index - 1 ; } } } _ => { print_error ( chunk , i , " " ) ; return 0 ; } } return 1 ; }
Takes a generator and an index as its arguments.
Takes a generator and an index as its arguments .
&mut self
scopes
&mut Vec<RefCell<HashMap<String, Rc<RefCell<Value>>>>>
global_functions
&mut RefCell<HashMap<String, Chunk>>
prev_local_vars_stacks
&mut Vec<Rc<RefCell<Vec<Rc<RefCell<Value>>>>>>
chunk
&Chunk
i
usize
line_col
(u32, u32)
running
Arc<AtomicBool>