Simplified variable usage

This commit is contained in:
Eduard Urbach 2024-07-22 19:10:14 +02:00
parent 6276562777
commit c3234361f7
Signed by: eduard
GPG key ID: 49226B848C78F6C8
8 changed files with 45 additions and 44 deletions

View file

@ -6,8 +6,22 @@ import (
// Variable represents a named register.
type Variable struct {
Scope *Scope
Name string
Register cpu.Register
Alive int
Depth uint8
Register cpu.Register
}
// IsAlive returns true if the variable is still alive.
func (v *Variable) IsAlive() bool {
return v.Alive > 0
}
// Use reduces the lifetime counter by one.
func (v *Variable) Use() {
v.Alive--
if v.Alive < 0 {
panic("incorrect number of variable use calls")
}
}