Added scope package
This commit is contained in:
36
src/build/core/useVariable.go
Normal file
36
src/build/core/useVariable.go
Normal file
@ -0,0 +1,36 @@
|
||||
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)
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user