Simplified file structure

This commit is contained in:
Eduard Urbach 2024-08-07 19:39:10 +02:00
parent cacee7260a
commit a466281307
Signed by: eduard
GPG key ID: 49226B848C78F6C8
219 changed files with 453 additions and 457 deletions

30
src/scope/Scope.go Normal file
View file

@ -0,0 +1,30 @@
package scope
import (
"git.akyoto.dev/cli/q/src/cpu"
)
// Scope represents an independent code block.
type Scope struct {
Variables []*Variable
Depth uint8
InLoop bool
cpu.State
}
// AddVariable adds a new variable to the current scope.
func (s *Scope) AddVariable(variable *Variable) {
s.Variables = append(s.Variables, variable)
s.Use(variable.Register)
}
// VariableByName returns the variable with the given name or `nil` if it doesn't exist.
func (s *Scope) VariableByName(name string) *Variable {
for _, v := range s.Variables {
if v.Name == name {
return v
}
}
return nil
}