Reduced memory usage
This commit is contained in:
parent
2b002f03c4
commit
6276562777
5 changed files with 26 additions and 18 deletions
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue