@@ -32,16 +32,16 @@ use crate::{
3232 function:: DynamicFunction ,
3333 lsp:: { CodeMeta , Completion , ImportSrc , SetInverses , SigDecl } ,
3434 media:: { LayoutParam , VoxelsParam } ,
35- parse:: ident_modifier_args,
3635 parse:: {
37- flip_unsplit_items, flip_unsplit_lines, max_placeholder, parse, split_items, split_words,
36+ flip_unsplit_items, flip_unsplit_lines, ident_modifier_args, max_placeholder, parse,
37+ split_items, split_words,
3838 } ,
3939 Array , ArrayValue , Assembly , BindingKind , BindingMeta , Boxed , CodeSpan , CustomInverse ,
40- Diagnostic , DiagnosticKind , DocComment , DocCommentSig , Function , FunctionId , GitTarget , Ident ,
41- ImplPrimitive , InputSrc , IntoInputSrc , IntoSysBackend , Node , NumericSubscript , PrimClass ,
42- Primitive , Purity , RunMode , SemanticComment , SigNode , Signature , Sp , Span , SubSide , Subscript ,
43- SysBackend , Uiua , UiuaError , UiuaErrorKind , UiuaResult , Value , CONSTANTS , EXAMPLE_UA ,
44- SUBSCRIPT_DIGITS , VERSION ,
40+ Diagnostic , DiagnosticKind , DocComment , DocCommentSig , ExactDoubleIterator , Function ,
41+ FunctionId , GitTarget , Ident , ImplPrimitive , InputSrc , IntoInputSrc , IntoSysBackend , Node ,
42+ NumericSubscript , PrimClass , Primitive , Purity , RunMode , SemanticComment , SigNode , Signature ,
43+ Sp , Span , SubSide , Subscript , SysBackend , Uiua , UiuaError , UiuaErrorKind , UiuaResult , Value ,
44+ CONSTANTS , EXAMPLE_UA , SUBSCRIPT_DIGITS , VERSION ,
4545} ;
4646pub ( crate ) use data:: * ;
4747pub use pre_eval:: PreEvalMode ;
@@ -231,7 +231,7 @@ enum ScopeKind {
231231 /// A scope that includes all bindings in a module
232232 AllInModule ,
233233 /// A temporary scope, probably for a macro
234- Temp ( Option < MacroLocal > ) ,
234+ Macro ( Option < MacroLocal > ) ,
235235 /// A binding scope
236236 Binding ,
237237 /// A function scope between some delimiters
@@ -389,8 +389,11 @@ impl Compiler {
389389 let src = self . asm . inputs . add_src ( src, input) ;
390390 self . load_impl ( input, src)
391391 }
392- fn scopes ( & self ) -> impl Iterator < Item = & Scope > {
393- once ( & self . scope ) . chain ( self . higher_scopes . iter ( ) . rev ( ) )
392+ fn scopes ( & self ) -> impl ExactDoubleIterator < Item = & Scope > {
393+ once ( & self . scope )
394+ . chain ( self . higher_scopes . iter ( ) . rev ( ) )
395+ . collect :: < Vec < _ > > ( )
396+ . into_iter ( )
394397 }
395398 #[ allow( dead_code) ]
396399 fn scopes_mut ( & mut self ) -> impl Iterator < Item = & mut Scope > {
@@ -1686,23 +1689,23 @@ impl Compiler {
16861689 // for scope in self.scopes() {
16871690 // println!(" {:?} {:?}", scope.kind, scope.names);
16881691 // }
1692+ let skip = if skip_temp {
1693+ self . scopes ( )
1694+ . rposition ( |sc| matches ! ( sc. kind, ScopeKind :: Macro ( _) ) )
1695+ . map ( |s| s + 1 )
1696+ . unwrap_or ( 0 )
1697+ } else {
1698+ 0
1699+ } ;
16891700 let mut hit_file = false ;
1690- let mut hit_temp = false ;
1691- for scope in self . scopes ( ) {
1701+ for scope in self . scopes ( ) . skip ( skip) {
16921702 if matches ! ( scope. kind, ScopeKind :: File ( _) )
16931703 || stop_at_binding && matches ! ( scope. kind, ScopeKind :: Binding )
16941704 {
16951705 if hit_file {
16961706 break ;
16971707 }
16981708 hit_file = true ;
1699- } else if matches ! ( scope. kind, ScopeKind :: Temp ( _) ) {
1700- if skip_temp && !hit_temp {
1701- hit_temp = true ;
1702- continue ;
1703- }
1704- } else if skip_temp && !hit_temp {
1705- continue ;
17061709 }
17071710 if let Some ( local) = scope. names . get ( name) . copied ( ) {
17081711 return Some ( local) ;
@@ -2814,7 +2817,7 @@ impl Compiler {
28142817 }
28152818 SetterStashKind :: Scope ( ScopeKind :: Binding ) => "binding" ,
28162819 SetterStashKind :: Scope ( ScopeKind :: File ( _) ) => "file" ,
2817- SetterStashKind :: Scope ( ScopeKind :: Temp ( _) ) => "macro" ,
2820+ SetterStashKind :: Scope ( ScopeKind :: Macro ( _) ) => "macro" ,
28182821 SetterStashKind :: Scope ( ScopeKind :: Module ( _) ) => "module" ,
28192822 SetterStashKind :: Scope ( ScopeKind :: Test ) => "test scope" ,
28202823 } ;
0 commit comments