MCPcopy Index your code
hub / github.com/aiscriptdev/aiscript / resolve_upvalue

Method resolve_upvalue

aiscript-vm/src/compiler/codegen.rs:1666–1693  ·  view source on GitHub ↗
(
        &mut self,
        name: &str,
    )

Source from the content-addressed store, hash-verified

1664 }
1665
1666 fn resolve_upvalue(
1667 &mut self,
1668 name: &str,
1669 ) -> Result<Option<(u8, isize, Mutability)>, &'static str> {
1670 if let Some((index, depth, mutability)) = self
1671 .enclosing
1672 .as_mut()
1673 .and_then(|enclosing| enclosing.resolve_local(name))
1674 {
1675 if let Some(enclosing) = self.enclosing.as_mut() {
1676 // When resolving an identifier, if we end up creating an upvalue for
1677 // a local variable, we mark it as captured.
1678 enclosing.locals[index as usize].is_captured = true;
1679 }
1680 let index = self.add_upvalue(index as usize, true)?;
1681 return Ok(Some((index as u8, depth, mutability)));
1682 } else if let Some((index, depth, mutability)) = self
1683 .enclosing
1684 .as_mut()
1685 .and_then(|enclosing| enclosing.resolve_upvalue(name).ok())
1686 .flatten()
1687 {
1688 let index = self.add_upvalue(index as usize, false)?;
1689 return Ok(Some((index as u8, depth, mutability)));
1690 }
1691
1692 Ok(None)
1693 }
1694
1695 fn add_upvalue(&mut self, index: usize, is_local: bool) -> Result<usize, &'static str> {
1696 let upvalue_index = self.function.upvalues.len();

Callers 2

generate_exprMethod · 0.80
named_variableMethod · 0.80

Calls 3

as_mutMethod · 0.80
resolve_localMethod · 0.80
add_upvalueMethod · 0.80

Tested by

no test coverage detected