Added eval package

This commit is contained in:
2025-02-27 19:45:18 +01:00
parent efb3089211
commit e7afb2dab5
16 changed files with 274 additions and 148 deletions

11
src/eval/Kind.go Normal file

@ -0,0 +1,11 @@
package eval
type Kind uint8
const (
Invalid Kind = iota // Invalid is an invalid value.
Number // Number is an immediately encoded value stored together with the instruction.
Register // Register is a CPU register.
Memory // Memory is an area in the RAM.
Label // Label is a reference to a name that can only be resolved once the program is fully compiled.
)

32
src/eval/Value.go Normal file

@ -0,0 +1,32 @@
package eval
import (
"git.urbach.dev/cli/q/src/asm"
"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
Label string
Number int
Memory asm.Memory
Register cpu.Register
Alive uint8
Kind Kind
}
// 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--
}