Reduced interface bloat
All checks were successful
/ test (push) Successful in 32s

This commit is contained in:
Eduard Urbach 2025-07-03 20:12:11 +02:00
parent ba2314db4a
commit b77d876ebb
Signed by: akyoto
GPG key ID: 49226B848C78F6C8
11 changed files with 36 additions and 37 deletions

View file

@ -8,7 +8,7 @@ type Block struct {
// Append adds a new instruction to the block.
func (block *Block) Append(instr Value) Value {
for _, dep := range instr.Dependencies() {
dep.AddUser(instr)
dep.(HasLiveness).AddUser(instr)
}
block.Instructions = append(block.Instructions, instr)

6
src/ssa/HasLiveness.go Normal file
View file

@ -0,0 +1,6 @@
package ssa
type HasLiveness interface {
AddUser(Value)
Users() []Value
}

8
src/ssa/HasSource.go Normal file
View file

@ -0,0 +1,8 @@
package ssa
import "git.urbach.dev/cli/q/src/token"
type HasSource interface {
Start() token.Position
End() token.Position
}

View file

@ -8,6 +8,6 @@ func (v *Liveness) AddUser(user Value) {
v.users = append(v.users, user)
}
func (v *Liveness) CountUsers() int {
return len(v.users)
func (v *Liveness) Users() []Value {
return v.users
}

View file

@ -1,6 +0,0 @@
package ssa
type NoLiveness struct{}
func (a *NoLiveness) AddUser(user Value) { panic("value does not have liveness") }
func (a *NoLiveness) CountUsers() int { return 0 }

View file

@ -11,7 +11,6 @@ type Return struct {
Id
Arguments
Source
NoLiveness
}
func (a *Return) Equals(v Value) bool {

View file

@ -4,14 +4,10 @@ import "git.urbach.dev/cli/q/src/token"
type Source token.List
func (v Source) End() token.Position {
return v[len(v)-1].End()
}
func (v *Source) SetSource(source token.List) {
*v = Source(source)
}
func (v Source) Start() token.Position {
return v[0].Position
}
func (v Source) End() token.Position {
return v[len(v)-1].End()
}

View file

@ -1,29 +1,16 @@
package ssa
import (
"git.urbach.dev/cli/q/src/token"
"git.urbach.dev/cli/q/src/types"
)
type Value interface {
// Essentials
Debug(bool) string
Dependencies() []Value
Equals(Value) bool
ID() int
IsConst() bool
SetID(int)
String() string
Type() types.Type
// Arguments
Dependencies() []Value
Equals(Value) bool
// Liveness
AddUser(Value)
CountUsers() int
// Source
SetSource(token.List)
Start() token.Position
End() token.Position
}