Added eval package

This commit is contained in:
Eduard Urbach 2025-02-27 19:45:18 +01:00
parent 891b4d9f90
commit 3d294eb35c
Signed by: eduard
GPG key ID: 49226B848C78F6C8
16 changed files with 274 additions and 148 deletions

View file

@ -3,6 +3,7 @@ package scope
import (
"git.urbach.dev/cli/q/src/ast"
"git.urbach.dev/cli/q/src/cpu"
"git.urbach.dev/cli/q/src/eval"
"git.urbach.dev/cli/q/src/token"
)
@ -45,7 +46,8 @@ func (stack *Stack) PushScope(body ast.AST, buffer []byte) *Scope {
s.Variables = append(s.Variables, &Variable{
Name: v.Name,
Value: Value{
Value: eval.Value{
Kind: eval.Register,
Register: v.Register,
Alive: count,
Type: v.Type,

View file

@ -1,27 +0,0 @@
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,7 +1,9 @@
package scope
import "git.urbach.dev/cli/q/src/eval"
// Variable is a named value.
type Variable struct {
Value
Name string
eval.Value
}