mirror of
https://github.com/RustPython/Parser.git
synced 2025-07-18 18:45:23 +00:00
Merge pull request #2006 from Lynskylate/try-to-use-local
Use loadname local replace loadname free
This commit is contained in:
commit
3c080eb4cc
2 changed files with 12 additions and 4 deletions
|
@ -298,7 +298,15 @@ impl<O: OutputStream> Compiler<O> {
|
|||
SymbolScope::Global => bytecode::NameScope::Global,
|
||||
SymbolScope::Nonlocal => bytecode::NameScope::NonLocal,
|
||||
SymbolScope::Unknown => bytecode::NameScope::Free,
|
||||
SymbolScope::Local => bytecode::NameScope::Free,
|
||||
SymbolScope::Local => {
|
||||
// Only in function block, we use load local
|
||||
// https://github.com/python/cpython/blob/master/Python/compile.c#L3582
|
||||
if self.ctx.in_func() {
|
||||
bytecode::NameScope::Local
|
||||
} else {
|
||||
bytecode::NameScope::Free
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -698,11 +698,11 @@ impl SymbolTableBuilder {
|
|||
self.scan_expressions(vals, context)?;
|
||||
}
|
||||
Subscript { a, b } => {
|
||||
self.scan_expression(a, context)?;
|
||||
self.scan_expression(b, context)?;
|
||||
self.scan_expression(a, &ExpressionContext::Load)?;
|
||||
self.scan_expression(b, &ExpressionContext::Load)?;
|
||||
}
|
||||
Attribute { value, .. } => {
|
||||
self.scan_expression(value, context)?;
|
||||
self.scan_expression(value, &ExpressionContext::Load)?;
|
||||
}
|
||||
Dict { elements } => {
|
||||
for (key, value) in elements {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue