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

Method declare_variable

aiscript-vm/src/compiler/codegen.rs:1764–1782  ·  view source on GitHub ↗
(&mut self, name: Token<'gc>, mutability: Mutability)

Source from the content-addressed store, hash-verified

1762 }
1763
1764 fn declare_variable(&mut self, name: Token<'gc>, mutability: Mutability) -> usize {
1765 if self.scope_depth == 0 {
1766 return 0;
1767 }
1768
1769 for i in (0..self.local_count).rev() {
1770 let local = &self.locals[i];
1771 if local.is_initialized() && local.depth < self.scope_depth {
1772 // Stop when we reach an outer scope
1773 break;
1774 }
1775 if local.name.lexeme == name.lexeme {
1776 self.error_at(name, "Already a variable with this name in this scope.");
1777 // return;
1778 }
1779 }
1780
1781 self.add_local(name, mutability)
1782 }
1783
1784 fn update_top_local_name(&mut self, name: Token<'gc>) {
1785 self.locals[self.local_count - 1].name = name;

Callers 5

generate_stmtMethod · 0.80
generate_lambdaMethod · 0.80
generate_classMethod · 0.80
generate_functionMethod · 0.80

Calls 3

is_initializedMethod · 0.80
add_localMethod · 0.80
error_atMethod · 0.45

Tested by

no test coverage detected