@@ -184,25 +184,24 @@ impl VM {
184184 if self . environs . len ( ) == 0 {
185185 panic ! ( "pop_environment: environs is empty" ) ;
186186 }
187- // Fuck reference counted ptrs
188- // Why do I have to count references, MANUALLY
189- // (there is probably a better way to do this, but time's ticking)
190- let environ = self . environs . last ( ) . unwrap ( ) ;
191- let mut refs: usize = 0 ;
192- for e in self . environs . iter ( ) {
193- if Rc :: ptr_eq ( e, environ) {
194- refs += 1 ;
187+
188+ let mut in_use = false ;
189+ let env = self . environs . last ( ) . unwrap ( ) ;
190+ for environ in self . environs . iter ( ) {
191+ for var in ( & * environ. borrow ( ) ) . vars . iter ( ) {
192+ if let Value :: FunctionRefEnv ( _, _, e) = & var. 1 {
193+ if let Some ( e) = & e. upgrade ( ) {
194+ if Rc :: ptr_eq ( env, e) {
195+ in_use = true ;
196+ }
197+ }
198+ }
195199 }
196200 }
197201
198- // If refs != 1, the vars are prolly used somewhere else so don't clear them
199- // TODO: This doesn't work and doesn't pass the fourth test in vm_closure.rs, instead we
200- // should try using weak ptr's
201- if refs == 1 {
202- ( & mut * environ. borrow_mut ( ) ) . vars . clear ( ) ;
202+ if !in_use {
203+ //self.environs.pop();
203204 }
204-
205- self . environs . pop ( ) ;
206205 }
207206
208207 pub fn get_function_name_from_pc ( & mut self , pc : u64 ) -> Option < String > {
0 commit comments