Implemented variable scopes

This commit is contained in:
2024-07-15 16:51:36 +02:00
parent 948d499231
commit 24d3e8f2be
13 changed files with 81 additions and 26 deletions

View File

@ -12,3 +12,19 @@ type Variable struct {
Register cpu.Register
Alive int
}
// Variable returns the variable with the given name or `nil` if it doesn't exist.
func (s *state) Variable(name string) *Variable {
return s.Scope()[name]
}
// VariableInRegister returns the variable that occupies the given register or `nil` if none occupy the register.
func (s *state) VariableInRegister(register cpu.Register) *Variable {
for _, v := range s.Scope() {
if v.Register == register {
return v
}
}
return nil
}