File tree Expand file tree Collapse file tree 2 files changed +120
-270
lines changed Expand file tree Collapse file tree 2 files changed +120
-270
lines changed Original file line number Diff line number Diff line change @@ -98,6 +98,28 @@ impl<A: Clone> Environment<A> {
98
98
pub fn pop ( & mut self ) -> ( ) {
99
99
self . stack . pop_front ( ) ;
100
100
}
101
+
102
+ pub fn get_all_variables ( & self ) -> Vec < ( Name , A ) > {
103
+ let mut vars = Vec :: new ( ) ;
104
+
105
+ // First get variables from local scopes (in reverse order to respect shadowing)
106
+ for scope in self . stack . iter ( ) {
107
+ for ( name, value) in & scope. variables {
108
+ if !vars. iter ( ) . any ( |( n, _) | n == name) {
109
+ vars. push ( ( name. clone ( ) , value. clone ( ) ) ) ;
110
+ }
111
+ }
112
+ }
113
+
114
+ // Then get variables from global scope (if not already found)
115
+ for ( name, value) in & self . globals . variables {
116
+ if !vars. iter ( ) . any ( |( n, _) | n == name) {
117
+ vars. push ( ( name. clone ( ) , value. clone ( ) ) ) ;
118
+ }
119
+ }
120
+
121
+ vars
122
+ }
101
123
}
102
124
103
125
#[ cfg( test) ]
You can’t perform that action at this time.
0 commit comments