Added eval package
This commit is contained in:
11
src/eval/Kind.go
Normal file
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
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--
|
||||
}
|
Reference in New Issue
Block a user