Fixed register allocation on function calls

This commit is contained in:
2025-02-05 22:49:39 +01:00
parent 5d38a4980a
commit 12894dbcc5
5 changed files with 40 additions and 67 deletions

View File

@ -3,7 +3,6 @@ package core
import (
"fmt"
"git.akyoto.dev/cli/q/src/asm"
"git.akyoto.dev/cli/q/src/errors"
"git.akyoto.dev/cli/q/src/expression"
"git.akyoto.dev/cli/q/src/types"
@ -103,33 +102,6 @@ func (f *Function) CompileCall(root *expression.Expression) (*Function, error) {
}
}
for _, register := range f.CPU.Output[:len(fn.Output)] {
f.SaveRegister(register)
}
for _, register := range f.CPU.General {
if f.RegisterIsUsed(register) {
f.Register(asm.PUSH, register)
}
}
f.Call(fn.UniqueName)
for _, register := range registers {
if register == f.CPU.Output[0] && root.Parent != nil {
continue
}
f.FreeRegister(register)
}
for i := len(f.CPU.General) - 1; i >= 0; i-- {
register := f.CPU.General[i]
if f.RegisterIsUsed(register) {
f.Register(asm.POP, register)
}
}
f.CallSafe(fn, registers)
return fn, nil
}