fn lookup(&mut self, name: &str) -> Result<Option<VariablePlace>, ErrorKind> {
      // Work inside out: try innermost scopes (own locals) first.
      for scope in self.scopes.iter().rev() {
         if let Some(var) = scope.variables_by_name.get(name) {
            return Ok(Some(VariablePlace::Local(var.stack_slot)));
         }
      }
      // If there isn't a local with the given name, go up a level and look for locals to capture
      // or existing upvalues.
      if let Some(parent) = self.parent.as_mut() {
         if let Some(place) = parent.lookup(name)? {
            match place {
               VariablePlace::Local(local_slot) => {
                  let (_, variable) = parent
                     .variables_in_scope_mut()
                     .find(|(_, var)| var.stack_slot == local_slot)
                     .unwrap();
                  variable.is_captured = true;
                  let stack_slot = variable.stack_slot;
                  let upvalue_index = self.capture_index(CaptureKind::Local(stack_slot))?;
                  return Ok(Some(VariablePlace::Upvalue(upvalue_index)));
               }
               VariablePlace::Upvalue(upvalue_index) => {
                  let own_index = self.capture_index(CaptureKind::Upvalue(upvalue_index))?;
                  return Ok(Some(VariablePlace::Upvalue(own_index)));
               }
               VariablePlace::Global(_) => unreachable!(),
            }
         }
      }
      Ok(None)
   }
/// Performs a local variable lookup. This may modify parent Locals and capture upvalues.
Performs a local variable lookup. This may modify parent Locals and capture upvalues.
Performs a local variable lookup . This may modify parent Locals and capture upvalues .
fn lookup(&mut self, name: &str) -> Result<Option<VariablePlace>, ErrorKind> {
      // Work inside out: try innermost scopes (own locals) first.
      for scope in self.scopes.iter().rev() {
         if let Some(var) = scope.variables_by_name.get(name) {
            return Ok(Some(VariablePlace::Local(var.stack_slot)));
         }
      }
      // If there isn't a local with the given name, go up a level and look for locals to capture
      // or existing upvalues.
      if let Some(parent) = self.parent.as_mut() {
         if let Some(place) = parent.lookup(name)? {
            match place {
               VariablePlace::Local(local_slot) => {
                  let (_, variable) = parent
                     .variables_in_scope_mut()
                     .find(|(_, var)| var.stack_slot == local_slot)
                     .unwrap();
                  variable.is_captured = true;
                  let stack_slot = variable.stack_slot;
                  let upvalue_index = self.capture_index(CaptureKind::Local(stack_slot))?;
                  return Ok(Some(VariablePlace::Upvalue(upvalue_index)));
               }
               VariablePlace::Upvalue(upvalue_index) => {
                  let own_index = self.capture_index(CaptureKind::Upvalue(upvalue_index))?;
                  return Ok(Some(VariablePlace::Upvalue(own_index)));
               }
               VariablePlace::Global(_) => unreachable!(),
            }
         }
      }
      Ok(None)
   }
fn lookup ( & mut self , name : & str ) -> Result < Option < VariablePlace > , ErrorKind > { // Work inside out: try innermost scopes (own locals) first. for scope in self . scopes . iter ( ) . rev ( ) { if let Some ( var ) = scope . variables_by_name . get ( name ) { return Ok ( Some ( VariablePlace :: Local ( var . stack_slot ) ) ) ; } } // If there isn't a local with the given name, go up a level and look for locals to capture // or existing upvalues. if let Some ( parent ) = self . parent . as_mut ( ) { if let Some ( place ) = parent . lookup ( name ) ? { match place { VariablePlace :: Local ( local_slot ) => { let ( _ , variable ) = parent . variables_in_scope_mut ( ) . find ( | ( _ , var ) | var . stack_slot == local_slot ) . unwrap ( ) ; variable . is_captured = true ; let stack_slot = variable . stack_slot ; let upvalue_index = self . capture_index ( CaptureKind :: Local ( stack_slot ) ) ? ; return Ok ( Some ( VariablePlace :: Upvalue ( upvalue_index ) ) ) ; } VariablePlace :: Upvalue ( upvalue_index ) => { let own_index = self . capture_index ( CaptureKind :: Upvalue ( upvalue_index ) ) ? ; return Ok ( Some ( VariablePlace :: Upvalue ( own_index ) ) ) ; } VariablePlace :: Global ( _ ) => unreachable ! ( ) , } } } Ok ( None ) }
Performs a local variable lookup.
Performs a local variable lookup .
&mut self
name
&str