fn enter_function(
      &mut self,
      env: &mut Environment,
      globals: &mut Globals,
      gc: &mut Memory,
      closure: GcRaw<Closure>,
      argument_count: usize,
   ) -> Result<(), Error> {
      let function = unsafe { env.get_function_unchecked_mut(closure.get().function_id) };
      match &mut function.kind {
         FunctionKind::Bytecode { chunk, .. } => {
            self.save_return_point();
            self.chunk = Rc::clone(chunk);
            self.closure = Some(closure);
            self.pc = 0;
            self.stack_bottom = self.stack.len() - argument_count;
            self.allocate_chunk_storage_slots(chunk.preallocate_stack_slots as usize);
         }
         FunctionKind::Foreign(f) => {
            let arguments =
               unsafe { self.stack.get_unchecked(self.stack.len() - argument_count..) };
            let result = match f(gc, arguments) {
               Ok(value) => value,
               Err(kind) => {
                  return Err(self.error_outside_function_call(Some(closure), env, kind));
               }
            };
            for _ in 0..argument_count {
               self.pop();
            }
            self.push(result);
         }
         &mut FunctionKind::Control(ctl) => {
            self.call_control(env, globals, gc, ctl, argument_count)?;
         }
      }
      Ok(())
   }
/// Calls a function. For bytecode functions this saves the stack and begins executing the
/// function's chunk. For foreign functions it simply calls the function.
Calls a function. For bytecode functions this saves the stack and begins executing the
function's chunk. For foreign functions it simply calls the function.
Calls a function . For bytecode functions this saves the stack and begins executing the function ' s chunk . For foreign functions it simply calls the function .
fn enter_function(
      &mut self,
      env: &mut Environment,
      globals: &mut Globals,
      gc: &mut Memory,
      closure: GcRaw<Closure>,
      argument_count: usize,
   ) -> Result<(), Error> {
      let function = unsafe { env.get_function_unchecked_mut(closure.get().function_id) };
      match &mut function.kind {
         FunctionKind::Bytecode { chunk, .. } => {
            self.save_return_point();
            self.chunk = Rc::clone(chunk);
            self.closure = Some(closure);
            self.pc = 0;
            self.stack_bottom = self.stack.len() - argument_count;
            self.allocate_chunk_storage_slots(chunk.preallocate_stack_slots as usize);
         }
         FunctionKind::Foreign(f) => {
            let arguments =
               unsafe { self.stack.get_unchecked(self.stack.len() - argument_count..) };
            let result = match f(gc, arguments) {
               Ok(value) => value,
               Err(kind) => {
                  return Err(self.error_outside_function_call(Some(closure), env, kind));
               }
            };
            for _ in 0..argument_count {
               self.pop();
            }
            self.push(result);
         }
         &mut FunctionKind::Control(ctl) => {
            self.call_control(env, globals, gc, ctl, argument_count)?;
         }
      }
      Ok(())
   }
fn enter_function ( & mut self , env : & mut Environment , globals : & mut Globals , gc : & mut Memory , closure : GcRaw < Closure > , argument_count : usize , ) -> Result < ( ) , Error > { let function = unsafe { env . get_function_unchecked_mut ( closure . get ( ) . function_id ) } ; match & mut function . kind { FunctionKind :: Bytecode { chunk , .. } => { self . save_return_point ( ) ; self . chunk = Rc :: clone ( chunk ) ; self . closure = Some ( closure ) ; self . pc = 0 ; self . stack_bottom = self . stack . len ( ) - argument_count ; self . allocate_chunk_storage_slots ( chunk . preallocate_stack_slots as usize ) ; } FunctionKind :: Foreign ( f ) => { let arguments = unsafe { self . stack . get_unchecked ( self . stack . len ( ) - argument_count .. ) } ; let result = match f ( gc , arguments ) { Ok ( value ) => value , Err ( kind ) => { return Err ( self . error_outside_function_call ( Some ( closure ) , env , kind ) ) ; } } ; for _ in 0 .. argument_count { self . pop ( ) ; } self . push ( result ) ; } & mut FunctionKind :: Control ( ctl ) => { self . call_control ( env , globals , gc , ctl , argument_count ) ? ; } } Ok ( ( ) ) }
Calls a function.
Calls a function .
&mut self
env
&mut Environment
globals
&mut Globals
gc
&mut Memory
closure
GcRaw<Closure>
argument_count
usize