Implemented Value interface
This commit is contained in:
parent
fbcadae268
commit
9cfca57111
36 changed files with 194 additions and 153 deletions
|
@ -15,7 +15,7 @@ type Scope struct {
|
|||
// 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)
|
||||
s.Use(variable.Value.Register)
|
||||
}
|
||||
|
||||
// VariableByName returns the variable with the given name or `nil` if it doesn't exist.
|
||||
|
|
|
@ -46,11 +46,10 @@ func (stack *Stack) PushScope(body ast.AST, buffer []byte) *Scope {
|
|||
|
||||
s.Variables = append(s.Variables, &Variable{
|
||||
Name: v.Name,
|
||||
Value: eval.Value{
|
||||
Kind: eval.Register,
|
||||
Register: v.Register,
|
||||
Value: eval.Register{
|
||||
Typ: v.Value.Typ,
|
||||
Alive: count,
|
||||
Type: v.Type,
|
||||
Register: v.Value.Register,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
@ -73,10 +72,10 @@ func (stack *Stack) UseVariable(variable *Variable) {
|
|||
continue
|
||||
}
|
||||
|
||||
local.Use()
|
||||
local.Value.Use()
|
||||
|
||||
if !local.IsAlive() {
|
||||
scope.Free(local.Register)
|
||||
if !local.Value.IsAlive() {
|
||||
scope.Free(local.Value.Register)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -89,7 +88,7 @@ func (stack *Stack) VariableByName(name string) *Variable {
|
|||
// VariableByRegister returns the variable that occupies the given register or `nil` if none occupy the register.
|
||||
func (stack *Stack) VariableByRegister(register cpu.Register) *Variable {
|
||||
for _, v := range stack.CurrentScope().Variables {
|
||||
if v.Register == register {
|
||||
if v.Value.Register == register {
|
||||
return v
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,6 +4,6 @@ import "git.urbach.dev/cli/q/src/eval"
|
|||
|
||||
// Variable is a named value.
|
||||
type Variable struct {
|
||||
Name string
|
||||
eval.Value
|
||||
Name string
|
||||
Value eval.Register
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue