Simplified Evaluate function

This commit is contained in:
Eduard Urbach 2025-02-27 15:30:44 +01:00
parent da6dcc4433
commit 891b4d9f90
Signed by: eduard
GPG key ID: 49226B848C78F6C8
15 changed files with 98 additions and 96 deletions

View file

@ -44,10 +44,12 @@ func (stack *Stack) PushScope(body ast.AST, buffer []byte) *Scope {
}
s.Variables = append(s.Variables, &Variable{
Name: v.Name,
Register: v.Register,
Alive: count,
Type: v.Type,
Name: v.Name,
Value: Value{
Register: v.Register,
Alive: count,
Type: v.Type,
},
})
}
}

27
src/scope/Value.go Normal file
View file

@ -0,0 +1,27 @@
package scope
import (
"git.urbach.dev/cli/q/src/cpu"
"git.urbach.dev/cli/q/src/types"
)
// Value combines a register with its data type.
type Value struct {
Type types.Type
Register cpu.Register
Alive uint8
}
// IsAlive returns true if the Value is still alive.
func (v *Value) IsAlive() bool {
return v.Alive > 0
}
// Use reduces the lifetime counter by one.
func (v *Value) Use() {
if v.Alive == 0 {
panic("incorrect number of value use calls")
}
v.Alive--
}

View file

@ -1,28 +1,7 @@
package scope
import (
"git.urbach.dev/cli/q/src/cpu"
"git.urbach.dev/cli/q/src/types"
)
// Variable represents a named register.
// Variable is a named value.
type Variable struct {
Type types.Type
Name string
Alive uint8
Register cpu.Register
}
// IsAlive returns true if the variable is still alive.
func (v *Variable) IsAlive() bool {
return v.Alive > 0
}
// Use reduces the lifetime counter by one.
func (v *Variable) Use() {
if v.Alive == 0 {
panic("incorrect number of variable use calls")
}
v.Alive--
Value
Name string
}