37 lines
708 B
Go
37 lines
708 B
Go
package core
|
|
|
|
import (
|
|
"git.akyoto.dev/cli/q/src/build/config"
|
|
"git.akyoto.dev/cli/q/src/build/scope"
|
|
)
|
|
|
|
func (f *Function) useVariable(variable *scope.Variable) {
|
|
for i, scope := range f.Scopes {
|
|
if scope.InLoop && variable.Scope != scope {
|
|
continue
|
|
}
|
|
|
|
local := scope.Variables[variable.Name]
|
|
|
|
if local == nil {
|
|
continue
|
|
}
|
|
|
|
local.Alive--
|
|
|
|
if local.Alive < 0 {
|
|
panic("incorrect number of variable use calls")
|
|
}
|
|
|
|
if local.Alive == 0 {
|
|
if config.Comments {
|
|
f.Comment("%s (%s) died in scope %d", local.Name, local.Register, i)
|
|
}
|
|
|
|
scope.Free(local.Register)
|
|
} else if config.Comments {
|
|
f.Comment("%s (%s) used in scope %d", local.Name, local.Register, i)
|
|
}
|
|
}
|
|
}
|