Added eval package
This commit is contained in:
parent
891b4d9f90
commit
3d294eb35c
16 changed files with 274 additions and 148 deletions
|
@ -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,
|
||||
|
|
|
@ -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--
|
||||
}
|
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue