Simplified variable usage
This commit is contained in:
parent
6276562777
commit
c3234361f7
8 changed files with 45 additions and 44 deletions
|
@ -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")
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue