Implemented variable scopes
This commit is contained in:
@ -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
|
||||
}
|
||||
|
Reference in New Issue
Block a user