Added separate value type for extern calls
All checks were successful
/ test (push) Successful in 30s

This commit is contained in:
Eduard Urbach 2025-07-03 16:57:39 +02:00
parent 4aa4d613a1
commit 3f481d0bd3
Signed by: akyoto
GPG key ID: 49226B848C78F6C8
4 changed files with 110 additions and 28 deletions

73
src/ssa/CallExtern.go Normal file
View file

@ -0,0 +1,73 @@
package ssa
import (
"strconv"
"strings"
"git.urbach.dev/cli/q/src/types"
)
type CallExtern struct {
Id
Arguments
Liveness
Source
}
func (a *CallExtern) Equals(v Value) bool {
b, sameType := v.(*CallExtern)
if !sameType {
return false
}
return a.Arguments.Equals(b.Arguments)
}
func (v *CallExtern) IsConst() bool {
return false
}
func (v *CallExtern) Debug(expand bool) string {
tmp := strings.Builder{}
if expand {
tmp.WriteString(v.Arguments[0].String())
} else {
tmp.WriteString("%")
tmp.WriteString(strconv.Itoa(v.Arguments[0].ID()))
}
tmp.WriteString("(")
args := v.Arguments[1:]
for i, arg := range args {
if expand {
tmp.WriteString(arg.String())
} else {
tmp.WriteString("%")
tmp.WriteString(strconv.Itoa(arg.ID()))
}
if i != len(args)-1 {
tmp.WriteString(", ")
}
}
tmp.WriteString(")")
return tmp.String()
}
func (v *CallExtern) String() string {
return v.Debug(true)
}
func (v *CallExtern) Type() types.Type {
typ := v.Arguments[0].(*Function).Typ
if len(typ.Output) == 0 {
return types.Void
}
return typ.Output[0]
}