Added scope package

This commit is contained in:
2024-07-20 23:20:23 +02:00
parent 263c0cfb8b
commit 43cdac5572
37 changed files with 416 additions and 371 deletions

View 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)
}
}
}