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

Method add_upvalue

aiscript-vm/src/compiler/codegen.rs:1695–1716  ·  view source on GitHub ↗
(&mut self, index: usize, is_local: bool)

Source from the content-addressed store, hash-verified

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();
1697
1698 // before we add a new upvalue, we first check to see if the function
1699 // already has an upvalue that closes over that variable.
1700 if let Some(i) = self
1701 .function
1702 .upvalues
1703 .iter()
1704 .position(|u| u.index == index && u.is_local == is_local)
1705 {
1706 return Ok(i);
1707 }
1708
1709 if self.function.upvalues.len() == MAX_LOCALS {
1710 return Err("Too many closure variables in function.");
1711 }
1712
1713 self.function.upvalues.push(Upvalue { index, is_local });
1714 // println!("add upvalue to {upvalue_index} of {:?}", Upvalue { index, is_local });
1715 Ok(upvalue_index)
1716 }
1717
1718 // Scope management methods
1719 fn begin_scope(&mut self) {

Callers 1

resolve_upvalueMethod · 0.80

Calls 2

lenMethod · 0.80
pushMethod · 0.80

Tested by

no test coverage detected