Reduced memory usage

This commit is contained in:
Eduard Urbach 2024-07-22 17:49:44 +02:00
parent 2b002f03c4
commit 6276562777
Signed by: eduard
GPG key ID: 49226B848C78F6C8
5 changed files with 26 additions and 18 deletions

View file

@ -6,7 +6,25 @@ import (
// Scope represents an independent code block.
type Scope struct {
Variables map[string]*Variable
Variables []*Variable
InLoop bool
cpu.State
}
// AddVariable adds a new variable to the current scope.
func (s *Scope) AddVariable(variable *Variable) {
variable.Scope = s
s.Variables = append(s.Variables, variable)
s.Use(variable.Register)
}
// VariableByName returns the variable with the given name or `nil` if it doesn't exist.
func (s *Scope) VariableByName(name string) *Variable {
for _, v := range s.Variables {
if v.Name == name {
return v
}
}
return nil
}