From 1825a72f8c2bbf5f212be8956f549051603f5099 Mon Sep 17 00:00:00 2001 From: Eduard Urbach Date: Tue, 16 Jul 2024 15:39:32 +0200 Subject: [PATCH] Removed unused variables from scopes --- src/build/core/Scope.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/build/core/Scope.go b/src/build/core/Scope.go index db9f6bd..a88187b 100644 --- a/src/build/core/Scope.go +++ b/src/build/core/Scope.go @@ -27,11 +27,17 @@ func (s *state) pushScope(body ast.AST) { scope.variables = make(map[string]*Variable, len(lastScope.variables)) for k, v := range lastScope.variables { + count := ast.Count(body, token.Identifier, v.Name) + + if count == 0 { + continue + } + scope.variables[k] = &Variable{ Value: v.Value, Name: v.Name, Register: v.Register, - Alive: ast.Count(body, token.Identifier, v.Name), + Alive: count, } } } else {